Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93a51acbda |
@@ -202,18 +202,14 @@ def plotSpectrumAtZ(filename, path_to_species, z_position, plot_axis, output_per
|
||||
spectrum_at_z = spectrumAtZ(
|
||||
filename, path_to_species, z_position, output_period)
|
||||
E_bins = energyBinsDensityfield(filename, path_to_species)
|
||||
# included to get dn/dE
|
||||
E_bin_volumes = E_bins[1:] - E_bins[:-1]
|
||||
plot_bins, plot_datas = makeBarPlotData(
|
||||
spectrum_at_z[1:-1]/E_bin_volumes, E_bins[0:-1], E_bins[1:])
|
||||
spectrum_at_z[1:-1], E_bins[0:-1], E_bins[1:])
|
||||
plot_axis.plot(plot_bins, plot_datas, label=str(path_to_species))
|
||||
plot_axis.set_xscale("log")
|
||||
plot_axis.set_yscale("log")
|
||||
plot_axis.set_xlabel(r"Energy $E$ (eV)")
|
||||
plot_axis.set_ylabel(
|
||||
r"Diff. Density $\frac{\mathrm{d}n_e}{\mathrm{d}E}$ $\left(\frac{1}{\mathrm{m}^{3} \mathrm{eV}}\right)$")
|
||||
# plot_axis.set_ylabel(
|
||||
# r"Diff. Density $\frac{\mathrm{d}n_e}{\mathrm{d}\log_{10}E}$ $\left(\frac{1}{\mathrm{m}^{3} \log_{10}(\mathrm{eV})}\right)$")
|
||||
r"Diff. Density $\frac{\mathrm{d}n_e}{\mathrm{d}\log_{10}E}$ $\left(\frac{1}{\mathrm{m}^{3} \log_{10}(\mathrm{eV})}\right)$")
|
||||
|
||||
|
||||
def plotAllSpectrumAtZ(filename, z_position, output_period, specie_keys, output_folder):
|
||||
@@ -260,7 +256,7 @@ def plotLongitudinalParticleCurrentVsZ(filename, path_to_species, plot_axis, out
|
||||
z_bins = zBinsDensityField(filename, path_to_species)
|
||||
plot_axis.plot(z_bins, current_in_z, label=str(path_to_species))
|
||||
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
|
||||
plot_axis.set_ylabel(r"Particle current $j$ ($m^{-2}s^{-1}$)")
|
||||
plot_axis.set_ylabel(r"Particle current $j$ ($m^{-3}s^{-1}$)")
|
||||
|
||||
|
||||
def plotAllLongitudinalParticleCurrentVsZ(filename, output_period, specie_keys, output_folder):
|
||||
@@ -282,7 +278,7 @@ def plotLongitudinalElectricCurrentVsZ(filename, path_to_species, plot_axis, out
|
||||
z_bins = zBinsDensityField(filename, path_to_species)
|
||||
plot_axis.plot(z_bins, current_in_z)
|
||||
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
|
||||
plot_axis.set_ylabel(r"Electric current $I$ ($A$)") # unit should be wrong, think it should be A/m^2
|
||||
plot_axis.set_ylabel(r"Electric current $I$ ($A$)")
|
||||
|
||||
|
||||
def printDeletionLoggerStats(filename, path_to_species, output_period="LastSyncPeriod"):
|
||||
@@ -304,50 +300,3 @@ def printDeletionLoggerStats(filename, path_to_species, output_period="LastSyncP
|
||||
def printAllDeletionLoggerStats(filename, specie_keys, output_period):
|
||||
for key in specie_keys:
|
||||
printDeletionLoggerStats(filename, key, output_period)
|
||||
|
||||
def zBinsPoissonSolver(filename, path_to_poisson_solver):
|
||||
file = h5py.File(filename, 'r')
|
||||
path_to_border = path_to_poisson_solver + "/BinBorders/longitudinal"
|
||||
return np.array(file[path_to_border])
|
||||
|
||||
def rBinsPoissonSolver(filename, path_to_poisson_solver):
|
||||
file = h5py.File(filename, 'r')
|
||||
path_to_border = path_to_poisson_solver + "/BinBorders/radial"
|
||||
return np.array(file[path_to_border])
|
||||
|
||||
def potential(filename, path_to_poisson_solver, output_period):
|
||||
file = h5py.File(filename, 'r')
|
||||
path_to_density = path_to_poisson_solver + "/SimulationData" + \
|
||||
outputPeriodKey(output_period) + "/Potential"
|
||||
return np.array(file[path_to_density])
|
||||
|
||||
# returns potential averaged over r-direction; assumes only one azimuthal bin
|
||||
def potentialVsZ(filename, path_to_poisson_solver, output_period="LastSyncPeriod"):
|
||||
rbinBorders = rBinsPoissonSolver(filename, path_to_poisson_solver)
|
||||
deltar = rbinBorders[1] - rbinBorders[0] #assumption of linear binning
|
||||
weights = rbinBorders[1:]**2 - rbinBorders[:-1]**2 + deltar**2
|
||||
weights = np.append(deltar**2/4, weights)
|
||||
potentialValues = potential(filename, path_to_poisson_solver, output_period)
|
||||
weightedPotential = potentialValues*weights[:, np.newaxis, np.newaxis]
|
||||
return np.sum(weightedPotential, axis=(0,1)) / np.sum(weights)
|
||||
|
||||
def plotPotentialVsZ(filename, path_to_poisson_solver, plot_axis, output_period="LastSyncPeriod"):
|
||||
potential_ = potentialVsZ(filename, path_to_poisson_solver, output_period)
|
||||
z_bins = zBinsPoissonSolver(filename, path_to_poisson_solver)
|
||||
plot_bins, plot_datas = makeBarPlotData(
|
||||
potential_, z_bins, z_bins)
|
||||
plot_axis.plot(plot_bins, plot_datas)
|
||||
# plot_axis.set_yscale("log")
|
||||
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
|
||||
plot_axis.set_ylabel(r"Potential $\Phi$ ($V$)")
|
||||
|
||||
def plotAllPotentialVsZ(filename, output_period, output_folder):
|
||||
pst.setRcParams()
|
||||
fig, ax = plt.subplots(figsize=pst.set_size('thesis'))
|
||||
key = "PoissonSolver"
|
||||
plotPotentialVsZ(filename, key, ax, output_period)
|
||||
|
||||
ax.set_facecolor('#e7e7e7ff')
|
||||
ax.grid(color='white')
|
||||
fig.savefig(output_folder + "/potential_vs_z_at_period={}.pdf".format(output_period),
|
||||
format='pdf', bbox_inches='tight')
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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_;
|
||||
OutputTask task_potential_; // no meta data written for now
|
||||
|
||||
Hdf5Writer writer;
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ 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 {
|
||||
|
||||
@@ -57,10 +57,10 @@ class PoissonSolver {
|
||||
int num_cycles,
|
||||
int solver_intervall,
|
||||
int solver_offset,
|
||||
bool do_solver);
|
||||
bool reset_after_solving);
|
||||
|
||||
void solvePotential(const blitz::Array<double, 3> charge_density,
|
||||
int cpu_sync);
|
||||
int cpu_sync, bool& reset);
|
||||
blitz::Array<double, 3> potential();
|
||||
std::shared_ptr<VectorField> staticElectricField();
|
||||
const CylinderBinning* densityBinning();
|
||||
@@ -76,7 +76,7 @@ class PoissonSolver {
|
||||
const int num_cycles_;
|
||||
const int solver_intervall_;
|
||||
const int solver_offset_;
|
||||
const bool do_solver_;
|
||||
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
|
||||
|
||||
@@ -31,6 +31,8 @@ class CurrentCollector {
|
||||
|
||||
double physicalTime() const;
|
||||
|
||||
void resetCurrentCollector();
|
||||
|
||||
friend class CpuSynchronizer;
|
||||
|
||||
private:
|
||||
|
||||
@@ -38,6 +38,8 @@ 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;
|
||||
|
||||
@@ -23,15 +23,12 @@ class ElectricField {
|
||||
|
||||
class MagneticField {
|
||||
public:
|
||||
MagneticField(std::shared_ptr<VectorField> field,
|
||||
std::shared_ptr<VectorField> gradient);
|
||||
MagneticField(std::shared_ptr<VectorField> field);
|
||||
|
||||
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 {
|
||||
|
||||
@@ -23,6 +23,8 @@ class DeletionLogger {
|
||||
void numDeletions(long int new_value, DeletionType type);
|
||||
long int numDeletions(DeletionType type) const;
|
||||
|
||||
void resetDeletionLogger();
|
||||
|
||||
friend class CpuSynchronizer;
|
||||
|
||||
private:
|
||||
|
||||
@@ -10,6 +10,7 @@ class Timer {
|
||||
double time() const;
|
||||
void increaseTimestep(double time_s);
|
||||
void setTime(double time_s);
|
||||
void resetTime();
|
||||
|
||||
private:
|
||||
double current_time_s_;
|
||||
|
||||
@@ -54,13 +54,6 @@
|
||||
"yValuesKey": "/vz(ms)",
|
||||
"prefactor": 1
|
||||
}
|
||||
},
|
||||
"f5": {
|
||||
"Exponential": {
|
||||
"scale": -1,
|
||||
"prefactor": 1,
|
||||
"comment": "f5 = prefactor*exp(scale*x)"
|
||||
}
|
||||
}
|
||||
},
|
||||
"3dto1D examples": {
|
||||
|
||||
@@ -568,15 +568,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"GradientField": {
|
||||
"VectorFieldFunctionInZ": {
|
||||
"zFunction": {
|
||||
"Constant3D": {
|
||||
"constant": 2.5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"GravityField": {
|
||||
@@ -625,8 +616,7 @@
|
||||
"TargetAccuracy": 1e-7,
|
||||
"NumCycles": 2e4,
|
||||
"Intervall": 1,
|
||||
"Offset": 9,
|
||||
"DoSolver": "true"
|
||||
"Offset": 9
|
||||
},
|
||||
"Simulation": {
|
||||
"SimulatedEvents": 1,
|
||||
@@ -649,7 +639,9 @@
|
||||
"OverwriteLast": "true"
|
||||
},
|
||||
"DeletionLogger": {
|
||||
"Species": "all",
|
||||
"Species": [
|
||||
"all"
|
||||
],
|
||||
"Intervall": "EachSync",
|
||||
"OverwriteLast": "true"
|
||||
},
|
||||
|
||||
@@ -565,15 +565,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"GradientField": {
|
||||
"VectorFieldFunctionInZ": {
|
||||
"zFunction": {
|
||||
"Constant3D": {
|
||||
"constant": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"PoissonSolver": {
|
||||
@@ -594,30 +585,13 @@
|
||||
"GlobalPositionBinning"
|
||||
]
|
||||
},
|
||||
"Boundary": {
|
||||
"Top": {
|
||||
"type": "neumann",
|
||||
"value": 0
|
||||
},
|
||||
"Bottom": {
|
||||
"type": "dirichlet",
|
||||
"value": 0
|
||||
},
|
||||
"Hull": {
|
||||
"type": "dirichlet",
|
||||
"value": 0
|
||||
}
|
||||
},
|
||||
"TargetAccuracy": 1e-7,
|
||||
"NumCycles": 2e4,
|
||||
"Intervall": 1,
|
||||
"Offset": 0
|
||||
"NumCycles": 2e4
|
||||
},
|
||||
"Simulation": {
|
||||
"SimulatedEvents": 1,
|
||||
"EventStride": 1,
|
||||
"PoissonOffset": 0,
|
||||
"DoSolver": "false"
|
||||
"PoissonOffset": 0
|
||||
},
|
||||
"Output": {
|
||||
"folder": "output",
|
||||
|
||||
@@ -55,10 +55,6 @@ 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,13 +71,6 @@ 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,8 +7,7 @@ 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, {"GradientField"}))));
|
||||
buildVectorField(json_object_by_path(object, {"VectorField"}))));
|
||||
}
|
||||
|
||||
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 correctly.");
|
||||
ERROR("The mass is not given correcty.");
|
||||
return 0.;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ namespace generator {
|
||||
int num_cycles = parameter.intValue(json_path_append({"PoissonSolver"},
|
||||
{"NumCycles"}));
|
||||
|
||||
bool do_solver = parameter.boolValue(json_path_append({"PoissonSolver"},
|
||||
{"DoSolver"}), true);
|
||||
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,
|
||||
do_solver));
|
||||
reset_after_solving));
|
||||
}
|
||||
|
||||
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
|
||||
|
||||
@@ -143,7 +143,7 @@ std::shared_ptr<SimulationOutput> buildSimulationOutput(
|
||||
intervall = 1;
|
||||
}
|
||||
ASSERT_POSITIVE(&intervall,
|
||||
"The output intervall for the poisson solver output must be positive.");
|
||||
"The intervall for the poisson solver output must be positive");
|
||||
|
||||
bool overwrite_last = json_bool(
|
||||
json_object_by_path(object, {"PoissonSolver", "OverwriteLast"}));
|
||||
|
||||
@@ -44,10 +44,8 @@ blitz::Array<double, 3> readFromFile(json_t* object) {
|
||||
blitz::Array<double, 3> readComponentFromFile(json_t* object, int component) {
|
||||
std::string absolute_filename =
|
||||
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
||||
DEBUG_LEVEL_3("path to h5: " + absolute_filename);
|
||||
std::string key = json_string(
|
||||
json_array_get(json_object_by_path(object, {"Keys"}), component));
|
||||
DEBUG_LEVEL_3("key: " + key);
|
||||
json_array_get(json_object_by_path(object, {"PathToH5"}), component));
|
||||
|
||||
Hdf5Reader reader(absolute_filename);
|
||||
return reader.readD3Double(key);
|
||||
|
||||
@@ -18,7 +18,7 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
int num_cycles,
|
||||
int solver_intervall,
|
||||
int solver_offset,
|
||||
bool do_solver)
|
||||
bool reset_after_solving)
|
||||
: bottom_boundary_(bottom_boundary),
|
||||
top_boundary_(top_boundary),
|
||||
hull_boundary_(hull_boundary),
|
||||
@@ -36,7 +36,7 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
num_cycles_(num_cycles),
|
||||
solver_intervall_(solver_intervall),
|
||||
solver_offset_(solver_offset),
|
||||
do_solver_(do_solver) {
|
||||
reset_after_solving_(reset_after_solving) {
|
||||
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||
@@ -81,13 +81,16 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
blitz::Range(density_binning.binIndexMin()(2),
|
||||
density_binning.binIndexMax()(2)));
|
||||
zero_chargedensity = 0.;
|
||||
solvePotential(zero_chargedensity, 0);
|
||||
bool reset;
|
||||
solvePotential(zero_chargedensity, 0, reset);
|
||||
}
|
||||
|
||||
void PoissonSolver::solvePotential(
|
||||
const blitz::Array<double, 3> charge_density, int cpu_sync) {
|
||||
if ((!do_solver_) || ((cpu_sync % solver_intervall_ != 0) || ((cpu_sync <= solver_offset_)
|
||||
&& (cpu_sync > 0)))) {
|
||||
const blitz::Array<double, 3> charge_density, int cpu_sync,
|
||||
bool& reset) {
|
||||
if ((cpu_sync % solver_intervall_ != 0) || ((cpu_sync <= solver_offset_)
|
||||
&& (cpu_sync > 0))) {
|
||||
reset = false;
|
||||
return;
|
||||
}
|
||||
DEBUG_LEVEL_3("Interpolating chargedensity.");
|
||||
@@ -104,6 +107,7 @@ void PoissonSolver::solvePotential(
|
||||
}
|
||||
++it;
|
||||
} while (it < num_cycles_);
|
||||
reset = reset_after_solving_;
|
||||
}
|
||||
|
||||
void PoissonSolver::solverIteration(
|
||||
@@ -245,7 +249,7 @@ bool PoissonSolver::converged(
|
||||
double normalized_maximum =
|
||||
maximum_difference*SI::eps0/(fabs(blitz::max(interpolated_density)) + 1e-12);
|
||||
std::ostringstream message;
|
||||
message << "Maximum Differenece normalized by order of magnitude: "
|
||||
message << "Maximum Difference normalized by order of magnitude: "
|
||||
<< normalized_difference;
|
||||
DEBUG_LEVEL_0(message.str());
|
||||
return normalized_difference < target_accuracy_;
|
||||
|
||||
@@ -240,3 +240,14 @@ 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.;
|
||||
}
|
||||
@@ -205,6 +205,13 @@ 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.;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -16,18 +16,13 @@ void ElectricField::updateDynamicField(std::shared_ptr<VectorField> field) {
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
MagneticField::MagneticField(std::shared_ptr<VectorField> field,
|
||||
std::shared_ptr<VectorField> gradient)
|
||||
: field_(field), gradient_(gradient) {}
|
||||
MagneticField::MagneticField(std::shared_ptr<VectorField> field)
|
||||
: field_(field) {}
|
||||
|
||||
CylinderVector MagneticField::value(const Coordinate& position) const {
|
||||
return field_->value(position);
|
||||
}
|
||||
|
||||
CylinderVector MagneticField::gradientValue(const Coordinate& position) const {
|
||||
return gradient_->value(position);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -30,3 +30,9 @@ long int DeletionLogger::numDeletions(DeletionType type) const {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DeletionLogger::resetDeletionLogger() {
|
||||
for(auto& pair : num_deletions) {
|
||||
pair.second = 0;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-100
@@ -29,22 +29,19 @@ void BorisMover::move(particle::Particle* particle,
|
||||
auto old_position = particle->position();
|
||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
// 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;
|
||||
// }
|
||||
if (old_kinetic_energy < 1E-9) {
|
||||
// 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 || died_in_bin) &&
|
||||
(leftover_distance > 0.)) {
|
||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain) &&
|
||||
(leftover_distance > 0.)) {
|
||||
old_position = particle->position();
|
||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
@@ -54,13 +51,8 @@ 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);
|
||||
|
||||
const blitz::TinyVector<double, 3> force_over_q =
|
||||
E + particle->mass_kg()/particle->charge_C()*g;
|
||||
|
||||
movementStep(particle, force_over_q, B, moved_distance);
|
||||
movementStep(particle, E, B, moved_distance);
|
||||
particle->increaseTimeAlive(maximal_time_step_s_);
|
||||
particle->increaseTimeInBin(maximal_time_step_s_);
|
||||
|
||||
@@ -77,9 +69,6 @@ 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;
|
||||
}
|
||||
|
||||
@@ -203,70 +192,39 @@ void DriftMover::move(particle::Particle* particle,
|
||||
while (
|
||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain) &&
|
||||
(leftover_distance > 0.) && !(died_in_bin)) {
|
||||
std::stringstream out;
|
||||
old_position = particle->position();
|
||||
old_velocity = particle->velocity();
|
||||
|
||||
out << "cylinder vector pos: " << old_position.cartesianEntries() <<"\n";
|
||||
|
||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
// out << " old kinetic Energy: " << old_kinetic_energy << "\n";
|
||||
|
||||
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> 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();
|
||||
|
||||
const blitz::TinyVector<double, 3> B =
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||
const double B_norm = kinematic::norm(B);
|
||||
|
||||
out << " B(cyli): " << magnetic_field->value(old_position).cylinderEntries()<<"\n";
|
||||
// Todo: add calculation of divB here
|
||||
// use Kassiopeia paper for reference
|
||||
|
||||
const blitz::TinyVector<double, 3> v_parallel =
|
||||
kinematic::parallelVector(old_velocity.cartesianEntries(), B);
|
||||
const double v_parallel_norm = kinematic::norm(v_parallel);
|
||||
// out << " v_parallel: " << v_parallel << "\n";
|
||||
|
||||
const blitz::TinyVector<double, 3> v_perp =
|
||||
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
|
||||
const double v_perp_norm = kinematic::norm(v_perp);
|
||||
out << " v_perp: " << v_perp << "\n";
|
||||
|
||||
// magnetic moment force / q
|
||||
const double magnetic_moment = (particle->mass_kg()*(v_perp_norm*v_perp_norm/2))/B_norm;
|
||||
out << " magnetic moment: " << magnetic_moment << "\n";
|
||||
|
||||
force_over_charge += -(magnetic_moment / particle->charge_C() *
|
||||
magnetic_field->gradientValue(old_position).cartesianEntries(old_position));
|
||||
// out << " gradB (cyli): "
|
||||
// << magnetic_field->gradientValue(old_position).cylinderEntries(old_position)
|
||||
// << "\n";
|
||||
// centrifugal force / q
|
||||
force_over_charge += -(particle->mass_kg()/particle->charge_C() *
|
||||
(v_parallel_norm*v_parallel_norm) *
|
||||
kinematic::perpendicularVector(magnetic_field->
|
||||
gradientValue(old_position).cartesianEntries(old_position), B) /
|
||||
B_norm);
|
||||
// debugging
|
||||
// const blitz::TinyVector<double, 3> tmpfrc = -(particle->mass_kg()/particle->charge_C() *
|
||||
// (v_perp_norm*v_perp_norm/2) *
|
||||
// magnetic_field->gradientValue(old_position).cartesianEntries(old_position) /
|
||||
// B_norm);
|
||||
// out << " gradB force/q: " << tmpfrc << "\n";
|
||||
|
||||
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
|
||||
// should be a very rare case (but has happend)
|
||||
const double timestep = std::min(
|
||||
stepsize / (v_parallel_norm + v_perp_norm + v_drift_norm),
|
||||
max_time_alive);
|
||||
// out << " timestep: " << timestep << "\n";
|
||||
|
||||
const blitz::TinyVector<double, 3> movement_parallel =
|
||||
v_parallel * timestep;
|
||||
@@ -274,14 +232,12 @@ void DriftMover::move(particle::Particle* particle,
|
||||
|
||||
const blitz::TinyVector<double, 3> force_over_charge_parallel =
|
||||
kinematic::parallelVector(force_over_charge, B);
|
||||
|
||||
const blitz::TinyVector<double, 3> dv_electric =
|
||||
timestep * particle->charge_C() * force_over_charge_parallel / particle->mass_kg();
|
||||
|
||||
if (v_perp_norm > SimConstants::compare_epsilon) {
|
||||
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
||||
(B_norm * particle->charge_C());
|
||||
// out << " gyroradius: " << gyro_radius << "\n";
|
||||
(B_norm * std::abs(particle->charge_C()));
|
||||
|
||||
const blitz::TinyVector<double, 3> velocity_normal =
|
||||
(-1) * blitz::cross(B, v_perp);
|
||||
@@ -289,56 +245,23 @@ void DriftMover::move(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3> offset_to_gyro_center =
|
||||
gyro_radius * velocity_normal / kinematic::norm(velocity_normal);
|
||||
|
||||
const blitz::TinyVector<double, 3> guiding_center =
|
||||
(offset_to_gyro_center + old_position.cartesianEntries());
|
||||
out << " guiding center: " << guiding_center << "\n";
|
||||
out << " offset gyro: " << offset_to_gyro_center << "\n";
|
||||
out << " movement parallel:" << movement_parallel << "\n";
|
||||
|
||||
const double gyro_frequency =
|
||||
particle->charge_C() * B_norm / particle->mass_kg();
|
||||
|
||||
const double total_rotation_angle = -gyro_frequency * timestep;
|
||||
out << " tot rot angle: " << total_rotation_angle << "\n";
|
||||
const double total_rotation_angle = gyro_frequency * timestep;
|
||||
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
||||
offset_to_gyro_center - kinematic::rotateVector(offset_to_gyro_center,
|
||||
B, total_rotation_angle);
|
||||
// out << " movement around gyro: " << movement_around_gyro_center << "\n";
|
||||
|
||||
const double v_parallel_new_norm = kinematic::norm(v_parallel + dv_electric);
|
||||
// v_perp by conservation of magn. moment
|
||||
const blitz::TinyVector<double, 3> new_position = old_position.cartesianEntries()
|
||||
+ movement_parallel + movement_drift
|
||||
+ movement_around_gyro_center;
|
||||
const blitz::TinyVector<double, 3> B_new =
|
||||
magnetic_field->value(CartesianCoordinate(new_position))
|
||||
.cartesianEntries(CartesianCoordinate(new_position));
|
||||
|
||||
const double v_perp_new_norm =
|
||||
sqrt(2*magnetic_moment*kinematic::norm(B_new)/particle->mass_kg());
|
||||
kinematic::rotateVector(offset_to_gyro_center, B,
|
||||
total_rotation_angle) -
|
||||
offset_to_gyro_center;
|
||||
|
||||
const blitz::TinyVector<double, 3> v_perp_rotated =
|
||||
kinematic::rotateVector(v_perp, B, total_rotation_angle);
|
||||
// out << " v_perp,rotated: " << v_perp_rotated << "\n";
|
||||
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
|
||||
particle->move(CartesianCoordinate(movement_parallel + movement_drift +
|
||||
movement_around_gyro_center));
|
||||
// project v_parallel and v_perp onto the new direction of B
|
||||
const blitz::TinyVector<double, 3> v_parallel_new =
|
||||
kinematic::parallelVector(v_parallel + dv_electric, B_new);
|
||||
const blitz::TinyVector<double, 3> v_perpendicular_new =
|
||||
kinematic::perpendicularVector(v_perp_rotated, B_new);
|
||||
|
||||
// use the new direction for the actual velocity (nec. for mu to be const)
|
||||
const blitz::TinyVector<double, 3> v_new =
|
||||
v_parallel_new/kinematic::norm(v_parallel_new) * v_parallel_new_norm +
|
||||
v_perpendicular_new/kinematic::norm(v_perpendicular_new) * v_perp_new_norm;
|
||||
|
||||
particle->velocity(CartesianVector(v_new));
|
||||
particle->velocity(
|
||||
CartesianVector(v_parallel + v_perp_rotated + dv_electric));
|
||||
} else {
|
||||
// neccessary to adjust as well? i.e. adjust the direction of v_parallel
|
||||
particle->move(CartesianCoordinate(movement_parallel + movement_drift));
|
||||
particle->velocity(CartesianVector(v_parallel + dv_electric));
|
||||
}
|
||||
@@ -363,7 +286,6 @@ void DriftMover::move(particle::Particle* particle,
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||
|
||||
leftover_distance -= stepsize;
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
}
|
||||
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
|
||||
@@ -106,6 +106,7 @@ 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: " +
|
||||
@@ -123,7 +124,7 @@ void Simulation::start() {
|
||||
|
||||
SIM_INFO("Poisson step.");
|
||||
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
|
||||
poisson_solver_->solvePotential(chargedensity(), num_cpu_syncs);
|
||||
poisson_solver_->solvePotential(chargedensity(), num_cpu_syncs, reset);
|
||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||
|
||||
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
|
||||
@@ -132,6 +133,20 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,3 +13,7 @@ void Timer::increaseTimestep(double time_s) {
|
||||
void Timer::setTime(double time_s) {
|
||||
current_time_s_ = time_s;
|
||||
}
|
||||
|
||||
void Timer::resetTime() {
|
||||
setTime(0.);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user