<commit_before>/*
 * Particle.hpp
 *
 *  Created on: 28.04.2010
 *      Author: gmueller
 */

#ifndef SMOOTH_PARTICLE_HPP_
#define SMOOTH_PARTICLE_HPP_

#include <ostream>
#include <vector>
#include "gadget/Vector3.hpp"
#include <stdint.h>

class SmoothParticle {
public:
	typedef float float_t;
	typedef Vector3<float_t> vector_t;

	vector_t position;
	vector_t bfield;
	float_t smoothingLength;
	float_t mass;
	float_t rho;

	// see http://arxiv.org/abs/0807.3553v2
	static float_t kernel(float_t r) {
		if (r < 0.5) {
			return 1.0 + 6 * r * r * (r - 1);
		} else if (r < 1.0) {
			float x = (1 - r);
			return 2 * x * x * x;
		} else {
			return 0.0;
		}
	}

	static float_t kernel(float_t value, float_t center, float_t position,
			float_t hsml) {
		return value * kernel(std::fabs((center - position) / hsml));
	}

	static float_t kernel(float_t value, const vector_t &center,
			const vector_t &position, float_t hsml) {
		return value * kernel(std::fabs((center - position).length() / hsml));
	}

	float_t kernel(const vector_t &center) const {
		return kernel(std::fabs((center - position).length() / smoothingLength));
	}

	float_t weight() const {
		return 8 / (M_PI * smoothingLength * smoothingLength * smoothingLength);
	}

	void updateRho(const std::vector<SmoothParticle> &particles) {
		rho = 0;
		for (size_t i = 0; i < particles.size(); i++) {
			rho += particles[i].mass * particles[i].weight()
					* particles[i].kernel(position);
		}
	}
};

class SmoothParticleHelper {
public:
	static void updateRho(std::vector<SmoothParticle> &particles) {
		const size_t s = particles.size();
//#pragma omp parallel for
		for (size_t i = 0; i < s; i++) {
			particles[i].updateRho(particles);
		}
	}
<commit_msg>add scale function to SmoothParticle<commit_after>/*
 * Particle.hpp
 *
 *  Created on: 28.04.2010
 *      Author: gmueller
 */

#ifndef SMOOTH_PARTICLE_HPP_
#define SMOOTH_PARTICLE_HPP_

#include <ostream>
#include <vector>
#include "gadget/Vector3.hpp"
#include <stdint.h>

class SmoothParticle {
public:
	typedef float float_t;
	typedef Vector3<float_t> vector_t;

	vector_t position;
	vector_t bfield;
	float_t smoothingLength;
	float_t mass;
	float_t rho;

	void scale(float_t f, vector_t pivot) {
		smoothingLength *= f;
		mass *= f;
		position.scale(f, pivot);
	}

	// see http://arxiv.org/abs/0807.3553v2
	static float_t kernel(float_t r) {
		if (r < 0.5) {
			return 1.0 + 6 * r * r * (r - 1);
		} else if (r < 1.0) {
			float x = (1 - r);
			return 2 * x * x * x;
		} else {
			return 0.0;
		}
	}

	static float_t kernel(float_t value, float_t center, float_t position,
			float_t hsml) {
		return value * kernel(std::fabs((center - position) / hsml));
	}

	static float_t kernel(float_t value, const vector_t &center,
			const vector_t &position, float_t hsml) {
		return value * kernel(std::fabs((center - position).length() / hsml));
	}

	float_t kernel(const vector_t &point) const {
		float_t distance = (point - position).length();
		float_t normalizedDistance = distance /  smoothingLength;
		return kernel(normalizedDistance);
	}

	float_t weight() const {
		return 8 / (M_PI * smoothingLength * smoothingLength * smoothingLength);
	}

	void updateRho(const std::vector<SmoothParticle> &particles) {
		rho = 0;
		for (size_t i = 0; i < particles.size(); i++) {
			rho += particles[i].mass * particles[i].weight()
					* particles[i].kernel(position);
		}
	}
};

class SmoothParticleHelper {
public:
	static void updateRho(std::vector<SmoothParticle> &particles) {
		const size_t s = particles.size();
//#pragma omp parallel for
		for (size_t i = 0; i < s; i++) {
			particles[i].updateRho(particles);
		}
	}

{'fraction_non_alphanumeric': 0.13757193751712798, 'fraction_numerical': 0.01918333790079474, 'mean_word_length': 3.7096774193548385, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3608071', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1362, 'n_words': 341}