Author SHA1 Message Date
csendlinger dc226a8d53 Added gradB as input, adjusted drift mover
to include gradB (not yet tested for correctness)
2024-05-10 14:34:03 +02:00
csendlinger 1f4314c527 added exponential into predefined functions 2024-05-10 14:21:07 +02:00
csendlinger 1efcb58d35 Added gravity array to boris push,
minor cosmetic changes
2024-05-02 09:06:40 +02:00
22 changed files with 72 additions and 91 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ class SimulationOutput {
std::vector<OutputTask> tasks_density_fields_;
std::vector<OutputTask> tasks_current_collector_;
std::vector<OutputTask> tasks_deletion_logger_;
OutputTask task_potential_; // no meta data written for now
OutputTask task_potential_;
Hdf5Writer writer;
+2
View File
@@ -12,6 +12,8 @@ std::function<double(double)> Constant(double constant);
std::function<double(double)> Product(
std::vector<std::function<double(double)>> functions);
std::function<double(double)> Exponential(double prefactor, double scale);
}; // namespace D1ToD1
namespace D3ToD1 {
+2 -4
View File
@@ -56,11 +56,10 @@ class PoissonSolver {
double target_accuracy,
int num_cycles,
int solver_intervall,
int solver_offset,
bool reset_after_solving);
int solver_offset);
void solvePotential(const blitz::Array<double, 3> charge_density,
int cpu_sync, bool& reset);
int cpu_sync);
blitz::Array<double, 3> potential();
std::shared_ptr<VectorField> staticElectricField();
const CylinderBinning* densityBinning();
@@ -76,7 +75,6 @@ class PoissonSolver {
const int num_cycles_;
const int solver_intervall_;
const int solver_offset_;
const bool reset_after_solving_;
// density binning defined on the cell centers, potential defined
// such that it exists on the cell edges so that the azimuthal
-2
View File
@@ -31,8 +31,6 @@ class CurrentCollector {
double physicalTime() const;
void resetCurrentCollector();
friend class CpuSynchronizer;
private:
-2
View File
@@ -38,8 +38,6 @@ class DynamicDensityField : public DensityField {
double density(const Coordinate& position);
double density(const Coordinate& position, double energy_eV);
void resetDynamicDensityField();
blitz::Array<double, 3> densityArray();
blitz::Array<double, 4> spectrumArray();
blitz::Array<double, 4> timeInBinArray() const;
+4 -1
View File
@@ -23,12 +23,15 @@ class ElectricField {
class MagneticField {
public:
MagneticField(std::shared_ptr<VectorField> field);
MagneticField(std::shared_ptr<VectorField> field,
std::shared_ptr<VectorField> gradient);
CylinderVector value(const Coordinate& position) const;
CylinderVector gradientValue(const Coordinate& position) const;
private:
std::shared_ptr<VectorField> field_;
std::shared_ptr<VectorField> gradient_;
};
class GravityField {
-2
View File
@@ -23,8 +23,6 @@ class DeletionLogger {
void numDeletions(long int new_value, DeletionType type);
long int numDeletions(DeletionType type) const;
void resetDeletionLogger();
friend class CpuSynchronizer;
private:
-1
View File
@@ -10,7 +10,6 @@ class Timer {
double time() const;
void increaseTimestep(double time_s);
void setTime(double time_s);
void resetTime();
private:
double current_time_s_;
+4
View File
@@ -55,6 +55,10 @@ std::function<double(double)> Product(
return product;
};
}
std::function<double(double)> Exponential(double prefactor, double scale) {
return [=](double x) { return prefactor * std::exp(scale * x); };
}
}; // namespace D1ToD1
namespace D3ToD1 {
+7
View File
@@ -71,6 +71,13 @@ std::function<double(double)> function1D(json_t* object) {
}
return D1ToD1::Product(functions);
} else if (json_object_by_path(object, {"Exponential"})) {
DEBUG_LEVEL_2("Creating function1d: Exponential.");
double prefactor = json_double(json_object_by_path(
object, {"Exponential", {"prefactor"}}));
double scale = json_double(json_object_by_path(
object, {"Exponential", {"scale"}}));
return D1ToD1::Exponential(prefactor, scale);
} else {
ERROR("This 1d to 1d function is not implemented.");
return nullptr;
+2 -1
View File
@@ -7,7 +7,8 @@ namespace generator {
std::shared_ptr<MagneticField> magneticField(json_t* object) {
DEBUG_LEVEL_2("Generating magnetic field.");
return std::shared_ptr<MagneticField>(new MagneticField(
buildVectorField(json_object_by_path(object, {"VectorField"}))));
buildVectorField(json_object_by_path(object, {"VectorField"})),
buildVectorField(json_object_by_path(object, {"GradientField"}))));
}
std::shared_ptr<MagneticField> magneticField(Parameter& parameter) {
+1 -1
View File
@@ -33,7 +33,7 @@ double buildMass(json_t* object) {
} else if (json_object_by_path(object, {"value"})) {
return json_double(json_object_by_path(object, {"value"}));
} else {
ERROR("The mass is not given correcty.");
ERROR("The mass is not given correctly.");
return 0.;
}
}
+1 -5
View File
@@ -52,13 +52,9 @@ namespace generator {
int num_cycles = parameter.intValue(json_path_append({"PoissonSolver"},
{"NumCycles"}));
bool reset_after_solving = parameter.boolValue(
json_path_append({"PoissonSolver"}, {"ResetAfterSolving"}), false);
return std::shared_ptr<PoissonSolver>(new PoissonSolver(boundaries.at("Bottom"),
boundaries.at("Top"), boundaries.at("Hull"), geometry, position_binning,
electrodes, target_accuracy, num_cycles, solver_intervall, solver_offset,
reset_after_solving));
electrodes, target_accuracy, num_cycles, solver_intervall, solver_offset));
}
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
@@ -143,7 +143,7 @@ std::shared_ptr<SimulationOutput> buildSimulationOutput(
intervall = 1;
}
ASSERT_POSITIVE(&intervall,
"The intervall for the poisson solver output must be positive");
"The output intervall for the poisson solver output must be positive.");
bool overwrite_last = json_bool(
json_object_by_path(object, {"PoissonSolver", "OverwriteLast"}));
+5 -11
View File
@@ -17,8 +17,7 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
double target_accuracy,
int num_cycles,
int solver_intervall,
int solver_offset,
bool reset_after_solving)
int solver_offset)
: bottom_boundary_(bottom_boundary),
top_boundary_(top_boundary),
hull_boundary_(hull_boundary),
@@ -35,8 +34,7 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
target_accuracy_(target_accuracy),
num_cycles_(num_cycles),
solver_intervall_(solver_intervall),
solver_offset_(solver_offset),
reset_after_solving_(reset_after_solving) {
solver_offset_(solver_offset) {
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
@@ -81,16 +79,13 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
blitz::Range(density_binning.binIndexMin()(2),
density_binning.binIndexMax()(2)));
zero_chargedensity = 0.;
bool reset;
solvePotential(zero_chargedensity, 0, reset);
solvePotential(zero_chargedensity, 0);
}
void PoissonSolver::solvePotential(
const blitz::Array<double, 3> charge_density, int cpu_sync,
bool& reset) {
const blitz::Array<double, 3> charge_density, int cpu_sync) {
if ((cpu_sync % solver_intervall_ != 0) || ((cpu_sync <= solver_offset_)
&& (cpu_sync > 0))) {
reset = false;
return;
}
DEBUG_LEVEL_3("Interpolating chargedensity.");
@@ -107,7 +102,6 @@ void PoissonSolver::solvePotential(
}
++it;
} while (it < num_cycles_);
reset = reset_after_solving_;
}
void PoissonSolver::solverIteration(
@@ -249,7 +243,7 @@ bool PoissonSolver::converged(
double normalized_maximum =
maximum_difference*SI::eps0/(fabs(blitz::max(interpolated_density)) + 1e-12);
std::ostringstream message;
message << "Maximum Difference normalized by order of magnitude: "
message << "Maximum Differenece normalized by order of magnitude: "
<< normalized_difference;
DEBUG_LEVEL_0(message.str());
return normalized_difference < target_accuracy_;
-11
View File
@@ -240,14 +240,3 @@ blitz::Array<double, 3> CurrentCollector::currentInR() const {
double CurrentCollector::physicalTime() const {
return timer_->time();
}
void CurrentCollector::resetCurrentCollector() {
z_negative_crossings = 0.;
z_positive_crossings = 0.;
phi_negative_crossings = 0.;
phi_positive_crossings = 0.;
r_negative_crossings = 0.;
r_positive_crossings = 0.;
}
-7
View File
@@ -205,13 +205,6 @@ double DynamicDensityField::physicalTime() const {
return timer_->time();
}
void DynamicDensityField::resetDynamicDensityField() {
timer_->resetTime(); // reductive since shared between species
time_in_bin_s_ = 0.;
deleted_particles_ = 0.;
density_per_m3_ = 0.;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
+7 -2
View File
@@ -16,13 +16,18 @@ void ElectricField::updateDynamicField(std::shared_ptr<VectorField> field) {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
MagneticField::MagneticField(std::shared_ptr<VectorField> field)
: field_(field) {}
MagneticField::MagneticField(std::shared_ptr<VectorField> field,
std::shared_ptr<VectorField> gradient)
: field_(field), gradient_(gradient) {}
CylinderVector MagneticField::value(const Coordinate& position) const {
return field_->value(position);
}
CylinderVector MagneticField::gradientValue(const Coordinate& position) const {
return gradient_->value(position);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
-6
View File
@@ -30,9 +30,3 @@ long int DeletionLogger::numDeletions(DeletionType type) const {
return 0;
}
}
void DeletionLogger::resetDeletionLogger() {
for(auto& pair : num_deletions) {
pair.second = 0;
}
}
+33 -12
View File
@@ -29,18 +29,21 @@ void BorisMover::move(particle::Particle* particle,
auto old_position = particle->position();
double old_kinetic_energy = particle->kineticEnergy_eV();
if (old_kinetic_energy < 1E-9) {
// Guard against small enegies taking up much time without contributing to
// density
return;
}
// if (old_kinetic_energy < 1E-9) {
// DEBUG_LEVEL_2("Particle has too low an energy.");
// // Guard against small enegies taking up much time without contributing to
// // density
// //return;
// }
bool changed_position_bin = false;
bool changed_energy_bin = false;
bool left_simulation_domain = false;
bool died_in_bin = false;
while (
!(changed_position_bin || changed_energy_bin || left_simulation_domain) &&
!(changed_position_bin || changed_energy_bin
|| left_simulation_domain || died_in_bin) &&
(leftover_distance > 0.)) {
old_position = particle->position();
old_kinetic_energy = particle->kineticEnergy_eV();
@@ -51,8 +54,13 @@ void BorisMover::move(particle::Particle* particle,
electric_field->value(old_position).cartesianEntries(old_position);
const blitz::TinyVector<double, 3> B =
magnetic_field->value(old_position).cartesianEntries(old_position);
const blitz::TinyVector<double, 3> g =
gravity_field->value(old_position).cartesianEntries(old_position);
movementStep(particle, E, B, moved_distance);
const blitz::TinyVector<double, 3> force_over_q =
E + particle->mass_kg()/particle->charge_C()*g;
movementStep(particle, force_over_q, B, moved_distance);
particle->increaseTimeAlive(maximal_time_step_s_);
particle->increaseTimeInBin(maximal_time_step_s_);
@@ -69,6 +77,9 @@ void BorisMover::move(particle::Particle* particle,
left_simulation_domain =
particle->specie()->terminator()->leftSimulationDomain(particle);
died_in_bin =
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
leftover_distance -= moved_distance;
}
@@ -197,10 +208,12 @@ void DriftMover::move(particle::Particle* particle,
old_kinetic_energy = particle->kineticEnergy_eV();
const blitz::TinyVector<double, 3> force_over_charge =
electric_field->value(old_position).cartesianEntries(old_position) +
gravity_field->value(old_position).cartesianEntries(old_position) *
particle->mass_kg() / particle->charge_C();
blitz::TinyVector<double, 3> force_over_charge =
electric_field->value(old_position).cartesianEntries(old_position);
// gravity force / q
force_over_charge += gravity_field->value(old_position).cartesianEntries(old_position)
* particle->mass_kg() / particle->charge_C();
const blitz::TinyVector<double, 3> B =
magnetic_field->value(old_position).cartesianEntries(old_position);
@@ -216,12 +229,20 @@ void DriftMover::move(particle::Particle* particle,
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
const double v_perp_norm = kinematic::norm(v_perp);
// centrifugal and magnetic moment force / q
// not sure if correct. It might be that the centrifugal force includes only the
// perpendicular part of grad(B)
force_over_charge += -(particle->mass_kg()/particle->charge_C() *
(v_parallel_norm*v_parallel_norm + v_perp_norm*v_perp_norm/2) *
magnetic_field->gradientValue(old_position).cartesianEntries(old_position) /
B_norm);
const blitz::TinyVector<double, 3> v_drift = driftVelocity(force_over_charge, B);
const double v_drift_norm = kinematic::norm(v_drift);
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 (but has happend)
// should be a very rare case
const double timestep = std::min(
stepsize / (v_parallel_norm + v_perp_norm + v_drift_norm),
max_time_alive);
+1 -16
View File
@@ -106,7 +106,6 @@ void Simulation::start() {
int leftover_events = events_this_cpu;
int num_cpu_syncs = 0;
bool reset = false;
while (leftover_events > 0) {
int events_of_cylcle = eventsOfCycle(event_stride, leftover_events);
SIM_INFO("Leftover events on first cpu: " +
@@ -124,7 +123,7 @@ void Simulation::start() {
SIM_INFO("Poisson step.");
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
poisson_solver_->solvePotential(chargedensity(), num_cpu_syncs, reset);
poisson_solver_->solvePotential(chargedensity(), num_cpu_syncs);
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
@@ -133,20 +132,6 @@ void Simulation::start() {
SimulationTimer::eventStartPoint(std::string("Output"));
output_->writeSimulationData(num_cpu_syncs, tracked_species_, poisson_solver_.get());
SimulationTimer::eventStopPoint(std::string("Output"));
if(reset) {
SIM_INFO("Reset density, current fields and deletions.");
for(auto& pair : tracked_species_) {
pair.second->dynamicDensityField()->resetDynamicDensityField();
pair.second->lastSyncDensityField()->resetDynamicDensityField();
pair.second->currentCollector()->resetCurrentCollector();
pair.second->lastSyncCurrentCollector()->resetCurrentCollector();
pair.second->deletionLogger()->resetDeletionLogger();
pair.second->lastSyncDeletionLogger()->resetDeletionLogger();
}
}
}
}
-4
View File
@@ -13,7 +13,3 @@ void Timer::increaseTimestep(double time_s) {
void Timer::setTime(double time_s) {
current_time_s_ = time_s;
}
void Timer::resetTime() {
setTime(0.);
}