10 Commits
28 changed files with 250 additions and 64 deletions
+20
View File
@@ -70,6 +70,26 @@ E.g. "scattering_angle_example.json" shows the four different types of
scattering angle distributions that can be used in the code and how they are to be
structured in a working parameter file.
INPUT OF THE SIMULATION (HDF5 files):
For several groups in the JSON input file it is possible to read data from an external
HDF5 file, these groups are those that specify a Vector Field, Function or a Scattering Angle Distribution.
For the Scattering Angle Distribution it is necessary that the HDF5 files contain the
three objects "energies(eV)", "angles(rad)" and "cross_sections(m-2)". The first two
both have to be one dimensional arrays, containing the energies in eV and angles in rad
where the cross sections are defined respectivley. The thrid key has to contain a
two-dimensional array containing the actual values of the cross section in m^2, with the
first dimension being the energy and the second dimension being the angle.
In case of the Vector Field or the Function the structure of the input HDF5 file
is not as rigid, since the keys to the specific objects in the file have to be provided
in the JSON object.
The necessary structure in the JSON file for these two types types
of objects can either be found in the provided example JSON files or in the comments
in the corresponding generator files (i.e. "include/generators/vector_field_generator.h"
and "include/generators/function_generator.h").
NOTES:
Kommentare in den files: position_binning.*, current_collector.*, kinematic.*, sim_constants.h, mover.*, simulation_output.*, functions.*, injector_generator.h, ionization.h, recombination.cpp und species_generator überprüfen lassen
+13
View File
@@ -41,6 +41,13 @@ class Coordinate {
// return the value of the stored coordinate transformed to Cylinder space
virtual blitz::TinyVector<double, 3> cylinderEntries() const = 0;
// return cos(phi) with phi the second variable of the coordinate in cylinder
// coordinates
virtual double cosAzimuth() const = 0;
// return cos(phi) with phi the second variable of the coordinate in cylinder
// coordinates
virtual double sinAzimuth() const = 0;
// add the values of the parameter coordinate to the value stored in this variable
virtual void add(const Coordinate& coordinate) = 0;
};
@@ -58,6 +65,9 @@ class CartesianCoordinate : public Coordinate {
// return the value of the stored coordinate transformed to Cylider space
blitz::TinyVector<double, 3> cylinderEntries() const;
double cosAzimuth() const;
double sinAzimuth() const;
// add the values of the parameter coordinate to the value stored in this variable
void add(const Coordinate& coordinate);
@@ -77,6 +87,9 @@ class CylinderCoordinate : public Coordinate {
// return the value of the stored coordinate transformed to Cylinder space
blitz::TinyVector<double, 3> cylinderEntries() const;
double cosAzimuth() const;
double sinAzimuth() const;
// add the values of the parameter coordinate to the value stored in this variable
void add(const Coordinate& coordinate);
+3
View File
@@ -14,6 +14,9 @@ class DriftVelocity {
// returns the drift velocity value at the Coordinate position as a CartesianVector
CartesianVector driftVelocity(const Coordinate& position);
// overload using both the cartesian and cylinder coordinate version of the position
CartesianVector driftVelocity(const CartesianCoordinate& cartpos,
const CylinderCoordinate& cylpos);
private:
std::shared_ptr<VectorField> drift_velocity_;
+2 -1
View File
@@ -102,7 +102,8 @@ blitz::TinyVector<double, 3> parallelVector(
const blitz::TinyVector<double, 3>& direction);
// rotate vector around rotation_axis about the angle angle
// (vectors cartesian)
// (vectors cartesian) according to the right hand rule
// using Rogrigues' formula
blitz::TinyVector<double, 3> rotateVector(
const blitz::TinyVector<double, 3>& vector,
const blitz::TinyVector<double, 3>& rotation_axis,
+3
View File
@@ -35,9 +35,12 @@ class BorisMover : public Mover {
// single update step of the Boris push algorithm
// updates moved_distance by the distance the particle moved during the update step
// the electric_field and magnetic_field TinyVectors have to contain the electric and
// magnetic fields in Cartesian coordinates
void movementStep(particle::Particle* particle,
const blitz::TinyVector<double, 3>& electric_field,
const blitz::TinyVector<double, 3>& magnetic_field,
const double timestep,
double& moved_distance) const;
};
+4 -1
View File
@@ -19,8 +19,10 @@ class Particle {
// set the position of the particle to the provided Coordinate new_position
void position(const Coordinate& new_position);
// return the position of the particle as a CartesianVector
// return the position of the particle as a CartesianCoordinate
CartesianCoordinate position() const;
// return the cylinder position of the particle
CylinderCoordinate cylinderPosition() const;
// set the velocity of the particle to the provided CartesianVector new_velocity
void velocity(const CartesianVector& new_velocity);
@@ -77,6 +79,7 @@ class Particle {
private:
CartesianVector velocity_;
CartesianCoordinate position_;
CylinderCoordinate position_cyl_;
double time_alive_s_;
double time_in_bin_s_;
+3 -1
View File
@@ -45,8 +45,10 @@ LIBS += $(HDF5P_LIBRARIES)
CXXFLAGS += $(JANSSON_INCLUDES)
LIBS += $(JANSSON_LIBRARIES)
CXXFLAGS += -g
ifeq ($(DO_DEBUGGING),true)
CXXFLAGS += -ftemplate-depth-30 -g -DBZ_DEBUG
CXXFLAGS += -ftemplate-depth-30 #-DBZ_DEBUG
CXXFLAGS += -Ddebug
CXXFLAGS += -Ddebug_level$(DEBUG_LEVEL)
endif
@@ -426,6 +426,7 @@
"clustering": {
"Type": "Clustering",
"Target": "TritiumGas",
"ClusteringType": "radiative",
"Product": "T3+",
"CrossSection": {
"PredefinedFunction": "T2pT2_clustering_janev"
@@ -521,6 +522,7 @@
"clustering1": {
"Type": "Clustering",
"Target": "TritiumGas",
"ClusteringType": "radiative",
"Product": "T3+",
"CrossSection": {
"PredefinedFunction": "TpT2_clustering_radiative_ascendion_pasil"
@@ -529,6 +531,7 @@
"clustering2": {
"Type": "Clustering",
"Target": "TritiumGas",
"ClusteringType": "tertiary",
"Product": "T3+",
"CrossSection": {
"PredefinedFunction": "TpT2_clustering_tertiary_ascendion_pasil"
@@ -753,7 +756,7 @@
}
},
"Activity": {
"value": 1E14,
"value": 3.7e9,
"unit": "Bq"
}
},
+27
View File
@@ -27,6 +27,9 @@ void SimulationOutput::addDeletionLoggerOutput(OutputTask task) {
void SimulationOutput::writeMetaData(
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species) {
if (MpiCommunication::mpi_rank == 0) {
// write number of processes that have been used in the simulation
writer.write(MpiCommunication::mpiSize(), "/NumberProcesses");
for (auto& pair : species) {
writeMetaData(pair.second.get());
}
@@ -48,7 +51,9 @@ void SimulationOutput::writeSimulationData(
int cpu_sync,
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species) {
if (MpiCommunication::mpi_rank == 0) {
#if defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_2("Write density field data.");
#endif
for (auto& task : tasks_density_fields_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
@@ -56,7 +61,9 @@ void SimulationOutput::writeSimulationData(
specie_path, cpu_sync, task.overwrite_last);
}
}
#if defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_2("Write current collector data.");
#endif
for (auto& task : tasks_current_collector_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
@@ -64,7 +71,9 @@ void SimulationOutput::writeSimulationData(
specie_path, cpu_sync, task.overwrite_last);
}
}
#if defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_2("Write deletion logger data.");
#endif
for (auto& task : tasks_deletion_logger_) {
if (cpu_sync % task.intervall == 0) {
std::string specie_path = "/" + task.specie_name;
@@ -85,15 +94,25 @@ void SimulationOutput::writeSimulationData(DynamicDensityField* density_field,
}
std::string path = species_path + "/DensityField/SimulationData/" + sync_path;
#if defined(debug_level3)
DEBUG_LEVEL_3("Write spectrum.");
#endif
writeSpectrum(density_field, path);
#if defined(debug_level3)
DEBUG_LEVEL_3("Write density.");
#endif
writeDensity(density_field, path);
#if defined(debug_level3)
DEBUG_LEVEL_3("Write time in bin.");
#endif
writeTimeInBin(density_field, path);
#if defined(debug_level3)
DEBUG_LEVEL_3("Write deleted particles.");
#endif
writeDeletedParticles(density_field, path);
#if defined(debug_level3)
DEBUG_LEVEL_3("Write physical time.");
#endif
writePhysicalTime(density_field, path);
}
@@ -107,11 +126,17 @@ void SimulationOutput::writeSimulationData(CurrentCollector* current_collector,
}
std::string path =
species_path + "/CurrentCollector/SimulationData/" + sync_path;
#if defined(debug_level3)
DEBUG_LEVEL_3("Write current crossings.");
#endif
writeCurrentCrossings(current_collector, path);
#if defined(debug_level3)
DEBUG_LEVEL_3("Write current.");
#endif
writeCurrent(current_collector, path);
#if defined(debug_level3)
DEBUG_LEVEL_3("Write physical time.");
#endif
writePhysicalTime(current_collector, path);
}
@@ -124,7 +149,9 @@ void SimulationOutput::writeSimulationData(DeletionLogger* logger,
sync_path = "LastSyncPeriod";
}
std::string path = species_path + "/DeletionLogger/" + sync_path;
#if defined(debug_level3)
DEBUG_LEVEL_3("Write number of deletions.");
#endif
writeNumDeletions(logger, path);
}
+2 -1
View File
@@ -204,7 +204,8 @@ void addInteractions(
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
new interaction::ClusterFormationTertiary(cross_section, target, product)));
} else {
ERROR(clustering_type + ": no known, choose either 'radiative' or 'tertiary'.");
ERROR("ClusteringType " + clustering_type +
": not known, choose either 'radiative' or 'tertiary'.");
}
} else if (type == "ChargeExchange") {
DEBUG_LEVEL_2("Adding interactions: ChargeExchange");
+4 -2
View File
@@ -13,13 +13,15 @@ ChargeExchange::ChargeExchange(std::function<double(double)> cross_section,
InteractionOutput ChargeExchange::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#if defined(debug_level3)
DEBUG_LEVEL_3("Perform charge exchange.");
#endif
const auto x_impact = particle.position();
// draw velocity of the target specie
const blitz::TinyVector<double, 3> v_target =
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
target_->velocityDistibution()
target_->driftVelocity()->driftVelocity(x_impact, particle.cylinderPosition())
.cartesianEntries() + target_->velocityDistibution()
->rollVelocity(x_impact, generator->engine())
.cartesianEntries();
+4 -2
View File
@@ -18,11 +18,13 @@ ClusterFormation::ClusterFormation(
InteractionOutput ClusterFormation::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#if defined(debug_level3)
DEBUG_LEVEL_3("Perform cluster formation.");
#endif
const auto x_impact = particle.position();
const blitz::TinyVector<double, 3> v_target =
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
target_->velocityDistibution()
target_->driftVelocity()->driftVelocity(x_impact, particle.cylinderPosition())
.cartesianEntries() + target_->velocityDistibution()
->rollVelocity(x_impact, generator->engine())
.cartesianEntries();
// kinetic energy of the target particle
+4 -2
View File
@@ -18,15 +18,17 @@ ElasticScattering::ElasticScattering(
InteractionOutput ElasticScattering::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#if defined(debug_level3)
DEBUG_LEVEL_3("Perform elastic scattering.");
#endif
// get the information of the incident particle
const blitz::TinyVector<double, 3> v_impact =
particle.velocity().cartesianEntries();
const auto x_impact = particle.position();
// draw the velocity of the target particle
const blitz::TinyVector<double, 3> v_target =
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
target_->velocityDistibution()
target_->driftVelocity()->driftVelocity(x_impact, particle.cylinderPosition())
.cartesianEntries() + target_->velocityDistibution()
->rollVelocity(x_impact, generator->engine())
.cartesianEntries();
+3 -1
View File
@@ -18,7 +18,9 @@ Excitation::Excitation(std::function<double(double)> cross_section,
InteractionOutput Excitation::performInteraction(particle::Particle& particle,
RandomNumbers* generator) {
#if defined(debug_level3)
DEBUG_LEVEL_3("Perform excitation.");
#endif
const blitz::TinyVector<double, 3> v_impact =
particle.velocity().cartesianEntries();
const blitz::TinyVector<double, 3> n_impact =
@@ -26,7 +28,7 @@ InteractionOutput Excitation::performInteraction(particle::Particle& particle,
const double E_kin = kinematic::kineticEnergy(v_impact, particle.mass_kg()) *
UnitConversion::JouleToeV;
// since the target is (usually) not tracked, only the energy of the energy of the
// since the target is (usually) not tracked, so only the energy of the
// electron changes
const double E_kin_new = E_kin - excitation_energy_eV_;
+2
View File
@@ -10,7 +10,9 @@ FreeMovement::FreeMovement()
InteractionOutput FreeMovement::performInteraction(particle::Particle& particle,
RandomNumbers* generator) {
#if defined(debug_level3)
DEBUG_LEVEL_3("Perform free movement.");
#endif
// do nothing
return InteractionOutput();
}
+4 -2
View File
@@ -29,7 +29,9 @@ ElectronIonization::ElectronIonization(
InteractionOutput ElectronIonization::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#if defined(debug_level3)
DEBUG_LEVEL_3("Perform ionization.");
#endif
const blitz::TinyVector<double, 3> v_impact =
particle.velocity().cartesianEntries();
@@ -45,8 +47,8 @@ InteractionOutput ElectronIonization::performInteraction(
double E_impact;
do {
v_target =
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
target_->velocityDistibution()
target_->driftVelocity()->driftVelocity(x_impact, particle.cylinderPosition())
.cartesianEntries() + target_->velocityDistibution()
->rollVelocity(x_impact, generator->engine())
.cartesianEntries();
+8 -5
View File
@@ -16,7 +16,9 @@ Recombination::Recombination(std::function<double(double)> cross_section,
InteractionOutput Recombination::performInteraction(
particle::Particle& particle,
RandomNumbers* generator) {
#if defined(debug_level3)
DEBUG_LEVEL_3("Perform recombination.");
#endif
std::vector<double> macroscopic_bin_cross_sections_m;
const int number_energy_bins = recombination_target_->dynamicDensityField()
@@ -28,7 +30,7 @@ InteractionOutput Recombination::performInteraction(
if(recombination_target_->type() == species::ImplementedSpecies::electron) {
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
macroscopic_bin_cross_sections_m.push_back(
macroscopicCrossSection(particle.position(), bin));
macroscopicCrossSection(particle.cylinderPosition(), bin));
}
} else {
const blitz::TinyVector<double, 3> v_particle =
@@ -43,7 +45,8 @@ InteractionOutput Recombination::performInteraction(
// drift velocity of the target particle
const blitz::TinyVector<double, 3> v_partner =
recombination_target_->driftVelocity()
->driftVelocity(particle.position()).cartesianEntries();
->driftVelocity(particle.position(),
particle.cylinderPosition()).cartesianEntries();
// velocity of incident particle in the drift frame of the target species
const blitz::TinyVector<double, 3> velocity_target_fixed =
@@ -61,9 +64,9 @@ InteractionOutput Recombination::performInteraction(
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
energy_eV_bin_center = (energyBinBorders[bin] + energyBinBorders[bin+1])/2.;
macroscopic_bin_cross_sections_m.push_back(
microscopicCrossSection(kinetic_energy_eV, particle.position()) *
microscopicCrossSection(kinetic_energy_eV, particle.cylinderPosition()) *
recombination_target_->dynamicDensityField()
->density(particle.position(), energy_eV_bin_center));
->density(particle.cylinderPosition(), energy_eV_bin_center));
}
}
@@ -108,7 +111,7 @@ double Recombination::macroscopicCrossSection(particle::Particle& particle) {
const int numBins = recombination_target_->dynamicDensityField()->
energyBinning()->binIndexMax();
double macroscopic_cross_section = 0.;
const auto position = particle.position();
const auto position = particle.cylinderPosition();
for (int bin = 0; bin < numBins - 1; ++bin) {
macroscopic_cross_section += macroscopicCrossSection(position, bin);
}
+26 -4
View File
@@ -56,6 +56,18 @@ blitz::TinyVector<double, 3> CartesianCoordinate::cartesianEntries() const {
return cartesian_position;
}
double CartesianCoordinate::cosAzimuth() const {
double rad = std::sqrt(cartesian_position(0)*cartesian_position(0) +
cartesian_position(1)*cartesian_position(1));
return cartesian_position(0)/rad;
}
double CartesianCoordinate::sinAzimuth() const {
double rad = std::sqrt(cartesian_position(0)*cartesian_position(0) +
cartesian_position(1)*cartesian_position(1));
return cartesian_position(1)/rad;
}
blitz::TinyVector<double, 3> CartesianCoordinate::cylinderEntries() const {
const double radius = std::sqrt(std::pow(cartesian_position(0), 2) +
std::pow(cartesian_position(1), 2));
@@ -104,6 +116,14 @@ void CylinderCoordinate::limitPhi() {
}
}
double CylinderCoordinate::cosAzimuth() const {
return std::cos(cylinder_position(1));
}
double CylinderCoordinate::sinAzimuth() const {
return std::sin(cylinder_position(1));
}
void CylinderCoordinate::add(const Coordinate& coordinate) {
const blitz::TinyVector<double, 3> new_cart_position =
cartesianEntries() + coordinate.cartesianEntries();
@@ -134,12 +154,14 @@ CylinderVector CylinderVector::operator+(const CylinderVector& vector) {
blitz::TinyVector<double, 3> CylinderVector::cartesianEntries(
const Coordinate& coordinate) const {
double sinPhi = coordinate.sinAzimuth();
double cosPhi = coordinate.cosAzimuth();
const double A_x =
std::cos(coordinate.cylinderEntries()(1)) * cylinder_vector(0) -
std::sin(coordinate.cylinderEntries()(1)) * cylinder_vector(1);
cosPhi * cylinder_vector(0) -
sinPhi * cylinder_vector(1);
const double A_y =
std::sin(coordinate.cylinderEntries()(1)) * cylinder_vector(0) +
std::cos(coordinate.cylinderEntries()(1)) * cylinder_vector(1);
sinPhi * cylinder_vector(0) +
cosPhi * cylinder_vector(1);
const double A_z = cylinder_vector(2);
return blitz::TinyVector<double, 3>(A_x, A_y, A_z);
}
+1 -1
View File
@@ -133,7 +133,7 @@ void CpuSynchronizer::synchronize(
tracked_species) {
MPI_Barrier(MPI_COMM_WORLD);
auto it = tracked_species.begin();
DEBUG_LEVEL_3("Timer Synchronization.");
// DEBUG_LEVEL_3("Timer Synchronization.");
synchronize(it->second->dynamicDensityField()->timer_.get(),
it->second->lastSyncDensityField()->timer_.get());
+1 -1
View File
@@ -130,7 +130,7 @@ void CurrentCollector::collect(particle::Particle* particle,
blitz::TinyVector<int, 3> bin_old =
position_binning_.bin(old_position.cylinderEntries());
blitz::TinyVector<int, 3> bin_new =
position_binning_.bin(particle->position().cylinderEntries());
position_binning_.bin(particle->cylinderPosition().cylinderEntries());
collectRadialMovement(bin_old, bin_new);
collectLongitudinalMovement(bin_old, bin_new);
+5
View File
@@ -8,3 +8,8 @@ DriftVelocity::DriftVelocity(std::shared_ptr<VectorField> drift_velocity)
CartesianVector DriftVelocity::driftVelocity(const Coordinate& position) {
return CartesianVector(drift_velocity_->value(position), position);
}
CartesianVector DriftVelocity::driftVelocity(const CartesianCoordinate& cartpos,
const CylinderCoordinate& cylpos) {
return CartesianVector(drift_velocity_->value(cylpos), cartpos);
}
+2
View File
@@ -45,8 +45,10 @@ std::vector<particle::Particle> Injector::rollNewParticles(
// particles are assumed to be created by a decay process
// therefore the resulting particles all start out at the same position
CylinderCoordinate position = position_distribution_->rollPosition(engine);
#if defined(debug_level3)
DEBUG_LEVEL_3("Injected z position: " +
std::to_string(position.cylinderEntries()(2)));
#endif
std::vector<particle::Particle> new_particles;
// draw the velocity of all particles to be injected an append them to the new_particles vector
for (auto& injector_info : injector_infos_) {
+3 -2
View File
@@ -32,7 +32,7 @@ Interaction::Interaction(std::function<double(double)> cross_section,
: cross_section_(cross_section), target_(target) {}
double Interaction::macroscopicCrossSection(particle::Particle& particle) {
const auto x_particle = particle.position();
const auto x_particle = particle.cylinderPosition();
const blitz::TinyVector<double, 3> v_particle =
particle.velocity().cartesianEntries();
if(!target_->driftVelocity()) {
@@ -40,7 +40,8 @@ double Interaction::macroscopicCrossSection(particle::Particle& particle) {
}
const blitz::TinyVector<double, 3> v_partner =
target_->driftVelocity()->driftVelocity(x_particle).cartesianEntries();
target_->driftVelocity()->driftVelocity(x_particle, particle.cylinderPosition())
.cartesianEntries();
const blitz::TinyVector<double, 3> velocity_target_fixed =
kinematic::velocityTargetFixed(v_particle, v_partner, particle.mass_kg(),
+40 -24
View File
@@ -24,6 +24,7 @@ void BorisMover::move(particle::Particle* particle,
ElectricField* electric_field,
MagneticField* magnetic_field) {
double leftover_distance = mfp_m;
double timestep = 0;
auto old_position = particle->position();
double old_kinetic_energy = particle->kineticEnergy_eV();
@@ -44,6 +45,11 @@ void BorisMover::move(particle::Particle* particle,
old_position = particle->position();
old_kinetic_energy = particle->kineticEnergy_eV();
double old_velocity = particle->absoluteVelocity();
timestep = std::min(maximal_time_step_s_,
(leftover_distance + SimConstants::random_lower_limit)/old_velocity);
double moved_distance = 0.;
const blitz::TinyVector<double, 3> E =
@@ -51,9 +57,9 @@ void BorisMover::move(particle::Particle* particle,
const blitz::TinyVector<double, 3> B =
magnetic_field->value(old_position).cartesianEntries(old_position);
movementStep(particle, E, B, moved_distance);
particle->increaseTimeAlive(maximal_time_step_s_);
particle->increaseTimeInBin(maximal_time_step_s_);
movementStep(particle, E, B, timestep, moved_distance);
particle->increaseTimeAlive(timestep);
particle->increaseTimeInBin(timestep);
auto new_position = particle->position();
@@ -81,6 +87,7 @@ void BorisMover::movementStep(
particle::Particle* particle,
const blitz::TinyVector<double, 3>& electric_field,
const blitz::TinyVector<double, 3>& magnetic_field,
const double timestep,
double& moved_distance) const {
const blitz::TinyVector<double, 3> v =
particle->velocity().cartesianEntries();
@@ -88,21 +95,21 @@ void BorisMover::movementStep(
const double q = particle->charge_C();
const double u_minus_x =
v(0) + (q * electric_field(0) * maximal_time_step_s_) / (2. * m);
v(0) + (q * electric_field(0) * timestep) / (2. * m);
const double u_minus_y =
v(1) + (q * electric_field(1) * maximal_time_step_s_) / (2. * m);
v(1) + (q * electric_field(1) * timestep) / (2. * m);
const double u_minus_z =
v(2) + (q * electric_field(2) * maximal_time_step_s_) / (2. * m);
v(2) + (q * electric_field(2) * timestep) / (2. * m);
const double gamma = kinematic::relativisticGamma(
blitz::TinyVector<double, 3>(u_minus_x, u_minus_y, u_minus_z));
const double temp_1_x =
(q * magnetic_field(0) * maximal_time_step_s_) / (2 * m * gamma);
(q * magnetic_field(0) * timestep) / (2 * m * gamma);
const double temp_1_y =
(q * magnetic_field(1) * maximal_time_step_s_) / (2 * m * gamma);
(q * magnetic_field(1) * timestep) / (2 * m * gamma);
const double temp_1_z =
(q * magnetic_field(2) * maximal_time_step_s_) / (2 * m * gamma);
(q * magnetic_field(2) * timestep) / (2 * m * gamma);
const double u_prime_x =
u_minus_x + (u_minus_y * temp_1_z - u_minus_z * temp_1_y);
@@ -129,16 +136,16 @@ void BorisMover::movementStep(
u_minus_z + (u_prime_x * temp_2_y - u_prime_y * temp_2_x);
const double u_new_x =
u_plus_x + (q * electric_field(0) * maximal_time_step_s_) / (2. * m);
u_plus_x + (q * electric_field(0) * timestep) / (2. * m);
const double u_new_y =
u_plus_y + (q * electric_field(1) * maximal_time_step_s_) / (2. * m);
u_plus_y + (q * electric_field(1) * timestep) / (2. * m);
const double u_new_z =
u_plus_z + (q * electric_field(2) * maximal_time_step_s_) / (2. * m);
u_plus_z + (q * electric_field(2) * timestep) / (2. * m);
const blitz::TinyVector<double, 3> u_new(u_new_x, u_new_y, u_new_z);
particle->velocity(CartesianVector(u_new));
const CartesianCoordinate distance(u_new * maximal_time_step_s_);
const CartesianCoordinate distance(u_new * timestep);
particle->move(distance);
moved_distance += std::sqrt(
@@ -158,7 +165,8 @@ void DriftMover::move(particle::Particle* particle,
MagneticField* magnetic_field) {
double leftover_distance = mfp_m;
auto old_position = particle->position();
CartesianCoordinate old_position = particle->position();
CylinderCoordinate old_position_cyl = particle->cylinderPosition();
auto old_velocity = particle->velocity();
double old_kinetic_energy = particle->kineticEnergy_eV();
@@ -174,15 +182,18 @@ void DriftMover::move(particle::Particle* particle,
!(changed_position_bin || changed_energy_bin || left_simulation_domain) &&
(leftover_distance > 0.) && !(died_in_bin)) {
old_position = particle->position();
old_position_cyl = particle->cylinderPosition();
old_velocity = particle->velocity();
old_kinetic_energy = particle->kineticEnergy_eV();
const blitz::TinyVector<double, 3> E =
electric_field->value(old_position).cartesianEntries(old_position);
electric_field->value(particle->cylinderPosition())
.cartesianEntries(old_position);
const blitz::TinyVector<double, 3> B =
magnetic_field->value(old_position).cartesianEntries(old_position);
magnetic_field->value(particle->cylinderPosition())
.cartesianEntries(old_position);
const double B_norm = kinematic::norm(B);
// calculate component of the velocity parallel to the magnetic field
@@ -202,8 +213,11 @@ void DriftMover::move(particle::Particle* particle,
const double stepsize = std::min(leftover_distance, maximal_distance_m_);
// guard against very large timesteps i.e. v ~ 0 -> timestep = Inf
// should be a very rare case
// only works if |v| >> |v_drift|
const double timestep = std::min(
stepsize / (v_parallel_norm + v_perp_norm + v_drift_norm),
stepsize / std::sqrt(v_parallel_norm * v_parallel_norm +
v_perp_norm * v_perp_norm +
v_drift_norm * v_drift_norm),
max_time_alive);
const blitz::TinyVector<double, 3> movement_parallel =
@@ -222,16 +236,18 @@ void DriftMover::move(particle::Particle* particle,
const double gyro_radius = particle->mass_kg() * v_perp_norm /
(B_norm * particle->charge_C());
// direction of the magnetic part of the Lorentz force for a positive charge
const blitz::TinyVector<double, 3> velocity_normal =
(-1) * blitz::cross(B, v_perp);
blitz::cross(v_perp, B);
// calculate the vector pointing from the gyro center to the particle position
const blitz::TinyVector<double, 3> offset_to_gyro_center =
gyro_radius * velocity_normal / kinematic::norm(velocity_normal);
-gyro_radius * velocity_normal / kinematic::norm(velocity_normal);
const double gyro_frequency =
particle->charge_C() * B_norm / particle->mass_kg();
const double total_rotation_angle = gyro_frequency * timestep;
// negative charges gyrate acc to right hand rule (wrt the magnetic field direction)
const double total_rotation_angle = -gyro_frequency * timestep;
// move the particle around the gyro center
const blitz::TinyVector<double, 3> movement_around_gyro_center =
kinematic::rotateVector(offset_to_gyro_center, B,
@@ -254,14 +270,14 @@ void DriftMover::move(particle::Particle* particle,
particle->increaseTimeAlive(timestep);
particle->increaseTimeInBin(timestep);
const auto new_position = particle->position();
// const auto new_position = particle->position();
died_in_bin =
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
changed_position_bin =
particle->specie()->dynamicDensityField()->changedPositionBin(
old_position, new_position);
old_position_cyl, particle->cylinderPosition());
changed_energy_bin =
particle->specie()->dynamicDensityField()->changedEnergyBin(
@@ -274,9 +290,9 @@ void DriftMover::move(particle::Particle* particle,
}
particle->specie()->dynamicDensityField()->logMovement(
old_position, old_kinetic_energy, particle->timeInBin());
old_position_cyl, old_kinetic_energy, particle->timeInBin());
particle->resetTimeInBin();
particle->specie()->currentCollector()->collect(particle, old_position);
particle->specie()->currentCollector()->collect(particle, old_position_cyl);
}
blitz::TinyVector<double, 3> DriftMover::driftVelocity(
+7
View File
@@ -9,6 +9,7 @@ Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
const Vector& velocity)
: specie_(specie),
position_(position),
position_cyl_(position),
velocity_(velocity, position),
id_(this->last_id_),
time_alive_s_(0.),
@@ -54,8 +55,14 @@ CartesianCoordinate Particle::position() const {
return position_;
}
CylinderCoordinate Particle::cylinderPosition() const {
return position_cyl_;
}
void Particle::move(const Coordinate& distance) {
position_.add(distance);
// update the cylinder entries only after movement
position_cyl_ = CylinderCoordinate(position_);
}
double Particle::kineticEnergy_eV() const {
+48 -8
View File
@@ -38,29 +38,43 @@ void Simulation::init(Parameter& parameter) {
magnetic_field_ = generator::magneticField(parameter);
electric_field_ = generator::electricField(parameter);
#ifdef debug
DEBUG_LEVEL_0("Creating species.");
#endif
generator::SpeciesBuilder builder(parameter);
tracked_species_ = builder.trackedSpecies();
background_species_ = builder.backgroundSpecies();
timer_ = builder.timer();
#ifdef debug
DEBUG_LEVEL_0("Creating injector.");
#endif
injector_ = generator::buildInjector(tracked_species_, background_species_,
parameter);
#ifdef debug
DEBUG_LEVEL_0("Init random numbers.");
#endif
random_ = generator::buildRandomNumbers(parameter);
#ifdef debug
DEBUG_LEVEL_0("Init output.");
#endif
output_ = generator::buildSimulationOutput(
parameter.jsonObjectFromBase({"Output"}), tracked_species_);
#ifdef debug
DEBUG_LEVEL_0("Output meta data.");
#endif
output_->writeMetaData(tracked_species_);
#ifdef debug
DEBUG_LEVEL_0("Init cpu synchronizer.");
#endif
cpu_synchronizer_ = std::make_shared<CpuSynchronizer>();
#if defined(debug_level3)
DEBUG_LEVEL_3("Init done.");
#endif
}
int eventsThisCpu(int events_all_cpus) {
@@ -105,7 +119,7 @@ void Simulation::start() {
if((events_this_cpu % event_stride == 0) &&
(total_simulated_events % MpiCommunication::mpiSize()
<= MpiCommunication::mpiRank())) {
DEBUG_LEVEL_3("empty loop");
// DEBUG_LEVEL_3("empty loop");
empty_loop = true;
}
}
@@ -114,7 +128,7 @@ void Simulation::start() {
// special case of unbalanced cpu load, with a part of the cpus having one cycle
// that has no events, while the rest of the cpus have a single event (questionable if needed)
if(leftover_events == 0 && empty_loop) {
DEBUG_LEVEL_3("empty loop looped");
// DEBUG_LEVEL_3("empty loop looped");
empty_loop = false;
}
@@ -123,7 +137,9 @@ void Simulation::start() {
std::to_string(leftover_events));
processEvents(evenst_of_cycle);
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_1("Leftover events: " + std::to_string(leftover_events));
#endif
leftover_events -= evenst_of_cycle;
SIM_INFO("Cpu sync.");
@@ -132,9 +148,9 @@ void Simulation::start() {
num_cpu_syncs += 1;
SimulationTimer::eventStopPoint(std::string("CpuSync"));
SIM_INFO("Poisson step.");
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
// SIM_INFO("Poisson step.");
// SimulationTimer::eventStartPoint(std::string("PoissonStep"));
// SimulationTimer::eventStopPoint(std::string("PoissonStep"));
SIM_INFO("Perform output.");
SimulationTimer::eventStartPoint(std::string("Output"));
@@ -148,27 +164,37 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
}
void Simulation::processEvents(int events) {
#ifdef debug
DEBUG_LEVEL_0("Processing events.");
#endif
std::vector<particle::Particle> particle_queue;
particle_queue.reserve(100);
int current_event = 0;
while ((current_event < events) || (!particle_queue.empty())) {
#if defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
#endif
// if the particle queue is empty a new beta decay event is started
if (particle_queue.empty()) {
current_event += 1;
#if defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_2("Inject particles to queue.");
#endif
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
// draw new beta decay particles
std::vector<particle::Particle> new_particles =
determineInjectedParticles(random_.get());
SimulationTimer::eventStopPoint(std::string("ParticleInjection"));
#if defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_2("Injected particles to queue.");
#endif
particle_queue.insert(particle_queue.end(), new_particles.begin(),
new_particles.end());
}
#if defined(debug_level2) || defined(debug_level3)
DEBUG_LEVEL_2("Particles in queue: " + std::to_string(particle_queue.size()));
#endif
// choose a random particle from the particle queue to be processed
const int particle_number =
particleNumberFromQueue(particle_queue.size(), random_.get());
@@ -185,9 +211,11 @@ void Simulation::processEvents(int events) {
void Simulation::processUntilTermination(
particle::Particle& particle,
std::vector<particle::Particle>& particle_queue) {
#ifdef debug_level3
DEBUG_LEVEL_3("Process particle until termination");
#endif
while (particle.specie()->terminator()->isAlive(&particle)) {
auto old_position = particle.position();
CylinderCoordinate old_position = particle.cylinderPosition();
double old_energy = particle.kineticEnergy_eV();
std::vector<double> macroscopic_cross_sections_m;
@@ -205,8 +233,10 @@ void Simulation::processUntilTermination(
bool was_reflected = false;
if (particle.specie()->reflector()->needsReflectionBackToDomain(
&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Reflect particle.");
old_position = particle.position();
#endif
old_position = particle.cylinderPosition();
particle.specie()->reflector()->reflectBackToDomain(&particle);
particle.specie()->currentCollector()->collect(&particle, old_position);
was_reflected = true;
@@ -214,7 +244,9 @@ void Simulation::processUntilTermination(
if (particle.specie()->terminator()->reachedMaxTimeAlive(
&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Terminate particle. Reached max time alive.");
#endif
if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(
particle.position(), DeletionType::max_time_alive);
@@ -222,11 +254,13 @@ void Simulation::processUntilTermination(
break;
} else if (particle.specie()->terminator()->leftSimulationDomain(
&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Terminate particle. Left simulation domain.");
std::stringstream output_ss;
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
output_ss << " (cart): " << particle.position().cartesianEntries();
DEBUG_LEVEL_3(output_ss.str());
#endif
if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(particle.position(),
DeletionType::wall);
@@ -235,10 +269,11 @@ void Simulation::processUntilTermination(
}
if (!(particle.specie()->dynamicDensityField()->changedPositionBin(
old_position, particle.position())) &&
old_position, particle.cylinderPosition())) &&
!(particle.specie()->dynamicDensityField()->changedEnergyBin(
old_energy, particle.kineticEnergy_eV())) &&
!was_reflected) {
#ifdef debug_level3
DEBUG_LEVEL_3("Perform interaction.");
DEBUG_LEVEL_3("Number of Interactions: " +
std::to_string(particle.interactionCounter()));
@@ -247,6 +282,7 @@ void Simulation::processUntilTermination(
std::stringstream output_ss;
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
DEBUG_LEVEL_3(output_ss.str());
#endif
SimulationTimer::eventStartPoint(std::string("Interaction"));
interaction::InteractionOutput output = interact(particle, random_.get(),
@@ -260,13 +296,17 @@ void Simulation::processUntilTermination(
}
if (output.deleteCurrentParticle()) {
#ifdef debug_level3
DEBUG_LEVEL_3(particle.specie()->name() + " removed due to interaction.");
#endif
break;
}
if (particle.specie()->terminator()->reachedMaxInteractions(&particle)) {
#ifdef debug_level3
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
+ ". Reached max interactions.");
#endif
if (particle.specie()->deletionLogger()) {
particle.specie()->deletionLogger()->logDeletion(
particle.position(), DeletionType::max_interactions);
+1 -1
View File
@@ -36,7 +36,7 @@ bool Terminator::reachedMaxTimeAlive(const particle::Particle* particle) const {
bool Terminator::leftSimulationDomain(
const particle::Particle* particle) const {
return !(geometry_->isInside(particle->position()));
return !(geometry_->isInside(particle->cylinderPosition()));
}
double Terminator::maxTimeAlive() const {
@@ -14,10 +14,12 @@ IsotropicDistribution::IsotropicDistribution(
blitz::TinyVector<double, 3> rollUnitVector(std::mt19937* engine) {
std::uniform_real_distribution<double> distribution(0.0, 1.0);
const double theta = distribution(*engine) * 2 * M_PI;
const double phi = distribution(*engine) * M_PI;
return blitz::TinyVector<double, 3>(std::cos(theta) * std::sin(phi),
std::sin(theta) * std::sin(phi),
std::cos(phi));
// const double phi = distribution(*engine) * M_PI;
const double cos_phi = (2*distribution(*engine) - 1);
const double sin_phi = std::sqrt(1 - cos_phi*cos_phi);
return blitz::TinyVector<double, 3>(std::cos(theta) * sin_phi,
std::sin(theta) * sin_phi,
cos_phi);
}
CartesianVector IsotropicDistribution::rollVelocity(std::mt19937* engine) {