Moved drawing from density to seperate classes
This commit is contained in:
+26
-81
@@ -11,17 +11,6 @@
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
#include <sstream>
|
||||
|
||||
blitz::TinyVector<double, 3> perpendicularNormalVector(blitz::TinyVector<double, 3> vector) {
|
||||
blitz::TinyVector<double, 3> result(0,0,0);
|
||||
result[0] = std::copysign(vector[2], vector[0]);
|
||||
result[1] = std::copysign(vector[2], vector[1]);
|
||||
result[2] = - std::copysign(std::fabs(vector[0] + std::fabs(vector[1])), vector[2]);
|
||||
|
||||
// DEBUG_LEVEL_3("dot product: " + std::to_string(blitz::dot(result, vector)));
|
||||
|
||||
return result / kinematic::norm(result);
|
||||
}
|
||||
|
||||
Injector::Injector(
|
||||
std::vector<InjectorInfo>& injector_info,
|
||||
double activity,
|
||||
@@ -65,6 +54,9 @@ void Injector::initInjectionTimeDistribution(double delta_t) {
|
||||
|
||||
std::vector<particle::Particle> Injector::rollNewParticles(
|
||||
std::mt19937* engine, const double current_time) {
|
||||
// pull drawing from the position distribution into the "multiplicity" loop?
|
||||
// (would improve resolution stuff in space as well as just in velocity direction
|
||||
// especially for slow particles, i.e. ions)
|
||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
@@ -85,90 +77,43 @@ std::vector<particle::Particle> Injector::rollNewParticles(
|
||||
return new_particles;
|
||||
}
|
||||
|
||||
/*
|
||||
void Injector::rollNewParticleFromDensityField(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::vector<particle::Particle>& queue,
|
||||
const double weight,
|
||||
const double injection_time) {
|
||||
blitz::TinyVector<double, 4> particle_specs =
|
||||
specie->densityForDrawing()->drawPositionAndEnergy(engine);
|
||||
|
||||
// check if density was empty (i.e. Energy component is 0)
|
||||
if (particle_specs[3] == 0) {
|
||||
DEBUG_LEVEL_3(specie->name() + ": has zero density");
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LEVEL_3("Injected z position: " + std::to_string(particle_specs(2)));
|
||||
DEBUG_LEVEL_3("Injected r position: " + std::to_string(particle_specs(0)));
|
||||
|
||||
const double v_abs = kinematic::velocity(particle_specs[3], specie->mass_kg());
|
||||
|
||||
std::uniform_real_distribution<double> distribution(0.0, 1.0);
|
||||
const double theta = distribution(*engine) * 2 * M_PI;
|
||||
const double phi = std::acos(1. - 2.*distribution(*engine));
|
||||
|
||||
// for now, draw the particles with an isotropic velocity distribution,
|
||||
// is not realistic but as of now there is no information about the
|
||||
// velocity vector distribution in the respective cell
|
||||
blitz::TinyVector<double, 3> v_normal(std::cos(theta) * std::sin(phi),
|
||||
std::sin(theta) * std::sin(phi),
|
||||
std::cos(phi));
|
||||
|
||||
particle::Particle drawn_particle(specie, CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3>(particle_specs[0],
|
||||
particle_specs[1], particle_specs[2])),
|
||||
CartesianVector(v_normal*v_abs), injection_time, weight);
|
||||
|
||||
queue.push_back(drawn_particle);
|
||||
}
|
||||
*/
|
||||
|
||||
void Injector::rollNewParticleFromDensityField(std::mt19937* engine,
|
||||
void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::vector<particle::Particle>& queue,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const double weight,
|
||||
const double injection_time) {
|
||||
blitz::TinyVector<double, 5> particle_specs =
|
||||
specie->densityForDrawing()->draw(engine);
|
||||
// draw the position
|
||||
CylinderCoordinate position =
|
||||
specie->positionDistributionFromDensity()->drawPosition(engine);
|
||||
|
||||
// check if density was empty (i.e. Energy component is 0)
|
||||
if (particle_specs[4] == 0) {
|
||||
// check if density was empty (i.e. phi value lower than 0)
|
||||
if (position.cylinderEntries()(1) < 0) {
|
||||
DEBUG_LEVEL_3(specie->name() + ": has zero density");
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LEVEL_3("Injected z position: " + std::to_string(particle_specs(2)));
|
||||
DEBUG_LEVEL_3("Injected r position: " + std::to_string(particle_specs(0)));
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
DEBUG_LEVEL_3("Injected r position: " +
|
||||
std::to_string(position.cylinderEntries()(0)));
|
||||
|
||||
CylinderCoordinate position(blitz::TinyVector<double, 3>(particle_specs[0],
|
||||
particle_specs[1],
|
||||
particle_specs[2]));
|
||||
// draw the velocity
|
||||
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
||||
|
||||
const double v_abs = kinematic::velocity(particle_specs[4], specie->mass_kg());
|
||||
|
||||
std::uniform_real_distribution<double> distribution(0.0, 1.0);
|
||||
const double theta = distribution(*engine) * 2 * M_PI;
|
||||
|
||||
const double mu = particle_specs[3];
|
||||
DEBUG_LEVEL_3("mu: " + std::to_string(mu));
|
||||
|
||||
blitz::TinyVector<double, 3> magnetic_field_value = magnetic_field->
|
||||
value(position).cartesianEntries(position);
|
||||
const double abs_B = kinematic::norm(magnetic_field_value);
|
||||
|
||||
blitz::TinyVector<double, 3> perpendicular_vector =
|
||||
perpendicularNormalVector(magnetic_field_value);
|
||||
|
||||
blitz::TinyVector<double, 3> v_normal = mu*magnetic_field_value/abs_B +
|
||||
std::sqrt(1-mu*mu)*kinematic::rotateVector(perpendicular_vector,
|
||||
magnetic_field_value,
|
||||
theta);
|
||||
// in case the magnetic field is 0 at the current position draw the velocity
|
||||
// with respect to the z-axis otherwise use the magnetic field
|
||||
if(kinematic::norm(magnetic_field->value(position).
|
||||
cartesianEntries(position)) == 0) {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
rollVelocity(position, engine);
|
||||
} else {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
rollVelocity(position, engine, magnetic_field);
|
||||
}
|
||||
|
||||
particle::Particle drawn_particle(specie, position,
|
||||
CartesianVector(v_normal*v_abs), injection_time, weight);
|
||||
velocity, injection_time, weight);
|
||||
|
||||
queue.push_back(drawn_particle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user