Added Terminator type, which detects the crossing across two surfaces (very rudamentary check)
This commit is contained in:
@@ -5,22 +5,45 @@
|
|||||||
|
|
||||||
class Geometry;
|
class Geometry;
|
||||||
class DynamicDensityField;
|
class DynamicDensityField;
|
||||||
|
class Coordinate;
|
||||||
class Terminator {
|
class Terminator {
|
||||||
public:
|
public:
|
||||||
Terminator(long int max_interactions,
|
Terminator(long int max_interactions,
|
||||||
double max_time_alive,
|
double max_time_alive,
|
||||||
std::shared_ptr<Geometry> geometry);
|
std::shared_ptr<Geometry> geometry);
|
||||||
|
Terminator();
|
||||||
|
|
||||||
bool isAlive(const particle::Particle* particle) const;
|
virtual bool isAlive(const particle::Particle* particle) const;
|
||||||
bool leftSimulationDomain(const particle::Particle* particle) const;
|
virtual bool isAlive(const particle::Particle* particle,
|
||||||
bool reachedMaxInteractions(const particle::Particle* particle) const;
|
const Coordinate& old_pos) const;
|
||||||
bool reachedMaxTimeAlive(const particle::Particle* particle) const;
|
virtual bool leftSimulationDomain(const particle::Particle* particle) const;
|
||||||
double maxTimeAlive() const;
|
virtual bool leftSimulationDomain(const particle::Particle* particle,
|
||||||
|
const Coordinate& old_position) const;
|
||||||
|
virtual bool reachedMaxInteractions(const particle::Particle* particle) const;
|
||||||
|
virtual bool reachedMaxTimeAlive(const particle::Particle* particle) const;
|
||||||
|
virtual double maxTimeAlive() const;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
const long int max_interactions_;
|
const long int max_interactions_;
|
||||||
const double max_time_alive_;
|
const double max_time_alive_;
|
||||||
std::shared_ptr<Geometry> geometry_;
|
std::shared_ptr<Geometry> geometry_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TerminatorWithPlates : public Terminator {
|
||||||
|
public:
|
||||||
|
TerminatorWithPlates(long int max_interactions, double max_time_alive,
|
||||||
|
std::shared_ptr<Geometry> geometry,
|
||||||
|
double zpos1, double zpos2, double innerRadius1,
|
||||||
|
double innerRadius2, double outerRadius1,
|
||||||
|
double outerRadius2);
|
||||||
|
|
||||||
|
virtual bool leftSimulationDomain(const particle::Particle* particle) const;
|
||||||
|
virtual bool leftSimulationDomain(const particle::Particle* particle,
|
||||||
|
const Coordinate& old_position) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const double zpos1_, innerRadius1_, outerRadius1_;
|
||||||
|
const double zpos2_, innerRadius2_, outerRadius2_;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* TERMINATOR_H */
|
#endif /* TERMINATOR_H */
|
||||||
|
|||||||
@@ -8,22 +8,90 @@ std::shared_ptr<Terminator> buildTerminator(
|
|||||||
Parameter& parameter,
|
Parameter& parameter,
|
||||||
const json_path& path_to_terminator) {
|
const json_path& path_to_terminator) {
|
||||||
#ifdef debug_level2
|
#ifdef debug_level2
|
||||||
DEBUG_LEVEL_2("Creating terminator.");
|
DEBUG_LEVEL_2("Creating terminator.");
|
||||||
#endif
|
#endif
|
||||||
long int max_interactions = static_cast<long int>(parameter.doubleValue(
|
if (parameter.jsonObjectFromBase(
|
||||||
json_path_append(path_to_terminator, {"MaximumInteractions"})));
|
json_path_append(path_to_terminator, {"Cylinder"}))) {
|
||||||
double max_time_alive = parameter.doubleValue(
|
long int max_interactions = static_cast<long int>(parameter.doubleValue(
|
||||||
json_path_append(path_to_terminator, {"MaxTimeAlive", "value"}));
|
json_path_append(path_to_terminator, {"Cylinder", "MaximumInteractions"})));
|
||||||
|
double max_time_alive = parameter.doubleValue(
|
||||||
|
json_path_append(path_to_terminator, {"Cylinder", "MaxTimeAlive", "value"}));
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
|
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
|
||||||
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
|
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<Geometry> geometry = buildGeometryIncludingRedirection(
|
std::shared_ptr<Geometry> geometry = buildGeometryIncludingRedirection(
|
||||||
parameter, json_path_append(path_to_terminator, {"BoundaryGeometry"}));
|
parameter, json_path_append(path_to_terminator, {"Cylinder", "BoundaryGeometry"}));
|
||||||
|
|
||||||
return std::shared_ptr<Terminator>(
|
return std::shared_ptr<Terminator>(
|
||||||
new Terminator(max_interactions, max_time_alive, geometry));
|
new Terminator(max_interactions, max_time_alive, geometry));
|
||||||
|
|
||||||
|
} else if (parameter.jsonObjectFromBase(json_path_append(path_to_terminator,
|
||||||
|
{"CylinderWithPlates"}))) {
|
||||||
|
long int max_interactions = static_cast<long int>(parameter.doubleValue(
|
||||||
|
json_path_append(path_to_terminator, {"CylinderWithPlates", "MaximumInteractions"})));
|
||||||
|
double max_time_alive = parameter.doubleValue(
|
||||||
|
json_path_append(path_to_terminator, {"CylinderWithPlates", "MaxTimeAlive", "value"}));
|
||||||
|
#ifdef debug_level3
|
||||||
|
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
|
||||||
|
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::shared_ptr<Geometry> geometry = buildGeometryIncludingRedirection(
|
||||||
|
parameter, json_path_append(path_to_terminator, {"CylinderWithPlates", "BoundaryGeometry"}));
|
||||||
|
|
||||||
|
double zpos1 = json_read_length(
|
||||||
|
parameter.jsonObjectFromBase(
|
||||||
|
json_path_append(path_to_terminator,
|
||||||
|
{"CylinderWithPlates", "Plate1", "zPosition"})));
|
||||||
|
|
||||||
|
double rInner1 = json_read_length(
|
||||||
|
parameter.jsonObjectFromBase(
|
||||||
|
json_path_append(path_to_terminator,
|
||||||
|
{"CylinderWithPlates", "Plate1", "innerRadius"})));
|
||||||
|
|
||||||
|
double rOuter1 = json_read_length(
|
||||||
|
parameter.jsonObjectFromBase(
|
||||||
|
json_path_append(path_to_terminator,
|
||||||
|
{"CylinderWithPlates", "Plate1", "outerRadius"})));
|
||||||
|
|
||||||
|
double zpos2 = json_read_length(
|
||||||
|
parameter.jsonObjectFromBase(
|
||||||
|
json_path_append(path_to_terminator,
|
||||||
|
{"CylinderWithPlates", "Plate2", "zPosition"})));
|
||||||
|
|
||||||
|
double rInner2 = json_read_length(
|
||||||
|
parameter.jsonObjectFromBase(
|
||||||
|
json_path_append(path_to_terminator,
|
||||||
|
{"CylinderWithPlates", "Plate2", "innerRadius"})));
|
||||||
|
|
||||||
|
double rOuter2 = json_read_length(
|
||||||
|
parameter.jsonObjectFromBase(
|
||||||
|
json_path_append(path_to_terminator,
|
||||||
|
{"CylinderWithPlates", "Plate2", "outerRadius"})));
|
||||||
|
|
||||||
|
if(MpiCommunication::mpi_rank == 0) {
|
||||||
|
std::stringstream out;
|
||||||
|
out << "Specifications of Plate 1:\n";
|
||||||
|
out << "\tz position: " << zpos1 << " m\n\t";
|
||||||
|
out << "inner radius: " << rInner1 << " m\n\t";
|
||||||
|
out << "outer radius: " << rOuter1 << " m\n";
|
||||||
|
out << "Specifications of Plate 2:\n";
|
||||||
|
out << "\tz position: " << zpos2 << " m\n\t";
|
||||||
|
out << "inner radius: " << rInner2 << " m\n\t";
|
||||||
|
out << "outer radius: " << rOuter2 << " m\n";
|
||||||
|
SIM_INFO(out.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::shared_ptr<TerminatorWithPlates>(
|
||||||
|
new TerminatorWithPlates(max_interactions, max_time_alive, geometry,
|
||||||
|
zpos1, zpos2, rInner1, rInner2, rOuter1, rOuter2));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ERROR("Unknown Terminator type");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}; // namespace generator
|
}; // namespace generator
|
||||||
@@ -116,7 +116,7 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
old_kinetic_energy, particle->kineticEnergy_eV());
|
old_kinetic_energy, particle->kineticEnergy_eV());
|
||||||
|
|
||||||
left_simulation_domain =
|
left_simulation_domain =
|
||||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
particle->specie()->terminator()->leftSimulationDomain(particle, old_position_cyl);
|
||||||
|
|
||||||
died_in_bin =
|
died_in_bin =
|
||||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||||
@@ -491,7 +491,7 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
left_simulation_domain =
|
left_simulation_domain =
|
||||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
particle->specie()->terminator()->leftSimulationDomain(particle, old_position_cyl);
|
||||||
|
|
||||||
leftover_time -= timestep;
|
leftover_time -= timestep;
|
||||||
particle->reduceTimeUntilCollision(timestep);
|
particle->reduceTimeUntilCollision(timestep);
|
||||||
|
|||||||
@@ -376,9 +376,11 @@ void Simulation::processUntilTermination(particle::Particle& particle) {
|
|||||||
DEBUG_LEVEL_3("Process particle until termination");
|
DEBUG_LEVEL_3("Process particle until termination");
|
||||||
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
|
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
|
||||||
#endif
|
#endif
|
||||||
while (particle.specie()->terminator()->isAlive(&particle)) {
|
|
||||||
auto old_position = particle.cylinderPosition();
|
auto old_position = particle.cylinderPosition();
|
||||||
double old_energy = particle.kineticEnergy_eV();
|
double old_energy = particle.kineticEnergy_eV();
|
||||||
|
while (particle.specie()->terminator()->isAlive(&particle, old_position)) {
|
||||||
|
old_position = particle.cylinderPosition();
|
||||||
|
old_energy = particle.kineticEnergy_eV();
|
||||||
|
|
||||||
if(!particle.isNextInteractionValid()) {
|
if(!particle.isNextInteractionValid()) {
|
||||||
// DEBUG_LEVEL_1("Calculate time until collision");
|
// DEBUG_LEVEL_1("Calculate time until collision");
|
||||||
@@ -416,7 +418,7 @@ void Simulation::processUntilTermination(particle::Particle& particle) {
|
|||||||
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
||||||
&particle) &&
|
&particle) &&
|
||||||
!particle.specie()->terminator()->leftSimulationDomain(
|
!particle.specie()->terminator()->leftSimulationDomain(
|
||||||
&particle)) {
|
&particle, old_position)) {
|
||||||
// particle.invalidateNextInteraction();
|
// particle.invalidateNextInteraction();
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
|
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
|
||||||
@@ -443,7 +445,7 @@ void Simulation::processUntilTermination(particle::Particle& particle) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
||||||
&particle)) {
|
&particle, old_position)) {
|
||||||
#if defined(debug)
|
#if defined(debug)
|
||||||
DEBUG("Terminate particle " + particle.specie()->name()
|
DEBUG("Terminate particle " + particle.specie()->name()
|
||||||
+ ". Left simulation domain.");
|
+ ". Left simulation domain.");
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Terminator::Terminator(long int max_interactions,
|
|||||||
max_time_alive_(max_time_alive),
|
max_time_alive_(max_time_alive),
|
||||||
geometry_(geometry) {
|
geometry_(geometry) {
|
||||||
if (!geometry_) {
|
if (!geometry_) {
|
||||||
ERROR("No particle lives forever. Give a geometry to terminatior.\n");
|
ERROR("No particle lives forever. Give a geometry to terminator.\n");
|
||||||
}
|
}
|
||||||
ASSERT_POSITIVE(
|
ASSERT_POSITIVE(
|
||||||
&max_interactions_,
|
&max_interactions_,
|
||||||
@@ -27,6 +27,12 @@ bool Terminator::isAlive(const particle::Particle* particle) const {
|
|||||||
!leftSimulationDomain(particle);
|
!leftSimulationDomain(particle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Terminator::isAlive(const particle::Particle* particle,
|
||||||
|
const Coordinate& old_position) const {
|
||||||
|
return !reachedMaxInteractions(particle) && !reachedMaxTimeAlive(particle) &&
|
||||||
|
!leftSimulationDomain(particle, old_position);
|
||||||
|
}
|
||||||
|
|
||||||
bool Terminator::reachedMaxInteractions(
|
bool Terminator::reachedMaxInteractions(
|
||||||
const particle::Particle* particle) const {
|
const particle::Particle* particle) const {
|
||||||
return particle->interactionCounter() > max_interactions_;
|
return particle->interactionCounter() > max_interactions_;
|
||||||
@@ -41,6 +47,43 @@ bool Terminator::leftSimulationDomain(
|
|||||||
return !(geometry_->isInside(particle->cylinderPosition()));
|
return !(geometry_->isInside(particle->cylinderPosition()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Terminator::leftSimulationDomain(
|
||||||
|
const particle::Particle* particle, const Coordinate& old_position) const {
|
||||||
|
return !(geometry_->isInside(particle->cylinderPosition()));
|
||||||
|
}
|
||||||
|
|
||||||
double Terminator::maxTimeAlive() const {
|
double Terminator::maxTimeAlive() const {
|
||||||
return max_time_alive_;
|
return max_time_alive_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TerminatorWithPlates::TerminatorWithPlates(long int max_interactions, double max_time_alive,
|
||||||
|
std::shared_ptr<Geometry> geometry,
|
||||||
|
double zpos1, double zpos2, double innerRadius1,
|
||||||
|
double innerRadius2, double outerRadius1,
|
||||||
|
double outerRadius2) :
|
||||||
|
zpos1_(zpos1), zpos2_(zpos2),
|
||||||
|
innerRadius1_(innerRadius1), innerRadius2_(innerRadius2),
|
||||||
|
outerRadius1_(outerRadius1), outerRadius2_(outerRadius2),
|
||||||
|
Terminator(max_interactions, max_time_alive, geometry) {}
|
||||||
|
|
||||||
|
bool TerminatorWithPlates::leftSimulationDomain(const particle::Particle* particle,
|
||||||
|
const Coordinate& old_position) const {
|
||||||
|
blitz::TinyVector<double, 3> cyl_pos_new = particle->cylinderPosition().cylinderEntries();
|
||||||
|
blitz::TinyVector<double, 3> cyl_pos_old = old_position.cylinderEntries();
|
||||||
|
bool outerbounds = Terminator::leftSimulationDomain(particle);
|
||||||
|
// crossing of zpos1_ plane
|
||||||
|
bool firstPlate = ((cyl_pos_new(2)-zpos1_)*(cyl_pos_old(2)-zpos1_) < 0) &&
|
||||||
|
(cyl_pos_new(0) > innerRadius1_) &&
|
||||||
|
(cyl_pos_new(0) < outerRadius1_);
|
||||||
|
|
||||||
|
bool secondPlate = ((cyl_pos_new(2)-zpos2_)*(cyl_pos_old(2)-zpos2_) < 0) &&
|
||||||
|
(cyl_pos_new(0) > innerRadius2_) &&
|
||||||
|
(cyl_pos_new(0) < outerRadius2_);
|
||||||
|
|
||||||
|
return outerbounds || firstPlate || secondPlate;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TerminatorWithPlates::leftSimulationDomain(const particle::Particle* particle) const {
|
||||||
|
ERROR("TerminatorWithPlates: \"leftSimulationDomain\" cannot be called with only a single set of coordinates!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user