Compare commits
3
Commits
karl_2d
...
dc226a8d53
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc226a8d53 | ||
|
|
1f4314c527 | ||
|
|
1efcb58d35 |
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"}));
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+33
-12
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user