Moved drawing from density to seperate classes
This commit is contained in:
@@ -3,6 +3,21 @@
|
||||
#include "simulation/drift_velocity.h"
|
||||
#include "simulation/kinematic.h"
|
||||
#include "simulation/velocity_distribution_function.h"
|
||||
#include "simulation/density_field.h"
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
|
||||
// utility function returning a unit vector perpendicular to the given
|
||||
// (cartesian) TinyVector
|
||||
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]);
|
||||
|
||||
return result / kinematic::norm(result);
|
||||
}
|
||||
|
||||
VelocityDistributionFromFunction::VelocityDistributionFromFunction(
|
||||
std::shared_ptr<VelocityDistributionFunction> fv)
|
||||
@@ -13,3 +28,113 @@ CartesianVector VelocityDistributionFromFunction::rollVelocity(
|
||||
std::mt19937* engine) {
|
||||
return fv_->rollVelocity(engine);
|
||||
}
|
||||
|
||||
VelocityDistributionFromDensityField::VelocityDistributionFromDensityField(
|
||||
std::shared_ptr<DynamicDensityField> density_field, double mass_kg):
|
||||
density_field_(density_field),
|
||||
energyBinBorders_(density_field->energyBinning()->binBorders()),
|
||||
pitchAngleBinBorders_(density_field->pitchAngleBinning()->binBorders()),
|
||||
theta_distribution_(std::uniform_real_distribution<double>(0.,1.)),
|
||||
mass_kg_(mass_kg) {}
|
||||
|
||||
// not important as of now since it's meant for drawing a velocity from the
|
||||
// pitch angle distribution and not to be used in an interaction context in which
|
||||
// the drift velocity is necessary for the determination of the cross section
|
||||
// (might be possible to extract from the pitch angle dist or from the current)
|
||||
// returns a 0 CartesianVector
|
||||
CartesianVector VelocityDistributionFromDensityField::driftVelocity_ms(
|
||||
const CylinderVector& position) {
|
||||
return CartesianVector(blitz::TinyVector<double, 3> (0,0,0));
|
||||
}
|
||||
|
||||
CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine) {
|
||||
|
||||
// draw energy from DynamicDensityField
|
||||
blitz::Array<double, 1> energyValues = density_field_->
|
||||
sliceSpectrumArray(position);
|
||||
|
||||
std::piecewise_constant_distribution<double> energy_dist(
|
||||
energyBinBorders_.begin(),
|
||||
energyBinBorders_.end(),
|
||||
energyValues.begin());
|
||||
|
||||
double energy_eV = energy_dist(*engine);
|
||||
|
||||
// draw pitch angle from DynamicDensityField
|
||||
|
||||
blitz::Array<double, 1> pitchAngleValues = density_field_->
|
||||
sliceTimeInBinArray(position, energy_eV);
|
||||
|
||||
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
||||
pitchAngleBinBorders_.begin(),
|
||||
pitchAngleBinBorders_.end(),
|
||||
pitchAngleValues.begin());
|
||||
|
||||
double pitchAngle = pitchAngle_dist(*engine);
|
||||
|
||||
// construct the velocity
|
||||
|
||||
const double theta = theta_distribution_(*engine)*2*M_PI;
|
||||
|
||||
blitz::TinyVector<double, 3> zDirection(0,0,1);
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
// vector perpendicular to e_z
|
||||
blitz::TinyVector<double, 3> v_perp(1,0,0);
|
||||
|
||||
blitz::TinyVector<double, 3> v_direction = pitchAngle * zDirection
|
||||
+ std::sqrt(1 - pitchAngle*pitchAngle)
|
||||
* kinematic::rotateVector(v_perp, zDirection, theta);
|
||||
|
||||
return CartesianVector(v_direction * vMagnitude);
|
||||
}
|
||||
|
||||
CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
std::shared_ptr<MagneticField> magnetic_field) {
|
||||
|
||||
// draw energy from DynamicDensityField
|
||||
blitz::Array<double, 1> energyValues = density_field_->
|
||||
sliceSpectrumArray(position);
|
||||
|
||||
std::piecewise_constant_distribution<double> energy_dist(
|
||||
energyBinBorders_.begin(),
|
||||
energyBinBorders_.end(),
|
||||
energyValues.begin());
|
||||
|
||||
double energy_eV = energy_dist(*engine);
|
||||
|
||||
// draw pitch angle from DynamicDensityField
|
||||
|
||||
blitz::Array<double, 1> pitchAngleValues = density_field_->
|
||||
sliceTimeInBinArray(position, energy_eV);
|
||||
|
||||
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
||||
pitchAngleBinBorders_.begin(),
|
||||
pitchAngleBinBorders_.end(),
|
||||
pitchAngleValues.begin());
|
||||
|
||||
double pitchAngle = pitchAngle_dist(*engine);
|
||||
|
||||
// construct the velocity
|
||||
|
||||
const double theta = theta_distribution_(*engine)*2*M_PI;
|
||||
|
||||
blitz::TinyVector<double, 3> cartesianB_values =
|
||||
magnetic_field->value(position).cartesianEntries(position);
|
||||
const double Bmagnitude = kinematic::norm(cartesianB_values);
|
||||
|
||||
const double vMagnitude = kinematic::velocity(energy_eV, mass_kg_);
|
||||
|
||||
blitz::TinyVector<double, 3> v_perp =
|
||||
perpendicularNormalVector(cartesianB_values);
|
||||
|
||||
blitz::TinyVector<double, 3> v_direction = pitchAngle
|
||||
* cartesianB_values/Bmagnitude
|
||||
+ std::sqrt(1 - pitchAngle*pitchAngle)
|
||||
* kinematic::rotateVector(v_perp, cartesianB_values, theta);
|
||||
|
||||
return CartesianVector(v_direction * vMagnitude);
|
||||
}
|
||||
Reference in New Issue
Block a user