Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18dc3d56bb | ||
|
|
cc7d57ba9c | ||
|
|
d8163516e7 | ||
|
|
f130274ea5 | ||
|
|
1e1c84a211 | ||
|
|
d98a14f9ea | ||
|
|
6c02cac31f | ||
|
|
12aeead76d | ||
|
|
4cf84d7f9d | ||
|
|
ba84963f96 |
@@ -202,14 +202,18 @@ def plotSpectrumAtZ(filename, path_to_species, z_position, plot_axis, output_per
|
|||||||
spectrum_at_z = spectrumAtZ(
|
spectrum_at_z = spectrumAtZ(
|
||||||
filename, path_to_species, z_position, output_period)
|
filename, path_to_species, z_position, output_period)
|
||||||
E_bins = energyBinsDensityfield(filename, path_to_species)
|
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(
|
plot_bins, plot_datas = makeBarPlotData(
|
||||||
spectrum_at_z[1:-1], E_bins[0:-1], E_bins[1:])
|
spectrum_at_z[1:-1]/E_bin_volumes, E_bins[0:-1], E_bins[1:])
|
||||||
plot_axis.plot(plot_bins, plot_datas, label=str(path_to_species))
|
plot_axis.plot(plot_bins, plot_datas, label=str(path_to_species))
|
||||||
plot_axis.set_xscale("log")
|
plot_axis.set_xscale("log")
|
||||||
plot_axis.set_yscale("log")
|
plot_axis.set_yscale("log")
|
||||||
plot_axis.set_xlabel(r"Energy $E$ (eV)")
|
plot_axis.set_xlabel(r"Energy $E$ (eV)")
|
||||||
plot_axis.set_ylabel(
|
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}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)$")
|
||||||
|
|
||||||
|
|
||||||
def plotAllSpectrumAtZ(filename, z_position, output_period, specie_keys, output_folder):
|
def plotAllSpectrumAtZ(filename, z_position, output_period, specie_keys, output_folder):
|
||||||
@@ -256,7 +260,7 @@ def plotLongitudinalParticleCurrentVsZ(filename, path_to_species, plot_axis, out
|
|||||||
z_bins = zBinsDensityField(filename, path_to_species)
|
z_bins = zBinsDensityField(filename, path_to_species)
|
||||||
plot_axis.plot(z_bins, current_in_z, label=str(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_xlabel(r"Distance to rear wall $z$ (m)")
|
||||||
plot_axis.set_ylabel(r"Particle current $j$ ($m^{-3}s^{-1}$)")
|
plot_axis.set_ylabel(r"Particle current $j$ ($m^{-2}s^{-1}$)")
|
||||||
|
|
||||||
|
|
||||||
def plotAllLongitudinalParticleCurrentVsZ(filename, output_period, specie_keys, output_folder):
|
def plotAllLongitudinalParticleCurrentVsZ(filename, output_period, specie_keys, output_folder):
|
||||||
@@ -278,7 +282,7 @@ def plotLongitudinalElectricCurrentVsZ(filename, path_to_species, plot_axis, out
|
|||||||
z_bins = zBinsDensityField(filename, path_to_species)
|
z_bins = zBinsDensityField(filename, path_to_species)
|
||||||
plot_axis.plot(z_bins, current_in_z)
|
plot_axis.plot(z_bins, current_in_z)
|
||||||
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
|
plot_axis.set_xlabel(r"Distance to rear wall $z$ (m)")
|
||||||
plot_axis.set_ylabel(r"Electric current $I$ ($A$)")
|
plot_axis.set_ylabel(r"Electric current $I$ ($A$)") # unit should be wrong, think it should be A/m^2
|
||||||
|
|
||||||
|
|
||||||
def printDeletionLoggerStats(filename, path_to_species, output_period="LastSyncPeriod"):
|
def printDeletionLoggerStats(filename, path_to_species, output_period="LastSyncPeriod"):
|
||||||
@@ -300,3 +304,50 @@ def printDeletionLoggerStats(filename, path_to_species, output_period="LastSyncP
|
|||||||
def printAllDeletionLoggerStats(filename, specie_keys, output_period):
|
def printAllDeletionLoggerStats(filename, specie_keys, output_period):
|
||||||
for key in specie_keys:
|
for key in specie_keys:
|
||||||
printDeletionLoggerStats(filename, key, output_period)
|
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.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -56,7 +56,8 @@ class PoissonSolver {
|
|||||||
double target_accuracy,
|
double target_accuracy,
|
||||||
int num_cycles,
|
int num_cycles,
|
||||||
int solver_intervall,
|
int solver_intervall,
|
||||||
int solver_offset);
|
int solver_offset,
|
||||||
|
bool do_solver);
|
||||||
|
|
||||||
void solvePotential(const blitz::Array<double, 3> charge_density,
|
void solvePotential(const blitz::Array<double, 3> charge_density,
|
||||||
int cpu_sync);
|
int cpu_sync);
|
||||||
@@ -75,6 +76,7 @@ class PoissonSolver {
|
|||||||
const int num_cycles_;
|
const int num_cycles_;
|
||||||
const int solver_intervall_;
|
const int solver_intervall_;
|
||||||
const int solver_offset_;
|
const int solver_offset_;
|
||||||
|
const bool do_solver_;
|
||||||
|
|
||||||
// density binning defined on the cell centers, potential defined
|
// density binning defined on the cell centers, potential defined
|
||||||
// such that it exists on the cell edges so that the azimuthal
|
// such that it exists on the cell edges so that the azimuthal
|
||||||
|
|||||||
@@ -54,6 +54,13 @@
|
|||||||
"yValuesKey": "/vz(ms)",
|
"yValuesKey": "/vz(ms)",
|
||||||
"prefactor": 1
|
"prefactor": 1
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"f5": {
|
||||||
|
"Exponential": {
|
||||||
|
"scale": -1,
|
||||||
|
"prefactor": 1,
|
||||||
|
"comment": "f5 = prefactor*exp(scale*x)"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"3dto1D examples": {
|
"3dto1D examples": {
|
||||||
|
|||||||
@@ -568,6 +568,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"GradientField": {
|
||||||
|
"VectorFieldFunctionInZ": {
|
||||||
|
"zFunction": {
|
||||||
|
"Constant3D": {
|
||||||
|
"constant": 2.5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"GravityField": {
|
"GravityField": {
|
||||||
@@ -616,7 +625,8 @@
|
|||||||
"TargetAccuracy": 1e-7,
|
"TargetAccuracy": 1e-7,
|
||||||
"NumCycles": 2e4,
|
"NumCycles": 2e4,
|
||||||
"Intervall": 1,
|
"Intervall": 1,
|
||||||
"Offset": 9
|
"Offset": 9,
|
||||||
|
"DoSolver": "true"
|
||||||
},
|
},
|
||||||
"Simulation": {
|
"Simulation": {
|
||||||
"SimulatedEvents": 1,
|
"SimulatedEvents": 1,
|
||||||
@@ -639,9 +649,7 @@
|
|||||||
"OverwriteLast": "true"
|
"OverwriteLast": "true"
|
||||||
},
|
},
|
||||||
"DeletionLogger": {
|
"DeletionLogger": {
|
||||||
"Species": [
|
"Species": "all",
|
||||||
"all"
|
|
||||||
],
|
|
||||||
"Intervall": "EachSync",
|
"Intervall": "EachSync",
|
||||||
"OverwriteLast": "true"
|
"OverwriteLast": "true"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -565,6 +565,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"GradientField": {
|
||||||
|
"VectorFieldFunctionInZ": {
|
||||||
|
"zFunction": {
|
||||||
|
"Constant3D": {
|
||||||
|
"constant": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"PoissonSolver": {
|
"PoissonSolver": {
|
||||||
@@ -585,13 +594,30 @@
|
|||||||
"GlobalPositionBinning"
|
"GlobalPositionBinning"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"Boundary": {
|
||||||
|
"Top": {
|
||||||
|
"type": "neumann",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
"Bottom": {
|
||||||
|
"type": "dirichlet",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
|
"Hull": {
|
||||||
|
"type": "dirichlet",
|
||||||
|
"value": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
"TargetAccuracy": 1e-7,
|
"TargetAccuracy": 1e-7,
|
||||||
"NumCycles": 2e4
|
"NumCycles": 2e4,
|
||||||
|
"Intervall": 1,
|
||||||
|
"Offset": 0
|
||||||
},
|
},
|
||||||
"Simulation": {
|
"Simulation": {
|
||||||
"SimulatedEvents": 1,
|
"SimulatedEvents": 1,
|
||||||
"EventStride": 1,
|
"EventStride": 1,
|
||||||
"PoissonOffset": 0
|
"PoissonOffset": 0,
|
||||||
|
"DoSolver": "false"
|
||||||
},
|
},
|
||||||
"Output": {
|
"Output": {
|
||||||
"folder": "output",
|
"folder": "output",
|
||||||
|
|||||||
@@ -52,9 +52,13 @@ namespace generator {
|
|||||||
int num_cycles = parameter.intValue(json_path_append({"PoissonSolver"},
|
int num_cycles = parameter.intValue(json_path_append({"PoissonSolver"},
|
||||||
{"NumCycles"}));
|
{"NumCycles"}));
|
||||||
|
|
||||||
|
bool do_solver = parameter.boolValue(json_path_append({"PoissonSolver"},
|
||||||
|
{"DoSolver"}), true);
|
||||||
|
|
||||||
return std::shared_ptr<PoissonSolver>(new PoissonSolver(boundaries.at("Bottom"),
|
return std::shared_ptr<PoissonSolver>(new PoissonSolver(boundaries.at("Bottom"),
|
||||||
boundaries.at("Top"), boundaries.at("Hull"), geometry, position_binning,
|
boundaries.at("Top"), boundaries.at("Hull"), geometry, position_binning,
|
||||||
electrodes, target_accuracy, num_cycles, solver_intervall, solver_offset));
|
electrodes, target_accuracy, num_cycles, solver_intervall, solver_offset,
|
||||||
|
do_solver));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
|
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
|
||||||
|
|||||||
@@ -44,8 +44,10 @@ blitz::Array<double, 3> readFromFile(json_t* object) {
|
|||||||
blitz::Array<double, 3> readComponentFromFile(json_t* object, int component) {
|
blitz::Array<double, 3> readComponentFromFile(json_t* object, int component) {
|
||||||
std::string absolute_filename =
|
std::string absolute_filename =
|
||||||
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
||||||
|
DEBUG_LEVEL_3("path to h5: " + absolute_filename);
|
||||||
std::string key = json_string(
|
std::string key = json_string(
|
||||||
json_array_get(json_object_by_path(object, {"PathToH5"}), component));
|
json_array_get(json_object_by_path(object, {"Keys"}), component));
|
||||||
|
DEBUG_LEVEL_3("key: " + key);
|
||||||
|
|
||||||
Hdf5Reader reader(absolute_filename);
|
Hdf5Reader reader(absolute_filename);
|
||||||
return reader.readD3Double(key);
|
return reader.readD3Double(key);
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
|||||||
double target_accuracy,
|
double target_accuracy,
|
||||||
int num_cycles,
|
int num_cycles,
|
||||||
int solver_intervall,
|
int solver_intervall,
|
||||||
int solver_offset)
|
int solver_offset,
|
||||||
|
bool do_solver)
|
||||||
: bottom_boundary_(bottom_boundary),
|
: bottom_boundary_(bottom_boundary),
|
||||||
top_boundary_(top_boundary),
|
top_boundary_(top_boundary),
|
||||||
hull_boundary_(hull_boundary),
|
hull_boundary_(hull_boundary),
|
||||||
@@ -34,7 +35,8 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
|||||||
target_accuracy_(target_accuracy),
|
target_accuracy_(target_accuracy),
|
||||||
num_cycles_(num_cycles),
|
num_cycles_(num_cycles),
|
||||||
solver_intervall_(solver_intervall),
|
solver_intervall_(solver_intervall),
|
||||||
solver_offset_(solver_offset) {
|
solver_offset_(solver_offset),
|
||||||
|
do_solver_(do_solver) {
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||||
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||||
@@ -84,8 +86,8 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
|||||||
|
|
||||||
void PoissonSolver::solvePotential(
|
void PoissonSolver::solvePotential(
|
||||||
const blitz::Array<double, 3> charge_density, int cpu_sync) {
|
const blitz::Array<double, 3> charge_density, int cpu_sync) {
|
||||||
if ((cpu_sync % solver_intervall_ != 0) || ((cpu_sync <= solver_offset_)
|
if ((!do_solver_) || ((cpu_sync % solver_intervall_ != 0) || ((cpu_sync <= solver_offset_)
|
||||||
&& (cpu_sync > 0))) {
|
&& (cpu_sync > 0)))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DEBUG_LEVEL_3("Interpolating chargedensity.");
|
DEBUG_LEVEL_3("Interpolating chargedensity.");
|
||||||
|
|||||||
+71
-14
@@ -203,10 +203,14 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
while (
|
while (
|
||||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain) &&
|
!(changed_position_bin || changed_energy_bin || left_simulation_domain) &&
|
||||||
(leftover_distance > 0.) && !(died_in_bin)) {
|
(leftover_distance > 0.) && !(died_in_bin)) {
|
||||||
|
std::stringstream out;
|
||||||
old_position = particle->position();
|
old_position = particle->position();
|
||||||
old_velocity = particle->velocity();
|
old_velocity = particle->velocity();
|
||||||
|
|
||||||
|
out << "cylinder vector pos: " << old_position.cartesianEntries() <<"\n";
|
||||||
|
|
||||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
|
// out << " old kinetic Energy: " << old_kinetic_energy << "\n";
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> force_over_charge =
|
blitz::TinyVector<double, 3> force_over_charge =
|
||||||
electric_field->value(old_position).cartesianEntries(old_position);
|
electric_field->value(old_position).cartesianEntries(old_position);
|
||||||
@@ -218,24 +222,40 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
const blitz::TinyVector<double, 3> B =
|
const blitz::TinyVector<double, 3> B =
|
||||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||||
const double B_norm = kinematic::norm(B);
|
const double B_norm = kinematic::norm(B);
|
||||||
// Todo: add calculation of divB here
|
|
||||||
// use Kassiopeia paper for reference
|
out << " B(cyli): " << magnetic_field->value(old_position).cylinderEntries()<<"\n";
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v_parallel =
|
const blitz::TinyVector<double, 3> v_parallel =
|
||||||
kinematic::parallelVector(old_velocity.cartesianEntries(), B);
|
kinematic::parallelVector(old_velocity.cartesianEntries(), B);
|
||||||
const double v_parallel_norm = kinematic::norm(v_parallel);
|
const double v_parallel_norm = kinematic::norm(v_parallel);
|
||||||
|
// out << " v_parallel: " << v_parallel << "\n";
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v_perp =
|
const blitz::TinyVector<double, 3> v_perp =
|
||||||
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
|
kinematic::perpendicularVector(old_velocity.cartesianEntries(), B);
|
||||||
const double v_perp_norm = kinematic::norm(v_perp);
|
const double v_perp_norm = kinematic::norm(v_perp);
|
||||||
|
out << " v_perp: " << v_perp << "\n";
|
||||||
|
|
||||||
// centrifugal and magnetic moment force / q
|
// magnetic moment force / q
|
||||||
// not sure if correct. It might be that the centrifugal force includes only the
|
const double magnetic_moment = (particle->mass_kg()*(v_perp_norm*v_perp_norm/2))/B_norm;
|
||||||
// perpendicular part of grad(B)
|
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() *
|
force_over_charge += -(particle->mass_kg()/particle->charge_C() *
|
||||||
(v_parallel_norm*v_parallel_norm + v_perp_norm*v_perp_norm/2) *
|
(v_parallel_norm*v_parallel_norm) *
|
||||||
magnetic_field->gradientValue(old_position).cartesianEntries(old_position) /
|
kinematic::perpendicularVector(magnetic_field->
|
||||||
|
gradientValue(old_position).cartesianEntries(old_position), B) /
|
||||||
B_norm);
|
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 blitz::TinyVector<double, 3> v_drift = driftVelocity(force_over_charge, B);
|
||||||
const double v_drift_norm = kinematic::norm(v_drift);
|
const double v_drift_norm = kinematic::norm(v_drift);
|
||||||
@@ -246,6 +266,7 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
const double timestep = std::min(
|
const double timestep = std::min(
|
||||||
stepsize / (v_parallel_norm + v_perp_norm + v_drift_norm),
|
stepsize / (v_parallel_norm + v_perp_norm + v_drift_norm),
|
||||||
max_time_alive);
|
max_time_alive);
|
||||||
|
// out << " timestep: " << timestep << "\n";
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> movement_parallel =
|
const blitz::TinyVector<double, 3> movement_parallel =
|
||||||
v_parallel * timestep;
|
v_parallel * timestep;
|
||||||
@@ -253,12 +274,14 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
|
|
||||||
const blitz::TinyVector<double, 3> force_over_charge_parallel =
|
const blitz::TinyVector<double, 3> force_over_charge_parallel =
|
||||||
kinematic::parallelVector(force_over_charge, B);
|
kinematic::parallelVector(force_over_charge, B);
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> dv_electric =
|
const blitz::TinyVector<double, 3> dv_electric =
|
||||||
timestep * particle->charge_C() * force_over_charge_parallel / particle->mass_kg();
|
timestep * particle->charge_C() * force_over_charge_parallel / particle->mass_kg();
|
||||||
|
|
||||||
if (v_perp_norm > SimConstants::compare_epsilon) {
|
if (v_perp_norm > SimConstants::compare_epsilon) {
|
||||||
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
||||||
(B_norm * std::abs(particle->charge_C()));
|
(B_norm * particle->charge_C());
|
||||||
|
// out << " gyroradius: " << gyro_radius << "\n";
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> velocity_normal =
|
const blitz::TinyVector<double, 3> velocity_normal =
|
||||||
(-1) * blitz::cross(B, v_perp);
|
(-1) * blitz::cross(B, v_perp);
|
||||||
@@ -266,23 +289,56 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
const blitz::TinyVector<double, 3> offset_to_gyro_center =
|
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 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 =
|
const double gyro_frequency =
|
||||||
particle->charge_C() * B_norm / particle->mass_kg();
|
particle->charge_C() * B_norm / particle->mass_kg();
|
||||||
const double total_rotation_angle = gyro_frequency * timestep;
|
|
||||||
|
const double total_rotation_angle = -gyro_frequency * timestep;
|
||||||
|
out << " tot rot angle: " << total_rotation_angle << "\n";
|
||||||
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
const blitz::TinyVector<double, 3> movement_around_gyro_center =
|
||||||
kinematic::rotateVector(offset_to_gyro_center, B,
|
offset_to_gyro_center - kinematic::rotateVector(offset_to_gyro_center,
|
||||||
total_rotation_angle) -
|
B, total_rotation_angle);
|
||||||
offset_to_gyro_center;
|
// 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());
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v_perp_rotated =
|
const blitz::TinyVector<double, 3> v_perp_rotated =
|
||||||
kinematic::rotateVector(v_perp, B, total_rotation_angle);
|
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 +
|
particle->move(CartesianCoordinate(movement_parallel + movement_drift +
|
||||||
movement_around_gyro_center));
|
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);
|
||||||
|
|
||||||
particle->velocity(
|
// use the new direction for the actual velocity (nec. for mu to be const)
|
||||||
CartesianVector(v_parallel + v_perp_rotated + dv_electric));
|
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));
|
||||||
} else {
|
} else {
|
||||||
|
// neccessary to adjust as well? i.e. adjust the direction of v_parallel
|
||||||
particle->move(CartesianCoordinate(movement_parallel + movement_drift));
|
particle->move(CartesianCoordinate(movement_parallel + movement_drift));
|
||||||
particle->velocity(CartesianVector(v_parallel + dv_electric));
|
particle->velocity(CartesianVector(v_parallel + dv_electric));
|
||||||
}
|
}
|
||||||
@@ -307,6 +363,7 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||||
|
|
||||||
leftover_distance -= stepsize;
|
leftover_distance -= stepsize;
|
||||||
|
DEBUG_LEVEL_3(out.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
particle->specie()->dynamicDensityField()->logMovement(
|
particle->specie()->dynamicDensityField()->logMovement(
|
||||||
|
|||||||
Reference in New Issue
Block a user