Compare commits
75
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4638a6563c | ||
|
|
324da20d4a | ||
|
|
32f4703f4e | ||
|
|
364191d92f | ||
|
|
ca78062738 | ||
|
|
c9a8b511f9 | ||
|
|
0a843f0a4c | ||
|
|
32521298d4 | ||
|
|
26b5820a15 | ||
|
|
41ffe0b96f | ||
|
|
68d1d88962 | ||
|
|
09dfddb6da | ||
|
|
5d72083a25 | ||
|
|
af2ea430f4 | ||
|
|
753ff2c09a | ||
|
|
5cb560e727 | ||
|
|
5c39fb1745 | ||
|
|
5094a1da35 | ||
|
|
880de9f1ba | ||
|
|
f57895bcef | ||
|
|
f5ff3d2f7c | ||
|
|
753cbe31f5 | ||
|
|
31c2b230a9 | ||
|
|
21ad9cd30a | ||
|
|
85ec40d37b | ||
|
|
4a11245994 | ||
|
|
8425535f9d | ||
|
|
de2c3618e3 | ||
|
|
f87bb0d9f0 | ||
|
|
80b46f70e6 | ||
|
|
d5e01e3f4a | ||
|
|
641e26c10b | ||
|
|
c57dd44dde | ||
|
|
bea8751f1d | ||
|
|
285d165615 | ||
|
|
cc827f1417 | ||
|
|
abab8810f3 | ||
|
|
ddfa5672df | ||
|
|
711c030cae | ||
|
|
76a93f5aa4 | ||
|
|
0dd65d38f3 | ||
|
|
1859243475 | ||
|
|
5f025c667f | ||
|
|
0237292c5c | ||
|
|
603434e161 | ||
|
|
f5a4e63627 | ||
|
|
c4ae430fff | ||
|
|
7ddb57e72e | ||
|
|
f9307af911 | ||
|
|
b2399c3812 | ||
|
|
b8a4631676 | ||
|
|
87ffe087b8 | ||
|
|
9ef7fcd3ca | ||
|
|
d06d805465 | ||
|
|
249fbfc275 | ||
|
|
05125a3fc1 | ||
|
|
024fe59410 | ||
|
|
d621932172 | ||
|
|
d6578e540d | ||
|
|
f510d0a39a | ||
|
|
e2167fb75b | ||
|
|
a33e97187e | ||
|
|
0af4959fa0 | ||
|
|
59f4041238 | ||
|
|
786cb6d877 | ||
|
|
1194dba918 | ||
|
|
5179869039 | ||
|
|
1a7931bbea | ||
|
|
b28245f1a8 | ||
|
|
60430abcba | ||
|
|
2c79c567d8 | ||
|
|
89e0a0eb2a | ||
|
|
d17602e1fa | ||
|
|
5bc545ac99 | ||
|
|
d62c49a15d |
@@ -0,0 +1,170 @@
|
||||
import numpy as np
|
||||
import matplotlib
|
||||
matplotlib.use("agg")
|
||||
import matplotlib.pyplot as plt
|
||||
import h5py
|
||||
import argparse
|
||||
import glob
|
||||
import re
|
||||
import os
|
||||
import plot_standards as pst
|
||||
|
||||
def get_time_and_total_charge_(files, considered_keys=['All'], exclude_underflow=False):
|
||||
times = []
|
||||
total_charges = []
|
||||
for file in files:
|
||||
with h5py.File(file, 'r') as cfile:
|
||||
total_charge = 0
|
||||
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
|
||||
charge = cfile[f'{key}/Charge'][()]
|
||||
cfile_speciesDensity = cfile[key]['DensityField']
|
||||
# binVolumes = cfile_speciesDensity['BinVolumes'][()]
|
||||
cfile_simData = cfile_speciesDensity['SimulationData']
|
||||
|
||||
for time_key in cfile_simData.keys():
|
||||
time = cfile_simData[time_key]['PhysicalTime'][()]
|
||||
|
||||
density = cfile_simData[time_key]['TimeInBin'][()]
|
||||
if not exclude_underflow:
|
||||
total_charge = np.sum(density)*charge
|
||||
else:
|
||||
total_charge = np.array([np.sum(density[:,:,:,:,1:-1])])*charge
|
||||
# print(total_charge)
|
||||
|
||||
try:
|
||||
index = times.index(time)
|
||||
total_charges[index] += total_charge
|
||||
except:
|
||||
times.append(time)
|
||||
total_charges.append(total_charge)
|
||||
|
||||
times = np.array(times)[:,0]
|
||||
# print(total_charge)
|
||||
total_charges = np.array(total_charges)[:,0]
|
||||
|
||||
sorting_mask = np.argsort(times)
|
||||
times = times[sorting_mask]
|
||||
total_charges = total_charges[sorting_mask]
|
||||
|
||||
return times, total_charges
|
||||
|
||||
def get_time_and_wall_losses(files, considered_keys=['All']):
|
||||
times = []
|
||||
phys_wall_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:
|
||||
phys_wall_loss[index] += cfile_specieslogger[time_key]\
|
||||
['NumDeletions/Wall(physical)'][0]/deltat
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
times.append(time)
|
||||
try:
|
||||
phys_wall_loss.append(cfile_specieslogger[time_key]\
|
||||
['NumDeletions/Wall(physical)'][0]/deltat)
|
||||
except:
|
||||
phys_wall_loss.append(-1)
|
||||
|
||||
times = np.array(times)
|
||||
phys_wall_loss = np.array(phys_wall_loss)
|
||||
|
||||
sorting_mask = np.argsort(times)
|
||||
times = times[sorting_mask]
|
||||
phys_wall_loss = phys_wall_loss[sorting_mask]
|
||||
|
||||
return times, phys_wall_loss
|
||||
|
||||
def getFiles(dir:str, base_name:str, pattern:str) :
|
||||
if dir[-1] == '/':
|
||||
pathname = dir + base_name
|
||||
else:
|
||||
pathname = dir + '/' + base_name
|
||||
# print(glob.glob(pathname + "*.h5"))
|
||||
return [file for file in glob.glob(pathname + "*.h5") if re.match(rf"{pathname}{pattern}+\.h5", str(file))]
|
||||
|
||||
if __name__ == '__main__':
|
||||
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("basename", type = str, help = 'identifying pattern of the files (i.e. basename[0-9]*\\.h5])')
|
||||
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("--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("species", action='extend', nargs='+', help = 'Names of the Species in the KARL output or \'All\' if all species should be summed. If name does not exist it will be ignored.')
|
||||
args = parser.parse_args()
|
||||
|
||||
# print(args.dir, args.basename, args.species)
|
||||
|
||||
files = getFiles(args.dir, args.basename, args.pattern)
|
||||
print(files)
|
||||
|
||||
if(files == []):
|
||||
print(f"No files found in {args.dir}, which match '{args.basename}{args.pattern}\\.h5'")
|
||||
exit(1)
|
||||
|
||||
if (not args.width == 'thesis') and (not args.width == 'beamer'):
|
||||
print(f"{args.width} is not a valid parameter for width; fall back to \'thesis\'")
|
||||
args.width = 'thesis'
|
||||
|
||||
if args.losses:
|
||||
times, charges = get_time_and_wall_losses(files, args.species)
|
||||
else:
|
||||
times, charges = get_time_and_total_charge_(files, args.species)
|
||||
|
||||
legstr = ''
|
||||
for val in args.species:
|
||||
legstr += val + " + "
|
||||
legstr = legstr[:-3]
|
||||
|
||||
|
||||
plt.rcParams.update({'font.size': 10})
|
||||
fig = plt.figure(figsize=pst.set_size(args.width))
|
||||
plt.plot(times, charges, marker = 'x', label = legstr)
|
||||
if args.losses:
|
||||
plt.ylabel('loss rate (1/s)')
|
||||
else:
|
||||
plt.ylabel('charge (C)')
|
||||
plt.xlabel('time (s)')
|
||||
plt.legend()
|
||||
plt.grid()
|
||||
plt.tight_layout()
|
||||
|
||||
outname = args.dir
|
||||
if not outname[-1] == '/':
|
||||
outname += '/'
|
||||
|
||||
outname += "plots/"
|
||||
|
||||
os.makedirs(outname, exist_ok=True)
|
||||
|
||||
if args.losses:
|
||||
outname += args.basename + "_wallLossRateAgainstTime_species-"
|
||||
else:
|
||||
outname += args.basename + "_chargeAgainstTime_species-"
|
||||
|
||||
for value in args.species:
|
||||
outname += value
|
||||
outname += '_test.pdf'
|
||||
|
||||
# print(outname)
|
||||
plt.savefig(outname, format='pdf', bbox_inches = 'tight')
|
||||
# plt.show()
|
||||
Binary file not shown.
@@ -15,6 +15,7 @@ class Hdf5Reader {
|
||||
blitz::Array<double, 2> readD2Double(std::string path);
|
||||
blitz::Array<double, 1> readD1Double(std::string path);
|
||||
double readDouble(std::string path);
|
||||
int readInt(std::string path);
|
||||
|
||||
blitz::Array<long int, 5> readD5LongInt(std::string path);
|
||||
blitz::Array<long int, 4> readD4LongInt(std::string path);
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
#ifndef MPI_PARTICLE_FORMAT_H
|
||||
#define MPI_PARTICLE_FORMAT_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "mpi.h"
|
||||
/* File format (as in ACRONYM):
|
||||
*
|
||||
* mpi_io_header
|
||||
* <padding>
|
||||
* cpu_header[n_cpus]
|
||||
* <padding>
|
||||
* data_of_cpu_1 <padding>
|
||||
* data_of_cpu_2 <padding>
|
||||
* ...
|
||||
*/
|
||||
|
||||
/* file header*/
|
||||
struct mpi_io_header_t {
|
||||
std::uint64_t magic;
|
||||
std::uint64_t cpu_header_offset;
|
||||
std::uint32_t num_cpus;
|
||||
double dt;
|
||||
|
||||
bool verify() {
|
||||
// Sanity Check if file is the right format
|
||||
if(magic != ((std::uint64_t)'KA'<<32) + 'RL') {
|
||||
return false;
|
||||
}
|
||||
if(dt < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/* per-CPU header */
|
||||
struct cpu_header_t {
|
||||
std::uint64_t num_particles;
|
||||
std::uint64_t file_offset;
|
||||
};
|
||||
|
||||
// seems to work only if alignment is a power of 2
|
||||
static std::uint64_t pad_to_blocksize(std::uint64_t size, std::uint64_t alignment) {
|
||||
size &= ~(alignment - 1);
|
||||
size += alignment;
|
||||
return size;
|
||||
}
|
||||
|
||||
#ifdef MPI_VERSION
|
||||
|
||||
#ifndef MPI_UINT32_T
|
||||
#define MPI_UNIT32_T MPI_UNSIGNED
|
||||
#endif
|
||||
|
||||
#ifndef MPI_UINT64_T
|
||||
#define MPI_UNIT64_T MPI_UNSIGNED_LONG_LONG
|
||||
#endif
|
||||
|
||||
/* Custom MPI data types for the header structs */
|
||||
static MPI_Datatype build_file_header_type() {
|
||||
int status;
|
||||
MPI_Datatype type;
|
||||
int blocklengths[4];
|
||||
MPI_Aint disps[4];
|
||||
MPI_Datatype types[4];
|
||||
|
||||
disps[0] = offsetof(mpi_io_header_t, magic);
|
||||
types[0] = MPI_UINT64_T;
|
||||
blocklengths[0] = 1;
|
||||
|
||||
disps[1] = offsetof(mpi_io_header_t, cpu_header_offset);
|
||||
types[1] = MPI_UINT64_T;
|
||||
blocklengths[1] = 1;
|
||||
|
||||
disps[2] = offsetof(mpi_io_header_t, num_cpus);
|
||||
types[2] = MPI_UINT32_T;
|
||||
blocklengths[2] = 1;
|
||||
|
||||
disps[3] = offsetof(mpi_io_header_t, dt);
|
||||
types[3] = MPI_DOUBLE;
|
||||
blocklengths[3] = 1;
|
||||
|
||||
status = MPI_Type_create_struct(4, blocklengths, disps, types, &type);
|
||||
status |= MPI_Type_commit(&type);
|
||||
|
||||
if(status) {
|
||||
fprintf(stderr, "Creation of the data type \"file_header\" failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static MPI_Datatype build_cpu_header_type() {
|
||||
int status;
|
||||
MPI_Datatype type;
|
||||
int blocklengths[2];
|
||||
MPI_Aint disps[2];
|
||||
MPI_Datatype types[2];
|
||||
|
||||
disps[0] = offsetof(cpu_header_t, num_particles);
|
||||
types[0] = MPI_UINT64_T;
|
||||
blocklengths[0] = 1;
|
||||
|
||||
disps[1] = offsetof(cpu_header_t, file_offset);
|
||||
types[1] = MPI_UINT64_T;
|
||||
blocklengths[1] = 1;
|
||||
|
||||
status = MPI_Type_create_struct(2, blocklengths, disps, types, &type);
|
||||
status |= MPI_Type_commit(&type);
|
||||
|
||||
if(status) {
|
||||
fprintf(stderr, "Creation of the data type \"cpu_header\" failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
#endif /* MPI_VERSION */
|
||||
|
||||
#endif /* MPI_PARTICLE_FORMAT_H */
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef MPI_PARTICLE_READER_H
|
||||
#define MPI_PARTICLE_READER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace particle {
|
||||
class SerializedParticle;
|
||||
}
|
||||
|
||||
class MpiParticleReader {
|
||||
public:
|
||||
MpiParticleReader(std::string directory, std::string filename, int restart_at);
|
||||
MpiParticleReader(std::string absolute_filename);
|
||||
MpiParticleReader(std::string abs_filename_without_extension, int restart_at);
|
||||
|
||||
void readParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
||||
|
||||
private:
|
||||
std::string absolute_filename_;
|
||||
};
|
||||
|
||||
#endif /* MPI_PARTICLE_READER_H */
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef MPI_PARTICLE_WRITER_H
|
||||
#define MPI_PARTICLE_WRITER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace particle {
|
||||
class SerializedParticle;
|
||||
}
|
||||
|
||||
class MpiParticleWriter {
|
||||
public:
|
||||
MpiParticleWriter(std::string directory = "./output",
|
||||
std::string filename = "output",
|
||||
int fs_blocksize = 4096);
|
||||
|
||||
void output_particles(std::vector<particle::SerializedParticle>& particles,
|
||||
int cpu_sync, double dt);
|
||||
|
||||
private:
|
||||
std::string directory_;
|
||||
std::string filename_;
|
||||
void createFolder(std::string directory);
|
||||
int fs_blocksize_;
|
||||
};
|
||||
|
||||
#endif /* MPI_PARTICLE_WRITER_H */
|
||||
+15
-3
@@ -4,14 +4,20 @@
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "IO/hdf5_reader.h"
|
||||
#include "IO/mpi_particle_reader.h"
|
||||
|
||||
namespace species {
|
||||
class TrackedSpecie;
|
||||
enum class ImplementedSpecies;
|
||||
}; // namespace species
|
||||
|
||||
namespace particle {
|
||||
class SerializedParticle;
|
||||
};
|
||||
|
||||
class DynamicDensityField;
|
||||
class PoissonSolver;
|
||||
class RandomNumbers;
|
||||
@@ -23,11 +29,15 @@ class RandomNumbers;
|
||||
// here after the potential is loaded; would need the electric field class to be included
|
||||
class Restart {
|
||||
public:
|
||||
Restart(bool do_restart, std::string absolute_filename,
|
||||
std::string restart_identifier);
|
||||
// Restart(bool do_restart, std::string absolute_filename,
|
||||
// std::string restart_identifier);
|
||||
Restart(bool do_restart, std::string absolute_filename_without_extension,
|
||||
std::string restart_identifier, int particle_restart_at);
|
||||
|
||||
void restart(std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||
PoissonSolver* poisson_solver, RandomNumbers* random_numbers);
|
||||
PoissonSolver* poisson_solver, RandomNumbers* random_numbers,
|
||||
std::vector<particle::SerializedParticle>& storage_queue,
|
||||
int& injectionGroupOffset);
|
||||
|
||||
private:
|
||||
void restartTimer(species::TrackedSpecie* reference_specie);
|
||||
@@ -36,9 +46,11 @@ class Restart {
|
||||
// only load in the potential and calc the electric field
|
||||
void restartPoissonSolver(PoissonSolver* solver);
|
||||
void restartRandomNumbers(RandomNumbers* random);
|
||||
void restartParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
||||
|
||||
bool do_restart_;
|
||||
std::string restart_identifier_; // i.e. "LastSyncPeriod" or "SyncPeriod_*"
|
||||
Hdf5Reader reader_;
|
||||
MpiParticleReader particle_reader_;
|
||||
};
|
||||
#endif /* RESTART_H */
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include "IO/hdf5_writer.h"
|
||||
#include "IO/mpi_particle_writer.h"
|
||||
|
||||
class DynamicDensityField;
|
||||
class CurrentBorder;
|
||||
@@ -30,13 +31,15 @@ struct OutputTask {
|
||||
class SimulationOutput {
|
||||
public:
|
||||
SimulationOutput(const std::string& output_folder,
|
||||
const std::string& output_filename);
|
||||
const std::string& output_filename,
|
||||
int fs_blocksize=4096);
|
||||
|
||||
void addDensityFieldOutput(OutputTask task);
|
||||
void addCurrentBorderOutput(OutputTask task);
|
||||
void addDeletionLoggerOutput(OutputTask task);
|
||||
void setPotentialOutput(OutputTask task);
|
||||
void setRestartInfoOutput(OutputTask task);
|
||||
void setParticleOutput(OutputTask task);
|
||||
|
||||
void writeMetaData(
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||
@@ -45,7 +48,14 @@ class SimulationOutput {
|
||||
void writeSimulationData(
|
||||
int cpu_sync,
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||
PoissonSolver* poisson_solver, std::mt19937* engine);
|
||||
PoissonSolver* poisson_solver, std::mt19937* engine,
|
||||
std::vector<particle::SerializedParticle>& storage_queue,
|
||||
int injectionGroupOffset);
|
||||
|
||||
#ifdef GENRICHCURRENT
|
||||
void setResetCurrentCollector(int cpu_sync,
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species);
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::vector<OutputTask> tasks_density_fields_;
|
||||
@@ -53,8 +63,10 @@ class SimulationOutput {
|
||||
std::vector<OutputTask> tasks_deletion_logger_;
|
||||
OutputTask task_potential_;
|
||||
OutputTask task_rng_;
|
||||
OutputTask task_particles_;
|
||||
|
||||
Hdf5Writer writer;
|
||||
MpiParticleWriter particle_writer;
|
||||
|
||||
void writeSimulationData(DynamicDensityField* density_field,
|
||||
std::string species_path,
|
||||
@@ -64,8 +76,8 @@ class SimulationOutput {
|
||||
void writeSpectrum(DynamicDensityField* density_field, std::string path);
|
||||
void writeDensity(DynamicDensityField* density_field, std::string path);
|
||||
void writeTimeInBin(DynamicDensityField* density_field, std::string path);
|
||||
void writeDeletedParticles(DynamicDensityField* density_field,
|
||||
std::string path);
|
||||
// void writeDeletedParticles(DynamicDensityField* density_field,
|
||||
// std::string path);
|
||||
void writePhysicalTime(DynamicDensityField* density_field, std::string path);
|
||||
|
||||
void writeSimulationData(CurrentCollector* current_collector,
|
||||
@@ -107,8 +119,11 @@ class SimulationOutput {
|
||||
std::string path_to_field);
|
||||
|
||||
void writeRestartData(std::mt19937* engine, int cpu_sync,
|
||||
bool overwrite_last);
|
||||
bool overwrite_last, int injectionGroupOffset);
|
||||
void writeRandomEngineState(std::mt19937* engine, std::string path);
|
||||
|
||||
void writeParticles(std::vector<particle::SerializedParticle>& particles,
|
||||
int cpu_sync, double dt);
|
||||
};
|
||||
|
||||
#endif /* SIMULATION_OUTPUT_H */
|
||||
|
||||
@@ -24,10 +24,10 @@ struct TrackedSpeciesBuilderInfo {
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution;
|
||||
std::shared_ptr<DriftVelocity> drift_velocity;
|
||||
std::shared_ptr<DynamicDensityField> last_sync_density_field;
|
||||
std::shared_ptr<DynamicDensityField> density_drawing_field;
|
||||
|
||||
double mass_kg;
|
||||
double charge_C;
|
||||
bool explicitly_stored;
|
||||
species::ImplementedSpecies type;
|
||||
std::string name;
|
||||
json_path path_in_json;
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
namespace generator {
|
||||
std::shared_ptr<VectorField> buildVectorField(json_t* object);
|
||||
std::string readAbsoluteFilename(json_t* object);
|
||||
blitz::Array<double, 3> readComponentFromFile(json_t* object, int component);
|
||||
blitz::Array<double, 3> readFromFile(json_t* object);
|
||||
blitz::Array<double, 2> readComponentFromFile(json_t* object, int component);
|
||||
blitz::Array<double, 2> readFromFile(json_t* object);
|
||||
} // namespace generator
|
||||
|
||||
#endif /* VECTOR_FIELD_GENERATOR_H */
|
||||
|
||||
@@ -10,18 +10,45 @@ class Specie;
|
||||
|
||||
namespace interaction {
|
||||
|
||||
// class for (radiative) cluster formation interactions (A + B --> AB)
|
||||
class ClusterFormation : public Interaction {
|
||||
public:
|
||||
ClusterFormation(std::function<double(double)> cross_section,
|
||||
std::shared_ptr<species::Specie> target,
|
||||
std::shared_ptr<species::TrackedSpecie> product);
|
||||
InteractionOutput performInteraction(particle::Particle& particle,
|
||||
virtual InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<species::TrackedSpecie> product_;
|
||||
};
|
||||
|
||||
// class for tertiary association (A + B + B --> AB + B or A + B2 -> AB + B)
|
||||
class ClusterFormationTertiary : public ClusterFormation {
|
||||
public:
|
||||
// Constructor: takes the function describing the cross section (dependent on the energy of the incident particle)
|
||||
// and a shared_ptr to the Species that is the target in the interaction
|
||||
// and a shared_ptr to the TrackedSpecie that is the product of the interaction
|
||||
ClusterFormationTertiary(std::function<double(double)> cross_section,
|
||||
std::shared_ptr<species::Specie> target,
|
||||
std::shared_ptr<species::TrackedSpecie> product,
|
||||
bool rate_coefficient = true);
|
||||
|
||||
// due to only the rate coefficients being available the cross section is
|
||||
// approximated as sigma = rate_coefficient * density / velocity
|
||||
// (units of the tertiary rate coefficient m^6/s)
|
||||
double microscopicCrossSection(double energy_eV, const Coordinate& position);
|
||||
|
||||
InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
|
||||
private:
|
||||
std::shared_ptr<species::TrackedSpecie> product_;
|
||||
// flag whether the "cross_section_" function is in truth calculated using a
|
||||
// three body association rate
|
||||
bool rate_coefficient_;
|
||||
};
|
||||
|
||||
|
||||
}; // namespace interaction
|
||||
|
||||
#endif /* CLUSTER_FORMATION_H */
|
||||
|
||||
@@ -15,7 +15,8 @@ class ElasticScattering : public Interaction {
|
||||
|
||||
InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
|
||||
virtual double drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
private:
|
||||
std::shared_ptr<ScatteringAngleDistribution> theta_distrib_;
|
||||
};
|
||||
|
||||
@@ -13,8 +13,10 @@ class FreeMovement : public Interaction {
|
||||
InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
|
||||
double microscopicCrossSection(double energy_eV);
|
||||
double microscopicCrossSection(double energy_eV, const Coordinate& position);
|
||||
double macroscopicCrossSection(particle::Particle& particle);
|
||||
double drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
};
|
||||
|
||||
}; // namespace interaction
|
||||
|
||||
@@ -15,6 +15,8 @@ class Recombination : public Interaction {
|
||||
|
||||
double macroscopicCrossSection(particle::Particle& particle);
|
||||
|
||||
double drawCollisionTime(particle::Particle& particle, RandomNumbers* generator);
|
||||
|
||||
private:
|
||||
double macroscopicCrossSection(const Coordinate& position, const int bin_index);
|
||||
std::shared_ptr<species::TrackedSpecie> recombination_target_;
|
||||
|
||||
@@ -29,11 +29,14 @@ struct GlobalBoundary {
|
||||
BoundaryType type;
|
||||
};
|
||||
|
||||
|
||||
// only useful at the initialization of the PoissonSolver...
|
||||
// (or if at later times a time dependent value is desired)
|
||||
class Electrode {
|
||||
public:
|
||||
Electrode(double potential);
|
||||
virtual bool isOnElectrode(const Coordinate& position) = 0;
|
||||
double electrodePotential();
|
||||
virtual double electrodePotential();
|
||||
|
||||
protected:
|
||||
const double potential_;
|
||||
@@ -45,6 +48,21 @@ class RearWall : public Electrode {
|
||||
bool isOnElectrode(const Coordinate& position);
|
||||
};
|
||||
|
||||
class RingElectrode : public Electrode {
|
||||
public:
|
||||
RingElectrode(double potential, const double zPosition,
|
||||
const double innerRadius,
|
||||
const double outerRadius,
|
||||
const blitz::TinyVector<double, 2> stepsize);
|
||||
bool isOnElectrode(const Coordinate& position);
|
||||
|
||||
private:
|
||||
// stores (rinner, router, zpos) in this order
|
||||
blitz::TinyVector<double,3> specs_;
|
||||
blitz::TinyVector<double,2> stepsize_;
|
||||
};
|
||||
|
||||
// for (r,z) axially density
|
||||
class PoissonSolver {
|
||||
public:
|
||||
PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
@@ -57,13 +75,12 @@ class PoissonSolver {
|
||||
int num_cycles,
|
||||
bool do_solver);
|
||||
|
||||
void solvePotential(const blitz::Array<double, 3> charge_density,
|
||||
const bool solve);
|
||||
blitz::Array<double, 3> potential();
|
||||
void solvePotential(const blitz::Array<double, 2> charge_density);
|
||||
blitz::Array<double, 2> potential();
|
||||
std::shared_ptr<VectorField> staticElectricField();
|
||||
const CylinderBinning* densityBinning();
|
||||
|
||||
void setPotential(blitz::Array<double, 3>& potential);
|
||||
void setPotential(blitz::Array<double, 2>& potential);
|
||||
|
||||
private:
|
||||
GlobalBoundary bottom_boundary_;
|
||||
@@ -79,13 +96,13 @@ class PoissonSolver {
|
||||
// density binning defined on the cell centers, potential defined
|
||||
// such that it exists on the cell edges so that the azimuthal
|
||||
// position is the same as the one of the density binning
|
||||
blitz::Array<PotentialGridPoint, 3> potential_; //unit V
|
||||
blitz::Array<PotentialGridPoint, 2> potential_; //unit V
|
||||
|
||||
blitz::Array<double, 3> interpolateDensityToPotentialGrid(
|
||||
const blitz::Array<double, 3> charge_density);
|
||||
blitz::Array<double, 2> interpolateDensityToPotentialGrid(
|
||||
const blitz::Array<double, 2> charge_density);
|
||||
|
||||
void solverIteration(const blitz::Array<double, 3>& interpolated_density);
|
||||
bool converged(const blitz::Array<double, 3>& interpolated_density);
|
||||
void solverIteration(const blitz::Array<double, 2>& interpolated_density);
|
||||
bool converged(const blitz::Array<double, 2>& interpolated_density);
|
||||
};
|
||||
|
||||
// Electrodes can only be dirichlet boundary conditions
|
||||
|
||||
@@ -27,6 +27,9 @@ class Coordinate {
|
||||
virtual blitz::TinyVector<double, 3> cartesianEntries() const = 0;
|
||||
virtual blitz::TinyVector<double, 3> cylinderEntries() const = 0;
|
||||
|
||||
virtual double cosAzimuth() const = 0;
|
||||
virtual double sinAzimuth() const = 0;
|
||||
|
||||
virtual void add(const Coordinate& coordinate) = 0;
|
||||
};
|
||||
|
||||
@@ -38,6 +41,9 @@ class CartesianCoordinate : public Coordinate {
|
||||
blitz::TinyVector<double, 3> cartesianEntries() const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries() const;
|
||||
|
||||
double cosAzimuth() const;
|
||||
double sinAzimuth() const;
|
||||
|
||||
void add(const Coordinate& coordinate);
|
||||
|
||||
private:
|
||||
@@ -52,11 +58,17 @@ class CylinderCoordinate : public Coordinate {
|
||||
blitz::TinyVector<double, 3> cartesianEntries() const;
|
||||
blitz::TinyVector<double, 3> cylinderEntries() const;
|
||||
|
||||
double cosAzimuth() const;
|
||||
double sinAzimuth() const;
|
||||
|
||||
void add(const Coordinate& coordinate);
|
||||
|
||||
private:
|
||||
void limitPhi();
|
||||
blitz::TinyVector<double, 3> cylinder_position;
|
||||
#ifdef debug
|
||||
bool phi_was_set = false;
|
||||
#endif
|
||||
};
|
||||
|
||||
class Vector {
|
||||
|
||||
@@ -21,11 +21,9 @@ class CpuSynchronizer {
|
||||
|
||||
void synchronize(
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
|
||||
tracked_species, bool reset);
|
||||
tracked_species);
|
||||
|
||||
void synchronize(DynamicDensityField* field,
|
||||
DynamicDensityField* density_for_drawing,
|
||||
bool reset);
|
||||
void synchronize(DynamicDensityField* field);
|
||||
void synchronize(CurrentCollector* collector);
|
||||
void synchronize(DeletionLogger* logger);
|
||||
void synchronize(Timer* timer, Timer* last_sync_timer);
|
||||
@@ -34,10 +32,6 @@ class CpuSynchronizer {
|
||||
/*
|
||||
sums delta = * - last_sync_* to last_sync_* over all CPUs
|
||||
*/
|
||||
void sumToAll(blitz::Array<double, 4>& array,
|
||||
blitz::Array<double, 4>& last_sync_array);
|
||||
void sumToAll(blitz::Array<double, 5>& array,
|
||||
blitz::Array<double, 5>& last_sync_array);
|
||||
void sumToAll(blitz::Array<double, 3>& array,
|
||||
blitz::Array<double, 3>& last_sync_array);
|
||||
void sumToAll(blitz::Array<long int, 4>& array,
|
||||
@@ -46,6 +40,18 @@ class CpuSynchronizer {
|
||||
blitz::Array<long int, 5>& last_sync_array);
|
||||
void sumToAll(double& value, double& last_sync_value);
|
||||
void sumToAll(long int& value, long int& last_sync_value);
|
||||
|
||||
// array has to be the delta of the timestep
|
||||
void sumToAll(blitz::Array<double, 5>& array);
|
||||
void sumToAll(blitz::Array<double, 4>& array);
|
||||
|
||||
// collect data to rank 0 functions
|
||||
void sumToRoot(blitz::Array<double, 3>& array);
|
||||
void sumToRoot(blitz::Array<double, 2>& array);
|
||||
void sumToRoot(long int& value);
|
||||
void sumToRoot(double& value);
|
||||
|
||||
const int root = 0;
|
||||
};
|
||||
|
||||
#endif /* CPU_SYNCHRONIZER_H */
|
||||
|
||||
@@ -14,20 +14,28 @@ class CurrentCollector {
|
||||
|
||||
void collect(particle::Particle* particle, const Coordinate& old_position);
|
||||
|
||||
blitz::Array<double, 3> negativeCrossingsInR() const;
|
||||
blitz::Array<double, 3> positiveCrossingsInR() const;
|
||||
blitz::Array<double, 3> areaInR() const;
|
||||
blitz::Array<double, 3> currentInR() const;
|
||||
blitz::Array<double, 2> negativeCrossingsInR() const;
|
||||
blitz::Array<double, 2> positiveCrossingsInR() const;
|
||||
blitz::Array<double, 2> areaInR() const;
|
||||
blitz::Array<double, 2> currentInR() const;
|
||||
|
||||
blitz::Array<double, 3> negativeCrossingsInPhi() const;
|
||||
blitz::Array<double, 3> positiveCrossingsInPhi() const;
|
||||
blitz::Array<double, 3> areaInPhi() const;
|
||||
blitz::Array<double, 3> currentInPhi() const;
|
||||
blitz::Array<double, 2> negativeCrossingsInPhi() const;
|
||||
blitz::Array<double, 2> positiveCrossingsInPhi() const;
|
||||
blitz::Array<double, 2> areaInPhi() const;
|
||||
blitz::Array<double, 2> currentInPhi() const;
|
||||
|
||||
blitz::Array<double, 3> negativeCrossingsInZ() const;
|
||||
blitz::Array<double, 3> positiveCrossingsInZ() const;
|
||||
blitz::Array<double, 3> areaInZ() const;
|
||||
blitz::Array<double, 3> currentInZ() const;
|
||||
blitz::Array<double, 2> negativeCrossingsInZ() const;
|
||||
blitz::Array<double, 2> positiveCrossingsInZ() const;
|
||||
blitz::Array<double, 2> areaInZ() 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;
|
||||
|
||||
@@ -36,52 +44,55 @@ class CurrentCollector {
|
||||
friend class CpuSynchronizer;
|
||||
|
||||
private:
|
||||
void collectRadialMovement(const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
void collectRadialMovement(const blitz::TinyVector<int, 2>& bin_old,
|
||||
const blitz::TinyVector<int, 2>& bin_new,
|
||||
const double weight);
|
||||
void collectLongitudinalMovement(const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
void collectLongitudinalMovement(const blitz::TinyVector<int, 2>& bin_old,
|
||||
const blitz::TinyVector<int, 2>& bin_new,
|
||||
#ifdef GENRICHCURRENT
|
||||
const double energy_eV,
|
||||
#endif
|
||||
const double weight);
|
||||
void collectAzimuthalMovement(const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
void collectAzimuthalMovement(const blitz::TinyVector<double, 3>& old_pos_cart,
|
||||
const blitz::TinyVector<double, 3>& new_pos_cart,
|
||||
const blitz::TinyVector<int,2>& bin_old,
|
||||
const double weight);
|
||||
|
||||
blitz::Array<double, 3> createAreaLongitudinal(
|
||||
blitz::Array<double, 2> createAreaLongitudinal(
|
||||
const CylinderBinning& position_binning);
|
||||
blitz::Array<double, 3> createCrossingsLongitudinal(
|
||||
blitz::Array<double, 2> createCrossingsLongitudinal(
|
||||
const CylinderBinning& position_binning);
|
||||
|
||||
blitz::Array<double, 3> createAreaRadial(
|
||||
blitz::Array<double, 2> createAreaRadial(
|
||||
const CylinderBinning& position_binning);
|
||||
blitz::Array<double, 3> createCrossingsRadial(
|
||||
blitz::Array<double, 2> createCrossingsRadial(
|
||||
const CylinderBinning& position_binning);
|
||||
|
||||
blitz::Array<double, 3> createAreaAzimuthal(
|
||||
blitz::Array<double, 2> createAreaAzimuthal(
|
||||
const CylinderBinning& position_binning);
|
||||
blitz::Array<double, 3> createCrossingsAzimuthal(
|
||||
blitz::Array<double, 2> createCrossingsAzimuthal(
|
||||
const CylinderBinning& position_binning);
|
||||
|
||||
blitz::Array<double, 3> z_negative_crossings;
|
||||
blitz::Array<double, 3> z_positive_crossings;
|
||||
blitz::Array<double, 2> z_negative_crossings;
|
||||
blitz::Array<double, 2> z_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> phi_negative_crossings;
|
||||
blitz::Array<double, 3> phi_positive_crossings;
|
||||
blitz::Array<double, 2> phi_negative_crossings;
|
||||
blitz::Array<double, 2> phi_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> r_negative_crossings;
|
||||
blitz::Array<double, 3> r_positive_crossings;
|
||||
blitz::Array<double, 2> r_negative_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, 2> collector_areas_r;
|
||||
blitz::Array<double, 2> collector_areas_phi;
|
||||
blitz::Array<double, 2> collector_areas_z;
|
||||
|
||||
blitz::Array<double, 3> sync_phi_negative_crossings;
|
||||
blitz::Array<double, 3> sync_phi_positive_crossings;
|
||||
#ifdef GENRICHCURRENT
|
||||
blitz::Array<double, 2> sample_z_negative_crossings;
|
||||
EnergyBinning energy_binning_;
|
||||
|
||||
blitz::Array<double, 3> sync_r_negative_crossings;
|
||||
blitz::Array<double, 3> sync_r_positive_crossings;
|
||||
|
||||
blitz::Array<double, 3> collector_areas_r;
|
||||
blitz::Array<double, 3> collector_areas_phi;
|
||||
blitz::Array<double, 3> collector_areas_z;
|
||||
bool needs_reset = false;
|
||||
double time_since_reset = 0;
|
||||
#endif //GENRICHCURRENT
|
||||
|
||||
CylinderBinning position_binning_;
|
||||
std::shared_ptr<Timer> timer_;
|
||||
|
||||
@@ -31,7 +31,6 @@ class DynamicDensityField : public DensityField {
|
||||
|
||||
double density(const Coordinate& position);
|
||||
double density(const Coordinate& position, double energy_eV);
|
||||
double density(const Coordinate& position, double energy_split, bool above);
|
||||
|
||||
bool changedPositionBin(const Coordinate& old_position,
|
||||
const Coordinate& new_position) const;
|
||||
@@ -40,40 +39,26 @@ class DynamicDensityField : public DensityField {
|
||||
|
||||
void logMovement(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle,
|
||||
double time_in_bin_s);
|
||||
|
||||
void logDeletion(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle);
|
||||
|
||||
// return the particle number stored in the density of this object
|
||||
double particleNumber();
|
||||
// return the particle number stored for energies higher than E_thresh
|
||||
// (above = true) or for energies below (above = false)
|
||||
// The energy bin, in which E_thresh is located, will be included in the
|
||||
// 'above=true' case (and excluded in the other case)
|
||||
double particleNumber(double E_thresh, bool above);
|
||||
double pitch_angle,
|
||||
double weight);
|
||||
|
||||
// returns true if the old pitch angle and the new pitch angle are in different bins
|
||||
// of the pitch angle binning
|
||||
bool changedPitchAngleBin(double old_pitch_angle, double new_pitch_angle) const;
|
||||
|
||||
blitz::Array<double, 3> densityArray();
|
||||
blitz::Array<double, 4> spectrumArray();
|
||||
blitz::Array<double, 5> timeInBinArray() const;
|
||||
blitz::Array<long int, 5> deletedParticlesArray() const;
|
||||
blitz::Array<double, 3> binVolumeArray() const;
|
||||
|
||||
blitz::Array<double, 3> densityArray(double energy_split, bool above);
|
||||
blitz::Array<double, 2> densityArray();
|
||||
blitz::Array<double, 3> spectrumArray();
|
||||
blitz::Array<double, 4> numberInBinArray() const;
|
||||
blitz::Array<double, 2> binVolumeArray() const;
|
||||
|
||||
// return an array of the density values at the Coordinate position (only energy
|
||||
// direction left); overbin is removed
|
||||
// direction left); over and underflow bin are removed
|
||||
// (might not be good, since then the underflow particles are lost...)
|
||||
blitz::Array<double, 1> sliceSpectrumArray(const Coordinate& position) const;
|
||||
|
||||
// return an array of the time in bin at the Coordinate position and the energy
|
||||
// energy_eV (only pitch angle direction left); over and underflow bin are removed
|
||||
blitz::Array<double, 1> sliceTimeInBinArray(const Coordinate& position,
|
||||
blitz::Array<double, 1> sliceNumberInBinArray(const Coordinate& position,
|
||||
double energy_eV) const;
|
||||
|
||||
const EnergyBinning* energyBinning() const;
|
||||
@@ -88,22 +73,19 @@ class DynamicDensityField : public DensityField {
|
||||
friend class CpuSynchronizer;
|
||||
|
||||
void restartTimer(double time, double delta_t);
|
||||
void restartTimeInBin(blitz::Array<double, 5> time_in_bin);
|
||||
void restartDeletedParticlesArray(blitz::Array<long int, 5> deleted_particles);
|
||||
|
||||
private:
|
||||
void restartNumberInBin(blitz::Array<double, 4> number_in_bin);
|
||||
|
||||
void recalculateDensityArray();
|
||||
|
||||
// use ordering r, phi, z, pitch_angle, E
|
||||
blitz::Array<double, 5> time_in_bin_s_;
|
||||
blitz::Array<long int, 5> deleted_particles_;
|
||||
private:
|
||||
|
||||
blitz::Array<double, 5> sync_time_in_bin_s_;
|
||||
blitz::Array<long int, 5> sync_deleted_particles_;
|
||||
// use ordering r, z, pitch_angle, E.
|
||||
// Full symmetry in azimuthal direction -> no phi resolution
|
||||
blitz::Array<double, 4> number_in_bin_;
|
||||
blitz::Array<double, 4> sync_number_in_bin_;
|
||||
|
||||
blitz::Array<double, 4> density_per_m3_;
|
||||
blitz::Array<double, 3> bin_volume_m3_;
|
||||
blitz::Array<double, 3> density_per_m3_;
|
||||
blitz::Array<double, 2> bin_volume_m3_;
|
||||
|
||||
const CylinderBinning position_binning_;
|
||||
const EnergyBinning energy_binning_;
|
||||
|
||||
@@ -11,6 +11,8 @@ class DriftVelocity {
|
||||
DriftVelocity(std::shared_ptr<VectorField> drift_velocity);
|
||||
|
||||
CartesianVector driftVelocity(const Coordinate& position);
|
||||
CartesianVector driftVelocity(const CartesianCoordinate& cartCoord,
|
||||
const CylinderCoordinate& cylCoord);
|
||||
|
||||
private:
|
||||
std::shared_ptr<VectorField> drift_velocity_;
|
||||
|
||||
@@ -20,6 +20,17 @@ class TritiumBetaDecay : public EnergyDistributionFunction {
|
||||
std::uniform_real_distribution<double> y_distribution_;
|
||||
};
|
||||
|
||||
class TritiumBetaDecayIon : public EnergyDistributionFunction {
|
||||
public:
|
||||
TritiumBetaDecayIon(double endpoint_eV);
|
||||
double rollEnergy(std::mt19937* engine);
|
||||
|
||||
private:
|
||||
const std::function<double(double)> tritium_spectrum_, tritium_spectrum_ion_;
|
||||
std::uniform_real_distribution<double> x_distribution_;
|
||||
std::uniform_real_distribution<double> y_distribution_;
|
||||
};
|
||||
|
||||
class MaxwellBoltzmann : public EnergyDistributionFunction {
|
||||
public:
|
||||
MaxwellBoltzmann(double temperature_K);
|
||||
|
||||
@@ -37,37 +37,4 @@ class EventPositionDistribution {
|
||||
std::uniform_real_distribution<double> density_values;
|
||||
};
|
||||
|
||||
// Class to draw a position from the density provided by a pointer
|
||||
// to a DynamicDensityField object
|
||||
class PositionDistributionFromDensity {
|
||||
public:
|
||||
// Constructor taking a pointer to a DynamicDensityField object
|
||||
PositionDistributionFromDensity(std::shared_ptr<DynamicDensityField> density);
|
||||
|
||||
// draw a position from the density provided at construction using the rejection method
|
||||
CylinderCoordinate drawPosition(std::mt19937* engine);
|
||||
|
||||
CylinderCoordinate drawPosition(std::mt19937* engine, double energy_split, bool above);
|
||||
// sets the maximum density value needed for the rejection method
|
||||
// should not be called frequently, since during each call the density field is
|
||||
// recalculated from scratch by the DynamicDensityField object
|
||||
void setMaximumDensity();
|
||||
void setMaximumDensityAboveAndBelow(double energy_split);
|
||||
|
||||
private:
|
||||
// variable storing the maximum value of the density
|
||||
double maximum_density_ = 1.;
|
||||
|
||||
double maximum_density_below_ = 1.;
|
||||
double maximum_density_above_ = 1.;
|
||||
|
||||
std::shared_ptr<DynamicDensityField> density_;
|
||||
|
||||
// distributions for the spatial directions and for the density
|
||||
std::uniform_real_distribution<double> r_values;
|
||||
std::uniform_real_distribution<double> phi_values;
|
||||
std::uniform_real_distribution<double> z_values;
|
||||
std::uniform_real_distribution<double> density_values;
|
||||
};
|
||||
|
||||
#endif /* EVENT_POSITION_DISTRIBUTION_H */
|
||||
|
||||
@@ -28,7 +28,9 @@ struct InjectorInfo {
|
||||
public:
|
||||
std::shared_ptr<species::TrackedSpecie> created_specie;
|
||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution;
|
||||
// int multiplicity;
|
||||
double weight = 0;
|
||||
int injection_group;
|
||||
int injection_stride;
|
||||
};
|
||||
|
||||
class Injector {
|
||||
@@ -39,36 +41,21 @@ class Injector {
|
||||
std::shared_ptr<DriftVelocity> mother_drift_velocity);
|
||||
|
||||
std::vector<particle::Particle> rollNewParticles(std::mt19937* engine,
|
||||
const double current_time,
|
||||
const double beta_particle_weight);
|
||||
const int timestep);
|
||||
|
||||
// draw new particles from the DynamicDensityField of the provided specie
|
||||
// the new particles are then appened to the vector queue
|
||||
// the magnetic field is necessary for the determination of the direction of the
|
||||
// injected particles
|
||||
// the weight scales the time a particle contributes to a certain bin
|
||||
// and the injection time specifies the time the particle is injected (has to be
|
||||
// between T, T+\DeltaT)
|
||||
void drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::vector<particle::Particle>& queue,
|
||||
std::shared_ptr<MagneticField> field,
|
||||
const double weight,
|
||||
const double injection_time);
|
||||
// physical_number: physical number of particles that are injected in one
|
||||
// timestep
|
||||
// numerical_number: number of numerical beta particles to be injected on
|
||||
// a single process
|
||||
void setWeights(const double physical_number, const int numerical_number);
|
||||
|
||||
void initInjectionTimeDistribution(double delta_t);
|
||||
|
||||
double timePassed() const;
|
||||
|
||||
void fillParticleNumbers(std::shared_ptr<species::TrackedSpecie> specie);
|
||||
|
||||
double energySplit() const;
|
||||
|
||||
private:
|
||||
std::vector<InjectorInfo> injector_infos_;
|
||||
const double activity_;
|
||||
double energySplit_;
|
||||
std::map<std::string, std::vector<double>> particleNumbersMap_;
|
||||
std::shared_ptr<EventPositionDistribution> position_distribution_;
|
||||
std::shared_ptr<DriftVelocity> mother_drift_velocity_;
|
||||
std::uniform_real_distribution<double> injection_time_distribution_;
|
||||
@@ -80,13 +67,6 @@ class Injector {
|
||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution,
|
||||
const double time_birth,
|
||||
const double weight);
|
||||
|
||||
particle::Particle drawNewDensityParticleAboveOrBelow(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::shared_ptr<MagneticField> field,
|
||||
const double weight,
|
||||
const double injection_time,
|
||||
const bool above);
|
||||
};
|
||||
|
||||
#endif /* INJECTOR_H */
|
||||
|
||||
@@ -30,15 +30,22 @@ class Interaction {
|
||||
Interaction(std::function<double(double)> cross_section,
|
||||
std::shared_ptr<species::Specie> target);
|
||||
|
||||
virtual double microscopicCrossSection(double energy_eV);
|
||||
virtual double microscopicCrossSection(double energy_eV, const Coordinate& position);
|
||||
virtual double macroscopicCrossSection(particle::Particle& particle);
|
||||
|
||||
// return the time the given particle can travel in the laboratory frame
|
||||
// before this specific interaction occurs (also stores the velocity of the
|
||||
// target particle)
|
||||
virtual double drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator);
|
||||
|
||||
virtual InteractionOutput performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator) = 0;
|
||||
|
||||
protected:
|
||||
std::function<double(double)> cross_section_;
|
||||
std::shared_ptr<species::Specie> target_;
|
||||
CartesianVector target_velocity_;
|
||||
};
|
||||
|
||||
}; // namespace interaction
|
||||
|
||||
@@ -20,6 +20,10 @@ blitz::TinyVector<double, 3> rotateVector(const blitz::TinyVector<double, 3>& v,
|
||||
double theta,
|
||||
double phi);
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVector2(const blitz::TinyVector<double, 3>& v,
|
||||
double theta,
|
||||
double phi);
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
|
||||
const blitz::TinyVector<double, 3>& velocity_1,
|
||||
const blitz::TinyVector<double, 3>& velocity_2,
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/particle.h"
|
||||
|
||||
// to count numerical particle deletions
|
||||
enum class DeletionType {
|
||||
wall,
|
||||
recombination,
|
||||
@@ -13,13 +14,23 @@ enum class DeletionType {
|
||||
cluster_formation
|
||||
};
|
||||
|
||||
// to count physical particle deletion
|
||||
enum class PhysicalDeletionType {
|
||||
wall
|
||||
};
|
||||
class Coordinate;
|
||||
|
||||
class DeletionLogger {
|
||||
public:
|
||||
DeletionLogger(std::vector<DeletionType> used_types);
|
||||
DeletionLogger(std::vector<DeletionType> used_types,
|
||||
std::vector<PhysicalDeletionType> used_phys_types);
|
||||
// why a coordinate as a parameter -> not used in implementation
|
||||
virtual void logDeletion(const Coordinate& coordinate, DeletionType type);
|
||||
virtual void logDeletion(const particle::Particle& particle,
|
||||
PhysicalDeletionType type);
|
||||
|
||||
std::map<DeletionType, long int> numDeletions() const;
|
||||
std::map<PhysicalDeletionType, double> numPhysDeletions() const;
|
||||
void numDeletions(long int new_value, DeletionType type);
|
||||
long int numDeletions(DeletionType type) const;
|
||||
|
||||
@@ -29,7 +40,11 @@ class DeletionLogger {
|
||||
|
||||
private:
|
||||
std::map<DeletionType, long int> num_deletions;
|
||||
std::map<DeletionType, long int> sync_num_deletions;
|
||||
// std::map<DeletionType, long int> sync_num_deletions;
|
||||
|
||||
std::map<PhysicalDeletionType, double> num_phys_deletions;
|
||||
// std::map<PhysicalDeletionType, double> sync_num_phys_deletions;
|
||||
|
||||
};
|
||||
|
||||
#endif /* LOGGER_H */
|
||||
|
||||
@@ -4,10 +4,16 @@
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
#include "simulation/particle.h"
|
||||
|
||||
class CylinderCoordinate;
|
||||
/*
|
||||
change the mfp_m variable to a time_s variable!
|
||||
*/
|
||||
|
||||
class Mover {
|
||||
public:
|
||||
virtual void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
// return the last position, with which the particle has been checked to be alive with
|
||||
virtual CylinderCoordinate move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) = 0;
|
||||
@@ -17,8 +23,8 @@ class BorisMover : public Mover {
|
||||
public:
|
||||
BorisMover(double maximal_time_step_s);
|
||||
|
||||
void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
CylinderCoordinate move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field);
|
||||
@@ -30,7 +36,7 @@ class BorisMover : public Mover {
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const blitz::TinyVector<double, 3>& gravity_field,
|
||||
double& moved_distance,
|
||||
// double& moved_distance,
|
||||
double timestep) const;
|
||||
};
|
||||
|
||||
@@ -38,8 +44,8 @@ class DriftMover : public Mover {
|
||||
public:
|
||||
DriftMover(double maximal_distance);
|
||||
|
||||
void move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
CylinderCoordinate move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef MPI_COMMUNICATION_H
|
||||
#define MPI_COMMUNICATION_H
|
||||
|
||||
#include "mpi.h"
|
||||
class MpiCommunication {
|
||||
public:
|
||||
static int mpi_rank;
|
||||
@@ -10,6 +11,9 @@ class MpiCommunication {
|
||||
static int mpiSize();
|
||||
|
||||
static void init(int argc, char* argv[]);
|
||||
|
||||
static void create_mpi_info(MPI_Info* info);
|
||||
|
||||
static void finalize();
|
||||
};
|
||||
|
||||
|
||||
@@ -5,21 +5,64 @@
|
||||
#include "simulation/coordinates.h"
|
||||
#include "simulation/species.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
class MpiParticleReader;
|
||||
|
||||
namespace particle {
|
||||
|
||||
class SerializedParticle {
|
||||
public:
|
||||
SerializedParticle(double weight,
|
||||
blitz::TinyVector<double, 3> cart_pos,
|
||||
blitz::TinyVector<double, 3> cart_vel,
|
||||
std::string spec_name,
|
||||
int next_interaction_index,
|
||||
double time_until_interaction);
|
||||
SerializedParticle() {};
|
||||
|
||||
double weight();
|
||||
blitz::TinyVector<double, 3> cartesianPosition();
|
||||
blitz::TinyVector<double, 3> cartesianVelocity();
|
||||
std::string specieName();
|
||||
double timeUntilCollision();
|
||||
int indexNextInteraction();
|
||||
|
||||
private:
|
||||
blitz::TinyVector<double, 3> cartesian_position_;
|
||||
blitz::TinyVector<double, 3> cartesian_velocity_;
|
||||
// has to include null character, s.t. the transformation back
|
||||
// to a string becomes trivial. This requires the actual string
|
||||
// to be 16-1=15 characters long at most
|
||||
// (it can be shorter due to the null character)
|
||||
// Example: "e-" -> ['e', '-', '\0', ...] gets correctly transformed back
|
||||
// into "e-"
|
||||
std::array<char, 16> specie_name_;
|
||||
double weight_;
|
||||
|
||||
int idx_nxt_interaction_;
|
||||
double time_until_interaction_;
|
||||
};
|
||||
|
||||
class Particle {
|
||||
public:
|
||||
// Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
// Coordinate* position,
|
||||
// Vector* velocity);
|
||||
Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
const Coordinate& position,
|
||||
const Vector& velocity,
|
||||
const double time_birth,
|
||||
const double weight);
|
||||
|
||||
Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
const Coordinate& position,
|
||||
const Vector& velocity,
|
||||
const double weight);
|
||||
|
||||
Particle(particle::SerializedParticle sparticle, std::map<std::string,
|
||||
std::shared_ptr<species::TrackedSpecie>>& tracked_species);
|
||||
|
||||
void position(const Coordinate& new_position);
|
||||
CartesianCoordinate position() const;
|
||||
CartesianCoordinate cartesianPosition() const;
|
||||
CylinderCoordinate cylinderPosition() const;
|
||||
|
||||
void velocity(const CartesianVector& new_velocity);
|
||||
CartesianVector velocity() const;
|
||||
@@ -44,24 +87,51 @@ class Particle {
|
||||
void increaseTimeAlive(double time_s);
|
||||
double timeAlive() const;
|
||||
|
||||
void increaseTimeInBin(double time_s);
|
||||
void resetTimeInBin();
|
||||
double timeInBin() const;
|
||||
|
||||
long int ID() const;
|
||||
|
||||
double weight() const;
|
||||
|
||||
void indexNextInteration(const int index) { index_next_interaction_ = index; };
|
||||
int indexNextInteraction() { return index_next_interaction_; };
|
||||
void invalidateNextInteraction() { index_next_interaction_ = -1; };
|
||||
bool isNextInteractionValid() { return index_next_interaction_ >= 0; };
|
||||
|
||||
void timeUntilCollision(const double time_until_collision);
|
||||
double timeUntilCollision() const;
|
||||
void reduceTimeUntilCollision(const double delta);
|
||||
|
||||
void deposited(bool truthValue=true);
|
||||
bool wasDeposited();
|
||||
|
||||
void setLocalFields(const blitz::TinyVector<double,3>& E,
|
||||
const blitz::TinyVector<double,3>& B);
|
||||
blitz::TinyVector<double, 3> getLocalE() const;
|
||||
blitz::TinyVector<double, 3> getLocalB() const;
|
||||
bool areLocalFieldsSet() const;
|
||||
|
||||
// note: particle id is not being stored!
|
||||
particle::SerializedParticle serialize();
|
||||
|
||||
private:
|
||||
double weight_;
|
||||
|
||||
CartesianVector velocity_;
|
||||
CartesianCoordinate position_;
|
||||
CartesianCoordinate position_cart_;
|
||||
CylinderCoordinate position_cyl_;
|
||||
|
||||
blitz::TinyVector<double, 3> local_E_cart_ = 0.;
|
||||
blitz::TinyVector<double, 3> local_B_cart_ = 0.;
|
||||
|
||||
double time_alive_s_;
|
||||
double time_in_bin_s_;
|
||||
// double time_in_bin_s_;
|
||||
long int interaction_counter_;
|
||||
|
||||
bool deposited_ = false;
|
||||
bool set_local_fields_ = false;
|
||||
// index of the interaction with the sortest distance (-1 if that's none of them)
|
||||
int index_next_interaction_ = -1;
|
||||
double time_until_collision_;
|
||||
|
||||
std::shared_ptr<species::TrackedSpecie> specie_;
|
||||
long int id_;
|
||||
|
||||
|
||||
@@ -60,21 +60,19 @@ class CylinderBinning {
|
||||
public:
|
||||
CylinderBinning(int num_bins_radial,
|
||||
double radius,
|
||||
int num_bins_azimuthal,
|
||||
int num_bins_longitudinal,
|
||||
double height);
|
||||
|
||||
blitz::TinyVector<int, 3> bin(
|
||||
blitz::TinyVector<int, 2> bin(
|
||||
const blitz::TinyVector<double, 3>& cylinder_position) const;
|
||||
blitz::TinyVector<double, 3> stepsize() const;
|
||||
blitz::TinyVector<double, 2> stepsize() const;
|
||||
|
||||
blitz::TinyVector<int, 3> numBins() const;
|
||||
blitz::TinyVector<int, 3> numBinsIncludingOverUnderflow() const;
|
||||
blitz::TinyVector<int, 3> binIndexMin() const;
|
||||
blitz::TinyVector<int, 3> binIndexMax() const;
|
||||
blitz::TinyVector<int, 2> numBins() const;
|
||||
blitz::TinyVector<int, 2> numBinsIncludingOverUnderflow() const;
|
||||
blitz::TinyVector<int, 2> binIndexMin() const;
|
||||
blitz::TinyVector<int, 2> binIndexMax() const;
|
||||
|
||||
const LowerBoundBinningWithOverflow radial_binning;
|
||||
const LowerAndUpperBoundBinning azimuth_binning;
|
||||
const BinningWithOverAndUnderflow longitudinal_binning;
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <memory>
|
||||
#include <random>
|
||||
|
||||
#include "blitz/array.h"
|
||||
|
||||
class RandomNumbers {
|
||||
public:
|
||||
RandomNumbers(int seed);
|
||||
@@ -19,4 +21,31 @@ class RandomNumbers {
|
||||
std::uniform_real_distribution<double> real_distribution_;
|
||||
};
|
||||
|
||||
// class to handle a random walk through a density field, where every
|
||||
// bin is visited exactly once
|
||||
class RandomIndex {
|
||||
public:
|
||||
// num_bins: contains the number of bins of all dimensions of a
|
||||
// density binning (order: radial, azimuthal, longitudinal,
|
||||
// pitch angle, energy)
|
||||
RandomIndex(blitz::TinyVector<int, 5> num_bins);
|
||||
|
||||
// get the next index
|
||||
blitz::TinyVector<int, 5> index();
|
||||
|
||||
// check if all bins have been visited
|
||||
bool visited_all();
|
||||
|
||||
// create a new random order and reset the check if all bins have been visited
|
||||
void reshuffle(std::mt19937* engine);
|
||||
|
||||
private:
|
||||
const blitz::TinyVector<int, 5> num_bins_;
|
||||
|
||||
std::vector<size_t> one_dimensional_indices_;
|
||||
|
||||
size_t total_bin_number_;
|
||||
size_t current_index_in_vector_;
|
||||
};
|
||||
|
||||
#endif /* RANDOM_NUMBERS_H */
|
||||
|
||||
@@ -20,6 +20,16 @@ class ReflectorDPS : public Reflector {
|
||||
const double z_position_dps_;
|
||||
};
|
||||
|
||||
class LongitudinalReflector : public Reflector {
|
||||
public:
|
||||
LongitudinalReflector(double height);
|
||||
bool needsReflectionBackToDomain(const particle::Particle* particle) const;
|
||||
void reflectBackToDomain(particle::Particle* particle) const;
|
||||
|
||||
private:
|
||||
const double height_;
|
||||
};
|
||||
|
||||
class NoReflector : public Reflector {
|
||||
bool needsReflectionBackToDomain(const particle::Particle* particle) const;
|
||||
void reflectBackToDomain(particle::Particle* particle) const;
|
||||
|
||||
@@ -34,30 +34,25 @@ class Simulation {
|
||||
void init(Parameter& parameter);
|
||||
void start();
|
||||
void finalize();
|
||||
// cpu_syncs only included for debug purposes, e.g. only drawing decay particles
|
||||
// at the 0th timestep
|
||||
void processEvents(int events, const double beta_particle_weight);
|
||||
void processEvents(int events);
|
||||
|
||||
void processDensityEvents(int events, const double weight_factor);
|
||||
void processDensityEvents();
|
||||
void processUntilTermination(particle::Particle& particle);
|
||||
|
||||
private:
|
||||
std::vector<particle::Particle> determineInjectedParticles(RandomNumbers* random,
|
||||
const double beta_particle_weight);
|
||||
std::vector<particle::Particle> determineInjectedDensityParticles(
|
||||
RandomNumbers* random,
|
||||
const double weight_factor,
|
||||
const int current,
|
||||
std::map<std::string, double>& particleNumbers);
|
||||
|
||||
double meanFreePath(particle::Particle& particle, RandomNumbers* random,
|
||||
std::vector<double>& macroscopic_cross_sections_m);
|
||||
// draw the individual collision times of the possible interactions and return the
|
||||
// minimum of them. Also sets the "nextInteractionIndex" in the particle to the
|
||||
// interaction of the chosen time.
|
||||
void collisionTime(particle::Particle& particle, RandomNumbers* random);
|
||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||
RandomNumbers* random);
|
||||
|
||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||
RandomNumbers* random,
|
||||
std::vector<double>& macroscopic_cross_sections_m);
|
||||
|
||||
blitz::Array<double,3> chargedensity();
|
||||
blitz::Array<double,2> chargedensity();
|
||||
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>
|
||||
tracked_species_;
|
||||
@@ -81,6 +76,13 @@ class Simulation {
|
||||
std::shared_ptr<CpuSynchronizer> cpu_synchronizer_;
|
||||
|
||||
std::vector<particle::Particle> queue_;
|
||||
std::vector<particle::SerializedParticle> storage_queue_[2];
|
||||
|
||||
int active_storage = 0;
|
||||
int inactive_storage = 1;
|
||||
|
||||
int timestep = 0;
|
||||
int injectionGroupOffset = 0;
|
||||
};
|
||||
|
||||
#endif /* SIMULATION_H */
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "simulation/parameter.h"
|
||||
|
||||
class RandomIndex;
|
||||
class Mover;
|
||||
class Terminator;
|
||||
class Reflector;
|
||||
@@ -42,7 +43,7 @@ class Specie {
|
||||
std::string name() const;
|
||||
|
||||
virtual DensityField* densityField() = 0;
|
||||
virtual VelocityDistribution* velocityDistibution() = 0;
|
||||
virtual VelocityDistribution* velocityDistribution() = 0;
|
||||
virtual DriftVelocity* driftVelocity() = 0;
|
||||
|
||||
protected:
|
||||
@@ -63,11 +64,10 @@ class TrackedSpecie : public Specie {
|
||||
std::shared_ptr<Reflector> reflector,
|
||||
std::shared_ptr<DynamicDensityField> density_field,
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution,
|
||||
std::shared_ptr<DriftVelocity> drift_velocity,
|
||||
std::shared_ptr<DynamicDensityField> density_for_drawing);
|
||||
std::shared_ptr<DriftVelocity> drift_velocity);
|
||||
|
||||
DensityField* densityField();
|
||||
VelocityDistribution* velocityDistibution();
|
||||
VelocityDistribution* velocityDistribution();
|
||||
DriftVelocity* driftVelocity();
|
||||
|
||||
DynamicDensityField* dynamicDensityField();
|
||||
@@ -78,22 +78,17 @@ class TrackedSpecie : public Specie {
|
||||
DeletionLogger* deletionLogger();
|
||||
void deletionLogger(std::shared_ptr<DeletionLogger> new_logger);
|
||||
|
||||
DynamicDensityField* densityForDrawing();
|
||||
|
||||
CurrentCollector* currentCollector();
|
||||
void currentCollector(std::shared_ptr<CurrentCollector> new_collector);
|
||||
|
||||
std::vector<std::shared_ptr<interaction::Interaction>> interactions();
|
||||
void addInteraction(std::shared_ptr<interaction::Interaction> interaction);
|
||||
|
||||
// getter for the raw pointer to the positionDistributionFromDensity object
|
||||
PositionDistributionFromDensity* positionDistributionFromDensity();
|
||||
// getter for the raw pointer to the VelocityDistributionFromDensityField object
|
||||
VelocityDistributionFromDensityField* velocityDistributionFromDensityField();
|
||||
|
||||
private:
|
||||
std::shared_ptr<DynamicDensityField> density_field_;
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution_;
|
||||
std::shared_ptr<DriftVelocity> drift_velocity_;
|
||||
|
||||
std::shared_ptr<Mover> mover_;
|
||||
@@ -104,9 +99,7 @@ class TrackedSpecie : public Specie {
|
||||
std::shared_ptr<CurrentCollector> current_collector_;
|
||||
std::vector<std::shared_ptr<interaction::Interaction>> interactions_;
|
||||
|
||||
std::shared_ptr<DynamicDensityField> density_for_drawing_;
|
||||
std::shared_ptr<PositionDistributionFromDensity>
|
||||
position_distribution_from_density_;
|
||||
// necessary for interactions between TrackedSpecies
|
||||
std::shared_ptr<VelocityDistributionFromDensityField>
|
||||
velocity_distribution_from_density_;
|
||||
};
|
||||
@@ -122,7 +115,7 @@ class BackgroundSpecie : public Specie {
|
||||
std::shared_ptr<DriftVelocity> drift_velocity);
|
||||
|
||||
DensityField* densityField();
|
||||
VelocityDistribution* velocityDistibution();
|
||||
VelocityDistribution* velocityDistribution();
|
||||
DriftVelocity* driftVelocity();
|
||||
|
||||
private:
|
||||
|
||||
@@ -5,22 +5,45 @@
|
||||
|
||||
class Geometry;
|
||||
class DynamicDensityField;
|
||||
class Coordinate;
|
||||
class Terminator {
|
||||
public:
|
||||
Terminator(long int max_interactions,
|
||||
double max_time_alive,
|
||||
std::shared_ptr<Geometry> geometry);
|
||||
Terminator();
|
||||
|
||||
bool isAlive(const particle::Particle* particle) const;
|
||||
bool leftSimulationDomain(const particle::Particle* particle) const;
|
||||
bool reachedMaxInteractions(const particle::Particle* particle) const;
|
||||
bool reachedMaxTimeAlive(const particle::Particle* particle) const;
|
||||
double maxTimeAlive() const;
|
||||
virtual bool isAlive(const particle::Particle* particle) const;
|
||||
virtual bool isAlive(const particle::Particle* particle,
|
||||
const Coordinate& old_pos) const;
|
||||
virtual bool leftSimulationDomain(const particle::Particle* particle) const;
|
||||
virtual bool leftSimulationDomain(const particle::Particle* particle,
|
||||
const Coordinate& old_position) const;
|
||||
virtual bool reachedMaxInteractions(const particle::Particle* particle) const;
|
||||
virtual bool reachedMaxTimeAlive(const particle::Particle* particle) const;
|
||||
virtual double maxTimeAlive() const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
const long int max_interactions_;
|
||||
const double max_time_alive_;
|
||||
std::shared_ptr<Geometry> geometry_;
|
||||
};
|
||||
|
||||
class TerminatorWithPlates : public Terminator {
|
||||
public:
|
||||
TerminatorWithPlates(long int max_interactions, double max_time_alive,
|
||||
std::shared_ptr<Geometry> geometry,
|
||||
double zpos1, double zpos2, double innerRadius1,
|
||||
double innerRadius2, double outerRadius1,
|
||||
double outerRadius2);
|
||||
|
||||
virtual bool leftSimulationDomain(const particle::Particle* particle) const;
|
||||
virtual bool leftSimulationDomain(const particle::Particle* particle,
|
||||
const Coordinate& old_position) const;
|
||||
|
||||
private:
|
||||
const double zpos1_, innerRadius1_, outerRadius1_;
|
||||
const double zpos2_, innerRadius2_, outerRadius2_;
|
||||
};
|
||||
|
||||
#endif /* TERMINATOR_H */
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <functional>
|
||||
|
||||
std::function<double(double)> tritiumDecayEnergySpectrum(double prefactor);
|
||||
std::function<double(double)> tritiumDecayEnergySpectrumIon(double endpoint);
|
||||
|
||||
|
||||
#endif /* TRITIUM_SPECTRUM_H */
|
||||
|
||||
@@ -14,9 +14,9 @@ class VectorField {
|
||||
|
||||
class VectorFieldFromArray : public VectorField {
|
||||
public:
|
||||
VectorFieldFromArray(const blitz::Array<double, 3>& radial_component,
|
||||
const blitz::Array<double, 3>& azimuthal_component,
|
||||
const blitz::Array<double, 3>& longitudial_component,
|
||||
VectorFieldFromArray(const blitz::Array<double, 2>& radial_component,
|
||||
const blitz::Array<double, 2>& azimuthal_component,
|
||||
const blitz::Array<double, 2>& longitudial_component,
|
||||
double radius,
|
||||
double length);
|
||||
|
||||
@@ -24,12 +24,12 @@ class VectorFieldFromArray : public VectorField {
|
||||
|
||||
private:
|
||||
// todo: make sure we use fast axis on z to reduce access time
|
||||
const blitz::Array<double, 3> Fr_;
|
||||
const blitz::Array<double, 3> Fphi_;
|
||||
const blitz::Array<double, 3> Fz_;
|
||||
const blitz::Array<double, 2> Fr_;
|
||||
const blitz::Array<double, 2> Fphi_;
|
||||
const blitz::Array<double, 2> Fz_;
|
||||
|
||||
CylinderBinning binning_;
|
||||
CylinderVector value(const blitz::TinyVector<int, 3>& bin) const;
|
||||
CylinderVector value(const blitz::TinyVector<int, 2>& bin) const;
|
||||
};
|
||||
|
||||
class VectorFieldConstant : public VectorField {
|
||||
|
||||
@@ -52,34 +52,17 @@ class VelocityDistributionFromDensityField : public VelocityDistribution {
|
||||
// use the given magnetic field at the provided position to determine the
|
||||
// direction of velocity from the pitch angle
|
||||
// the direction of the perpendicular part of the velocity vector is drawn isotropically
|
||||
CartesianVector rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
CartesianVector rollVelocity(const Coordinate& position, std::mt19937* engine,
|
||||
std::shared_ptr<MagneticField> magnetic_field);
|
||||
|
||||
// returns a velocity vector drawn from the energy and pitch angle distributions
|
||||
// use the given magnetic field at the provided position to determine the
|
||||
// direction of velocity from the pitch angle
|
||||
// the direction of the perpendicular part of the velocity vector is drawn isotropically
|
||||
// draw from the distribution below the threshold energy if above = false
|
||||
// and from above otherwise
|
||||
CartesianVector rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const int E_th_bin,
|
||||
const bool above);
|
||||
|
||||
CartesianVector rollVelocity(
|
||||
const Coordinate& position, std::mt19937* engine,
|
||||
const int E_th_bin,
|
||||
const bool above);
|
||||
private:
|
||||
// mass of the species of which the density field is a part of
|
||||
const double mass_kg_;
|
||||
|
||||
std::shared_ptr<DynamicDensityField> density_field_;
|
||||
|
||||
blitz::Array<double, 1> energy_values;
|
||||
blitz::Array<double, 1> mu_values;
|
||||
// blitz::Array<double, 1> energy_values;
|
||||
// blitz::Array<double, 1> mu_values;
|
||||
|
||||
std::vector<double> energyBinBorders_;
|
||||
std::vector<double> pitchAngleBinBorders_;
|
||||
|
||||
@@ -35,6 +35,8 @@ LIBS =#-static
|
||||
|
||||
CXXFLAGS += -DHOMEBASE=$(HOMEBASE)
|
||||
|
||||
#CXXFLAGS += -Ddebug_timedist
|
||||
|
||||
# Blitz
|
||||
CXXFLAGS += $(BLITZ_INCLUDES)
|
||||
LIBS += $(BLITZ_LIBS)
|
||||
@@ -47,12 +49,18 @@ LIBS += $(HDF5P_LIBRARIES)
|
||||
CXXFLAGS += $(JANSSON_INCLUDES)
|
||||
LIBS += $(JANSSON_LIBRARIES)
|
||||
|
||||
|
||||
CXXFLAGS += -g
|
||||
ifeq ($(DO_DEBUGGING),true)
|
||||
CXXFLAGS += -ftemplate-depth-30 -g -DBZ_DEBUG
|
||||
CXXFLAGS += -ftemplate-depth-30 -DBZ_DEBUG
|
||||
CXXFLAGS += -Ddebug
|
||||
CXXFLAGS += -Ddebug_level$(DEBUG_LEVEL)
|
||||
endif
|
||||
|
||||
ifeq ($(DO_GENRICHCURRENT),true)
|
||||
CXXFLAGS += -DGENRICHCURRENT #-Ddebug_genrich
|
||||
endif
|
||||
|
||||
# Catch2
|
||||
CXXFLAGS += $(CATCH_INCLUDES)
|
||||
|
||||
|
||||
+66
-55
@@ -9,7 +9,7 @@
|
||||
}
|
||||
},
|
||||
"Longitudinal": {
|
||||
"NumberOfBins": 50,
|
||||
"NumberOfBins": 100,
|
||||
"MaxLength": {
|
||||
"value": 1657,
|
||||
"unit": "cm"
|
||||
@@ -60,7 +60,7 @@
|
||||
},
|
||||
"xValuesKey": "/z_position(m)",
|
||||
"yValuesKey": "/n(m3)",
|
||||
"prefactor": 1E20
|
||||
"prefactor": 6.337599E20
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,11 +124,12 @@
|
||||
"Tracked": {
|
||||
"e-": {
|
||||
"ParticleType": "electron",
|
||||
"StoreInQueue": "true",
|
||||
"Mover": {
|
||||
"Drift": {
|
||||
"MaximalMovedDistance": {
|
||||
"value": 1E-3,
|
||||
"unit": "m"
|
||||
"Boris": {
|
||||
"MaximalTimestepLength": {
|
||||
"value": 2e-11,
|
||||
"unit": "s"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -168,7 +169,7 @@
|
||||
},
|
||||
"EnergyBinning": {
|
||||
"Type": "Logarithmic",
|
||||
"NumberOfBins": 10,
|
||||
"NumberOfBins": 100,
|
||||
"MinEnergy": {
|
||||
"value": 1E-6,
|
||||
"unit": "eV"
|
||||
@@ -180,7 +181,7 @@
|
||||
},
|
||||
"PitchAngleBinning": {
|
||||
"Type": "Linear",
|
||||
"NumberOfBins": 15
|
||||
"NumberOfBins": 5
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -213,7 +214,7 @@
|
||||
"CompositeAngleDistribution": {
|
||||
"LowerDistribution": {
|
||||
"Isotropic": {}
|
||||
},
|
||||
},
|
||||
"HigherDistribution": {
|
||||
"AngleDistributionFromFile": {
|
||||
"PathToH5": {
|
||||
@@ -350,18 +351,19 @@
|
||||
},
|
||||
"T2+": {
|
||||
"ParticleType": "T2+",
|
||||
"StoreInQueue": "false",
|
||||
"Mover": {
|
||||
"Drift": {
|
||||
"MaximalMovedDistance": {
|
||||
"value": 1E-3,
|
||||
"unit": "m"
|
||||
"Boris": {
|
||||
"MaximalTimestepLength": {
|
||||
"value": 6e-11,
|
||||
"unit": "s"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Terminator": {
|
||||
"MaximumInteractions": 1E6,
|
||||
"MaxTimeAlive": {
|
||||
"value": 1,
|
||||
"value": 10,
|
||||
"unit": "s"
|
||||
},
|
||||
"BoundaryGeometry": {
|
||||
@@ -389,19 +391,19 @@
|
||||
},
|
||||
"EnergyBinning": {
|
||||
"Type": "Logarithmic",
|
||||
"NumberOfBins": 10,
|
||||
"NumberOfBins": 50,
|
||||
"MinEnergy": {
|
||||
"value": 1E-6,
|
||||
"unit": "eV"
|
||||
},
|
||||
"MaxEnergy": {
|
||||
"value": 1E3,
|
||||
"value": 1E1,
|
||||
"unit": "eV"
|
||||
}
|
||||
},
|
||||
"PitchAngleBinning": {
|
||||
"Type": "Linear",
|
||||
"NumberOfBins": 15
|
||||
"NumberOfBins": 5
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -434,6 +436,7 @@
|
||||
"clustering": {
|
||||
"Type": "Clustering",
|
||||
"Target": "TritiumGas",
|
||||
"ClusteringType": "radiative",
|
||||
"Product": "T3+",
|
||||
"CrossSection": {
|
||||
"PredefinedFunction": "T2pT2_clustering_janev"
|
||||
@@ -446,11 +449,11 @@
|
||||
},
|
||||
"T+": {
|
||||
"ParticleType": "T+",
|
||||
"StoreInQueue": "false",
|
||||
"Mover": {
|
||||
"Boris": {
|
||||
"BorisStepsPerMovementCylce": 10,
|
||||
"MaximalTimestepLength": {
|
||||
"value": 1E-8,
|
||||
"value": 6e-11,
|
||||
"unit": "s"
|
||||
}
|
||||
}
|
||||
@@ -458,7 +461,7 @@
|
||||
"Terminator": {
|
||||
"MaximumInteractions": 1E6,
|
||||
"MaxTimeAlive": {
|
||||
"value": 1,
|
||||
"value": 10,
|
||||
"unit": "s"
|
||||
},
|
||||
"BoundaryGeometry": {
|
||||
@@ -486,19 +489,19 @@
|
||||
},
|
||||
"EnergyBinning": {
|
||||
"Type": "Logarithmic",
|
||||
"NumberOfBins": 10,
|
||||
"NumberOfBins": 50,
|
||||
"MinEnergy": {
|
||||
"value": 1E-6,
|
||||
"unit": "eV"
|
||||
},
|
||||
"MaxEnergy": {
|
||||
"value": 1E3,
|
||||
"value": 1E1,
|
||||
"unit": "eV"
|
||||
}
|
||||
},
|
||||
"PitchAngleBinning": {
|
||||
"Type": "Linear",
|
||||
"NumberOfBins": 15
|
||||
"NumberOfBins": 5
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -534,6 +537,7 @@
|
||||
"clustering1": {
|
||||
"Type": "Clustering",
|
||||
"Target": "TritiumGas",
|
||||
"ClusteringType": "radiative",
|
||||
"Product": "T3+",
|
||||
"CrossSection": {
|
||||
"PredefinedFunction": "TpT2_clustering_radiative_ascendion_pasil"
|
||||
@@ -542,6 +546,7 @@
|
||||
"clustering2": {
|
||||
"Type": "Clustering",
|
||||
"Target": "TritiumGas",
|
||||
"ClusteringType": "tertiary",
|
||||
"Product": "T3+",
|
||||
"CrossSection": {
|
||||
"PredefinedFunction": "TpT2_clustering_tertiary_ascendion_pasil"
|
||||
@@ -554,18 +559,19 @@
|
||||
},
|
||||
"T3+": {
|
||||
"ParticleType": "T3+",
|
||||
"StoreInQueue": "false",
|
||||
"Mover": {
|
||||
"Drift": {
|
||||
"MaximalMovedDistance": {
|
||||
"value": 1E-3,
|
||||
"unit": "m"
|
||||
"Boris": {
|
||||
"MaximalTimestepLength": {
|
||||
"value": 6e-11,
|
||||
"unit": "s"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Terminator": {
|
||||
"MaximumInteractions": 1E6,
|
||||
"MaxTimeAlive": {
|
||||
"value": 1,
|
||||
"value": 10,
|
||||
"unit": "s"
|
||||
},
|
||||
"BoundaryGeometry": {
|
||||
@@ -593,7 +599,7 @@
|
||||
},
|
||||
"EnergyBinning": {
|
||||
"Type": "Logarithmic",
|
||||
"NumberOfBins": 10,
|
||||
"NumberOfBins": 100,
|
||||
"MinEnergy": {
|
||||
"value": 1E-6,
|
||||
"unit": "eV"
|
||||
@@ -605,7 +611,7 @@
|
||||
},
|
||||
"PitchAngleBinning": {
|
||||
"Type": "Linear",
|
||||
"NumberOfBins": 15
|
||||
"NumberOfBins": 5
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -662,7 +668,8 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"InjectionStride": 1
|
||||
},
|
||||
"specie2": {
|
||||
"TrackedSpecieName": "T2+",
|
||||
@@ -684,7 +691,8 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"InjectionStride": 1
|
||||
}
|
||||
},
|
||||
"EventPositionDistribution": {
|
||||
@@ -770,7 +778,7 @@
|
||||
}
|
||||
},
|
||||
"Activity": {
|
||||
"value": 1E7,
|
||||
"value": 3.7e10,
|
||||
"unit": "Bq"
|
||||
}
|
||||
},
|
||||
@@ -809,7 +817,7 @@
|
||||
"VectorFieldFunctionInZ": {
|
||||
"zFunction": {
|
||||
"Constant3D": {
|
||||
"constant": 2.5
|
||||
"constant": 0.025
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -823,13 +831,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
"GravityField": {
|
||||
"VectorField": {
|
||||
"VectorFieldFunctionInZ": {
|
||||
"zFunction": {
|
||||
"Constant3D": {
|
||||
"constant": 0
|
||||
"constant": 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -846,7 +854,7 @@
|
||||
},
|
||||
"Boundary": {
|
||||
"Top": {
|
||||
"type": "neumann",
|
||||
"type": "dirichlet",
|
||||
"value": 0
|
||||
},
|
||||
"Bottom": {
|
||||
@@ -860,53 +868,56 @@
|
||||
},
|
||||
"TargetAccuracy": 1e-6,
|
||||
"NumCycles": 2e4,
|
||||
"DoSolver": "false"
|
||||
"DoSolver": "true"
|
||||
},
|
||||
"Simulation": {
|
||||
"NumberTimesteps": 10,
|
||||
"EventStride": 1000,
|
||||
"NumberTimesteps": 20,
|
||||
"EventStride": 10,
|
||||
"TimeResolutionEvents": 10,
|
||||
"DensityEventsPerCPU": 1000,
|
||||
"BetaDecayEventsPerCPU": 1000
|
||||
"BetaDecayEventsPerCPU": 10,
|
||||
"InjectionStride": 1,
|
||||
"NumberDensityParticlesPerBinPerCPU": 1
|
||||
},
|
||||
"Output": {
|
||||
"folder": "output",
|
||||
"filename": "katrin_drawing",
|
||||
"filename": "wgts",
|
||||
"DensityFields": {
|
||||
"Species": "all",
|
||||
"Intervall": 1,
|
||||
"Intervall": 288,
|
||||
"OverwriteLast": "false"
|
||||
},
|
||||
"CurrentBorders": {
|
||||
"Species": "all",
|
||||
"Intervall": "EachSync",
|
||||
"Intervall": 288,
|
||||
"OverwriteLast": "false"
|
||||
},
|
||||
"DeletionLogger": {
|
||||
"Species": "all",
|
||||
"Intervall": "EachSync",
|
||||
"Intervall": 288,
|
||||
"OverwriteLast": "false"
|
||||
},
|
||||
"PoissonSolver": {
|
||||
"Intervall": 1,
|
||||
"Intervall": 288,
|
||||
"OverwriteLast": "false"
|
||||
},
|
||||
"RestartInfo": {
|
||||
"Intervall": 1,
|
||||
"Intervall": 288,
|
||||
"OverwriteLast": "false"
|
||||
},
|
||||
"Particles": {
|
||||
"Intervall": 2880
|
||||
}
|
||||
},
|
||||
"Restart" : {
|
||||
"Restart": {
|
||||
"Do": "false",
|
||||
"SyncPeriod": 2,
|
||||
"SyncPeriod": 2880,
|
||||
"PathToH5": {
|
||||
"Type": "RelativeToHomebase",
|
||||
"RelativePath": "output",
|
||||
"Filename": "breakInMover3",
|
||||
"comment": "if the restarted file and the output file are the same, the data that is restarted from is overwritten!"
|
||||
"Type": "AbsolutePath",
|
||||
"AbsoluteFolderPath": "/home/christian/Documents/Heidelberg/karl/timeResolvedTests/thermalization/output",
|
||||
"Filename": "const_target_energy"
|
||||
}
|
||||
},
|
||||
"RandomNumbers": {
|
||||
"Seed": 1337
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+1049
File diff suppressed because it is too large
Load Diff
+40
-3
@@ -132,6 +132,36 @@ double Hdf5Reader::readDouble(std::string path) {
|
||||
return data;
|
||||
}
|
||||
|
||||
int Hdf5Reader::readInt(std::string path) {
|
||||
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||
|
||||
// H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
||||
hid_t dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
||||
hid_t dataspace = H5Dget_space(dataset);
|
||||
if (dataset < 0) {
|
||||
ERROR("The given dataset could not be opened");
|
||||
}
|
||||
// turn error report back onby hdf5 because of check H5Dopen2
|
||||
// H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
||||
|
||||
const int ndims = H5Sget_simple_extent_ndims(dataspace);
|
||||
hsize_t dims[ndims];
|
||||
if (ndims != 1) {
|
||||
ERROR("The given dataset is not one dimensional. It has dims: " + ndims);
|
||||
}
|
||||
H5Sget_simple_extent_dims(dataspace, dims, NULL);
|
||||
|
||||
int data;
|
||||
|
||||
H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
||||
&data);
|
||||
|
||||
H5Sclose(dataspace);
|
||||
H5Dclose(dataset);
|
||||
H5Fclose(file);
|
||||
return data;
|
||||
}
|
||||
|
||||
blitz::Array<double, 4> Hdf5Reader::readD4Double(std::string path) {
|
||||
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||
|
||||
@@ -277,23 +307,24 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) {
|
||||
std::to_string(SimConstants::engine_string_length_max) +
|
||||
", size of string: " + std::to_string(size));
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("RestartInfo: " + std::to_string(H5Tdetect_class(dtype, H5T_STRING)));
|
||||
#endif
|
||||
|
||||
const int ndims = H5Sget_simple_extent_ndims(dataspace);
|
||||
hsize_t dims[ndims];
|
||||
if (ndims != 1) {
|
||||
ERROR("The given dataset is not one dimensional. It has dims: " + ndims);
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(std::to_string(ndims));
|
||||
DEBUG_LEVEL_3("RestartInfo: " + std::to_string(size));
|
||||
#endif
|
||||
H5Sget_simple_extent_dims(dataspace, dims, NULL);
|
||||
|
||||
char data[SimConstants::engine_string_length_max];
|
||||
H5Dread(dataset, dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT,
|
||||
&data);
|
||||
|
||||
std::stringstream temp;
|
||||
temp << data;
|
||||
|
||||
H5Tclose(dtype);
|
||||
H5Sclose(dataspace);
|
||||
@@ -314,15 +345,21 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) {
|
||||
|
||||
size_t length;
|
||||
H5Dread(dataset, H5T_NATIVE_HSIZE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &length);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("RestartInfo: read length from file: " + std::to_string(length));
|
||||
#endif
|
||||
|
||||
H5Sclose(dataspace);
|
||||
H5Dclose(dataset);
|
||||
|
||||
H5Fclose(file);
|
||||
|
||||
std::stringstream temp;
|
||||
temp << data;
|
||||
out << temp.str().substr(0, length);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(std::to_string(out.str().size()));
|
||||
#endif
|
||||
|
||||
return out;
|
||||
}
|
||||
@@ -517,7 +517,7 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
|
||||
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
||||
H5Pset_create_intermediate_group(lcpl, 1);
|
||||
|
||||
int mpi_rank = MpiCommunication::mpiRank();
|
||||
int mpi_rank = MpiCommunication::mpi_rank;
|
||||
std::string out{data};
|
||||
|
||||
size_t stateStringSize = out.size();
|
||||
@@ -540,14 +540,18 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
|
||||
// turn of error report by hdf5 because of check H5Dopen2
|
||||
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
||||
|
||||
for(int i = 0; i < MpiCommunication::mpiSize(); ++i) {
|
||||
for(int i = 0; i < MpiCommunication::mpi_size; ++i) {
|
||||
std::string path = path_base + std::to_string(i);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path);
|
||||
#endif
|
||||
hid_t dataset_string = H5Dcreate2(file, (path + "/string").c_str(), dtype, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT);
|
||||
// this sadly seems to be the option that takes the least amount of effort.
|
||||
// H5Lexits() would be an option but (!) each group would need to be checked for existance first, which sucks
|
||||
if(dataset_string < 0) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Dataset could not be created");
|
||||
#endif
|
||||
dataset_string = H5Dopen2(file, (path + "/string").c_str(), H5P_DEFAULT);
|
||||
if(dataset_string < 0) {
|
||||
ERROR("Dataset for string can neither be created nor opened");
|
||||
@@ -556,7 +560,9 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
|
||||
|
||||
hid_t dataset_length = H5Dcreate2(file, (path + "/length").c_str(), H5T_NATIVE_HSIZE, filespace, lcpl, H5P_DEFAULT, H5P_DEFAULT);
|
||||
if(dataset_length < 0) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Dataset could not be created");
|
||||
#endif
|
||||
dataset_length = H5Dopen2(file, (path + "/length").c_str(), H5P_DEFAULT);
|
||||
if(dataset_length < 0) {
|
||||
ERROR("Dataset for length can neither be created nor opened");
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
#include "IO/mpi_particle_reader.h"
|
||||
#include "IO/mpi_particle_format.h"
|
||||
#include "simulation/mpi_communication.h"
|
||||
#include "simulation/particle.h"
|
||||
|
||||
#include "mpi.h"
|
||||
|
||||
// filename has to NOT include the ".mpi" component!
|
||||
MpiParticleReader::MpiParticleReader(std::string directory, std::string filename,
|
||||
int restart_at):
|
||||
absolute_filename_(directory + "/" + filename + "-CPUSync-"
|
||||
+ std::to_string(restart_at) + ".mpi") {}
|
||||
|
||||
MpiParticleReader::MpiParticleReader(std::string absolute_filename):
|
||||
absolute_filename_(absolute_filename) {}
|
||||
|
||||
MpiParticleReader::MpiParticleReader(std::string abs_filename_without_extension,
|
||||
int restart_at):
|
||||
absolute_filename_(abs_filename_without_extension + "-CPUSync-" +
|
||||
std::to_string(restart_at) + ".mpi") {}
|
||||
|
||||
void MpiParticleReader::readParticles(
|
||||
std::vector<particle::SerializedParticle>& storage_queue) {
|
||||
MPI_Comm io_comm;
|
||||
int io_rank;
|
||||
|
||||
io_comm = MPI_COMM_WORLD;
|
||||
io_rank = MpiCommunication::mpiRank();
|
||||
|
||||
#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_rank;
|
||||
|
||||
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);
|
||||
#if defined(debug_level1)
|
||||
{
|
||||
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, cpu_header.file_offset, MPI_DOUBLE,
|
||||
particle_type, (char*)"native", info);
|
||||
if(status) {
|
||||
ERROR("File view for the Particles could not be set!");
|
||||
}
|
||||
|
||||
storage_queue.resize(cpu_header.num_particles);
|
||||
|
||||
// read the particles
|
||||
status = MPI_File_read_all(file, storage_queue.data(), cpu_header.num_particles,
|
||||
particle_type, &mstatus);
|
||||
if(status) {
|
||||
ERROR("Particles could not be read (status: " + std::to_string(status) +
|
||||
")!");
|
||||
}
|
||||
|
||||
#ifdef debug_level1
|
||||
{
|
||||
std::stringstream out;
|
||||
out << io_rank << ": 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();
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "IO/mpi_particle_writer.h"
|
||||
#include "IO/mpi_particle_format.h"
|
||||
#include "simulation/particle.h"
|
||||
#include "simulation/mpi_communication.h"
|
||||
#include "simulation/errors.h"
|
||||
|
||||
|
||||
void MpiParticleWriter::createFolder(std::string directory) {
|
||||
mkdir(directory.c_str(), 0755);
|
||||
}
|
||||
|
||||
MpiParticleWriter::MpiParticleWriter(std::string directory,
|
||||
std::string filename,
|
||||
int fs_blocksize) :
|
||||
directory_(directory),
|
||||
filename_(filename),
|
||||
fs_blocksize_(fs_blocksize) {
|
||||
createFolder(directory_);
|
||||
}
|
||||
|
||||
void MpiParticleWriter::output_particles(
|
||||
std::vector<particle::SerializedParticle>& particles,
|
||||
int cpu_sync, double dt) {
|
||||
int status;
|
||||
|
||||
std::stringstream path;
|
||||
path << directory_ << "/" << filename_ << "-CPUSync-" << cpu_sync << ".mpi";
|
||||
|
||||
int io_rank = MpiCommunication::mpiRank();
|
||||
int total_procs = MpiCommunication::mpiSize();
|
||||
MPI_Comm io_comm = MPI_COMM_WORLD;
|
||||
|
||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
||||
DEBUG_LEVEL_1("Starting MPI particle output: " + path.str());
|
||||
#endif
|
||||
|
||||
// size of headers
|
||||
std::uint64_t file_header_size = pad_to_blocksize(sizeof(mpi_io_header_t),
|
||||
fs_blocksize_);
|
||||
std::uint64_t cpu_headers_size = pad_to_blocksize(file_header_size
|
||||
+ sizeof(cpu_header_t) * total_procs, fs_blocksize_);
|
||||
|
||||
// commnicate the number of particles on all cpus
|
||||
std::uint64_t* part_bytes_in = new uint64_t[total_procs];
|
||||
std::uint64_t* part_bytes = new uint64_t[total_procs];
|
||||
|
||||
for(int i = 0; i < total_procs; i++) {
|
||||
part_bytes_in[i] = 0;
|
||||
}
|
||||
|
||||
part_bytes_in[io_rank] = particles.size() * sizeof(particle::SerializedParticle);
|
||||
part_bytes_in[io_rank] = pad_to_blocksize(part_bytes_in[io_rank], fs_blocksize_);
|
||||
|
||||
MPI_Allreduce(part_bytes_in, part_bytes, total_procs,
|
||||
MPI_LONG_LONG, MPI_SUM, io_comm);
|
||||
|
||||
delete[] part_bytes_in;
|
||||
|
||||
// Calculate the offset from the prefix sum
|
||||
std::uint64_t tmp = 0;
|
||||
std::uint64_t prev = 0;
|
||||
for(int i = 0; i < total_procs; i++) {
|
||||
tmp += part_bytes[i];
|
||||
part_bytes[i] = prev;
|
||||
prev = tmp;
|
||||
}
|
||||
|
||||
// data type of a single particle
|
||||
MPI_Datatype particle_type;
|
||||
|
||||
if(sizeof(particle::SerializedParticle) % sizeof(double) != 0) {
|
||||
// since type is created as a set of MPI_DOUBLES
|
||||
ERROR("Size of particle 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) {
|
||||
delete[] part_bytes;
|
||||
ERROR("Mpi particle data type could not be created!");
|
||||
}
|
||||
|
||||
// enable collective buffering
|
||||
MPI_Info info;
|
||||
MpiCommunication::create_mpi_info(&info);
|
||||
|
||||
// open the file
|
||||
MPI_File file;
|
||||
MPI_Status mstatus;
|
||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
||||
DEBUG_LEVEL_1("Writing particles to " + path.str());
|
||||
#endif
|
||||
status = MPI_File_open(io_comm, (char*)path.str().c_str(),
|
||||
MPI_MODE_WRONLY|MPI_MODE_CREATE, info, &file);
|
||||
if(status) {
|
||||
ERROR("File could not be opened or created! " + path.str());
|
||||
}
|
||||
|
||||
// collectively write file header
|
||||
MPI_Datatype file_header_type = build_file_header_type();
|
||||
mpi_io_header_t file_header;
|
||||
|
||||
file_header.magic = ((std::uint64_t)'KA' << 32) + (uint64_t)'RL';
|
||||
file_header.num_cpus = total_procs;
|
||||
file_header.cpu_header_offset = file_header_size;
|
||||
file_header.dt = dt;
|
||||
|
||||
status = MPI_File_set_view(file, 0, file_header_type, file_header_type,
|
||||
(char*)"native", info);
|
||||
if(status) {
|
||||
ERROR("View for the file header could not be set!");
|
||||
}
|
||||
|
||||
status = MPI_File_write_all(file, &file_header, 1, file_header_type, &mstatus);
|
||||
if(status) {
|
||||
ERROR("File header could not be written (status: " + std::to_string(status) + ")");
|
||||
}
|
||||
|
||||
MPI_Type_free(&file_header_type);
|
||||
|
||||
// calculate where the header of this cpu starts
|
||||
std::uint64_t headeroffset = file_header_size + sizeof(cpu_header_t)*io_rank;
|
||||
|
||||
// calcualte the offset to the data
|
||||
std::uint64_t dataoffset = cpu_headers_size + part_bytes[io_rank];
|
||||
|
||||
// Write per-CPU header
|
||||
cpu_header_t our_cpu_header;
|
||||
our_cpu_header.num_particles = particles.size();
|
||||
our_cpu_header.file_offset = dataoffset;
|
||||
|
||||
MPI_Datatype cpu_header_type = build_cpu_header_type();
|
||||
|
||||
int typesize;
|
||||
MPI_Type_size(cpu_header_type, &typesize);
|
||||
|
||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
||||
DEBUG_LEVEL_1("Rank " + std::to_string(io_rank) + " has its header at offset " +
|
||||
std::to_string(headeroffset));
|
||||
#endif
|
||||
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_write_all(file, &our_cpu_header, 1, cpu_header_type, &mstatus);
|
||||
if(status) {
|
||||
ERROR("Cpu header could not be written!");
|
||||
}
|
||||
|
||||
// set file view for the particles
|
||||
// the offset is the offset of all headers plus the particles of all prior CPUs
|
||||
status = MPI_File_set_view(file, dataoffset, MPI_DOUBLE, particle_type,
|
||||
(char*)"native", info);
|
||||
if(status) {
|
||||
delete[] part_bytes;
|
||||
ERROR("File view for the particles could not be set!");
|
||||
}
|
||||
|
||||
// dump all particles like they are in memory
|
||||
status = MPI_File_write_all(file, particles.data(), particles.size(),
|
||||
particle_type, &mstatus);
|
||||
if(status) {
|
||||
ERROR("Particles could not be written! status: " + std::to_string(status));
|
||||
}
|
||||
|
||||
// close everything
|
||||
delete[] part_bytes;
|
||||
MPI_File_close(&file);
|
||||
MPI_Type_free(&particle_type);
|
||||
MPI_Type_free(&cpu_header_type);
|
||||
MPI_Info_free(&info);
|
||||
}
|
||||
+62
-25
@@ -10,43 +10,66 @@
|
||||
#include "poisson_solver/poisson_solver.h"
|
||||
#include "simulation/timer.h"
|
||||
#include "simulation/event_position_distribution.h"
|
||||
#include "constants/ionization_constants.h"
|
||||
|
||||
// Note: error handling is a bit messy. Sometimes it's dealt with in the
|
||||
// called reset function (e.g. in the density field) and sometimes it's
|
||||
// handled here
|
||||
|
||||
Restart::Restart(bool do_restart, std::string absolute_filename,
|
||||
std::string restart_identifier):
|
||||
do_restart_(do_restart),
|
||||
restart_identifier_(restart_identifier),
|
||||
reader_(Hdf5Reader(absolute_filename)) {}
|
||||
// Restart::Restart(bool do_restart, std::string absolute_filename,
|
||||
// std::string restart_identifier):
|
||||
// do_restart_(do_restart),
|
||||
// restart_identifier_(restart_identifier),
|
||||
// reader_(Hdf5Reader(absolute_filename)) {}
|
||||
|
||||
void Restart::restart(std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||
PoissonSolver* poisson_solver, RandomNumbers* random_numbers) {
|
||||
Restart::Restart(bool do_restart, std::string absolute_filename_without_extension,
|
||||
std::string restart_idenitfier, int particle_restart_at):
|
||||
do_restart_(do_restart),
|
||||
restart_identifier_(restart_idenitfier),
|
||||
reader_(absolute_filename_without_extension + ".h5"),
|
||||
particle_reader_(absolute_filename_without_extension,
|
||||
particle_restart_at) {}
|
||||
|
||||
void Restart::restart(
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||
PoissonSolver* poisson_solver,
|
||||
RandomNumbers* random_numbers,
|
||||
std::vector<particle::SerializedParticle>& storage_queue,
|
||||
int& injectionGroupOffset) {
|
||||
|
||||
if(!do_restart_) {
|
||||
return;
|
||||
}
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Restarting rng");
|
||||
#endif
|
||||
restartRandomNumbers(random_numbers);
|
||||
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Restarting poisson solver.");
|
||||
#endif
|
||||
restartPoissonSolver(poisson_solver);
|
||||
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Restarting timer.");
|
||||
#endif
|
||||
restartTimer(species.begin()->second.get());
|
||||
|
||||
for(const auto& pair: species) {
|
||||
std::string path = pair.second->name() + "/DensityField/SimulationData/" +
|
||||
restart_identifier_;
|
||||
restartDrawingDensityField(pair.second->densityForDrawing(), path);
|
||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
||||
// ist nicht gut so, weils von der injector version entkoppelt ist...
|
||||
// muss noch irgendwie geändert werden
|
||||
pair.second->positionDistributionFromDensity()
|
||||
->setMaximumDensityAboveAndBelow(
|
||||
ionization::ionization_energy_janev_atomic);
|
||||
restartDrawingDensityField(pair.second->dynamicDensityField(), path);
|
||||
// pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
||||
}
|
||||
|
||||
{
|
||||
std::string path = "/RestartInfo/" + restart_identifier_ + "/InjectionGroupOffset";
|
||||
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) {
|
||||
@@ -74,7 +97,9 @@ void Restart::restartTimer(species::TrackedSpecie* reference_specie) {
|
||||
{
|
||||
std::string path = reference_specie->name() + "/DensityField/SimulationData/" +
|
||||
restart_identifier_ + "/PhysicalTime";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path);
|
||||
#endif
|
||||
// probably add a function in the reader to read a single double value instead of
|
||||
// an 1d array of doubles
|
||||
blitz::Array<double, 1> restart_time = reader_.readD1Double(path);
|
||||
@@ -90,7 +115,9 @@ void Restart::restartTimer(species::TrackedSpecie* reference_specie) {
|
||||
{
|
||||
std::string path = reference_specie->name() + "/CurrentCollector/SimulationData/" +
|
||||
restart_identifier_ + "/PhysicalTime";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path);
|
||||
#endif
|
||||
// probably add a function in the reader to read a single double value instead of
|
||||
// a 1d array of doubles
|
||||
blitz::Array<double, 1> time_resolution = reader_.readD1Double(path);
|
||||
@@ -109,18 +136,21 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string
|
||||
// restart TimeInBin field
|
||||
{
|
||||
std::string path_to_data = path + "/TimeInBin";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path_to_data);
|
||||
blitz::Array<double, 5> time_in_bin = reader_.readD5Double(path_to_data);
|
||||
field->restartTimeInBin(time_in_bin);
|
||||
#endif
|
||||
blitz::Array<double, 4> number_in_bin = reader_.readD4Double(path_to_data);
|
||||
field->restartNumberInBin(number_in_bin);
|
||||
field->recalculateDensityArray();
|
||||
}
|
||||
|
||||
// restart deleted particles
|
||||
{
|
||||
std::string path_to_data = path + "/DeletedParticles";
|
||||
DEBUG_LEVEL_3(path_to_data);
|
||||
blitz::Array<long int, 5> deleted_particles = reader_.readD5LongInt(path_to_data);
|
||||
field->restartDeletedParticlesArray(deleted_particles);
|
||||
}
|
||||
// // restart deleted particles
|
||||
// {
|
||||
// std::string path_to_data = path + "/DeletedParticles";
|
||||
// DEBUG_LEVEL_3(path_to_data);
|
||||
// blitz::Array<long int, 5> deleted_particles = reader_.readD5LongInt(path_to_data);
|
||||
// field->restartDeletedParticlesArray(deleted_particles);
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -130,7 +160,14 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string
|
||||
void Restart::restartPoissonSolver(PoissonSolver* solver) {
|
||||
std::string path = "PoissonSolver/SimulationData/" + restart_identifier_ +
|
||||
"/Potential/";
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path);
|
||||
blitz::Array<double, 3> potential = reader_.readD3Double(path);
|
||||
#endif
|
||||
blitz::Array<double, 2> potential = reader_.readD2Double(path);
|
||||
solver->setPotential(potential);
|
||||
}
|
||||
|
||||
void Restart::restartParticles(
|
||||
std::vector<particle::SerializedParticle>& storage_queue) {
|
||||
particle_reader_.readParticles(storage_queue);
|
||||
}
|
||||
+115
-36
@@ -11,8 +11,11 @@
|
||||
#include "poisson_solver/poisson_solver.h"
|
||||
|
||||
SimulationOutput::SimulationOutput(const std::string& output_folder,
|
||||
const std::string& output_filename)
|
||||
: writer(Hdf5Writer(output_folder, output_filename)) {}
|
||||
const std::string& output_filename,
|
||||
int fs_blocksize)
|
||||
: writer(Hdf5Writer(output_folder, output_filename)),
|
||||
particle_writer(MpiParticleWriter(output_folder,
|
||||
output_filename, fs_blocksize)) {}
|
||||
|
||||
void SimulationOutput::addDensityFieldOutput(OutputTask task) {
|
||||
tasks_density_fields_.push_back(task);
|
||||
@@ -34,6 +37,10 @@ void SimulationOutput::setRestartInfoOutput(OutputTask task) {
|
||||
task_rng_ = task;
|
||||
}
|
||||
|
||||
void SimulationOutput::setParticleOutput(OutputTask task) {
|
||||
task_particles_ = task;
|
||||
}
|
||||
|
||||
void SimulationOutput::writeMetaData(
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||
const std::shared_ptr<PoissonSolver>& poisson_solver) {
|
||||
@@ -70,9 +77,14 @@ void SimulationOutput::writeSimulationData(
|
||||
int cpu_sync,
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||
PoissonSolver* poisson_solver,
|
||||
std::mt19937* engine) {
|
||||
std::mt19937* engine,
|
||||
std::vector<particle::SerializedParticle>& storage_queue,
|
||||
int injectionGroupOffset) {
|
||||
if (MpiCommunication::mpi_rank == 0) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Write density field data.");
|
||||
#endif
|
||||
|
||||
for (auto& task : tasks_density_fields_) {
|
||||
if (cpu_sync % task.intervall == 0) {
|
||||
std::string specie_path = "/" + task.specie_name;
|
||||
@@ -80,7 +92,9 @@ void SimulationOutput::writeSimulationData(
|
||||
specie_path, cpu_sync, task.overwrite_last);
|
||||
}
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Write current collector data.");
|
||||
#endif
|
||||
for (auto& task : tasks_current_collector_) {
|
||||
if (cpu_sync % task.intervall == 0) {
|
||||
std::string specie_path = "/" + task.specie_name;
|
||||
@@ -88,7 +102,9 @@ void SimulationOutput::writeSimulationData(
|
||||
specie_path, cpu_sync, task.overwrite_last);
|
||||
}
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Write deletion logger data.");
|
||||
#endif
|
||||
for (auto& task : tasks_deletion_logger_) {
|
||||
if (cpu_sync % task.intervall == 0) {
|
||||
std::string specie_path = "/" + task.specie_name;
|
||||
@@ -96,7 +112,9 @@ void SimulationOutput::writeSimulationData(
|
||||
specie_path, cpu_sync, task.overwrite_last);
|
||||
}
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Write PoissonSolver data.");
|
||||
#endif
|
||||
if (cpu_sync % task_potential_.intervall == 0) {
|
||||
std::string poisson_path = "/" + task_potential_.specie_name;
|
||||
writeSimulationData(poisson_solver, poisson_path, cpu_sync,
|
||||
@@ -107,7 +125,12 @@ void SimulationOutput::writeSimulationData(
|
||||
// if the rng intervall = 0 (no neg. intervalls allowed) -> no output,
|
||||
// otherwise the intervall used the same as for the other outputs
|
||||
if((task_rng_.intervall > 0) && (cpu_sync%task_rng_.intervall == 0)) {
|
||||
writeRestartData(engine, cpu_sync, task_rng_.overwrite_last);
|
||||
writeRestartData(engine, cpu_sync, task_rng_.overwrite_last, injectionGroupOffset);
|
||||
}
|
||||
|
||||
if((task_particles_.intervall > 0) && (cpu_sync%task_particles_.intervall == 0)) {
|
||||
writeParticles(storage_queue, cpu_sync,
|
||||
species.begin()->second->dynamicDensityField()->timeResolution());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,15 +144,23 @@ void SimulationOutput::writeSimulationData(DynamicDensityField* density_field,
|
||||
}
|
||||
std::string path = species_path + "/DensityField/SimulationData/" + sync_path;
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write spectrum.");
|
||||
#endif
|
||||
writeSpectrum(density_field, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write density.");
|
||||
#endif
|
||||
writeDensity(density_field, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write time in bin.");
|
||||
#endif
|
||||
writeTimeInBin(density_field, path);
|
||||
DEBUG_LEVEL_3("Write deleted particles.");
|
||||
writeDeletedParticles(density_field, path);
|
||||
// DEBUG_LEVEL_3("Write deleted particles.");
|
||||
// writeDeletedParticles(density_field, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write physical time.");
|
||||
#endif
|
||||
writePhysicalTime(density_field, path);
|
||||
}
|
||||
|
||||
@@ -143,11 +174,17 @@ void SimulationOutput::writeSimulationData(CurrentCollector* current_collector,
|
||||
}
|
||||
std::string path =
|
||||
species_path + "/CurrentCollector/SimulationData/" + sync_path;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write current crossings.");
|
||||
#endif
|
||||
writeCurrentCrossings(current_collector, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write current.");
|
||||
#endif
|
||||
writeCurrent(current_collector, path);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write physical time.");
|
||||
#endif
|
||||
writePhysicalTime(current_collector, path);
|
||||
}
|
||||
|
||||
@@ -160,7 +197,9 @@ void SimulationOutput::writeSimulationData(DeletionLogger* logger,
|
||||
sync_path = "LastSyncPeriod";
|
||||
}
|
||||
std::string path = species_path + "/DeletionLogger/" + sync_path;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write number of deletions.");
|
||||
#endif
|
||||
writeNumDeletions(logger, path);
|
||||
}
|
||||
|
||||
@@ -173,22 +212,36 @@ void SimulationOutput::writeSimulationData(PoissonSolver* poisson_solver,
|
||||
sync_path = "/LastSyncPeriod";
|
||||
}
|
||||
std::string path = poisson_path + "/SimulationData" + sync_path;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Write potential.");
|
||||
#endif
|
||||
writePotential(poisson_solver, path);
|
||||
}
|
||||
|
||||
void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
|
||||
bool overwrite_last) {
|
||||
bool overwrite_last, int injectionGroupOffset) {
|
||||
std::string path_base = "/RestartInfo/SyncPeriod_" +
|
||||
std::to_string(cpu_sync) +
|
||||
"/CPU_";
|
||||
if (overwrite_last) {
|
||||
path_base = "/RestartInfo/LastSyncPeriod/CPU_";
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(path_base);
|
||||
DEBUG_LEVEL_3("Write restart info.");
|
||||
#endif
|
||||
writeRandomEngineState(engine, path_base);
|
||||
DEBUG_LEVEL_3("Done");
|
||||
|
||||
if(MpiCommunication::mpi_rank == 0) {
|
||||
std::string path = "/RestartInfo/SyncPeriod_" +
|
||||
std::to_string(cpu_sync) +
|
||||
"/InjectionGroupOffset";
|
||||
if (overwrite_last) {
|
||||
path = "/RestartInfo/LastSyncPeriod/InjectionGroupOffset";
|
||||
}
|
||||
writer.write(injectionGroupOffset, path);
|
||||
}
|
||||
// DEBUG_LEVEL_3("Done");
|
||||
}
|
||||
|
||||
void SimulationOutput::writeRandomEngineState(std::mt19937* engine, std::string path) {
|
||||
@@ -214,6 +267,13 @@ void SimulationOutput::writeNumDeletions(DeletionLogger* logger,
|
||||
writer.write(pair.second, path_to_deletions + "/ClusterFormation");
|
||||
}
|
||||
}
|
||||
|
||||
auto physDeletions = logger->numPhysDeletions();
|
||||
for (auto& pair : physDeletions) {
|
||||
if (pair.first == PhysicalDeletionType::wall) {
|
||||
writer.write(pair.second, path_to_deletions + "/Wall(physical)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SimulationOutput::writeCurrentCrossings(
|
||||
@@ -233,6 +293,11 @@ void SimulationOutput::writeCurrentCrossings(
|
||||
path + "/PositiveCrossingsInZ");
|
||||
writer.write(current_collector->negativeCrossingsInZ(),
|
||||
path + "/NegativeCrossingsInZ");
|
||||
|
||||
#ifdef GENRICHCURRENT
|
||||
writer.write(current_collector->sampleNegativeCrossings(),
|
||||
path + "/SampleNegativeCrossings");
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimulationOutput::writeCurrent(CurrentCollector* current_collector,
|
||||
@@ -245,6 +310,10 @@ void SimulationOutput::writeCurrent(CurrentCollector* current_collector,
|
||||
void SimulationOutput::writePhysicalTime(CurrentCollector* current_collector,
|
||||
std::string path) {
|
||||
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,
|
||||
@@ -254,19 +323,21 @@ void SimulationOutput::writeSpectrum(DynamicDensityField* density_field,
|
||||
|
||||
void SimulationOutput::writeDensity(DynamicDensityField* density_field,
|
||||
std::string path) {
|
||||
// precaution, shouldn't be necessary due to calculation after cpu sync
|
||||
// density_field->recalculateDensityArray();
|
||||
writer.write(density_field->densityArray(), path + "/Density");
|
||||
}
|
||||
|
||||
void SimulationOutput::writeTimeInBin(DynamicDensityField* density_field,
|
||||
std::string path) {
|
||||
writer.write(density_field->timeInBinArray(), path + "/TimeInBin");
|
||||
writer.write(density_field->numberInBinArray(), path + "/TimeInBin");
|
||||
}
|
||||
|
||||
void SimulationOutput::writeDeletedParticles(DynamicDensityField* density_field,
|
||||
std::string path) {
|
||||
writer.write(density_field->deletedParticlesArray(),
|
||||
path + "/DeletedParticles");
|
||||
}
|
||||
// void SimulationOutput::writeDeletedParticles(DynamicDensityField* density_field,
|
||||
// std::string path) {
|
||||
// writer.write(density_field->deletedParticlesArray(),
|
||||
// path + "/DeletedParticles");
|
||||
// }
|
||||
|
||||
void SimulationOutput::writePhysicalTime(DynamicDensityField* density_field,
|
||||
std::string path) {
|
||||
@@ -322,10 +393,6 @@ void SimulationOutput::writeMetaData(DynamicDensityField* density_field,
|
||||
density_field->positionBinning()->radial_binning.binBorders();
|
||||
writer.write(radial_bin_borders, path_to_bin_borders + "/radial");
|
||||
|
||||
std::vector<double> azimuth_bin_borders =
|
||||
density_field->positionBinning()->azimuth_binning.binBorders();
|
||||
writer.write(azimuth_bin_borders, path_to_bin_borders + "/azimuth");
|
||||
|
||||
std::vector<double> longitudinal_bin_borders =
|
||||
density_field->positionBinning()->longitudinal_binning.binBorders();
|
||||
writer.write(longitudinal_bin_borders, path_to_bin_borders + "/longitudinal");
|
||||
@@ -334,12 +401,11 @@ void SimulationOutput::writeMetaData(DynamicDensityField* density_field,
|
||||
// write num bins
|
||||
{
|
||||
std::string path_to_num_bins = path_to_field + "/NumBins";
|
||||
blitz::TinyVector<int, 4> num_bins = density_field->spectrumArray().extent();
|
||||
blitz::TinyVector<int, 3> num_bins = density_field->spectrumArray().extent();
|
||||
|
||||
writer.write(num_bins(0), path_to_num_bins + "/energy");
|
||||
writer.write(num_bins(1), path_to_num_bins + "/radial");
|
||||
writer.write(num_bins(2), path_to_num_bins + "/azimuthal");
|
||||
writer.write(num_bins(3), path_to_num_bins + "/longitudinal");
|
||||
writer.write(num_bins(0), path_to_num_bins + "/radial");
|
||||
writer.write(num_bins(1), path_to_num_bins + "/longitudinal");
|
||||
writer.write(num_bins(2), path_to_num_bins + "/energy");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,10 +426,6 @@ void SimulationOutput::writeMetaData(PoissonSolver* poisson_solver,
|
||||
poisson_solver->densityBinning()->radial_binning.binBorders();
|
||||
writer.write(radial_bin_borders, path_to_bin_borders + "/radial");
|
||||
|
||||
std::vector<double> azimuth_bin_borders =
|
||||
poisson_solver->densityBinning()->azimuth_binning.binBorders();
|
||||
writer.write(azimuth_bin_borders, path_to_bin_borders + "/azimuth");
|
||||
|
||||
std::vector<double> longitudinal_bin_borders =
|
||||
poisson_solver->densityBinning()->longitudinal_binning.binBorders();
|
||||
writer.write(longitudinal_bin_borders, path_to_bin_borders + "/longitudinal");
|
||||
@@ -374,6 +436,10 @@ void SimulationOutput::writeCollectorAreas(CurrentCollector* current_collector,
|
||||
writer.write(current_collector->areaInR(), path + "/AreaInR");
|
||||
writer.write(current_collector->areaInPhi(), path + "/AreaInPhi");
|
||||
writer.write(current_collector->areaInZ(), path + "/AreaInZ");
|
||||
|
||||
#ifdef GENRICHCURRENT
|
||||
writer.write(current_collector->energyBinBorders(), path + "/EnergyBinBorders");
|
||||
#endif
|
||||
}
|
||||
|
||||
void SimulationOutput::writeBinVolumes(DynamicDensityField* density_field,
|
||||
@@ -385,12 +451,11 @@ void SimulationOutput::writeBinVolumes(DynamicDensityField* density_field,
|
||||
void SimulationOutput::writeNumBins(DynamicDensityField* density_field,
|
||||
std::string path_to_field) {
|
||||
std::string path_to_num_bins = path_to_field + "/NumBins";
|
||||
blitz::TinyVector<int, 4> num_bins = density_field->spectrumArray().extent();
|
||||
blitz::TinyVector<int, 3> num_bins = density_field->spectrumArray().extent();
|
||||
|
||||
writer.write(num_bins(0), path_to_num_bins + "/energy");
|
||||
writer.write(num_bins(1), path_to_num_bins + "/radial");
|
||||
writer.write(num_bins(2), path_to_num_bins + "/azimuthal");
|
||||
writer.write(num_bins(3), path_to_num_bins + "/longitudinal");
|
||||
writer.write(num_bins(0), path_to_num_bins + "/radial");
|
||||
writer.write(num_bins(1), path_to_num_bins + "/longitudinal");
|
||||
writer.write(num_bins(2), path_to_num_bins + "/energy");
|
||||
}
|
||||
|
||||
void SimulationOutput::writeBinBorders(DynamicDensityField* density_field,
|
||||
@@ -405,11 +470,25 @@ void SimulationOutput::writeBinBorders(DynamicDensityField* density_field,
|
||||
density_field->positionBinning()->radial_binning.binBorders();
|
||||
writer.write(radial_bin_borders, path_to_bin_borders + "/radial");
|
||||
|
||||
std::vector<double> azimuth_bin_borders =
|
||||
density_field->positionBinning()->azimuth_binning.binBorders();
|
||||
writer.write(azimuth_bin_borders, path_to_bin_borders + "/azimuth");
|
||||
|
||||
std::vector<double> longitudinal_bin_borders =
|
||||
density_field->positionBinning()->longitudinal_binning.binBorders();
|
||||
writer.write(longitudinal_bin_borders, path_to_bin_borders + "/longitudinal");
|
||||
}
|
||||
|
||||
void SimulationOutput::writeParticles(
|
||||
std::vector<particle::SerializedParticle>& particles,
|
||||
int cpu_sync,
|
||||
double 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
|
||||
@@ -10,7 +10,9 @@ namespace generator {
|
||||
|
||||
CylinderBinning buildPositionBinning(json_t* object) {
|
||||
if (json_object_by_path(object, {"CylinderBinning"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating position binning: cylinder binning.");
|
||||
#endif
|
||||
object = json_object_by_path(object, {"CylinderBinning"});
|
||||
|
||||
json_t* radial = json_object_by_path(object, {"Radial"});
|
||||
@@ -21,12 +23,6 @@ CylinderBinning buildPositionBinning(json_t* object) {
|
||||
json_read_length(json_object_by_path(radial, {"MaxRadius"}), "m");
|
||||
ASSERT_POSITIVE(&max_radius, "Radius must be positive");
|
||||
|
||||
json_t* azimuthal = json_object_by_path(object, {"Azimuthal"});
|
||||
int number_of_bins_azimuthal =
|
||||
json_int(json_object_by_path(azimuthal, {"NumberOfBins"}));
|
||||
ASSERT_POSITIVE(&number_of_bins_azimuthal,
|
||||
"Number of Bins must be positive");
|
||||
|
||||
json_t* longitudinal = json_object_by_path(object, {"Longitudinal"});
|
||||
int number_of_bins_longitudinal =
|
||||
json_int(json_object_by_path(longitudinal, {"NumberOfBins"}));
|
||||
@@ -36,21 +32,20 @@ CylinderBinning buildPositionBinning(json_t* object) {
|
||||
json_read_length(json_object_by_path(longitudinal, {"MaxLength"}), "m");
|
||||
ASSERT_POSITIVE(&max_length, "Radius must be positive");
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with number of bins radial: " +
|
||||
std::to_string(number_of_bins_radial));
|
||||
DEBUG_LEVEL_3("with number of bins azimuthal: " +
|
||||
std::to_string(number_of_bins_azimuthal));
|
||||
DEBUG_LEVEL_3("with number of bins longitudinal: " +
|
||||
std::to_string(number_of_bins_longitudinal));
|
||||
DEBUG_LEVEL_3("with radius: " + std::to_string(max_radius) + " m");
|
||||
DEBUG_LEVEL_3("with height: " + std::to_string(max_length) + " m");
|
||||
#endif
|
||||
|
||||
return CylinderBinning(number_of_bins_radial, max_radius,
|
||||
number_of_bins_azimuthal,
|
||||
number_of_bins_longitudinal, max_length);
|
||||
} else {
|
||||
ERROR("This position binning is not implemented.");
|
||||
return CylinderBinning(0, 0, 0, 0, 0);
|
||||
return CylinderBinning(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,14 +54,18 @@ CylinderBinning buildPositionBinningIncludingRedirection(
|
||||
json_path& path_to_binning) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating position binning: CreateSameAs.");
|
||||
#endif
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"})));
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
return buildPositionBinningIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildPositionBinning(parameter.jsonObjectFromBase(path_to_binning));
|
||||
@@ -76,7 +75,9 @@ CylinderBinning buildPositionBinningIncludingRedirection(
|
||||
EnergyBinning buildEnergyBinning(json_t* object) {
|
||||
std::string energy_type = json_string(json_object_by_path(object, {"Type"}));
|
||||
if (energy_type == "Logarithmic") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy binning: logarithmic.");
|
||||
#endif
|
||||
int number_of_bins =
|
||||
json_int(json_object_by_path(object, {"NumberOfBins"}));
|
||||
ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive");
|
||||
@@ -87,9 +88,11 @@ EnergyBinning buildEnergyBinning(json_t* object) {
|
||||
json_read_energy(json_object_by_path(object, {"MaxEnergy"}), "eV");
|
||||
ASSERT_POSITIVE(&max_energy, "Max Energy must be positive");
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins));
|
||||
DEBUG_LEVEL_3("with min energy: " + std::to_string(min_energy));
|
||||
DEBUG_LEVEL_3("with max energy: " + std::to_string(max_energy));
|
||||
#endif
|
||||
|
||||
return EnergyBinning(min_energy, max_energy, number_of_bins);
|
||||
|
||||
@@ -104,14 +107,22 @@ EnergyBinning buildEnergyBinningIncludingRedirection(
|
||||
json_path& path_to_binning) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"}))) {
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy binning: CreateSameAs.");
|
||||
#endif
|
||||
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"})));
|
||||
|
||||
#ifdef debug_level3
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
|
||||
return buildEnergyBinningIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildEnergyBinning(parameter.jsonObjectFromBase(path_to_binning));
|
||||
@@ -121,12 +132,18 @@ EnergyBinning buildEnergyBinningIncludingRedirection(
|
||||
PitchAngleBinning buildPitchAngleBinning(json_t* object) {
|
||||
std::string pitch_angle_type = json_string(json_object_by_path(object, {"Type"}));
|
||||
if (pitch_angle_type == "Linear") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating pitch angle binning: linear.");
|
||||
#endif
|
||||
|
||||
int number_of_bins =
|
||||
json_int(json_object_by_path(object, {"NumberOfBins"}));
|
||||
ASSERT_POSITIVE(&number_of_bins, "Number of Bins must be positive");
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with number of bins: " + std::to_string(number_of_bins));
|
||||
#endif
|
||||
|
||||
return PitchAngleBinning(number_of_bins);
|
||||
|
||||
} else {
|
||||
@@ -140,14 +157,21 @@ PitchAngleBinning buildPitchAngleBinningIncludingRedirection(
|
||||
json_path& path_to_binning) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy binning: CreateSameAs.");
|
||||
#endif
|
||||
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_binning, {"CreateSameAs"})));
|
||||
|
||||
#ifdef debug_level3
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
|
||||
return buildPitchAngleBinningIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildPitchAngleBinning(parameter.jsonObjectFromBase(path_to_binning));
|
||||
|
||||
@@ -9,7 +9,9 @@ std::shared_ptr<CurrentCollector> buildCurrentCollector(
|
||||
Parameter& parameter,
|
||||
const json_path& path_to_collector,
|
||||
std::shared_ptr<Timer>& timer) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating current collector.");
|
||||
#endif
|
||||
json_path path_binning =
|
||||
json_path_append(path_to_collector, {"PositionBinning"});
|
||||
CylinderBinning position_binning =
|
||||
|
||||
@@ -10,7 +10,9 @@ namespace generator {
|
||||
|
||||
std::shared_ptr<ConstantDensityField> buildConstantDensityField(
|
||||
json_t* object) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating constant density field.");
|
||||
#endif
|
||||
json_path path = {"ScalarField"};
|
||||
std::shared_ptr<ScalarField> field =
|
||||
buildScalarField(json_object_by_path(object, path));
|
||||
@@ -22,7 +24,9 @@ std::shared_ptr<DynamicDensityField> buildDynamicDensityField(
|
||||
const json_path& path_to_field,
|
||||
std::shared_ptr<Timer>& timer) {
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating dynamic density field with pitch angle.");
|
||||
#endif
|
||||
json_path path_binning = json_path_append(path_to_field, {"PositionBinning"});
|
||||
CylinderBinning position_binning =
|
||||
buildPositionBinningIncludingRedirection(parameter, path_binning);
|
||||
|
||||
@@ -9,14 +9,18 @@ std::shared_ptr<DriftVelocity> buildDriftVelocity(
|
||||
const json_path& path_to_drift_velocity) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"VectorField"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating drift velocity: Vector field.");
|
||||
#endif
|
||||
std::shared_ptr<VectorField> field =
|
||||
buildVectorField(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"VectorField"})));
|
||||
return std::shared_ptr<DriftVelocity>(new DriftVelocity(field));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"null"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating drift velocity: null.");
|
||||
#endif
|
||||
return nullptr;
|
||||
} else {
|
||||
ERROR("No drift velocity given.");
|
||||
@@ -29,14 +33,18 @@ std::shared_ptr<DriftVelocity> buildDriftVelocityIncludingRedirection(
|
||||
std::stringstream cpath;
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"CreateSameAs"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating drift velocity: CreateSameAs.");
|
||||
#endif
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_drift_velocity, {"CreateSameAs"})));
|
||||
#ifdef debug_level3
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
return buildDriftVelocityIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildDriftVelocity(parameter, path_to_drift_velocity);
|
||||
|
||||
@@ -6,12 +6,16 @@
|
||||
namespace generator {
|
||||
|
||||
std::shared_ptr<ElectricField> electricField(json_t* object) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating electric field.");
|
||||
#endif
|
||||
std::shared_ptr<VectorField> background;
|
||||
std::shared_ptr<VectorField> dynamic;
|
||||
|
||||
if (json_object_by_path(object, {"Background"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating background electric field.");
|
||||
#endif
|
||||
background = buildVectorField(
|
||||
json_object_by_path(object, {"Background", "VectorField"}));
|
||||
} else {
|
||||
@@ -19,7 +23,9 @@ std::shared_ptr<ElectricField> electricField(json_t* object) {
|
||||
}
|
||||
|
||||
if (json_object_by_path(object, {"Dynamic"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating dynamic electric field.");
|
||||
#endif
|
||||
dynamic = buildVectorField(
|
||||
json_object_by_path(object, {"Dynamic", "VectorField"}));
|
||||
} else {
|
||||
|
||||
@@ -11,21 +11,37 @@ std::shared_ptr<EnergyDistributionFunction> buildEnergyDistributionFunction(
|
||||
json_t* object = parameter.jsonObjectFromBase(path_to_function);
|
||||
|
||||
if (json_object_by_path(object, {"TritiumBetaDecay"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy distribution function: tritium beta decay.");
|
||||
#endif
|
||||
return std::shared_ptr<EnergyDistributionFunction>(new TritiumBetaDecay());
|
||||
|
||||
} else if (json_object_by_path(object, {"MaxwellBoltzmann"})) {
|
||||
} else if(json_object_by_path(object, {"TritiumBetaDecayIon"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy distribution function: tritium beta decay ion.");
|
||||
#endif
|
||||
double endpoint_eV = json_read_energy(json_object_by_path(object,
|
||||
{"TritiumBetaDecayIon", "MaxRecoilEnergy"}));
|
||||
return std::shared_ptr<EnergyDistributionFunction>(new TritiumBetaDecayIon(endpoint_eV));
|
||||
}else if (json_object_by_path(object, {"MaxwellBoltzmann"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy distribution function: Maxwell Boltzmann.");
|
||||
#endif
|
||||
double temperature_K = json_double(json_object_by_path(
|
||||
object, {"MaxwellBoltzmann", "Temperature", "value"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with temperature: " + std::to_string(temperature_K) + " K");
|
||||
#endif
|
||||
return std::shared_ptr<EnergyDistributionFunction>(
|
||||
new MaxwellBoltzmann(temperature_K));
|
||||
} else if (json_object_by_path(object, {"Constant"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating energy distribution function: Constant.");
|
||||
#endif
|
||||
double constant_eV = json_double(
|
||||
json_object_by_path(object, {"Constant", "constant", "value"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with constant: " + std::to_string(constant_eV) + " eV");
|
||||
#endif
|
||||
return std::shared_ptr<EnergyDistributionFunction>(
|
||||
new Constant(constant_eV));
|
||||
}
|
||||
|
||||
@@ -11,14 +11,20 @@ namespace generator {
|
||||
|
||||
std::function<double(double)> function1D(json_t* object) {
|
||||
if (json_object_by_path(object, {"Constant"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: constant.");
|
||||
#endif
|
||||
double constant =
|
||||
json_double(json_object_by_path(object, {"Constant", "constant"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with constant: " + std::to_string(constant));
|
||||
#endif
|
||||
return D1ToD1::Constant(constant);
|
||||
|
||||
} else if (json_object_by_path(object, {"PiecewiseLinear"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear.");
|
||||
#endif
|
||||
std::vector<double> x_values = json_vector(
|
||||
json_object_by_path(object, {"PiecewiseLinear", {"xValues"}}));
|
||||
std::vector<double> y_values = json_vector(
|
||||
@@ -31,11 +37,15 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
return D1ToD1::PiecewiseLinear(x_values, y_values);
|
||||
|
||||
} else if (json_object_by_path(object, {"PiecewiseLinearFromFile"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: PiecewiseLinear from file.");
|
||||
#endif
|
||||
|
||||
std::string absolute_filename = readAbsoluteFilename(
|
||||
json_object_by_path(object, {"PiecewiseLinearFromFile", "PathToH5"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with filename: " + absolute_filename);
|
||||
#endif
|
||||
Hdf5Reader reader(absolute_filename);
|
||||
|
||||
std::string x_values_key = json_string(
|
||||
@@ -53,7 +63,9 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
|
||||
double prefactor = json_double(json_object_by_path(
|
||||
object, {"PiecewiseLinearFromFile", {"prefactor"}}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with prefactor: " + std::to_string(prefactor));
|
||||
#endif
|
||||
|
||||
for (int i = 0; i < y_values.size(); ++i) {
|
||||
y_values[i] = y_values[i] * prefactor;
|
||||
@@ -61,7 +73,9 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
return D1ToD1::PiecewiseLinear(x_values, y_values);
|
||||
|
||||
} else if (json_object_by_path(object, {"Product"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: Product.");
|
||||
#endif
|
||||
json_t* function_array = json_object_by_path(object, {"Product"});
|
||||
std::vector<std::function<double(double)>> functions;
|
||||
size_t index;
|
||||
@@ -72,7 +86,9 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
return D1ToD1::Product(functions);
|
||||
|
||||
} else if (json_object_by_path(object, {"Exponential"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function1d: Exponential.");
|
||||
#endif
|
||||
double prefactor = json_double(json_object_by_path(
|
||||
object, {"Exponential", {"prefactor"}}));
|
||||
double scale = json_double(json_object_by_path(
|
||||
@@ -86,12 +102,16 @@ std::function<double(double)> function1D(json_t* object) {
|
||||
|
||||
std::function<double(double, double, double)> function3D(json_t* object) {
|
||||
if (json_object_by_path(object, {"Constant3D"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function3d: Constant3D.");
|
||||
#endif
|
||||
double constant =
|
||||
json_double(json_object_by_path(object, {"Constant3D", "constant"}));
|
||||
return D3ToD1::Constant(constant);
|
||||
} else if (json_object_by_path(object, {"Product"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating function3d: Product.");
|
||||
#endif
|
||||
std::function<double(double)> fi =
|
||||
function1D(json_object_by_path(object, {"Product", "fi"}));
|
||||
std::function<double(double)> fj =
|
||||
|
||||
@@ -7,7 +7,9 @@ std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
|
||||
const json_path& path_to_geometry) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_geometry, {"Cylinder"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating geometry: cylinder.");
|
||||
#endif
|
||||
double radius =
|
||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_geometry, {"Cylinder", "Radius"})),
|
||||
@@ -16,8 +18,10 @@ std::shared_ptr<Geometry> buildGeometry(Parameter& parameter,
|
||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_geometry, {"Cylinder", "Height"})),
|
||||
"m");
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with radius: " + std::to_string(radius) + " m");
|
||||
DEBUG_LEVEL_3("with height: " + std::to_string(height) + " m");
|
||||
#endif
|
||||
return std::shared_ptr<Geometry>(new Cylinder(radius, height));
|
||||
} else {
|
||||
ERROR("This geometry is not implemented.");
|
||||
@@ -29,14 +33,18 @@ std::shared_ptr<Geometry> buildGeometryIncludingRedirection(
|
||||
Parameter& parameter, const json_path& path_to_geometry) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_geometry, {"CreateSameAs"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating geometry: CreateSameAs.");
|
||||
#endif
|
||||
json_path path_to_same = json_path_get(parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_geometry, {"CreateSameAs"})));
|
||||
std::stringstream path;
|
||||
for (auto& p : path_to_same) {
|
||||
path << p << " ";
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("From path: " + path.str());
|
||||
#endif
|
||||
return buildGeometryIncludingRedirection(parameter, path_to_same);
|
||||
} else {
|
||||
return buildGeometry(parameter, path_to_geometry);
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
namespace generator {
|
||||
|
||||
std::shared_ptr<GravityField> gravityField(json_t* object) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating gravity field.");
|
||||
#endif
|
||||
return std::shared_ptr<GravityField>(new GravityField(
|
||||
buildVectorField(json_object_by_path(object, {"VectorField"}))));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "generators/velocity_distribution_generator.h"
|
||||
#include "simulation/event_position_distribution.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
#include "simulation/mpi_communication.h"
|
||||
|
||||
namespace generator {
|
||||
|
||||
@@ -25,7 +26,9 @@ std::shared_ptr<Injector> buildInjector(
|
||||
json_object_foreach(array, key, value) {
|
||||
std::string specie_name =
|
||||
json_string(json_object_by_path(value, {"TrackedSpecieName"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Injected specie: " + specie_name);
|
||||
#endif
|
||||
InjectorInfo info;
|
||||
info.created_specie = tracked_species[specie_name];
|
||||
|
||||
@@ -37,11 +40,25 @@ std::shared_ptr<Injector> buildInjector(
|
||||
// info.multiplicity = json_int(json_object_by_path(value, {"Multiplicity"}), 1);
|
||||
// ASSERT_POSITIVE(&info.multiplicity, "The multiplicity has to be positive. " +
|
||||
// specie_name + " multiplicity: " + std::to_string(info.multiplicity));
|
||||
int injection_stride = json_int(json_object_by_path(value, {"InjectionStride"}), 1);
|
||||
ASSERT_POSITIVE(&injection_stride, "The injection stride for " + specie_name +
|
||||
" is not positive! (" + std::to_string(injection_stride) + ")");
|
||||
if(injection_stride > MpiCommunication::mpiSize()) {
|
||||
ERROR("Injection stride for " + specie_name + ": "
|
||||
+ std::to_string(injection_stride) + " is larger than the number"
|
||||
" of processes (" + std::to_string(MpiCommunication::mpiSize()) + ")");
|
||||
}
|
||||
|
||||
info.injection_stride = injection_stride;
|
||||
info.injection_group = MpiCommunication::mpi_rank % injection_stride;
|
||||
|
||||
injector_infos.push_back(info);
|
||||
}
|
||||
|
||||
// EventPositionDistribution
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating event distribution.");
|
||||
#endif
|
||||
std::shared_ptr<ScalarField> field = buildScalarField(json_object_by_path(
|
||||
object, {"EventPositionDistribution", "ScalarField"}));
|
||||
|
||||
@@ -80,7 +97,9 @@ std::shared_ptr<Injector> buildInjector(
|
||||
position_limit_phi, position_limit_z));
|
||||
|
||||
// MotherDriftVelocity
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating mother drift velocity.");
|
||||
#endif
|
||||
std::shared_ptr<DriftVelocity> drift_velocity = buildDriftVelocity(
|
||||
parameter, json_path_append(path_to_injector, {"MotherDriftVelocity"}));
|
||||
|
||||
|
||||
@@ -33,7 +33,9 @@ void addInteractions(
|
||||
std::string type = json_string(json_object_by_path(value, {"Type"}));
|
||||
|
||||
if (type == "ElasticScattering") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: ElasticScattering");
|
||||
#endif
|
||||
std::function<double(double)> cross_section =
|
||||
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
|
||||
|
||||
@@ -43,7 +45,9 @@ void addInteractions(
|
||||
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with target " + target_name);
|
||||
#endif
|
||||
|
||||
std::shared_ptr<species::Specie> target =
|
||||
findTarget(target_name, tracked_species, background_species);
|
||||
@@ -53,11 +57,15 @@ void addInteractions(
|
||||
scattering_angle_distribution)));
|
||||
|
||||
} else if (type == "FreeMovement") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: FreeMovement");
|
||||
#endif
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::FreeMovement()));
|
||||
} else if (type == "ElectronIonization") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: Ionization");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::Specie> target =
|
||||
@@ -183,7 +191,9 @@ void addInteractions(
|
||||
ERROR("This ionization model is not implemented: " + ionization_model);
|
||||
}
|
||||
} else if (type == "Excitation") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: Excitation");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::Specie> target =
|
||||
@@ -201,7 +211,9 @@ void addInteractions(
|
||||
cross_section, target, excitation_energy)));
|
||||
|
||||
} else if (type == "Clustering") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: Clustering");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::Specie> target =
|
||||
@@ -212,12 +224,37 @@ void addInteractions(
|
||||
std::shared_ptr<species::TrackedSpecie> product =
|
||||
findTracked(product_name, tracked_species);
|
||||
|
||||
std::string clustering_type =
|
||||
json_string(json_object_by_path(value, {"ClusteringType"}));
|
||||
|
||||
std::function<double(double)> cross_section =
|
||||
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::ClusterFormation(cross_section, target, product)));
|
||||
|
||||
if(clustering_type == "radiative") {
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::ClusterFormation(cross_section, target, product)));
|
||||
} else if (clustering_type == "tertiary") {
|
||||
SIM_INFO("Warning: tertiary clustering has been chosen. Be warned "
|
||||
"that the cross section function is scaled by the density "
|
||||
"of the target specie at the position of the interaction "
|
||||
"(cross section function assumed to have the units m^5)");
|
||||
|
||||
if(json_string(json_object_by_path(value, {"CrossSection", "PredefinedFunction"}))
|
||||
== "T2pT2_clustering_janev") {
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::ClusterFormationTertiary(cross_section, target, product, false)));
|
||||
} else {
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::ClusterFormationTertiary(cross_section, target, product)));
|
||||
}
|
||||
} else {
|
||||
ERROR("ClusteringType " + clustering_type +
|
||||
": not known, choose either 'radiative' or 'tertiary'.");
|
||||
}
|
||||
} else if (type == "ChargeExchange") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: ChargeExchange");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::Specie> target =
|
||||
@@ -228,7 +265,9 @@ void addInteractions(
|
||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||
new interaction::ChargeExchange(cross_section, target)));
|
||||
} else if (type == "Recombination") {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding interactions: Recombination");
|
||||
#endif
|
||||
std::string target_name =
|
||||
json_string(json_object_by_path(value, {"Target"}));
|
||||
std::shared_ptr<species::TrackedSpecie> target =
|
||||
@@ -288,7 +327,7 @@ std::function<double(double)> buildTotalCrossSection(json_t* object) {
|
||||
return interaction::totalCrossSection::eT_ionization_from_ground_janev();
|
||||
} else if (function_name == "TpT_clustering_tertiary_janev") {
|
||||
// needs to be changed to account for the temperature, probs smth like excitation
|
||||
return interaction::totalCrossSection::TpT_clustering_tertiary_janev(80.);
|
||||
return interaction::totalCrossSection::TpT_clustering_tertiary_janev(5e-3);
|
||||
} else if (function_name == "eTp_recombination_kotelnikov") {
|
||||
return interaction::totalCrossSection::eTp_recombination_kotelnikov();
|
||||
} else if (function_name == "TpT_charge_exchange_janev") {
|
||||
@@ -471,18 +510,24 @@ std::function<double(double, double)> build2DCrossSection(json_t* object) {
|
||||
std::shared_ptr<ScatteringAngleDistribution> buildScatteringAngleDistribution(
|
||||
json_t* object) {
|
||||
if (json_object_by_path(object, {"Isotropic"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Adding ScatteringAngleDistribution: Isotropic");
|
||||
#endif
|
||||
return std::shared_ptr<ScatteringAngleDistribution>(
|
||||
new IsotropicAngleDistribution());
|
||||
} else if (json_object_by_path(object, {"AngleDistributionFromFile"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Adding ScatteringAngleDistribution: AngleDistributionFromFile");
|
||||
#endif
|
||||
std::string absolute_filepath = readAbsoluteFilename(
|
||||
json_object_by_path(object, {"AngleDistributionFromFile", "PathToH5"}));
|
||||
return std::make_shared<AngleDistributionFromFile>(absolute_filepath);
|
||||
} else if (json_object_by_path(object, {"CompositeAngleDistribution"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Adding ScatteringAngleDistribution: CompositeAngleDistribution");
|
||||
#endif
|
||||
json_t* object_composite =
|
||||
json_object_by_path(object, {"CompositeAngleDistribution"});
|
||||
const double decider_energy = json_read_energy(
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace generator {
|
||||
|
||||
std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
||||
std::vector<DeletionType> used_types;
|
||||
std::vector<PhysicalDeletionType> used_phys_types;
|
||||
|
||||
json_t* type = json_object_by_path(object, {"Type"});
|
||||
if (json_is_array(type)) {
|
||||
@@ -24,7 +25,9 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
||||
used_types.push_back(DeletionType::max_time_alive);
|
||||
} else if (type_alias == "cluster_formation") {
|
||||
used_types.push_back(DeletionType::cluster_formation);
|
||||
} else {
|
||||
} else if (type_alias == "wall_physical") {
|
||||
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||
}else {
|
||||
ERROR("This deletion type " + type_alias + " is not known.");
|
||||
}
|
||||
}
|
||||
@@ -35,15 +38,18 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
||||
used_types.push_back(DeletionType::max_interactions);
|
||||
used_types.push_back(DeletionType::max_time_alive);
|
||||
used_types.push_back(DeletionType::cluster_formation);
|
||||
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_shared<DeletionLogger>(used_types);
|
||||
return std::make_shared<DeletionLogger>(used_types, used_phys_types);
|
||||
}
|
||||
std::shared_ptr<DeletionLogger> buildDeletionLogger(
|
||||
Parameter& parameter,
|
||||
const json_path& path_to_loggers) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating deletion logger.");
|
||||
#endif
|
||||
|
||||
json_path path_logger = json_path_append(path_to_loggers, {"Deletion"});
|
||||
json_t* object = parameter.jsonObjectFromBase(path_logger);
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
namespace generator {
|
||||
|
||||
std::shared_ptr<MagneticField> magneticField(json_t* object) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating magnetic field.");
|
||||
#endif
|
||||
return std::shared_ptr<MagneticField>(new MagneticField(
|
||||
buildVectorField(json_object_by_path(object, {"VectorField"})),
|
||||
buildVectorField(json_object_by_path(object, {"GradientField"}))));
|
||||
|
||||
@@ -7,13 +7,17 @@ std::shared_ptr<Mover> buildMover(Parameter& parameter,
|
||||
const json_path& path_to_mover) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_mover, {"Boris"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating mover: Boris.");
|
||||
#endif
|
||||
double max_timestep_length = parameter.doubleValue(json_path_append(
|
||||
path_to_mover, {"Boris", "MaximalTimestepLength", "value"}));
|
||||
return std::shared_ptr<Mover>(new BorisMover(max_timestep_length));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_mover, {"Drift"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating mover: Drift.");
|
||||
#endif
|
||||
double maximal_moved_distance =
|
||||
json_read_length(parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_mover, {"Drift", "MaximalMovedDistance"})));
|
||||
|
||||
@@ -10,11 +10,14 @@ namespace generator {
|
||||
std::shared_ptr<PoissonSolver> buildPoissonSolver(
|
||||
Parameter& parameter) {
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Generating Poisson solver.");
|
||||
#endif
|
||||
std::shared_ptr<Geometry> geometry;
|
||||
|
||||
json_t* object = json_object_by_path(
|
||||
parameter.jsonFile(), {"PoissonSolver"});
|
||||
|
||||
//create geometry
|
||||
if (json_object_by_path(object, {"BoundaryGeometry"})) {
|
||||
geometry = buildGeometryIncludingRedirection(parameter,
|
||||
@@ -22,6 +25,7 @@ namespace generator {
|
||||
} else {
|
||||
ERROR("Cannot find boundary geometry for poisson solver.");
|
||||
}
|
||||
|
||||
//create binning
|
||||
json_path path_binning = json_path_append({"PoissonSolver"},
|
||||
{"PositionBinning"});
|
||||
@@ -30,7 +34,37 @@ namespace generator {
|
||||
|
||||
auto boundaries = buildBoundaries(parameter, {"PoissonSolver", "Boundary"});
|
||||
|
||||
// build electrodes, might be good to put into own function
|
||||
std::vector<std::shared_ptr<Electrode>> electrodes{};
|
||||
const char* key;
|
||||
json_t* value;
|
||||
json_t* array = parameter.jsonObjectFromBase({"PoissonSolver", "Electrodes"});
|
||||
json_object_foreach(array, key, value) {
|
||||
std::string type = json_string(json_object_by_path(value, {"Type"}));
|
||||
if(type == "RingElectrode") {
|
||||
double zpos = json_read_length(json_object_by_path(value, {"zPosition"}));
|
||||
double rInner = json_read_length(json_object_by_path(value, {"InnerRadius"}));
|
||||
double rOuter = json_read_length(json_object_by_path(value, {"OuterRadius"}));
|
||||
double potentialValue = json_double(json_object_by_path(value, {"Potential", "value"}));
|
||||
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << "Electrode " << std::string(key) << ":\n\t";
|
||||
out << "z position: " << zpos << " m\n\t";
|
||||
out << "inner radius: " << rInner << " m\n\t";
|
||||
out << "outer radius: " << rOuter << " m\n\t";
|
||||
out << "potential: " << potentialValue << " V";
|
||||
DEBUG(out.str());
|
||||
#endif
|
||||
|
||||
electrodes.push_back(
|
||||
std::shared_ptr<RingElectrode>(
|
||||
new RingElectrode(potentialValue, zpos, rInner, rOuter,
|
||||
position_binning.stepsize())));
|
||||
} else {
|
||||
ERROR("Unknown or not implemented electrode type: " + type + ". Available options: \"RingElectrode\"");
|
||||
}
|
||||
}
|
||||
|
||||
double target_accuracy = parameter.doubleValue(
|
||||
json_path_append({"PoissonSolver"}, {"TargetAccuracy"}));
|
||||
@@ -48,7 +82,9 @@ namespace generator {
|
||||
|
||||
std::map<std::string, GlobalBoundary> buildBoundaries(Parameter& parameter,
|
||||
const json_path& path_to_boundaries) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Creating Boundaries.");
|
||||
#endif
|
||||
std::map<std::string, GlobalBoundary> boundary_map {
|
||||
{"Bottom", {0., BoundaryType::dirichlet}},
|
||||
{"Top", {0., BoundaryType::dirichlet}},
|
||||
@@ -63,7 +99,9 @@ namespace generator {
|
||||
json_t* value;
|
||||
json_object_foreach(parameter.jsonObjectFromBase(path_to_boundaries),
|
||||
key, value) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Creating " + std::string(key) + ": ");
|
||||
#endif
|
||||
if(!(boundary_map.find(std::string(key)) == boundary_map.end())) {
|
||||
double boundary_value =
|
||||
json_double(json_object_by_path(value, {"value"}));
|
||||
@@ -82,8 +120,10 @@ namespace generator {
|
||||
". Using default boundary (dirichtlet, value 0)");
|
||||
continue;
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with type: " + boundary_type);
|
||||
DEBUG_LEVEL_3("with value: " + std::to_string(boundary_value));
|
||||
#endif
|
||||
|
||||
} else {
|
||||
SIM_INFO(std::string(key) + ": unknown location. Is ignored.");
|
||||
|
||||
@@ -8,15 +8,25 @@ std::shared_ptr<Reflector> buildReflector(Parameter& parameter,
|
||||
const json_path& path_to_reflector) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_reflector, {"ReflectorDPS"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Create reflector: ReflectorDPS");
|
||||
#endif
|
||||
double position_z = json_read_length(
|
||||
parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_reflector, {"ReflectorDPS", "position_z"})),
|
||||
"m");
|
||||
return std::shared_ptr<Reflector>(new ReflectorDPS(position_z));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_reflector, {"LongitudinalReflector"}))) {
|
||||
double height = json_read_length(
|
||||
parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_reflector, {"LongitudinalReflector", "height"})), "m");
|
||||
return std::shared_ptr<Reflector>(new LongitudinalReflector(height));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_reflector, {"NoReflector"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Create reflector: NoReflector");
|
||||
#endif
|
||||
return std::shared_ptr<Reflector>(new NoReflector());
|
||||
} else {
|
||||
ERROR("This reflector is not implemented.");
|
||||
|
||||
@@ -7,29 +7,42 @@ namespace generator {
|
||||
DEBUG_LEVEL_3("Build Restart.");
|
||||
bool do_restart = json_bool(json_object_by_path(object, {"Do"}));
|
||||
if (!do_restart) {
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("No Restart desired.");
|
||||
return Restart(false, "", "");
|
||||
#endif
|
||||
return Restart(false, "", "", 0);
|
||||
}
|
||||
|
||||
std::string filepath = readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}))
|
||||
+ ".h5";
|
||||
// no file extensions!!! Those get added in the constructor of the hdf5 and mpi
|
||||
// reader classes
|
||||
std::string filepath =
|
||||
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Restart: file path:" + filepath);
|
||||
#endif
|
||||
|
||||
std::string identifier;
|
||||
int sync_period = json_int(json_object_by_path(object, {"SyncPeriod"}));
|
||||
int part_restart_at = sync_period;
|
||||
|
||||
if(sync_period == 0 && json_string(json_object_by_path(object, {"SyncPeriod"}))
|
||||
== "LastSyncPeriod") {
|
||||
identifier = "LastSyncPeriod";
|
||||
|
||||
part_restart_at = json_int(json_object_by_path(object, {"ParticleSyncPeriod"}));
|
||||
ASSERT_POSITIVE(&part_restart_at, "The ParticleSyncPeriod has to be positive!");
|
||||
|
||||
} else {
|
||||
ASSERT_POSITIVE(&sync_period, "The SyncPeriod for the restart has to be either"
|
||||
" positive or \"LastSyncPeriod\".");
|
||||
identifier = "SyncPeriod_" + std::to_string(sync_period);
|
||||
}
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Restart: SyncPeriod to be started from: " + identifier);
|
||||
#endif
|
||||
|
||||
return Restart(do_restart, filepath, identifier);
|
||||
return Restart(do_restart, filepath, identifier, part_restart_at);
|
||||
}
|
||||
|
||||
Restart buildRestart(Parameter& parameter) {
|
||||
|
||||
@@ -166,7 +166,9 @@ std::shared_ptr<SimulationOutput> buildSimulationOutput(
|
||||
}
|
||||
ASSERT_NOTNEGATIVE(&intervall, "The intervall for RestartInfo has to be either 0"
|
||||
",if no output is required or positive otherwise");
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Restart output interval: " + std::to_string(intervall));
|
||||
#endif
|
||||
|
||||
bool overwrite_last = json_bool(
|
||||
json_object_by_path(object, {"RestartInfo", "OverwriteLast"}));
|
||||
@@ -176,6 +178,31 @@ std::shared_ptr<SimulationOutput> buildSimulationOutput(
|
||||
output->setRestartInfoOutput(task);
|
||||
}
|
||||
|
||||
// Particles
|
||||
{
|
||||
int intervall =
|
||||
json_int(json_object_by_path(object, {"Particles", "Intervall"}), -1);
|
||||
// DEBUG_LEVEL_2("Try value of Intervall as string");
|
||||
if (intervall == -1 && json_string(json_object_by_path(
|
||||
object, {"Particles", "Intervall"})) == "EachSync") {
|
||||
intervall = 1;
|
||||
} else if (intervall == -1) {
|
||||
intervall = 0;
|
||||
}
|
||||
ASSERT_NOTNEGATIVE(&intervall, "The intervall for Particles output has to be either 0"
|
||||
",if no output is required or positive otherwise");
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Particles output interval: " + std::to_string(intervall));
|
||||
#endif
|
||||
|
||||
// could be done, but then the naming of the mpi file would need to be adjusted
|
||||
bool overwrite_last = false;
|
||||
|
||||
OutputTask task = {"Particles", overwrite_last, intervall};
|
||||
|
||||
output->setParticleOutput(task);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,13 +107,17 @@ std::shared_ptr<Timer> SpeciesBuilder::lastSyncTimer() {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::initTimer() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Init timer.");
|
||||
#endif
|
||||
timer_ = std::shared_ptr<Timer>(new Timer());
|
||||
last_sync_timer_ = std::shared_ptr<Timer>(new Timer());
|
||||
}
|
||||
|
||||
void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Init background species info.");
|
||||
#endif
|
||||
const char* key;
|
||||
json_t* value;
|
||||
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Background"}),
|
||||
@@ -126,11 +130,18 @@ void SpeciesBuilder::initBackgroundSpecies(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Init tracked species info.");
|
||||
#endif
|
||||
const char* key;
|
||||
json_t* value;
|
||||
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Tracked"}), key,
|
||||
value) {
|
||||
if(std::string(key).size() >= 16) {
|
||||
std::stringstream out;
|
||||
out << std::string(key) << ": name is to long, has to be 15 chars or less!";
|
||||
ERROR(out.str());
|
||||
}
|
||||
tracked_species_info[std::string(key)] = TrackedSpeciesBuilderInfo();
|
||||
tracked_species_info[std::string(key)].name = std::string(key);
|
||||
tracked_species_info[std::string(key)].path_in_json = {"Species", "Tracked",
|
||||
@@ -139,11 +150,15 @@ void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill background species type.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
std::string type = json_string(parameter.jsonObjectFromBase(
|
||||
json_path_append(b.second.path_in_json, {"ParticleType"})));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Type: " + type);
|
||||
#endif
|
||||
if (SpeciesAlias::isAlias(type)) {
|
||||
b.second.type = SpeciesAlias::alias(type);
|
||||
} else {
|
||||
@@ -153,11 +168,15 @@ void SpeciesBuilder::fillBackgroundSpecieType(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill tracked species type.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
std::string type = json_string(parameter.jsonObjectFromBase(
|
||||
json_path_append(b.second.path_in_json, {"ParticleType"})));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Type: " + type);
|
||||
#endif
|
||||
if (SpeciesAlias::isAlias(type)) {
|
||||
b.second.type = SpeciesAlias::alias(type);
|
||||
} else {
|
||||
@@ -167,7 +186,9 @@ void SpeciesBuilder::fillTrackedSpecieType(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill background density.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.density = buildConstantDensityField(parameter.jsonObjectFromBase(
|
||||
json_path_append(b.second.path_in_json, {"ConstantDensityField"})));
|
||||
@@ -175,7 +196,9 @@ void SpeciesBuilder::fillBackgroundDensity(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill velocity distributions.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.velocity_distribution = buildVelocityDistribution(
|
||||
parameter,
|
||||
@@ -189,7 +212,9 @@ void SpeciesBuilder::fillVelocityDistribution(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill drift velocity.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.drift_velocity = buildDriftVelocityIncludingRedirection(
|
||||
parameter, json_path_append(b.second.path_in_json, {"DriftVelocity"}));
|
||||
@@ -201,7 +226,9 @@ void SpeciesBuilder::fillDriftVelocity(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillMass() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill masses.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.mass_kg = SpeciesMasses::mass(b.second.type);
|
||||
}
|
||||
@@ -211,7 +238,9 @@ void SpeciesBuilder::fillMass() {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillCharge() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill charges.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
b.second.charge_C = SpeciesCharges::charge(b.second.type);
|
||||
}
|
||||
@@ -221,7 +250,9 @@ void SpeciesBuilder::fillCharge() {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillMover(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill movers.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
if ((b.second.mover == nullptr)) {
|
||||
b.second.mover = buildMover(
|
||||
@@ -231,7 +262,9 @@ void SpeciesBuilder::fillMover(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillTerminator(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill terminators.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
if ((b.second.terminator == nullptr)) {
|
||||
b.second.terminator = buildTerminator(
|
||||
@@ -241,7 +274,9 @@ void SpeciesBuilder::fillTerminator(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillReflector(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill reflectors.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
if ((b.second.reflector == nullptr)) {
|
||||
b.second.reflector = buildReflector(
|
||||
@@ -252,25 +287,22 @@ void SpeciesBuilder::fillReflector(Parameter& parameter) {
|
||||
|
||||
// TBD: Fill and create dynamic density fields with pitch angle distribution
|
||||
void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill tracked density.");
|
||||
#endif
|
||||
for (auto& b : tracked_species_info) {
|
||||
b.second.density_field = buildDynamicDensityField(
|
||||
parameter,
|
||||
json_path_append(b.second.path_in_json,
|
||||
{"DensityField", "DynamicDensityField"}),
|
||||
timer_);
|
||||
|
||||
// not the optimal solution! (has to be optimized)
|
||||
b.second.density_drawing_field = buildDynamicDensityField(
|
||||
parameter,
|
||||
json_path_append(b.second.path_in_json,
|
||||
{"DensityField", "DynamicDensityField"}),
|
||||
timer_);
|
||||
}
|
||||
}
|
||||
|
||||
void SpeciesBuilder::buildSpecies() {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Build species from info.");
|
||||
#endif
|
||||
for (auto& b : background_species_info) {
|
||||
background_species[b.first] = std::shared_ptr<species::BackgroundSpecie>(
|
||||
new species::BackgroundSpecie(
|
||||
@@ -285,12 +317,14 @@ void SpeciesBuilder::buildSpecies() {
|
||||
b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C,
|
||||
b.second.mover, b.second.terminator, b.second.reflector,
|
||||
b.second.density_field, b.second.velocity_distribution,
|
||||
b.second.drift_velocity, b.second.density_drawing_field));
|
||||
b.second.drift_velocity));
|
||||
}
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill current collectors.");
|
||||
#endif
|
||||
for (auto& b : tracked_species) {
|
||||
auto current_collector = buildCurrentCollector(
|
||||
parameter,
|
||||
@@ -302,7 +336,9 @@ void SpeciesBuilder::fillCurrentCollector(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillLoggers(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill loggers.");
|
||||
#endif
|
||||
for (auto& b : tracked_species) {
|
||||
auto deletion_logger = buildDeletionLogger(
|
||||
parameter,
|
||||
@@ -313,7 +349,9 @@ void SpeciesBuilder::fillLoggers(Parameter& parameter) {
|
||||
}
|
||||
|
||||
void SpeciesBuilder::fillInteractions(Parameter& parameter) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Fill interactions.");
|
||||
#endif
|
||||
for (auto& b : tracked_species) {
|
||||
json_path path = tracked_species_info[b.first].path_in_json;
|
||||
path = json_path_append(path, {"Interactions"});
|
||||
|
||||
@@ -7,19 +7,91 @@ namespace generator {
|
||||
std::shared_ptr<Terminator> buildTerminator(
|
||||
Parameter& parameter,
|
||||
const json_path& path_to_terminator) {
|
||||
DEBUG_LEVEL_2("Creating terminator.");
|
||||
long int max_interactions = static_cast<long int>(parameter.doubleValue(
|
||||
json_path_append(path_to_terminator, {"MaximumInteractions"})));
|
||||
double max_time_alive = parameter.doubleValue(
|
||||
json_path_append(path_to_terminator, {"MaxTimeAlive", "value"}));
|
||||
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
|
||||
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating terminator.");
|
||||
#endif
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_terminator, {"Cylinder"}))) {
|
||||
long int max_interactions = static_cast<long int>(parameter.doubleValue(
|
||||
json_path_append(path_to_terminator, {"Cylinder", "MaximumInteractions"})));
|
||||
double max_time_alive = parameter.doubleValue(
|
||||
json_path_append(path_to_terminator, {"Cylinder", "MaxTimeAlive", "value"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
|
||||
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
|
||||
#endif
|
||||
|
||||
std::shared_ptr<Geometry> geometry = buildGeometryIncludingRedirection(
|
||||
parameter, json_path_append(path_to_terminator, {"BoundaryGeometry"}));
|
||||
std::shared_ptr<Geometry> geometry = buildGeometryIncludingRedirection(
|
||||
parameter, json_path_append(path_to_terminator, {"Cylinder", "BoundaryGeometry"}));
|
||||
|
||||
return std::shared_ptr<Terminator>(
|
||||
new Terminator(max_interactions, max_time_alive, geometry));
|
||||
return std::shared_ptr<Terminator>(
|
||||
new Terminator(max_interactions, max_time_alive, geometry));
|
||||
|
||||
} else if (parameter.jsonObjectFromBase(json_path_append(path_to_terminator,
|
||||
{"CylinderWithPlates"}))) {
|
||||
long int max_interactions = static_cast<long int>(parameter.doubleValue(
|
||||
json_path_append(path_to_terminator, {"CylinderWithPlates", "MaximumInteractions"})));
|
||||
double max_time_alive = parameter.doubleValue(
|
||||
json_path_append(path_to_terminator, {"CylinderWithPlates", "MaxTimeAlive", "value"}));
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("with max interactions: " + std::to_string(max_interactions));
|
||||
DEBUG_LEVEL_3("with max time alive: " + std::to_string(max_time_alive));
|
||||
#endif
|
||||
|
||||
std::shared_ptr<Geometry> geometry = buildGeometryIncludingRedirection(
|
||||
parameter, json_path_append(path_to_terminator, {"CylinderWithPlates", "BoundaryGeometry"}));
|
||||
|
||||
double zpos1 = json_read_length(
|
||||
parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_terminator,
|
||||
{"CylinderWithPlates", "Plate1", "zPosition"})));
|
||||
|
||||
double rInner1 = json_read_length(
|
||||
parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_terminator,
|
||||
{"CylinderWithPlates", "Plate1", "innerRadius"})));
|
||||
|
||||
double rOuter1 = json_read_length(
|
||||
parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_terminator,
|
||||
{"CylinderWithPlates", "Plate1", "outerRadius"})));
|
||||
|
||||
double zpos2 = json_read_length(
|
||||
parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_terminator,
|
||||
{"CylinderWithPlates", "Plate2", "zPosition"})));
|
||||
|
||||
double rInner2 = json_read_length(
|
||||
parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_terminator,
|
||||
{"CylinderWithPlates", "Plate2", "innerRadius"})));
|
||||
|
||||
double rOuter2 = json_read_length(
|
||||
parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_terminator,
|
||||
{"CylinderWithPlates", "Plate2", "outerRadius"})));
|
||||
|
||||
if(MpiCommunication::mpi_rank == 0) {
|
||||
std::stringstream out;
|
||||
out << "Specifications of Plate 1:\n";
|
||||
out << "\tz position: " << zpos1 << " m\n\t";
|
||||
out << "inner radius: " << rInner1 << " m\n\t";
|
||||
out << "outer radius: " << rOuter1 << " m\n";
|
||||
out << "Specifications of Plate 2:\n";
|
||||
out << "\tz position: " << zpos2 << " m\n\t";
|
||||
out << "inner radius: " << rInner2 << " m\n\t";
|
||||
out << "outer radius: " << rOuter2 << " m\n";
|
||||
SIM_INFO(out.str());
|
||||
}
|
||||
|
||||
return std::shared_ptr<TerminatorWithPlates>(
|
||||
new TerminatorWithPlates(max_interactions, max_time_alive, geometry,
|
||||
zpos1, zpos2, rInner1, rInner2, rOuter1, rOuter2));
|
||||
|
||||
} else {
|
||||
ERROR("Unknown Terminator type");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}; // namespace generator
|
||||
@@ -32,28 +32,30 @@ std::string readAbsoluteFilename(json_t* object) {
|
||||
}
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> readFromFile(json_t* object) {
|
||||
blitz::Array<double, 2> readFromFile(json_t* object) {
|
||||
std::string absolute_filename =
|
||||
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
||||
std::string key = json_string(json_object_by_path(object, {"Key"}));
|
||||
|
||||
Hdf5Reader reader(absolute_filename);
|
||||
return reader.readD3Double(key);
|
||||
return reader.readD2Double(key);
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> readComponentFromFile(json_t* object, int component) {
|
||||
blitz::Array<double, 2> readComponentFromFile(json_t* object, int component) {
|
||||
std::string absolute_filename =
|
||||
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
||||
std::string key = json_string(
|
||||
json_array_get(json_object_by_path(object, {"Keys"}), component));
|
||||
|
||||
Hdf5Reader reader(absolute_filename);
|
||||
return reader.readD3Double(key);
|
||||
return reader.readD2Double(key);
|
||||
}
|
||||
|
||||
std::shared_ptr<VectorField> buildVectorField(json_t* object) {
|
||||
if (json_object_by_path(object, {"VectorFieldConstant"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldConstant");
|
||||
#endif
|
||||
blitz::TinyVector<double, 3> constant = json_blitz_vector<3>(
|
||||
json_object_by_path(object, {"VectorFieldConstant", "constant"}));
|
||||
|
||||
@@ -61,23 +63,27 @@ std::shared_ptr<VectorField> buildVectorField(json_t* object) {
|
||||
new VectorFieldConstant(CylinderVector(constant)));
|
||||
|
||||
} else if (json_object_by_path(object, {"VectorFieldFunctionInZ"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFunctionInZ");
|
||||
#endif
|
||||
std::function<double(double, double, double)> z_function = function3D(
|
||||
json_object_by_path(object, {"VectorFieldFunctionInZ", "zFunction"}));
|
||||
return std::shared_ptr<VectorField>(new VectorFieldFunctionInZ(z_function));
|
||||
|
||||
} else if (json_object_by_path(object, {"VectorFieldFromArray"})) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating Vector field: VectorFieldFromArray");
|
||||
#endif
|
||||
|
||||
blitz::Array<double, 3> v_radial = readComponentFromFile(
|
||||
blitz::Array<double, 2> v_radial = readComponentFromFile(
|
||||
json_object_by_path(object,
|
||||
{"VectorFieldFromArray", "ReadArrayFromFile"}),
|
||||
0);
|
||||
blitz::Array<double, 3> v_azimuthal = readComponentFromFile(
|
||||
blitz::Array<double, 2> v_azimuthal = readComponentFromFile(
|
||||
json_object_by_path(object,
|
||||
{"VectorFieldFromArray", "ReadArrayFromFile"}),
|
||||
1);
|
||||
blitz::Array<double, 3> v_longitudinal = readComponentFromFile(
|
||||
blitz::Array<double, 2> v_longitudinal = readComponentFromFile(
|
||||
json_object_by_path(object,
|
||||
{"VectorFieldFromArray", "ReadArrayFromFile"}),
|
||||
2);
|
||||
|
||||
@@ -11,8 +11,10 @@ std::shared_ptr<VelocityDistributionFunction> buildVelocityDistributionFunction(
|
||||
const json_path& path_to_distribution) {
|
||||
if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_distribution, {"IsotropicDistribution"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Creating velocity distribution function: IsotropicDistribution");
|
||||
#endif
|
||||
std::shared_ptr<EnergyDistributionFunction> fE =
|
||||
buildEnergyDistributionFunction(
|
||||
parameter, json_path_append(path_to_distribution,
|
||||
@@ -26,8 +28,10 @@ std::shared_ptr<VelocityDistributionFunction> buildVelocityDistributionFunction(
|
||||
|
||||
} else if (parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_distribution, {"DirectedDistribution"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Creating velocity distribution function: DirectedDistribution");
|
||||
#endif
|
||||
std::shared_ptr<EnergyDistributionFunction> fE =
|
||||
buildEnergyDistributionFunction(
|
||||
parameter, json_path_append(path_to_distribution,
|
||||
|
||||
@@ -10,8 +10,10 @@ std::shared_ptr<VelocityDistribution> buildVelocityDistribution(
|
||||
const json_path& path_to_distribution) {
|
||||
if (parameter.jsonObjectFromBase(json_path_append(
|
||||
path_to_distribution, {"VelocityDistributionFromFunction"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2(
|
||||
"Creating velocity distribution: VelocityDistributionFromFunction");
|
||||
#endif
|
||||
std::shared_ptr<VelocityDistributionFunction> v =
|
||||
buildVelocityDistributionFunction(
|
||||
parameter, json_path_append(path_to_distribution,
|
||||
@@ -21,7 +23,9 @@ std::shared_ptr<VelocityDistribution> buildVelocityDistribution(
|
||||
new VelocityDistributionFromFunction(v));
|
||||
} else if (parameter.jsonObjectFromBase(
|
||||
json_path_append(path_to_distribution, {"null"}))) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Creating velocity distribution: null");
|
||||
#endif
|
||||
return nullptr;
|
||||
} else {
|
||||
ERROR("This velocity distribution is not implemented.");
|
||||
|
||||
@@ -13,16 +13,18 @@ ChargeExchange::ChargeExchange(std::function<double(double)> cross_section,
|
||||
InteractionOutput ChargeExchange::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform charge exchange.");
|
||||
#endif
|
||||
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
// const auto x_impact = particle.position();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
|
||||
particle.velocity(CartesianVector(v_target));
|
||||
particle.velocity(CartesianVector(target_velocity_));
|
||||
return InteractionOutput();
|
||||
}
|
||||
};
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "simulation/logger.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
#include "constants/physical_constants.h"
|
||||
#include "simulation/density_field.h"
|
||||
|
||||
namespace interaction {
|
||||
|
||||
@@ -17,21 +18,33 @@ ClusterFormation::ClusterFormation(
|
||||
InteractionOutput ClusterFormation::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform cluster formation.");
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
#endif
|
||||
const auto x_impact = particle.cartesianPosition();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
/*****************************************************************************
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(v_target, target_->mass_kg()) *
|
||||
kinematic::kineticEnergy(target_velocity_.cartesianEntries(), target_->mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
const blitz::TinyVector<double, 3> v_cluster =
|
||||
kinematic::velocity(energy_eV, product_->mass_kg()) *
|
||||
v_target / kinematic::norm(v_target);
|
||||
target_velocity_.cartesianEntries() / kinematic::norm(target_velocity_.cartesianEntries());
|
||||
// product inherits weight of the main particle (not the target, which is
|
||||
// assumed to be just a density, i.e. has no weight of its own)
|
||||
********************************************************************************/
|
||||
|
||||
// neglect the momentum of the photon -> the cluster moves with the CoM velocity
|
||||
// after the collision
|
||||
blitz::TinyVector<double, 3> v_cluster =
|
||||
(particle.mass_kg()*particle.velocity().cartesianEntries() +
|
||||
target_->mass_kg()*target_velocity_.cartesianEntries()) /
|
||||
(particle.mass_kg() + target_->mass_kg());
|
||||
|
||||
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster),
|
||||
particle.timeAlive(), particle.weight());
|
||||
|
||||
@@ -47,4 +60,110 @@ InteractionOutput ClusterFormation::performInteraction(
|
||||
return output;
|
||||
}
|
||||
|
||||
ClusterFormationTertiary::ClusterFormationTertiary(
|
||||
std::function<double(double)> cross_section,
|
||||
std::shared_ptr<species::Specie> target,
|
||||
std::shared_ptr<species::TrackedSpecie> product,
|
||||
bool rate_coefficient) :
|
||||
ClusterFormation(cross_section, target, product), rate_coefficient_(rate_coefficient) {}
|
||||
|
||||
double ClusterFormationTertiary::microscopicCrossSection(double energy_eV,
|
||||
const Coordinate& position) {
|
||||
// SIM_INFO("Tertiary cross section.");
|
||||
if(!rate_coefficient_) {
|
||||
return cross_section_(energy_eV);
|
||||
}
|
||||
const double rate_over_velocity = cross_section_(energy_eV);
|
||||
auto density = target_->densityField()->density(position);
|
||||
return rate_over_velocity * density;
|
||||
}
|
||||
|
||||
InteractionOutput ClusterFormationTertiary::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform cluster formation.");
|
||||
#endif
|
||||
const auto x_impact = particle.cartesianPosition();
|
||||
/******************************************************************
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(target_velocity_.cartesianEntries(), target_->mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
const blitz::TinyVector<double, 3> v_cluster =
|
||||
kinematic::velocity(energy_eV, product_->mass_kg()) *
|
||||
target_velocity_.cartesianEntries() / kinematic::norm(target_velocity_.cartesianEntries());
|
||||
// product inherits weight of the main particle (not the target, which is
|
||||
// assumed to be just a density, i.e. has no weight of its own)
|
||||
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster),
|
||||
particle.timeAlive(), particle.weight());
|
||||
*****************************************************************/
|
||||
|
||||
// strictly speaking only correct for the reaction T2+ + T2 -> T3+ + T
|
||||
// (otherwise missing momentum component of actual third body)
|
||||
blitz::TinyVector<double, 3> v_com = particle.mass_kg()*particle.velocity().cartesianEntries() +
|
||||
target_->mass_kg()*target_velocity_.cartesianEntries();
|
||||
|
||||
double E0_com = 0;
|
||||
double total_mass = target_->mass_kg() + particle.mass_kg();
|
||||
|
||||
// differentiate between T+ + 2T2 and T2+ + T2 (probably not ideal if new types
|
||||
// were to be implemented)
|
||||
if(particle.specie()->type() == species::ImplementedSpecies::Tplus &&
|
||||
target_->type() == species::ImplementedSpecies::T2) {
|
||||
// ignore any bulk movement of third interaction partner
|
||||
blitz::TinyVector<double, 3> v3 = target_->velocityDistribution()
|
||||
->rollVelocity(x_impact, generator->engine()).cartesianEntries();
|
||||
total_mass += target_->mass_kg();
|
||||
v_com += target_->mass_kg()*v3;
|
||||
v_com /= particle.mass_kg() + 2*target_->mass_kg();
|
||||
E0_com += 0.5*target_->mass_kg()*blitz::dot(v3 - v_com, v3 - v_com);
|
||||
} else {
|
||||
v_com /= total_mass;
|
||||
}
|
||||
blitz::TinyVector<double, 3> vi_com = particle.velocity().cartesianEntries() - v_com;
|
||||
blitz::TinyVector<double, 3> vt_com = target_velocity_.cartesianEntries() - v_com;
|
||||
|
||||
E0_com += 0.5*particle.mass_kg()*blitz::dot(vi_com, vi_com) +
|
||||
0.5*target_->mass_kg()*blitz::dot(vt_com, vt_com);
|
||||
|
||||
double cluster_mass = product_->mass_kg();
|
||||
double rest_mass = total_mass - cluster_mass;
|
||||
double reduced_mass = 1/(1/cluster_mass + 1/rest_mass);
|
||||
|
||||
// momentum of the scattered particles in the CoM frame
|
||||
double norm_pnew_com = std::sqrt(2*reduced_mass*E0_com);
|
||||
|
||||
double phi = generator->rollUniform(0,1)*M_PI*2;
|
||||
double theta = std::acos(1 - 2*generator->rollUniform(0,1));
|
||||
|
||||
// assume isotropic distribution of the scattered momenta in the CoM frame
|
||||
// (removes the need to rotate wrt the incoming velocity)
|
||||
// if a more general approach is needed, use the same calculation as in elastic scattering
|
||||
|
||||
blitz::TinyVector<double, 3> p_cluster_com(std::sin(theta)*std::cos(phi),
|
||||
std::sin(theta)*std::sin(phi),
|
||||
std::cos(theta));
|
||||
p_cluster_com *= norm_pnew_com;
|
||||
blitz::TinyVector<double, 3> v_cluster = (p_cluster_com/cluster_mass) + v_com;
|
||||
|
||||
particle::Particle cluster(product_, x_impact, CartesianVector(v_cluster),
|
||||
particle.timeAlive(), particle.weight());
|
||||
|
||||
InteractionOutput output;
|
||||
output.add(cluster);
|
||||
output.deleteCurrentParticle(true);
|
||||
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(
|
||||
x_impact, DeletionType::cluster_formation);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
} // namespace interaction
|
||||
|
||||
@@ -28,14 +28,20 @@ std::function<double(double, double)> eT2_ionization_bed() {
|
||||
} else {
|
||||
const double t = impact_energy / ionization_energy;
|
||||
const double w = energy_after_collision / ionization_energy;
|
||||
|
||||
double y = 1 / (w + 1);
|
||||
double ysq = y*y;
|
||||
double invtmw = 1. / (t - w);
|
||||
|
||||
const double factor = S_m2 / ionization_energy / (t + u + 1);
|
||||
const double summand_1 =
|
||||
(Ni / N - 2) / (t + 1) * (1 / (w + 1) + 1 / (t - w));
|
||||
(Ni / N - 2) / (t + 1) * (y + invtmw);
|
||||
const double summand_2 =
|
||||
(2 - Ni / N) * (std::pow(w + 1, -2) + std::pow(t - w, -2));
|
||||
double y = 1 / (w + 1);
|
||||
const double dfdw = c[0] * std::pow(y, 3) + c[1] * std::pow(y, 4) +
|
||||
c[2] * std::pow(y, 5) + c[3] * std::pow(y, 6);
|
||||
(2 - Ni / N) * (ysq + invtmw*invtmw);
|
||||
|
||||
// const double dfdw = c[0] * std::pow(y, 3) + c[1] * std::pow(y, 4) +
|
||||
// c[2] * std::pow(y, 5) + c[3] * std::pow(y, 6);
|
||||
const double dfdw = ysq*(y*c[0] + ysq*(c[1] + y*(c[2] + y*c[3])));
|
||||
const double summand_3 = std::log(t) / (N * (w + 1)) * dfdw;
|
||||
return factor * (summand_1 + summand_2 + summand_3);
|
||||
}
|
||||
@@ -57,14 +63,20 @@ std::function<double(double, double)> eT_ionization_bed() {
|
||||
} else {
|
||||
const double t = impact_energy / ionization_energy;
|
||||
const double w = energy_after_collision / ionization_energy;
|
||||
|
||||
double y = 1 / (w + 1);
|
||||
double ysq = y*y;
|
||||
double invtmw = 1. / (t - w);
|
||||
|
||||
const double factor = S_m2 / ionization_energy / (t + u + 1);
|
||||
const double summand_1 =
|
||||
(Ni / N - 2) / (t + 1) * (1 / (w + 1) + 1 / (t - w));
|
||||
(Ni / N - 2) / (t + 1) * (y + invtmw);
|
||||
const double summand_2 =
|
||||
(2 - Ni / N) * (std::pow(w + 1, -2) + std::pow(t - w, -2));
|
||||
double y = 1 / (w + 1);
|
||||
const double dfdw = c[0] * std::pow(y, 2) + c[1] * std::pow(y, 3) +
|
||||
c[2] * std::pow(y, 4) + c[3] * std::pow(y, 5);
|
||||
(2 - Ni / N) * (ysq + invtmw*invtmw);
|
||||
|
||||
// const double dfdw = c[0] * std::pow(y, 2) + c[1] * std::pow(y, 3) +
|
||||
// c[2] * std::pow(y, 4) + c[3] * std::pow(y, 5);
|
||||
const double dfdw = ysq * (c[0] + y*(c[1] + y*(c[2] + y*c[3])));
|
||||
const double summand_3 = std::log(t) / (N * (w + 1)) * dfdw;
|
||||
return factor * (summand_1 + summand_2 + summand_3);
|
||||
}
|
||||
@@ -161,7 +173,8 @@ std::function<double(double)> eT_elastic_scattering() {
|
||||
std::function<double(double)> T2pT2_charge_exchange_janev() {
|
||||
return [=](double energy) {
|
||||
const double sig_ll =
|
||||
6.59 / (std::pow(energy, 0.5) * (1 + 2.29 * std::pow(energy, 1.78))) +
|
||||
// 6.59 / (std::pow(energy, 0.5) * (1 + 2.29 * std::pow(energy, 1.78))) +
|
||||
6.59 / (std::sqrt(energy) * (1 + 2.29 * std::pow(energy, 1.78))) +
|
||||
12.85 * std::exp(-1.84 * std::pow(energy, -1.55)) /
|
||||
(std::pow(energy, 0.0673) * (1 + 2.6E-3 * std::pow(energy, 0.97) +
|
||||
1.63E-10 * std::pow(energy, 2.76)));
|
||||
@@ -196,9 +209,13 @@ std::function<double(double)> eT2_ionization_bed() {
|
||||
const double t = energy / ionization_energy;
|
||||
const double factor = S_m2 / (t + u + 1);
|
||||
const double yh = 2. / (t + 1);
|
||||
const double yh2 = yh*yh;
|
||||
// const double D =
|
||||
// c[0] / 3 * (1 - std::pow(yh, 3)) + c[1] / 4 * (1 - std::pow(yh, 4)) +
|
||||
// c[2] / 5 * (1 - std::pow(yh, 5)) + c[3] / 6 * (1 - std::pow(yh, 6));
|
||||
const double D =
|
||||
c[0] / 3 * (1 - std::pow(yh, 3)) + c[1] / 4 * (1 - std::pow(yh, 4)) +
|
||||
c[2] / 5 * (1 - std::pow(yh, 5)) + c[3] / 6 * (1 - std::pow(yh, 6));
|
||||
(c[0]/3 + c[1]/4 + c[2]/5 + c[3]/6) -
|
||||
yh2 * (yh*(c[0]/3 + c[2]/5 * yh2) + yh2 * (c[1]/4 + c[3]/6 * yh2));
|
||||
const double summand_1 = D * std::log(t);
|
||||
const double summand_2 =
|
||||
(2 - Ni / N) * ((t - 1) / t - std::log(t) / (t + 1));
|
||||
@@ -560,8 +577,12 @@ std::function<double(double)> eT2_excitation_vibrational_janev_first() {
|
||||
return 0.;
|
||||
}
|
||||
const double rel = energy / deltaE_eV;
|
||||
return 5.78 * std::pow(deltaE_eV, -4) * std::pow(rel, -2) *
|
||||
std::pow(1 - 1 / rel, 6.11 * std::pow(deltaE_eV, -0.5)) * 1E-20;
|
||||
// return 5.78 * std::pow(deltaE_eV, -4) * std::pow(rel, -2) *
|
||||
// std::pow(1 - 1 / rel, 6.11 * std::pow(deltaE_eV, -0.5)) * 1E-20;
|
||||
// change calculation of deltaE_eV^{-4} to a simple constant? (don't know
|
||||
// it the compiler already changes that)
|
||||
return 5.78 * std::pow(deltaE_eV, -4) * 1/(rel*rel) *
|
||||
std::pow(1 - 1 / rel, 6.11 / std::sqrt(deltaE_eV)) * 1E-20;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -572,8 +593,11 @@ std::function<double(double)> eT2_excitation_vibrational_janev_second() {
|
||||
return 0.;
|
||||
}
|
||||
const double rel = energy / deltaE_eV;
|
||||
return 5.78 * 0.628 * std::pow(deltaE_eV, -4) * std::pow(rel, -2) *
|
||||
std::pow(1 - 1 / rel, 6.11 * std::pow(deltaE_eV, -0.5)) * 1E-20;
|
||||
// return 5.78 * 0.628 * std::pow(deltaE_eV, -4) * std::pow(rel, -2) *
|
||||
// std::pow(1 - 1 / rel, 6.11 * std::pow(deltaE_eV, -0.5)) * 1E-20;
|
||||
// same comment as for the function above
|
||||
return 5.78 * 0.628 * std::pow(deltaE_eV, -4) / (rel*rel) *
|
||||
std::pow(1 - 1 / rel, 6.11 / std::sqrt(deltaE_eV)) * 1E-20;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -628,7 +652,8 @@ std::function<double(double)> eT2p_recombination_janev() {
|
||||
(1 + 1.1 * std::pow(energy, 0.512) +
|
||||
0.011 * std::pow(energy, 3.10)),
|
||||
-1) +
|
||||
0.133 * std::exp(-0.35 * std::pow(energy - 6.05, 2)));
|
||||
// 0.133 * std::exp(-0.35 * std::pow(energy - 6.05, 2)));
|
||||
0.133 * std::exp(-0.35 * (energy - 6.05)*(energy - 6.05)));
|
||||
};
|
||||
}
|
||||
std::function<double(double)> eT3p_recombination_janev() {
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
#include "simulation/kinematic.h"
|
||||
#include "simulation/scattering_angle_distribution.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
|
||||
#include "constants/sim_constants.h"
|
||||
#include "simulation/density_field.h"
|
||||
namespace interaction {
|
||||
|
||||
ElasticScattering::ElasticScattering(
|
||||
@@ -18,18 +19,21 @@ ElasticScattering::ElasticScattering(
|
||||
InteractionOutput ElasticScattering::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform elastic scattering.");
|
||||
#endif
|
||||
const blitz::TinyVector<double, 3> v_impact =
|
||||
particle.velocity().cartesianEntries();
|
||||
const auto x_impact = particle.position();
|
||||
const blitz::TinyVector<double, 3> v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
// const auto x_impact = particle.position();
|
||||
// const blitz::TinyVector<double, 3> v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
|
||||
const blitz::TinyVector<double, 3> v_laboratory =
|
||||
kinematic::velocityTargetFixed(v_impact, v_target, particle.mass_kg(),
|
||||
kinematic::velocityTargetFixed(v_impact, target_velocity_.cartesianEntries(),
|
||||
particle.mass_kg(),
|
||||
target_->mass_kg());
|
||||
|
||||
const double E_kin =
|
||||
@@ -41,13 +45,85 @@ InteractionOutput ElasticScattering::performInteraction(
|
||||
|
||||
const blitz::TinyVector<double, 3> v_impact_new =
|
||||
kinematic::rotateVelocityInCenterOfMassFrame(
|
||||
v_impact, v_target, particle.mass_kg(), target_->mass_kg(), theta,
|
||||
phi);
|
||||
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(),
|
||||
target_->mass_kg(), theta, phi);
|
||||
|
||||
particle.velocity(CartesianVector(v_impact_new));
|
||||
// no Gyrocentrum movement because boris push is used;
|
||||
|
||||
return InteractionOutput();
|
||||
}
|
||||
|
||||
double ElasticScattering::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
CartesianVector particle_velocity = particle.velocity();
|
||||
|
||||
target_velocity_ = target_->velocityDistribution()->
|
||||
rollVelocity(particle.cylinderPosition(),
|
||||
generator->engine());
|
||||
|
||||
// // if no drift velocity is present, then assume target at rest otherwise
|
||||
// // use the drift velocity
|
||||
if(target_->driftVelocity()) {
|
||||
// auto tmp = target_->driftVelocity()->driftVelocity(particle.position());
|
||||
target_velocity_.add(target_->driftVelocity()->driftVelocity(
|
||||
particle.cartesianPosition(), particle.cylinderPosition()),
|
||||
particle.cartesianPosition());
|
||||
}
|
||||
|
||||
// masses are irrelevant for the transformation
|
||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
|
||||
target_velocity_.cartesianEntries(), 0, 0);
|
||||
|
||||
const double relative_velocity = kinematic::norm(velocity_target_fixed);
|
||||
|
||||
// std::stringstream out;
|
||||
// out << "particle "<< particle.specie()->name() <<" velocity: "
|
||||
// << particle_velocity.cartesianEntries();
|
||||
// out << "\ntarget "<< target_->name() <<" velocity: "
|
||||
// << target_velocity_.cartesianEntries();
|
||||
// out << "\nabsolute relative velocity: " << relative_velocity;
|
||||
|
||||
// check if the relative velocity is smaller than an epsilon compared to the larger
|
||||
// of the two present velocities (to avoid division by 0 if either is 0) probably
|
||||
// a better version possible
|
||||
if(relative_velocity/std::max(
|
||||
kinematic::norm(particle_velocity.cartesianEntries()),
|
||||
kinematic::norm(target_velocity_.cartesianEntries())
|
||||
) < SimConstants::compare_epsilon) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
||||
UnitConversion::JouleToeV;
|
||||
|
||||
// out << "energy collision time: " << energy_eV;
|
||||
|
||||
const double crosssection = microscopicCrossSection(energy_eV,
|
||||
particle.cylinderPosition());
|
||||
// out << "\ncross section: " << crosssection;
|
||||
const double density = target_->densityField()->density(particle.cylinderPosition());
|
||||
|
||||
// out << "\ninverse mfp: " << crosssection*density << ", sigma: " << crosssection;
|
||||
// out << ", density: " << density;
|
||||
|
||||
const double random_number = generator->rollUniform(0.,1.);
|
||||
if (random_number == 0) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double distance_target_fixed =
|
||||
- 1./(crosssection * density) * log(random_number);
|
||||
|
||||
// out << "\ndistance in target fixed frame: " << distance_target_fixed;
|
||||
|
||||
const double time = distance_target_fixed / relative_velocity;
|
||||
// out << "\ntime before collision: " << time;
|
||||
// if(density != 0)
|
||||
// DEBUG_LEVEL_1(out.str());
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
}; // namespace interaction
|
||||
@@ -18,7 +18,9 @@ Excitation::Excitation(std::function<double(double)> cross_section,
|
||||
|
||||
InteractionOutput Excitation::performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform excitation.");
|
||||
#endif
|
||||
const blitz::TinyVector<double, 3> v_impact =
|
||||
particle.velocity().cartesianEntries();
|
||||
const blitz::TinyVector<double, 3> n_impact =
|
||||
|
||||
@@ -10,12 +10,15 @@ FreeMovement::FreeMovement()
|
||||
|
||||
InteractionOutput FreeMovement::performInteraction(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform free movement.");
|
||||
#endif
|
||||
// do nothing
|
||||
return InteractionOutput();
|
||||
}
|
||||
|
||||
double FreeMovement::microscopicCrossSection(double energy_eV) {
|
||||
double FreeMovement::microscopicCrossSection(double energy_eV,
|
||||
const Coordinate& position) {
|
||||
// returns very small number
|
||||
return SimConstants::minimal_cross_section;
|
||||
}
|
||||
@@ -23,4 +26,8 @@ double FreeMovement::macroscopicCrossSection(particle::Particle& particle) {
|
||||
// returns a very small number, so the interaction will only be
|
||||
return SimConstants::minimal_macroscopic_cross_section;
|
||||
}
|
||||
double FreeMovement::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
}; // namespace interaction
|
||||
@@ -29,28 +29,48 @@ ElectronIonization::ElectronIonization(
|
||||
InteractionOutput ElectronIonization::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform ionization.");
|
||||
#endif
|
||||
|
||||
const blitz::TinyVector<double, 3> v_impact =
|
||||
particle.velocity().cartesianEntries();
|
||||
const auto x_impact = particle.position();
|
||||
const auto x_impact = particle.cartesianPosition();
|
||||
|
||||
blitz::TinyVector<double, 3> v_target;
|
||||
blitz::TinyVector<double, 3> v_laboratory;
|
||||
double E_impact;
|
||||
do {
|
||||
v_target =
|
||||
target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
target_->velocityDistibution()
|
||||
->rollVelocity(x_impact, generator->engine())
|
||||
.cartesianEntries();
|
||||
blitz::TinyVector<double, 3> v_target = target_->velocityDistribution()->
|
||||
rollVelocity(particle.cylinderPosition(),
|
||||
generator->engine()).cartesianEntries();
|
||||
if(target_->driftVelocity()) {
|
||||
v_target += target_->driftVelocity()
|
||||
->driftVelocity(x_impact, particle.cylinderPosition())
|
||||
.cartesianEntries();
|
||||
}
|
||||
|
||||
v_laboratory = kinematic::velocityTargetFixed(
|
||||
v_impact, v_target, particle.mass_kg(), target_->mass_kg());
|
||||
// don't think is quite right, since there is no energy transfer to the ion,
|
||||
// and in the case of a dissociative event, the energy of the parent particle
|
||||
// is split between the child particles -> no rescaling required, since
|
||||
// the neutral child particle also carries some of the energy
|
||||
// v_target *= std::sqrt(target_->mass_kg()/ion_->mass_kg());
|
||||
|
||||
E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
} while (E_impact <= ionization_energy_eV_);
|
||||
blitz::TinyVector<double, 3> v_laboratory = kinematic::velocityTargetFixed(
|
||||
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(), target_->mass_kg()
|
||||
);
|
||||
|
||||
double E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
// do {
|
||||
// v_target =
|
||||
// target_->driftVelocity()->driftVelocity(x_impact).cartesianEntries() +
|
||||
// target_->velocityDistribution()
|
||||
// ->rollVelocity(x_impact, generator->engine())
|
||||
// .cartesianEntries();
|
||||
|
||||
// v_laboratory = kinematic::velocityTargetFixed(
|
||||
// v_impact, v_target, particle.mass_kg(), target_->mass_kg());
|
||||
|
||||
// E_impact = kinematic::kineticEnergy(v_laboratory, particle.mass_kg()) *
|
||||
// UnitConversion::JouleToeV;
|
||||
// } while (E_impact <= ionization_energy_eV_);
|
||||
|
||||
const double E_impact_new =
|
||||
energy_distribution_->rollImpactParticleEnergyAfterCollision(E_impact,
|
||||
@@ -66,7 +86,7 @@ InteractionOutput ElectronIonization::performInteraction(
|
||||
|
||||
const double azimuth_angle_impact_new =
|
||||
angle_distribution_->rollAzimuthImpactParticleAfterCollision(
|
||||
E_impact, E_impact_new, generator);
|
||||
E_impact, E_ejected, generator);
|
||||
const double azimuth_angle_ejected =
|
||||
angle_distribution_->rollAzimuthEjectedParticleAfterCollision(
|
||||
E_impact, E_ejected, generator);
|
||||
@@ -83,13 +103,13 @@ InteractionOutput ElectronIonization::performInteraction(
|
||||
kinematic::rotateVector(v_lab_norm, azimuth_angle_impact_new,
|
||||
polar_angle_impact_new) *
|
||||
v_lab_impact_new +
|
||||
v_target;
|
||||
target_velocity_.cartesianEntries();
|
||||
|
||||
const blitz::TinyVector<double, 3> v_ejected =
|
||||
kinematic::rotateVector(v_lab_norm, azimuth_angle_ejected,
|
||||
polar_angle_ejected) *
|
||||
v_lab_ejected +
|
||||
v_target;
|
||||
target_velocity_.cartesianEntries();
|
||||
|
||||
particle.velocity(v_impact_new);
|
||||
|
||||
@@ -119,7 +139,7 @@ double IonizationEnergyDistribution::rollImpactParticleEnergyAfterCollision(
|
||||
// using rejection method:
|
||||
// assuming cross section is highest at smallest numbers
|
||||
const double energy_after_min = SimConstants::random_lower_limit;
|
||||
const double energy_after_max = impact_energy - ionization_energy_eV_;
|
||||
const double energy_after_max = impact_energy - ionization_energy_eV_; // probably multiply by 0.5
|
||||
const double cross_section_min = 0;
|
||||
const double cross_section_max =
|
||||
d2_cross_section_(impact_energy, energy_after_min);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "constants/physical_constants.h"
|
||||
#include "simulation/drift_velocity.h"
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
|
||||
namespace interaction {
|
||||
|
||||
@@ -17,105 +18,107 @@ Recombination::Recombination(std::function<double(double)> cross_section,
|
||||
InteractionOutput Recombination::performInteraction(
|
||||
particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform recombination.");
|
||||
#endif
|
||||
|
||||
std::vector<double> macroscopic_bin_cross_sections_m;
|
||||
const int number_energy_bins = recombination_target_->dynamicDensityField()
|
||||
->energyBinning()->binIndexMax();
|
||||
std::vector<double> energyBinBorders = recombination_target_->
|
||||
dynamicDensityField()->energyBinning()->binBorders();
|
||||
// std::vector<double> macroscopic_bin_cross_sections_m;
|
||||
// const int number_energy_bins = recombination_target_->dynamicDensityField()
|
||||
// ->energyBinning()->binIndexMax();
|
||||
// std::vector<double> energyBinBorders = recombination_target_->
|
||||
// dynamicDensityField()->energyBinning()->binBorders();
|
||||
|
||||
if(recombination_target_->type() == species::ImplementedSpecies::electron) {
|
||||
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||||
macroscopic_bin_cross_sections_m.push_back(
|
||||
macroscopicCrossSection(particle.position(), bin));
|
||||
}
|
||||
} else {
|
||||
const blitz::TinyVector<double, 3> v_particle =
|
||||
particle.velocity().cartesianEntries();
|
||||
// if(recombination_target_->type() == species::ImplementedSpecies::electron) {
|
||||
// for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||||
// macroscopic_bin_cross_sections_m.push_back(
|
||||
// macroscopicCrossSection(particle.position(), bin));
|
||||
// }
|
||||
// } else {
|
||||
// const blitz::TinyVector<double, 3> v_particle =
|
||||
// particle.velocity().cartesianEntries();
|
||||
|
||||
if(!recombination_target_->driftVelocity()) {
|
||||
ERROR(recombination_target_->name() + ": does not have a drift velocity!");
|
||||
}
|
||||
// if(!recombination_target_->driftVelocity()) {
|
||||
// ERROR(recombination_target_->name() + ": does not have a drift velocity!");
|
||||
// }
|
||||
|
||||
const blitz::TinyVector<double, 3> v_partner =
|
||||
recombination_target_->driftVelocity()
|
||||
->driftVelocity(particle.position()).cartesianEntries();
|
||||
// const blitz::TinyVector<double, 3> v_partner =
|
||||
// recombination_target_->driftVelocity()
|
||||
// ->driftVelocity(particle.position()).cartesianEntries();
|
||||
|
||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
kinematic::velocityTargetFixed(v_particle, v_partner, particle.mass_kg(),
|
||||
recombination_target_->mass_kg());
|
||||
// const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
// kinematic::velocityTargetFixed(v_particle, v_partner, particle.mass_kg(),
|
||||
// recombination_target_->mass_kg());
|
||||
|
||||
const double kinetic_energy_eV =
|
||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg()) *
|
||||
UnitConversion::JouleToeV;
|
||||
// const double kinetic_energy_eV =
|
||||
// kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg()) *
|
||||
// UnitConversion::JouleToeV;
|
||||
|
||||
|
||||
double energy_eV_bin_center;
|
||||
for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||||
energy_eV_bin_center = (energyBinBorders[bin] + energyBinBorders[bin+1])/2.;
|
||||
macroscopic_bin_cross_sections_m.push_back(
|
||||
microscopicCrossSection(kinetic_energy_eV) *
|
||||
recombination_target_->dynamicDensityField()
|
||||
->density(particle.position(), energy_eV_bin_center));
|
||||
}
|
||||
}
|
||||
// double energy_eV_bin_center;
|
||||
// for (int bin = 0; bin < number_energy_bins - 1; ++bin) {
|
||||
// energy_eV_bin_center = (energyBinBorders[bin] + energyBinBorders[bin+1])/2.;
|
||||
// macroscopic_bin_cross_sections_m.push_back(
|
||||
// microscopicCrossSection(kinetic_energy_eV) *
|
||||
// recombination_target_->dynamicDensityField()
|
||||
// ->density(particle.position(), energy_eV_bin_center));
|
||||
// }
|
||||
// }
|
||||
|
||||
const double total_macroscopic_cross_section_m =
|
||||
std::accumulate(macroscopic_bin_cross_sections_m.begin(),
|
||||
macroscopic_bin_cross_sections_m.end(), 0.0);
|
||||
// const double total_macroscopic_cross_section_m =
|
||||
// std::accumulate(macroscopic_bin_cross_sections_m.begin(),
|
||||
// macroscopic_bin_cross_sections_m.end(), 0.0);
|
||||
|
||||
if(total_macroscopic_cross_section_m <= 0.) {
|
||||
ERROR("Total cross section is " +
|
||||
std::to_string(total_macroscopic_cross_section_m) +
|
||||
". But recombination was chosen.");
|
||||
}
|
||||
// if(total_macroscopic_cross_section_m <= 0.) {
|
||||
// ERROR("Total cross section is " +
|
||||
// std::to_string(total_macroscopic_cross_section_m) +
|
||||
// ". But recombination was chosen.");
|
||||
// }
|
||||
|
||||
std::discrete_distribution<int> energy_bin_decider(
|
||||
macroscopic_bin_cross_sections_m.begin(),
|
||||
macroscopic_bin_cross_sections_m.end());
|
||||
// std::discrete_distribution<int> energy_bin_decider(
|
||||
// macroscopic_bin_cross_sections_m.begin(),
|
||||
// macroscopic_bin_cross_sections_m.end());
|
||||
|
||||
const int energy_bin = energy_bin_decider(*(generator->engine()));
|
||||
const double energy_eV = (energyBinBorders[energy_bin] +
|
||||
energyBinBorders[energy_bin+1]) / 2.;
|
||||
// const int energy_bin = energy_bin_decider(*(generator->engine()));
|
||||
// const double energy_eV = (energyBinBorders[energy_bin] +
|
||||
// energyBinBorders[energy_bin+1]) / 2.;
|
||||
|
||||
blitz::TinyVector<double, 3> position_bins = recombination_target_->dynamicDensityField()
|
||||
->positionBinning()->bin(particle.position().cylinderEntries());
|
||||
// blitz::TinyVector<double, 3> position_bins = recombination_target_->dynamicDensityField()
|
||||
// ->positionBinning()->bin(particle.position().cylinderEntries());
|
||||
|
||||
const blitz::Array<double, 1> mu_distribution =
|
||||
recombination_target_->dynamicDensityField()
|
||||
->timeInBinArray()(position_bins(0),
|
||||
position_bins(1),
|
||||
position_bins(2),
|
||||
blitz::Range::all(),
|
||||
energy_bin);
|
||||
// const blitz::Array<double, 1> mu_distribution =
|
||||
// recombination_target_->dynamicDensityField()
|
||||
// ->timeInBinArray()(position_bins(0),
|
||||
// position_bins(1),
|
||||
// position_bins(2),
|
||||
// blitz::Range::all(),
|
||||
// energy_bin);
|
||||
|
||||
std::vector<double> mu_borders = recombination_target_->dynamicDensityField()
|
||||
->pitchAngleBinning()->binBorders();
|
||||
// std::vector<double> mu_borders = recombination_target_->dynamicDensityField()
|
||||
// ->pitchAngleBinning()->binBorders();
|
||||
|
||||
std::discrete_distribution<int> mu_bin_decider(mu_distribution.begin(),
|
||||
mu_distribution.end());
|
||||
// std::discrete_distribution<int> mu_bin_decider(mu_distribution.begin(),
|
||||
// mu_distribution.end());
|
||||
|
||||
const int mu_bin = mu_bin_decider(*(generator->engine()));
|
||||
// const int mu_bin = mu_bin_decider(*(generator->engine()));
|
||||
|
||||
if((mu_bin == 0) || (mu_bin == mu_distribution.size()-1)) {
|
||||
ERROR("Recombination: drawn mu is from over- or underflow bin!");
|
||||
std::stringstream out;
|
||||
out << "mu distribution values: n";
|
||||
out << mu_distribution;
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
}
|
||||
const double mu = (mu_borders[mu_bin - 1] + mu_borders[mu_bin])/2.;
|
||||
// if((mu_bin == 0) || (mu_bin == mu_distribution.size()-1)) {
|
||||
// ERROR("Recombination: drawn mu is from over- or underflow bin!");
|
||||
// std::stringstream out;
|
||||
// out << "mu distribution values: n";
|
||||
// out << mu_distribution;
|
||||
// DEBUG_LEVEL_3(out.str());
|
||||
// }
|
||||
// const double mu = (mu_borders[mu_bin - 1] + mu_borders[mu_bin])/2.;
|
||||
|
||||
recombination_target_->dynamicDensityField()->logDeletion(particle.position(),
|
||||
energy_eV, mu);
|
||||
// recombination_target_->dynamicDensityField()->logDeletion(particle.position(),
|
||||
// energy_eV, mu);
|
||||
|
||||
InteractionOutput output;
|
||||
output.deleteCurrentParticle(true);
|
||||
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(
|
||||
particle.position(), DeletionType::recombination);
|
||||
particle.cartesianPosition(), DeletionType::recombination);
|
||||
}
|
||||
|
||||
return output;
|
||||
@@ -126,7 +129,7 @@ double Recombination::macroscopicCrossSection(particle::Particle& particle) {
|
||||
const int numBins = recombination_target_->dynamicDensityField()->
|
||||
energyBinning()->binIndexMax();
|
||||
double macroscopic_cross_section = 0.;
|
||||
const auto position = particle.position();
|
||||
const auto position = particle.cylinderPosition();
|
||||
for (int bin = 0; bin < numBins - 1; ++bin) {
|
||||
macroscopic_cross_section += macroscopicCrossSection(position, bin);
|
||||
}
|
||||
@@ -156,11 +159,100 @@ double Recombination::macroscopicCrossSection(const Coordinate& position,
|
||||
//Simpson's rule
|
||||
const double integrated_microscopic_cross_section =
|
||||
(upper_bound - lower_bound)/6. *
|
||||
(microscopicCrossSection(upper_bound) +
|
||||
4*microscopicCrossSection(intermediate_value) +
|
||||
microscopicCrossSection(lower_bound));
|
||||
(microscopicCrossSection(upper_bound, position) +
|
||||
4*microscopicCrossSection(intermediate_value, position) +
|
||||
microscopicCrossSection(lower_bound, position));
|
||||
// assumption, that the differential density is constant within a cell
|
||||
return differential_density_value * integrated_microscopic_cross_section;
|
||||
}
|
||||
|
||||
double Recombination::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
CartesianVector particle_velocity = particle.velocity();
|
||||
// const double density = target_->densityField()->density(particle.cylinderPosition());
|
||||
// Use the density for drawing field, since it contains the density of the earlier
|
||||
// timestep
|
||||
const double density = recombination_target_->dynamicDensityField()
|
||||
->density(particle.cylinderPosition());
|
||||
|
||||
// recombination_target_->densityForDrawing()->recalculateDensityArray();
|
||||
// if(density != recombination_target_->densityForDrawing()
|
||||
// ->density(particle.cylinderPosition())) {
|
||||
// ERROR("density changes after recalculation of density array!");
|
||||
// }
|
||||
// density effectively 0
|
||||
if(density <= SimConstants::compare_epsilon) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
// Assumes that B || z, which is obviously not necessarily the case !!!
|
||||
target_velocity_ = recombination_target_->velocityDistributionFromDensityField()
|
||||
->rollVelocity(particle.cylinderPosition(), generator->engine());
|
||||
|
||||
// for testing purposes
|
||||
// target_velocity_ = CartesianVector(blitz::TinyVector<double, 3>(0.,0.,0.));
|
||||
|
||||
// masses are irrelevant for the transformation
|
||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
|
||||
target_velocity_.cartesianEntries(), 0, 0);
|
||||
|
||||
const double relative_velocity = kinematic::norm(velocity_target_fixed);
|
||||
|
||||
// check if the relative velocity is smaller than an epsilon compared to the larger
|
||||
// of the two present velocities (to avoid division by 0 if either is 0) probably
|
||||
// a better version possible
|
||||
if(relative_velocity/std::max(
|
||||
kinematic::norm(particle_velocity.cartesianEntries()),
|
||||
kinematic::norm(target_velocity_.cartesianEntries())
|
||||
) < SimConstants::compare_epsilon) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double energy_eV =
|
||||
(recombination_target_->type() == species::ImplementedSpecies::electron) ?
|
||||
kinematic::kineticEnergy(velocity_target_fixed, recombination_target_->mass_kg())*
|
||||
UnitConversion::JouleToeV :
|
||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
||||
UnitConversion::JouleToeV;
|
||||
|
||||
const double crosssection = microscopicCrossSection(energy_eV,
|
||||
particle.cylinderPosition());
|
||||
|
||||
#if defined(debug)
|
||||
if(density > 0 && std::isnan(crosssection)) {
|
||||
std::stringstream msg;
|
||||
msg << particle.specie()->name() << particle.cartesianPosition().cartesianEntries();
|
||||
msg << " " << recombination_target_->dynamicDensityField()->positionBinning()->bin(particle.cylinderPosition().cylinderEntries());
|
||||
msg << ": Recombination: density is not nan but the cross section is ";
|
||||
msg << density << ", " << crosssection;
|
||||
msg << recombination_target_->dynamicDensityField()->sliceSpectrumArray(particle.cylinderPosition());
|
||||
ERROR(msg.str());
|
||||
}
|
||||
#endif
|
||||
|
||||
const double random_number = generator->rollUniform(0.,1.);
|
||||
if (random_number == 0) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double distance_target_fixed =
|
||||
- 1./(crosssection * density) * log(random_number);
|
||||
|
||||
const double time = distance_target_fixed / relative_velocity;
|
||||
|
||||
|
||||
#ifdef debug_level2
|
||||
std::stringstream out;
|
||||
out << "particle energy: " << particle.kineticEnergy_eV();
|
||||
out << "\ncross section: " << crosssection;
|
||||
out << "\ndensity: " << density;
|
||||
out << "\ntime: " << time;
|
||||
if(density > 0)
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
#endif
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
}; // namespace interaction
|
||||
@@ -22,77 +22,74 @@ PoissonSolver::PoissonSolver(GlobalBoundary bottom_boundary,
|
||||
hull_boundary_(hull_boundary),
|
||||
geometry_(geometry),
|
||||
density_binning_(density_binning),
|
||||
potential_(blitz::Array<PotentialGridPoint, 3>(
|
||||
potential_(blitz::Array<PotentialGridPoint, 2>(
|
||||
blitz::Range(density_binning.binIndexMin()(0),
|
||||
density_binning.binIndexMax()(0)),
|
||||
blitz::Range(density_binning.binIndexMin()(1),
|
||||
density_binning.binIndexMax()(1)), // the azimuthal direction is periodic
|
||||
blitz::Range(density_binning.binIndexMin()(2) + 1,
|
||||
density_binning.binIndexMax()(2)))),
|
||||
blitz::Range(density_binning.binIndexMin()(1) + 1,
|
||||
density_binning.binIndexMax()(1)))),
|
||||
electrodes_(electrodes),
|
||||
target_accuracy_(target_accuracy),
|
||||
num_cycles_(num_cycles),
|
||||
do_solver_(do_solver) {
|
||||
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
blitz::TinyVector<double, 2> stepsize = density_binning_.stepsize();
|
||||
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||
for (int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for (int k = potential_.lbound(2); k <= potential_.ubound(2);
|
||||
++k) {
|
||||
CylinderCoordinate position(blitz::TinyVector<double, 3>(
|
||||
i * stepsize(0), j * stepsize(1), k * stepsize(2)));
|
||||
CylinderCoordinate position(blitz::TinyVector<double, 3>(
|
||||
i * stepsize(0), 0, j * stepsize(1)));
|
||||
|
||||
switch(geometry_->isWhere(position)) {
|
||||
case GeometryPositioning::bottom:
|
||||
potential_(i,j,k) = {bottom_boundary_.type, bottom_boundary_.boundary_value};
|
||||
break;
|
||||
case GeometryPositioning::top:
|
||||
potential_(i,j,k) = {top_boundary_.type, top_boundary_.boundary_value};
|
||||
break;
|
||||
case GeometryPositioning::hull:
|
||||
potential_(i,j,k) = {hull_boundary_.type, hull_boundary_.boundary_value};
|
||||
break;
|
||||
case GeometryPositioning::inside:
|
||||
potential_(i,j,k) = {BoundaryType::no_boundary, 0.};
|
||||
break;
|
||||
default:
|
||||
// include position in output
|
||||
ERROR("Something went terribly wrong. Position is nowhere.");
|
||||
break;
|
||||
}
|
||||
for (auto& electrode : electrodes_) {
|
||||
if (electrode->isOnElectrode(position)) {
|
||||
potential_(i,j,k).type = BoundaryType::dirichlet;
|
||||
potential_(i,j,k).value = electrode->electrodePotential();
|
||||
}
|
||||
switch(geometry_->isWhere(position)) {
|
||||
case GeometryPositioning::bottom:
|
||||
potential_(i,j) = {bottom_boundary_.type, bottom_boundary_.boundary_value};
|
||||
break;
|
||||
case GeometryPositioning::top:
|
||||
potential_(i,j) = {top_boundary_.type, top_boundary_.boundary_value};
|
||||
break;
|
||||
case GeometryPositioning::hull:
|
||||
potential_(i,j) = {hull_boundary_.type, hull_boundary_.boundary_value};
|
||||
break;
|
||||
case GeometryPositioning::inside:
|
||||
potential_(i,j) = {BoundaryType::no_boundary, 0.};
|
||||
break;
|
||||
default:
|
||||
// include position in output
|
||||
ERROR("Something went terribly wrong. Position is nowhere.");
|
||||
break;
|
||||
}
|
||||
for (auto& electrode : electrodes_) {
|
||||
if (electrode->isOnElectrode(position)) {
|
||||
potential_(i,j).type = BoundaryType::dirichlet;
|
||||
potential_(i,j).value = electrode->electrodePotential();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
blitz::Array<double, 3> zero_chargedensity(
|
||||
blitz::Array<double, 2> zero_chargedensity(
|
||||
blitz::Range(density_binning.binIndexMin()(0),
|
||||
density_binning.binIndexMax()(0)),
|
||||
blitz::Range(density_binning.binIndexMin()(1),
|
||||
density_binning.binIndexMax()(1)),
|
||||
blitz::Range(density_binning.binIndexMin()(2),
|
||||
density_binning.binIndexMax()(2)));
|
||||
density_binning.binIndexMax()(1)));
|
||||
zero_chargedensity = 0.;
|
||||
solvePotential(zero_chargedensity, true);
|
||||
solvePotential(zero_chargedensity);
|
||||
}
|
||||
|
||||
void PoissonSolver::solvePotential(
|
||||
const blitz::Array<double, 3> charge_density, const bool solve) {
|
||||
if (!(do_solver_) || !(solve)) {
|
||||
const blitz::Array<double, 2> charge_density) {
|
||||
if (!(do_solver_)) {
|
||||
return;
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Interpolating chargedensity.");
|
||||
blitz::Array<double, 3> interpolated_density =
|
||||
#endif
|
||||
blitz::Array<double, 2> interpolated_density =
|
||||
interpolateDensityToPotentialGrid(charge_density);
|
||||
int it = 1;
|
||||
do {
|
||||
solverIteration(interpolated_density);
|
||||
if (it % 1000 == 0) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Poisson solver, iteration: " + std::to_string(it));
|
||||
#endif
|
||||
if (converged(interpolated_density)) {
|
||||
break;
|
||||
};
|
||||
@@ -102,61 +99,45 @@ void PoissonSolver::solvePotential(
|
||||
}
|
||||
|
||||
void PoissonSolver::solverIteration(
|
||||
const blitz::Array<double, 3>& interpolated_density) {
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
const double dr_sq = std::pow(stepsize(0), 2); // shorthand
|
||||
const double dth_sq = std::pow(stepsize(1), 2); // shorthand
|
||||
const double dz_sq = std::pow(stepsize(2), 2); // shorthand
|
||||
const blitz::Array<double, 2>& interpolated_density) {
|
||||
blitz::TinyVector<double, 2> stepsize = density_binning_.stepsize();
|
||||
const double dr_sq = stepsize(0)*stepsize(0); // shorthand
|
||||
const double dz_sq = stepsize(1)*stepsize(1); // shorthand
|
||||
|
||||
for (int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||
for (int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for (int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) {
|
||||
//rewrite with a switch-case
|
||||
if (potential_(i, j, k).type == BoundaryType::dirichlet) {
|
||||
potential_(i, j, k).value = potential_(i, j, k).value;
|
||||
} else if (potential_(i, j, k).type == BoundaryType::neumann_to_top) {
|
||||
potential_(i, j, k).value = potential_(i, j, k - 1).value
|
||||
+ top_boundary_.boundary_value * stepsize(2);
|
||||
} else if (potential_(i, j, k).type == BoundaryType::neumann_to_bottom) {
|
||||
potential_(i, j, k).value = potential_(i, j, k + 1).value
|
||||
- bottom_boundary_.boundary_value * stepsize(2);
|
||||
} else if (potential_(i, j, k).type == BoundaryType::neumann_to_hull) {
|
||||
potential_(i, j, k).value = potential_(i - 1, j, k).value
|
||||
+ hull_boundary_.boundary_value * stepsize(0);
|
||||
} else if (i == 0) {
|
||||
// special calculation for r=0
|
||||
const int jmirror = (j<potential_.extent(1)/2) ? j+potential_.extent(1)/2
|
||||
: j-potential_.extent(1)/2;
|
||||
const double scaling_factor = 4 / dr_sq + 2 / dz_sq;
|
||||
potential_(i, j, k).value =
|
||||
(1 / scaling_factor) *
|
||||
((2 / dr_sq) * (potential_(i + 1, j, k).value +
|
||||
potential_(i + 1, jmirror, k).value) +
|
||||
(1 / dz_sq) * (potential_(i, j, k + 1).value +
|
||||
potential_(i, j, k - 1).value) +
|
||||
interpolated_density(i, j, k)/SI::eps0);
|
||||
//rewrite with a switch-case
|
||||
if (potential_(i, j).type == BoundaryType::dirichlet) {
|
||||
potential_(i, j).value = potential_(i, j).value;
|
||||
} else if (potential_(i, j).type == BoundaryType::neumann_to_top) {
|
||||
potential_(i, j).value = potential_(i, j-1).value
|
||||
+ top_boundary_.boundary_value * stepsize(1);
|
||||
} else if (potential_(i, j).type == BoundaryType::neumann_to_bottom) {
|
||||
potential_(i, j).value = potential_(i, j + 1).value
|
||||
- bottom_boundary_.boundary_value * stepsize(1);
|
||||
} else if (potential_(i, j).type == BoundaryType::neumann_to_hull) {
|
||||
potential_(i, j).value = potential_(i - 1, j).value
|
||||
+ hull_boundary_.boundary_value * stepsize(0);
|
||||
} else if (i == 0) {
|
||||
// special calculation for r=0
|
||||
const double scaling_factor = 4 / dr_sq + 2 / dz_sq;
|
||||
potential_(i, j).value =
|
||||
(1 / scaling_factor) *
|
||||
((4 / dr_sq) * (potential_(i + 1, j).value) +
|
||||
(1 / dz_sq) * (potential_(i, j + 1).value +
|
||||
potential_(i, j - 1).value) +
|
||||
interpolated_density(i, j)/SI::eps0);
|
||||
|
||||
} else {
|
||||
const int jp1 = j + 1 > potential_.ubound(1)
|
||||
? potential_.lbound(1)
|
||||
: j + 1; // j+1 with periodic guard
|
||||
const int jm1 = j - 1 < potential_.lbound(1)
|
||||
? potential_.ubound(1)
|
||||
: j - 1; // j-1 with periodic guard
|
||||
|
||||
const double scaling_factor = 2 / dr_sq + 2 / dz_sq +
|
||||
2 / (std::pow(i, 2) * dr_sq * dth_sq);
|
||||
} else {
|
||||
const double scaling_factor = 2 / dr_sq + 2 / dz_sq;
|
||||
|
||||
potential_(i, j, k).value =
|
||||
(1 / scaling_factor) *
|
||||
((1 / dr_sq * (1 + 1. / (2. * i))) * potential_(i + 1, j, k).value +
|
||||
(1 / dr_sq * (1 - 1. / (2. * i))) * potential_(i - 1, j, k).value +
|
||||
(1 / (std::pow(i, 2) * dr_sq * dth_sq)) *
|
||||
(potential_(i, jp1, k).value + potential_(i, jm1, k).value) +
|
||||
(1 / dz_sq) * (potential_(i, j, k + 1).value +
|
||||
potential_(i, j, k - 1).value) +
|
||||
interpolated_density(i, j, k)/SI::eps0);
|
||||
}
|
||||
potential_(i, j).value =
|
||||
(1 / scaling_factor) *
|
||||
((1 / dr_sq * (1 + 1. / (2. * i))) * potential_(i + 1, j).value +
|
||||
(1 / dr_sq * (1 - 1. / (2. * i))) * potential_(i - 1, j).value +
|
||||
(1 / dz_sq) * (potential_(i, j + 1).value +
|
||||
potential_(i, j - 1).value) +
|
||||
interpolated_density(i, j)/SI::eps0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,11 +146,10 @@ void PoissonSolver::solverIteration(
|
||||
//as of now does not check for inner cells with dirichlet or neumann
|
||||
//boundary, probably needs to be added (or the "electrodes" removed)
|
||||
bool PoissonSolver::converged(
|
||||
const blitz::Array<double, 3>& interpolated_density) {
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
const double dr_sq = std::pow(stepsize(0), 2); // shorthand
|
||||
const double dth_sq = std::pow(stepsize(1), 2); // shorthand
|
||||
const double dz_sq = std::pow(stepsize(2), 2); // shorthand
|
||||
const blitz::Array<double, 2>& interpolated_density) {
|
||||
blitz::TinyVector<double, 2> stepsize = density_binning_.stepsize();
|
||||
const double dr_sq = stepsize(0)*stepsize(0); // shorthand
|
||||
const double dz_sq = stepsize(1)*stepsize(1); // shorthand
|
||||
|
||||
double cumulated_quadradic_difference = 0.;
|
||||
double normalized_difference = 0.;
|
||||
@@ -177,104 +157,88 @@ bool PoissonSolver::converged(
|
||||
|
||||
for (int i = potential_.lbound(0); i < potential_.ubound(0); ++i) {
|
||||
for (int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for (int k = potential_.lbound(2) + 1; k <= potential_.ubound(2) - 1;
|
||||
++k) {
|
||||
if(potential_(i,j,k).type != BoundaryType::no_boundary) {
|
||||
continue;
|
||||
if(potential_(i,j).type != BoundaryType::no_boundary) {
|
||||
continue;
|
||||
}
|
||||
if (i == 0) {
|
||||
// special calculation for r=0
|
||||
const double difference = interpolated_density(i,j)/SI::eps0 +
|
||||
4*(potential_(i+1,j).value - potential_(i,j).value)/dr_sq +
|
||||
(potential_(i,j+1).value - 2*potential_(i,j).value +
|
||||
potential_(i,j-1).value)/dz_sq;
|
||||
|
||||
cumulated_quadradic_difference += difference*difference;
|
||||
|
||||
if(fabs(difference) > maximum_difference) {
|
||||
maximum_difference = fabs(difference);
|
||||
}
|
||||
if (i == 0) {
|
||||
// special calculation for r=0
|
||||
//Note: the value \phi_{i,j+Nj/2,k} as the replacement of
|
||||
// \phi_{i-1,j,k} is only correct if Nj is even otherwise the mirrored point
|
||||
// lies inbetween two known values; additionally not sure if this calculation
|
||||
// is correct at all (would definitely be fine for cylindrical symmetric calc.)
|
||||
const int jmirror = (j<potential_.extent(1)/2) ? j+potential_.extent(1)/2
|
||||
: j-potential_.extent(1)/2;
|
||||
const double difference = interpolated_density(i,j,k)/SI::eps0 +
|
||||
2*(potential_(i+1,j,k).value - 2*potential_(i,j,k).value +
|
||||
potential_(i+1,jmirror,k).value)/dr_sq +
|
||||
(potential_(i,j,k+1).value - 2*potential_(i,j,k).value +
|
||||
potential_(i,j,k-1).value)/dz_sq;
|
||||
|
||||
cumulated_quadradic_difference += std::pow(difference, 2);
|
||||
|
||||
if(fabs(difference) > maximum_difference) {
|
||||
maximum_difference = fabs(difference);
|
||||
}
|
||||
} else {
|
||||
const double difference = interpolated_density(i,j)/SI::eps0 +
|
||||
(potential_(i+1,j).value - 2*potential_(i,j).value +
|
||||
potential_(i-1,j).value)/dr_sq +
|
||||
(potential_(i+1,j).value - potential_(i-1,j).value)/
|
||||
(2*i*dr_sq) +
|
||||
(potential_(i,j+1).value - 2*potential_(i,j).value +
|
||||
potential_(i,j-1).value)/dz_sq;
|
||||
|
||||
} else {
|
||||
const int jp1 = j + 1 > potential_.ubound(1)
|
||||
? potential_.lbound(1)
|
||||
: j + 1; // j+1 with periodic guard
|
||||
const int jm1 = j - 1 < potential_.lbound(1)
|
||||
? potential_.ubound(1)
|
||||
: j - 1; // j-1 with periodic guard
|
||||
cumulated_quadradic_difference += difference*difference;
|
||||
|
||||
const double difference = interpolated_density(i,j,k)/SI::eps0 +
|
||||
(potential_(i+1,j,k).value - 2*potential_(i,j,k).value +
|
||||
potential_(i-1,j,k).value)/dr_sq +
|
||||
(potential_(i+1,j,k).value - potential_(i-1,j,k).value)/
|
||||
(2*i*dr_sq) +
|
||||
(potential_(i,jp1,k).value - 2*potential_(i,j,k).value +
|
||||
potential_(i,jm1,k).value)/(std::pow(i,2)*dr_sq*dth_sq) +
|
||||
(potential_(i,j,k+1).value - 2*potential_(i,j,k).value +
|
||||
potential_(i,j,k-1).value)/dz_sq;
|
||||
|
||||
cumulated_quadradic_difference += std::pow(difference, 2);
|
||||
|
||||
if(fabs(difference) > maximum_difference) {
|
||||
maximum_difference = fabs(difference);
|
||||
}
|
||||
if(fabs(difference) > maximum_difference) {
|
||||
maximum_difference = fabs(difference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const int nr = potential_.extent(0) - 1;
|
||||
const int nth = potential_.extent(1);
|
||||
const int nz = potential_.extent(2) - 2;
|
||||
const int nz = potential_.extent(1) - 2;
|
||||
|
||||
normalized_difference =
|
||||
std::sqrt(cumulated_quadradic_difference / (nr * nth * nz));
|
||||
DEBUG_LEVEL_0("Poisson solver reached a normalized difference of: " +
|
||||
std::to_string(normalized_difference));
|
||||
std::sqrt(cumulated_quadradic_difference / (nr * nz));
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << "Poisson solver reached a normalized difference of: ";
|
||||
out << normalized_difference;
|
||||
DEBUG_LEVEL_0(out.str());
|
||||
#endif
|
||||
double normalized_maximum =
|
||||
maximum_difference*SI::eps0/(fabs(blitz::max(interpolated_density)) + 1e-12);
|
||||
#ifdef debug
|
||||
std::ostringstream message;
|
||||
message << "Maximum Difference normalized by order of magnitude: "
|
||||
<< normalized_difference;
|
||||
DEBUG_LEVEL_0(message.str());
|
||||
<< normalized_maximum;
|
||||
DEBUG(message.str());
|
||||
#endif
|
||||
return normalized_difference < target_accuracy_;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> PoissonSolver::potential() {
|
||||
blitz::Array<double, 2> PoissonSolver::potential() {
|
||||
// there might be a better way to do this... (if one can do array.memberValue without
|
||||
// explicitely looping)
|
||||
blitz::Array<double, 3> potentialValues(potential_.lbound(), potential_.extent());
|
||||
blitz::Array<double, 2> potentialValues(potential_.lbound(), potential_.extent());
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Extracting potential values");
|
||||
#endif
|
||||
for(int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for(int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) {
|
||||
potentialValues(i,j,k) = potential_(i,j,k).value;
|
||||
}
|
||||
potentialValues(i,j) = potential_(i,j).value;
|
||||
}
|
||||
}
|
||||
return potentialValues;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> PoissonSolver::interpolateDensityToPotentialGrid(
|
||||
const blitz::Array<double, 3> density) {
|
||||
blitz::Array<double, 2> PoissonSolver::interpolateDensityToPotentialGrid(
|
||||
const blitz::Array<double, 2> density) {
|
||||
// adapted from the external poisson solver (SDS: \\lsdf02.urz.uni-heidelberg.de\SD19H002\karl\src\tools\analysis_jkellerer)
|
||||
blitz::Array<double, 3> interpolatedDensity(potential_.lbound(), potential_.extent());
|
||||
blitz::Array<double, 2> interpolatedDensity(potential_.lbound(), potential_.extent());
|
||||
interpolatedDensity = 0.;
|
||||
|
||||
//center values
|
||||
for(int i = potential_.lbound(0)+1; i <= potential_.ubound(0); ++i) {
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for(int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) {
|
||||
interpolatedDensity(i, j, k) = (
|
||||
density(i-1, j , k-1) + density(i, j , k-1) +
|
||||
density(i-1, j , k ) + density(i, j , k ))/4.;
|
||||
}
|
||||
interpolatedDensity(i, j) = (
|
||||
density(i-1, j-1) + density(i, j-1) +
|
||||
density(i-1, j ) + density(i, j ))/4.;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,80 +246,57 @@ blitz::Array<double, 3> PoissonSolver::interpolateDensityToPotentialGrid(
|
||||
//values for r=0; charge density has to be single valued at r=0
|
||||
//therefore all elements in the j index have to be the same
|
||||
fixedIndex = potential_.lbound(0);
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for(int k = potential_.lbound(2)+1; k <= potential_.ubound(2)-1; ++k) {
|
||||
//might not work that way, would need a dummy variable otherwise
|
||||
interpolatedDensity(potential_.lbound(0), blitz::Range::all(), k) +=
|
||||
(density(fixedIndex, j, k-1) + density(fixedIndex, j, k))/2.;
|
||||
}
|
||||
for(int k = potential_.lbound(1)+1; k <= potential_.ubound(1)-1; ++k) {
|
||||
//might not work that way, would need a dummy variable otherwise
|
||||
interpolatedDensity(potential_.lbound(0), k) =
|
||||
(density(fixedIndex, k-1) + density(fixedIndex, k))/2.;
|
||||
}
|
||||
|
||||
//might not work that way (if not needs a loop)
|
||||
interpolatedDensity(fixedIndex, blitz::Range::all(), blitz::Range::all()) /=
|
||||
potential_.extent(1);
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Max Value in interpolated density array: " +
|
||||
std::to_string(blitz::max(interpolatedDensity)));
|
||||
#endif
|
||||
//for r=r_max, k=k_min and k=k_max do not use an interpolation,
|
||||
//since no boundary cell needs the information about its density value
|
||||
return interpolatedDensity;
|
||||
}
|
||||
|
||||
std::shared_ptr<VectorField> PoissonSolver::staticElectricField() {
|
||||
blitz::TinyVector<double, 3> stepsize = density_binning_.stepsize();
|
||||
blitz::TinyVector<int,3> Eextent = potential_.extent() -
|
||||
blitz::TinyVector<int,3>(1,0,1);
|
||||
blitz::Array<double, 3> Er(potential_.lbound(), Eextent);
|
||||
blitz::Array<double, 3> Ephi(potential_.lbound(), Eextent);
|
||||
blitz::Array<double, 3> Ez(potential_.lbound(), Eextent);
|
||||
blitz::TinyVector<double, 2> stepsize = density_binning_.stepsize();
|
||||
blitz::TinyVector<int,2> Eextent = potential_.extent() -
|
||||
blitz::TinyVector<int,2>(1,1);
|
||||
blitz::Array<double, 2> Er(potential_.lbound(), Eextent);
|
||||
blitz::Array<double, 2> Ephi(potential_.lbound(), Eextent);
|
||||
blitz::Array<double, 2> Ez(potential_.lbound(), Eextent);
|
||||
|
||||
Ephi = 0.;
|
||||
//do calculation of E from the potential and interpolation to
|
||||
//cell center at the same time
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
int jp = (j+1 > potential_.ubound(1)) ? potential_.lbound(1) : j+1;
|
||||
int jm = (j-1 < potential_.lbound(1)) ? potential_.ubound(1) : j-1;
|
||||
for(int i = potential_.lbound(0); i < potential_.ubound(0); ++i) {
|
||||
for(int k = potential_.lbound(2); k < potential_.ubound(2); ++k) {
|
||||
Er(i,j,k) = -(potential_(i+1,j,k ).value -
|
||||
potential_(i ,j,k ).value +
|
||||
potential_(i+1,j,k+1).value -
|
||||
potential_(i ,j,k+1).value)
|
||||
/(2*stepsize(0));
|
||||
|
||||
Ez(i,j,k) = -(potential_(i ,j,k+1).value -
|
||||
potential_(i ,j,k ).value +
|
||||
potential_(i+1,j,k+1).value -
|
||||
potential_(i+1,j,k ).value)
|
||||
/(2*stepsize(2));
|
||||
for(int i = potential_.lbound(0); i < potential_.ubound(0); ++i) {
|
||||
for(int k = potential_.lbound(1); k < potential_.ubound(1); ++k) {
|
||||
Er(i,k) = -(potential_(i+1,k ).value -
|
||||
potential_(i ,k ).value +
|
||||
potential_(i+1,k+1).value -
|
||||
potential_(i ,k+1).value ) /(2*stepsize(0));
|
||||
|
||||
if(i==potential_.lbound(0)) {
|
||||
Ephi(i,j,k) = -(
|
||||
potential_(i+1,jp,k ).value - potential_(i+1,jm,k ).value +
|
||||
potential_(i+1,jp,k+1).value - potential_(i+1,jm,k+1).value)
|
||||
/((i+1)*stepsize(0)*stepsize(2))/4.;
|
||||
} else {
|
||||
Ephi(i,j,k) = -(
|
||||
(potential_(i ,jp,k ).value - potential_(i ,jm,k ).value +
|
||||
potential_(i ,jp,k+1).value - potential_(i ,jm,k+1).value)
|
||||
/(i*stepsize(0)) +
|
||||
(potential_(i+1,jp,k ).value - potential_(i+1,jm,k ).value +
|
||||
potential_(i+1,jp,k+1).value - potential_(i+1,jm,k+1).value)
|
||||
/((i+1)*stepsize(0)) )/(4.*stepsize(1));
|
||||
}
|
||||
}
|
||||
Ez(i,k) = -(potential_(i ,k+1).value -
|
||||
potential_(i ,k ).value +
|
||||
potential_(i+1,k+1).value -
|
||||
potential_(i+1,k ).value )/(2*stepsize(1));
|
||||
}
|
||||
}
|
||||
|
||||
return std::shared_ptr<VectorField>(
|
||||
new VectorFieldFromArray(Er, Ephi, Ez,
|
||||
Eextent(0)*stepsize(0), Eextent(2)*stepsize(2)));
|
||||
Eextent(0)*stepsize(0), Eextent(1)*stepsize(1)));
|
||||
}
|
||||
|
||||
const CylinderBinning* PoissonSolver::densityBinning() {
|
||||
return &density_binning_;
|
||||
}
|
||||
|
||||
void PoissonSolver::setPotential(blitz::Array<double, 3>& potential) {
|
||||
void PoissonSolver::setPotential(blitz::Array<double, 2>& potential) {
|
||||
// check if the loaded potential has the same size as the potential
|
||||
// specified by the json file
|
||||
if(!blitz::all(potential.length() == potential_.length())) {
|
||||
@@ -370,13 +311,10 @@ void PoissonSolver::setPotential(blitz::Array<double, 3>& potential) {
|
||||
// while the parameter array is most likely starting from 0)
|
||||
const int i_offset = potential.lbound(0) - potential_.lbound(0);
|
||||
const int j_offset = potential.lbound(1) - potential_.lbound(1);
|
||||
const int k_offset = potential.lbound(2) - potential_.lbound(2);
|
||||
|
||||
for(int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
|
||||
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
|
||||
for(int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) {
|
||||
potential_(i,j,k).value = potential(i + i_offset,j + j_offset,k + k_offset);
|
||||
}
|
||||
potential_(i,j).value = potential(i + i_offset,j + j_offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -395,4 +333,34 @@ RearWall::RearWall(double potential): Electrode(potential) {};
|
||||
bool RearWall::isOnElectrode(const Coordinate& position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RingElectrode::RingElectrode(double potential, const double zPosition,
|
||||
const double innerRadius,
|
||||
const double outerRadius,
|
||||
const blitz::TinyVector<double, 2> stepsize):
|
||||
Electrode(potential),
|
||||
specs_(blitz::TinyVector<double, 3>(innerRadius, outerRadius, zPosition)),
|
||||
stepsize_(stepsize) {}
|
||||
|
||||
bool RingElectrode::isOnElectrode(const Coordinate& pos) {
|
||||
blitz::TinyVector<double, 3> pos_cyl = pos.cylinderEntries();
|
||||
|
||||
bool zdir = std::abs(pos_cyl(2) - specs_(2)) <= stepsize_(1)/2;
|
||||
zdir = (specs_(2) - pos_cyl(2) == stepsize_(1)/2) ? false : zdir;
|
||||
|
||||
bool rInner = (pos_cyl(0) >= specs_(0));
|
||||
bool rOuter = (pos_cyl(0) < specs_(1));
|
||||
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << "Position " << pos_cyl << ": \n\t";
|
||||
out << "z-dir: " << ((zdir) ? "true" : "false") << "\n\t";
|
||||
out << "rinner-dir: " << ((rInner) ? "true" : "false") << "\n\t";
|
||||
out << "router-dir: " << ((rOuter) ? "true" : "false") << "\n\t";
|
||||
out << "total: " << ((zdir && rInner && rOuter) ? "true" : "false") << "\n\t";
|
||||
DEBUG(out.str());
|
||||
#endif
|
||||
|
||||
return zdir && rInner && rOuter;
|
||||
}
|
||||
|
||||
@@ -56,10 +56,24 @@ blitz::TinyVector<double, 3> CartesianCoordinate::cartesianEntries() const {
|
||||
return cartesian_position;
|
||||
}
|
||||
|
||||
double CartesianCoordinate::sinAzimuth() const {
|
||||
double rad = std::sqrt(cartesian_position(0)*cartesian_position(0) +
|
||||
cartesian_position(1)*cartesian_position(1));
|
||||
return cartesian_position(1)/rad;
|
||||
}
|
||||
|
||||
double CartesianCoordinate::cosAzimuth() const {
|
||||
double rad = std::sqrt(cartesian_position(0)*cartesian_position(0) +
|
||||
cartesian_position(1)*cartesian_position(1));
|
||||
return cartesian_position(0)/rad;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> CartesianCoordinate::cylinderEntries() const {
|
||||
const double radius = std::sqrt(std::pow(cartesian_position(0), 2) +
|
||||
std::pow(cartesian_position(1), 2));
|
||||
const double phi = std::atan2(cartesian_position(1), cartesian_position(0));
|
||||
// const double radius = std::sqrt(std::pow(cartesian_position(0), 2) +
|
||||
// std::pow(cartesian_position(1), 2));
|
||||
const double radius = std::sqrt(cartesian_position(0)*cartesian_position(0) +
|
||||
cartesian_position(1)*cartesian_position(1));
|
||||
const double phi = 0.;//std::atan2(cartesian_position(1), cartesian_position(0));
|
||||
const double z = cartesian_position(2);
|
||||
return blitz::TinyVector<double, 3>(radius, phi, z);
|
||||
}
|
||||
@@ -75,6 +89,9 @@ void CartesianCoordinate::add(const Coordinate& coordinate) {
|
||||
CylinderCoordinate::CylinderCoordinate(
|
||||
const blitz::TinyVector<double, 3>& cylinder_position)
|
||||
: cylinder_position(cylinder_position) {
|
||||
#ifdef debug
|
||||
phi_was_set = true;
|
||||
#endif
|
||||
// limitPhi();
|
||||
}
|
||||
|
||||
@@ -83,7 +100,27 @@ CylinderCoordinate::CylinderCoordinate(const Coordinate& coordinate)
|
||||
// limitPhi();
|
||||
}
|
||||
|
||||
double CylinderCoordinate::cosAzimuth() const {
|
||||
#ifdef debug
|
||||
if(!phi_was_set)
|
||||
fprintf(stdout, "CylinderCoordinate cos calc\n");
|
||||
#endif
|
||||
return std::cos(cylinder_position(1));
|
||||
}
|
||||
|
||||
double CylinderCoordinate::sinAzimuth() const {
|
||||
#ifdef debug
|
||||
if(!phi_was_set)
|
||||
fprintf(stdout, "CylinderCoordinate sin calc\n");
|
||||
#endif
|
||||
return std::sin(cylinder_position(1));
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> CylinderCoordinate::cartesianEntries() const {
|
||||
#ifdef debug
|
||||
if(!phi_was_set)
|
||||
fprintf(stdout, "Transformation form cylinder coordinate to cartesian!\n");
|
||||
#endif
|
||||
return blitz::TinyVector<double, 3>(
|
||||
cylinder_position(0) * std::cos(cylinder_position(1)),
|
||||
cylinder_position(0) * std::sin(cylinder_position(1)),
|
||||
@@ -110,7 +147,7 @@ void CylinderCoordinate::add(const Coordinate& coordinate) {
|
||||
const CartesianCoordinate c_cart(new_cart_position);
|
||||
const CylinderCoordinate c_cyl(c_cart);
|
||||
cylinder_position = c_cyl.cylinderEntries();
|
||||
limitPhi();
|
||||
// limitPhi();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -134,12 +171,16 @@ CylinderVector CylinderVector::operator+(const CylinderVector& vector) {
|
||||
|
||||
blitz::TinyVector<double, 3> CylinderVector::cartesianEntries(
|
||||
const Coordinate& coordinate) const {
|
||||
// double phi = coordinate.cylinderEntries()(1);
|
||||
double cosphi = coordinate.cosAzimuth();
|
||||
double sinphi = coordinate.sinAzimuth();
|
||||
|
||||
const double A_x =
|
||||
std::cos(coordinate.cylinderEntries()(1)) * cylinder_vector(0) -
|
||||
std::sin(coordinate.cylinderEntries()(1)) * cylinder_vector(1);
|
||||
cosphi * cylinder_vector(0) -
|
||||
sinphi * cylinder_vector(1);
|
||||
const double A_y =
|
||||
std::sin(coordinate.cylinderEntries()(1)) * cylinder_vector(0) +
|
||||
std::cos(coordinate.cylinderEntries()(1)) * cylinder_vector(1);
|
||||
sinphi * cylinder_vector(0) +
|
||||
cosphi * cylinder_vector(1);
|
||||
const double A_z = cylinder_vector(2);
|
||||
return blitz::TinyVector<double, 3>(A_x, A_y, A_z);
|
||||
}
|
||||
@@ -153,6 +194,7 @@ blitz::TinyVector<double, 3> CylinderVector::cylinderEntries() const {
|
||||
return cylinder_vector;
|
||||
}
|
||||
|
||||
// think that function is wrong
|
||||
void CylinderVector::add(const Vector& vector, const Coordinate& coordinate) {
|
||||
cylinder_vector += vector.cylinderEntries(coordinate);
|
||||
}
|
||||
@@ -183,6 +225,7 @@ blitz::TinyVector<double, 3> CartesianVector::cartesianEntries() const {
|
||||
|
||||
blitz::TinyVector<double, 3> CartesianVector::cylinderEntries(
|
||||
const Coordinate& coordinate) const {
|
||||
fprintf(stdout, "Transformation Cartesian Vector to Cylinder vector\n");
|
||||
const blitz::TinyVector<double, 3> cylinder_vector =
|
||||
coordinate.cylinderEntries();
|
||||
|
||||
|
||||
@@ -7,24 +7,16 @@
|
||||
#include "simulation/species.h"
|
||||
#include "simulation/mpi_communication.h"
|
||||
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 4>& array,
|
||||
blitz::Array<double, 4>& last_sync_array) {
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 4>& array) {
|
||||
int size = array.size();
|
||||
blitz::Array<double, 4> delta(array.extent());
|
||||
delta = array - last_sync_array;
|
||||
MPI_Allreduce(MPI_IN_PLACE, delta.data(), size, MPI_DOUBLE,
|
||||
MPI_Allreduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE,
|
||||
MPI_SUM, MPI_COMM_WORLD);
|
||||
last_sync_array += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 5>& array,
|
||||
blitz::Array<double, 5>& last_sync_array) {
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<double, 5>& array) {
|
||||
int size = array.size();
|
||||
blitz::Array<double, 5> delta(array.extent());
|
||||
delta = array - last_sync_array;
|
||||
MPI_Allreduce(MPI_IN_PLACE, delta.data(), size, MPI_DOUBLE,
|
||||
MPI_Allreduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE,
|
||||
MPI_SUM, MPI_COMM_WORLD);
|
||||
last_sync_array += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToAll(blitz::Array<long int, 4>& array,
|
||||
@@ -73,6 +65,40 @@ void CpuSynchronizer::sumToAll(long int& value, long int& last_sync_value) {
|
||||
last_sync_value += delta;
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToRoot(blitz::Array<double, 3>& array) {
|
||||
int size = array.size();
|
||||
if(MpiCommunication::mpi_rank == root)
|
||||
MPI_Reduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
else
|
||||
MPI_Reduce(array.data(), nullptr, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToRoot(blitz::Array<double, 2>& array) {
|
||||
int size = array.size();
|
||||
if(MpiCommunication::mpi_rank == root)
|
||||
MPI_Reduce(MPI_IN_PLACE, array.data(), size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
else
|
||||
MPI_Reduce(array.data(), nullptr, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToRoot(long int& value) {
|
||||
int size = 1;
|
||||
if(MpiCommunication::mpi_rank == root) {
|
||||
MPI_Reduce(MPI_IN_PLACE, &value, size, MPI_LONG, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
} else {
|
||||
MPI_Reduce(&value, nullptr, size, MPI_LONG, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
}
|
||||
}
|
||||
|
||||
void CpuSynchronizer::sumToRoot(double& value) {
|
||||
int size = 1;
|
||||
if(MpiCommunication::mpi_rank == root) {
|
||||
MPI_Reduce(MPI_IN_PLACE, &value, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
} else {
|
||||
MPI_Reduce(&value, nullptr, size, MPI_DOUBLE, MPI_SUM, root, MPI_COMM_WORLD);
|
||||
}
|
||||
}
|
||||
|
||||
void CpuSynchronizer::synchronize(Timer* timer, Timer* last_sync_timer) {
|
||||
if(timer == last_sync_timer) {
|
||||
ERROR("Synchronization of timers cannot work, point to same object.");
|
||||
@@ -84,53 +110,58 @@ void CpuSynchronizer::synchronize(Timer* timer, Timer* last_sync_timer) {
|
||||
last_sync_timer->setTime(last_sync_time_s);
|
||||
}
|
||||
|
||||
void CpuSynchronizer::synchronize(DynamicDensityField* field,
|
||||
DynamicDensityField* density_for_drawing,
|
||||
bool reset) {
|
||||
// synchronize density field across cpus and set the
|
||||
// array storing the previous timestep
|
||||
void CpuSynchronizer::synchronize(DynamicDensityField* field) {
|
||||
if (field) {
|
||||
sumToAll(field->time_in_bin_s_, field->sync_time_in_bin_s_);
|
||||
field->time_in_bin_s_ = field->sync_time_in_bin_s_;
|
||||
|
||||
sumToAll(field->deleted_particles_, field->sync_deleted_particles_);
|
||||
field->deleted_particles_ = field->sync_deleted_particles_;
|
||||
if (reset) {
|
||||
density_for_drawing->time_in_bin_s_ = field->time_in_bin_s_;
|
||||
density_for_drawing->deleted_particles_ = field->deleted_particles_;
|
||||
}
|
||||
sumToAll(field->sync_number_in_bin_);
|
||||
field->number_in_bin_ = field->sync_number_in_bin_;
|
||||
field->recalculateDensityArray();
|
||||
}
|
||||
}
|
||||
|
||||
void CpuSynchronizer::synchronize(CurrentCollector* collector) {
|
||||
if (collector) {
|
||||
sumToAll(collector->z_negative_crossings,
|
||||
collector->sync_z_negative_crossings);
|
||||
collector->z_negative_crossings =
|
||||
collector->sync_z_negative_crossings;
|
||||
// sumToAll(collector->z_negative_crossings,
|
||||
// collector->sync_z_negative_crossings);
|
||||
// collector->z_negative_crossings =
|
||||
// collector->sync_z_negative_crossings;
|
||||
sumToRoot(collector->z_negative_crossings);
|
||||
|
||||
sumToAll(collector->z_positive_crossings,
|
||||
collector->sync_z_positive_crossings);
|
||||
collector->z_positive_crossings =
|
||||
collector->sync_z_positive_crossings;
|
||||
// sumToAll(collector->z_positive_crossings,
|
||||
// collector->sync_z_positive_crossings);
|
||||
// collector->z_positive_crossings =
|
||||
// collector->sync_z_positive_crossings;
|
||||
sumToRoot(collector->z_positive_crossings);
|
||||
|
||||
sumToAll(collector->phi_negative_crossings,
|
||||
collector->sync_phi_negative_crossings);
|
||||
collector->phi_negative_crossings =
|
||||
collector->sync_phi_negative_crossings;
|
||||
// sumToAll(collector->phi_negative_crossings,
|
||||
// collector->sync_phi_negative_crossings);
|
||||
// collector->phi_negative_crossings =
|
||||
// collector->sync_phi_negative_crossings;
|
||||
sumToRoot(collector->phi_negative_crossings);
|
||||
|
||||
sumToAll(collector->phi_positive_crossings,
|
||||
collector->sync_phi_positive_crossings);
|
||||
collector->phi_positive_crossings =
|
||||
collector->sync_phi_positive_crossings;
|
||||
// sumToAll(collector->phi_positive_crossings,
|
||||
// collector->sync_phi_positive_crossings);
|
||||
// collector->phi_positive_crossings =
|
||||
// collector->sync_phi_positive_crossings;
|
||||
sumToRoot(collector->phi_positive_crossings);
|
||||
|
||||
sumToAll(collector->r_negative_crossings,
|
||||
collector->sync_r_negative_crossings);
|
||||
collector->r_negative_crossings =
|
||||
collector->sync_r_negative_crossings;
|
||||
// sumToAll(collector->r_negative_crossings,
|
||||
// collector->sync_r_negative_crossings);
|
||||
// collector->r_negative_crossings =
|
||||
// collector->sync_r_negative_crossings;
|
||||
sumToRoot(collector->r_negative_crossings);
|
||||
|
||||
sumToAll(collector->r_positive_crossings,
|
||||
collector->sync_r_positive_crossings);
|
||||
collector->r_positive_crossings =
|
||||
collector->sync_r_positive_crossings;
|
||||
// sumToAll(collector->r_positive_crossings,
|
||||
// collector->sync_r_positive_crossings);
|
||||
// collector->r_positive_crossings =
|
||||
// collector->sync_r_positive_crossings;
|
||||
sumToRoot(collector->r_positive_crossings);
|
||||
|
||||
#ifdef GENRICHCURRENT
|
||||
if(collector->getNeedsReset())
|
||||
sumToRoot(collector->sample_z_negative_crossings);
|
||||
#endif //GENRICHCURRENT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,25 +169,33 @@ void CpuSynchronizer::synchronize(DeletionLogger* logger) {
|
||||
if (logger) {
|
||||
for (auto& pair : logger->num_deletions) {
|
||||
long int num_deletion = pair.second;
|
||||
long int last_sync_num_deletion = logger->sync_num_deletions[pair.first];
|
||||
sumToAll(num_deletion, last_sync_num_deletion);
|
||||
// long int last_sync_num_deletion = logger->sync_num_deletions[pair.first];
|
||||
sumToRoot(num_deletion);//, last_sync_num_deletion
|
||||
// last_sync_num_deletion now contains the total number of deletions
|
||||
// across all cpus -> update the values in the objects
|
||||
pair.second = last_sync_num_deletion;
|
||||
logger->sync_num_deletions[pair.first] = last_sync_num_deletion;
|
||||
pair.second = num_deletion; //last_sync_num_deletion;
|
||||
// logger->sync_num_deletions[pair.first] = last_sync_num_deletion;
|
||||
}
|
||||
for (auto& pair : logger->num_phys_deletions) {
|
||||
double num_deletion = pair.second;
|
||||
// double last_sync_num_deletion = logger->sync_num_phys_deletions[pair.first];
|
||||
sumToRoot(num_deletion);//, last_sync_num_deletion);
|
||||
// last_sync_num_deletion now contains the total number of deletions
|
||||
// across all cpus -> update the values in the objects
|
||||
pair.second = num_deletion; //last_sync_num_deletion;
|
||||
// logger->sync_num_phys_deletions[pair.first] = last_sync_num_deletion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CpuSynchronizer::synchronize(
|
||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>&
|
||||
tracked_species, bool reset) {
|
||||
tracked_species) {
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
auto it = tracked_species.begin();
|
||||
|
||||
for (auto& pair : tracked_species) {
|
||||
synchronize(pair.second->dynamicDensityField(),
|
||||
pair.second->densityForDrawing(), reset);
|
||||
synchronize(pair.second->dynamicDensityField());
|
||||
synchronize(pair.second->currentCollector());
|
||||
synchronize(pair.second->deletionLogger());
|
||||
}
|
||||
|
||||
@@ -12,242 +12,271 @@ CurrentCollector::CurrentCollector(const CylinderBinning& position_binning,
|
||||
collector_areas_r(createAreaRadial(position_binning)),
|
||||
phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
||||
phi_positive_crossings(createCrossingsAzimuthal(position_binning)),
|
||||
collector_areas_phi(createAreaAzimuthal(position_binning)),
|
||||
sync_z_negative_crossings(createCrossingsLongitudinal(position_binning)),
|
||||
sync_z_positive_crossings(createCrossingsLongitudinal(position_binning)),
|
||||
sync_r_negative_crossings(createCrossingsRadial(position_binning)),
|
||||
sync_r_positive_crossings(createCrossingsRadial(position_binning)),
|
||||
sync_phi_negative_crossings(createCrossingsAzimuthal(position_binning)),
|
||||
sync_phi_positive_crossings(createCrossingsAzimuthal(position_binning)) {}
|
||||
collector_areas_phi(createAreaAzimuthal(position_binning))
|
||||
#ifdef GENRICHCURRENT
|
||||
// Hard coded values, not ideal, but it didn't work using defines...
|
||||
, energy_binning_(0.1, 5, 100)
|
||||
, sample_z_negative_crossings(
|
||||
blitz::Range(position_binning.binIndexMin()(0),
|
||||
position_binning.binIndexMax()(0)),
|
||||
blitz::Range(-1, 100))
|
||||
#endif //GENRICHCURRENT
|
||||
{
|
||||
#ifdef GENRICHCURRENT
|
||||
sample_z_negative_crossings = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createAreaLongitudinal(
|
||||
blitz::Array<double, 2> CurrentCollector::createAreaLongitudinal(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> area_z(
|
||||
blitz::Array<double, 2> area_z(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0)),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(0, bin_index_max(2)));
|
||||
blitz::Range(0, bin_index_max(1)));
|
||||
|
||||
for (int ir = 0; ir <= area_z.ubound(0); ++ir) {
|
||||
const double dr = position_binning.stepsize()(0);
|
||||
const double r1 = ir * dr;
|
||||
const double r2 = (ir + 1) * dr;
|
||||
const double area_element =
|
||||
(std::pow(r2, 2) - std::pow(r1, 2)) * M_PI / (area_z.extent(1));
|
||||
area_z(ir, blitz::Range::all(), blitz::Range::all()) = area_element;
|
||||
// const double area_element =
|
||||
// (std::pow(r2, 2) - std::pow(r1, 2)) * M_PI / (area_z.extent(1));
|
||||
const double area_element = (r2*r2 - r1*r1) * M_PI;
|
||||
area_z(ir, blitz::Range::all()) = area_element;
|
||||
}
|
||||
return area_z;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createCrossingsLongitudinal(
|
||||
blitz::Array<double, 2> CurrentCollector::createCrossingsLongitudinal(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> crossings_longitudinal(
|
||||
blitz::Array<double, 2> crossings_longitudinal(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0)),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(0, bin_index_max(2)));
|
||||
blitz::Range(0, bin_index_max(1)));
|
||||
crossings_longitudinal = 0.;
|
||||
return crossings_longitudinal;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createAreaRadial(
|
||||
blitz::Array<double, 2> CurrentCollector::createAreaRadial(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> area_r(
|
||||
blitz::Array<double, 2> area_r(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0) - 1),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(bin_index_min(2), bin_index_max(2)));
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)));
|
||||
|
||||
for (int ir = 0; ir <= area_r.ubound(0); ++ir) {
|
||||
const double dr = position_binning.stepsize()(0);
|
||||
const double dz = position_binning.stepsize()(2);
|
||||
const double dz = position_binning.stepsize()(1);
|
||||
const double r = (ir + 1) * dr;
|
||||
const double area_element = (2 * M_PI * r) / area_r.extent(1) * dz;
|
||||
const double area_element = (2 * M_PI * r) * dz;
|
||||
|
||||
area_r(ir, blitz::Range::all(), blitz::Range::all()) = area_element;
|
||||
area_r(ir, blitz::Range::all()) = area_element;
|
||||
}
|
||||
return area_r;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createCrossingsRadial(
|
||||
blitz::Array<double, 2> CurrentCollector::createCrossingsRadial(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> crossings_radial(
|
||||
blitz::Array<double, 2> crossings_radial(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0) - 1),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(bin_index_min(2), bin_index_max(2)));
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)));
|
||||
crossings_radial = 0.;
|
||||
return crossings_radial;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createAreaAzimuthal(
|
||||
blitz::Array<double, 2> CurrentCollector::createAreaAzimuthal(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> area_phi(
|
||||
blitz::Array<double, 2> area_phi(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0)),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(bin_index_min(2), bin_index_max(2)));
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)));
|
||||
|
||||
const double dr = position_binning.stepsize()(0);
|
||||
const double dz = position_binning.stepsize()(2);
|
||||
const double dz = position_binning.stepsize()(1);
|
||||
const double area_element = dr * dz;
|
||||
area_phi(blitz::Range::all(), blitz::Range::all(), blitz::Range::all()) =
|
||||
area_phi(blitz::Range::all(), blitz::Range::all()) =
|
||||
area_element;
|
||||
return area_phi;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::createCrossingsAzimuthal(
|
||||
blitz::Array<double, 2> CurrentCollector::createCrossingsAzimuthal(
|
||||
const CylinderBinning& position_binning) {
|
||||
const blitz::TinyVector<int, 3> bin_index_min =
|
||||
const blitz::TinyVector<int, 2> bin_index_min =
|
||||
position_binning.binIndexMin();
|
||||
const blitz::TinyVector<int, 3> bin_index_max =
|
||||
const blitz::TinyVector<int, 2> bin_index_max =
|
||||
position_binning.binIndexMax();
|
||||
|
||||
blitz::Array<double, 3> crossings_azimuthal(
|
||||
blitz::Array<double, 2> crossings_azimuthal(
|
||||
blitz::Range(bin_index_min(0), bin_index_max(0)),
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)),
|
||||
blitz::Range(bin_index_min(2), bin_index_max(2)));
|
||||
blitz::Range(bin_index_min(1), bin_index_max(1)));
|
||||
crossings_azimuthal = 0;
|
||||
return crossings_azimuthal;
|
||||
}
|
||||
|
||||
// old_position should be a CartesianCoordinate, since the cartesian entries are needed
|
||||
// for the Azimuthal collection and a transformation from cylinder -> cartesian is not possible
|
||||
void CurrentCollector::collect(particle::Particle* particle,
|
||||
const Coordinate& old_position) {
|
||||
blitz::TinyVector<int, 3> bin_old =
|
||||
blitz::TinyVector<int, 2> bin_old =
|
||||
position_binning_.bin(old_position.cylinderEntries());
|
||||
blitz::TinyVector<int, 3> bin_new =
|
||||
position_binning_.bin(particle->position().cylinderEntries());
|
||||
blitz::TinyVector<int, 2> bin_new =
|
||||
position_binning_.bin(particle->cylinderPosition().cylinderEntries());
|
||||
|
||||
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);
|
||||
collectLongitudinalMovement(bin_old, bin_new, weight);
|
||||
collectAzimuthalMovement(bin_old, bin_new, weight);
|
||||
collectLongitudinalMovement(bin_old, bin_new,
|
||||
#ifdef GENRICHCURRENT
|
||||
particle->kineticEnergy_eV(),
|
||||
#endif
|
||||
weight);
|
||||
collectAzimuthalMovement(old_position.cartesianEntries(),
|
||||
particle->cartesianPosition().cartesianEntries(),
|
||||
bin_old, weight);
|
||||
}
|
||||
|
||||
void CurrentCollector::collectRadialMovement(
|
||||
const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
const blitz::TinyVector<int, 2>& bin_old,
|
||||
const blitz::TinyVector<int, 2>& bin_new,
|
||||
const double weight) {
|
||||
if (bin_new(0) < bin_old(0)) {
|
||||
r_negative_crossings(bin_new(0), bin_old(1), bin_old(2)) += weight;
|
||||
r_negative_crossings(bin_new(0), bin_old(1)) += weight;
|
||||
} else if (bin_new(0) > bin_old(0)) {
|
||||
r_positive_crossings(bin_new(0) - 1, bin_old(1), bin_old(2)) += weight;
|
||||
r_positive_crossings(bin_new(0) - 1, bin_old(1)) += weight;
|
||||
}
|
||||
}
|
||||
void CurrentCollector::collectLongitudinalMovement(
|
||||
const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
const blitz::TinyVector<int, 2>& bin_old,
|
||||
const blitz::TinyVector<int, 2>& bin_new,
|
||||
#ifdef GENRICHCURRENT
|
||||
const double energy_eV,
|
||||
#endif
|
||||
const double weight) {
|
||||
if (bin_new(2) < bin_old(2)) {
|
||||
z_negative_crossings(bin_old(0), bin_old(1), bin_new(2) + 1) += weight;
|
||||
} else if (bin_new(2) > bin_old(2)) {
|
||||
z_positive_crossings(bin_old(0), bin_old(1), bin_new(2)) += weight;
|
||||
if (bin_new(1) < bin_old(1)) {
|
||||
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)) {
|
||||
z_positive_crossings(bin_old(0), bin_new(1)) += weight;
|
||||
}
|
||||
}
|
||||
// does not work correctly if \Delta t*v_phi > pi*r!
|
||||
void CurrentCollector::collectAzimuthalMovement(
|
||||
const blitz::TinyVector<int, 3>& bin_old,
|
||||
const blitz::TinyVector<int, 3>& bin_new,
|
||||
const blitz::TinyVector<double, 3>& old_pos_cart,
|
||||
const blitz::TinyVector<double, 3>& new_pos_cart,
|
||||
const blitz::TinyVector<int, 2>& bin_old,
|
||||
const double weight) {
|
||||
if ((bin_new(1) < bin_old(1)) ||
|
||||
((bin_old(1) == 0) &&
|
||||
(bin_new(1) == position_binning_.binIndexMax()(1)))) {
|
||||
phi_negative_crossings(bin_old(0), bin_new(1), bin_old(2)) += weight;
|
||||
} else if ((bin_new(1) > bin_old(1)) ||
|
||||
((bin_old(1) == position_binning_.binIndexMax()(1)) &&
|
||||
(bin_new(1) == 0))) {
|
||||
phi_positive_crossings(bin_old(0), bin_new(1) - 1, bin_old(2)) += weight;
|
||||
if(old_pos_cart(0) < 0 && new_pos_cart(0) < 0) {
|
||||
return;
|
||||
}
|
||||
if(old_pos_cart(1) > 0 && new_pos_cart(1) < 0) {
|
||||
phi_negative_crossings(bin_old) += weight;
|
||||
} else if (old_pos_cart(1) < 0 && new_pos_cart(1) > 0) {
|
||||
phi_positive_crossings(bin_old) += weight;
|
||||
}
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::negativeCrossingsInZ() const {
|
||||
blitz::Array<double, 2> CurrentCollector::negativeCrossingsInZ() const {
|
||||
return z_negative_crossings;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::positiveCrossingsInZ() const {
|
||||
blitz::Array<double, 2> CurrentCollector::positiveCrossingsInZ() const {
|
||||
return z_positive_crossings;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::negativeCrossingsInPhi() const {
|
||||
blitz::Array<double, 2> CurrentCollector::negativeCrossingsInPhi() const {
|
||||
return phi_negative_crossings;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::positiveCrossingsInPhi() const {
|
||||
blitz::Array<double, 2> CurrentCollector::positiveCrossingsInPhi() const {
|
||||
return phi_positive_crossings;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::negativeCrossingsInR() const {
|
||||
blitz::Array<double, 2> CurrentCollector::negativeCrossingsInR() const {
|
||||
return r_negative_crossings;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::positiveCrossingsInR() const {
|
||||
blitz::Array<double, 2> CurrentCollector::positiveCrossingsInR() const {
|
||||
return r_positive_crossings;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::areaInR() const {
|
||||
blitz::Array<double, 2> CurrentCollector::areaInR() const {
|
||||
return collector_areas_r;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::areaInPhi() const {
|
||||
blitz::Array<double, 2> CurrentCollector::areaInPhi() const {
|
||||
return collector_areas_phi;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::areaInZ() const {
|
||||
blitz::Array<double, 2> CurrentCollector::areaInZ() const {
|
||||
return collector_areas_z;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> CurrentCollector::currentInZ() const {
|
||||
blitz::Array<double, 3> current_in_z = z_positive_crossings.copy();
|
||||
current_in_z(blitz::Range::all(), blitz::Range::all(), blitz::Range::all()) =
|
||||
(z_positive_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all()) -
|
||||
z_negative_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all())) /
|
||||
blitz::Array<double, 2> CurrentCollector::currentInZ() const {
|
||||
blitz::Array<double, 2> current_in_z = z_positive_crossings.copy();
|
||||
current_in_z(blitz::Range::all(), blitz::Range::all()) =
|
||||
(z_positive_crossings(blitz::Range::all(), blitz::Range::all()) -
|
||||
z_negative_crossings(blitz::Range::all(), blitz::Range::all())) /
|
||||
(physicalTime() * collector_areas_z(blitz::Range::all(),
|
||||
blitz::Range::all(),
|
||||
blitz::Range::all()));
|
||||
return current_in_z;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::currentInPhi() const {
|
||||
blitz::Array<double, 3> current_in_phi = phi_positive_crossings.copy();
|
||||
current_in_phi(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all()) =
|
||||
(phi_positive_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all()) -
|
||||
phi_negative_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all())) /
|
||||
|
||||
// does not work due to wrong phi_{positive/negative}_crossings
|
||||
blitz::Array<double, 2> CurrentCollector::currentInPhi() const {
|
||||
blitz::Array<double, 2> current_in_phi = phi_positive_crossings.copy();
|
||||
current_in_phi(blitz::Range::all(), blitz::Range::all()) =
|
||||
(phi_positive_crossings(blitz::Range::all(), blitz::Range::all()) -
|
||||
phi_negative_crossings(blitz::Range::all(), blitz::Range::all())) /
|
||||
(physicalTime() * collector_areas_phi(blitz::Range::all(),
|
||||
blitz::Range::all(),
|
||||
blitz::Range::all()));
|
||||
return current_in_phi;
|
||||
}
|
||||
blitz::Array<double, 3> CurrentCollector::currentInR() const {
|
||||
blitz::Array<double, 3> current_in_r = r_positive_crossings.copy();
|
||||
current_in_r(blitz::Range::all(), blitz::Range::all(), blitz::Range::all()) =
|
||||
(r_positive_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all()) -
|
||||
r_negative_crossings(blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all())) /
|
||||
|
||||
blitz::Array<double, 2> CurrentCollector::currentInR() const {
|
||||
blitz::Array<double, 2> current_in_r = r_positive_crossings.copy();
|
||||
current_in_r(blitz::Range::all(), blitz::Range::all()) =
|
||||
(r_positive_crossings(blitz::Range::all(), blitz::Range::all()) -
|
||||
r_negative_crossings(blitz::Range::all(), blitz::Range::all())) /
|
||||
(physicalTime() * collector_areas_r(blitz::Range::all(),
|
||||
blitz::Range::all(),
|
||||
blitz::Range::all()));
|
||||
return current_in_r;
|
||||
}
|
||||
|
||||
double CurrentCollector::physicalTime() const {
|
||||
return timer_->getDeltaT();
|
||||
}
|
||||
@@ -262,12 +291,25 @@ void CurrentCollector::resetCurrentCollector() {
|
||||
r_negative_crossings = 0.;
|
||||
r_positive_crossings = 0.;
|
||||
|
||||
sync_z_negative_crossings = 0.;
|
||||
sync_z_positive_crossings = 0.;
|
||||
#ifdef GENRICHCURRENT
|
||||
if(needs_reset) {
|
||||
sample_z_negative_crossings = 0.;
|
||||
needs_reset = false;
|
||||
time_since_reset = timer_->getDeltaT();
|
||||
} else {
|
||||
time_since_reset += timer_->getDeltaT();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
sync_phi_negative_crossings = 0.;
|
||||
sync_phi_positive_crossings = 0.;
|
||||
#ifdef GENRICHCURRENT
|
||||
|
||||
sync_r_negative_crossings = 0.;
|
||||
sync_r_positive_crossings = 0.;
|
||||
}
|
||||
blitz::Array<double, 2> CurrentCollector::sampleNegativeCrossings() const {
|
||||
return sample_z_negative_crossings;
|
||||
}
|
||||
|
||||
std::vector<double> CurrentCollector::energyBinBorders() const {
|
||||
return energy_binning_.binBorders();
|
||||
}
|
||||
|
||||
#endif
|
||||
+121
-243
@@ -9,11 +9,20 @@
|
||||
#include "tools/simulation_time.h"
|
||||
|
||||
template <class T>
|
||||
blitz::Array<T, 4> initiate4DArray(blitz::Range radial,
|
||||
blitz::Range phi,
|
||||
blitz::Array<T, 3> initiate3DArray(blitz::Range radial,
|
||||
blitz::Range longitudinal,
|
||||
blitz::Range energy) {
|
||||
blitz::Array<T, 4> data(radial, phi, longitudinal, energy);
|
||||
blitz::Array<T, 3> data(radial, longitudinal, energy);
|
||||
data = static_cast<T>(0);
|
||||
return data.copy();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
blitz::Array<T, 4> initiate4DArray(blitz::Range radial,
|
||||
blitz::Range longitudinal,
|
||||
blitz::Range energy,
|
||||
blitz::Range pitchangle) {
|
||||
blitz::Array<T, 4> data(radial, longitudinal, energy, pitchangle);
|
||||
data = static_cast<T>(0);
|
||||
return data.copy();
|
||||
}
|
||||
@@ -29,24 +38,23 @@ blitz::Array<T, 5> initiate5DArray(blitz::Range radial,
|
||||
return data.copy();
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> initiateVolumeArray(
|
||||
blitz::Array<double, 2> initiateVolumeArray(
|
||||
blitz::Range radial,
|
||||
blitz::Range phi,
|
||||
blitz::Range longitudinal,
|
||||
const blitz::TinyVector<double, 3>& position_spacing) {
|
||||
blitz::Array<double, 3> volume(radial, phi, longitudinal);
|
||||
const blitz::TinyVector<double, 2>& position_spacing) {
|
||||
blitz::Array<double, 2> volume(radial, longitudinal);
|
||||
|
||||
for (int ir = 0; ir <= volume.ubound(0); ++ir) {
|
||||
const double r1 = ir * position_spacing(0);
|
||||
const double r2 = (ir + 1) * position_spacing(0);
|
||||
for (int iz = volume.lbound(2); iz <= volume.ubound(2); ++iz) {
|
||||
const double z1 = iz * position_spacing(2);
|
||||
const double z2 = (iz + 1) * position_spacing(2);
|
||||
for (int iz = volume.lbound(1); iz <= volume.ubound(1); ++iz) {
|
||||
const double z1 = iz * position_spacing(1);
|
||||
const double z2 = (iz + 1) * position_spacing(1);
|
||||
|
||||
const double bin_volume =
|
||||
M_PI * (std::pow(r2, 2) - std::pow(r1, 2)) * (z2 - z1) / phi.length();
|
||||
M_PI * ((r2*r2) - (r1*r1)) * (z2 - z1);
|
||||
|
||||
volume(ir, blitz::Range::all(), iz) = bin_volume;
|
||||
volume(ir, iz) = bin_volume;
|
||||
}
|
||||
}
|
||||
return volume.copy();
|
||||
@@ -61,55 +69,27 @@ DynamicDensityField::DynamicDensityField(
|
||||
energy_binning_(energy_binning),
|
||||
pitch_angle_binning_(pitch_angle_binning),
|
||||
timer_(timer),
|
||||
time_in_bin_s_(initiate5DArray<double>(
|
||||
number_in_bin_(initiate4DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
sync_time_in_bin_s_(initiate5DArray<double>(
|
||||
sync_number_in_bin_(initiate4DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
deleted_particles_(initiate5DArray<long int>(
|
||||
density_per_m3_(initiate3DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
sync_deleted_particles_(initiate5DArray<long int>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(pitch_angle_binning.binIndexMin(),
|
||||
pitch_angle_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
energy_binning.binIndexMax()))),
|
||||
density_per_m3_(initiate4DArray<double>(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
blitz::Range(energy_binning.binIndexMin(),
|
||||
@@ -117,8 +97,6 @@ DynamicDensityField::DynamicDensityField(
|
||||
bin_volume_m3_(initiateVolumeArray(
|
||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||
position_binning.radial_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||
position_binning.azimuth_binning.binIndexMax()),
|
||||
blitz::Range(position_binning.longitudinal_binning.binIndexMin(),
|
||||
position_binning.longitudinal_binning.binIndexMax()),
|
||||
position_binning.stepsize())) {
|
||||
@@ -128,80 +106,61 @@ DynamicDensityField::DynamicDensityField(
|
||||
}
|
||||
|
||||
double DynamicDensityField::density(const Coordinate& position) {
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
const blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
const double t = timer_->getDeltaT();
|
||||
#ifdef debug_level1
|
||||
blitz::Array<double, 4> check = density_per_m3_.copy();
|
||||
recalculateDensityArray();
|
||||
if(!blitz::all(check == density_per_m3_)) {
|
||||
ERROR("Density changes after recalculateDensityArray!");
|
||||
}
|
||||
#endif
|
||||
|
||||
return blitz::sum(density_per_m3_(position_bin(0), position_bin(1),
|
||||
blitz::Range::all()));
|
||||
|
||||
/*/
|
||||
// const double t = timer_->getDeltaT();
|
||||
const double time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), blitz::Range::all()));
|
||||
const long int deleted_particles = blitz::sum(deleted_particles_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), blitz::Range::all()));
|
||||
// const long int deleted_particles = blitz::sum(deleted_particles_(
|
||||
// position_bin(0), position_bin(1), position_bin(2),
|
||||
// blitz::Range::all(), blitz::Range::all()));
|
||||
|
||||
return (time_in_bin / t - deleted_particles) /
|
||||
return (time_in_bin) / //- deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1), position_bin(2));
|
||||
*/
|
||||
}
|
||||
|
||||
double DynamicDensityField::density(const Coordinate& position,
|
||||
double energy_eV) {
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
const blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
const double t = timer_->getDeltaT();
|
||||
const double time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), energy_bin));
|
||||
const long deleted_particles = blitz::sum(deleted_particles_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), energy_bin));
|
||||
// const double t = timer_->getDeltaT();
|
||||
const double number_in_bin = blitz::sum(number_in_bin_(
|
||||
position_bin(0), position_bin(1), blitz::Range::all(), energy_bin));
|
||||
// const long deleted_particles = blitz::sum(deleted_particles_(
|
||||
// position_bin(0), position_bin(1), position_bin(2),
|
||||
// blitz::Range::all(), energy_bin));
|
||||
|
||||
return (time_in_bin / t - deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1), position_bin(2));
|
||||
}
|
||||
|
||||
double DynamicDensityField::density(const Coordinate& position,
|
||||
double energy_split,
|
||||
bool above) {
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
const int energy_split_bin = energy_binning_.bin(energy_split);
|
||||
|
||||
blitz::Range range;
|
||||
|
||||
if(above) {
|
||||
range = blitz::Range(energy_split_bin, energy_binning_.binIndexMax());
|
||||
} else {
|
||||
if(energy_split_bin == energy_binning_.binIndexMin())
|
||||
return 0;
|
||||
range = blitz::Range(energy_binning_.binIndexMin(), energy_split_bin-1);
|
||||
}
|
||||
|
||||
const double t = timer_->getDeltaT();
|
||||
const double time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), range));
|
||||
const long deleted_particles = blitz::sum(deleted_particles_(
|
||||
position_bin(0), position_bin(1), position_bin(2),
|
||||
blitz::Range::all(), range));
|
||||
|
||||
return (time_in_bin / t - deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1), position_bin(2));
|
||||
return (number_in_bin) / // - deleted_particles) /
|
||||
bin_volume_m3_(position_bin(0), position_bin(1));
|
||||
}
|
||||
|
||||
bool DynamicDensityField::changedPositionBin(
|
||||
const Coordinate& old_position,
|
||||
const Coordinate& new_position) const {
|
||||
const blitz::TinyVector<int, 3> old_bin =
|
||||
const blitz::TinyVector<int, 2> old_bin =
|
||||
position_binning_.bin(old_position.cylinderEntries());
|
||||
|
||||
const blitz::TinyVector<int, 3> new_bin =
|
||||
const blitz::TinyVector<int, 2> new_bin =
|
||||
position_binning_.bin(new_position.cylinderEntries());
|
||||
|
||||
return !((old_bin(0) == new_bin(0)) && (old_bin(1) == new_bin(1)) &&
|
||||
(old_bin(2) == new_bin(2)));
|
||||
return !((old_bin(0) == new_bin(0)) && (old_bin(1) == new_bin(1)));
|
||||
}
|
||||
|
||||
bool DynamicDensityField::changedEnergyBin(double old_energy_eV,
|
||||
@@ -216,12 +175,14 @@ bool DynamicDensityField::changedPitchAngleBin(double old_mu,
|
||||
const int old_bin = pitch_angle_binning_.bin(old_mu);
|
||||
const int new_bin = pitch_angle_binning_.bin(new_mu);
|
||||
|
||||
#ifdef debug_level3
|
||||
if(!(old_bin == new_bin)) {
|
||||
DEBUG_LEVEL_3("old mu: " + std::to_string(old_mu));
|
||||
DEBUG_LEVEL_3("old bin: " + std::to_string(old_bin));
|
||||
DEBUG_LEVEL_3("new mu: " + std::to_string(new_mu));
|
||||
DEBUG_LEVEL_3("new bin: " + std::to_string(new_bin));
|
||||
}
|
||||
#endif
|
||||
|
||||
return !(old_bin == new_bin);
|
||||
}
|
||||
@@ -229,97 +190,50 @@ bool DynamicDensityField::changedPitchAngleBin(double old_mu,
|
||||
void DynamicDensityField::logMovement(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle,
|
||||
double time_in_bin_s) {
|
||||
double weight) {
|
||||
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
const blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
||||
|
||||
time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||
pitch_angle_bin, energy_bin) += time_in_bin_s;
|
||||
sync_number_in_bin_(position_bin(0), position_bin(1),
|
||||
pitch_angle_bin, energy_bin) += weight;
|
||||
}
|
||||
|
||||
void DynamicDensityField::logDeletion(const Coordinate& position,
|
||||
double energy_eV,
|
||||
double pitch_angle) {
|
||||
|
||||
const blitz::TinyVector<int, 3> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
const int energy_bin = energy_binning_.bin(energy_eV);
|
||||
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
||||
|
||||
deleted_particles_(position_bin(0), position_bin(1), position_bin(2), pitch_angle_bin,
|
||||
energy_bin) += 1;
|
||||
return;
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> DynamicDensityField::densityArray() {
|
||||
blitz::Array<double, 2> DynamicDensityField::densityArray() {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("recalc Density array");
|
||||
recalculateDensityArray();
|
||||
#endif
|
||||
// recalculated after a timestep reset (as of now hope that's enough and works correctly)
|
||||
// recalculateDensityArray();
|
||||
|
||||
blitz::TinyVector<int,3> lowerbound(density_per_m3_.lbound(0),
|
||||
density_per_m3_.lbound(1),
|
||||
density_per_m3_.lbound(2));
|
||||
blitz::TinyVector<int,3> extent(density_per_m3_.extent(0),
|
||||
density_per_m3_.extent(1),
|
||||
density_per_m3_.extent(2));
|
||||
blitz::Array<double, 3> density(lowerbound, extent);
|
||||
blitz::TinyVector<int,2> lowerbound(density_per_m3_.lbound(0),
|
||||
density_per_m3_.lbound(1));
|
||||
blitz::TinyVector<int,2> extent(density_per_m3_.extent(0),
|
||||
density_per_m3_.extent(1));
|
||||
blitz::Array<double, 2> density(lowerbound, extent);
|
||||
|
||||
blitz::fourthIndex iE;
|
||||
DEBUG_LEVEL_3("density sum");
|
||||
blitz::thirdIndex iE;
|
||||
// DEBUG_LEVEL_3("density sum");
|
||||
density = blitz::sum(density_per_m3_, iE);
|
||||
return density.copy();
|
||||
}
|
||||
|
||||
blitz::Array<double, 3> DynamicDensityField::densityArray(
|
||||
double energy_split, bool above) {
|
||||
DEBUG_LEVEL_3("recalc Density array");
|
||||
recalculateDensityArray();
|
||||
|
||||
const int energy_split_bin = energy_binning_.bin(energy_split);
|
||||
|
||||
blitz::TinyVector<int,3> lowerbound(density_per_m3_.lbound(0),
|
||||
density_per_m3_.lbound(1),
|
||||
density_per_m3_.lbound(2));
|
||||
blitz::TinyVector<int,3> extent(density_per_m3_.extent(0),
|
||||
density_per_m3_.extent(1),
|
||||
density_per_m3_.extent(2));
|
||||
blitz::Array<double, 3> density(lowerbound, extent);
|
||||
density = 0;
|
||||
|
||||
blitz::Range range;
|
||||
if(above) {
|
||||
range = blitz::Range(energy_split_bin, energy_binning_.binIndexMax());
|
||||
} else {
|
||||
if(energy_split_bin == energy_binning_.binIndexMin())
|
||||
return density;
|
||||
range = blitz::Range(energy_binning_.binIndexMin(), energy_split_bin-1);
|
||||
}
|
||||
|
||||
blitz::Range all = blitz::Range::all();
|
||||
|
||||
blitz::fourthIndex iE;
|
||||
DEBUG_LEVEL_3("density sum");
|
||||
density = blitz::sum(density_per_m3_(all, all, all, range), iE);
|
||||
|
||||
return density.copy();
|
||||
}
|
||||
|
||||
blitz::Array<double, 4> DynamicDensityField::spectrumArray() {
|
||||
recalculateDensityArray();
|
||||
blitz::Array<double, 3> DynamicDensityField::spectrumArray() {
|
||||
// recalculateDensityArray();
|
||||
return density_per_m3_;
|
||||
}
|
||||
|
||||
blitz::Array<double, 5> DynamicDensityField::timeInBinArray() const {
|
||||
return time_in_bin_s_;
|
||||
blitz::Array<double, 4> DynamicDensityField::numberInBinArray() const {
|
||||
return number_in_bin_;
|
||||
}
|
||||
|
||||
blitz::Array<long int, 5> DynamicDensityField::deletedParticlesArray() const {
|
||||
return deleted_particles_;
|
||||
}
|
||||
// blitz::Array<long int, 5> DynamicDensityField::deletedParticlesArray() const {
|
||||
// return deleted_particles_;
|
||||
// }
|
||||
|
||||
blitz::Array<double, 3> DynamicDensityField::binVolumeArray() const {
|
||||
blitz::Array<double, 2> DynamicDensityField::binVolumeArray() const {
|
||||
return bin_volume_m3_;
|
||||
}
|
||||
|
||||
@@ -346,88 +260,52 @@ double DynamicDensityField::timeResolution() const {
|
||||
void DynamicDensityField::recalculateDensityArray() {
|
||||
// SimulationTimer::eventStartPoint("recalcDensityArray");
|
||||
blitz::firstIndex ir;
|
||||
blitz::secondIndex iphi;
|
||||
blitz::thirdIndex iz;
|
||||
blitz::fourthIndex ipitch;
|
||||
blitz::fifthIndex iE;
|
||||
|
||||
const double t = timer_->getDeltaT();
|
||||
blitz::secondIndex iz;
|
||||
blitz::thirdIndex ipitch;
|
||||
blitz::fourthIndex iE;
|
||||
|
||||
// reduction only seems to work for the last dimension (iE)
|
||||
// -> first reorder (by exchanging iE and ipitch) and afterwards doing
|
||||
// the reduction over iE (which now contains the pitch dimension)
|
||||
// blitz::Array<double, 5> temp((time_in_bin_s_(ir, iphi, iz, ipitch, iE)));
|
||||
|
||||
density_per_m3_ = blitz::sum((time_in_bin_s_(ir, iphi, iz, iE, ipitch) / t -
|
||||
deleted_particles_(ir, iphi, iz, iE, ipitch)), iE) /
|
||||
bin_volume_m3_(ir, iphi, iz);
|
||||
density_per_m3_ = blitz::sum((number_in_bin_(ir, iz, iE, ipitch)), iE) /
|
||||
bin_volume_m3_(ir, iz);
|
||||
// SimulationTimer::eventStopPoint("recalcDensityArray");
|
||||
}
|
||||
|
||||
double DynamicDensityField::particleNumber() {
|
||||
blitz::Array<double, 3> density = densityArray();
|
||||
double particleNumber = blitz::sum(density * bin_volume_m3_);
|
||||
DEBUG_LEVEL_3("particle number: " + std::to_string(particleNumber));
|
||||
return particleNumber;
|
||||
}
|
||||
|
||||
double DynamicDensityField::particleNumber(double E_thresh, bool above) {
|
||||
const int energy_bin = energy_binning_.bin(E_thresh);
|
||||
|
||||
double time_in_bin = 0;
|
||||
double deleted_particles = 0;
|
||||
|
||||
blitz::Range range;
|
||||
|
||||
if(above) {
|
||||
range = blitz::Range(energy_bin, energy_binning_.binIndexMax());
|
||||
} else {
|
||||
if(energy_bin == energy_binning_.binIndexMin())
|
||||
return 0;
|
||||
range = blitz::Range(energy_binning_.binIndexMin(), energy_bin-1);
|
||||
}
|
||||
|
||||
time_in_bin = blitz::sum(time_in_bin_s_(
|
||||
blitz::Range::all(), blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all(), range));
|
||||
|
||||
deleted_particles = blitz::sum(deleted_particles_(
|
||||
blitz::Range::all(), blitz::Range::all(), blitz::Range::all(),
|
||||
blitz::Range::all(), range));
|
||||
|
||||
const double t = timer_->getDeltaT();
|
||||
|
||||
return (time_in_bin / t - deleted_particles);
|
||||
}
|
||||
|
||||
blitz::Array<double, 1> DynamicDensityField::
|
||||
sliceSpectrumArray(const Coordinate& position) const {
|
||||
blitz::TinyVector<int, 3> position_bin =
|
||||
// in a specific bin the "density" across E is proportional to the
|
||||
// particle number
|
||||
blitz::Array<double, 1> DynamicDensityField::sliceSpectrumArray(
|
||||
const Coordinate& position) const {
|
||||
blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
|
||||
// blitz::Array<double, 4> check = density_per_m3_.copy();
|
||||
// recalculateDensityArray();
|
||||
// if(!blitz::all(check == density_per_m3_)) {
|
||||
// ERROR("splice specturm array: check failed.");
|
||||
// }
|
||||
|
||||
return density_per_m3_(position_bin(0), position_bin(1), position_bin(2),
|
||||
return density_per_m3_(position_bin(0), position_bin(1),
|
||||
blitz::Range(energy_binning_.binIndexMin(),
|
||||
energy_binning_.binIndexMax()-1)).copy();
|
||||
energy_binning_.binIndexMax()-1));
|
||||
}
|
||||
|
||||
blitz::Array<double, 1> DynamicDensityField::
|
||||
sliceTimeInBinArray(const Coordinate& position, double energy_eV) const {
|
||||
blitz::TinyVector<int, 3> position_bin =
|
||||
blitz::Array<double, 1> DynamicDensityField::sliceNumberInBinArray(
|
||||
const Coordinate& position, double energy_eV) const {
|
||||
blitz::TinyVector<int, 2> position_bin =
|
||||
position_binning_.bin(position.cylinderEntries());
|
||||
int energy_bin = energy_binning_.bin(energy_eV);
|
||||
|
||||
return time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||
return number_in_bin_(position_bin(0), position_bin(1),
|
||||
blitz::Range(0, pitch_angle_binning_.binIndexMax()-1),
|
||||
energy_bin).copy();
|
||||
energy_bin);
|
||||
}
|
||||
|
||||
// resets the field that logs the new density
|
||||
void DynamicDensityField::resetDynamicDensityField() {
|
||||
//timer_->resetTime(); // time stays global
|
||||
time_in_bin_s_ = 0.;
|
||||
deleted_particles_ = 0.;
|
||||
density_per_m3_ = 0.;
|
||||
sync_time_in_bin_s_ = 0.;
|
||||
sync_deleted_particles_ = 0.;
|
||||
sync_number_in_bin_ = 0.;
|
||||
}
|
||||
|
||||
void DynamicDensityField::restartTimer(double time, double delta_t) {
|
||||
@@ -441,28 +319,28 @@ void DynamicDensityField::restartTimer(double time, double delta_t) {
|
||||
timer_->setDeltaT(delta_t);
|
||||
}
|
||||
|
||||
void DynamicDensityField::restartTimeInBin(blitz::Array<double, 5> time_in_bin) {
|
||||
if(!blitz::all(time_in_bin_s_.length() == time_in_bin.length())) {
|
||||
void DynamicDensityField::restartNumberInBin(blitz::Array<double, 4> number_in_bin) {
|
||||
if(!blitz::all(number_in_bin_.length() == number_in_bin.length())) {
|
||||
std::stringstream out;
|
||||
out << "Expected a size of " << time_in_bin_s_.length();
|
||||
out << ", received a length of " << time_in_bin.length();
|
||||
out << "Expected a size of " << number_in_bin_.length();
|
||||
out << ", received a length of " << number_in_bin.length();
|
||||
out << " for time_in_bin array";
|
||||
ERROR(out.str());
|
||||
}
|
||||
time_in_bin_s_ = time_in_bin.copy().reindex(time_in_bin_s_.lbound());
|
||||
number_in_bin_ = number_in_bin.copy().reindex(number_in_bin_.lbound());
|
||||
}
|
||||
|
||||
void DynamicDensityField::restartDeletedParticlesArray(
|
||||
blitz::Array<long int, 5> deleted_particles) {
|
||||
if(!blitz::all(deleted_particles_.length() == deleted_particles.length())) {
|
||||
std::stringstream out;
|
||||
out << "Expected a size of " << deleted_particles_.length();
|
||||
out << ", received a length of " << deleted_particles.length();
|
||||
out << " for deleted_particles array";
|
||||
ERROR(out.str());
|
||||
}
|
||||
deleted_particles_ = deleted_particles.copy().reindex(deleted_particles_.lbound());
|
||||
}
|
||||
// void DynamicDensityField::restartDeletedParticlesArray(
|
||||
// blitz::Array<long int, 5> deleted_particles) {
|
||||
// if(!blitz::all(deleted_particles_.length() == deleted_particles.length())) {
|
||||
// std::stringstream out;
|
||||
// out << "Expected a size of " << deleted_particles_.length();
|
||||
// out << ", received a length of " << deleted_particles.length();
|
||||
// out << " for deleted_particles array";
|
||||
// ERROR(out.str());
|
||||
// }
|
||||
// deleted_particles_ = deleted_particles.copy().reindex(deleted_particles_.lbound());
|
||||
// }
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -8,3 +8,8 @@ DriftVelocity::DriftVelocity(std::shared_ptr<VectorField> drift_velocity)
|
||||
CartesianVector DriftVelocity::driftVelocity(const Coordinate& position) {
|
||||
return CartesianVector(drift_velocity_->value(position), position);
|
||||
}
|
||||
|
||||
CartesianVector DriftVelocity::driftVelocity(const CartesianCoordinate& cartPos,
|
||||
const CylinderCoordinate& cylPos) {
|
||||
return CartesianVector(drift_velocity_->value(cylPos), cartPos);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "simulation/energy_binning.h"
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
std::vector<double> generateLogBinBorders(double bin_min,
|
||||
double bin_max,
|
||||
@@ -24,10 +26,11 @@ std::vector<double> generateLinearBinBorders(double bin_min,
|
||||
const double bin_size = (bin_max - bin_min) / num_bins;
|
||||
|
||||
std::vector<double> bin_borders;
|
||||
for (int i = 0; i <= num_bins; ++i) {
|
||||
for (int i = 0; i < num_bins; ++i) {
|
||||
const double bin_border = bin_size * i + bin_min;
|
||||
bin_borders.push_back(bin_border);
|
||||
}
|
||||
bin_borders.push_back(bin_max);
|
||||
return bin_borders;
|
||||
}
|
||||
|
||||
@@ -66,18 +69,24 @@ PitchAngleBinning::PitchAngleBinning(int num_bins) :
|
||||
pitch_angle_bin_borders_(generateLinearBinBorders(-1, 1, num_bins)) {}
|
||||
|
||||
int PitchAngleBinning::bin(double pitch_angle) const {
|
||||
|
||||
auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(),
|
||||
pitch_angle_bin_borders_.end(),
|
||||
pitch_angle);
|
||||
// otherwise the valid mu-value of -1 is assigned to the underflow
|
||||
// auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(),
|
||||
// pitch_angle_bin_borders_.end(),
|
||||
// pitch_angle);
|
||||
int bin = static_cast<int>((pitch_angle + 1)/2 * numBins());
|
||||
// otherwise the valid mu-value of -1 is assigned to the underflow
|
||||
// bin which can lead to a segfault in the drawing of the pitch
|
||||
// angle in "velocity_distribution.cpp"
|
||||
if(!(pitch_angle < pitch_angle_bin_borders_.front()) &&
|
||||
(it == pitch_angle_bin_borders_.begin())) {
|
||||
return (it - pitch_angle_bin_borders_.begin());
|
||||
// if(!(pitch_angle < pitch_angle_bin_borders_.front()) &&
|
||||
// (it == pitch_angle_bin_borders_.begin())) {
|
||||
// return (it - pitch_angle_bin_borders_.begin());
|
||||
// }
|
||||
// return (it - pitch_angle_bin_borders_.begin()) - 1;
|
||||
// exclude mu=1 from the overflow bin
|
||||
if (bin == numBins() && pitch_angle <= 1) {
|
||||
bin--;
|
||||
}
|
||||
return (it - pitch_angle_bin_borders_.begin()) - 1;
|
||||
|
||||
return bin;
|
||||
}
|
||||
|
||||
int PitchAngleBinning::numBins() const {
|
||||
|
||||
@@ -27,6 +27,31 @@ double TritiumBetaDecay::rollEnergy(std::mt19937* engine) {
|
||||
return random_number_x;
|
||||
}
|
||||
|
||||
// endpoint_eV is the recoil energy of the target species for an electron
|
||||
// energy at 18.6keV (i.e. the endpoint energy of the electron distribution)
|
||||
TritiumBetaDecayIon::TritiumBetaDecayIon(double endpoint_eV)
|
||||
: x_distribution_(
|
||||
std::uniform_real_distribution<double>(0., T2BetaDecay::E0_T)),
|
||||
y_distribution_(std::uniform_real_distribution<double>(
|
||||
0.,
|
||||
T2BetaDecay::spectrum_maximum)),
|
||||
tritium_spectrum_(tritiumDecayEnergySpectrum(1.)),
|
||||
tritium_spectrum_ion_(tritiumDecayEnergySpectrumIon(endpoint_eV)) {}
|
||||
|
||||
// due to not great structure, draw a(nother) electron energy to inject
|
||||
// the ion at the corresponding (approximated) energy
|
||||
double TritiumBetaDecayIon::rollEnergy(std::mt19937* engine) {
|
||||
double random_number_x;
|
||||
double random_number_y;
|
||||
double return_value;
|
||||
do {
|
||||
random_number_x = x_distribution_(*engine);
|
||||
random_number_y = y_distribution_(*engine);
|
||||
} while (random_number_y > tritium_spectrum_(random_number_x));
|
||||
|
||||
return tritium_spectrum_ion_(random_number_x);
|
||||
}
|
||||
|
||||
MaxwellBoltzmann::MaxwellBoltzmann(double temperature_K)
|
||||
: distribution_(std::gamma_distribution<double>(
|
||||
3. / 2.,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "simulation/event_position_distribution.h"
|
||||
#include "simulation/errors.h"
|
||||
|
||||
EventPositionDistribution::EventPositionDistribution(
|
||||
std::shared_ptr<ScalarField> mother_density,
|
||||
@@ -17,8 +16,7 @@ EventPositionDistribution::EventPositionDistribution(
|
||||
density_values(
|
||||
std::uniform_real_distribution<double>(density.min, density.max)) {}
|
||||
|
||||
CylinderCoordinate EventPositionDistribution::rollPosition(
|
||||
std::mt19937* engine) {
|
||||
CylinderCoordinate EventPositionDistribution::rollPosition(std::mt19937* engine) {
|
||||
double random_number_z;
|
||||
double random_numer_r;
|
||||
double random_number_phi;
|
||||
@@ -39,95 +37,4 @@ CylinderCoordinate EventPositionDistribution::rollPosition(
|
||||
|
||||
return CylinderCoordinate(blitz::TinyVector<double, 3>(
|
||||
random_numer_r, random_number_phi, random_number_z));
|
||||
}
|
||||
|
||||
PositionDistributionFromDensity::PositionDistributionFromDensity(
|
||||
std::shared_ptr<DynamicDensityField> density):
|
||||
density_(density),
|
||||
density_values(std::uniform_real_distribution<double>(0.,1.)) {
|
||||
|
||||
// get the extent of the domain of the DynamicDensityField object to be used for
|
||||
// the rejection method
|
||||
double rmin = density->positionBinning()->radial_binning.binBorders().front();
|
||||
double rmax = density->positionBinning()->radial_binning.binBorders().back();
|
||||
|
||||
double phimin = 0;
|
||||
double phimax = 2*M_PI;
|
||||
|
||||
double zmin = density->positionBinning()->longitudinal_binning.binBorders().front();
|
||||
double zmax = density->positionBinning()->longitudinal_binning.binBorders().back();
|
||||
|
||||
// initialize the distributions
|
||||
r_values = std::uniform_real_distribution<double>(rmin*rmin, rmax*rmax);
|
||||
phi_values = std::uniform_real_distribution<double>(phimin, phimax);
|
||||
z_values = std::uniform_real_distribution<double>(zmin, zmax);
|
||||
|
||||
}
|
||||
|
||||
void PositionDistributionFromDensity::setMaximumDensity() {
|
||||
maximum_density_ = blitz::max(density_->densityArray());
|
||||
}
|
||||
|
||||
void PositionDistributionFromDensity::setMaximumDensityAboveAndBelow(
|
||||
double energy_split) {
|
||||
maximum_density_below_ = blitz::max(
|
||||
density_->densityArray(energy_split, false));
|
||||
maximum_density_above_ = blitz::max(
|
||||
density_->densityArray(energy_split, true));
|
||||
}
|
||||
|
||||
CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* engine) {
|
||||
if(isEqual(maximum_density_, 0.)) {
|
||||
// abuse the phi coordinate as a check if the density was zero
|
||||
// only works if phi \in (0, 2pi)
|
||||
return CylinderCoordinate(blitz::TinyVector<double,3>(0,-1,0));
|
||||
}
|
||||
|
||||
double random_r, random_phi, random_z, random_n;
|
||||
|
||||
do {
|
||||
random_r = std::sqrt(r_values(*engine));
|
||||
random_phi = phi_values(*engine);
|
||||
random_z = z_values(*engine);
|
||||
random_n = density_values(*engine);
|
||||
// might be bad that the value gets recalculated for each call of density_->density(...)
|
||||
} while (random_n*maximum_density_ > density_->density(CylinderCoordinate(
|
||||
blitz::TinyVector<double,3>(random_r, random_phi, random_z))));
|
||||
|
||||
return CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3>(random_r, random_phi, random_z));
|
||||
}
|
||||
|
||||
CylinderCoordinate PositionDistributionFromDensity::drawPosition(
|
||||
std::mt19937* engine, double energy_split, bool above) {
|
||||
const double max_density = above ? maximum_density_above_ : maximum_density_below_;
|
||||
if(isEqual(max_density, 0.)) {
|
||||
// abuse the phi coordinate as a check if the density was zero
|
||||
// only works if phi \in (0, 2pi)
|
||||
return CylinderCoordinate(blitz::TinyVector<double,3>(0,-1,0));
|
||||
}
|
||||
|
||||
double random_r, random_phi, random_z, random_n;
|
||||
double density_at_position;
|
||||
|
||||
// std::stringstream out;
|
||||
// above ? out << "Above: " : out << "Below: ";
|
||||
// out << "densities: ";
|
||||
|
||||
do {
|
||||
random_r = std::sqrt(r_values(*engine));
|
||||
random_phi = phi_values(*engine);
|
||||
random_z = z_values(*engine);
|
||||
random_n = density_values(*engine);
|
||||
density_at_position = density_->density(CylinderCoordinate(
|
||||
blitz::TinyVector<double,3>(random_r, random_phi, random_z)),
|
||||
energy_split, above);
|
||||
// out << density_at_position << "\n";
|
||||
// might be bad that the value gets recalculated for each call of density_->density(...)
|
||||
} while (random_n*max_density > density_at_position);
|
||||
|
||||
// DEBUG_LEVEL_2(out.str());
|
||||
|
||||
return CylinderCoordinate(
|
||||
blitz::TinyVector<double, 3>(random_r, random_phi, random_z));
|
||||
}
|
||||
+45
-170
@@ -9,7 +9,7 @@
|
||||
#include "simulation/density_field.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
#include "simulation/electromagnetic_field.h"
|
||||
#include "constants/ionization_constants.h"
|
||||
#include "simulation/random_numbers.h"
|
||||
#include <sstream>
|
||||
|
||||
Injector::Injector(
|
||||
@@ -20,8 +20,7 @@ Injector::Injector(
|
||||
: injector_infos_(injector_info),
|
||||
activity_(activity),
|
||||
position_distribution_(position_distribution),
|
||||
mother_drift_velocity_(mother_drift_velocity),
|
||||
energySplit_(ionization::ionization_energy_janev_atomic) {
|
||||
mother_drift_velocity_(mother_drift_velocity) {
|
||||
ASSERT_POSITIVE(&activity_, "Injector: Activity must be positive");
|
||||
ASSERT_EXISTS(&position_distribution_,
|
||||
"Injector: The position distribution is null.");
|
||||
@@ -59,185 +58,61 @@ void Injector::initInjectionTimeDistribution(double delta_t) {
|
||||
}
|
||||
|
||||
std::vector<particle::Particle> Injector::rollNewParticles(
|
||||
std::mt19937* engine, const double current_time,
|
||||
const double beta_particle_weight) {
|
||||
std::mt19937* engine, const int timestep) {
|
||||
|
||||
std::vector<particle::Particle> new_particles;
|
||||
|
||||
const double time_birth = current_time - injection_time_distribution_(*engine);
|
||||
const double time_birth = injection_time_distribution_(*engine);
|
||||
|
||||
for (auto& injector_info : injector_infos_) {
|
||||
|
||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
|
||||
new_particles.push_back(
|
||||
rollNewParticle(engine, position, injector_info.created_specie,
|
||||
injector_info.creation_velocity_distribution,
|
||||
time_birth, beta_particle_weight));
|
||||
if((timestep % injector_info.injection_stride) == injector_info.injection_group) {
|
||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
#endif
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0(std::to_string(MpiCommunication::mpi_rank) + ": injection "
|
||||
+ injector_info.created_specie->name() + " at "
|
||||
"timestep " + std::to_string(timestep));
|
||||
#endif
|
||||
new_particles.push_back(
|
||||
rollNewParticle(engine, position, injector_info.created_specie,
|
||||
injector_info.creation_velocity_distribution,
|
||||
time_birth, injector_info.weight));
|
||||
}
|
||||
}
|
||||
return new_particles;
|
||||
}
|
||||
|
||||
void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::vector<particle::Particle>& queue,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const double weight_factor,
|
||||
const double injection_time) {
|
||||
void Injector::setWeights(const double physical_number, const int numerical_number) {
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << "Weights:\n";
|
||||
#endif
|
||||
int groupsize;
|
||||
|
||||
if(specie->type() == species::ImplementedSpecies::electron) {
|
||||
|
||||
if(!(particleNumbersMap_[specie->name()][1] == 0))
|
||||
queue.push_back(drawNewDensityParticleAboveOrBelow(engine, specie,
|
||||
magnetic_field, weight_factor, injection_time, true));
|
||||
if(!(particleNumbersMap_[specie->name()][0] == 0))
|
||||
queue.push_back(drawNewDensityParticleAboveOrBelow(engine, specie,
|
||||
magnetic_field, weight_factor, injection_time, false));
|
||||
return;
|
||||
for(auto& injector_info : injector_infos_) {
|
||||
groupsize = MpiCommunication::mpi_size / injector_info.injection_stride;
|
||||
if((MpiCommunication::mpi_size - groupsize * injector_info.injection_stride)
|
||||
> injector_info.injection_group) {
|
||||
groupsize += 1;
|
||||
}
|
||||
injector_info.weight = physical_number / static_cast<double>(numerical_number *
|
||||
groupsize);
|
||||
#ifdef debug
|
||||
out << "\t" << injector_info.created_specie->name();
|
||||
out << ": " << injector_info.weight;
|
||||
out << " (group: " << injector_info.injection_group;
|
||||
out << ", size: " << groupsize;
|
||||
out << ")\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
if(particleNumbersMap_[specie->name()][0] == 0) {
|
||||
return;
|
||||
}
|
||||
// draw the position
|
||||
CylinderCoordinate position =
|
||||
specie->positionDistributionFromDensity()->drawPosition(engine);
|
||||
|
||||
// check if density was empty (i.e. phi value lower than 0)
|
||||
if (position.cylinderEntries()(1) < 0) {
|
||||
DEBUG_LEVEL_3(specie->name() + ": has zero density");
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LEVEL_3("Injected z position: " +
|
||||
std::to_string(position.cylinderEntries()(2)));
|
||||
DEBUG_LEVEL_3("Injected r position: " +
|
||||
std::to_string(position.cylinderEntries()(0)));
|
||||
|
||||
// draw the velocity
|
||||
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
||||
|
||||
// in case the magnetic field is 0 at the current position draw the velocity
|
||||
// with respect to the z-axis otherwise use the magnetic field
|
||||
if(kinematic::norm(magnetic_field->value(position).
|
||||
cartesianEntries(position)) == 0) {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
rollVelocity(position, engine);
|
||||
} else {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
rollVelocity(position, engine, magnetic_field);
|
||||
}
|
||||
|
||||
particle::Particle drawn_particle(specie, position,
|
||||
velocity, injection_time, weight_factor*particleNumbersMap_[specie->name()][0]);
|
||||
|
||||
queue.push_back(drawn_particle);
|
||||
#ifdef debug
|
||||
DEBUG(out.str());
|
||||
#endif
|
||||
}
|
||||
|
||||
double Injector::timePassed() const {
|
||||
return 1 / activity_;
|
||||
}
|
||||
|
||||
void Injector::fillParticleNumbers(std::shared_ptr<species::TrackedSpecie> specie) {
|
||||
// std::stringstream out;
|
||||
// out << specie->name() << ":";
|
||||
std::vector<double> numbers;
|
||||
double nTot = 0;
|
||||
if(specie->type() == species::ImplementedSpecies::electron) {
|
||||
double numberBelow = specie->densityForDrawing()->particleNumber(
|
||||
energySplit_, false);
|
||||
numbers.push_back(numberBelow);
|
||||
double numberAbove = specie->densityForDrawing()->particleNumber(
|
||||
energySplit_, true);
|
||||
numbers.push_back(numberAbove);
|
||||
// out << "\n\tN( E < " << energySplit_<< ")"
|
||||
// << " = " << numberBelow;
|
||||
// out << "\n\tN( E > " << energySplit_<< ")"
|
||||
// << " = " << numberAbove;
|
||||
nTot = numberBelow + numberAbove;
|
||||
} else {
|
||||
numbers.push_back(specie->densityForDrawing()->particleNumber());
|
||||
// out << numbers[0];
|
||||
nTot = numbers[0];
|
||||
}
|
||||
particleNumbersMap_[specie->name()] = numbers;
|
||||
// out << "\n\t N_total = " << nTot;
|
||||
|
||||
// DEBUG_LEVEL_2(out.str());
|
||||
}
|
||||
|
||||
particle::Particle Injector::drawNewDensityParticleAboveOrBelow(
|
||||
std::mt19937* engine,
|
||||
std::shared_ptr<species::TrackedSpecie> specie,
|
||||
std::shared_ptr<MagneticField> magnetic_field,
|
||||
const double weight_factor,
|
||||
const double injection_time,
|
||||
const bool above) {
|
||||
|
||||
std::string above_string = above ? "Above" : "Below";
|
||||
// std::stringstream out;
|
||||
// // draw the position
|
||||
// out << above_string << "\n";
|
||||
// out << "\tPosition: ";
|
||||
CylinderCoordinate position =
|
||||
specie->positionDistributionFromDensity()
|
||||
->drawPosition(engine, energySplit_, above);
|
||||
|
||||
// out << position.cylinderEntries();
|
||||
|
||||
double den_at_pos_below =
|
||||
specie->densityForDrawing()->density(position, energySplit_, false);
|
||||
// out << "\n\tDensity At position below: " << den_at_pos_below;
|
||||
|
||||
// check if density was empty (i.e. phi value lower than 0)
|
||||
if (position.cylinderEntries()(1) < 0) {
|
||||
ERROR(specie->name() + ": has zero density");
|
||||
}
|
||||
|
||||
// DEBUG_LEVEL_3("Injected z position: " +
|
||||
// std::to_string(position.cylinderEntries()(2)));
|
||||
// DEBUG_LEVEL_3("Injected r position: " +
|
||||
// std::to_string(position.cylinderEntries()(0)));
|
||||
|
||||
// draw the velocity
|
||||
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
||||
|
||||
const int energy_split_bin =
|
||||
specie->dynamicDensityField()->energyBinning()->bin(energySplit_);
|
||||
// out << "\n\tEnergy split bin: " << energy_split_bin;
|
||||
|
||||
// in case the magnetic field is 0 at the current position draw the velocity
|
||||
// with respect to the z-axis otherwise use the magnetic field
|
||||
if(kinematic::norm(magnetic_field->value(position).
|
||||
cartesianEntries(position)) == 0) {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
rollVelocity(position, engine, energy_split_bin, above);
|
||||
} else {
|
||||
velocity = specie->velocityDistributionFromDensityField()->
|
||||
rollVelocity(position, engine, magnetic_field,
|
||||
energy_split_bin,
|
||||
above);
|
||||
}
|
||||
|
||||
// out << "\n\tVelocity: " << velocity.cartesianEntries();
|
||||
|
||||
int index = above ? 1 : 0;
|
||||
// out << "\n\tWeight: " << weight_factor*particleNumbersMap_[specie->name()][index];
|
||||
|
||||
// out << "particleNumbersMap: ";
|
||||
// for(auto element : particleNumbersMap_[specie->name()])
|
||||
// out << element << " ";
|
||||
|
||||
|
||||
particle::Particle drawn_particle(specie, position,
|
||||
velocity, injection_time, weight_factor*particleNumbersMap_[specie->name()][index]);
|
||||
|
||||
// DEBUG_LEVEL_1(out.str());
|
||||
|
||||
return drawn_particle;
|
||||
}
|
||||
|
||||
double Injector::energySplit() const {
|
||||
return energySplit_;
|
||||
}
|
||||
@@ -29,11 +29,12 @@ std::vector<particle::Particle> InteractionOutput::newParticles() {
|
||||
|
||||
Interaction::Interaction(std::function<double(double)> cross_section,
|
||||
std::shared_ptr<species::Specie> target)
|
||||
: cross_section_(cross_section), target_(target) {}
|
||||
: cross_section_(cross_section), target_(target),
|
||||
target_velocity_(blitz::TinyVector<double, 3> (0,0,0)) {};
|
||||
|
||||
// assumes that v_particle >> v_target
|
||||
double Interaction::macroscopicCrossSection(particle::Particle& particle) {
|
||||
const auto x_particle = particle.position();
|
||||
const auto x_particle = particle.cylinderPosition();
|
||||
const blitz::TinyVector<double, 3> v_particle =
|
||||
particle.velocity().cartesianEntries();
|
||||
if(!target_->driftVelocity()) {
|
||||
@@ -52,13 +53,79 @@ double Interaction::macroscopicCrossSection(particle::Particle& particle) {
|
||||
UnitConversion::JouleToeV;
|
||||
|
||||
const double density = target_->densityField()->density(x_particle);
|
||||
const double cross_section = microscopicCrossSection(kinetic_energy_eV);
|
||||
const double cross_section = microscopicCrossSection(kinetic_energy_eV,
|
||||
particle.cylinderPosition());
|
||||
|
||||
return cross_section * density;
|
||||
};
|
||||
|
||||
double Interaction::microscopicCrossSection(double energy_eV) {
|
||||
double Interaction::microscopicCrossSection(double energy_eV,
|
||||
const Coordinate& position) {
|
||||
return cross_section_(energy_eV);
|
||||
}
|
||||
|
||||
// think i need to include the magnetic field for it to be really correct
|
||||
// also sets the velocity of the interaction partner
|
||||
double Interaction::drawCollisionTime(particle::Particle& particle,
|
||||
RandomNumbers* generator) {
|
||||
CartesianVector particle_velocity = particle.velocity();
|
||||
|
||||
// approximation for electrons: v_e >> v_t
|
||||
if(particle.specie()->type() == species::ImplementedSpecies::electron) {
|
||||
target_velocity_ = CartesianVector(blitz::TinyVector<double, 3>(0,0,0));
|
||||
} else {
|
||||
target_velocity_ = target_->velocityDistribution()->
|
||||
rollVelocity(particle.cylinderPosition(),
|
||||
generator->engine());
|
||||
|
||||
// // if no drift velocity is present, then assume target at rest otherwise
|
||||
// // use the drift velocity
|
||||
if(target_->driftVelocity()) {
|
||||
// auto tmp = target_->driftVelocity()->driftVelocity(particle.position());
|
||||
target_velocity_.add(target_->driftVelocity()->driftVelocity(
|
||||
particle.cartesianPosition(), particle.cylinderPosition()),
|
||||
particle.cartesianPosition());
|
||||
}
|
||||
}
|
||||
|
||||
// target_velocity_ = CartesianVector(blitz::TinyVector<double, 3>(0.,0.,0.));
|
||||
|
||||
// masses are irrelevant for the transformation
|
||||
const blitz::TinyVector<double, 3> velocity_target_fixed =
|
||||
kinematic::velocityTargetFixed(particle_velocity.cartesianEntries(),
|
||||
target_velocity_.cartesianEntries(), 0, 0);
|
||||
|
||||
const double relative_velocity = kinematic::norm(velocity_target_fixed);
|
||||
|
||||
// check if the relative velocity is smaller than an epsilon compared to the larger
|
||||
// of the two present velocities (to avoid division by 0 if either is 0) probably
|
||||
// a better version possible
|
||||
if(relative_velocity/std::max(
|
||||
kinematic::norm(particle_velocity.cartesianEntries()),
|
||||
kinematic::norm(target_velocity_.cartesianEntries())
|
||||
) < SimConstants::compare_epsilon) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double energy_eV =
|
||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
||||
UnitConversion::JouleToeV;
|
||||
|
||||
const double crosssection = microscopicCrossSection(energy_eV,
|
||||
particle.cylinderPosition());
|
||||
const double density = target_->densityField()->density(particle.cylinderPosition());
|
||||
|
||||
const double random_number = generator->rollUniform(0.,1.);
|
||||
if (random_number == 0) {
|
||||
return std::numeric_limits<double>::max();
|
||||
}
|
||||
|
||||
const double distance_target_fixed =
|
||||
- 1./(crosssection * density) * log(random_number);
|
||||
|
||||
const double time = distance_target_fixed / relative_velocity;
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
}; // namespace interaction
|
||||
@@ -50,6 +50,36 @@ blitz::TinyVector<double, 3> rotateVector(const blitz::TinyVector<double, 3>& v,
|
||||
}
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVector2(const blitz::TinyVector<double, 3>& v,
|
||||
double theta,
|
||||
double phi) {
|
||||
const double norm_value(norm(v));
|
||||
if (norm_value == 0) {
|
||||
return v;
|
||||
}
|
||||
const blitz::TinyVector<double, 3> n = v / norm_value;
|
||||
if (n(2) != -1) {
|
||||
double denominator = (1 + n(2));
|
||||
const double vx =
|
||||
((n(1)*n(1)/denominator + n(2))* std::cos(phi) - n(0)*n(1)/denominator
|
||||
* std::sin(phi)) * std::sin(theta) +
|
||||
n(0) * std::cos(theta);
|
||||
const double vy =
|
||||
((n(0)*n(0)/denominator + n(2))* std::sin(phi) - n(0)*n(1)/denominator
|
||||
* std::cos(phi)) * std::sin(theta) +
|
||||
n(1) * std::cos(theta);
|
||||
const double vz =
|
||||
n(2)*std::cos(theta) - (n(1) * std::sin(phi) + n(0)*std::cos(phi))
|
||||
*std::sin(theta);
|
||||
return blitz::TinyVector<double, 3>(vx, vy, vz) * norm_value;
|
||||
} else {
|
||||
const double vx = std::sin(theta) * std::cos(phi);
|
||||
const double vy = std::sin(theta) * std::sin(phi);
|
||||
const double vz = std::cos(theta);
|
||||
return -blitz::TinyVector<double, 3>(vx, vy, vz) * norm_value;
|
||||
}
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
|
||||
const blitz::TinyVector<double, 3>& velocity_1,
|
||||
const blitz::TinyVector<double, 3>& velocity_2,
|
||||
@@ -62,7 +92,7 @@ blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
|
||||
const blitz::TinyVector<double, 3> v1_in_center_of_mass_frame =
|
||||
velocity_1 - v_center_of_mass;
|
||||
const blitz::TinyVector<double, 3> v1_rot_in_center_of_mass_frame =
|
||||
rotateVector(v1_in_center_of_mass_frame, theta, phi);
|
||||
rotateVector2(v1_in_center_of_mass_frame, theta, phi);
|
||||
return v1_rot_in_center_of_mass_frame + v_center_of_mass;
|
||||
}
|
||||
|
||||
@@ -92,7 +122,7 @@ double velocity(double energy_eV, double mass_kg) {
|
||||
}
|
||||
|
||||
double relativisticGamma(const blitz::TinyVector<double, 3>& velocity) {
|
||||
return std::sqrt(1. + blitz::dot(velocity, velocity) / std::pow(SI::c, 2));
|
||||
return std::sqrt(1. + blitz::dot(velocity, velocity) / (SI::c*SI::c));
|
||||
}
|
||||
|
||||
double relativisticGamma(double kin_energy_eV, double mass_eV) {
|
||||
@@ -105,7 +135,8 @@ double relativisticBeta(double velocity_ms) {
|
||||
|
||||
double relativisticBeta(double kin_energy_eV, double mass_eV) {
|
||||
const double gamma = relativisticGamma(kin_energy_eV, mass_eV);
|
||||
return std::sqrt(1 - std::pow(1 / gamma, 2));
|
||||
// return std::sqrt(1 - std::pow(1 / gamma, 2));
|
||||
return std::sqrt(1 - 1 / (gamma*gamma));
|
||||
}
|
||||
|
||||
double relativisticMomentum(double energy_eV, double mass_eV) {
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
#include "simulation/logger.h"
|
||||
#include "simulation/coordinates.h"
|
||||
|
||||
DeletionLogger::DeletionLogger(std::vector<DeletionType> used_types) {
|
||||
DeletionLogger::DeletionLogger(std::vector<DeletionType> used_types,
|
||||
std::vector<PhysicalDeletionType> used_phys_types) {
|
||||
for (auto& type : used_types) {
|
||||
num_deletions[type] = 0;
|
||||
sync_num_deletions[type] = 0;
|
||||
// sync_num_deletions[type] = 0;
|
||||
}
|
||||
for (auto& type: used_phys_types) {
|
||||
num_phys_deletions[type] = 0.;
|
||||
// sync_num_phys_deletions[type] = 0.;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +20,21 @@ void DeletionLogger::logDeletion(const Coordinate& coordinate,
|
||||
}
|
||||
}
|
||||
|
||||
void DeletionLogger::logDeletion(const particle::Particle& particle,
|
||||
PhysicalDeletionType type) {
|
||||
if (num_phys_deletions.count(type) > 0) {
|
||||
num_phys_deletions.at(type) += particle.weight();
|
||||
}
|
||||
}
|
||||
|
||||
std::map<DeletionType, long int> DeletionLogger::numDeletions() const {
|
||||
return num_deletions;
|
||||
}
|
||||
|
||||
std::map<PhysicalDeletionType, double> DeletionLogger::numPhysDeletions() const {
|
||||
return num_phys_deletions;
|
||||
}
|
||||
|
||||
void DeletionLogger::numDeletions(long int new_value, DeletionType type) {
|
||||
if (num_deletions.count(type)) {
|
||||
num_deletions.at(type) = new_value;
|
||||
@@ -36,7 +53,13 @@ void DeletionLogger::resetDeletionLogger() {
|
||||
for(auto& pair : num_deletions) {
|
||||
pair.second = 0;
|
||||
}
|
||||
for (auto& pair : sync_num_deletions) {
|
||||
// for (auto& pair : sync_num_deletions) {
|
||||
// pair.second = 0;
|
||||
// }
|
||||
for(auto& pair : num_phys_deletions) {
|
||||
pair.second = 0;
|
||||
}
|
||||
// for (auto& pair : sync_num_phys_deletions) {
|
||||
// pair.second = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
+167
-110
@@ -19,123 +19,121 @@ BorisMover::BorisMover(double maximal_time_step_s)
|
||||
"The maximal timestep for boris push must be positive.");
|
||||
}
|
||||
|
||||
// TBD: include F_g (simply add to electric force)
|
||||
void BorisMover::move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
CylinderCoordinate BorisMover::move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) {
|
||||
|
||||
// DEBUG("start mover");
|
||||
// only useful if the timescale defined by the gyro frequency allows fast particles
|
||||
// to move too far
|
||||
// keep hard coded for now; has to be decided to be either kept (new field for Boris
|
||||
// mover in json file) or removed again
|
||||
const double max_distance = 1e-4;
|
||||
const double max_distance = 1e-3;
|
||||
const double delta_timeresolution = particle->specie()->
|
||||
dynamicDensityField()->timeResolution();
|
||||
// in order to try to minimize the overshoot in the time domain (i.e. if particle
|
||||
// can only life a time dt < min(distance/v, maximal_timestep), which might even be
|
||||
// a lot larger than dt, which would increase the influence of the particle on the
|
||||
// density)
|
||||
double max_time_alive = particle->specie()->dynamicDensityField()->physicalTime() -
|
||||
particle->timeAlive();
|
||||
double leftover_distance = mfp_m;
|
||||
double max_time_alive = delta_timeresolution - particle->timeAlive();
|
||||
double leftover_time = collision_time_s;
|
||||
|
||||
CartesianCoordinate old_position_cart = particle->cartesianPosition();
|
||||
CylinderCoordinate old_position_cyl = particle->cylinderPosition();
|
||||
|
||||
auto old_position = particle->position();
|
||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
blitz::TinyVector<double, 3> B_old =
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||
|
||||
double old_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_old) == 0) {
|
||||
old_mu = kinematic::cosPitchAngle(
|
||||
blitz::TinyVector<double, 3>(0,0,1),
|
||||
particle->velocity().cartesianEntries(old_position));
|
||||
blitz::TinyVector<double, 3> B =
|
||||
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
blitz::TinyVector<double, 3> E;
|
||||
if(particle->areLocalFieldsSet()) {
|
||||
// In case of spatially variable magnetic fields use the one at the "actual" particle
|
||||
// position, since that value is not dependent on the particles itself
|
||||
// B = particle->getLocalB();
|
||||
E = particle->getLocalE();
|
||||
} else {
|
||||
old_mu = kinematic::cosPitchAngle(
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position),
|
||||
particle->velocity().cartesianEntries(old_position));
|
||||
B = magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
E = electric_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
particle->setLocalFields(E, B);
|
||||
}
|
||||
|
||||
double timestep = 0;
|
||||
|
||||
// if (old_kinetic_energy < 1E-9) {
|
||||
// // Guard against small enegies taking up much time without contributing to
|
||||
// // density
|
||||
// SIM_INFO("particle skipped due to energy.");
|
||||
// return;
|
||||
// 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;
|
||||
|
||||
bool changed_position_bin = false;
|
||||
bool changed_energy_bin = false;
|
||||
bool left_simulation_domain = false;
|
||||
bool changed_mu_bin = false;
|
||||
bool died_in_bin = false;
|
||||
// bool changed_mu_bin = false;
|
||||
bool died_in_bin = particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||
|
||||
while (
|
||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain ||
|
||||
changed_mu_bin || died_in_bin) && (leftover_distance > 0.)) {
|
||||
old_position = particle->position();
|
||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain || // changed_mu_bin ||
|
||||
died_in_bin) && (leftover_time > 0.)) {
|
||||
old_position_cart = particle->cartesianPosition();
|
||||
old_position_cyl = particle->cylinderPosition();
|
||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
double old_velocity = particle->absoluteVelocity();
|
||||
timestep = std::min(maximal_time_step_s_,
|
||||
(leftover_distance + SimConstants::random_lower_limit) / old_velocity);
|
||||
timestep = std::min(maximal_time_step_s_, leftover_time);
|
||||
timestep = std::min(timestep, max_distance / old_velocity);
|
||||
timestep = std::min(timestep, max_time_alive);
|
||||
|
||||
double moved_distance = 0.;
|
||||
|
||||
const blitz::TinyVector<double, 3> E =
|
||||
electric_field->value(old_position).cartesianEntries(old_position);
|
||||
const blitz::TinyVector<double, 3> B =
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||
// const blitz::TinyVector<double, 3> E =
|
||||
// electric_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
const blitz::TinyVector<double, 3> g =
|
||||
gravity_field->value(old_position).cartesianEntries(old_position);
|
||||
gravity_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
|
||||
movementStep(particle, E, B, g, timestep);
|
||||
|
||||
movementStep(particle, E, B, g, moved_distance, timestep);
|
||||
particle->increaseTimeAlive(timestep);
|
||||
particle->increaseTimeInBin(timestep);
|
||||
|
||||
auto new_position = particle->position();
|
||||
auto new_position_cart = particle->cartesianPosition();
|
||||
auto new_velocity = particle->velocity();
|
||||
|
||||
const blitz::TinyVector<double, 3> B_new =
|
||||
magnetic_field->value(new_position).cartesianEntries(new_position);
|
||||
B = magnetic_field->value(particle->cylinderPosition()).
|
||||
cartesianEntries(new_position_cart);
|
||||
|
||||
double new_mu;
|
||||
if (kinematic::norm(B_new) == 0) {
|
||||
new_mu = kinematic::cosPitchAngle(
|
||||
blitz::TinyVector<double, 3>(0,0,1),
|
||||
new_velocity.cartesianEntries(new_position));
|
||||
} else {
|
||||
new_mu = kinematic::cosPitchAngle(
|
||||
magnetic_field->value(new_position).cartesianEntries(new_position),
|
||||
new_velocity.cartesianEntries(new_position));
|
||||
}
|
||||
// if (kinematic::norm(B) == 0) {
|
||||
// new_mu = kinematic::cosPitchAngle(
|
||||
// blitz::TinyVector<double, 3>(0,0,1), new_velocity.cartesianEntries());
|
||||
// } else {
|
||||
// new_mu = kinematic::cosPitchAngle(B, new_velocity.cartesianEntries());
|
||||
// }
|
||||
|
||||
changed_mu_bin =
|
||||
particle->specie()->dynamicDensityField()->changedPitchAngleBin(
|
||||
old_mu, new_mu);
|
||||
// changed_mu_bin =
|
||||
// particle->specie()->dynamicDensityField()->changedPitchAngleBin(
|
||||
// old_mu, new_mu);
|
||||
|
||||
changed_position_bin =
|
||||
particle->specie()->dynamicDensityField()->changedPositionBin(
|
||||
old_position, new_position);
|
||||
old_position_cyl, particle->cylinderPosition());
|
||||
|
||||
changed_energy_bin =
|
||||
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
||||
old_kinetic_energy, particle->kineticEnergy_eV());
|
||||
|
||||
left_simulation_domain =
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle, old_position_cyl);
|
||||
|
||||
died_in_bin =
|
||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||
|
||||
leftover_distance -= moved_distance;
|
||||
leftover_time -= timestep;
|
||||
particle->reduceTimeUntilCollision(timestep);
|
||||
|
||||
// if max_time_alive == 0 but the difference between the time alive and
|
||||
// the endtime > 0 (think can happen due to numerical accuracy)
|
||||
@@ -146,10 +144,53 @@ void BorisMover::move(particle::Particle* particle,
|
||||
: (max_time_alive - timestep);
|
||||
}
|
||||
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
old_position, old_kinetic_energy, old_mu, particle->timeInBin());
|
||||
particle->resetTimeInBin();
|
||||
particle->specie()->currentCollector()->collect(particle, old_position);
|
||||
if(died_in_bin && !left_simulation_domain) {
|
||||
double new_mu;
|
||||
if (kinematic::norm(B) == 0) {
|
||||
new_mu = kinematic::cosPitchAngle(
|
||||
blitz::TinyVector<double, 3>(0,0,1), particle->velocity().cartesianEntries());
|
||||
} else {
|
||||
new_mu = kinematic::cosPitchAngle(B, particle->velocity().cartesianEntries());
|
||||
}
|
||||
// use new values, since that is necessary if died_in_bin and a change in
|
||||
// bin can occur at the same time
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
particle->cylinderPosition(), particle->kineticEnergy_eV(), new_mu,
|
||||
particle->weight());
|
||||
particle->deposited();
|
||||
}
|
||||
|
||||
#ifdef debug_level3
|
||||
double new_mu;
|
||||
if (kinematic::norm(B) == 0) {
|
||||
new_mu = kinematic::cosPitchAngle(
|
||||
blitz::TinyVector<double, 3>(0,0,1), particle->velocity().cartesianEntries());
|
||||
} else {
|
||||
new_mu = kinematic::cosPitchAngle(B, particle->velocity().cartesianEntries());
|
||||
}
|
||||
if((changed_energy_bin || changed_position_bin) && !left_simulation_domain && !died_in_bin && (leftover_time > 0)) {
|
||||
std::stringstream out;
|
||||
out << "move(...) interrupted by change in ";
|
||||
if(changed_energy_bin){
|
||||
out << "energy bin: ";
|
||||
out << old_kinetic_energy << " (old), " << particle->kineticEnergy_eV();
|
||||
} else if (changed_position_bin) {
|
||||
out << "position bin: ";
|
||||
out << old_position_cyl.cylinderEntries() << " (old), " << particle->cylinderPosition().cylinderEntries();
|
||||
// } else if(changed_mu_bin) {
|
||||
// out << "mu bin: ";
|
||||
// out << old_mu << " (old), " << new_mu;
|
||||
} else {
|
||||
out <<"unknown bin... " << changed_energy_bin << changed_position_bin << left_simulation_domain << died_in_bin << leftover_time;
|
||||
}
|
||||
out << "\n(gyroradius = " << particle->mass_kg()*std::sqrt(1-new_mu*new_mu)*particle->absoluteVelocity()/(particle->specie()->charge_C()*kinematic::norm(B)) << " m";
|
||||
out << " energy: " << particle->kineticEnergy_eV() <<" eV)";
|
||||
DEBUG(out.str());
|
||||
}
|
||||
#endif
|
||||
particle->specie()->currentCollector()->collect(particle, old_position_cart);
|
||||
return old_position_cyl;
|
||||
// DEBUG("end mover");
|
||||
}
|
||||
|
||||
void BorisMover::movementStep(
|
||||
@@ -157,13 +198,14 @@ void BorisMover::movementStep(
|
||||
const blitz::TinyVector<double, 3>& electric_field,
|
||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||
const blitz::TinyVector<double, 3>& gravity_field,
|
||||
double& moved_distance,
|
||||
double timestep) const {
|
||||
|
||||
const blitz::TinyVector<double, 3> v =
|
||||
particle->velocity().cartesianEntries();
|
||||
const double m = particle->mass_kg();
|
||||
const double q = particle->charge_C();
|
||||
|
||||
/*
|
||||
const double u_minus_x =
|
||||
v(0) + (q * electric_field(0) * timestep) / (2. * m)
|
||||
+ (gravity_field(0) * timestep) / 2.;
|
||||
@@ -218,14 +260,16 @@ void BorisMover::movementStep(
|
||||
u_plus_z + (q * electric_field(2) * timestep) / (2. * m)
|
||||
+ (gravity_field(2) * timestep) / 2.;
|
||||
const blitz::TinyVector<double, 3> u_new(u_new_x, u_new_y, u_new_z);
|
||||
*/
|
||||
|
||||
blitz::TinyVector<double, 3> acceleration = q * electric_field / m +
|
||||
gravity_field;
|
||||
/*
|
||||
Might be slower, but essentially the same code
|
||||
Might be slower, but essentially the same code */
|
||||
const blitz::TinyVector<double, 3> u_minus =
|
||||
v + (q * electric_field * maximal_time_step_s_) / (2. * m);
|
||||
const double gamma = kinematic::relativisticGamma(u_minus);;
|
||||
v + (acceleration * timestep) / (2.);
|
||||
const blitz::TinyVector<double, 3> temp_1 =
|
||||
(q * magnetic_field * maximal_time_step_s_) / (2. * m * gamma);
|
||||
(q * magnetic_field * timestep) / (2. * m * kinematic::relativisticGamma(u_minus));
|
||||
const blitz::TinyVector<double, 3> u_prime =
|
||||
u_minus + (blitz::cross(u_minus, temp_1));
|
||||
const blitz::TinyVector<double, 3> temp_2 =
|
||||
@@ -233,16 +277,12 @@ void BorisMover::movementStep(
|
||||
const blitz::TinyVector<double, 3> u_plus =
|
||||
u_minus + (blitz::cross(u_prime, temp_2));
|
||||
const blitz::TinyVector<double, 3> u_new =
|
||||
u_plus + (q * electric_field * maximal_time_step_s_) / (2. * m);
|
||||
*/
|
||||
u_plus + (acceleration * timestep) / (2.);
|
||||
|
||||
particle->velocity(CartesianVector(u_new));
|
||||
|
||||
const CartesianCoordinate distance(u_new * timestep);
|
||||
particle->move(distance);
|
||||
|
||||
moved_distance += std::sqrt(
|
||||
blitz::dot(distance.cartesianEntries(), distance.cartesianEntries()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -252,19 +292,24 @@ void BorisMover::movementStep(
|
||||
DriftMover::DriftMover(double maximal_distance)
|
||||
: maximal_distance_m_(maximal_distance){};
|
||||
|
||||
void DriftMover::move(particle::Particle* particle,
|
||||
double mfp_m,
|
||||
CylinderCoordinate DriftMover::move(particle::Particle* particle,
|
||||
double collision_time_s,
|
||||
ElectricField* electric_field,
|
||||
MagneticField* magnetic_field,
|
||||
GravityField* gravity_field) {
|
||||
double leftover_distance = mfp_m;
|
||||
double leftover_time = collision_time_s;
|
||||
|
||||
// auto old_position = particle->cartesianPosition();
|
||||
CartesianCoordinate old_position_cart = particle->cartesianPosition();
|
||||
CylinderCoordinate old_position_cyl = particle->cylinderPosition();
|
||||
|
||||
auto old_position = particle->position();
|
||||
auto old_velocity = particle->velocity();
|
||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
double old_mu = kinematic::cosPitchAngle(
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position),
|
||||
old_velocity.cartesianEntries(old_position));
|
||||
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart),
|
||||
old_velocity.cartesianEntries());
|
||||
double new_mu = old_mu;
|
||||
|
||||
bool changed_position_bin = false;
|
||||
bool changed_energy_bin = false;
|
||||
@@ -274,29 +319,30 @@ void DriftMover::move(particle::Particle* particle,
|
||||
// -> add maximal timestep to time in bin and stop moving the particle
|
||||
bool died_in_bin = false;
|
||||
double max_time_alive =
|
||||
particle->specie()->dynamicDensityField()->physicalTime() -
|
||||
particle->specie()->dynamicDensityField()->timeResolution() -
|
||||
particle->timeAlive();
|
||||
|
||||
while (
|
||||
!(changed_position_bin || changed_energy_bin || changed_mu_bin
|
||||
|| left_simulation_domain) &&
|
||||
(leftover_distance > 0.) && !(died_in_bin)) {
|
||||
old_position = particle->position();
|
||||
(leftover_time > 0.) && !(died_in_bin)) {
|
||||
old_position_cart = particle->cartesianPosition();
|
||||
old_position_cyl = particle->cylinderPosition();
|
||||
old_velocity = particle->velocity();
|
||||
|
||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||
|
||||
blitz::TinyVector<double, 3> force_over_charge =
|
||||
electric_field->value(old_position).cartesianEntries(old_position) +
|
||||
gravity_field->value(old_position).cartesianEntries(old_position) *
|
||||
electric_field->value(old_position_cyl).cartesianEntries(old_position_cart) +
|
||||
gravity_field->value(old_position_cyl).cartesianEntries(old_position_cart) *
|
||||
particle->mass_kg() / particle->charge_C();
|
||||
|
||||
const blitz::TinyVector<double, 3> B =
|
||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
||||
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
const double B_norm = kinematic::norm(B);
|
||||
|
||||
const blitz::TinyVector<double, 3> gradB =
|
||||
magnetic_field->gradientValue(old_position).cartesianEntries(old_position);
|
||||
magnetic_field->gradientValue(old_position_cyl).cartesianEntries(old_position_cart);
|
||||
// Todo: add calculation of divB here
|
||||
// use Kassiopeia paper for reference
|
||||
|
||||
@@ -324,14 +370,15 @@ void DriftMover::move(particle::Particle* particle,
|
||||
driftVelocity(force_over_charge, B);
|
||||
const double v_drift_norm = kinematic::norm(v_drift);
|
||||
|
||||
const double stepsize = std::min(leftover_distance, maximal_distance_m_);
|
||||
// const double stepsize = std::min(leftover_distance, maximal_distance_m_);
|
||||
// guard against very large timesteps i.e. v ~ 0 -> timestep = Inf
|
||||
// should be a very rare case (but has happend)
|
||||
const double timestep = std::min(
|
||||
stepsize / std::sqrt(v_parallel_norm*v_parallel_norm +
|
||||
double timestep = std::min(
|
||||
maximal_distance_m_ / std::sqrt(v_parallel_norm*v_parallel_norm +
|
||||
v_perp_norm*v_perp_norm +
|
||||
v_drift_norm*v_drift_norm),
|
||||
max_time_alive);
|
||||
timestep = std::min(timestep, leftover_time);
|
||||
|
||||
const blitz::TinyVector<double, 3> movement_parallel =
|
||||
v_parallel * timestep;
|
||||
@@ -343,7 +390,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
const blitz::TinyVector<double, 3> dv_electric = timestep *
|
||||
particle->charge_C() * force_over_charge_parallel / particle->mass_kg();
|
||||
|
||||
if (v_perp_norm > SimConstants::compare_epsilon) {
|
||||
if (v_perp_norm/v_parallel_norm > SimConstants::compare_epsilon) {
|
||||
const double gyro_radius = particle->mass_kg() * v_perp_norm /
|
||||
(B_norm * particle->charge_C());
|
||||
|
||||
@@ -369,7 +416,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
// might be better to do after the actual movement and then just extract
|
||||
// the position again from the particle
|
||||
const blitz::TinyVector<double, 3> new_position =
|
||||
old_position.cartesianEntries() + movement_parallel
|
||||
old_position_cart.cartesianEntries() + movement_parallel
|
||||
+ movement_drift + movement_around_gyro_center;
|
||||
|
||||
const blitz::TinyVector<double, 3> B_new =
|
||||
@@ -401,7 +448,7 @@ void DriftMover::move(particle::Particle* particle,
|
||||
}
|
||||
|
||||
particle->increaseTimeAlive(timestep);
|
||||
particle->increaseTimeInBin(timestep);
|
||||
// particle->increaseTimeInBin(timestep);
|
||||
// if instead of eps*deltaT 0.0 is used the integral would be conserved
|
||||
// if no particles are lost at a boundary. however in that case the terminator does not
|
||||
// return the correct value if the time the particle is alive is identical
|
||||
@@ -415,52 +462,62 @@ void DriftMover::move(particle::Particle* particle,
|
||||
? particle->specie()->dynamicDensityField()
|
||||
->timeResolution()*SimConstants::compare_epsilon
|
||||
: (max_time_alive - timestep);
|
||||
#ifdef debug_level3
|
||||
if (max_time_alive == 0) {
|
||||
DEBUG_LEVEL_3("Mover: max_time_alive is 0.");
|
||||
DEBUG_LEVEL_3("Mover: particle time alive: " +
|
||||
std::to_string(particle->timeAlive()));
|
||||
}
|
||||
#endif
|
||||
|
||||
const auto new_position = particle->position();
|
||||
const auto new_position = particle->cartesianPosition();
|
||||
|
||||
died_in_bin =
|
||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||
#ifdef debug_level3
|
||||
if(died_in_bin) {
|
||||
DEBUG_LEVEL_3("Mover: particle died in bin.");
|
||||
}
|
||||
#endif
|
||||
|
||||
changed_position_bin =
|
||||
particle->specie()->dynamicDensityField()->changedPositionBin(
|
||||
old_position, new_position);
|
||||
old_position_cyl, particle->cylinderPosition());
|
||||
|
||||
changed_energy_bin =
|
||||
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
||||
old_kinetic_energy, particle->kineticEnergy_eV());
|
||||
|
||||
const double new_mu = kinematic::cosPitchAngle(magnetic_field
|
||||
->value(new_position).cartesianEntries(new_position),
|
||||
particle->velocity().cartesianEntries(new_position));
|
||||
new_mu = kinematic::cosPitchAngle(magnetic_field
|
||||
->value(particle->cylinderPosition()).cartesianEntries(new_position),
|
||||
particle->velocity().cartesianEntries());
|
||||
|
||||
changed_mu_bin = particle->specie()->dynamicDensityField()
|
||||
->changedPitchAngleBin(old_mu, new_mu);
|
||||
|
||||
#ifdef debug_level3
|
||||
if(changed_mu_bin) {
|
||||
DEBUG_LEVEL_3("cos(pitch old): " + std::to_string(old_mu));
|
||||
DEBUG_LEVEL_3("cos(pitch new): " + std::to_string(new_mu));
|
||||
}
|
||||
#endif
|
||||
|
||||
left_simulation_domain =
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||
particle->specie()->terminator()->leftSimulationDomain(particle, old_position_cyl);
|
||||
|
||||
leftover_distance -= stepsize;
|
||||
leftover_time -= timestep;
|
||||
particle->reduceTimeUntilCollision(timestep);
|
||||
}
|
||||
|
||||
// particle->specie()->dynamicDensityField()->logMovement(
|
||||
// old_position, old_kinetic_energy, particle->timeInBin());
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
old_position, old_kinetic_energy, old_mu, particle->timeInBin());
|
||||
particle->resetTimeInBin();
|
||||
particle->specie()->currentCollector()->collect(particle, old_position);
|
||||
// only log a particle in the bin where its movement ends, i.e. if
|
||||
// the particle reached the end of the timestep
|
||||
if(died_in_bin && !left_simulation_domain) {
|
||||
particle->specie()->dynamicDensityField()->logMovement(
|
||||
particle->cylinderPosition(), particle->kineticEnergy_eV(), new_mu,
|
||||
particle->weight());
|
||||
}
|
||||
particle->specie()->currentCollector()->collect(particle, old_position_cyl);
|
||||
return old_position_cyl;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> DriftMover::driftVelocity(
|
||||
|
||||
@@ -26,3 +26,28 @@ void MpiCommunication::init(int argc, char* argv[]) {
|
||||
void MpiCommunication::finalize() {
|
||||
MPI_Finalize();
|
||||
}
|
||||
|
||||
void MpiCommunication::create_mpi_info(MPI_Info* info) {
|
||||
MPI_Info_create(info);
|
||||
|
||||
struct {char key[32]; char val[32];} conf[] = {
|
||||
// keys and values adapted from acronym
|
||||
// deactivate data sieving
|
||||
{"romio_ds_read" , "disable"},
|
||||
{"romio_ds_write", "disable"},
|
||||
// collective buffering
|
||||
{"romio_cb_read" , "enable" },
|
||||
// acc. to acronym the following option (if enabled)
|
||||
// would "lead memory like crazy"
|
||||
{"romio_cb_write", "disable"},
|
||||
{"collective_buffering", "true"},
|
||||
{"cb_block_size" , "1048576"}, // 1 MiB
|
||||
{"cb_buffer_size", "8388608"}, // 8 MiB
|
||||
// end of conf data structure
|
||||
{"", ""}
|
||||
};
|
||||
|
||||
for (int i = 0; conf[i].key[0] != '\0'; ++i) {
|
||||
MPI_Info_set(*info, conf[i].key, conf[i].val);
|
||||
}
|
||||
}
|
||||
|
||||
+133
-18
@@ -18,22 +18,98 @@ Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
}
|
||||
*/
|
||||
|
||||
// requires the name of a species "spec_name" to be smaller than 16 characters
|
||||
// this is not! checked here and will lead to undefined behaviour if this
|
||||
// requirement is not fulfilled
|
||||
SerializedParticle::SerializedParticle(double weight,
|
||||
blitz::TinyVector<double, 3> cartPos,
|
||||
blitz::TinyVector<double, 3> cartVel,
|
||||
std::string spec_name,
|
||||
int idx_nxt_interaction,
|
||||
double time_until_collision) :
|
||||
weight_(weight),
|
||||
cartesian_position_(cartPos),
|
||||
cartesian_velocity_(cartVel),
|
||||
idx_nxt_interaction_(idx_nxt_interaction),
|
||||
time_until_interaction_(time_until_collision) {
|
||||
std::copy(spec_name.begin(), spec_name.end(), specie_name_.data());
|
||||
specie_name_[spec_name.length()] = '\0';
|
||||
}
|
||||
|
||||
double SerializedParticle::weight() {
|
||||
return weight_;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> SerializedParticle::cartesianPosition() {
|
||||
return cartesian_position_;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> SerializedParticle::cartesianVelocity() {
|
||||
return cartesian_velocity_;
|
||||
}
|
||||
|
||||
std::string SerializedParticle::specieName() {
|
||||
return std::string (specie_name_.data());
|
||||
}
|
||||
|
||||
double SerializedParticle::timeUntilCollision() {
|
||||
return time_until_interaction_;
|
||||
}
|
||||
|
||||
int SerializedParticle::indexNextInteraction() {
|
||||
return idx_nxt_interaction_;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
const Coordinate& position,
|
||||
const Vector& velocity,
|
||||
const double time_birth,
|
||||
const double weight)
|
||||
: specie_(specie),
|
||||
position_(position),
|
||||
position_cart_(position),
|
||||
position_cyl_(position),
|
||||
velocity_(velocity, position),
|
||||
id_(this->last_id_),
|
||||
time_alive_s_(time_birth),
|
||||
time_in_bin_s_(0.),
|
||||
interaction_counter_(0),
|
||||
weight_(weight) {
|
||||
last_id_++;
|
||||
}
|
||||
|
||||
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||
const Coordinate& position,
|
||||
const Vector& velocity,
|
||||
const double weight)
|
||||
: specie_(specie),
|
||||
position_cart_(position),
|
||||
position_cyl_(position),
|
||||
velocity_(velocity, position),
|
||||
id_(this->last_id_),
|
||||
time_alive_s_(0.),
|
||||
interaction_counter_(0),
|
||||
weight_(weight) {
|
||||
last_id_++;
|
||||
}
|
||||
|
||||
Particle::Particle(particle::SerializedParticle sparticle, std::map<std::string,
|
||||
std::shared_ptr<species::TrackedSpecie>>& tracked_species) :
|
||||
specie_(tracked_species[sparticle.specieName()]),
|
||||
position_cart_(sparticle.cartesianPosition()),
|
||||
position_cyl_(blitz::TinyVector<double, 3>(0,0,0)),
|
||||
velocity_(sparticle.cartesianVelocity()),
|
||||
id_(this->last_id_),
|
||||
time_alive_s_(0.),
|
||||
interaction_counter_(0),
|
||||
weight_(sparticle.weight()),
|
||||
index_next_interaction_(sparticle.indexNextInteraction()),
|
||||
time_until_collision_(sparticle.timeUntilCollision()) {
|
||||
last_id_++;
|
||||
position_cyl_ = CylinderCoordinate(position_cart_);
|
||||
}
|
||||
|
||||
long int Particle::last_id_ = 0;
|
||||
|
||||
double Particle::mass_kg() const {
|
||||
@@ -64,15 +140,21 @@ species::TrackedSpecie* Particle::specie() const {
|
||||
}
|
||||
|
||||
void Particle::position(const Coordinate& new_position) {
|
||||
position_ = CartesianCoordinate(new_position);
|
||||
position_cart_ = CartesianCoordinate(new_position);
|
||||
position_cyl_ = CylinderCoordinate(new_position);
|
||||
}
|
||||
|
||||
CartesianCoordinate Particle::position() const {
|
||||
return position_;
|
||||
CartesianCoordinate Particle::cartesianPosition() const {
|
||||
return position_cart_;
|
||||
}
|
||||
|
||||
CylinderCoordinate Particle::cylinderPosition() const {
|
||||
return position_cyl_;
|
||||
}
|
||||
|
||||
void Particle::move(const Coordinate& distance) {
|
||||
position_.add(distance);
|
||||
position_cart_.add(distance);
|
||||
position_cyl_ = CylinderCoordinate(position_cart_);
|
||||
}
|
||||
|
||||
double Particle::kineticEnergy_eV() const {
|
||||
@@ -101,18 +183,6 @@ double Particle::timeAlive() const {
|
||||
return time_alive_s_;
|
||||
}
|
||||
|
||||
void Particle::increaseTimeInBin(double time_s) {
|
||||
time_in_bin_s_ += time_s;
|
||||
}
|
||||
|
||||
void Particle::resetTimeInBin() {
|
||||
time_in_bin_s_ = 0.;
|
||||
}
|
||||
|
||||
double Particle::timeInBin() const {
|
||||
return time_in_bin_s_*weight_;
|
||||
}
|
||||
|
||||
long int Particle::ID() const {
|
||||
return id_;
|
||||
}
|
||||
@@ -121,4 +191,49 @@ double Particle::weight() const {
|
||||
return weight_;
|
||||
}
|
||||
|
||||
void Particle::deposited(bool truthValue) {
|
||||
deposited_ = truthValue;
|
||||
}
|
||||
|
||||
bool Particle::wasDeposited() {
|
||||
return deposited_;
|
||||
}
|
||||
|
||||
void Particle::timeUntilCollision(const double time_until_collision) {
|
||||
time_until_collision_ = time_until_collision;
|
||||
}
|
||||
|
||||
double Particle::timeUntilCollision() const {
|
||||
return time_until_collision_;
|
||||
}
|
||||
|
||||
void Particle::reduceTimeUntilCollision(double delta) {
|
||||
time_until_collision_ -= delta;
|
||||
}
|
||||
|
||||
void Particle::setLocalFields(const blitz::TinyVector<double, 3>& E,
|
||||
const blitz::TinyVector<double, 3>& B) {
|
||||
local_E_cart_ = E;
|
||||
local_B_cart_ = B;
|
||||
set_local_fields_ = true;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> Particle::getLocalE() const {
|
||||
return local_E_cart_;
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> Particle::getLocalB() const {
|
||||
return local_B_cart_;
|
||||
}
|
||||
|
||||
bool Particle::areLocalFieldsSet() const {
|
||||
return set_local_fields_;
|
||||
}
|
||||
|
||||
particle::SerializedParticle Particle::serialize() {
|
||||
return particle::SerializedParticle(weight_,
|
||||
position_cart_.cartesianEntries(), velocity_.cartesianEntries(),
|
||||
specie_->name(), index_next_interaction_, time_until_collision_);
|
||||
}
|
||||
|
||||
} // namespace particle
|
||||
|
||||
@@ -117,46 +117,40 @@ int BinningWithOverAndUnderflow::binIndexMax() const {
|
||||
|
||||
CylinderBinning::CylinderBinning(int num_bins_radial,
|
||||
double radius,
|
||||
int num_bins_azimuthal,
|
||||
int num_bins_longitudinal,
|
||||
double height)
|
||||
: radial_binning(num_bins_radial, radius),
|
||||
azimuth_binning(num_bins_azimuthal, 2 * M_PI),
|
||||
longitudinal_binning(num_bins_longitudinal, height) {}
|
||||
|
||||
blitz::TinyVector<int, 3> CylinderBinning::bin(
|
||||
blitz::TinyVector<int, 2> CylinderBinning::bin(
|
||||
const blitz::TinyVector<double, 3>& cylinder_position) const {
|
||||
return blitz::TinyVector<int, 3>(
|
||||
return blitz::TinyVector<int, 2>(
|
||||
radial_binning.bin(cylinder_position(0)),
|
||||
azimuth_binning.bin(cylinder_position(1)),
|
||||
longitudinal_binning.bin(cylinder_position(2)));
|
||||
}
|
||||
|
||||
blitz::TinyVector<int, 3> CylinderBinning::numBins() const {
|
||||
return blitz::TinyVector<int, 3>(
|
||||
radial_binning.numBinsWithoutOverflow(), azimuth_binning.numBins(),
|
||||
blitz::TinyVector<int, 2> CylinderBinning::numBins() const {
|
||||
return blitz::TinyVector<int, 2>(
|
||||
radial_binning.numBinsWithoutOverflow(),
|
||||
longitudinal_binning.numBinsWithoutOverUnderflow());
|
||||
}
|
||||
|
||||
blitz::TinyVector<double, 3> CylinderBinning::stepsize() const {
|
||||
return blitz::TinyVector<double, 3>(radial_binning.stepsize(),
|
||||
azimuth_binning.stepsize(),
|
||||
blitz::TinyVector<double, 2> CylinderBinning::stepsize() const {
|
||||
return blitz::TinyVector<double, 2>(radial_binning.stepsize(),
|
||||
longitudinal_binning.stepsize());
|
||||
}
|
||||
|
||||
blitz::TinyVector<int, 3> CylinderBinning::numBinsIncludingOverUnderflow()
|
||||
blitz::TinyVector<int, 2> CylinderBinning::numBinsIncludingOverUnderflow()
|
||||
const {
|
||||
return blitz::TinyVector<int, 3>(
|
||||
radial_binning.numBinsWithOverflow(), azimuth_binning.numBins(),
|
||||
return blitz::TinyVector<int, 2>(
|
||||
radial_binning.numBinsWithOverflow(),
|
||||
longitudinal_binning.numBinsWithOverUnderflow());
|
||||
}
|
||||
blitz::TinyVector<int, 3> CylinderBinning::binIndexMin() const {
|
||||
return blitz::TinyVector<int, 3>(radial_binning.binIndexMin(),
|
||||
azimuth_binning.binIndexMin(),
|
||||
blitz::TinyVector<int, 2> CylinderBinning::binIndexMin() const {
|
||||
return blitz::TinyVector<int, 2>(radial_binning.binIndexMin(),
|
||||
longitudinal_binning.binIndexMin());
|
||||
}
|
||||
blitz::TinyVector<int, 3> CylinderBinning::binIndexMax() const {
|
||||
return blitz::TinyVector<int, 3>(radial_binning.binIndexMax(),
|
||||
azimuth_binning.binIndexMax(),
|
||||
blitz::TinyVector<int, 2> CylinderBinning::binIndexMax() const {
|
||||
return blitz::TinyVector<int, 2>(radial_binning.binIndexMax(),
|
||||
longitudinal_binning.binIndexMax());
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "simulation/random_numbers.h"
|
||||
#include <algorithm>
|
||||
|
||||
RandomNumbers::RandomNumbers(int seed)
|
||||
: engine_(std::make_shared<std::mt19937>(seed)),
|
||||
@@ -15,3 +16,60 @@ double RandomNumbers::rollUniform(double min, double max) {
|
||||
std::mt19937* RandomNumbers::engine() {
|
||||
return engine_.get();
|
||||
}
|
||||
|
||||
// does NOT shuffle the indices!
|
||||
// num bins for the energy binning should include the underflow bin!
|
||||
RandomIndex::RandomIndex(blitz::TinyVector<int, 5> num_bins) :
|
||||
num_bins_(num_bins){
|
||||
|
||||
total_bin_number_ = blitz::product(num_bins_);
|
||||
|
||||
one_dimensional_indices_.reserve(total_bin_number_);
|
||||
|
||||
for(size_t i = 0; i < total_bin_number_; ++i) {
|
||||
one_dimensional_indices_.push_back(i);
|
||||
}
|
||||
|
||||
current_index_in_vector_ = 0;
|
||||
}
|
||||
|
||||
void RandomIndex::reshuffle(std::mt19937* engine) {
|
||||
current_index_in_vector_ = 0;
|
||||
std::shuffle(std::begin(one_dimensional_indices_),
|
||||
std::end(one_dimensional_indices_), *engine);
|
||||
}
|
||||
|
||||
bool RandomIndex::visited_all() {
|
||||
return current_index_in_vector_ == total_bin_number_;
|
||||
}
|
||||
|
||||
// return the next index in the shuffled index vector. Returns the last
|
||||
// index if all bins have been visited. Reshuffling resets this.
|
||||
// Note that the underflow bin for the energy is included, i.e. min index for E
|
||||
// is -1 not 0
|
||||
blitz::TinyVector<int, 5> RandomIndex::index() {
|
||||
size_t tmp_one_dimensional_idx = one_dimensional_indices_[current_index_in_vector_];
|
||||
|
||||
blitz::TinyVector<int, 5> return_index{0,0,0,0,0};
|
||||
|
||||
int tmp = 0;
|
||||
|
||||
size_t current_prod = total_bin_number_;
|
||||
|
||||
for(int d = 4; d >= 0; d--) {
|
||||
current_prod /= num_bins_(d);
|
||||
|
||||
tmp = tmp_one_dimensional_idx / current_prod;
|
||||
|
||||
return_index(d) = tmp;
|
||||
|
||||
tmp_one_dimensional_idx -= tmp * current_prod;
|
||||
}
|
||||
|
||||
return_index(4) -= 1;
|
||||
|
||||
if(!visited_all())
|
||||
current_index_in_vector_++;
|
||||
|
||||
return return_index;
|
||||
}
|
||||
@@ -5,20 +5,44 @@ ReflectorDPS::ReflectorDPS(double z_position_dps)
|
||||
|
||||
bool ReflectorDPS::needsReflectionBackToDomain(
|
||||
const particle::Particle* particle) const {
|
||||
return particle->position().cylinderEntries()(2) > z_position_dps_;
|
||||
return particle->cylinderPosition().cylinderEntries()(2) > z_position_dps_;
|
||||
}
|
||||
|
||||
void ReflectorDPS::reflectBackToDomain(particle::Particle* particle) const {
|
||||
blitz::TinyVector<double, 3> old_position =
|
||||
particle->position().cylinderEntries();
|
||||
particle->cartesianPosition().cartesianEntries();
|
||||
old_position(2) = 2 * z_position_dps_ - old_position(2);
|
||||
particle->position(CylinderCoordinate(old_position));
|
||||
particle->position(CartesianCoordinate(old_position));
|
||||
blitz::TinyVector<double, 3> old_velocity =
|
||||
particle->velocity().cartesianEntries();
|
||||
old_velocity(2) *= -1;
|
||||
particle->velocity(CartesianVector(old_velocity));
|
||||
}
|
||||
|
||||
LongitudinalReflector::LongitudinalReflector(double height) : height_(height) {}
|
||||
|
||||
bool LongitudinalReflector::needsReflectionBackToDomain(const particle::Particle* particle) const {
|
||||
blitz::TinyVector<double, 3> position = particle->cartesianPosition().cartesianEntries();
|
||||
if(position(2) < 0 || position(2) > height_) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void LongitudinalReflector::reflectBackToDomain(particle::Particle* particle) const {
|
||||
blitz::TinyVector<double, 3> old_position = particle->cartesianPosition().cartesianEntries();
|
||||
blitz::TinyVector<double, 3> old_velocity = particle->velocity().cartesianEntries();
|
||||
|
||||
if(old_position(2) < 0) {
|
||||
old_position(2) *= -1;
|
||||
} else if(old_position(2) > height_) {
|
||||
old_position(2) = 2*height_ - old_position(2);
|
||||
}
|
||||
old_velocity(2) *= -1.;
|
||||
|
||||
particle->position(CartesianCoordinate(old_position));
|
||||
particle->velocity(CartesianVector(old_velocity));
|
||||
}
|
||||
|
||||
bool NoReflector::needsReflectionBackToDomain(
|
||||
const particle::Particle* particle) const {
|
||||
return false;
|
||||
|
||||
@@ -58,7 +58,7 @@ CompositeAngleDistribution::CompositeAngleDistribution(
|
||||
|
||||
double CompositeAngleDistribution::roll(std::mt19937* engine,
|
||||
double energy_eV) {
|
||||
if (energy_eV <= decider_energy_) {
|
||||
if (!(energy_eV > decider_energy_)) {
|
||||
return lower_distribution_->roll(engine, energy_eV);
|
||||
} else {
|
||||
return higher_distribution_->roll(engine, energy_eV);
|
||||
|
||||
+308
-242
@@ -3,6 +3,7 @@
|
||||
#include <numeric>
|
||||
#include <random>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "constants/sim_constants.h"
|
||||
#include "simulation/cpu_synchronizer.h"
|
||||
#include "simulation/current_collector.h"
|
||||
@@ -37,39 +38,69 @@
|
||||
|
||||
#include "tools/simulation_time.h"
|
||||
|
||||
// #ifdef debug_timedist
|
||||
// #include <fstream>
|
||||
// #include <iomanip>
|
||||
// #endif
|
||||
|
||||
Simulation::Simulation(std::string parameter_filename)
|
||||
: parameter_(parameter_filename) {
|
||||
init(parameter_);
|
||||
}
|
||||
|
||||
void Simulation::init(Parameter& parameter) {
|
||||
// reserve some size for the different particle queues
|
||||
queue_.reserve(100);
|
||||
storage_queue_[0].reserve(1000);
|
||||
storage_queue_[1].reserve(1000);
|
||||
|
||||
#ifdef debug
|
||||
std::stringstream out;
|
||||
out << "Size of a Particle: " << sizeof(particle::Particle);
|
||||
out << "\nSize of a Serialized Particle: " << sizeof(particle::SerializedParticle);
|
||||
DEBUG_LEVEL_0(out.str());
|
||||
#endif
|
||||
|
||||
magnetic_field_ = generator::magneticField(parameter);
|
||||
electric_field_ = generator::electricField(parameter);
|
||||
gravity_field_ = generator::gravityField(parameter);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Creating species.");
|
||||
#endif
|
||||
generator::SpeciesBuilder builder(parameter);
|
||||
tracked_species_ = builder.trackedSpecies();
|
||||
background_species_ = builder.backgroundSpecies();
|
||||
timer_ = builder.timer();
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Creating injector.");
|
||||
#endif
|
||||
injector_ = generator::buildInjector(tracked_species_, background_species_,
|
||||
parameter);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init random numbers.");
|
||||
#endif
|
||||
random_ = generator::buildRandomNumbers(parameter);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init poisson solver.");
|
||||
#endif
|
||||
poisson_solver_ = generator::buildPoissonSolver(parameter);
|
||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init cpu synchronizer.");
|
||||
#endif
|
||||
cpu_synchronizer_ = std::make_shared<CpuSynchronizer>();
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Init done.");
|
||||
#endif
|
||||
|
||||
Restart restarter = generator::buildRestart(parameter);
|
||||
restarter.restart(tracked_species_, poisson_solver_.get(), random_.get());
|
||||
restarter.restart(tracked_species_, poisson_solver_.get(), random_.get(),
|
||||
storage_queue_[active_storage], injectionGroupOffset);
|
||||
// poisson solver is restarted -> set the electric field from the potential
|
||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||
|
||||
@@ -77,11 +108,15 @@ void Simulation::init(Parameter& parameter) {
|
||||
// writing the metadata
|
||||
MPI_Barrier(MPI_COMM_WORLD);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Init output.");
|
||||
#endif
|
||||
output_ = generator::buildSimulationOutput(
|
||||
parameter.jsonObjectFromBase({"Output"}), tracked_species_);
|
||||
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Output meta data.");
|
||||
#endif
|
||||
output_->writeMetaData(tracked_species_, poisson_solver_);
|
||||
}
|
||||
|
||||
@@ -109,162 +144,118 @@ void Simulation::finalize() {
|
||||
void Simulation::start() {
|
||||
SIM_INFO("Starting Simulation.");
|
||||
|
||||
// stride wrt the number of beta decay events per CPU
|
||||
const int event_stride =
|
||||
parameter_.intValue(json_path({"Simulation", "EventStride"}), 1);
|
||||
|
||||
// number of timesteps to be simulated
|
||||
const int number_timesteps = parameter_.intValue(json_path({"Simulation",
|
||||
"NumberTimesteps"}), 1);
|
||||
|
||||
// number of physical beta events defining the timescale through
|
||||
// time_resolution_events/Activity
|
||||
const int time_resolution_events =
|
||||
parameter_.intValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
||||
MpiCommunication::mpiSize());
|
||||
// dt = time_resolution_events/Activity
|
||||
const double time_resolution_events =
|
||||
parameter_.doubleValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
||||
MpiCommunication::mpi_size);
|
||||
|
||||
// number of beta decay events per timestep and CPU (will get normalized s.t.
|
||||
// the physical number of particles is correct)
|
||||
const int beta_decay_events =
|
||||
parameter_.intValue(json_path{"Simulation", "BetaDecayEventsPerCPU"}, 1);
|
||||
|
||||
// weight of a particle created through beta decay wrt a physical particle
|
||||
const double beta_particle_weight = time_resolution_events/
|
||||
static_cast<double>(beta_decay_events*MpiCommunication::mpiSize());
|
||||
|
||||
// number of density events per timestep and CPU
|
||||
const int density_events =
|
||||
parameter_.intValue(json_path({"Simulation", "DensityEventsPerCPU"}), 0);
|
||||
|
||||
// calculate a 'stride' for the density events s.t. the same number of syncs
|
||||
// would be performed
|
||||
const int density_stride = std::ceil(density_events *
|
||||
(static_cast<double>(event_stride)/beta_decay_events));
|
||||
// calculate the scaling factor for the particle weight for particles
|
||||
// drawn from the density
|
||||
const double density_weight_factor =
|
||||
1./(MpiCommunication::mpiSize()*density_events);
|
||||
|
||||
DEBUG_LEVEL_0("Density events per cpu: " + std::to_string(density_events));
|
||||
injector_->setWeights(time_resolution_events, beta_decay_events);
|
||||
|
||||
SIM_INFO("Number of Timesteps: " + std::to_string(number_timesteps));
|
||||
SIM_INFO("Simulated events before cpu sync: " + std::to_string(event_stride));
|
||||
|
||||
int leftover_events_time_resolution = beta_decay_events;
|
||||
int leftover_density_events = density_events;
|
||||
SIM_INFO("Number of injected particles per timestep: " + std::to_string(beta_decay_events));
|
||||
|
||||
const double delta_t = time_resolution_events*injector_->timePassed();
|
||||
|
||||
// if delta_t of the timer after creation and potential restart is 0, then
|
||||
// it's indicative of no restart having occured (a simulation with a delta_t
|
||||
// of 0 would not be sensible)
|
||||
if(timer_->getDeltaT() != 0 && delta_t != timer_->getDeltaT()) {
|
||||
std::stringstream out;
|
||||
out << "Old delta t: " << timer_->getDeltaT();
|
||||
out << "; new delta t: " << delta_t;
|
||||
out << ". Currently not supported (leads to errors in the density calculated from "
|
||||
"the loaded data)";
|
||||
ERROR(out.str());
|
||||
}
|
||||
|
||||
timer_->setDeltaT(delta_t);
|
||||
injector_->initInjectionTimeDistribution(delta_t);
|
||||
for(auto element: tracked_species_)
|
||||
injector_->fillParticleNumbers(element.second);
|
||||
|
||||
int num_cpu_syncs = 0;
|
||||
bool reset = true;
|
||||
int timesteps = 0;
|
||||
|
||||
queue_.reserve(100);
|
||||
|
||||
timer_->increaseTimestep(delta_t);
|
||||
|
||||
while (timesteps < number_timesteps) {
|
||||
#if defined debug_level3
|
||||
while (timestep < number_timesteps) {
|
||||
#if defined(debug_level3)
|
||||
std::stringstream out;
|
||||
out << "Timeinterval: " << timer_->time() << "s.";
|
||||
DEBUG_LEVEL_3(out.str());
|
||||
#endif
|
||||
// calculate the number of beta events to be simulated before a
|
||||
// cpu sync is done
|
||||
int events_of_cycle =
|
||||
eventsOfCycle(event_stride, leftover_events_time_resolution);
|
||||
int density_events_of_cycle =
|
||||
eventsOfCycle(density_stride, leftover_density_events);
|
||||
|
||||
#ifdef debug_level1
|
||||
DEBUG_LEVEL_1("Events of cycle: " + std::to_string(events_of_cycle));
|
||||
DEBUG_LEVEL_1("Density Events of cycle: " +
|
||||
std::to_string(density_events_of_cycle));
|
||||
#endif
|
||||
|
||||
SIM_INFO("Processing timestep: " + std::to_string(timesteps));
|
||||
SIM_INFO("Leftover events this timestep this CPU: " +
|
||||
std::to_string(leftover_events_time_resolution));
|
||||
SIM_INFO("Leftover density events this timestep this CPU: " +
|
||||
std::to_string(leftover_density_events));
|
||||
if(timestep%(std::max(number_timesteps/100, 1)) == 0)
|
||||
SIM_INFO("Processing timestep: " + std::to_string(timestep));
|
||||
|
||||
// process both density and beta events before a cpu synchronization
|
||||
processDensityEvents(density_events_of_cycle, density_weight_factor);
|
||||
processEvents(events_of_cycle, beta_particle_weight);
|
||||
processDensityEvents();
|
||||
processEvents(beta_decay_events);
|
||||
|
||||
DEBUG_LEVEL_1("Processing timestep: " + std::to_string(timesteps));
|
||||
DEBUG_LEVEL_1("Leftover events this timestep: " +
|
||||
std::to_string(leftover_events_time_resolution));
|
||||
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
||||
DEBUG_LEVEL_1("Processing timestep: " + std::to_string(timestep));
|
||||
// DEBUG_LEVEL_1("Leftover events this timestep: " +
|
||||
// std::to_string(leftover_events_time_resolution));
|
||||
#endif
|
||||
|
||||
leftover_events_time_resolution -= events_of_cycle;
|
||||
leftover_density_events -= density_events_of_cycle;
|
||||
|
||||
reset = !(leftover_events_time_resolution > 0);
|
||||
#ifdef GENRICHCURRENT
|
||||
output_->setResetCurrentCollector(timestep + 1, tracked_species_);
|
||||
#endif
|
||||
|
||||
#ifdef debug
|
||||
SIM_INFO("Cpu sync.");
|
||||
#endif
|
||||
SimulationTimer::eventStartPoint(std::string("CpuSync"));
|
||||
// 'reset' necessary as parameter to set the density for drawing
|
||||
// otherwise it would be more difficult to set it... (cpu synchronizer
|
||||
// is a friend class of the density field, i.e. has access to the
|
||||
// private members)
|
||||
cpu_synchronizer_->synchronize(tracked_species_, reset);
|
||||
num_cpu_syncs += 1;
|
||||
cpu_synchronizer_->synchronize(tracked_species_);
|
||||
timer_->increaseTimestep(delta_t);
|
||||
timestep++;
|
||||
SimulationTimer::eventStopPoint(std::string("CpuSync"));
|
||||
|
||||
// can probably be moved into the reset section and therefore
|
||||
// the parameter 'reset' could probably be removed
|
||||
#ifdef debug
|
||||
SIM_INFO("Poisson step.");
|
||||
#endif
|
||||
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
|
||||
// only solves the potential anew if 'reset' is true
|
||||
poisson_solver_->solvePotential(chargedensity(), reset);
|
||||
|
||||
poisson_solver_->solvePotential(chargedensity());
|
||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||
|
||||
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
|
||||
|
||||
#ifdef debug
|
||||
SIM_INFO("Perform output.");
|
||||
#endif
|
||||
SimulationTimer::eventStartPoint(std::string("Output"));
|
||||
output_->writeSimulationData(num_cpu_syncs, tracked_species_, poisson_solver_.get(),
|
||||
random_->engine());
|
||||
|
||||
output_->writeSimulationData(timestep, tracked_species_, poisson_solver_.get(),
|
||||
random_->engine(), storage_queue_[inactive_storage],
|
||||
timestep + injectionGroupOffset);
|
||||
|
||||
SimulationTimer::eventStopPoint(std::string("Output"));
|
||||
|
||||
SimulationTimer::eventStartPoint("Reset");
|
||||
if(reset) {
|
||||
SIM_INFO("Do resets and increase the timestep for timeresolution.");
|
||||
for(auto& pair : tracked_species_) {
|
||||
pair.second->dynamicDensityField()->resetDynamicDensityField();
|
||||
#if defined(debug_level2) || defined(debug_level3)
|
||||
DEBUG("Number of particles in active storage queue: "
|
||||
+ std::to_string(storage_queue_[active_storage].size()));
|
||||
DEBUG("Number of particles in inactive storage queue: "
|
||||
+ std::to_string(storage_queue_[inactive_storage].size()));
|
||||
#endif
|
||||
#ifdef debug
|
||||
SIM_INFO("Do resets and increase the timestep for timeresolution.");
|
||||
#endif
|
||||
active_storage = (active_storage + 1) % 2;
|
||||
inactive_storage = (inactive_storage + 1) % 2;
|
||||
|
||||
pair.second->currentCollector()->resetCurrentCollector();
|
||||
for(auto& pair : tracked_species_) {
|
||||
pair.second->dynamicDensityField()->resetDynamicDensityField();
|
||||
|
||||
pair.second->deletionLogger()->resetDeletionLogger();
|
||||
pair.second->currentCollector()->resetCurrentCollector();
|
||||
|
||||
// the density from which new particles are drawn is only updated after a timestep
|
||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
||||
pair.second->positionDistributionFromDensity()
|
||||
->setMaximumDensityAboveAndBelow(injector_->energySplit());
|
||||
|
||||
injector_->fillParticleNumbers(pair.second);
|
||||
}
|
||||
|
||||
leftover_events_time_resolution = beta_decay_events;
|
||||
leftover_density_events = density_events;
|
||||
|
||||
timer_->increaseTimestep(delta_t);
|
||||
timesteps++;
|
||||
pair.second->deletionLogger()->resetDeletionLogger();
|
||||
}
|
||||
|
||||
SimulationTimer::eventStopPoint("Reset");
|
||||
}
|
||||
}
|
||||
@@ -273,195 +264,265 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
|
||||
return random->rollUniform(0, queue_length);
|
||||
}
|
||||
|
||||
void Simulation::processEvents(int events, const double beta_particle_weight) {
|
||||
void Simulation::processEvents(int events) {
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Processing events.");
|
||||
#endif
|
||||
int current_event = 0;
|
||||
|
||||
while ((current_event < events) || (!queue_.empty())) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
|
||||
#endif
|
||||
|
||||
if (queue_.empty()) {
|
||||
std::vector<particle::Particle> new_particles;
|
||||
|
||||
current_event += 1;
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Inject particles to queue.");
|
||||
#endif
|
||||
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
||||
new_particles = determineInjectedParticles(random_.get(),
|
||||
beta_particle_weight);
|
||||
new_particles = injector_->rollNewParticles(random_->engine(), timestep + injectionGroupOffset);
|
||||
// construction of stringstream can take up a lot of computation time
|
||||
// even if the debug output performs nothing therefore use the if defined
|
||||
// preprocessor directive
|
||||
#if defined debug_level3
|
||||
#if defined(debug_level3)
|
||||
for(auto& particle : new_particles) {
|
||||
std::stringstream output_ss;
|
||||
output_ss << particle.specie()->name() << " with velocity (cart): ";
|
||||
output_ss << particle.velocity().cartesianEntries();
|
||||
output_ss << " and position (cart)";
|
||||
output_ss << particle.position().cartesianEntries();
|
||||
output_ss << particle.cartesianPosition().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
}
|
||||
#endif
|
||||
SimulationTimer::eventStopPoint(std::string("ParticleInjection"));
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Injected particles to queue.");
|
||||
|
||||
#endif
|
||||
// if no new particles are injected trying to draw more particles will
|
||||
// again yield nothing. And since this block is only executed if
|
||||
// the "main"-queue is empty, this means that there is nothing to be
|
||||
// done in terms of new beta particles in this timestep
|
||||
if(new_particles.empty()) {
|
||||
DEBUG("No new beta particles.");
|
||||
return;
|
||||
}
|
||||
queue_.insert(queue_.end(), new_particles.begin(),
|
||||
new_particles.end());
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Particles in queue: " +
|
||||
std::to_string(queue_.size()));
|
||||
const int particle_number =
|
||||
particleNumberFromQueue(queue_.size(), random_.get());
|
||||
|
||||
// extract particle from queue here, so that an extension of the queue does
|
||||
// not mess up the reference
|
||||
particle::Particle particle = queue_.at(particle_number);
|
||||
queue_.erase(queue_.begin() + particle_number);
|
||||
#endif
|
||||
particle::Particle particle = queue_.back();
|
||||
queue_.pop_back();
|
||||
|
||||
processUntilTermination(particle);
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::processDensityEvents(int events, const double weight_factor) {
|
||||
void Simulation::processDensityEvents() {
|
||||
#ifdef debug
|
||||
DEBUG_LEVEL_0("Processing density events.");
|
||||
#endif
|
||||
// number of full grid traversions (legacy variable)
|
||||
int current_event = 0;
|
||||
|
||||
// calculate the number of particles currently contained within the densities
|
||||
// of the different tracked species before injection in order to avoid
|
||||
// the expensive recalculateDensityField funtion being calculated for every
|
||||
// new injection event
|
||||
std::map<std::string, double> particleNumbers;
|
||||
for(auto& pair: tracked_species_) {
|
||||
particleNumbers[pair.first] = (pair.second->densityForDrawing()->particleNumber());
|
||||
// injector_->fillParticleNumbers(pair.second);
|
||||
}
|
||||
|
||||
while ((current_event < events) || (!queue_.empty())) {
|
||||
while ((!queue_.empty()) || (!storage_queue_[active_storage].empty())) {
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Current event: " + std::to_string(current_event));
|
||||
#endif
|
||||
|
||||
if (queue_.empty()) {
|
||||
std::vector<particle::Particle> new_particles;
|
||||
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Current density event: " + std::to_string(current_event));
|
||||
#endif
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("DensityInjection"));
|
||||
new_particles = determineInjectedDensityParticles(random_.get(),
|
||||
weight_factor, current_event, particleNumbers);
|
||||
particle::Particle newParticle(storage_queue_[active_storage].back(),
|
||||
tracked_species_);
|
||||
storage_queue_[active_storage].pop_back();
|
||||
SimulationTimer::eventStopPoint(std::string("DensityInjection"));
|
||||
|
||||
#if defined debug_level3
|
||||
for(auto& particle : new_particles) {
|
||||
std::stringstream output_ss;
|
||||
output_ss << particle.specie()->name() << " with velocity (cart): ";
|
||||
output_ss << particle.velocity().cartesianEntries();
|
||||
output_ss << " and position (cart)";
|
||||
output_ss << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
}
|
||||
std::stringstream output_ss;
|
||||
output_ss << newParticle.specie()->name() << " with velocity (cart): ";
|
||||
output_ss << newParticle.velocity().cartesianEntries();
|
||||
output_ss << " and position (cart)";
|
||||
output_ss << newParticle.cartesianPosition().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
#endif
|
||||
// if no new particles could be injected from the density, it is not possible
|
||||
// that during another iteration cycle new particles will be injected
|
||||
// (drawing field only changes after timesteps)
|
||||
if(new_particles.empty()) {
|
||||
return;
|
||||
}
|
||||
// (drawing field only changes after timesteps)
|
||||
current_event += 1;
|
||||
|
||||
queue_.insert(queue_.end(), new_particles.begin(), new_particles.end());
|
||||
queue_.push_back(newParticle);
|
||||
}
|
||||
#ifdef debug_level2
|
||||
DEBUG_LEVEL_2("Particles in queue: " +
|
||||
std::to_string(queue_.size()));
|
||||
const int particle_number =
|
||||
particleNumberFromQueue(queue_.size(), random_.get());
|
||||
std::to_string(queue_.size()));
|
||||
#endif
|
||||
// const int particle_number =
|
||||
// particleNumberFromQueue(queue_.size(), random_.get());
|
||||
|
||||
// extract particle from queue here, so that an extension of the queue does
|
||||
// not mess up the reference
|
||||
particle::Particle particle = queue_.at(particle_number);
|
||||
queue_.erase(queue_.begin() + particle_number);
|
||||
particle::Particle particle = queue_.back();// queue_.at(particle_number);
|
||||
// queue_.erase(queue_.begin() + particle_number);
|
||||
queue_.pop_back();
|
||||
|
||||
processUntilTermination(particle);
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::processUntilTermination(
|
||||
particle::Particle& particle) {
|
||||
void Simulation::processUntilTermination(particle::Particle& particle) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Process particle until termination");
|
||||
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
|
||||
while (particle.specie()->terminator()->isAlive(&particle)) {
|
||||
auto old_position = particle.position();
|
||||
#endif
|
||||
auto old_position = particle.cylinderPosition();
|
||||
double old_energy = particle.kineticEnergy_eV();
|
||||
while (particle.specie()->terminator()->isAlive(&particle, old_position)) {
|
||||
old_position = particle.cylinderPosition();
|
||||
old_energy = particle.kineticEnergy_eV();
|
||||
|
||||
std::vector<double> macroscopic_cross_sections_m;
|
||||
if(!particle.isNextInteractionValid()) {
|
||||
// DEBUG_LEVEL_1("Calculate time until collision");
|
||||
SimulationTimer::eventStartPoint(std::string("CollTime calculation"));
|
||||
collisionTime(particle, random_.get());
|
||||
SimulationTimer::eventStopPoint(std::string("CollTime calculation"));
|
||||
}
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("MFP calculation"));
|
||||
const double mfp_m = meanFreePath(particle, random_.get(),
|
||||
macroscopic_cross_sections_m);
|
||||
SimulationTimer::eventStopPoint(std::string("MFP calculation"));
|
||||
#ifdef debug_level3
|
||||
std::stringstream out_;
|
||||
out_ << "Time until collision: " << particle.timeUntilCollision();
|
||||
DEBUG_LEVEL_1(out_.str());
|
||||
#endif
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("Mover"));
|
||||
particle.specie()->mover()->move(&particle, mfp_m, electric_field_.get(),
|
||||
magnetic_field_.get(), gravity_field_.get());
|
||||
old_position = particle.specie()->mover()->move(&particle,
|
||||
particle.timeUntilCollision(),
|
||||
electric_field_.get(),
|
||||
magnetic_field_.get(),
|
||||
gravity_field_.get());
|
||||
SimulationTimer::eventStopPoint(std::string("Mover"));
|
||||
|
||||
bool was_reflected = false;
|
||||
if (particle.specie()->reflector()->needsReflectionBackToDomain(
|
||||
&particle)) {
|
||||
if (particle.specie()->reflector()->needsReflectionBackToDomain(&particle)) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Reflect particle.");
|
||||
old_position = particle.position();
|
||||
#endif
|
||||
old_position = particle.cylinderPosition();
|
||||
particle.specie()->reflector()->reflectBackToDomain(&particle);
|
||||
// current in azimuthal direction will not be calculated correctly due
|
||||
// old_position being a CylinderCoordinate
|
||||
particle.specie()->currentCollector()->collect(&particle, old_position);
|
||||
was_reflected = true;
|
||||
}
|
||||
|
||||
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
||||
&particle)) {
|
||||
&particle) &&
|
||||
!particle.specie()->terminator()->leftSimulationDomain(
|
||||
&particle, old_position) &&
|
||||
!was_reflected) {
|
||||
// particle.invalidateNextInteraction();
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
|
||||
". Reached timeresolution.");
|
||||
#endif
|
||||
#ifdef debug
|
||||
if(!particle.wasDeposited()) {
|
||||
std::stringstream out;
|
||||
out << "particle " << particle.specie()->name();
|
||||
out << " reached maximum time alive and is deleted without contributing";
|
||||
out << " to the density";
|
||||
ERROR(out.str());
|
||||
}
|
||||
#endif
|
||||
|
||||
storage_queue_[inactive_storage].push_back(particle.serialize());
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(particle.specie()->name() + " pushed back into storage.");
|
||||
#endif
|
||||
|
||||
if(particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.position(),
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
||||
DeletionType::max_time_alive);
|
||||
}
|
||||
break;
|
||||
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
||||
&particle)) {
|
||||
#if defined debug_level3
|
||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
||||
&particle, old_position)) {
|
||||
#if defined(debug)
|
||||
DEBUG("Terminate particle " + particle.specie()->name()
|
||||
+ ". Left simulation domain.");
|
||||
std::stringstream output_ss;
|
||||
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
|
||||
output_ss << " (cart): " << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
// std::stringstream output_ss;
|
||||
// output_ss << "Position (cyl): " << particle.cylinderPosition().cylinderEntries();
|
||||
// output_ss << " (cart): " << particle.cartesianPosition().cartesianEntries();
|
||||
// ERROR(output_ss.str());
|
||||
#endif
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.position(),
|
||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
||||
DeletionType::wall);
|
||||
particle.specie()->deletionLogger()->logDeletion(particle,
|
||||
PhysicalDeletionType::wall);
|
||||
}
|
||||
#ifdef debug
|
||||
if(particle.wasDeposited()) {
|
||||
std::stringstream out;
|
||||
out << "particle " << particle.specie()->name();
|
||||
out << " left simulation domain but still contributes to the density";
|
||||
out << "\nold position: " << old_position.cylinderEntries();
|
||||
out << "\nposition: " << particle.cylinderPosition().cylinderEntries();
|
||||
out << "\nvelocity: " << particle.velocity().cartesianEntries();
|
||||
ERROR(out.str());
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(particle.specie()->dynamicDensityField()->changedPositionBin(
|
||||
old_position, particle.position())) &&
|
||||
if ((!(particle.specie()->dynamicDensityField()->changedPositionBin(
|
||||
old_position, particle.cylinderPosition())) &&
|
||||
!(particle.specie()->dynamicDensityField()->changedEnergyBin(
|
||||
old_energy, particle.kineticEnergy_eV())) &&
|
||||
!was_reflected) {
|
||||
!was_reflected) || particle.timeUntilCollision() <= 0.) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Perform interaction.");
|
||||
DEBUG_LEVEL_3("Number of Interactions: " +
|
||||
std::to_string(particle.interactionCounter()));
|
||||
DEBUG_LEVEL_3("Ekin before interact: " +
|
||||
std::to_string(particle.kineticEnergy_eV()));
|
||||
#if defined debug_level3
|
||||
std::stringstream output_ss;
|
||||
output_ss << "Position (cyl): " << particle.position().cylinderEntries();
|
||||
output_ss << "Position (cyl): " << particle.cylinderPosition().cylinderEntries();
|
||||
// output_ss << "\n (cart): " << particle.position().cartesianEntries();
|
||||
DEBUG_LEVEL_3(output_ss.str());
|
||||
#endif
|
||||
|
||||
SimulationTimer::eventStartPoint(std::string("Interaction"));
|
||||
interaction::InteractionOutput output = interact(particle, random_.get(),
|
||||
macroscopic_cross_sections_m);
|
||||
interaction::InteractionOutput output = interact(particle, random_.get());//,
|
||||
// macroscopic_cross_sections_m);
|
||||
SimulationTimer::eventStopPoint(std::string("Interaction"));
|
||||
|
||||
// particle has reached time resolution, but was not deposited due to
|
||||
// the interaction taking place at the same time.
|
||||
// If the particle is not destroyed in the interaction put it into the mover
|
||||
// in order to log the position. (Not ideal, but otherwise it would be a bit
|
||||
// more effort to calculate the pitchangle here again...)
|
||||
// should work, since the check for died in bin should immediatly happen (hopefully)
|
||||
// if(particle.specie()->terminator()->reachedMaxTimeAlive(&particle)
|
||||
// && !particle.wasDeposited() && !output.deleteCurrentParticle()) {
|
||||
// particle.specie()->mover()->move(&particle, 1,
|
||||
// electric_field_.get(), magnetic_field_.get(), gravity_field_.get());
|
||||
// if(!particle.wasDeposited()) {
|
||||
// ERROR("particle was not deposited even though it should have been");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
particle.increaseInteractionCounter();
|
||||
|
||||
for (auto& new_particle : output.newParticles()) {
|
||||
@@ -469,43 +530,80 @@ void Simulation::processUntilTermination(
|
||||
}
|
||||
|
||||
if (output.deleteCurrentParticle()) {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3(particle.specie()->name() + " removed due to interaction.");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (particle.specie()->terminator()->reachedMaxInteractions(&particle)) {
|
||||
// don't save particles that terminate due to the maximum interactions
|
||||
// for now (might have to be done in the future though)
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
||||
+ ". Reached max interactions.");
|
||||
#endif
|
||||
if (particle.specie()->deletionLogger()) {
|
||||
particle.specie()->deletionLogger()->logDeletion(
|
||||
particle.position(), DeletionType::max_interactions);
|
||||
particle.cylinderPosition(), DeletionType::max_interactions);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
particle.invalidateNextInteraction();
|
||||
}
|
||||
}
|
||||
|
||||
double Simulation::meanFreePath(particle::Particle& particle,
|
||||
RandomNumbers* random,
|
||||
std::vector<double>& macroscopic_cross_sections_m) {
|
||||
double total_macroscopic_cross_section_m = 0.;
|
||||
for (auto& interaction : particle.specie()->interactions()) {
|
||||
double cross_section_tmp = interaction->macroscopicCrossSection(particle);
|
||||
total_macroscopic_cross_section_m += cross_section_tmp;
|
||||
macroscopic_cross_sections_m.push_back(cross_section_tmp);
|
||||
// maybe rewrite to s.t. the min_element part can be removed (together with the
|
||||
// algorithm lib)
|
||||
void Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
||||
std::vector<double> collision_times;
|
||||
double tmp;
|
||||
|
||||
for(auto& interaction : particle.specie()->interactions()) {
|
||||
tmp = interaction->drawCollisionTime(particle, random);
|
||||
collision_times.push_back(tmp);
|
||||
}
|
||||
|
||||
if (total_macroscopic_cross_section_m <= 0.) {
|
||||
return std::numeric_limits<double>::max();
|
||||
} else {
|
||||
const double rnd_number = random->rollUniform(0., 1.);
|
||||
if (rnd_number <= 0) {
|
||||
return std::numeric_limits<double>::max();
|
||||
} else {
|
||||
return 1. / total_macroscopic_cross_section_m * log(1. / rnd_number);
|
||||
}
|
||||
auto min_iterator = std::min_element(collision_times.begin(), collision_times.end());
|
||||
|
||||
particle.indexNextInteration((min_iterator - collision_times.begin()));
|
||||
particle.timeUntilCollision(*min_iterator);
|
||||
|
||||
#ifdef debug_level1
|
||||
std::stringstream out;
|
||||
out << "collision times ";
|
||||
out << particle.specie()->name() <<":\n[ ";
|
||||
|
||||
for(auto& element : collision_times) {
|
||||
out << element << " ";
|
||||
}
|
||||
out << "]";
|
||||
out << "\nmin value: " << *min_iterator;
|
||||
out << "\nindexNextInteraction: " << particle.indexNextInteraction();
|
||||
|
||||
DEBUG(out.str());
|
||||
#endif
|
||||
}
|
||||
|
||||
interaction::InteractionOutput Simulation::interact(
|
||||
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())
|
||||
->performInteraction(particle, random);
|
||||
}
|
||||
|
||||
interaction::InteractionOutput Simulation::interact(
|
||||
@@ -532,70 +630,38 @@ interaction::InteractionOutput Simulation::interact(
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<particle::Particle> Simulation::determineInjectedParticles(
|
||||
RandomNumbers* random, const double beta_particle_weight) {
|
||||
return injector_->rollNewParticles(random->engine(), timer_->time(),
|
||||
beta_particle_weight);
|
||||
}
|
||||
|
||||
// weight_factor has to be such that particleNumber * weight_factor = weight
|
||||
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||
RandomNumbers* random, const double weight_factor, const int current,
|
||||
std::map<std::string, double>& particleNumbers) {
|
||||
std::vector<particle::Particle> new_particles{};
|
||||
|
||||
if(!new_particles.empty()) {
|
||||
ERROR("In drawing particles from the density:"
|
||||
" the new particles vector is not empty at initialization");
|
||||
}
|
||||
|
||||
const double injection_time = timer_->time() - timer_->getDeltaT();
|
||||
|
||||
for(auto& pair: tracked_species_) {
|
||||
if (particleNumbers[pair.first] == 0) {
|
||||
DEBUG_LEVEL_3("No particles in density of species: " + pair.second->name());
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined debug_level2
|
||||
// if (current == 0) {
|
||||
std::stringstream out;
|
||||
out << pair.second->name();
|
||||
out << "particle number from density: ";
|
||||
out << particleNumbers[pair.first];
|
||||
DEBUG_LEVEL_2(out.str());
|
||||
// }
|
||||
#endif
|
||||
|
||||
injector_->drawNewParticleFromDensityField(random->engine(),
|
||||
pair.second, new_particles, magnetic_field_,
|
||||
weight_factor, injection_time);
|
||||
}
|
||||
return new_particles;
|
||||
}
|
||||
|
||||
//maybe put that into the poisson solver
|
||||
blitz::Array<double,3> Simulation::chargedensity() {
|
||||
blitz::Array<double,2> Simulation::chargedensity() {
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Initialize chargedensity Array");
|
||||
#endif
|
||||
//not great but the size and bounds of the density arrays are needed...
|
||||
std::shared_ptr<species::TrackedSpecie> firstTracked =
|
||||
tracked_species_.begin()->second;
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("shared pointer extracted, key: "
|
||||
+ tracked_species_.begin()->first);
|
||||
#endif
|
||||
|
||||
if(!firstTracked)
|
||||
ERROR("Extracted pointer is null.");
|
||||
blitz::Array<double,3> init = firstTracked->
|
||||
|
||||
blitz::Array<double,2> init = firstTracked->
|
||||
dynamicDensityField()->densityArray();
|
||||
blitz::Array<double, 3> chargeden(init.lbound(), init.extent());
|
||||
blitz::Array<double, 2> chargeden(init.lbound(), init.extent());
|
||||
chargeden = 0.;
|
||||
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Collect chargedensity");
|
||||
#endif
|
||||
for (auto& pair : tracked_species_) {
|
||||
chargeden += pair.second->charge_C() * pair.second->dynamicDensityField()->
|
||||
densityArray();
|
||||
}
|
||||
#ifdef debug_level3
|
||||
DEBUG_LEVEL_3("Maximum value in the chargedensity: " +
|
||||
std::to_string(blitz::max(chargeden)));
|
||||
#endif
|
||||
|
||||
return chargeden;
|
||||
}
|
||||
|
||||
+13
-19
@@ -10,6 +10,7 @@
|
||||
#include "simulation/terminator.h"
|
||||
#include "simulation/velocity_distribution.h"
|
||||
#include "simulation/event_position_distribution.h"
|
||||
#include "simulation/random_numbers.h"
|
||||
|
||||
namespace species {
|
||||
|
||||
@@ -42,8 +43,7 @@ TrackedSpecie::TrackedSpecie(
|
||||
std::shared_ptr<Reflector> reflector,
|
||||
std::shared_ptr<DynamicDensityField> density_field,
|
||||
std::shared_ptr<VelocityDistribution> velocity_distribution,
|
||||
std::shared_ptr<DriftVelocity> drift_velocity,
|
||||
std::shared_ptr<DynamicDensityField> density_for_drawing)
|
||||
std::shared_ptr<DriftVelocity> drift_velocity)
|
||||
: Specie(type, name, mass_kg, charge_C),
|
||||
mover_(mover),
|
||||
terminator_(terminator),
|
||||
@@ -51,22 +51,25 @@ TrackedSpecie::TrackedSpecie(
|
||||
density_field_(density_field),
|
||||
deletion_logger_(std::shared_ptr<DeletionLogger>(nullptr)),
|
||||
current_collector_(std::shared_ptr<CurrentCollector>(nullptr)),
|
||||
velocity_distribution_(velocity_distribution),
|
||||
drift_velocity_(drift_velocity),
|
||||
density_for_drawing_(density_for_drawing),
|
||||
position_distribution_from_density_(
|
||||
std::make_shared<PositionDistributionFromDensity>(density_for_drawing)),
|
||||
velocity_distribution_from_density_(
|
||||
std::make_shared<VelocityDistributionFromDensityField>(
|
||||
density_for_drawing, mass_kg)) {}
|
||||
density_field, mass_kg)) {}
|
||||
|
||||
DensityField* TrackedSpecie::densityField() {
|
||||
// return the density field storing the previous timestep, since
|
||||
// that density is the only one that makes sense for the calculation
|
||||
// of e.g. MFP for Tracked-Tracked interactions
|
||||
return density_field_.get();
|
||||
}
|
||||
|
||||
VelocityDistribution* TrackedSpecie::velocityDistibution() {
|
||||
return velocity_distribution_.get();
|
||||
VelocityDistribution* TrackedSpecie::velocityDistribution() {
|
||||
// return velocity_distribution_.get();
|
||||
// return the distribution from the calculated density distribution instead of
|
||||
// the one (potentially) given at construction.
|
||||
return velocity_distribution_from_density_.get();
|
||||
}
|
||||
|
||||
DriftVelocity* TrackedSpecie::driftVelocity() {
|
||||
return drift_velocity_.get();
|
||||
}
|
||||
@@ -75,10 +78,6 @@ DynamicDensityField* TrackedSpecie::dynamicDensityField() {
|
||||
return density_field_.get();
|
||||
}
|
||||
|
||||
DynamicDensityField* TrackedSpecie::densityForDrawing() {
|
||||
return density_for_drawing_.get();
|
||||
}
|
||||
|
||||
Mover* TrackedSpecie::mover() {
|
||||
return mover_.get();
|
||||
}
|
||||
@@ -99,11 +98,6 @@ CurrentCollector* TrackedSpecie::currentCollector() {
|
||||
return current_collector_.get();
|
||||
}
|
||||
|
||||
PositionDistributionFromDensity*
|
||||
TrackedSpecie::positionDistributionFromDensity() {
|
||||
return position_distribution_from_density_.get();
|
||||
}
|
||||
|
||||
VelocityDistributionFromDensityField*
|
||||
TrackedSpecie::velocityDistributionFromDensityField() {
|
||||
return velocity_distribution_from_density_.get();
|
||||
@@ -144,7 +138,7 @@ BackgroundSpecie::BackgroundSpecie(
|
||||
DensityField* BackgroundSpecie::densityField() {
|
||||
return density_field_.get();
|
||||
}
|
||||
VelocityDistribution* BackgroundSpecie::velocityDistibution() {
|
||||
VelocityDistribution* BackgroundSpecie::velocityDistribution() {
|
||||
return velocity_distribution_.get();
|
||||
}
|
||||
DriftVelocity* BackgroundSpecie::driftVelocity() {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user