Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4638a6563c | ||
|
|
324da20d4a |
+7
-54
@@ -1,6 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib
|
import matplotlib
|
||||||
# matplotlib.use("agg")
|
matplotlib.use("agg")
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import h5py
|
import h5py
|
||||||
import argparse
|
import argparse
|
||||||
@@ -93,46 +93,6 @@ def get_time_and_wall_losses(files, considered_keys=['All']):
|
|||||||
|
|
||||||
return times, phys_wall_loss
|
return times, phys_wall_loss
|
||||||
|
|
||||||
def get_time_and_scatter_losses(files, considered_keys=['All']):
|
|
||||||
times = []
|
|
||||||
scatter_loss = []
|
|
||||||
for file in files:
|
|
||||||
with h5py.File(file, 'r') as cfile:
|
|
||||||
time = 0
|
|
||||||
for key in cfile.keys():
|
|
||||||
if(key == "PoissonSolver" or key == "RestartInfo" or key == 'NumberProcesses'):
|
|
||||||
continue
|
|
||||||
if (not considered_keys[0] == 'All') and (not key in considered_keys):
|
|
||||||
continue
|
|
||||||
cfile_specieslogger = cfile[key]['DeletionLogger']
|
|
||||||
|
|
||||||
for time_key in cfile_specieslogger.keys():
|
|
||||||
time = cfile[key]['DensityField/SimulationData'][time_key]['PhysicalTime'][0]
|
|
||||||
deltat = cfile[key]['CurrentCollector/SimulationData'][time_key]['PhysicalTime'][0]
|
|
||||||
try:
|
|
||||||
index = times.index(time)
|
|
||||||
try:
|
|
||||||
scatter_loss[index] += cfile_specieslogger[time_key]\
|
|
||||||
['NumDeletions/LargeEnergyTransfer'][0]/deltat
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except:
|
|
||||||
times.append(time)
|
|
||||||
try:
|
|
||||||
scatter_loss.append(cfile_specieslogger[time_key]\
|
|
||||||
['NumDeletions/LargeEnergyTransfer'][0]/deltat)
|
|
||||||
except:
|
|
||||||
scatter_loss.append(-1)
|
|
||||||
|
|
||||||
times = np.array(times)
|
|
||||||
scatter_loss = np.array(scatter_loss)
|
|
||||||
|
|
||||||
sorting_mask = np.argsort(times)
|
|
||||||
times = times[sorting_mask]
|
|
||||||
scatter_loss = scatter_loss[sorting_mask]
|
|
||||||
|
|
||||||
return times, scatter_loss
|
|
||||||
|
|
||||||
def getFiles(dir:str, base_name:str, pattern:str) :
|
def getFiles(dir:str, base_name:str, pattern:str) :
|
||||||
if dir[-1] == '/':
|
if dir[-1] == '/':
|
||||||
pathname = dir + base_name
|
pathname = dir + base_name
|
||||||
@@ -145,7 +105,7 @@ if __name__ == '__main__':
|
|||||||
parser = argparse.ArgumentParser(description="Program to create a plot of the charge against time from the output of KARL")
|
parser = argparse.ArgumentParser(description="Program to create a plot of the charge against time from the output of KARL")
|
||||||
parser.add_argument("dir", type = str, help="directory where the files are stored in")
|
parser.add_argument("dir", type = str, help="directory where the files are stored in")
|
||||||
parser.add_argument("basename", type = str, help = 'identifying pattern of the files (i.e. basename[0-9]*\\.h5])')
|
parser.add_argument("basename", type = str, help = 'identifying pattern of the files (i.e. basename[0-9]*\\.h5])')
|
||||||
parser.add_argument('--losses', nargs='?', choices=['Wall', 'Scattering'], help = 'choose to create loss rate plot (either from wall losses or due to scatterings)')
|
parser.add_argument('--losses', action='store_true', help = 'create wall loss rate plot instead')
|
||||||
parser.add_argument("--pattern", type = str, nargs = '?', help = 'Regular expression pattern, that specifies the naming of the files (by default [0-9]*). Gets added to dir+basename+pattern+".h5".', default = '[0-9]*')
|
parser.add_argument("--pattern", type = str, nargs = '?', help = 'Regular expression pattern, that specifies the naming of the files (by default [0-9]*). Gets added to dir+basename+pattern+".h5".', default = '[0-9]*')
|
||||||
parser.add_argument("--width", type = str, nargs = '?', default="thesis", help = "Either \'thesis\' or \'beamer\' as defined in plot_standards.py")
|
parser.add_argument("--width", type = str, nargs = '?', default="thesis", help = "Either \'thesis\' or \'beamer\' as defined in plot_standards.py")
|
||||||
parser.add_argument("--fraction", type = float, default=1, nargs="?", help= "the fraction of width that the plot should occupy, as defined in plot_standards.py")
|
parser.add_argument("--fraction", type = float, default=1, nargs="?", help= "the fraction of width that the plot should occupy, as defined in plot_standards.py")
|
||||||
@@ -165,11 +125,8 @@ if __name__ == '__main__':
|
|||||||
print(f"{args.width} is not a valid parameter for width; fall back to \'thesis\'")
|
print(f"{args.width} is not a valid parameter for width; fall back to \'thesis\'")
|
||||||
args.width = 'thesis'
|
args.width = 'thesis'
|
||||||
|
|
||||||
if args.losses in ['Wall', 'Scattering']:
|
if args.losses:
|
||||||
if args.losses == 'Wall':
|
times, charges = get_time_and_wall_losses(files, args.species)
|
||||||
times, charges = get_time_and_wall_losses(files, args.species)
|
|
||||||
else:
|
|
||||||
times, charges = get_time_and_scatter_losses(files, args.species)
|
|
||||||
else:
|
else:
|
||||||
times, charges = get_time_and_total_charge_(files, args.species)
|
times, charges = get_time_and_total_charge_(files, args.species)
|
||||||
|
|
||||||
@@ -181,11 +138,9 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
plt.rcParams.update({'font.size': 10})
|
plt.rcParams.update({'font.size': 10})
|
||||||
fig = plt.figure(figsize=pst.set_size(args.width))
|
fig = plt.figure(figsize=pst.set_size(args.width))
|
||||||
plt.plot(times, charges, marker = '.', label = legstr)
|
plt.plot(times, charges, marker = 'x', label = legstr)
|
||||||
if args.losses == 'Wall':
|
if args.losses:
|
||||||
plt.ylabel('loss rate (1/s)')
|
plt.ylabel('loss rate (1/s)')
|
||||||
elif args.losses == 'Scattering':
|
|
||||||
plt.ylabel("upscattering (particles/s)")
|
|
||||||
else:
|
else:
|
||||||
plt.ylabel('charge (C)')
|
plt.ylabel('charge (C)')
|
||||||
plt.xlabel('time (s)')
|
plt.xlabel('time (s)')
|
||||||
@@ -201,10 +156,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
os.makedirs(outname, exist_ok=True)
|
os.makedirs(outname, exist_ok=True)
|
||||||
|
|
||||||
if args.losses == 'Wall':
|
if args.losses:
|
||||||
outname += args.basename + "_wallLossRateAgainstTime_species-"
|
outname += args.basename + "_wallLossRateAgainstTime_species-"
|
||||||
elif args.losses == 'Scattering':
|
|
||||||
outname += args.basename + "_scatteringLossRateAgainstTime_species-"
|
|
||||||
else:
|
else:
|
||||||
outname += args.basename + "_chargeAgainstTime_species-"
|
outname += args.basename + "_chargeAgainstTime_species-"
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class MpiParticleReader {
|
|||||||
MpiParticleReader(std::string abs_filename_without_extension, int restart_at);
|
MpiParticleReader(std::string abs_filename_without_extension, int restart_at);
|
||||||
|
|
||||||
void readParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
void readParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
||||||
void readParticles(std::vector<particle::SerializedParticle>& storage_queue, int nold);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string absolute_filename_;
|
std::string absolute_filename_;
|
||||||
|
|||||||
@@ -46,11 +46,9 @@ class Restart {
|
|||||||
// only load in the potential and calc the electric field
|
// only load in the potential and calc the electric field
|
||||||
void restartPoissonSolver(PoissonSolver* solver);
|
void restartPoissonSolver(PoissonSolver* solver);
|
||||||
void restartRandomNumbers(RandomNumbers* random);
|
void restartRandomNumbers(RandomNumbers* random);
|
||||||
void restartRandomNumbers(RandomNumbers* random, int nold);
|
|
||||||
void restartParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
void restartParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
||||||
|
|
||||||
bool do_restart_;
|
bool do_restart_;
|
||||||
int process_number_old_; // number of processes of the state the simulation is restarted from
|
|
||||||
std::string restart_identifier_; // i.e. "LastSyncPeriod" or "SyncPeriod_*"
|
std::string restart_identifier_; // i.e. "LastSyncPeriod" or "SyncPeriod_*"
|
||||||
Hdf5Reader reader_;
|
Hdf5Reader reader_;
|
||||||
MpiParticleReader particle_reader_;
|
MpiParticleReader particle_reader_;
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ class SimulationOutput {
|
|||||||
|
|
||||||
void writeMetaData(
|
void writeMetaData(
|
||||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||||
const std::shared_ptr<PoissonSolver>& poisson_solver,
|
const std::shared_ptr<PoissonSolver>& poisson_solver);
|
||||||
std::string parameter_file_path);
|
|
||||||
|
|
||||||
void writeSimulationData(
|
void writeSimulationData(
|
||||||
int cpu_sync,
|
int cpu_sync,
|
||||||
@@ -53,6 +52,11 @@ class SimulationOutput {
|
|||||||
std::vector<particle::SerializedParticle>& storage_queue,
|
std::vector<particle::SerializedParticle>& storage_queue,
|
||||||
int injectionGroupOffset);
|
int injectionGroupOffset);
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
void setResetCurrentCollector(int cpu_sync,
|
||||||
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species);
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<OutputTask> tasks_density_fields_;
|
std::vector<OutputTask> tasks_density_fields_;
|
||||||
std::vector<OutputTask> tasks_current_collector_;
|
std::vector<OutputTask> tasks_current_collector_;
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ class CurrentCollector {
|
|||||||
blitz::Array<double, 2> areaInZ() const;
|
blitz::Array<double, 2> areaInZ() const;
|
||||||
blitz::Array<double, 2> currentInZ() const;
|
blitz::Array<double, 2> currentInZ() const;
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
blitz::Array<double, 2> sampleNegativeCrossings() const;
|
||||||
|
std::vector<double> energyBinBorders() const;
|
||||||
|
void needsReset() { needs_reset = true; };
|
||||||
|
bool getNeedsReset() const { return needs_reset; };
|
||||||
|
double timeSinceReset() const {return time_since_reset;};
|
||||||
|
#endif //GENRICHCURRENT
|
||||||
|
|
||||||
double physicalTime() const;
|
double physicalTime() const;
|
||||||
|
|
||||||
void resetCurrentCollector();
|
void resetCurrentCollector();
|
||||||
@@ -41,6 +49,9 @@ class CurrentCollector {
|
|||||||
const double weight);
|
const double weight);
|
||||||
void collectLongitudinalMovement(const blitz::TinyVector<int, 2>& bin_old,
|
void collectLongitudinalMovement(const blitz::TinyVector<int, 2>& bin_old,
|
||||||
const blitz::TinyVector<int, 2>& bin_new,
|
const blitz::TinyVector<int, 2>& bin_new,
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
const double energy_eV,
|
||||||
|
#endif
|
||||||
const double weight);
|
const double weight);
|
||||||
void collectAzimuthalMovement(const blitz::TinyVector<double, 3>& old_pos_cart,
|
void collectAzimuthalMovement(const blitz::TinyVector<double, 3>& old_pos_cart,
|
||||||
const blitz::TinyVector<double, 3>& new_pos_cart,
|
const blitz::TinyVector<double, 3>& new_pos_cart,
|
||||||
@@ -71,19 +82,18 @@ class CurrentCollector {
|
|||||||
blitz::Array<double, 2> r_negative_crossings;
|
blitz::Array<double, 2> r_negative_crossings;
|
||||||
blitz::Array<double, 2> r_positive_crossings;
|
blitz::Array<double, 2> r_positive_crossings;
|
||||||
|
|
||||||
// blitz::Array<double, 3> sync_z_negative_crossings;
|
|
||||||
// blitz::Array<double, 3> sync_z_positive_crossings;
|
|
||||||
|
|
||||||
// blitz::Array<double, 3> sync_phi_negative_crossings;
|
|
||||||
// blitz::Array<double, 3> sync_phi_positive_crossings;
|
|
||||||
|
|
||||||
// blitz::Array<double, 3> sync_r_negative_crossings;
|
|
||||||
// blitz::Array<double, 3> sync_r_positive_crossings;
|
|
||||||
|
|
||||||
blitz::Array<double, 2> collector_areas_r;
|
blitz::Array<double, 2> collector_areas_r;
|
||||||
blitz::Array<double, 2> collector_areas_phi;
|
blitz::Array<double, 2> collector_areas_phi;
|
||||||
blitz::Array<double, 2> collector_areas_z;
|
blitz::Array<double, 2> collector_areas_z;
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
blitz::Array<double, 2> sample_z_negative_crossings;
|
||||||
|
EnergyBinning energy_binning_;
|
||||||
|
|
||||||
|
bool needs_reset = false;
|
||||||
|
double time_since_reset = 0;
|
||||||
|
#endif //GENRICHCURRENT
|
||||||
|
|
||||||
CylinderBinning position_binning_;
|
CylinderBinning position_binning_;
|
||||||
std::shared_ptr<Timer> timer_;
|
std::shared_ptr<Timer> timer_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -26,38 +26,4 @@ class Cylinder : public Geometry {
|
|||||||
const double height_;
|
const double height_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
/|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾\ ‾‾‾
|
|
||||||
/ | | \ ^
|
|
||||||
/ | | \ |
|
|
||||||
/ | | \ | R_cylinder
|
|
||||||
/ | | \ ⌄
|
|
||||||
|<-->|<------------------>|<------------------><---> ---
|
|
||||||
z=0 ^ ^ |
|
|
||||||
| | |
|
|
||||||
H_cone H_cylinder symmetry axis
|
|
||||||
|
|
||||||
The geometry will only know 3 regions, "inside", "hull", "top". Meaning the
|
|
||||||
cone will always have the same boundary condition as the cylinder boundary.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
Geometry of a cylinder with a cone as the end with its tip at z=0.
|
|
||||||
*/
|
|
||||||
class HalfCylinderWithCone : public Geometry {
|
|
||||||
public:
|
|
||||||
HalfCylinderWithCone(double radiusCylinder, double heightCylinder,
|
|
||||||
double heightCone, double zfrustum);
|
|
||||||
bool isInside(const Coordinate& position) const;
|
|
||||||
GeometryPositioning isWhere(const Coordinate& position) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
const double cylinder_radius_;
|
|
||||||
const double cylinder_height_;
|
|
||||||
const double cone_height_;
|
|
||||||
const double z_frustum_;
|
|
||||||
|
|
||||||
double localRadius(double z) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* GEOMETRY_H */
|
#endif /* GEOMETRY_H */
|
||||||
|
|||||||
@@ -46,8 +46,6 @@ class Interaction {
|
|||||||
std::function<double(double)> cross_section_;
|
std::function<double(double)> cross_section_;
|
||||||
std::shared_ptr<species::Specie> target_;
|
std::shared_ptr<species::Specie> target_;
|
||||||
CartesianVector target_velocity_;
|
CartesianVector target_velocity_;
|
||||||
|
|
||||||
double threshold_increase_J = 6.9032515e-26; // J (5 mK)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}; // namespace interaction
|
}; // namespace interaction
|
||||||
|
|||||||
@@ -16,10 +16,8 @@ enum class DeletionType {
|
|||||||
|
|
||||||
// to count physical particle deletion
|
// to count physical particle deletion
|
||||||
enum class PhysicalDeletionType {
|
enum class PhysicalDeletionType {
|
||||||
wall,
|
wall
|
||||||
large_energy_transfer
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Coordinate;
|
class Coordinate;
|
||||||
|
|
||||||
class DeletionLogger {
|
class DeletionLogger {
|
||||||
|
|||||||
@@ -83,8 +83,6 @@ class Simulation {
|
|||||||
|
|
||||||
int timestep = 0;
|
int timestep = 0;
|
||||||
int injectionGroupOffset = 0;
|
int injectionGroupOffset = 0;
|
||||||
|
|
||||||
std::string parameter_file_path_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SIMULATION_H */
|
#endif /* SIMULATION_H */
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include "simulation/coordinates.h"
|
#include "simulation/coordinates.h"
|
||||||
#include "simulation/position_binning.h"
|
#include "simulation/position_binning.h"
|
||||||
#include "constants/physical_constants.h"
|
|
||||||
|
|
||||||
class VectorField {
|
class VectorField {
|
||||||
public:
|
public:
|
||||||
@@ -51,34 +50,4 @@ class VectorFieldFunctionInZ : public VectorField {
|
|||||||
std::function<double(double, double, double)> F_z_;
|
std::function<double(double, double, double)> F_z_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Vector field implementing the analytical approximation to the
|
|
||||||
// magnetic field in the Project 8 LFA case, all parameters are hard-coded for now
|
|
||||||
// Note that only one half of the whole system is considered -> only one Gaussian peak
|
|
||||||
class PredefinedMagneticVectorFieldLFA : public VectorField {
|
|
||||||
public:
|
|
||||||
PredefinedMagneticVectorFieldLFA();
|
|
||||||
// Important: coordinate has to be a Cartesian Coordinate in oder for the calculation to be correct
|
|
||||||
CylinderVector value(const Coordinate& coordinate) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
// half opening angle of the cones = 35 deg, I_Ioffe = 5kA
|
|
||||||
const double cosa = std::cos(M_PI*35./180.);
|
|
||||||
const double sina = std::sin(M_PI*35./180.);
|
|
||||||
const double B0Ioffe = SI::mu0*5000/(2*M_PI); // Tm
|
|
||||||
// background field
|
|
||||||
const double Bbg = 0.0207; // T
|
|
||||||
// radius of ioffe wires
|
|
||||||
const double RIoffe = 0.3326; // m
|
|
||||||
// steepness of transition functions, currently not used
|
|
||||||
const double c1 = 10.; // 1/m
|
|
||||||
const double c2 = 100.; // 1/m
|
|
||||||
|
|
||||||
blitz::Array<double, 1> cosktheta{128};
|
|
||||||
blitz::Array<double, 1> sinktheta{128};
|
|
||||||
// z1, z2 in the system, where the Ioffe cone tip is in the origin,
|
|
||||||
// zoffset the distance between ioffe cone tip and cavity cone tip,
|
|
||||||
// z1 is the start of the ioffe frustum and z2 the transition from cone to cylinder
|
|
||||||
double z1, z2, zoffset;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* VECTOR_FIELD_H */
|
#endif /* VECTOR_FIELD_H */
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ LIBS =#-static
|
|||||||
|
|
||||||
CXXFLAGS += -DHOMEBASE=$(HOMEBASE)
|
CXXFLAGS += -DHOMEBASE=$(HOMEBASE)
|
||||||
|
|
||||||
|
#CXXFLAGS += -Ddebug_timedist
|
||||||
|
|
||||||
# Blitz
|
# Blitz
|
||||||
CXXFLAGS += $(BLITZ_INCLUDES)
|
CXXFLAGS += $(BLITZ_INCLUDES)
|
||||||
LIBS += $(BLITZ_LIBS)
|
LIBS += $(BLITZ_LIBS)
|
||||||
@@ -55,6 +57,10 @@ ifeq ($(DO_DEBUGGING),true)
|
|||||||
CXXFLAGS += -Ddebug_level$(DEBUG_LEVEL)
|
CXXFLAGS += -Ddebug_level$(DEBUG_LEVEL)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(DO_GENRICHCURRENT),true)
|
||||||
|
CXXFLAGS += -DGENRICHCURRENT #-Ddebug_genrich
|
||||||
|
endif
|
||||||
|
|
||||||
# Catch2
|
# Catch2
|
||||||
CXXFLAGS += $(CATCH_INCLUDES)
|
CXXFLAGS += $(CATCH_INCLUDES)
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -20,7 +20,7 @@ blitz::Array<double, 3> Hdf5Reader::readD3Double(std::string path) {
|
|||||||
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -50,7 +50,7 @@ blitz::Array<double, 2> Hdf5Reader::readD2Double(std::string path) {
|
|||||||
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -79,7 +79,7 @@ blitz::Array<double, 1> Hdf5Reader::readD1Double(std::string path) {
|
|||||||
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -109,7 +109,7 @@ double Hdf5Reader::readDouble(std::string path) {
|
|||||||
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -139,7 +139,7 @@ int Hdf5Reader::readInt(std::string path) {
|
|||||||
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -170,7 +170,7 @@ blitz::Array<double, 4> Hdf5Reader::readD4Double(std::string path) {
|
|||||||
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -200,7 +200,7 @@ blitz::Array<double, 5> Hdf5Reader::readD5Double(std::string path) {
|
|||||||
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -230,7 +230,7 @@ blitz::Array<long int, 4> Hdf5Reader::readD4LongInt(std::string path) {
|
|||||||
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -260,7 +260,7 @@ blitz::Array<long int, 5> Hdf5Reader::readD5LongInt(std::string path) {
|
|||||||
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
@@ -293,7 +293,7 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) {
|
|||||||
hid_t dataset = H5Dopen2(file, (path + "/string").c_str(), H5P_DEFAULT);
|
hid_t dataset = H5Dopen2(file, (path + "/string").c_str(), H5P_DEFAULT);
|
||||||
hid_t dataspace = H5Dget_space(dataset);
|
hid_t dataspace = H5Dget_space(dataset);
|
||||||
if (dataset < 0) {
|
if (dataset < 0) {
|
||||||
ERROR("The given dataset could not be opened " + path);
|
ERROR("The given dataset could not be opened");
|
||||||
}
|
}
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
// turn error report back onby hdf5 because of check H5Dopen2
|
||||||
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||||
|
|||||||
@@ -145,169 +145,3 @@ void MpiParticleReader::readParticles(
|
|||||||
MPI_Type_free(&cpu_header_type);
|
MPI_Type_free(&cpu_header_type);
|
||||||
MPI_Info_free(&info);
|
MPI_Info_free(&info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MpiParticleReader::readParticles(
|
|
||||||
std::vector<particle::SerializedParticle>& storage_queue, int nold) {
|
|
||||||
MPI_Comm io_comm;
|
|
||||||
// io_group: from which previous process has to be read
|
|
||||||
// io_rank : the rank of this process within io_group
|
|
||||||
// io_group_size: the size of the group of processes with a specific io_group
|
|
||||||
int io_rank, io_group, io_group_size;
|
|
||||||
|
|
||||||
io_comm = MPI_COMM_WORLD;
|
|
||||||
io_group = MpiCommunication::mpiRank() % nold;
|
|
||||||
io_rank = MpiCommunication::mpiRank() / nold;
|
|
||||||
io_group_size = MpiCommunication::mpiSize() / nold;
|
|
||||||
if(io_group < MpiCommunication::mpiSize() % nold) {
|
|
||||||
io_group_size += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef debug_level3
|
|
||||||
fprintf(stdout, "<%d>: io_group: %d, io_rank: %d, io_group_size: %d\n",
|
|
||||||
MpiCommunication::mpiRank(), io_group, io_rank, io_group_size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef debug
|
|
||||||
DEBUG_LEVEL_0("Reading particles from: " + absolute_filename_);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int status;
|
|
||||||
|
|
||||||
MPI_Datatype particle_type;
|
|
||||||
if(sizeof(particle::SerializedParticle) % sizeof(double) != 0) {
|
|
||||||
ERROR("Size of SerializedParticle is not a multiple of the size of double!");
|
|
||||||
}
|
|
||||||
status = MPI_Type_contiguous(sizeof(particle::SerializedParticle)/sizeof(double),
|
|
||||||
MPI_DOUBLE, &particle_type);
|
|
||||||
status |= MPI_Type_commit(&particle_type);
|
|
||||||
|
|
||||||
if(status) {
|
|
||||||
ERROR("Particle data type could not be defined!");
|
|
||||||
}
|
|
||||||
|
|
||||||
MPI_Info info;
|
|
||||||
MPI_Info_create(&info);
|
|
||||||
|
|
||||||
// open file
|
|
||||||
MPI_File file;
|
|
||||||
MPI_Status mstatus;
|
|
||||||
|
|
||||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
|
||||||
DEBUG_LEVEL_1("Reading particles from: " + absolute_filename_);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
status = MPI_File_open(io_comm, (char*)absolute_filename_.c_str(),
|
|
||||||
MPI_MODE_RDONLY, info, &file);
|
|
||||||
if(status) {
|
|
||||||
ERROR("Particle file \'" + absolute_filename_ + "\' could not be opened!");
|
|
||||||
}
|
|
||||||
|
|
||||||
//read file header
|
|
||||||
MPI_Datatype file_header_type = build_file_header_type();
|
|
||||||
mpi_io_header_t file_header;
|
|
||||||
status = MPI_File_set_view(file, 0, file_header_type, file_header_type,
|
|
||||||
(char*)"native", info);
|
|
||||||
if(status) {
|
|
||||||
ERROR("View for file header could not be set!");
|
|
||||||
}
|
|
||||||
|
|
||||||
status = MPI_File_read_all(file, &file_header, 1, file_header_type, &mstatus);
|
|
||||||
if(status) {
|
|
||||||
ERROR("File header could not be read (status: " + std::to_string(status) +
|
|
||||||
")!");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!file_header.verify()) {
|
|
||||||
ERROR("File header does not verify!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// read CPU header
|
|
||||||
std::uint64_t headeroffset = file_header.cpu_header_offset +
|
|
||||||
sizeof(cpu_header_t)*io_group;
|
|
||||||
|
|
||||||
MPI_Datatype cpu_header_type = build_cpu_header_type();
|
|
||||||
cpu_header_t cpu_header;
|
|
||||||
|
|
||||||
status = MPI_File_set_view(file, headeroffset, cpu_header_type, cpu_header_type,
|
|
||||||
(char*)"native", info);
|
|
||||||
if(status) {
|
|
||||||
ERROR("File view for the CPU header could not be set!");
|
|
||||||
}
|
|
||||||
|
|
||||||
status = MPI_File_read_all(file, &cpu_header, 1, cpu_header_type, &mstatus);
|
|
||||||
if(status) {
|
|
||||||
ERROR("CPU header could not be read!");
|
|
||||||
}
|
|
||||||
|
|
||||||
storage_queue.reserve(cpu_header.num_particles);
|
|
||||||
|
|
||||||
// particle number if they were equally distributed across procs
|
|
||||||
size_t particle_number = cpu_header.num_particles / io_group_size;
|
|
||||||
|
|
||||||
int overflow = cpu_header.num_particles % io_group_size;
|
|
||||||
|
|
||||||
// calculate offset from particles read by other processes in this io_group
|
|
||||||
std::uint64_t this_offset = cpu_header.file_offset;
|
|
||||||
this_offset += io_rank*particle_number*sizeof(particle::SerializedParticle);
|
|
||||||
// fprintf(stdout, "<%d>: offset: %ld, numpart: %ld\n", MpiCommunication::mpiRank(), this_offset, particle_number);
|
|
||||||
this_offset = io_rank < overflow ? this_offset + io_rank*sizeof(particle::SerializedParticle)
|
|
||||||
: this_offset + overflow*sizeof(particle::SerializedParticle);
|
|
||||||
// fprintf(stdout, "<%d>: offset: %ld, sizeof(SerializedParticle): %ld\n", MpiCommunication::mpiRank(), this_offset, sizeof(particle::SerializedParticle));
|
|
||||||
|
|
||||||
// correct number of particles for this proc
|
|
||||||
particle_number = (io_rank < overflow) ? particle_number + 1 : particle_number;
|
|
||||||
|
|
||||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
|
||||||
{
|
|
||||||
std::stringstream out;
|
|
||||||
out << io_rank << ": trying to read " << cpu_header.num_particles;
|
|
||||||
out << " many particles";
|
|
||||||
DEBUG_LEVEL_1(out.str());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// set file view to the part where the particles are stored
|
|
||||||
status = MPI_File_set_view(file, this_offset, MPI_DOUBLE,
|
|
||||||
particle_type, (char*)"native", info);
|
|
||||||
if(status) {
|
|
||||||
ERROR("File view for the Particles could not be set!");
|
|
||||||
}
|
|
||||||
|
|
||||||
storage_queue.resize(particle_number);
|
|
||||||
|
|
||||||
// read the particles
|
|
||||||
status = MPI_File_read_all(file, storage_queue.data(), particle_number,
|
|
||||||
particle_type, &mstatus);
|
|
||||||
if(status) {
|
|
||||||
ERROR("Particles could not be read (status: " + std::to_string(status) +
|
|
||||||
")!");
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef debug_level3
|
|
||||||
{
|
|
||||||
// print first and last loaded particle to check if the alignment is sensible (i.e. no two processes load the same particle)
|
|
||||||
std::stringstream out;
|
|
||||||
out << "group: " << io_group << ", rank: "<< io_rank;
|
|
||||||
out << ": number of particles in queue: " << storage_queue.size();
|
|
||||||
out << "\nposition of first serialized particle: " << storage_queue[0].cartesianPosition();
|
|
||||||
out << "\nvelocity of first serialized particle: " << storage_queue[0].cartesianVelocity();
|
|
||||||
out << "\nweight of first serialized particle: " << storage_queue[0].weight();
|
|
||||||
out << "\nspecname of first serialized particle: " << storage_queue[0].specieName();
|
|
||||||
out << "\n";
|
|
||||||
out << "group: " << io_group << ", rank: "<< io_rank;
|
|
||||||
out << "\nposition of last serialized particle: " << storage_queue[particle_number - 1].cartesianPosition();
|
|
||||||
out << "\nvelocity of last serialized particle: " << storage_queue[particle_number - 1].cartesianVelocity();
|
|
||||||
out << "\nweight of last serialized particle: " << storage_queue[particle_number - 1].weight();
|
|
||||||
out << "\nspecname of last serialized particle: " << storage_queue[particle_number - 1].specieName();
|
|
||||||
DEBUG_LEVEL_1(out.str());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// close everything
|
|
||||||
MPI_File_close(&file);
|
|
||||||
MPI_Type_free(&particle_type);
|
|
||||||
MPI_Type_free(&file_header_type);
|
|
||||||
MPI_Type_free(&cpu_header_type);
|
|
||||||
MPI_Info_free(&info);
|
|
||||||
}
|
|
||||||
+9
-74
@@ -39,46 +39,10 @@ void Restart::restart(
|
|||||||
if(!do_restart_) {
|
if(!do_restart_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifdef debug_level1
|
||||||
SIM_INFO("Reading number of previous processes.");
|
DEBUG_LEVEL_1("Restarting rng");
|
||||||
process_number_old_ = reader_.readInt("NumberProcesses");
|
#endif
|
||||||
|
restartRandomNumbers(random_numbers);
|
||||||
if(process_number_old_ > MpiCommunication::mpiSize()) {
|
|
||||||
ERROR("Number of processes changes between restart! (old: " + std::to_string(process_number_old_)
|
|
||||||
+ ", new: " + std::to_string(MpiCommunication::mpiSize()) + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
SIM_INFO("Restarting from earlier state.");
|
|
||||||
|
|
||||||
if(process_number_old_ < MpiCommunication::mpiSize()) {
|
|
||||||
SIM_INFO("Warning: Restarting from a state with fewer processes. (#old: " +
|
|
||||||
std::to_string(process_number_old_) +
|
|
||||||
", #now: " +
|
|
||||||
std::to_string(MpiCommunication::mpiSize()) + ")");
|
|
||||||
|
|
||||||
#ifdef debug_level1
|
|
||||||
DEBUG_LEVEL_1("Restarting rng");
|
|
||||||
#endif
|
|
||||||
restartRandomNumbers(random_numbers, process_number_old_);
|
|
||||||
|
|
||||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
|
||||||
DEBUG_LEVEL_1("Reloading particles.");
|
|
||||||
#endif
|
|
||||||
particle_reader_.readParticles(storage_queue, process_number_old_);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
#ifdef debug_level1
|
|
||||||
DEBUG_LEVEL_1("Restarting rng");
|
|
||||||
#endif
|
|
||||||
restartRandomNumbers(random_numbers);
|
|
||||||
|
|
||||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
|
||||||
DEBUG_LEVEL_1("Reloading particles.");
|
|
||||||
#endif
|
|
||||||
particle_reader_.readParticles(storage_queue);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef debug_level1
|
#ifdef debug_level1
|
||||||
DEBUG_LEVEL_1("Restarting poisson solver.");
|
DEBUG_LEVEL_1("Restarting poisson solver.");
|
||||||
@@ -101,6 +65,11 @@ void Restart::restart(
|
|||||||
std::string path = "/RestartInfo/" + restart_identifier_ + "/InjectionGroupOffset";
|
std::string path = "/RestartInfo/" + restart_identifier_ + "/InjectionGroupOffset";
|
||||||
injectionGroupOffset = reader_.readInt(path);
|
injectionGroupOffset = reader_.readInt(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
||||||
|
DEBUG_LEVEL_1("Reloading particles.");
|
||||||
|
#endif
|
||||||
|
particle_reader_.readParticles(storage_queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Restart::restartRandomNumbers(RandomNumbers* random) {
|
void Restart::restartRandomNumbers(RandomNumbers* random) {
|
||||||
@@ -119,40 +88,6 @@ void Restart::restartRandomNumbers(RandomNumbers* random) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Restart::restartRandomNumbers(RandomNumbers* random, int nold) {
|
|
||||||
int io_group, io_rank;
|
|
||||||
io_group = MpiCommunication::mpiRank() % nold;
|
|
||||||
io_rank = MpiCommunication::mpiRank() / nold;
|
|
||||||
|
|
||||||
std::string path = "/RestartInfo/" + restart_identifier_
|
|
||||||
+ "/CPU_" + std::to_string(io_group);
|
|
||||||
std::stringstream engine_state = reader_.readEngineString(path);
|
|
||||||
std::mt19937* engine = random->engine();
|
|
||||||
engine_state >> *engine;
|
|
||||||
|
|
||||||
std::stringstream check;
|
|
||||||
check << *engine;
|
|
||||||
|
|
||||||
if(check.str() != engine_state.str()) {
|
|
||||||
ERROR("Something went wrong in the initialization of the "
|
|
||||||
"random engine.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// discard the first io_rank values
|
|
||||||
(*engine).discard(io_rank);
|
|
||||||
// draw the next value of the current engine
|
|
||||||
size_t seed = (*engine)();
|
|
||||||
|
|
||||||
// fprintf(stdout, "<%d>: io_group: %d, seed: %ld\n", MpiCommunication::mpiRank(), io_group, seed);
|
|
||||||
|
|
||||||
// use this value as a seed and create a temporary mt19937 object
|
|
||||||
std::mt19937 tmp(seed);
|
|
||||||
|
|
||||||
// serialize and de-serialize it to set the pointer of the actual engine (likely not the best implementation)
|
|
||||||
engine_state << tmp;
|
|
||||||
engine_state >> *engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only restart the time from which the simulation is restarted.
|
// only restart the time from which the simulation is restarted.
|
||||||
void Restart::restartTimer(species::TrackedSpecie* reference_specie) {
|
void Restart::restartTimer(species::TrackedSpecie* reference_specie) {
|
||||||
double time;
|
double time;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#include <fstream>
|
|
||||||
#include "mpi.h"
|
#include "mpi.h"
|
||||||
#include "IO/simulation_output.h"
|
#include "IO/simulation_output.h"
|
||||||
#include "IO/hdf5_writer.h"
|
#include "IO/hdf5_writer.h"
|
||||||
@@ -44,8 +43,7 @@ void SimulationOutput::setParticleOutput(OutputTask task) {
|
|||||||
|
|
||||||
void SimulationOutput::writeMetaData(
|
void SimulationOutput::writeMetaData(
|
||||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||||
const std::shared_ptr<PoissonSolver>& poisson_solver,
|
const std::shared_ptr<PoissonSolver>& poisson_solver) {
|
||||||
std::string parameter_file_path) {
|
|
||||||
if (MpiCommunication::mpi_rank == 0) {
|
if (MpiCommunication::mpi_rank == 0) {
|
||||||
for (auto& pair : species) {
|
for (auto& pair : species) {
|
||||||
writeMetaData(pair.second.get());
|
writeMetaData(pair.second.get());
|
||||||
@@ -68,27 +66,10 @@ void SimulationOutput::writeMetaData(
|
|||||||
writeMetaData(poisson_solver.get(), specie_path);
|
writeMetaData(poisson_solver.get(), specie_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the number of mpi processes used in the current simulation
|
// write the number of mpi processes used in the current simulation
|
||||||
{
|
{
|
||||||
writer.write(MpiCommunication::mpiSize(), "/NumberProcesses");
|
writer.write(MpiCommunication::mpiSize(), "/NumberProcesses");
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the json file to the hdf output
|
|
||||||
{
|
|
||||||
std::stringstream file;
|
|
||||||
std::ifstream istream(parameter_file_path.c_str());
|
|
||||||
istream >> file.rdbuf();
|
|
||||||
|
|
||||||
// find occurance of last slash in the path of the parameter
|
|
||||||
size_t slshidx = parameter_file_path.rfind("/");
|
|
||||||
|
|
||||||
// if its a relative path append a slash otherwise use the substring from the last slash onwards
|
|
||||||
std::string hdf5path = (slshidx == std::string::npos) ?
|
|
||||||
"/" + parameter_file_path :
|
|
||||||
parameter_file_path.substr(slshidx);
|
|
||||||
|
|
||||||
writer.write(file.str(), hdf5path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +81,6 @@ void SimulationOutput::writeSimulationData(
|
|||||||
std::vector<particle::SerializedParticle>& storage_queue,
|
std::vector<particle::SerializedParticle>& storage_queue,
|
||||||
int injectionGroupOffset) {
|
int injectionGroupOffset) {
|
||||||
if (MpiCommunication::mpi_rank == 0) {
|
if (MpiCommunication::mpi_rank == 0) {
|
||||||
|
|
||||||
#ifdef debug_level2
|
#ifdef debug_level2
|
||||||
DEBUG_LEVEL_2("Write density field data.");
|
DEBUG_LEVEL_2("Write density field data.");
|
||||||
#endif
|
#endif
|
||||||
@@ -292,8 +272,6 @@ void SimulationOutput::writeNumDeletions(DeletionLogger* logger,
|
|||||||
for (auto& pair : physDeletions) {
|
for (auto& pair : physDeletions) {
|
||||||
if (pair.first == PhysicalDeletionType::wall) {
|
if (pair.first == PhysicalDeletionType::wall) {
|
||||||
writer.write(pair.second, path_to_deletions + "/Wall(physical)");
|
writer.write(pair.second, path_to_deletions + "/Wall(physical)");
|
||||||
} else if (pair.first == PhysicalDeletionType::large_energy_transfer) {
|
|
||||||
writer.write(pair.second, path_to_deletions + "/LargeEnergyTransfer");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,6 +293,11 @@ void SimulationOutput::writeCurrentCrossings(
|
|||||||
path + "/PositiveCrossingsInZ");
|
path + "/PositiveCrossingsInZ");
|
||||||
writer.write(current_collector->negativeCrossingsInZ(),
|
writer.write(current_collector->negativeCrossingsInZ(),
|
||||||
path + "/NegativeCrossingsInZ");
|
path + "/NegativeCrossingsInZ");
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
writer.write(current_collector->sampleNegativeCrossings(),
|
||||||
|
path + "/SampleNegativeCrossings");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulationOutput::writeCurrent(CurrentCollector* current_collector,
|
void SimulationOutput::writeCurrent(CurrentCollector* current_collector,
|
||||||
@@ -327,6 +310,10 @@ void SimulationOutput::writeCurrent(CurrentCollector* current_collector,
|
|||||||
void SimulationOutput::writePhysicalTime(CurrentCollector* current_collector,
|
void SimulationOutput::writePhysicalTime(CurrentCollector* current_collector,
|
||||||
std::string path) {
|
std::string path) {
|
||||||
writer.write(current_collector->physicalTime(), path + "/PhysicalTime");
|
writer.write(current_collector->physicalTime(), path + "/PhysicalTime");
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
// write the time over which the "sample" current has been accumulated during
|
||||||
|
writer.write(current_collector->timeSinceReset(), path + "/TimeSinceReset");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulationOutput::writeSpectrum(DynamicDensityField* density_field,
|
void SimulationOutput::writeSpectrum(DynamicDensityField* density_field,
|
||||||
@@ -449,6 +436,10 @@ void SimulationOutput::writeCollectorAreas(CurrentCollector* current_collector,
|
|||||||
writer.write(current_collector->areaInR(), path + "/AreaInR");
|
writer.write(current_collector->areaInR(), path + "/AreaInR");
|
||||||
writer.write(current_collector->areaInPhi(), path + "/AreaInPhi");
|
writer.write(current_collector->areaInPhi(), path + "/AreaInPhi");
|
||||||
writer.write(current_collector->areaInZ(), path + "/AreaInZ");
|
writer.write(current_collector->areaInZ(), path + "/AreaInZ");
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
writer.write(current_collector->energyBinBorders(), path + "/EnergyBinBorders");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulationOutput::writeBinVolumes(DynamicDensityField* density_field,
|
void SimulationOutput::writeBinVolumes(DynamicDensityField* density_field,
|
||||||
@@ -490,3 +481,14 @@ void SimulationOutput::writeParticles(
|
|||||||
double dt) {
|
double dt) {
|
||||||
particle_writer.output_particles(particles, cpu_sync, dt);
|
particle_writer.output_particles(particles, cpu_sync, dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
void SimulationOutput::setResetCurrentCollector(int cpu_sync,
|
||||||
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species) {
|
||||||
|
for(auto& task : tasks_current_collector_) {
|
||||||
|
if(cpu_sync % task.intervall == 0)
|
||||||
|
species.at(task.specie_name)->currentCollector()->needsReset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -23,36 +23,6 @@ std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
|
|||||||
DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m");
|
DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m");
|
||||||
#endif
|
#endif
|
||||||
return std::shared_ptr<Geometry>(new Cylinder(radius, height));
|
return std::shared_ptr<Geometry>(new Cylinder(radius, height));
|
||||||
} else if(parameter.jsonObjectFromBase(
|
|
||||||
json_path_append(path_to_geometry, {"HalfCylinderWithCone"}))) {
|
|
||||||
|
|
||||||
#ifdef debug
|
|
||||||
DEBUG("Creating geometry: half cylinder with cone.");
|
|
||||||
#endif
|
|
||||||
double radius =
|
|
||||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
||||||
path_to_geometry, {"HalfCylinderWithCone", "Radius"})),
|
|
||||||
"m");
|
|
||||||
double heightcylinder =
|
|
||||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
||||||
path_to_geometry, {"HalfCylinderWithCone", "HeightCylinder"})),
|
|
||||||
"m");
|
|
||||||
double heightcone =
|
|
||||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
||||||
path_to_geometry, {"HalfCylinderWithCone", "HeightCone"})),
|
|
||||||
"m");
|
|
||||||
double z_frustum =
|
|
||||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
|
||||||
path_to_geometry, {"HalfCylinderWithCone", "FrustumStartZ"})),
|
|
||||||
"m");
|
|
||||||
|
|
||||||
#ifdef debug
|
|
||||||
std::stringstream out;
|
|
||||||
out << "height cyl: " << heightcylinder << ", height cone: " << heightcone << ", radius: " << radius << ", zfrustum: " << z_frustum << "\n";
|
|
||||||
DEBUG(out.str());
|
|
||||||
#endif
|
|
||||||
return std::shared_ptr<Geometry>(
|
|
||||||
new HalfCylinderWithCone(radius, heightcylinder, heightcone, z_frustum));
|
|
||||||
} else {
|
} else {
|
||||||
ERROR("This geometry is not implemented.");
|
ERROR("This geometry is not implemented.");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
|||||||
used_types.push_back(DeletionType::max_time_alive);
|
used_types.push_back(DeletionType::max_time_alive);
|
||||||
used_types.push_back(DeletionType::cluster_formation);
|
used_types.push_back(DeletionType::cluster_formation);
|
||||||
used_phys_types.push_back(PhysicalDeletionType::wall);
|
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||||
used_phys_types.push_back(PhysicalDeletionType::large_energy_transfer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,9 +95,6 @@ std::shared_ptr<VectorField> buildVectorField(json_t* object) {
|
|||||||
|
|
||||||
return std::make_shared<VectorFieldFromArray>(
|
return std::make_shared<VectorFieldFromArray>(
|
||||||
v_radial, v_azimuthal, v_longitudinal, radius, length);
|
v_radial, v_azimuthal, v_longitudinal, radius, length);
|
||||||
} else if (json_object_by_path(object, {"PredefinedLFAMagneticField"})) {
|
|
||||||
SIM_INFO("Warn: The predefined function is a magnetic field!!!");
|
|
||||||
return std::shared_ptr<VectorField>(new PredefinedMagneticVectorFieldLFA());
|
|
||||||
} else {
|
} else {
|
||||||
ERROR("This vector field is not implemented");
|
ERROR("This vector field is not implemented");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "simulation/velocity_distribution.h"
|
#include "simulation/velocity_distribution.h"
|
||||||
#include "constants/sim_constants.h"
|
#include "constants/sim_constants.h"
|
||||||
#include "simulation/density_field.h"
|
#include "simulation/density_field.h"
|
||||||
#include "simulation/logger.h"
|
|
||||||
namespace interaction {
|
namespace interaction {
|
||||||
|
|
||||||
ElasticScattering::ElasticScattering(
|
ElasticScattering::ElasticScattering(
|
||||||
@@ -25,8 +24,6 @@ InteractionOutput ElasticScattering::performInteraction(
|
|||||||
#endif
|
#endif
|
||||||
const blitz::TinyVector<double, 3> v_impact =
|
const blitz::TinyVector<double, 3> v_impact =
|
||||||
particle.velocity().cartesianEntries();
|
particle.velocity().cartesianEntries();
|
||||||
|
|
||||||
double E_i = kinematic::kineticEnergy(v_impact, particle.mass_kg());
|
|
||||||
// const auto x_impact = particle.position();
|
// const auto x_impact = particle.position();
|
||||||
// const blitz::TinyVector<double, 3> v_target =
|
// const blitz::TinyVector<double, 3> v_target =
|
||||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||||
@@ -51,13 +48,6 @@ InteractionOutput ElasticScattering::performInteraction(
|
|||||||
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(),
|
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(),
|
||||||
target_->mass_kg(), theta, phi);
|
target_->mass_kg(), theta, phi);
|
||||||
|
|
||||||
double E_iprime = kinematic::kineticEnergy(v_impact_new, particle.mass_kg());
|
|
||||||
|
|
||||||
// energy conservation: Ei + Et = Ei' + Et' <==> Et' - Et = Ei - Ei' (lab frame)
|
|
||||||
if(E_i - E_iprime >= threshold_increase_J) {
|
|
||||||
particle.specie()->deletionLogger()->logDeletion(particle, PhysicalDeletionType::large_energy_transfer);
|
|
||||||
}
|
|
||||||
|
|
||||||
particle.velocity(CartesianVector(v_impact_new));
|
particle.velocity(CartesianVector(v_impact_new));
|
||||||
|
|
||||||
return InteractionOutput();
|
return InteractionOutput();
|
||||||
|
|||||||
@@ -157,6 +157,11 @@ void CpuSynchronizer::synchronize(CurrentCollector* collector) {
|
|||||||
// collector->r_positive_crossings =
|
// collector->r_positive_crossings =
|
||||||
// collector->sync_r_positive_crossings;
|
// collector->sync_r_positive_crossings;
|
||||||
sumToRoot(collector->r_positive_crossings);
|
sumToRoot(collector->r_positive_crossings);
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
if(collector->getNeedsReset())
|
||||||
|
sumToRoot(collector->sample_z_negative_crossings);
|
||||||
|
#endif //GENRICHCURRENT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,20 @@ CurrentCollector::CurrentCollector(const CylinderBinning& position_binning,
|
|||||||
collector_areas_r(createAreaRadial(position_binning)),
|
collector_areas_r(createAreaRadial(position_binning)),
|
||||||
phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
||||||
phi_positive_crossings(createCrossingsAzimuthal(position_binning)),
|
phi_positive_crossings(createCrossingsAzimuthal(position_binning)),
|
||||||
collector_areas_phi(createAreaAzimuthal(position_binning))//,
|
collector_areas_phi(createAreaAzimuthal(position_binning))
|
||||||
// sync_z_negative_crossings(createCrossingsLongitudinal(position_binning)),
|
#ifdef GENRICHCURRENT
|
||||||
// sync_z_positive_crossings(createCrossingsLongitudinal(position_binning)),
|
// Hard coded values, not ideal, but it didn't work using defines...
|
||||||
// sync_r_negative_crossings(createCrossingsRadial(position_binning)),
|
, energy_binning_(0.1, 5, 100)
|
||||||
// sync_r_positive_crossings(createCrossingsRadial(position_binning)),
|
, sample_z_negative_crossings(
|
||||||
// sync_phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
blitz::Range(position_binning.binIndexMin()(0),
|
||||||
// sync_phi_positive_crossings(createCrossingsAzimuthal(position_binning))
|
position_binning.binIndexMax()(0)),
|
||||||
{}
|
blitz::Range(-1, 100))
|
||||||
|
#endif //GENRICHCURRENT
|
||||||
|
{
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
sample_z_negative_crossings = 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
blitz::Array<double, 2> CurrentCollector::createAreaLongitudinal(
|
blitz::Array<double, 2> CurrentCollector::createAreaLongitudinal(
|
||||||
const CylinderBinning& position_binning) {
|
const CylinderBinning& position_binning) {
|
||||||
@@ -138,8 +144,24 @@ void CurrentCollector::collect(particle::Particle* particle,
|
|||||||
|
|
||||||
const double weight = particle->weight();
|
const double weight = particle->weight();
|
||||||
|
|
||||||
|
#ifdef debug_genrich
|
||||||
|
if(particle->specie()->type() == species::ImplementedSpecies::Tplus &&
|
||||||
|
bin_new(1) == -1) {
|
||||||
|
std::stringstream out;
|
||||||
|
out << "Energy " << particle->kineticEnergy_eV() << " \n\t";
|
||||||
|
out << "Bin old " << bin_old << "; Bin new " << bin_new;
|
||||||
|
out << "; energy bin " << energy_binning_.bin(particle->kineticEnergy_eV());
|
||||||
|
out << "\n";
|
||||||
|
std::cout << out.str();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
collectRadialMovement(bin_old, bin_new, weight);
|
collectRadialMovement(bin_old, bin_new, weight);
|
||||||
collectLongitudinalMovement(bin_old, bin_new, weight);
|
collectLongitudinalMovement(bin_old, bin_new,
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
particle->kineticEnergy_eV(),
|
||||||
|
#endif
|
||||||
|
weight);
|
||||||
collectAzimuthalMovement(old_position.cartesianEntries(),
|
collectAzimuthalMovement(old_position.cartesianEntries(),
|
||||||
particle->cartesianPosition().cartesianEntries(),
|
particle->cartesianPosition().cartesianEntries(),
|
||||||
bin_old, weight);
|
bin_old, weight);
|
||||||
@@ -158,9 +180,21 @@ void CurrentCollector::collectRadialMovement(
|
|||||||
void CurrentCollector::collectLongitudinalMovement(
|
void CurrentCollector::collectLongitudinalMovement(
|
||||||
const blitz::TinyVector<int, 2>& bin_old,
|
const blitz::TinyVector<int, 2>& bin_old,
|
||||||
const blitz::TinyVector<int, 2>& bin_new,
|
const blitz::TinyVector<int, 2>& bin_new,
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
const double energy_eV,
|
||||||
|
#endif
|
||||||
const double weight) {
|
const double weight) {
|
||||||
if (bin_new(1) < bin_old(1)) {
|
if (bin_new(1) < bin_old(1)) {
|
||||||
z_negative_crossings(bin_old(0), bin_new(1) + 1) += weight;
|
z_negative_crossings(bin_old(0), bin_new(1) + 1) += weight;
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
if(bin_new(1) == -1) {
|
||||||
|
int ebin = energy_binning_.bin(energy_eV);
|
||||||
|
// #ifdef debug_genrich
|
||||||
|
// // fprintf(stdout, "Energybin: %d, energy: %f\n", ebin, energy_eV);
|
||||||
|
// #endif
|
||||||
|
sample_z_negative_crossings(bin_old(0), ebin) += weight;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else if (bin_new(1) > bin_old(1)) {
|
} else if (bin_new(1) > bin_old(1)) {
|
||||||
z_positive_crossings(bin_old(0), bin_new(1)) += weight;
|
z_positive_crossings(bin_old(0), bin_new(1)) += weight;
|
||||||
}
|
}
|
||||||
@@ -257,12 +291,25 @@ void CurrentCollector::resetCurrentCollector() {
|
|||||||
r_negative_crossings = 0.;
|
r_negative_crossings = 0.;
|
||||||
r_positive_crossings = 0.;
|
r_positive_crossings = 0.;
|
||||||
|
|
||||||
// sync_z_negative_crossings = 0.;
|
#ifdef GENRICHCURRENT
|
||||||
// sync_z_positive_crossings = 0.;
|
if(needs_reset) {
|
||||||
|
sample_z_negative_crossings = 0.;
|
||||||
// sync_phi_negative_crossings = 0.;
|
needs_reset = false;
|
||||||
// sync_phi_positive_crossings = 0.;
|
time_since_reset = timer_->getDeltaT();
|
||||||
|
} else {
|
||||||
// sync_r_negative_crossings = 0.;
|
time_since_reset += timer_->getDeltaT();
|
||||||
// sync_r_positive_crossings = 0.;
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
|
||||||
|
blitz::Array<double, 2> CurrentCollector::sampleNegativeCrossings() const {
|
||||||
|
return sample_z_negative_crossings;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<double> CurrentCollector::energyBinBorders() const {
|
||||||
|
return energy_binning_.binBorders();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -23,39 +23,3 @@ GeometryPositioning Cylinder::isWhere(const Coordinate& position) const {
|
|||||||
return GeometryPositioning::inside;
|
return GeometryPositioning::inside;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HalfCylinderWithCone::HalfCylinderWithCone(double radiusCylinder, double heightCylinder,
|
|
||||||
double heightCone, double z_frustum) :
|
|
||||||
cylinder_height_(heightCylinder),
|
|
||||||
cylinder_radius_(radiusCylinder),
|
|
||||||
cone_height_(heightCone),
|
|
||||||
z_frustum_(z_frustum) {}
|
|
||||||
|
|
||||||
bool HalfCylinderWithCone::isInside(const Coordinate& coordinate) const {
|
|
||||||
const blitz::TinyVector<double, 3> cylinder_position = coordinate.cylinderEntries();
|
|
||||||
return (cylinder_position(2) > z_frustum_) &&
|
|
||||||
(cylinder_position(2) < (cylinder_height_ + cone_height_)) &&
|
|
||||||
(cylinder_position(0) < localRadius(cylinder_position(2)));
|
|
||||||
}
|
|
||||||
|
|
||||||
GeometryPositioning HalfCylinderWithCone::isWhere(const Coordinate& coordinate) const {
|
|
||||||
const blitz::TinyVector<double, 3> cylinder_position = coordinate.cylinderEntries();
|
|
||||||
if(cylinder_position(2) <= z_frustum_ || cylinder_position(0) >= localRadius(cylinder_position(2))) {
|
|
||||||
return GeometryPositioning::hull;
|
|
||||||
} else if (cylinder_position(2) >= (cone_height_ + cylinder_height_)) {
|
|
||||||
return GeometryPositioning::top;
|
|
||||||
} else {
|
|
||||||
return GeometryPositioning::inside;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double HalfCylinderWithCone::localRadius(double z) const {
|
|
||||||
if(z >= cone_height_) {
|
|
||||||
return cylinder_radius_;
|
|
||||||
} else {
|
|
||||||
// can potentially be negative, but that should be fine for a check if
|
|
||||||
// the position is inside the geometry
|
|
||||||
return z/cone_height_*cylinder_radius_;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ CylinderCoordinate BorisMover::move(particle::Particle* particle,
|
|||||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> B =
|
blitz::TinyVector<double, 3> B =
|
||||||
magnetic_field->value(old_position_cart).cartesianEntries(old_position_cart);
|
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
blitz::TinyVector<double, 3> E;
|
blitz::TinyVector<double, 3> E;
|
||||||
if(particle->areLocalFieldsSet()) {
|
if(particle->areLocalFieldsSet()) {
|
||||||
// In case of spatially variable magnetic fields use the one at the "actual" particle
|
// In case of spatially variable magnetic fields use the one at the "actual" particle
|
||||||
@@ -53,11 +53,25 @@ CylinderCoordinate BorisMover::move(particle::Particle* particle,
|
|||||||
// B = particle->getLocalB();
|
// B = particle->getLocalB();
|
||||||
E = particle->getLocalE();
|
E = particle->getLocalE();
|
||||||
} else {
|
} else {
|
||||||
B = magnetic_field->value(old_position_cart).cartesianEntries(old_position_cart);
|
B = magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
E = electric_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
E = electric_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
particle->setLocalFields(E, B);
|
particle->setLocalFields(E, B);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// double old_mu;
|
||||||
|
// double new_mu;
|
||||||
|
// if magnetic field is 0 use e_z as a reference for the pitch angle
|
||||||
|
// calculation (don't know if best approach, probably not...)
|
||||||
|
// if (kinematic::norm(B) == 0) {
|
||||||
|
// old_mu = kinematic::cosPitchAngle(
|
||||||
|
// blitz::TinyVector<double, 3>(0,0,1),
|
||||||
|
// particle->velocity().cartesianEntries(old_position_cart));
|
||||||
|
// } else {
|
||||||
|
// old_mu = kinematic::cosPitchAngle(
|
||||||
|
// B, particle->velocity().cartesianEntries(old_position_cart));
|
||||||
|
// }
|
||||||
|
// new_mu = old_mu;
|
||||||
|
|
||||||
double timestep = 0;
|
double timestep = 0;
|
||||||
|
|
||||||
bool changed_position_bin = false;
|
bool changed_position_bin = false;
|
||||||
@@ -90,7 +104,7 @@ CylinderCoordinate BorisMover::move(particle::Particle* particle,
|
|||||||
auto new_position_cart = particle->cartesianPosition();
|
auto new_position_cart = particle->cartesianPosition();
|
||||||
auto new_velocity = particle->velocity();
|
auto new_velocity = particle->velocity();
|
||||||
|
|
||||||
B = magnetic_field->value(new_position_cart).
|
B = magnetic_field->value(particle->cylinderPosition()).
|
||||||
cartesianEntries(new_position_cart);
|
cartesianEntries(new_position_cart);
|
||||||
|
|
||||||
// if (kinematic::norm(B) == 0) {
|
// if (kinematic::norm(B) == 0) {
|
||||||
|
|||||||
@@ -38,8 +38,13 @@
|
|||||||
|
|
||||||
#include "tools/simulation_time.h"
|
#include "tools/simulation_time.h"
|
||||||
|
|
||||||
|
// #ifdef debug_timedist
|
||||||
|
// #include <fstream>
|
||||||
|
// #include <iomanip>
|
||||||
|
// #endif
|
||||||
|
|
||||||
Simulation::Simulation(std::string parameter_filename)
|
Simulation::Simulation(std::string parameter_filename)
|
||||||
: parameter_(parameter_filename), parameter_file_path_(parameter_filename) {
|
: parameter_(parameter_filename) {
|
||||||
init(parameter_);
|
init(parameter_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +117,7 @@ void Simulation::init(Parameter& parameter) {
|
|||||||
#ifdef debug
|
#ifdef debug
|
||||||
DEBUG_LEVEL_0("Output meta data.");
|
DEBUG_LEVEL_0("Output meta data.");
|
||||||
#endif
|
#endif
|
||||||
output_->writeMetaData(tracked_species_, poisson_solver_, parameter_file_path_);
|
output_->writeMetaData(tracked_species_, poisson_solver_);
|
||||||
}
|
}
|
||||||
|
|
||||||
int eventsThisCpu(int events_all_cpus) {
|
int eventsThisCpu(int events_all_cpus) {
|
||||||
@@ -192,6 +197,10 @@ void Simulation::start() {
|
|||||||
// std::to_string(leftover_events_time_resolution));
|
// std::to_string(leftover_events_time_resolution));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef GENRICHCURRENT
|
||||||
|
output_->setResetCurrentCollector(timestep + 1, tracked_species_);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
SIM_INFO("Cpu sync.");
|
SIM_INFO("Cpu sync.");
|
||||||
#endif
|
#endif
|
||||||
@@ -378,9 +387,7 @@ void Simulation::processUntilTermination(particle::Particle& particle) {
|
|||||||
#endif
|
#endif
|
||||||
auto old_position = particle.cylinderPosition();
|
auto old_position = particle.cylinderPosition();
|
||||||
double old_energy = particle.kineticEnergy_eV();
|
double old_energy = particle.kineticEnergy_eV();
|
||||||
bool was_reflected = false;
|
while (particle.specie()->terminator()->isAlive(&particle, old_position)) {
|
||||||
|
|
||||||
while (particle.specie()->terminator()->isAlive(&particle, old_position) || was_reflected) {
|
|
||||||
old_position = particle.cylinderPosition();
|
old_position = particle.cylinderPosition();
|
||||||
old_energy = particle.kineticEnergy_eV();
|
old_energy = particle.kineticEnergy_eV();
|
||||||
|
|
||||||
@@ -405,9 +412,8 @@ void Simulation::processUntilTermination(particle::Particle& particle) {
|
|||||||
gravity_field_.get());
|
gravity_field_.get());
|
||||||
SimulationTimer::eventStopPoint(std::string("Mover"));
|
SimulationTimer::eventStopPoint(std::string("Mover"));
|
||||||
|
|
||||||
was_reflected = false;
|
bool was_reflected = false;
|
||||||
if (particle.specie()->reflector()->needsReflectionBackToDomain(
|
if (particle.specie()->reflector()->needsReflectionBackToDomain(&particle)) {
|
||||||
&particle)) {
|
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Reflect particle.");
|
DEBUG_LEVEL_3("Reflect particle.");
|
||||||
#endif
|
#endif
|
||||||
@@ -479,11 +485,11 @@ void Simulation::processUntilTermination(particle::Particle& particle) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(particle.specie()->dynamicDensityField()->changedPositionBin(
|
if ((!(particle.specie()->dynamicDensityField()->changedPositionBin(
|
||||||
old_position, particle.cylinderPosition())) &&
|
old_position, particle.cylinderPosition())) &&
|
||||||
!(particle.specie()->dynamicDensityField()->changedEnergyBin(
|
!(particle.specie()->dynamicDensityField()->changedEnergyBin(
|
||||||
old_energy, particle.kineticEnergy_eV())) &&
|
old_energy, particle.kineticEnergy_eV())) &&
|
||||||
!was_reflected) {
|
!was_reflected) || particle.timeUntilCollision() <= 0.) {
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Perform interaction.");
|
DEBUG_LEVEL_3("Perform interaction.");
|
||||||
DEBUG_LEVEL_3("Number of Interactions: " +
|
DEBUG_LEVEL_3("Number of Interactions: " +
|
||||||
@@ -583,6 +589,19 @@ void Simulation::collisionTime(particle::Particle& particle, RandomNumbers* rand
|
|||||||
|
|
||||||
interaction::InteractionOutput Simulation::interact(
|
interaction::InteractionOutput Simulation::interact(
|
||||||
particle::Particle& particle, RandomNumbers* random) {
|
particle::Particle& particle, RandomNumbers* random) {
|
||||||
|
// #ifdef debug_timedist
|
||||||
|
// if(particle.kineticEnergy_eV() > 20 && particle.specie()->type() == species::ImplementedSpecies::electron) {
|
||||||
|
// std::ofstream file;
|
||||||
|
// std::stringstream filename;
|
||||||
|
// filename << MpiCommunication::mpi_rank << "_collisionTimeDistribution.dat";
|
||||||
|
// file.open(filename.str(), std::ios_base::app);
|
||||||
|
|
||||||
|
// file << std::setprecision(16) << particle.timeSinceCollision() << "\n";
|
||||||
|
// file.close();
|
||||||
|
// }
|
||||||
|
// particle.resetTimeSinceCollision();
|
||||||
|
// #endif
|
||||||
|
|
||||||
return particle.specie()->interactions().at(particle.indexNextInteraction())
|
return particle.specie()->interactions().at(particle.indexNextInteraction())
|
||||||
->performInteraction(particle, random);
|
->performInteraction(particle, random);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,91 +59,3 @@ CylinderVector VectorFieldFunctionInZ::value(
|
|||||||
0., 0.,
|
0., 0.,
|
||||||
F_z_(cylinder_position(0), cylinder_position(1), cylinder_position(2))));
|
F_z_(cylinder_position(0), cylinder_position(1), cylinder_position(2))));
|
||||||
}
|
}
|
||||||
|
|
||||||
PredefinedMagneticVectorFieldLFA::PredefinedMagneticVectorFieldLFA() {
|
|
||||||
double theta = M_PI/64.;
|
|
||||||
for(int i = 0; i < 128; ++i) {
|
|
||||||
cosktheta(i) = std::cos(i*theta);
|
|
||||||
sinktheta(i) = std::sin(i*theta);
|
|
||||||
}
|
|
||||||
|
|
||||||
z1 = 0.1;
|
|
||||||
z2 = RIoffe*cosa/sina;
|
|
||||||
zoffset = 6e-3/sina;
|
|
||||||
}
|
|
||||||
|
|
||||||
// does not make use of the transition functions!!!
|
|
||||||
CylinderVector PredefinedMagneticVectorFieldLFA::value(const Coordinate& coordinate) const {
|
|
||||||
// Important that coordinate is a CartesianCoordinate since the transformation from
|
|
||||||
// CylinderCoordinate to CartesianCoordinate does not work, since phi is not tracked
|
|
||||||
blitz::TinyVector<double, 3> cartPos = coordinate.cartesianEntries();
|
|
||||||
double x = cartPos(0); double y = cartPos(1); double z = cartPos(2) + zoffset;
|
|
||||||
double r = std::sqrt(x*x + y*y);
|
|
||||||
double Bx, By, Bz;
|
|
||||||
|
|
||||||
Bx = 0;
|
|
||||||
By = 0;
|
|
||||||
Bz = 0;
|
|
||||||
|
|
||||||
double Dp = x*x + y*y + z*z;
|
|
||||||
double D0 = x*x + y*y + RIoffe*RIoffe;
|
|
||||||
|
|
||||||
double Dpk_plus, Dpk_minus, D0k;
|
|
||||||
|
|
||||||
// loop to gather cylinder Ioffe contribution
|
|
||||||
double sign = -1;
|
|
||||||
for(int i = 0; i < 128; ++i) {
|
|
||||||
sign *= -1;
|
|
||||||
|
|
||||||
D0k = 2*RIoffe*(x*cosktheta(i) + y*sinktheta(i));
|
|
||||||
|
|
||||||
Bx += sign*(y - RIoffe*sinktheta(i))/(D0 - D0k);
|
|
||||||
By += sign*(RIoffe*cosktheta(i) - x)/(D0 - D0k);
|
|
||||||
}
|
|
||||||
|
|
||||||
// only consider the cone contibution close to the cone
|
|
||||||
if(z < 1.2*z1) {
|
|
||||||
// loop to gather the cone Ioffe contribution
|
|
||||||
for(int i = 0; i < 128; i+=4) {
|
|
||||||
// positive current contribution at index i
|
|
||||||
Dpk_plus = x*sina*cosktheta(i) + y*sina*sinktheta(i) + z*cosa;
|
|
||||||
// negative current contribution at index i+1
|
|
||||||
Dpk_minus = x*sina*cosktheta(i+1) + y*sina*sinktheta(i+1) + z*cosa;
|
|
||||||
|
|
||||||
Bx += (z*sina*sinktheta(i) - y*cosa)/(Dp - Dpk_plus*Dpk_plus) -
|
|
||||||
(z*sina*sinktheta(i+1) - y*cosa)/(Dp - Dpk_minus*Dpk_minus);
|
|
||||||
|
|
||||||
By += (x*cosa - z*sina*cosktheta(i) )/(Dp - Dpk_plus*Dpk_plus) -
|
|
||||||
(x*cosa - z*sina*cosktheta(i+1))/(Dp - Dpk_minus*Dpk_minus);
|
|
||||||
|
|
||||||
Bz += (y*sina*cosktheta(i) - x*sina*sinktheta(i) )/(Dp - Dpk_plus*Dpk_plus) -
|
|
||||||
(y*sina*cosktheta(i+1) - x*sina*sinktheta(i+1))/(Dp - Dpk_minus*Dpk_minus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Bx *= B0Ioffe;
|
|
||||||
By *= B0Ioffe;
|
|
||||||
Bz *= B0Ioffe;
|
|
||||||
|
|
||||||
|
|
||||||
// Magnetic Bottle
|
|
||||||
// assume the peak is located 2m away from the transition from cone to cylinder
|
|
||||||
double zg0 = z1 + 2; // m
|
|
||||||
double sig2 = 0.211954; // m^2
|
|
||||||
double B0g = 3.07e-4; // T
|
|
||||||
|
|
||||||
double Bzg = std::exp(-(z - zg0)*(z - zg0)/sig2)*B0g;
|
|
||||||
double Bxg = x*(z-zg0)/sig2*Bzg;
|
|
||||||
double Byg = y*(z-zg0)/sig2*Bzg;
|
|
||||||
|
|
||||||
// add all contributions
|
|
||||||
Bx += Bxg;
|
|
||||||
By += Byg;
|
|
||||||
Bz += Bzg + Bbg;
|
|
||||||
|
|
||||||
// transformation into cylinder vector
|
|
||||||
double Br = Bx*x/r + By*y/r;
|
|
||||||
double Bphi = By*x/r - Bx*y/r;
|
|
||||||
|
|
||||||
return CylinderVector(blitz::TinyVector<double, 3>(Br, Bphi, Bz));
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user