Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
@@ -15,6 +15,7 @@ class Hdf5Reader {
|
|||||||
blitz::Array<double, 2> readD2Double(std::string path);
|
blitz::Array<double, 2> readD2Double(std::string path);
|
||||||
blitz::Array<double, 1> readD1Double(std::string path);
|
blitz::Array<double, 1> readD1Double(std::string path);
|
||||||
double readDouble(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, 5> readD5LongInt(std::string path);
|
||||||
blitz::Array<long int, 4> readD4LongInt(std::string path);
|
blitz::Array<long int, 4> readD4LongInt(std::string path);
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class Hdf5Writer {
|
|||||||
void write(const blitz::Array<double, 3>& data, std::string path);
|
void write(const blitz::Array<double, 3>& data, std::string path);
|
||||||
void write(const blitz::Array<double, 4>& data, std::string path);
|
void write(const blitz::Array<double, 4>& data, std::string path);
|
||||||
void write(const blitz::Array<double, 5>& data, std::string path);
|
void write(const blitz::Array<double, 5>& data, std::string path);
|
||||||
void write(const blitz::Array<float, 5>& data, std::string path);
|
|
||||||
void write(const blitz::Array<long int, 4>& data, std::string path);
|
void write(const blitz::Array<long int, 4>& data, std::string path);
|
||||||
void write(const blitz::Array<long int, 5>& data, std::string path);
|
void write(const blitz::Array<long int, 5>& data, std::string path);
|
||||||
void write(const blitz::TinyVector<double, 3>& data, std::string path);
|
void write(const blitz::TinyVector<double, 3>& data, 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 <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "IO/hdf5_reader.h"
|
#include "IO/hdf5_reader.h"
|
||||||
|
#include "IO/mpi_particle_reader.h"
|
||||||
|
|
||||||
namespace species {
|
namespace species {
|
||||||
class TrackedSpecie;
|
class TrackedSpecie;
|
||||||
enum class ImplementedSpecies;
|
enum class ImplementedSpecies;
|
||||||
}; // namespace species
|
}; // namespace species
|
||||||
|
|
||||||
|
namespace particle {
|
||||||
|
class SerializedParticle;
|
||||||
|
};
|
||||||
|
|
||||||
class DynamicDensityField;
|
class DynamicDensityField;
|
||||||
class PoissonSolver;
|
class PoissonSolver;
|
||||||
class RandomNumbers;
|
class RandomNumbers;
|
||||||
@@ -23,11 +29,15 @@ class RandomNumbers;
|
|||||||
// here after the potential is loaded; would need the electric field class to be included
|
// here after the potential is loaded; would need the electric field class to be included
|
||||||
class Restart {
|
class Restart {
|
||||||
public:
|
public:
|
||||||
Restart(bool do_restart, std::string absolute_filename,
|
// Restart(bool do_restart, std::string absolute_filename,
|
||||||
std::string restart_identifier);
|
// 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,
|
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:
|
private:
|
||||||
void restartTimer(species::TrackedSpecie* reference_specie);
|
void restartTimer(species::TrackedSpecie* reference_specie);
|
||||||
@@ -36,9 +46,11 @@ class Restart {
|
|||||||
// only load in the potential and calc the electric field
|
// only load in the potential and calc the electric field
|
||||||
void restartPoissonSolver(PoissonSolver* solver);
|
void restartPoissonSolver(PoissonSolver* solver);
|
||||||
void restartRandomNumbers(RandomNumbers* random);
|
void restartRandomNumbers(RandomNumbers* random);
|
||||||
|
void restartParticles(std::vector<particle::SerializedParticle>& storage_queue);
|
||||||
|
|
||||||
bool do_restart_;
|
bool do_restart_;
|
||||||
std::string restart_identifier_; // i.e. "LastSyncPeriod" or "SyncPeriod_*"
|
std::string restart_identifier_; // i.e. "LastSyncPeriod" or "SyncPeriod_*"
|
||||||
Hdf5Reader reader_;
|
Hdf5Reader reader_;
|
||||||
|
MpiParticleReader particle_reader_;
|
||||||
};
|
};
|
||||||
#endif /* RESTART_H */
|
#endif /* RESTART_H */
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include "IO/hdf5_writer.h"
|
#include "IO/hdf5_writer.h"
|
||||||
|
#include "IO/mpi_particle_writer.h"
|
||||||
|
|
||||||
class DynamicDensityField;
|
class DynamicDensityField;
|
||||||
class CurrentBorder;
|
class CurrentBorder;
|
||||||
@@ -30,13 +31,15 @@ struct OutputTask {
|
|||||||
class SimulationOutput {
|
class SimulationOutput {
|
||||||
public:
|
public:
|
||||||
SimulationOutput(const std::string& output_folder,
|
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 addDensityFieldOutput(OutputTask task);
|
||||||
void addCurrentBorderOutput(OutputTask task);
|
void addCurrentBorderOutput(OutputTask task);
|
||||||
void addDeletionLoggerOutput(OutputTask task);
|
void addDeletionLoggerOutput(OutputTask task);
|
||||||
void setPotentialOutput(OutputTask task);
|
void setPotentialOutput(OutputTask task);
|
||||||
void setRestartInfoOutput(OutputTask task);
|
void setRestartInfoOutput(OutputTask task);
|
||||||
|
void setParticleOutput(OutputTask task);
|
||||||
|
|
||||||
void writeMetaData(
|
void writeMetaData(
|
||||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||||
@@ -45,7 +48,9 @@ class SimulationOutput {
|
|||||||
void writeSimulationData(
|
void writeSimulationData(
|
||||||
int cpu_sync,
|
int cpu_sync,
|
||||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
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);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<OutputTask> tasks_density_fields_;
|
std::vector<OutputTask> tasks_density_fields_;
|
||||||
@@ -53,8 +58,10 @@ class SimulationOutput {
|
|||||||
std::vector<OutputTask> tasks_deletion_logger_;
|
std::vector<OutputTask> tasks_deletion_logger_;
|
||||||
OutputTask task_potential_;
|
OutputTask task_potential_;
|
||||||
OutputTask task_rng_;
|
OutputTask task_rng_;
|
||||||
|
OutputTask task_particles_;
|
||||||
|
|
||||||
Hdf5Writer writer;
|
Hdf5Writer writer;
|
||||||
|
MpiParticleWriter particle_writer;
|
||||||
|
|
||||||
void writeSimulationData(DynamicDensityField* density_field,
|
void writeSimulationData(DynamicDensityField* density_field,
|
||||||
std::string species_path,
|
std::string species_path,
|
||||||
@@ -107,8 +114,11 @@ class SimulationOutput {
|
|||||||
std::string path_to_field);
|
std::string path_to_field);
|
||||||
|
|
||||||
void writeRestartData(std::mt19937* engine, int cpu_sync,
|
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 writeRandomEngineState(std::mt19937* engine, std::string path);
|
||||||
|
|
||||||
|
void writeParticles(std::vector<particle::SerializedParticle>& particles,
|
||||||
|
int cpu_sync, double dt);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SIMULATION_OUTPUT_H */
|
#endif /* SIMULATION_OUTPUT_H */
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ struct TrackedSpeciesBuilderInfo {
|
|||||||
|
|
||||||
double mass_kg;
|
double mass_kg;
|
||||||
double charge_C;
|
double charge_C;
|
||||||
|
bool explicitly_stored;
|
||||||
species::ImplementedSpecies type;
|
species::ImplementedSpecies type;
|
||||||
std::string name;
|
std::string name;
|
||||||
json_path path_in_json;
|
json_path path_in_json;
|
||||||
@@ -109,6 +110,7 @@ class SpeciesBuilder {
|
|||||||
void fillTerminator(Parameter& parameter);
|
void fillTerminator(Parameter& parameter);
|
||||||
void fillReflector(Parameter& parameter);
|
void fillReflector(Parameter& parameter);
|
||||||
void fillTrackedDensity(Parameter& parameter);
|
void fillTrackedDensity(Parameter& parameter);
|
||||||
|
void fillDensityDrawingType(Parameter& parameter);
|
||||||
|
|
||||||
void initTimer();
|
void initTimer();
|
||||||
void buildSpecies();
|
void buildSpecies();
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ class Specie;
|
|||||||
|
|
||||||
namespace interaction {
|
namespace interaction {
|
||||||
|
|
||||||
|
// class for (radiative) cluster formation interactions (A + B --> AB) 7
|
||||||
|
// or (A + BC --> AB + C)
|
||||||
class ClusterFormation : public Interaction {
|
class ClusterFormation : public Interaction {
|
||||||
public:
|
public:
|
||||||
ClusterFormation(std::function<double(double)> cross_section,
|
ClusterFormation(std::function<double(double)> cross_section,
|
||||||
@@ -18,10 +20,27 @@ class ClusterFormation : public Interaction {
|
|||||||
InteractionOutput performInteraction(particle::Particle& particle,
|
InteractionOutput performInteraction(particle::Particle& particle,
|
||||||
RandomNumbers* generator);
|
RandomNumbers* generator);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
std::shared_ptr<species::TrackedSpecie> product_;
|
std::shared_ptr<species::TrackedSpecie> product_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// class for tertiary association (A + B + B --> 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
}; // namespace interaction
|
}; // namespace interaction
|
||||||
|
|
||||||
#endif /* CLUSTER_FORMATION_H */
|
#endif /* CLUSTER_FORMATION_H */
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ class ElasticScattering : public Interaction {
|
|||||||
|
|
||||||
InteractionOutput performInteraction(particle::Particle& particle,
|
InteractionOutput performInteraction(particle::Particle& particle,
|
||||||
RandomNumbers* generator);
|
RandomNumbers* generator);
|
||||||
|
virtual double drawCollisionTime(particle::Particle& particle,
|
||||||
|
RandomNumbers* generator);
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<ScatteringAngleDistribution> theta_distrib_;
|
std::shared_ptr<ScatteringAngleDistribution> theta_distrib_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class FreeMovement : public Interaction {
|
|||||||
InteractionOutput performInteraction(particle::Particle& particle,
|
InteractionOutput performInteraction(particle::Particle& particle,
|
||||||
RandomNumbers* generator);
|
RandomNumbers* generator);
|
||||||
|
|
||||||
double microscopicCrossSection(double energy_eV);
|
double microscopicCrossSection(double energy_eV, const Coordinate& position);
|
||||||
double macroscopicCrossSection(particle::Particle& particle);
|
double macroscopicCrossSection(particle::Particle& particle);
|
||||||
double drawCollisionTime(particle::Particle& particle,
|
double drawCollisionTime(particle::Particle& particle,
|
||||||
RandomNumbers* generator);
|
RandomNumbers* generator);
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ class Recombination : public Interaction {
|
|||||||
|
|
||||||
double macroscopicCrossSection(particle::Particle& particle);
|
double macroscopicCrossSection(particle::Particle& particle);
|
||||||
|
|
||||||
|
double drawCollisionTime(particle::Particle& particle, RandomNumbers* generator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double macroscopicCrossSection(const Coordinate& position, const int bin_index);
|
double macroscopicCrossSection(const Coordinate& position, const int bin_index);
|
||||||
std::shared_ptr<species::TrackedSpecie> recombination_target_;
|
std::shared_ptr<species::TrackedSpecie> recombination_target_;
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ class CpuSynchronizer {
|
|||||||
*/
|
*/
|
||||||
void sumToAll(blitz::Array<double, 4>& array,
|
void sumToAll(blitz::Array<double, 4>& array,
|
||||||
blitz::Array<double, 4>& last_sync_array);
|
blitz::Array<double, 4>& last_sync_array);
|
||||||
void sumToAll(blitz::Array<float, 5>& array,
|
|
||||||
blitz::Array<float, 5>& last_sync_array);
|
|
||||||
void sumToAll(blitz::Array<double, 5>& array,
|
void sumToAll(blitz::Array<double, 5>& array,
|
||||||
blitz::Array<double, 5>& last_sync_array);
|
blitz::Array<double, 5>& last_sync_array);
|
||||||
void sumToAll(blitz::Array<double, 3>& array,
|
void sumToAll(blitz::Array<double, 3>& array,
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ class DynamicDensityField : public DensityField {
|
|||||||
|
|
||||||
blitz::Array<double, 3> densityArray();
|
blitz::Array<double, 3> densityArray();
|
||||||
blitz::Array<double, 4> spectrumArray();
|
blitz::Array<double, 4> spectrumArray();
|
||||||
blitz::Array<float, 5> timeInBinArray() const;
|
blitz::Array<double, 5> timeInBinArray() const;
|
||||||
// blitz::Array<long int, 5> deletedParticlesArray() const;
|
// blitz::Array<long int, 5> deletedParticlesArray() const;
|
||||||
blitz::Array<double, 3> binVolumeArray() const;
|
blitz::Array<double, 3> binVolumeArray() const;
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ class DynamicDensityField : public DensityField {
|
|||||||
|
|
||||||
// return an array of the time in bin at the Coordinate position and the energy
|
// 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
|
// energy_eV (only pitch angle direction left); over and underflow bin are removed
|
||||||
blitz::Array<float, 1> sliceTimeInBinArray(const Coordinate& position,
|
blitz::Array<double, 1> sliceTimeInBinArray(const Coordinate& position,
|
||||||
double energy_eV) const;
|
double energy_eV) const;
|
||||||
|
|
||||||
const EnergyBinning* energyBinning() const;
|
const EnergyBinning* energyBinning() const;
|
||||||
@@ -94,10 +94,10 @@ class DynamicDensityField : public DensityField {
|
|||||||
// time in bin now contains the physical particle number per bin
|
// time in bin now contains the physical particle number per bin
|
||||||
// (not renamed, since that would require many, many changes due to
|
// (not renamed, since that would require many, many changes due to
|
||||||
// renaming of the functions)
|
// renaming of the functions)
|
||||||
blitz::Array<float, 5> time_in_bin_s_;
|
blitz::Array<double, 5> time_in_bin_s_;
|
||||||
// blitz::Array<long int, 5> deleted_particles_;
|
// blitz::Array<long int, 5> deleted_particles_;
|
||||||
|
|
||||||
blitz::Array<float, 5> sync_time_in_bin_s_;
|
blitz::Array<double, 5> sync_time_in_bin_s_;
|
||||||
// blitz::Array<long int, 5> sync_deleted_particles_;
|
// blitz::Array<long int, 5> sync_deleted_particles_;
|
||||||
|
|
||||||
blitz::Array<double, 4> density_per_m3_;
|
blitz::Array<double, 4> density_per_m3_;
|
||||||
|
|||||||
@@ -44,30 +44,31 @@ class PositionDistributionFromDensity {
|
|||||||
// Constructor taking a pointer to a DynamicDensityField object
|
// Constructor taking a pointer to a DynamicDensityField object
|
||||||
PositionDistributionFromDensity(std::shared_ptr<DynamicDensityField> density);
|
PositionDistributionFromDensity(std::shared_ptr<DynamicDensityField> density);
|
||||||
|
|
||||||
// draw a position from the density provided at construction using the rejection method
|
// // draw a position from the density provided at construction using the rejection method
|
||||||
CylinderCoordinate drawPosition(std::mt19937* engine);
|
// CylinderCoordinate drawPosition(std::mt19937* engine);
|
||||||
|
|
||||||
// draw a position uniformly distributed within the bin of the given index
|
// draw a position uniformly distributed within the bin of the given index
|
||||||
// (note that the r-dependence of the particle number in a uniform density distribution
|
// (note that the r-dependence of the particle number in a uniform density distribution
|
||||||
// is not incorporated)
|
// is not incorporated)
|
||||||
CylinderCoordinate drawPosition(std::mt19937* engine, int r_idx, int phi_idx,
|
CylinderCoordinate drawPosition(std::mt19937* engine, int r_idx, int phi_idx,
|
||||||
int z_idx);
|
int z_idx);
|
||||||
// sets the maximum density value needed for the rejection method
|
// // sets the maximum density value needed for the rejection method
|
||||||
// should not be called frequently, since during each call the density field is
|
// // should not be called frequently, since during each call the density field is
|
||||||
// recalculated from scratch by the DynamicDensityField object
|
// // recalculated from scratch by the DynamicDensityField object
|
||||||
void setMaximumDensity();
|
// void setMaximumDensity();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// variable storing the maximum value of the density
|
// variable storing the maximum value of the density
|
||||||
double maximum_density_ = 1.;
|
// double maximum_density_ = 1.;
|
||||||
|
|
||||||
std::shared_ptr<DynamicDensityField> density_;
|
std::shared_ptr<DynamicDensityField> density_;
|
||||||
|
|
||||||
// distributions for the spatial directions and for the density
|
// // distributions for the spatial directions and for the density
|
||||||
std::uniform_real_distribution<double> r_values;
|
// std::uniform_real_distribution<double> r_values;
|
||||||
std::uniform_real_distribution<double> phi_values;
|
// std::uniform_real_distribution<double> phi_values;
|
||||||
std::uniform_real_distribution<double> z_values;
|
// std::uniform_real_distribution<double> z_values;
|
||||||
std::uniform_real_distribution<double> density_values;
|
// std::uniform_real_distribution<double> density_values;
|
||||||
|
std::uniform_real_distribution<double> std_unifrm;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* EVENT_POSITION_DISTRIBUTION_H */
|
#endif /* EVENT_POSITION_DISTRIBUTION_H */
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ struct InjectorInfo {
|
|||||||
public:
|
public:
|
||||||
std::shared_ptr<species::TrackedSpecie> created_specie;
|
std::shared_ptr<species::TrackedSpecie> created_specie;
|
||||||
std::shared_ptr<VelocityDistribution> creation_velocity_distribution;
|
std::shared_ptr<VelocityDistribution> creation_velocity_distribution;
|
||||||
// int multiplicity;
|
double weight = 0;
|
||||||
|
int injection_group;
|
||||||
|
int injection_stride;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Injector {
|
class Injector {
|
||||||
@@ -39,11 +41,16 @@ class Injector {
|
|||||||
std::shared_ptr<DriftVelocity> mother_drift_velocity);
|
std::shared_ptr<DriftVelocity> mother_drift_velocity);
|
||||||
|
|
||||||
std::vector<particle::Particle> rollNewParticles(std::mt19937* engine,
|
std::vector<particle::Particle> rollNewParticles(std::mt19937* engine,
|
||||||
const double current_time,
|
const int timestep);
|
||||||
const double beta_particle_weight);
|
|
||||||
|
|
||||||
// draw new particles from the DynamicDensityField of the provided specie
|
// physical_number: physical number of particles that are injected in one
|
||||||
// the new particles are then appened to the vector queue
|
// 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);
|
||||||
|
|
||||||
|
// 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
|
// the magnetic field is necessary for the determination of the direction of the
|
||||||
// injected particles
|
// injected particles
|
||||||
// the weight_factor scales the time a particle contributes to a certain bin
|
// the weight_factor scales the time a particle contributes to a certain bin
|
||||||
@@ -53,8 +60,7 @@ class Injector {
|
|||||||
std::shared_ptr<species::TrackedSpecie> specie,
|
std::shared_ptr<species::TrackedSpecie> specie,
|
||||||
std::vector<particle::Particle>& queue,
|
std::vector<particle::Particle>& queue,
|
||||||
std::shared_ptr<MagneticField> field,
|
std::shared_ptr<MagneticField> field,
|
||||||
const double weight_factor,
|
const double weight_factor);
|
||||||
const double injection_time);
|
|
||||||
|
|
||||||
void initInjectionTimeDistribution(double delta_t);
|
void initInjectionTimeDistribution(double delta_t);
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class Interaction {
|
|||||||
Interaction(std::function<double(double)> cross_section,
|
Interaction(std::function<double(double)> cross_section,
|
||||||
std::shared_ptr<species::Specie> target);
|
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);
|
virtual double macroscopicCrossSection(particle::Particle& particle);
|
||||||
|
|
||||||
// return the time the given particle can travel in the laboratory frame
|
// return the time the given particle can travel in the laboratory frame
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ blitz::TinyVector<double, 3> rotateVector(const blitz::TinyVector<double, 3>& v,
|
|||||||
double theta,
|
double theta,
|
||||||
double phi);
|
double phi);
|
||||||
|
|
||||||
|
blitz::TinyVector<double, 3> rotateVector2(const blitz::TinyVector<double, 3>& v,
|
||||||
|
double theta,
|
||||||
|
double phi);
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
|
blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
|
||||||
const blitz::TinyVector<double, 3>& velocity_1,
|
const blitz::TinyVector<double, 3>& velocity_1,
|
||||||
const blitz::TinyVector<double, 3>& velocity_2,
|
const blitz::TinyVector<double, 3>& velocity_2,
|
||||||
|
|||||||
@@ -3,28 +3,34 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "simulation/coordinates.h"
|
#include "simulation/particle.h"
|
||||||
|
|
||||||
|
// to count numerical particle deletions
|
||||||
enum class DeletionType {
|
enum class DeletionType {
|
||||||
wall,
|
wall,
|
||||||
recombination,
|
recombination,
|
||||||
max_interactions,
|
max_interactions,
|
||||||
max_time_alive,
|
max_time_alive,
|
||||||
cluster_formation,
|
cluster_formation
|
||||||
creation_beta,
|
|
||||||
creation_density,
|
|
||||||
creation_interaction,
|
|
||||||
creation_above_2keV,
|
|
||||||
loss_above_2keV
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// to count physical particle deletion
|
||||||
|
enum class PhysicalDeletionType {
|
||||||
|
wall
|
||||||
|
};
|
||||||
|
class Coordinate;
|
||||||
|
|
||||||
class DeletionLogger {
|
class DeletionLogger {
|
||||||
public:
|
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
|
// why a coordinate as a parameter -> not used in implementation
|
||||||
virtual void logDeletion(const Coordinate& coordinate, DeletionType type);
|
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<DeletionType, long int> numDeletions() const;
|
||||||
|
std::map<PhysicalDeletionType, double> numPhysDeletions() const;
|
||||||
void numDeletions(long int new_value, DeletionType type);
|
void numDeletions(long int new_value, DeletionType type);
|
||||||
long int numDeletions(DeletionType type) const;
|
long int numDeletions(DeletionType type) const;
|
||||||
|
|
||||||
@@ -35,6 +41,10 @@ class DeletionLogger {
|
|||||||
private:
|
private:
|
||||||
std::map<DeletionType, long int> num_deletions;
|
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 */
|
#endif /* LOGGER_H */
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef MPI_COMMUNICATION_H
|
#ifndef MPI_COMMUNICATION_H
|
||||||
#define MPI_COMMUNICATION_H
|
#define MPI_COMMUNICATION_H
|
||||||
|
|
||||||
|
#include "mpi.h"
|
||||||
class MpiCommunication {
|
class MpiCommunication {
|
||||||
public:
|
public:
|
||||||
static int mpi_rank;
|
static int mpi_rank;
|
||||||
@@ -10,6 +11,9 @@ class MpiCommunication {
|
|||||||
static int mpiSize();
|
static int mpiSize();
|
||||||
|
|
||||||
static void init(int argc, char* argv[]);
|
static void init(int argc, char* argv[]);
|
||||||
|
|
||||||
|
static void create_mpi_info(MPI_Info* info);
|
||||||
|
|
||||||
static void finalize();
|
static void finalize();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,19 +5,61 @@
|
|||||||
#include "simulation/coordinates.h"
|
#include "simulation/coordinates.h"
|
||||||
#include "simulation/species.h"
|
#include "simulation/species.h"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
class MpiParticleReader;
|
||||||
|
|
||||||
namespace particle {
|
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 {
|
class Particle {
|
||||||
public:
|
public:
|
||||||
// Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
|
||||||
// Coordinate* position,
|
|
||||||
// Vector* velocity);
|
|
||||||
Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||||
const Coordinate& position,
|
const Coordinate& position,
|
||||||
const Vector& velocity,
|
const Vector& velocity,
|
||||||
const double time_birth,
|
const double time_birth,
|
||||||
const double weight);
|
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);
|
void position(const Coordinate& new_position);
|
||||||
CartesianCoordinate cartesianPosition() const;
|
CartesianCoordinate cartesianPosition() const;
|
||||||
CylinderCoordinate cylinderPosition() const;
|
CylinderCoordinate cylinderPosition() const;
|
||||||
@@ -51,13 +93,21 @@ class Particle {
|
|||||||
|
|
||||||
void indexNextInteration(const int index) { index_next_interaction_ = index; };
|
void indexNextInteration(const int index) { index_next_interaction_ = index; };
|
||||||
int indexNextInteraction() { return index_next_interaction_; };
|
int indexNextInteraction() { return index_next_interaction_; };
|
||||||
|
void invalidateNextInteraction() { index_next_interaction_ = -1; };
|
||||||
|
bool isNextInteractionValid() { return index_next_interaction_ >= 0; };
|
||||||
|
|
||||||
void deposited();
|
void timeUntilCollision(const double time_until_collision);
|
||||||
|
double timeUntilCollision() const;
|
||||||
|
void reduceTimeUntilCollision(const double delta);
|
||||||
|
|
||||||
|
void deposited(bool truthValue=true);
|
||||||
bool wasDeposited();
|
bool wasDeposited();
|
||||||
|
|
||||||
|
// note: particle id is not being stored!
|
||||||
|
particle::SerializedParticle serialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double weight_;
|
double weight_;
|
||||||
bool deposited_ = false;
|
|
||||||
|
|
||||||
CartesianVector velocity_;
|
CartesianVector velocity_;
|
||||||
CartesianCoordinate position_cart_;
|
CartesianCoordinate position_cart_;
|
||||||
@@ -67,8 +117,10 @@ class Particle {
|
|||||||
// double time_in_bin_s_;
|
// double time_in_bin_s_;
|
||||||
long int interaction_counter_;
|
long int interaction_counter_;
|
||||||
|
|
||||||
|
bool deposited_ = false;
|
||||||
// index of the interaction with the sortest distance (-1 if that's none of them)
|
// index of the interaction with the sortest distance (-1 if that's none of them)
|
||||||
int index_next_interaction_ = -1;
|
int index_next_interaction_ = -1;
|
||||||
|
double time_until_collision_;
|
||||||
|
|
||||||
std::shared_ptr<species::TrackedSpecie> specie_;
|
std::shared_ptr<species::TrackedSpecie> specie_;
|
||||||
long int id_;
|
long int id_;
|
||||||
|
|||||||
@@ -34,16 +34,12 @@ class Simulation {
|
|||||||
void init(Parameter& parameter);
|
void init(Parameter& parameter);
|
||||||
void start();
|
void start();
|
||||||
void finalize();
|
void finalize();
|
||||||
// cpu_syncs only included for debug purposes, e.g. only drawing decay particles
|
void processEvents(int events);
|
||||||
// at the 0th timestep
|
|
||||||
void processEvents(int events, const double beta_particle_weight);
|
|
||||||
|
|
||||||
void processDensityEvents(int particles_per_bin, const double weight_factor);
|
void processDensityEvents(int particles_per_bin, const double weight_factor);
|
||||||
void processUntilTermination(particle::Particle& particle);
|
void processUntilTermination(particle::Particle& particle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<particle::Particle> determineInjectedParticles(RandomNumbers* random,
|
|
||||||
const double beta_particle_weight);
|
|
||||||
std::vector<particle::Particle> determineInjectedDensityParticles(
|
std::vector<particle::Particle> determineInjectedDensityParticles(
|
||||||
RandomNumbers* random,
|
RandomNumbers* random,
|
||||||
const double weight_factor,
|
const double weight_factor,
|
||||||
@@ -51,14 +47,10 @@ class Simulation {
|
|||||||
std::map<std::string, double>& particleNumbers,
|
std::map<std::string, double>& particleNumbers,
|
||||||
bool& all_bins_done);
|
bool& all_bins_done);
|
||||||
|
|
||||||
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
|
// draw the individual collision times of the possible interactions and return the
|
||||||
// minimum of them. Also sets the "nextInteractionIndex" in the particle to the
|
// minimum of them. Also sets the "nextInteractionIndex" in the particle to the
|
||||||
// interaction of the chosen time.
|
// interaction of the chosen time.
|
||||||
double collisionTime(particle::Particle& particle, RandomNumbers* random);
|
void collisionTime(particle::Particle& particle, RandomNumbers* random);
|
||||||
interaction::InteractionOutput interact(particle::Particle& particle,
|
interaction::InteractionOutput interact(particle::Particle& particle,
|
||||||
RandomNumbers* random);
|
RandomNumbers* random);
|
||||||
|
|
||||||
@@ -90,6 +82,13 @@ class Simulation {
|
|||||||
std::shared_ptr<CpuSynchronizer> cpu_synchronizer_;
|
std::shared_ptr<CpuSynchronizer> cpu_synchronizer_;
|
||||||
|
|
||||||
std::vector<particle::Particle> queue_;
|
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 */
|
#endif /* SIMULATION_H */
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class TrackedSpecie : public Specie {
|
|||||||
std::string name,
|
std::string name,
|
||||||
double mass_kg,
|
double mass_kg,
|
||||||
double charge_C,
|
double charge_C,
|
||||||
|
bool explicitly_stored,
|
||||||
std::shared_ptr<Mover> mover,
|
std::shared_ptr<Mover> mover,
|
||||||
std::shared_ptr<Terminator> terminator,
|
std::shared_ptr<Terminator> terminator,
|
||||||
std::shared_ptr<Reflector> reflector,
|
std::shared_ptr<Reflector> reflector,
|
||||||
@@ -95,6 +96,8 @@ class TrackedSpecie : public Specie {
|
|||||||
// getter for the raw pointer to the RandomIndex object
|
// getter for the raw pointer to the RandomIndex object
|
||||||
RandomIndex* randomIndex();
|
RandomIndex* randomIndex();
|
||||||
|
|
||||||
|
bool explicitlyStored();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<DynamicDensityField> density_field_;
|
std::shared_ptr<DynamicDensityField> density_field_;
|
||||||
std::shared_ptr<VelocityDistribution> velocity_distribution_;
|
std::shared_ptr<VelocityDistribution> velocity_distribution_;
|
||||||
@@ -115,6 +118,11 @@ class TrackedSpecie : public Specie {
|
|||||||
velocity_distribution_from_density_;
|
velocity_distribution_from_density_;
|
||||||
|
|
||||||
std::shared_ptr<RandomIndex> random_index_;
|
std::shared_ptr<RandomIndex> random_index_;
|
||||||
|
|
||||||
|
// should work if it changes from true -> false (after a restart)
|
||||||
|
// however, it should not work in the opposite case (in which the
|
||||||
|
// old density would be lost)
|
||||||
|
const bool explicitly_stored_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BackgroundSpecie : public Specie {
|
class BackgroundSpecie : public Specie {
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ class VelocityDistributionFromDensityField : public VelocityDistribution {
|
|||||||
private:
|
private:
|
||||||
// mass of the species of which the density field is a part of
|
// mass of the species of which the density field is a part of
|
||||||
const double mass_kg_;
|
const double mass_kg_;
|
||||||
|
double alpha_lower_limit;
|
||||||
|
double alpha_upper_limit;
|
||||||
|
|
||||||
std::shared_ptr<DynamicDensityField> density_field_;
|
std::shared_ptr<DynamicDensityField> density_field_;
|
||||||
|
|
||||||
|
|||||||
+62
-51
@@ -9,7 +9,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Longitudinal": {
|
"Longitudinal": {
|
||||||
"NumberOfBins": 50,
|
"NumberOfBins": 100,
|
||||||
"MaxLength": {
|
"MaxLength": {
|
||||||
"value": 1657,
|
"value": 1657,
|
||||||
"unit": "cm"
|
"unit": "cm"
|
||||||
@@ -60,7 +60,7 @@
|
|||||||
},
|
},
|
||||||
"xValuesKey": "/z_position(m)",
|
"xValuesKey": "/z_position(m)",
|
||||||
"yValuesKey": "/n(m3)",
|
"yValuesKey": "/n(m3)",
|
||||||
"prefactor": 1E20
|
"prefactor": 6.337599E20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,11 +124,12 @@
|
|||||||
"Tracked": {
|
"Tracked": {
|
||||||
"e-": {
|
"e-": {
|
||||||
"ParticleType": "electron",
|
"ParticleType": "electron",
|
||||||
|
"StoreInQueue": "true",
|
||||||
"Mover": {
|
"Mover": {
|
||||||
"Drift": {
|
"Boris": {
|
||||||
"MaximalMovedDistance": {
|
"MaximalTimestepLength": {
|
||||||
"value": 1E-3,
|
"value": 2e-11,
|
||||||
"unit": "m"
|
"unit": "s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -168,7 +169,7 @@
|
|||||||
},
|
},
|
||||||
"EnergyBinning": {
|
"EnergyBinning": {
|
||||||
"Type": "Logarithmic",
|
"Type": "Logarithmic",
|
||||||
"NumberOfBins": 10,
|
"NumberOfBins": 100,
|
||||||
"MinEnergy": {
|
"MinEnergy": {
|
||||||
"value": 1E-6,
|
"value": 1E-6,
|
||||||
"unit": "eV"
|
"unit": "eV"
|
||||||
@@ -180,7 +181,7 @@
|
|||||||
},
|
},
|
||||||
"PitchAngleBinning": {
|
"PitchAngleBinning": {
|
||||||
"Type": "Linear",
|
"Type": "Linear",
|
||||||
"NumberOfBins": 15
|
"NumberOfBins": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -350,18 +351,19 @@
|
|||||||
},
|
},
|
||||||
"T2+": {
|
"T2+": {
|
||||||
"ParticleType": "T2+",
|
"ParticleType": "T2+",
|
||||||
|
"StoreInQueue": "false",
|
||||||
"Mover": {
|
"Mover": {
|
||||||
"Drift": {
|
"Boris": {
|
||||||
"MaximalMovedDistance": {
|
"MaximalTimestepLength": {
|
||||||
"value": 1E-3,
|
"value": 6e-11,
|
||||||
"unit": "m"
|
"unit": "s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Terminator": {
|
"Terminator": {
|
||||||
"MaximumInteractions": 1E6,
|
"MaximumInteractions": 1E6,
|
||||||
"MaxTimeAlive": {
|
"MaxTimeAlive": {
|
||||||
"value": 1,
|
"value": 10,
|
||||||
"unit": "s"
|
"unit": "s"
|
||||||
},
|
},
|
||||||
"BoundaryGeometry": {
|
"BoundaryGeometry": {
|
||||||
@@ -389,19 +391,19 @@
|
|||||||
},
|
},
|
||||||
"EnergyBinning": {
|
"EnergyBinning": {
|
||||||
"Type": "Logarithmic",
|
"Type": "Logarithmic",
|
||||||
"NumberOfBins": 10,
|
"NumberOfBins": 50,
|
||||||
"MinEnergy": {
|
"MinEnergy": {
|
||||||
"value": 1E-6,
|
"value": 1E-6,
|
||||||
"unit": "eV"
|
"unit": "eV"
|
||||||
},
|
},
|
||||||
"MaxEnergy": {
|
"MaxEnergy": {
|
||||||
"value": 1E3,
|
"value": 1E1,
|
||||||
"unit": "eV"
|
"unit": "eV"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"PitchAngleBinning": {
|
"PitchAngleBinning": {
|
||||||
"Type": "Linear",
|
"Type": "Linear",
|
||||||
"NumberOfBins": 15
|
"NumberOfBins": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -434,6 +436,7 @@
|
|||||||
"clustering": {
|
"clustering": {
|
||||||
"Type": "Clustering",
|
"Type": "Clustering",
|
||||||
"Target": "TritiumGas",
|
"Target": "TritiumGas",
|
||||||
|
"ClusteringType": "radiative",
|
||||||
"Product": "T3+",
|
"Product": "T3+",
|
||||||
"CrossSection": {
|
"CrossSection": {
|
||||||
"PredefinedFunction": "T2pT2_clustering_janev"
|
"PredefinedFunction": "T2pT2_clustering_janev"
|
||||||
@@ -446,11 +449,11 @@
|
|||||||
},
|
},
|
||||||
"T+": {
|
"T+": {
|
||||||
"ParticleType": "T+",
|
"ParticleType": "T+",
|
||||||
|
"StoreInQueue": "false",
|
||||||
"Mover": {
|
"Mover": {
|
||||||
"Boris": {
|
"Boris": {
|
||||||
"BorisStepsPerMovementCylce": 10,
|
|
||||||
"MaximalTimestepLength": {
|
"MaximalTimestepLength": {
|
||||||
"value": 1E-8,
|
"value": 6e-11,
|
||||||
"unit": "s"
|
"unit": "s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -458,7 +461,7 @@
|
|||||||
"Terminator": {
|
"Terminator": {
|
||||||
"MaximumInteractions": 1E6,
|
"MaximumInteractions": 1E6,
|
||||||
"MaxTimeAlive": {
|
"MaxTimeAlive": {
|
||||||
"value": 1,
|
"value": 10,
|
||||||
"unit": "s"
|
"unit": "s"
|
||||||
},
|
},
|
||||||
"BoundaryGeometry": {
|
"BoundaryGeometry": {
|
||||||
@@ -486,19 +489,19 @@
|
|||||||
},
|
},
|
||||||
"EnergyBinning": {
|
"EnergyBinning": {
|
||||||
"Type": "Logarithmic",
|
"Type": "Logarithmic",
|
||||||
"NumberOfBins": 10,
|
"NumberOfBins": 50,
|
||||||
"MinEnergy": {
|
"MinEnergy": {
|
||||||
"value": 1E-6,
|
"value": 1E-6,
|
||||||
"unit": "eV"
|
"unit": "eV"
|
||||||
},
|
},
|
||||||
"MaxEnergy": {
|
"MaxEnergy": {
|
||||||
"value": 1E3,
|
"value": 1E1,
|
||||||
"unit": "eV"
|
"unit": "eV"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"PitchAngleBinning": {
|
"PitchAngleBinning": {
|
||||||
"Type": "Linear",
|
"Type": "Linear",
|
||||||
"NumberOfBins": 15
|
"NumberOfBins": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -534,6 +537,7 @@
|
|||||||
"clustering1": {
|
"clustering1": {
|
||||||
"Type": "Clustering",
|
"Type": "Clustering",
|
||||||
"Target": "TritiumGas",
|
"Target": "TritiumGas",
|
||||||
|
"ClusteringType": "radiative",
|
||||||
"Product": "T3+",
|
"Product": "T3+",
|
||||||
"CrossSection": {
|
"CrossSection": {
|
||||||
"PredefinedFunction": "TpT2_clustering_radiative_ascendion_pasil"
|
"PredefinedFunction": "TpT2_clustering_radiative_ascendion_pasil"
|
||||||
@@ -542,6 +546,7 @@
|
|||||||
"clustering2": {
|
"clustering2": {
|
||||||
"Type": "Clustering",
|
"Type": "Clustering",
|
||||||
"Target": "TritiumGas",
|
"Target": "TritiumGas",
|
||||||
|
"ClusteringType": "tertiary",
|
||||||
"Product": "T3+",
|
"Product": "T3+",
|
||||||
"CrossSection": {
|
"CrossSection": {
|
||||||
"PredefinedFunction": "TpT2_clustering_tertiary_ascendion_pasil"
|
"PredefinedFunction": "TpT2_clustering_tertiary_ascendion_pasil"
|
||||||
@@ -554,18 +559,19 @@
|
|||||||
},
|
},
|
||||||
"T3+": {
|
"T3+": {
|
||||||
"ParticleType": "T3+",
|
"ParticleType": "T3+",
|
||||||
|
"StoreInQueue": "false",
|
||||||
"Mover": {
|
"Mover": {
|
||||||
"Drift": {
|
"Boris": {
|
||||||
"MaximalMovedDistance": {
|
"MaximalTimestepLength": {
|
||||||
"value": 1E-3,
|
"value": 6e-11,
|
||||||
"unit": "m"
|
"unit": "s"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Terminator": {
|
"Terminator": {
|
||||||
"MaximumInteractions": 1E6,
|
"MaximumInteractions": 1E6,
|
||||||
"MaxTimeAlive": {
|
"MaxTimeAlive": {
|
||||||
"value": 1,
|
"value": 10,
|
||||||
"unit": "s"
|
"unit": "s"
|
||||||
},
|
},
|
||||||
"BoundaryGeometry": {
|
"BoundaryGeometry": {
|
||||||
@@ -593,7 +599,7 @@
|
|||||||
},
|
},
|
||||||
"EnergyBinning": {
|
"EnergyBinning": {
|
||||||
"Type": "Logarithmic",
|
"Type": "Logarithmic",
|
||||||
"NumberOfBins": 10,
|
"NumberOfBins": 100,
|
||||||
"MinEnergy": {
|
"MinEnergy": {
|
||||||
"value": 1E-6,
|
"value": 1E-6,
|
||||||
"unit": "eV"
|
"unit": "eV"
|
||||||
@@ -605,7 +611,7 @@
|
|||||||
},
|
},
|
||||||
"PitchAngleBinning": {
|
"PitchAngleBinning": {
|
||||||
"Type": "Linear",
|
"Type": "Linear",
|
||||||
"NumberOfBins": 15
|
"NumberOfBins": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -662,7 +668,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"InjectionStride": 1
|
||||||
},
|
},
|
||||||
"specie2": {
|
"specie2": {
|
||||||
"TrackedSpecieName": "T2+",
|
"TrackedSpecieName": "T2+",
|
||||||
@@ -684,7 +691,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"InjectionStride": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"EventPositionDistribution": {
|
"EventPositionDistribution": {
|
||||||
@@ -770,7 +778,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Activity": {
|
"Activity": {
|
||||||
"value": 1E7,
|
"value": 3.7e10,
|
||||||
"unit": "Bq"
|
"unit": "Bq"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -809,7 +817,7 @@
|
|||||||
"VectorFieldFunctionInZ": {
|
"VectorFieldFunctionInZ": {
|
||||||
"zFunction": {
|
"zFunction": {
|
||||||
"Constant3D": {
|
"Constant3D": {
|
||||||
"constant": 2.5
|
"constant": 0.025
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -829,7 +837,7 @@
|
|||||||
"VectorFieldFunctionInZ": {
|
"VectorFieldFunctionInZ": {
|
||||||
"zFunction": {
|
"zFunction": {
|
||||||
"Constant3D": {
|
"Constant3D": {
|
||||||
"constant": 0
|
"constant": 0.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -846,7 +854,7 @@
|
|||||||
},
|
},
|
||||||
"Boundary": {
|
"Boundary": {
|
||||||
"Top": {
|
"Top": {
|
||||||
"type": "neumann",
|
"type": "dirichlet",
|
||||||
"value": 0
|
"value": 0
|
||||||
},
|
},
|
||||||
"Bottom": {
|
"Bottom": {
|
||||||
@@ -860,50 +868,53 @@
|
|||||||
},
|
},
|
||||||
"TargetAccuracy": 1e-6,
|
"TargetAccuracy": 1e-6,
|
||||||
"NumCycles": 2e4,
|
"NumCycles": 2e4,
|
||||||
"DoSolver": "false"
|
"DoSolver": "true"
|
||||||
},
|
},
|
||||||
"Simulation": {
|
"Simulation": {
|
||||||
"NumberTimesteps": 10,
|
"NumberTimesteps": 20,
|
||||||
"EventStride": 1000,
|
"EventStride": 10,
|
||||||
"TimeResolutionEvents": 10,
|
"TimeResolutionEvents": 10,
|
||||||
"DensityEventsPerCPU": 1000,
|
"BetaDecayEventsPerCPU": 10,
|
||||||
"BetaDecayEventsPerCPU": 1000
|
"InjectionStride": 1,
|
||||||
|
"NumberDensityParticlesPerBinPerCPU": 1
|
||||||
},
|
},
|
||||||
"Output": {
|
"Output": {
|
||||||
"folder": "output",
|
"folder": "output",
|
||||||
"filename": "katrin_drawing",
|
"filename": "wgts",
|
||||||
"DensityFields": {
|
"DensityFields": {
|
||||||
"Species": "all",
|
"Species": "all",
|
||||||
"Intervall": 1,
|
"Intervall": 288,
|
||||||
"OverwriteLast": "false"
|
"OverwriteLast": "false"
|
||||||
},
|
},
|
||||||
"CurrentBorders": {
|
"CurrentBorders": {
|
||||||
"Species": "all",
|
"Species": "all",
|
||||||
"Intervall": "EachSync",
|
"Intervall": 288,
|
||||||
"OverwriteLast": "false"
|
"OverwriteLast": "false"
|
||||||
},
|
},
|
||||||
"DeletionLogger": {
|
"DeletionLogger": {
|
||||||
"Species": "all",
|
"Species": "all",
|
||||||
"Intervall": "EachSync",
|
"Intervall": 288,
|
||||||
"OverwriteLast": "false"
|
"OverwriteLast": "false"
|
||||||
},
|
},
|
||||||
"PoissonSolver": {
|
"PoissonSolver": {
|
||||||
"Intervall": 1,
|
"Intervall": 288,
|
||||||
"OverwriteLast": "false"
|
"OverwriteLast": "false"
|
||||||
},
|
},
|
||||||
"RestartInfo": {
|
"RestartInfo": {
|
||||||
"Intervall": 1,
|
"Intervall": 288,
|
||||||
"OverwriteLast": "false"
|
"OverwriteLast": "false"
|
||||||
|
},
|
||||||
|
"Particles": {
|
||||||
|
"Intervall": 2880
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Restart": {
|
"Restart": {
|
||||||
"Do": "false",
|
"Do": "false",
|
||||||
"SyncPeriod": 2,
|
"SyncPeriod": 2880,
|
||||||
"PathToH5": {
|
"PathToH5": {
|
||||||
"Type": "RelativeToHomebase",
|
"Type": "AbsolutePath",
|
||||||
"RelativePath": "output",
|
"AbsoluteFolderPath": "/home/christian/Documents/Heidelberg/karl/timeResolvedTests/thermalization/output",
|
||||||
"Filename": "breakInMover3",
|
"Filename": "const_target_energy"
|
||||||
"comment": "if the restarted file and the output file are the same, the data that is restarted from is overwritten!"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"RandomNumbers": {
|
"RandomNumbers": {
|
||||||
@@ -132,6 +132,36 @@ double Hdf5Reader::readDouble(std::string path) {
|
|||||||
return data;
|
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) {
|
blitz::Array<double, 4> Hdf5Reader::readD4Double(std::string path) {
|
||||||
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||||
|
|
||||||
|
|||||||
+2
-34
@@ -197,38 +197,6 @@ void Hdf5Writer::write(const blitz::Array<double, 5>& data, std::string path) {
|
|||||||
H5Fclose(file);
|
H5Fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hdf5Writer::write(const blitz::Array<float, 5>& data, std::string path) {
|
|
||||||
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
|
||||||
|
|
||||||
blitz::TinyVector<int, 5> size = data.extent();
|
|
||||||
blitz::TinyVector<int, 5> start(0, 0, 0, 0, 0);
|
|
||||||
|
|
||||||
hid_t filespace =
|
|
||||||
H5Screate_simple(5, blitz::TinyVector<hsize_t, 5>(size).data(), NULL);
|
|
||||||
|
|
||||||
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
|
||||||
H5Pset_create_intermediate_group(lcpl, 1);
|
|
||||||
|
|
||||||
// turn of error report by hdf5 because of check H5Dopen2
|
|
||||||
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
|
||||||
hid_t dataset;
|
|
||||||
dataset = H5Dopen2(file, path.c_str(), H5P_DEFAULT);
|
|
||||||
if (dataset < 0) {
|
|
||||||
dataset = H5Dcreate2(file, path.c_str(), H5T_NATIVE_FLOAT, filespace, lcpl,
|
|
||||||
H5P_DEFAULT, H5P_DEFAULT);
|
|
||||||
}
|
|
||||||
// turn error report back onby hdf5 because of check H5Dopen2
|
|
||||||
H5Eset_auto(H5E_DEFAULT, H5E_DEFAULT, H5E_DEFAULT);
|
|
||||||
|
|
||||||
H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, filespace, H5P_DEFAULT,
|
|
||||||
data.data());
|
|
||||||
|
|
||||||
H5Dclose(dataset);
|
|
||||||
H5Pclose(lcpl);
|
|
||||||
H5Sclose(filespace);
|
|
||||||
H5Fclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Hdf5Writer::write(const blitz::Array<long int, 4>& data,
|
void Hdf5Writer::write(const blitz::Array<long int, 4>& data,
|
||||||
std::string path) {
|
std::string path) {
|
||||||
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
hid_t file = H5Fopen(absolute_filename_.c_str(), H5F_ACC_RDWR, H5P_DEFAULT);
|
||||||
@@ -549,7 +517,7 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
|
|||||||
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
hid_t lcpl = H5Pcreate(H5P_LINK_CREATE);
|
||||||
H5Pset_create_intermediate_group(lcpl, 1);
|
H5Pset_create_intermediate_group(lcpl, 1);
|
||||||
|
|
||||||
int mpi_rank = MpiCommunication::mpiRank();
|
int mpi_rank = MpiCommunication::mpi_rank;
|
||||||
std::string out{data};
|
std::string out{data};
|
||||||
|
|
||||||
size_t stateStringSize = out.size();
|
size_t stateStringSize = out.size();
|
||||||
@@ -572,7 +540,7 @@ void Hdf5Writer::writeRNG(const std::string& data, std::string path_base) {
|
|||||||
// turn of error report by hdf5 because of check H5Dopen2
|
// turn of error report by hdf5 because of check H5Dopen2
|
||||||
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
|
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);
|
std::string path = path_base + std::to_string(i);
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3(path);
|
DEBUG_LEVEL_3(path);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
+36
-8
@@ -15,14 +15,26 @@
|
|||||||
// called reset function (e.g. in the density field) and sometimes it's
|
// called reset function (e.g. in the density field) and sometimes it's
|
||||||
// handled here
|
// handled here
|
||||||
|
|
||||||
Restart::Restart(bool do_restart, std::string absolute_filename,
|
// Restart::Restart(bool do_restart, std::string absolute_filename,
|
||||||
std::string restart_identifier):
|
// std::string restart_identifier):
|
||||||
do_restart_(do_restart),
|
// do_restart_(do_restart),
|
||||||
restart_identifier_(restart_identifier),
|
// restart_identifier_(restart_identifier),
|
||||||
reader_(Hdf5Reader(absolute_filename)) {}
|
// reader_(Hdf5Reader(absolute_filename)) {}
|
||||||
|
|
||||||
void Restart::restart(std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
Restart::Restart(bool do_restart, std::string absolute_filename_without_extension,
|
||||||
PoissonSolver* poisson_solver, RandomNumbers* random_numbers) {
|
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_) {
|
if(!do_restart_) {
|
||||||
return;
|
return;
|
||||||
@@ -31,6 +43,7 @@ void Restart::restart(std::map<std::string, std::shared_ptr<species::TrackedSpec
|
|||||||
DEBUG_LEVEL_1("Restarting rng");
|
DEBUG_LEVEL_1("Restarting rng");
|
||||||
#endif
|
#endif
|
||||||
restartRandomNumbers(random_numbers);
|
restartRandomNumbers(random_numbers);
|
||||||
|
|
||||||
#ifdef debug_level1
|
#ifdef debug_level1
|
||||||
DEBUG_LEVEL_1("Restarting poisson solver.");
|
DEBUG_LEVEL_1("Restarting poisson solver.");
|
||||||
#endif
|
#endif
|
||||||
@@ -45,8 +58,18 @@ void Restart::restart(std::map<std::string, std::shared_ptr<species::TrackedSpec
|
|||||||
std::string path = pair.second->name() + "/DensityField/SimulationData/" +
|
std::string path = pair.second->name() + "/DensityField/SimulationData/" +
|
||||||
restart_identifier_;
|
restart_identifier_;
|
||||||
restartDrawingDensityField(pair.second->densityForDrawing(), path);
|
restartDrawingDensityField(pair.second->densityForDrawing(), path);
|
||||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
// 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) {
|
void Restart::restartRandomNumbers(RandomNumbers* random) {
|
||||||
@@ -142,3 +165,8 @@ void Restart::restartPoissonSolver(PoissonSolver* solver) {
|
|||||||
blitz::Array<double, 3> potential = reader_.readD3Double(path);
|
blitz::Array<double, 3> potential = reader_.readD3Double(path);
|
||||||
solver->setPotential(potential);
|
solver->setPotential(potential);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Restart::restartParticles(
|
||||||
|
std::vector<particle::SerializedParticle>& storage_queue) {
|
||||||
|
particle_reader_.readParticles(storage_queue);
|
||||||
|
}
|
||||||
@@ -11,8 +11,11 @@
|
|||||||
#include "poisson_solver/poisson_solver.h"
|
#include "poisson_solver/poisson_solver.h"
|
||||||
|
|
||||||
SimulationOutput::SimulationOutput(const std::string& output_folder,
|
SimulationOutput::SimulationOutput(const std::string& output_folder,
|
||||||
const std::string& output_filename)
|
const std::string& output_filename,
|
||||||
: writer(Hdf5Writer(output_folder, 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) {
|
void SimulationOutput::addDensityFieldOutput(OutputTask task) {
|
||||||
tasks_density_fields_.push_back(task);
|
tasks_density_fields_.push_back(task);
|
||||||
@@ -34,6 +37,10 @@ void SimulationOutput::setRestartInfoOutput(OutputTask task) {
|
|||||||
task_rng_ = task;
|
task_rng_ = task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimulationOutput::setParticleOutput(OutputTask task) {
|
||||||
|
task_particles_ = task;
|
||||||
|
}
|
||||||
|
|
||||||
void SimulationOutput::writeMetaData(
|
void SimulationOutput::writeMetaData(
|
||||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||||
const std::shared_ptr<PoissonSolver>& poisson_solver) {
|
const std::shared_ptr<PoissonSolver>& poisson_solver) {
|
||||||
@@ -70,7 +77,9 @@ void SimulationOutput::writeSimulationData(
|
|||||||
int cpu_sync,
|
int cpu_sync,
|
||||||
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
std::map<std::string, std::shared_ptr<species::TrackedSpecie>>& species,
|
||||||
PoissonSolver* poisson_solver,
|
PoissonSolver* poisson_solver,
|
||||||
std::mt19937* engine) {
|
std::mt19937* engine,
|
||||||
|
std::vector<particle::SerializedParticle>& storage_queue,
|
||||||
|
int injectionGroupOffset) {
|
||||||
if (MpiCommunication::mpi_rank == 0) {
|
if (MpiCommunication::mpi_rank == 0) {
|
||||||
|
|
||||||
#ifdef debug_level2
|
#ifdef debug_level2
|
||||||
@@ -117,7 +126,12 @@ void SimulationOutput::writeSimulationData(
|
|||||||
// if the rng intervall = 0 (no neg. intervalls allowed) -> no output,
|
// if the rng intervall = 0 (no neg. intervalls allowed) -> no output,
|
||||||
// otherwise the intervall used the same as for the other outputs
|
// otherwise the intervall used the same as for the other outputs
|
||||||
if((task_rng_.intervall > 0) && (cpu_sync%task_rng_.intervall == 0)) {
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +220,7 @@ void SimulationOutput::writeSimulationData(PoissonSolver* poisson_solver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
|
void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
|
||||||
bool overwrite_last) {
|
bool overwrite_last, int injectionGroupOffset) {
|
||||||
std::string path_base = "/RestartInfo/SyncPeriod_" +
|
std::string path_base = "/RestartInfo/SyncPeriod_" +
|
||||||
std::to_string(cpu_sync) +
|
std::to_string(cpu_sync) +
|
||||||
"/CPU_";
|
"/CPU_";
|
||||||
@@ -218,6 +232,16 @@ void SimulationOutput::writeRestartData(std::mt19937* engine, int cpu_sync,
|
|||||||
DEBUG_LEVEL_3("Write restart info.");
|
DEBUG_LEVEL_3("Write restart info.");
|
||||||
#endif
|
#endif
|
||||||
writeRandomEngineState(engine, path_base);
|
writeRandomEngineState(engine, path_base);
|
||||||
|
|
||||||
|
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");
|
// DEBUG_LEVEL_3("Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,16 +266,13 @@ void SimulationOutput::writeNumDeletions(DeletionLogger* logger,
|
|||||||
writer.write(pair.second, path_to_deletions + "/MaxTimeAlive");
|
writer.write(pair.second, path_to_deletions + "/MaxTimeAlive");
|
||||||
} else if (pair.first == DeletionType::cluster_formation) {
|
} else if (pair.first == DeletionType::cluster_formation) {
|
||||||
writer.write(pair.second, path_to_deletions + "/ClusterFormation");
|
writer.write(pair.second, path_to_deletions + "/ClusterFormation");
|
||||||
} else if (pair.first == DeletionType::creation_beta) {
|
}
|
||||||
writer.write(pair.second, path_to_deletions + "/CreationBeta");
|
}
|
||||||
} else if (pair.first == DeletionType::creation_density) {
|
|
||||||
writer.write(pair.second, path_to_deletions + "/CreationDensity");
|
auto physDeletions = logger->numPhysDeletions();
|
||||||
} else if (pair.first == DeletionType::creation_interaction) {
|
for (auto& pair : physDeletions) {
|
||||||
writer.write(pair.second, path_to_deletions + "/CreationInteraction");
|
if (pair.first == PhysicalDeletionType::wall) {
|
||||||
} else if (pair.first == DeletionType::creation_above_2keV) {
|
writer.write(pair.second, path_to_deletions + "/Wall(physical)");
|
||||||
writer.write(pair.second, path_to_deletions + "/CreationAbove2keV");
|
|
||||||
} else if (pair.first == DeletionType::loss_above_2keV) {
|
|
||||||
writer.write(pair.second, path_to_deletions + "/LossAbove2keV");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -453,3 +474,10 @@ void SimulationOutput::writeBinBorders(DynamicDensityField* density_field,
|
|||||||
density_field->positionBinning()->longitudinal_binning.binBorders();
|
density_field->positionBinning()->longitudinal_binning.binBorders();
|
||||||
writer.write(longitudinal_bin_borders, path_to_bin_borders + "/longitudinal");
|
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);
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "generators/velocity_distribution_generator.h"
|
#include "generators/velocity_distribution_generator.h"
|
||||||
#include "simulation/event_position_distribution.h"
|
#include "simulation/event_position_distribution.h"
|
||||||
#include "simulation/velocity_distribution.h"
|
#include "simulation/velocity_distribution.h"
|
||||||
|
#include "simulation/mpi_communication.h"
|
||||||
|
|
||||||
namespace generator {
|
namespace generator {
|
||||||
|
|
||||||
@@ -39,6 +40,18 @@ std::shared_ptr<Injector> buildInjector(
|
|||||||
// info.multiplicity = json_int(json_object_by_path(value, {"Multiplicity"}), 1);
|
// info.multiplicity = json_int(json_object_by_path(value, {"Multiplicity"}), 1);
|
||||||
// ASSERT_POSITIVE(&info.multiplicity, "The multiplicity has to be positive. " +
|
// ASSERT_POSITIVE(&info.multiplicity, "The multiplicity has to be positive. " +
|
||||||
// specie_name + " multiplicity: " + std::to_string(info.multiplicity));
|
// 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);
|
injector_infos.push_back(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -224,10 +224,26 @@ void addInteractions(
|
|||||||
std::shared_ptr<species::TrackedSpecie> product =
|
std::shared_ptr<species::TrackedSpecie> product =
|
||||||
findTracked(product_name, tracked_species);
|
findTracked(product_name, tracked_species);
|
||||||
|
|
||||||
|
std::string clustering_type =
|
||||||
|
json_string(json_object_by_path(value, {"ClusteringType"}));
|
||||||
|
|
||||||
std::function<double(double)> cross_section =
|
std::function<double(double)> cross_section =
|
||||||
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
|
buildTotalCrossSection(json_object_by_path(value, {"CrossSection"}));
|
||||||
|
|
||||||
|
if(clustering_type == "radiative") {
|
||||||
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
specie->addInteraction(std::shared_ptr<interaction::Interaction>(
|
||||||
new interaction::ClusterFormation(cross_section, target, product)));
|
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)");
|
||||||
|
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") {
|
} else if (type == "ChargeExchange") {
|
||||||
#ifdef debug_level2
|
#ifdef debug_level2
|
||||||
DEBUG_LEVEL_2("Adding interactions: ChargeExchange");
|
DEBUG_LEVEL_2("Adding interactions: ChargeExchange");
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace generator {
|
|||||||
|
|
||||||
std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
||||||
std::vector<DeletionType> used_types;
|
std::vector<DeletionType> used_types;
|
||||||
|
std::vector<PhysicalDeletionType> used_phys_types;
|
||||||
|
|
||||||
json_t* type = json_object_by_path(object, {"Type"});
|
json_t* type = json_object_by_path(object, {"Type"});
|
||||||
if (json_is_array(type)) {
|
if (json_is_array(type)) {
|
||||||
@@ -24,6 +25,8 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
|||||||
used_types.push_back(DeletionType::max_time_alive);
|
used_types.push_back(DeletionType::max_time_alive);
|
||||||
} else if (type_alias == "cluster_formation") {
|
} else if (type_alias == "cluster_formation") {
|
||||||
used_types.push_back(DeletionType::cluster_formation);
|
used_types.push_back(DeletionType::cluster_formation);
|
||||||
|
} else if (type_alias == "wall_physical") {
|
||||||
|
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||||
}else {
|
}else {
|
||||||
ERROR("This deletion type " + type_alias + " is not known.");
|
ERROR("This deletion type " + type_alias + " is not known.");
|
||||||
}
|
}
|
||||||
@@ -35,17 +38,11 @@ std::shared_ptr<DeletionLogger> buildDeletionLogger(json_t* object) {
|
|||||||
used_types.push_back(DeletionType::max_interactions);
|
used_types.push_back(DeletionType::max_interactions);
|
||||||
used_types.push_back(DeletionType::max_time_alive);
|
used_types.push_back(DeletionType::max_time_alive);
|
||||||
used_types.push_back(DeletionType::cluster_formation);
|
used_types.push_back(DeletionType::cluster_formation);
|
||||||
// Debugging types, not yet able to be specified on their own, just
|
used_phys_types.push_back(PhysicalDeletionType::wall);
|
||||||
// in when "all" is used
|
|
||||||
used_types.push_back(DeletionType::creation_beta);
|
|
||||||
used_types.push_back(DeletionType::creation_density);
|
|
||||||
used_types.push_back(DeletionType::creation_interaction);
|
|
||||||
used_types.push_back(DeletionType::creation_above_2keV);
|
|
||||||
used_types.push_back(DeletionType::loss_above_2keV);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_shared<DeletionLogger>(used_types);
|
return std::make_shared<DeletionLogger>(used_types, used_phys_types);
|
||||||
}
|
}
|
||||||
std::shared_ptr<DeletionLogger> buildDeletionLogger(
|
std::shared_ptr<DeletionLogger> buildDeletionLogger(
|
||||||
Parameter& parameter,
|
Parameter& parameter,
|
||||||
|
|||||||
@@ -10,21 +10,28 @@ namespace generator {
|
|||||||
#ifdef debug
|
#ifdef debug
|
||||||
DEBUG_LEVEL_0("No Restart desired.");
|
DEBUG_LEVEL_0("No Restart desired.");
|
||||||
#endif
|
#endif
|
||||||
return Restart(false, "", "");
|
return Restart(false, "", "", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string filepath = readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}))
|
// no file extensions!!! Those get added in the constructor of the hdf5 and mpi
|
||||||
+ ".h5";
|
// reader classes
|
||||||
|
std::string filepath =
|
||||||
|
readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}));
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Restart: file path:" + filepath);
|
DEBUG_LEVEL_3("Restart: file path:" + filepath);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string identifier;
|
std::string identifier;
|
||||||
int sync_period = json_int(json_object_by_path(object, {"SyncPeriod"}));
|
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"}))
|
if(sync_period == 0 && json_string(json_object_by_path(object, {"SyncPeriod"}))
|
||||||
== "LastSyncPeriod") {
|
== "LastSyncPeriod") {
|
||||||
identifier = "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 {
|
} else {
|
||||||
ASSERT_POSITIVE(&sync_period, "The SyncPeriod for the restart has to be either"
|
ASSERT_POSITIVE(&sync_period, "The SyncPeriod for the restart has to be either"
|
||||||
" positive or \"LastSyncPeriod\".");
|
" positive or \"LastSyncPeriod\".");
|
||||||
@@ -35,7 +42,7 @@ namespace generator {
|
|||||||
DEBUG_LEVEL_3("Restart: SyncPeriod to be started from: " + identifier);
|
DEBUG_LEVEL_3("Restart: SyncPeriod to be started from: " + identifier);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return Restart(do_restart, filepath, identifier);
|
return Restart(do_restart, filepath, identifier, part_restart_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
Restart buildRestart(Parameter& parameter) {
|
Restart buildRestart(Parameter& parameter) {
|
||||||
|
|||||||
@@ -178,6 +178,31 @@ std::shared_ptr<SimulationOutput> buildSimulationOutput(
|
|||||||
output->setRestartInfoOutput(task);
|
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;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ SpeciesBuilder::SpeciesBuilder(Parameter& parameter) {
|
|||||||
fillTerminator(parameter);
|
fillTerminator(parameter);
|
||||||
fillReflector(parameter);
|
fillReflector(parameter);
|
||||||
fillTrackedDensity(parameter);
|
fillTrackedDensity(parameter);
|
||||||
|
fillDensityDrawingType(parameter);
|
||||||
|
|
||||||
buildSpecies();
|
buildSpecies();
|
||||||
fillInteractions(parameter);
|
fillInteractions(parameter);
|
||||||
@@ -137,6 +138,11 @@ void SpeciesBuilder::initTrackedSpecies(Parameter& parameter) {
|
|||||||
json_t* value;
|
json_t* value;
|
||||||
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Tracked"}), key,
|
json_object_foreach(parameter.jsonObjectFromBase({"Species", "Tracked"}), key,
|
||||||
value) {
|
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)] = TrackedSpeciesBuilderInfo();
|
||||||
tracked_species_info[std::string(key)].name = std::string(key);
|
tracked_species_info[std::string(key)].name = std::string(key);
|
||||||
tracked_species_info[std::string(key)].path_in_json = {"Species", "Tracked",
|
tracked_species_info[std::string(key)].path_in_json = {"Species", "Tracked",
|
||||||
@@ -301,6 +307,13 @@ void SpeciesBuilder::fillTrackedDensity(Parameter& parameter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SpeciesBuilder::fillDensityDrawingType(Parameter& parameter) {
|
||||||
|
for(auto& b : tracked_species_info) {
|
||||||
|
b.second.explicitly_stored = parameter.boolValue(
|
||||||
|
json_path_append(b.second.path_in_json, {"StoreInQueue"}), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SpeciesBuilder::buildSpecies() {
|
void SpeciesBuilder::buildSpecies() {
|
||||||
#ifdef debug_level2
|
#ifdef debug_level2
|
||||||
DEBUG_LEVEL_2("Build species from info.");
|
DEBUG_LEVEL_2("Build species from info.");
|
||||||
@@ -314,9 +327,15 @@ void SpeciesBuilder::buildSpecies() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto& b : tracked_species_info) {
|
for (auto& b : tracked_species_info) {
|
||||||
|
#ifdef debug
|
||||||
|
std::stringstream out;
|
||||||
|
out << b.second.name << ": stored in queue? " << (b.second.explicitly_stored ? "true": "false");
|
||||||
|
DEBUG_LEVEL_1(out.str());
|
||||||
|
#endif
|
||||||
tracked_species[b.first] =
|
tracked_species[b.first] =
|
||||||
std::shared_ptr<species::TrackedSpecie>(new species::TrackedSpecie(
|
std::shared_ptr<species::TrackedSpecie>(new species::TrackedSpecie(
|
||||||
b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C,
|
b.second.type, b.second.name, b.second.mass_kg, b.second.charge_C,
|
||||||
|
b.second.explicitly_stored,
|
||||||
b.second.mover, b.second.terminator, b.second.reflector,
|
b.second.mover, b.second.terminator, b.second.reflector,
|
||||||
b.second.density_field, b.second.velocity_distribution,
|
b.second.density_field, b.second.velocity_distribution,
|
||||||
b.second.drift_velocity, b.second.density_drawing_field));
|
b.second.drift_velocity, b.second.density_drawing_field));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "simulation/logger.h"
|
#include "simulation/logger.h"
|
||||||
#include "simulation/velocity_distribution.h"
|
#include "simulation/velocity_distribution.h"
|
||||||
#include "constants/physical_constants.h"
|
#include "constants/physical_constants.h"
|
||||||
|
#include "simulation/density_field.h"
|
||||||
|
|
||||||
namespace interaction {
|
namespace interaction {
|
||||||
|
|
||||||
@@ -46,9 +47,21 @@ InteractionOutput ClusterFormation::performInteraction(
|
|||||||
x_impact, DeletionType::cluster_formation);
|
x_impact, DeletionType::cluster_formation);
|
||||||
}
|
}
|
||||||
|
|
||||||
product_->deletionLogger()->logDeletion(x_impact, DeletionType::creation_interaction);
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClusterFormationTertiary::ClusterFormationTertiary(
|
||||||
|
std::function<double(double)> cross_section,
|
||||||
|
std::shared_ptr<species::Specie> target,
|
||||||
|
std::shared_ptr<species::TrackedSpecie> product) :
|
||||||
|
ClusterFormation(cross_section, target, product) {}
|
||||||
|
|
||||||
|
double ClusterFormationTertiary::microscopicCrossSection(double energy_eV,
|
||||||
|
const Coordinate& position) {
|
||||||
|
// SIM_INFO("Tertiary cross section.");
|
||||||
|
const double rate_over_velocity = cross_section_(energy_eV);
|
||||||
|
auto density = target_->densityField()->density(position);
|
||||||
|
return rate_over_velocity * density;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace interaction
|
} // namespace interaction
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#include "simulation/kinematic.h"
|
#include "simulation/kinematic.h"
|
||||||
#include "simulation/scattering_angle_distribution.h"
|
#include "simulation/scattering_angle_distribution.h"
|
||||||
#include "simulation/velocity_distribution.h"
|
#include "simulation/velocity_distribution.h"
|
||||||
|
#include "constants/sim_constants.h"
|
||||||
|
#include "simulation/density_field.h"
|
||||||
namespace interaction {
|
namespace interaction {
|
||||||
|
|
||||||
ElasticScattering::ElasticScattering(
|
ElasticScattering::ElasticScattering(
|
||||||
@@ -48,9 +49,81 @@ InteractionOutput ElasticScattering::performInteraction(
|
|||||||
target_->mass_kg(), theta, phi);
|
target_->mass_kg(), theta, phi);
|
||||||
|
|
||||||
particle.velocity(CartesianVector(v_impact_new));
|
particle.velocity(CartesianVector(v_impact_new));
|
||||||
// no Gyrocentrum movement because boris push is used;
|
|
||||||
|
|
||||||
return InteractionOutput();
|
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
|
}; // namespace interaction
|
||||||
@@ -17,7 +17,8 @@ InteractionOutput FreeMovement::performInteraction(particle::Particle& particle,
|
|||||||
return InteractionOutput();
|
return InteractionOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
double FreeMovement::microscopicCrossSection(double energy_eV) {
|
double FreeMovement::microscopicCrossSection(double energy_eV,
|
||||||
|
const Coordinate& position) {
|
||||||
// returns very small number
|
// returns very small number
|
||||||
return SimConstants::minimal_cross_section;
|
return SimConstants::minimal_cross_section;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "simulation/kinematic.h"
|
#include "simulation/kinematic.h"
|
||||||
#include "simulation/particle.h"
|
#include "simulation/particle.h"
|
||||||
#include "simulation/velocity_distribution.h"
|
#include "simulation/velocity_distribution.h"
|
||||||
#include "simulation/logger.h"
|
|
||||||
|
|
||||||
namespace interaction {
|
namespace interaction {
|
||||||
|
|
||||||
@@ -46,6 +45,9 @@ InteractionOutput ElectronIonization::performInteraction(
|
|||||||
->driftVelocity(x_impact, particle.cylinderPosition())
|
->driftVelocity(x_impact, particle.cylinderPosition())
|
||||||
.cartesianEntries();
|
.cartesianEntries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v_target *= std::sqrt(target_->mass_kg()/ion_->mass_kg());
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> v_laboratory = kinematic::velocityTargetFixed(
|
blitz::TinyVector<double, 3> v_laboratory = kinematic::velocityTargetFixed(
|
||||||
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(), target_->mass_kg()
|
v_impact, target_velocity_.cartesianEntries(), particle.mass_kg(), target_->mass_kg()
|
||||||
);
|
);
|
||||||
@@ -118,10 +120,6 @@ InteractionOutput ElectronIonization::performInteraction(
|
|||||||
output.add(particle::Particle(ion_, x_impact, CartesianVector(v_target),
|
output.add(particle::Particle(ion_, x_impact, CartesianVector(v_target),
|
||||||
time_birth, weight_parent));
|
time_birth, weight_parent));
|
||||||
|
|
||||||
ion_->deletionLogger()->logDeletion(x_impact, DeletionType::creation_interaction);
|
|
||||||
electron_->deletionLogger()
|
|
||||||
->logDeletion(x_impact, DeletionType::creation_interaction);
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "constants/physical_constants.h"
|
#include "constants/physical_constants.h"
|
||||||
#include "simulation/drift_velocity.h"
|
#include "simulation/drift_velocity.h"
|
||||||
#include "simulation/electromagnetic_field.h"
|
#include "simulation/electromagnetic_field.h"
|
||||||
|
#include "simulation/velocity_distribution.h"
|
||||||
|
|
||||||
namespace interaction {
|
namespace interaction {
|
||||||
|
|
||||||
@@ -158,11 +159,87 @@ double Recombination::macroscopicCrossSection(const Coordinate& position,
|
|||||||
//Simpson's rule
|
//Simpson's rule
|
||||||
const double integrated_microscopic_cross_section =
|
const double integrated_microscopic_cross_section =
|
||||||
(upper_bound - lower_bound)/6. *
|
(upper_bound - lower_bound)/6. *
|
||||||
(microscopicCrossSection(upper_bound) +
|
(microscopicCrossSection(upper_bound, position) +
|
||||||
4*microscopicCrossSection(intermediate_value) +
|
4*microscopicCrossSection(intermediate_value, position) +
|
||||||
microscopicCrossSection(lower_bound));
|
microscopicCrossSection(lower_bound, position));
|
||||||
// assumption, that the differential density is constant within a cell
|
// assumption, that the differential density is constant within a cell
|
||||||
return differential_density_value * integrated_microscopic_cross_section;
|
return differential_density_value * integrated_microscopic_cross_section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Recombination::drawCollisionTime(particle::Particle& particle,
|
||||||
|
RandomNumbers* generator) {
|
||||||
|
CartesianVector particle_velocity = particle.velocity();
|
||||||
|
|
||||||
|
// Assumes that B || z, which is obviously not necessarily the case !!!
|
||||||
|
target_velocity_ = recombination_target_->velocityDistributionFromDensityField()
|
||||||
|
->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());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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());
|
||||||
|
// 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_->densityForDrawing()
|
||||||
|
->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;
|
||||||
|
|
||||||
|
|
||||||
|
#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
|
}; // namespace interaction
|
||||||
@@ -27,16 +27,6 @@ void CpuSynchronizer::sumToAll(blitz::Array<double, 5>& array,
|
|||||||
last_sync_array += delta;
|
last_sync_array += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CpuSynchronizer::sumToAll(blitz::Array<float, 5>& array,
|
|
||||||
blitz::Array<float, 5>& last_sync_array) {
|
|
||||||
int size = array.size();
|
|
||||||
blitz::Array<float, 5> delta(array.extent());
|
|
||||||
delta = array - last_sync_array;
|
|
||||||
MPI_Allreduce(MPI_IN_PLACE, delta.data(), size, MPI_FLOAT,
|
|
||||||
MPI_SUM, MPI_COMM_WORLD);
|
|
||||||
last_sync_array += delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CpuSynchronizer::sumToAll(blitz::Array<long int, 4>& array,
|
void CpuSynchronizer::sumToAll(blitz::Array<long int, 4>& array,
|
||||||
blitz::Array<long int, 4>& last_sync_array) {
|
blitz::Array<long int, 4>& last_sync_array) {
|
||||||
int size = array.size();
|
int size = array.size();
|
||||||
@@ -155,6 +145,15 @@ void CpuSynchronizer::synchronize(DeletionLogger* logger) {
|
|||||||
pair.second = last_sync_num_deletion;
|
pair.second = last_sync_num_deletion;
|
||||||
logger->sync_num_deletions[pair.first] = 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];
|
||||||
|
sumToAll(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_phys_deletions[pair.first] = last_sync_num_deletion;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ DynamicDensityField::DynamicDensityField(
|
|||||||
energy_binning_(energy_binning),
|
energy_binning_(energy_binning),
|
||||||
pitch_angle_binning_(pitch_angle_binning),
|
pitch_angle_binning_(pitch_angle_binning),
|
||||||
timer_(timer),
|
timer_(timer),
|
||||||
time_in_bin_s_(initiate5DArray<float>(
|
time_in_bin_s_(initiate5DArray<double>(
|
||||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||||
position_binning.radial_binning.binIndexMax()),
|
position_binning.radial_binning.binIndexMax()),
|
||||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||||
@@ -72,7 +72,7 @@ DynamicDensityField::DynamicDensityField(
|
|||||||
pitch_angle_binning.binIndexMax()),
|
pitch_angle_binning.binIndexMax()),
|
||||||
blitz::Range(energy_binning.binIndexMin(),
|
blitz::Range(energy_binning.binIndexMin(),
|
||||||
energy_binning.binIndexMax()))),
|
energy_binning.binIndexMax()))),
|
||||||
sync_time_in_bin_s_(initiate5DArray<float>(
|
sync_time_in_bin_s_(initiate5DArray<double>(
|
||||||
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
blitz::Range(position_binning.radial_binning.binIndexMin(),
|
||||||
position_binning.radial_binning.binIndexMax()),
|
position_binning.radial_binning.binIndexMax()),
|
||||||
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
blitz::Range(position_binning.azimuth_binning.binIndexMin(),
|
||||||
@@ -209,7 +209,7 @@ void DynamicDensityField::logMovement(const Coordinate& position,
|
|||||||
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
const int pitch_angle_bin = pitch_angle_binning_.bin(pitch_angle);
|
||||||
|
|
||||||
time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
time_in_bin_s_(position_bin(0), position_bin(1), position_bin(2),
|
||||||
pitch_angle_bin, energy_bin) += static_cast<float>(weight);
|
pitch_angle_bin, energy_bin) += weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void DynamicDensityField::logDeletion(const Coordinate& position,
|
// void DynamicDensityField::logDeletion(const Coordinate& position,
|
||||||
@@ -251,7 +251,7 @@ blitz::Array<double, 4> DynamicDensityField::spectrumArray() {
|
|||||||
return density_per_m3_;
|
return density_per_m3_;
|
||||||
}
|
}
|
||||||
|
|
||||||
blitz::Array<float, 5> DynamicDensityField::timeInBinArray() const {
|
blitz::Array<double, 5> DynamicDensityField::timeInBinArray() const {
|
||||||
return time_in_bin_s_;
|
return time_in_bin_s_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +327,7 @@ blitz::Array<double, 1> DynamicDensityField::
|
|||||||
energy_binning_.binIndexMax()-1)).copy();
|
energy_binning_.binIndexMax()-1)).copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
blitz::Array<float, 1> DynamicDensityField::
|
blitz::Array<double, 1> DynamicDensityField::
|
||||||
sliceTimeInBinArray(const Coordinate& position, double energy_eV) const {
|
sliceTimeInBinArray(const Coordinate& position, double energy_eV) const {
|
||||||
blitz::TinyVector<int, 3> position_bin =
|
blitz::TinyVector<int, 3> position_bin =
|
||||||
position_binning_.bin(position.cylinderEntries());
|
position_binning_.bin(position.cylinderEntries());
|
||||||
|
|||||||
@@ -69,17 +69,24 @@ PitchAngleBinning::PitchAngleBinning(int num_bins) :
|
|||||||
pitch_angle_bin_borders_(generateLinearBinBorders(-1, 1, num_bins)) {}
|
pitch_angle_bin_borders_(generateLinearBinBorders(-1, 1, num_bins)) {}
|
||||||
|
|
||||||
int PitchAngleBinning::bin(double pitch_angle) const {
|
int PitchAngleBinning::bin(double pitch_angle) const {
|
||||||
auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(),
|
// auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(),
|
||||||
pitch_angle_bin_borders_.end(),
|
// pitch_angle_bin_borders_.end(),
|
||||||
pitch_angle);
|
// pitch_angle);
|
||||||
|
int bin = static_cast<int>((pitch_angle + 1)/2 * numBins());
|
||||||
// otherwise the valid mu-value of -1 is assigned to the underflow
|
// 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
|
// bin which can lead to a segfault in the drawing of the pitch
|
||||||
// angle in "velocity_distribution.cpp"
|
// angle in "velocity_distribution.cpp"
|
||||||
if(!(pitch_angle < pitch_angle_bin_borders_.front()) &&
|
// if(!(pitch_angle < pitch_angle_bin_borders_.front()) &&
|
||||||
(it == pitch_angle_bin_borders_.begin())) {
|
// (it == pitch_angle_bin_borders_.begin())) {
|
||||||
return (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 {
|
int PitchAngleBinning::numBins() const {
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ CylinderCoordinate EventPositionDistribution::rollPosition(
|
|||||||
PositionDistributionFromDensity::PositionDistributionFromDensity(
|
PositionDistributionFromDensity::PositionDistributionFromDensity(
|
||||||
std::shared_ptr<DynamicDensityField> density):
|
std::shared_ptr<DynamicDensityField> density):
|
||||||
density_(density),
|
density_(density),
|
||||||
density_values(std::uniform_real_distribution<double>(0.,1.)) {
|
std_unifrm(std::uniform_real_distribution<double>(0.,1.)) {
|
||||||
|
/************************************************************************************
|
||||||
// get the extent of the domain of the DynamicDensityField object to be used for
|
// get the extent of the domain of the DynamicDensityField object to be used for
|
||||||
// the rejection method
|
// the rejection method
|
||||||
double rmin = density->positionBinning()->radial_binning.binBorders().front();
|
double rmin = density->positionBinning()->radial_binning.binBorders().front();
|
||||||
@@ -60,9 +60,10 @@ PositionDistributionFromDensity::PositionDistributionFromDensity(
|
|||||||
r_values = std::uniform_real_distribution<double>(rmin*rmin, rmax*rmax);
|
r_values = std::uniform_real_distribution<double>(rmin*rmin, rmax*rmax);
|
||||||
phi_values = std::uniform_real_distribution<double>(phimin, phimax);
|
phi_values = std::uniform_real_distribution<double>(phimin, phimax);
|
||||||
z_values = std::uniform_real_distribution<double>(zmin, zmax);
|
z_values = std::uniform_real_distribution<double>(zmin, zmax);
|
||||||
|
**************************************************************************************/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
void PositionDistributionFromDensity::setMaximumDensity() {
|
void PositionDistributionFromDensity::setMaximumDensity() {
|
||||||
maximum_density_ = blitz::max(density_->densityArray());
|
maximum_density_ = blitz::max(density_->densityArray());
|
||||||
}
|
}
|
||||||
@@ -88,6 +89,7 @@ CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* e
|
|||||||
return CylinderCoordinate(
|
return CylinderCoordinate(
|
||||||
blitz::TinyVector<double, 3>(random_r, random_phi, random_z));
|
blitz::TinyVector<double, 3>(random_r, random_phi, random_z));
|
||||||
}
|
}
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* engine,
|
CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* engine,
|
||||||
int r_idx, int phi_idx, int z_idx) {
|
int r_idx, int phi_idx, int z_idx) {
|
||||||
@@ -102,9 +104,9 @@ CylinderCoordinate PositionDistributionFromDensity::drawPosition(std::mt19937* e
|
|||||||
|
|
||||||
double r_rndm, phi_rndm, z_rndm;
|
double r_rndm, phi_rndm, z_rndm;
|
||||||
|
|
||||||
r_rndm = density_values(*engine);
|
r_rndm = std_unifrm(*engine);
|
||||||
phi_rndm = density_values(*engine);
|
phi_rndm = std_unifrm(*engine);
|
||||||
z_rndm = density_values(*engine);
|
z_rndm = std_unifrm(*engine);
|
||||||
|
|
||||||
double radius = std::sqrt(left_bin_border_radial*left_bin_border_radial +
|
double radius = std::sqrt(left_bin_border_radial*left_bin_border_radial +
|
||||||
(2*left_bin_border_radial + stepsize(0))
|
(2*left_bin_border_radial + stepsize(0))
|
||||||
|
|||||||
+50
-35
@@ -10,8 +10,6 @@
|
|||||||
#include "simulation/velocity_distribution.h"
|
#include "simulation/velocity_distribution.h"
|
||||||
#include "simulation/electromagnetic_field.h"
|
#include "simulation/electromagnetic_field.h"
|
||||||
#include "simulation/random_numbers.h"
|
#include "simulation/random_numbers.h"
|
||||||
#include "simulation/logger.h"
|
|
||||||
#include "constants/physical_constants.h"
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
Injector::Injector(
|
Injector::Injector(
|
||||||
@@ -50,12 +48,6 @@ particle::Particle Injector::rollNewParticle(
|
|||||||
DEBUG_LEVEL_3(out.str());
|
DEBUG_LEVEL_3(out.str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
created_specie->deletionLogger()->logDeletion(position, DeletionType::creation_beta);
|
|
||||||
if(kinematic::kineticEnergy(velocity, created_specie->mass_kg())
|
|
||||||
*UnitConversion::JouleToeV > 2000) {
|
|
||||||
created_specie->deletionLogger()->logDeletion(position, DeletionType::creation_above_2keV);
|
|
||||||
}
|
|
||||||
|
|
||||||
return particle::Particle(created_specie, position,
|
return particle::Particle(created_specie, position,
|
||||||
CartesianVector(velocity), time_birth, weight);
|
CartesianVector(velocity), time_birth, weight);
|
||||||
}
|
}
|
||||||
@@ -66,45 +58,76 @@ void Injector::initInjectionTimeDistribution(double delta_t) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<particle::Particle> Injector::rollNewParticles(
|
std::vector<particle::Particle> Injector::rollNewParticles(
|
||||||
std::mt19937* engine, const double current_time,
|
std::mt19937* engine, const int timestep) {
|
||||||
const double beta_particle_weight) {
|
|
||||||
// pull drawing from the position distribution into the "multiplicity" loop?
|
|
||||||
// (would improve resolution stuff in space as well as just in velocity direction
|
|
||||||
// especially for slow particles, i.e. ions)
|
|
||||||
|
|
||||||
std::vector<particle::Particle> new_particles;
|
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_) {
|
for (auto& injector_info : injector_infos_) {
|
||||||
|
if((timestep % injector_info.injection_stride) == injector_info.injection_group) {
|
||||||
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
CylinderCoordinate position = position_distribution_->rollPosition(engine);
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Injected z position: " +
|
DEBUG_LEVEL_3("Injected z position: " +
|
||||||
std::to_string(position.cylinderEntries()(2)));
|
std::to_string(position.cylinderEntries()(2)));
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef debug
|
||||||
// for (int i = 0; i < injector_info.multiplicity; i++) {
|
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(
|
new_particles.push_back(
|
||||||
rollNewParticle(engine, position, injector_info.created_specie,
|
rollNewParticle(engine, position, injector_info.created_specie,
|
||||||
injector_info.creation_velocity_distribution,
|
injector_info.creation_velocity_distribution,
|
||||||
time_birth, beta_particle_weight));
|
time_birth, injector_info.weight));
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
return new_particles;
|
return new_particles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Injector::setWeights(const double physical_number, const int numerical_number) {
|
||||||
|
#ifdef debug
|
||||||
|
std::stringstream out;
|
||||||
|
out << "Weights:\n";
|
||||||
|
#endif
|
||||||
|
int groupsize;
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
#ifdef debug
|
||||||
|
DEBUG(out.str());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
||||||
std::shared_ptr<species::TrackedSpecie> specie,
|
std::shared_ptr<species::TrackedSpecie> specie,
|
||||||
std::vector<particle::Particle>& queue,
|
std::vector<particle::Particle>& queue,
|
||||||
std::shared_ptr<MagneticField> magnetic_field,
|
std::shared_ptr<MagneticField> magnetic_field,
|
||||||
const double weight_factor,
|
const double weight_factor) {
|
||||||
const double injection_time) {
|
|
||||||
blitz::TinyVector<int, 5> index = specie->randomIndex()->index();
|
blitz::TinyVector<int, 5> index = specie->randomIndex()->index();
|
||||||
|
|
||||||
const double num_part_in_bin = specie->densityForDrawing()->particleNumber(index);
|
const double num_part_in_bin = specie->densityForDrawing()->particleNumber(index);
|
||||||
|
|
||||||
if(num_part_in_bin == 0) {
|
if(num_part_in_bin == 0) {
|
||||||
|
#if defined(debug_level2) || defined(debug_level3)
|
||||||
|
std::stringstream out;
|
||||||
|
out << "index: "<< index <<" has no particles";
|
||||||
|
// DEBUG_LEVEL_2(out.str());
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,12 +135,6 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
|||||||
CylinderCoordinate position =
|
CylinderCoordinate position =
|
||||||
specie->positionDistributionFromDensity()->drawPosition(engine,
|
specie->positionDistributionFromDensity()->drawPosition(engine,
|
||||||
index(0), index(1), index(2));
|
index(0), index(1), index(2));
|
||||||
#ifdef debug_level3
|
|
||||||
DEBUG_LEVEL_3("Injected z position: " +
|
|
||||||
std::to_string(position.cylinderEntries()(2)));
|
|
||||||
DEBUG_LEVEL_3("Injected r position: " +
|
|
||||||
std::to_string(position.cylinderEntries()(0)));
|
|
||||||
#endif
|
|
||||||
// draw the velocity
|
// draw the velocity
|
||||||
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
CartesianVector velocity(blitz::TinyVector<double, 3>(0,0,0));
|
||||||
|
|
||||||
@@ -132,22 +149,20 @@ void Injector::drawNewParticleFromDensityField(std::mt19937* engine,
|
|||||||
drawVelocity(index, engine, position, magnetic_field);
|
drawVelocity(index, engine, position, magnetic_field);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef debug_level2
|
#if defined(debug_level2) || defined(debug_level3)
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "drawn index: " << index;
|
out << specie->name() << ":\n";
|
||||||
|
out << "\ndrawn index: " << index;
|
||||||
out << "\nnumber of particles (" << specie->name() << ") at index: " << num_part_in_bin;
|
out << "\nnumber of particles (" << specie->name() << ") at index: " << num_part_in_bin;
|
||||||
out << "\ndrawn position: " << position.cylinderEntries();
|
out << "\ndrawn position: " << position.cylinderEntries();
|
||||||
out << "\ndrawn velocity: " << velocity.cartesianEntries();
|
out << "\ndrawn velocity: " << velocity.cartesianEntries();
|
||||||
|
if(num_part_in_bin > 0)
|
||||||
DEBUG_LEVEL_2(out.str());
|
DEBUG_LEVEL_2(out.str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
particle::Particle drawn_particle(specie, position,
|
particle::Particle drawn_particle(specie, position,
|
||||||
velocity, injection_time, weight_factor*num_part_in_bin);
|
velocity, weight_factor*num_part_in_bin);
|
||||||
// debugging
|
|
||||||
specie->deletionLogger()->logDeletion(position, DeletionType::creation_density);
|
|
||||||
if(drawn_particle.kineticEnergy_eV() > 2000) {
|
|
||||||
specie->deletionLogger()->logDeletion(position, DeletionType::creation_above_2keV);
|
|
||||||
}
|
|
||||||
queue.push_back(drawn_particle);
|
queue.push_back(drawn_particle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,16 +53,19 @@ double Interaction::macroscopicCrossSection(particle::Particle& particle) {
|
|||||||
UnitConversion::JouleToeV;
|
UnitConversion::JouleToeV;
|
||||||
|
|
||||||
const double density = target_->densityField()->density(x_particle);
|
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;
|
return cross_section * density;
|
||||||
};
|
};
|
||||||
|
|
||||||
double Interaction::microscopicCrossSection(double energy_eV) {
|
double Interaction::microscopicCrossSection(double energy_eV,
|
||||||
|
const Coordinate& position) {
|
||||||
return cross_section_(energy_eV);
|
return cross_section_(energy_eV);
|
||||||
}
|
}
|
||||||
|
|
||||||
// think i need to include the magnetic field for it to be really correct
|
// 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,
|
double Interaction::drawCollisionTime(particle::Particle& particle,
|
||||||
RandomNumbers* generator) {
|
RandomNumbers* generator) {
|
||||||
CartesianVector particle_velocity = particle.velocity();
|
CartesianVector particle_velocity = particle.velocity();
|
||||||
@@ -94,13 +97,6 @@ double Interaction::drawCollisionTime(particle::Particle& particle,
|
|||||||
|
|
||||||
const double relative_velocity = kinematic::norm(velocity_target_fixed);
|
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
|
// 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
|
// of the two present velocities (to avoid division by 0 if either is 0) probably
|
||||||
// a better version possible
|
// a better version possible
|
||||||
@@ -115,15 +111,10 @@ double Interaction::drawCollisionTime(particle::Particle& particle,
|
|||||||
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
kinematic::kineticEnergy(velocity_target_fixed, particle.mass_kg())*
|
||||||
UnitConversion::JouleToeV;
|
UnitConversion::JouleToeV;
|
||||||
|
|
||||||
// out << "energy collision time: " << energy_eV;
|
const double crosssection = microscopicCrossSection(energy_eV,
|
||||||
|
particle.cylinderPosition());
|
||||||
const double crosssection = microscopicCrossSection(energy_eV);
|
|
||||||
// out << "\ncross section: " << crosssection;
|
|
||||||
const double density = target_->densityField()->density(particle.cylinderPosition());
|
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.);
|
const double random_number = generator->rollUniform(0.,1.);
|
||||||
if (random_number == 0) {
|
if (random_number == 0) {
|
||||||
return std::numeric_limits<double>::max();
|
return std::numeric_limits<double>::max();
|
||||||
@@ -132,12 +123,7 @@ double Interaction::drawCollisionTime(particle::Particle& particle,
|
|||||||
const double distance_target_fixed =
|
const double distance_target_fixed =
|
||||||
- 1./(crosssection * density) * log(random_number);
|
- 1./(crosssection * density) * log(random_number);
|
||||||
|
|
||||||
// out << "\ndistance in target fixed frame: " << distance_target_fixed;
|
|
||||||
|
|
||||||
const double time = distance_target_fixed / relative_velocity;
|
const double time = distance_target_fixed / relative_velocity;
|
||||||
// out << "\ntime before collision: " << time;
|
|
||||||
// if(density != 0)
|
|
||||||
// DEBUG_LEVEL_1(out.str());
|
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(
|
blitz::TinyVector<double, 3> rotateVelocityInCenterOfMassFrame(
|
||||||
const blitz::TinyVector<double, 3>& velocity_1,
|
const blitz::TinyVector<double, 3>& velocity_1,
|
||||||
const blitz::TinyVector<double, 3>& velocity_2,
|
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 =
|
const blitz::TinyVector<double, 3> v1_in_center_of_mass_frame =
|
||||||
velocity_1 - v_center_of_mass;
|
velocity_1 - v_center_of_mass;
|
||||||
const blitz::TinyVector<double, 3> v1_rot_in_center_of_mass_frame =
|
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;
|
return v1_rot_in_center_of_mass_frame + v_center_of_mass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
#include "simulation/logger.h"
|
#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) {
|
for (auto& type : used_types) {
|
||||||
num_deletions[type] = 0;
|
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.;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeletionLogger::logDeletion(const Coordinate& coordinate,
|
void DeletionLogger::logDeletion(const Coordinate& coordinate,
|
||||||
@@ -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 {
|
std::map<DeletionType, long int> DeletionLogger::numDeletions() const {
|
||||||
return num_deletions;
|
return num_deletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<PhysicalDeletionType, double> DeletionLogger::numPhysDeletions() const {
|
||||||
|
return num_phys_deletions;
|
||||||
|
}
|
||||||
|
|
||||||
void DeletionLogger::numDeletions(long int new_value, DeletionType type) {
|
void DeletionLogger::numDeletions(long int new_value, DeletionType type) {
|
||||||
if (num_deletions.count(type)) {
|
if (num_deletions.count(type)) {
|
||||||
num_deletions.at(type) = new_value;
|
num_deletions.at(type) = new_value;
|
||||||
@@ -39,4 +56,10 @@ void DeletionLogger::resetDeletionLogger() {
|
|||||||
for (auto& pair : sync_num_deletions) {
|
for (auto& pair : sync_num_deletions) {
|
||||||
pair.second = 0;
|
pair.second = 0;
|
||||||
}
|
}
|
||||||
|
for(auto& pair : num_phys_deletions) {
|
||||||
|
pair.second = 0;
|
||||||
|
}
|
||||||
|
for (auto& pair : sync_num_phys_deletions) {
|
||||||
|
pair.second = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+98
-78
@@ -19,7 +19,6 @@ BorisMover::BorisMover(double maximal_time_step_s)
|
|||||||
"The maximal timestep for boris push must be positive.");
|
"The maximal timestep for boris push must be positive.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TBD: include F_g (simply add to electric force)
|
|
||||||
void BorisMover::move(particle::Particle* particle,
|
void BorisMover::move(particle::Particle* particle,
|
||||||
double collision_time_s,
|
double collision_time_s,
|
||||||
ElectricField* electric_field,
|
ElectricField* electric_field,
|
||||||
@@ -30,56 +29,49 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
// to move too far
|
// to move too far
|
||||||
// keep hard coded for now; has to be decided to be either kept (new field for Boris
|
// keep hard coded for now; has to be decided to be either kept (new field for Boris
|
||||||
// mover in json file) or removed again
|
// 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()->
|
const double delta_timeresolution = particle->specie()->
|
||||||
dynamicDensityField()->timeResolution();
|
dynamicDensityField()->timeResolution();
|
||||||
// in order to try to minimize the overshoot in the time domain (i.e. if particle
|
// 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
|
// 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
|
// a lot larger than dt, which would increase the influence of the particle on the
|
||||||
// density)
|
// density)
|
||||||
double max_time_alive = particle->specie()->dynamicDensityField()->physicalTime() -
|
double max_time_alive = delta_timeresolution - particle->timeAlive();
|
||||||
particle->timeAlive();
|
|
||||||
double leftover_time = collision_time_s;
|
double leftover_time = collision_time_s;
|
||||||
|
|
||||||
// auto old_position = particle->position();
|
|
||||||
CartesianCoordinate old_position_cart = particle->cartesianPosition();
|
CartesianCoordinate old_position_cart = particle->cartesianPosition();
|
||||||
CylinderCoordinate old_position_cyl = particle->cylinderPosition();
|
CylinderCoordinate old_position_cyl = particle->cylinderPosition();
|
||||||
|
|
||||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> B_old =
|
blitz::TinyVector<double, 3> B =
|
||||||
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
|
|
||||||
double old_mu;
|
// double old_mu;
|
||||||
|
// double new_mu;
|
||||||
// if magnetic field is 0 use e_z as a reference for the pitch angle
|
// if magnetic field is 0 use e_z as a reference for the pitch angle
|
||||||
// calculation (don't know if best approach, probably not...)
|
// calculation (don't know if best approach, probably not...)
|
||||||
if (kinematic::norm(B_old) == 0) {
|
// if (kinematic::norm(B) == 0) {
|
||||||
old_mu = kinematic::cosPitchAngle(
|
// old_mu = kinematic::cosPitchAngle(
|
||||||
blitz::TinyVector<double, 3>(0,0,1),
|
// blitz::TinyVector<double, 3>(0,0,1),
|
||||||
particle->velocity().cartesianEntries(old_position_cart));
|
// particle->velocity().cartesianEntries(old_position_cart));
|
||||||
} else {
|
// } else {
|
||||||
old_mu = kinematic::cosPitchAngle(
|
// old_mu = kinematic::cosPitchAngle(
|
||||||
B_old, particle->velocity().cartesianEntries(old_position_cart));
|
// B, particle->velocity().cartesianEntries(old_position_cart));
|
||||||
}
|
// }
|
||||||
|
// new_mu = old_mu;
|
||||||
|
|
||||||
double timestep = 0;
|
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;
|
|
||||||
// }
|
|
||||||
|
|
||||||
bool changed_position_bin = false;
|
bool changed_position_bin = false;
|
||||||
bool changed_energy_bin = false;
|
bool changed_energy_bin = false;
|
||||||
bool left_simulation_domain = false;
|
bool left_simulation_domain = false;
|
||||||
bool changed_mu_bin = false;
|
// bool changed_mu_bin = false;
|
||||||
bool died_in_bin = false;
|
bool died_in_bin = particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||||
|
|
||||||
while (
|
while (
|
||||||
!(changed_position_bin || changed_energy_bin || left_simulation_domain ||
|
!(changed_position_bin || changed_energy_bin || left_simulation_domain || // changed_mu_bin ||
|
||||||
changed_mu_bin || died_in_bin) && (leftover_time > 0.)) {
|
died_in_bin) && (leftover_time > 0.)) {
|
||||||
old_position_cart = particle->cartesianPosition();
|
old_position_cart = particle->cartesianPosition();
|
||||||
old_position_cyl = particle->cylinderPosition();
|
old_position_cyl = particle->cylinderPosition();
|
||||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
@@ -89,39 +81,31 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
timestep = std::min(timestep, max_distance / old_velocity);
|
timestep = std::min(timestep, max_distance / old_velocity);
|
||||||
timestep = std::min(timestep, max_time_alive);
|
timestep = std::min(timestep, max_time_alive);
|
||||||
|
|
||||||
// can probably be removed
|
|
||||||
// double moved_distance = 0.;
|
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> E =
|
const blitz::TinyVector<double, 3> E =
|
||||||
electric_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
electric_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
const blitz::TinyVector<double, 3> B =
|
|
||||||
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
|
||||||
const blitz::TinyVector<double, 3> g =
|
const blitz::TinyVector<double, 3> g =
|
||||||
gravity_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
gravity_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
|
|
||||||
movementStep(particle, E, B, g, timestep);
|
movementStep(particle, E, B, g, timestep);
|
||||||
|
|
||||||
particle->increaseTimeAlive(timestep);
|
particle->increaseTimeAlive(timestep);
|
||||||
// particle->increaseTimeInBin(timestep);
|
|
||||||
|
|
||||||
auto new_position_cart = particle->cartesianPosition();
|
auto new_position_cart = particle->cartesianPosition();
|
||||||
auto new_velocity = particle->velocity();
|
auto new_velocity = particle->velocity();
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> B_new =
|
B = magnetic_field->value(particle->cylinderPosition()).
|
||||||
magnetic_field->value(particle->cylinderPosition()).
|
|
||||||
cartesianEntries(new_position_cart);
|
cartesianEntries(new_position_cart);
|
||||||
|
|
||||||
double new_mu;
|
// if (kinematic::norm(B) == 0) {
|
||||||
if (kinematic::norm(B_new) == 0) {
|
// new_mu = kinematic::cosPitchAngle(
|
||||||
new_mu = kinematic::cosPitchAngle(
|
// blitz::TinyVector<double, 3>(0,0,1), new_velocity.cartesianEntries());
|
||||||
blitz::TinyVector<double, 3>(0,0,1), new_velocity.cartesianEntries());
|
// } else {
|
||||||
} else {
|
// new_mu = kinematic::cosPitchAngle(B, new_velocity.cartesianEntries());
|
||||||
new_mu = kinematic::cosPitchAngle(
|
// }
|
||||||
B_new, new_velocity.cartesianEntries());
|
|
||||||
}
|
|
||||||
|
|
||||||
changed_mu_bin =
|
// changed_mu_bin =
|
||||||
particle->specie()->dynamicDensityField()->changedPitchAngleBin(
|
// particle->specie()->dynamicDensityField()->changedPitchAngleBin(
|
||||||
old_mu, new_mu);
|
// old_mu, new_mu);
|
||||||
|
|
||||||
changed_position_bin =
|
changed_position_bin =
|
||||||
particle->specie()->dynamicDensityField()->changedPositionBin(
|
particle->specie()->dynamicDensityField()->changedPositionBin(
|
||||||
@@ -138,6 +122,7 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
particle->specie()->terminator()->reachedMaxTimeAlive(particle);
|
||||||
|
|
||||||
leftover_time -= timestep;
|
leftover_time -= timestep;
|
||||||
|
particle->reduceTimeUntilCollision(timestep);
|
||||||
|
|
||||||
// if max_time_alive == 0 but the difference between the time alive and
|
// if max_time_alive == 0 but the difference between the time alive and
|
||||||
// the endtime > 0 (think can happen due to numerical accuracy)
|
// the endtime > 0 (think can happen due to numerical accuracy)
|
||||||
@@ -147,14 +132,44 @@ void BorisMover::move(particle::Particle* particle,
|
|||||||
? delta_timeresolution*SimConstants::compare_epsilon
|
? delta_timeresolution*SimConstants::compare_epsilon
|
||||||
: (max_time_alive - timestep);
|
: (max_time_alive - timestep);
|
||||||
}
|
}
|
||||||
if(died_in_bin) {
|
|
||||||
particle->specie()->dynamicDensityField()->logMovement(
|
if(died_in_bin && !left_simulation_domain) {
|
||||||
old_position_cyl, old_kinetic_energy, old_mu, particle->weight());
|
double new_mu;
|
||||||
#ifdef debug
|
if (kinematic::norm(B) == 0) {
|
||||||
particle->deposited();
|
new_mu = kinematic::cosPitchAngle(
|
||||||
#endif
|
blitz::TinyVector<double, 3>(0,0,1), particle->velocity().cartesianEntries());
|
||||||
|
} else {
|
||||||
|
new_mu = kinematic::cosPitchAngle(B, particle->velocity().cartesianEntries());
|
||||||
}
|
}
|
||||||
// particle->resetTimeInBin();
|
// 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
|
||||||
|
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 << changed_mu_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_cyl);
|
particle->specie()->currentCollector()->collect(particle, old_position_cyl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,8 +178,8 @@ void BorisMover::movementStep(
|
|||||||
const blitz::TinyVector<double, 3>& electric_field,
|
const blitz::TinyVector<double, 3>& electric_field,
|
||||||
const blitz::TinyVector<double, 3>& magnetic_field,
|
const blitz::TinyVector<double, 3>& magnetic_field,
|
||||||
const blitz::TinyVector<double, 3>& gravity_field,
|
const blitz::TinyVector<double, 3>& gravity_field,
|
||||||
// double& moved_distance,
|
|
||||||
double timestep) const {
|
double timestep) const {
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> v =
|
const blitz::TinyVector<double, 3> v =
|
||||||
particle->velocity().cartesianEntries();
|
particle->velocity().cartesianEntries();
|
||||||
const double m = particle->mass_kg();
|
const double m = particle->mass_kg();
|
||||||
@@ -232,10 +247,9 @@ void BorisMover::movementStep(
|
|||||||
/*
|
/*
|
||||||
Might be slower, but essentially the same code */
|
Might be slower, but essentially the same code */
|
||||||
const blitz::TinyVector<double, 3> u_minus =
|
const blitz::TinyVector<double, 3> u_minus =
|
||||||
v + (acceleration * maximal_time_step_s_) / (2.);
|
v + (acceleration * timestep) / (2.);
|
||||||
const double gamma = kinematic::relativisticGamma(u_minus);;
|
|
||||||
const blitz::TinyVector<double, 3> temp_1 =
|
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 =
|
const blitz::TinyVector<double, 3> u_prime =
|
||||||
u_minus + (blitz::cross(u_minus, temp_1));
|
u_minus + (blitz::cross(u_minus, temp_1));
|
||||||
const blitz::TinyVector<double, 3> temp_2 =
|
const blitz::TinyVector<double, 3> temp_2 =
|
||||||
@@ -243,15 +257,12 @@ void BorisMover::movementStep(
|
|||||||
const blitz::TinyVector<double, 3> u_plus =
|
const blitz::TinyVector<double, 3> u_plus =
|
||||||
u_minus + (blitz::cross(u_prime, temp_2));
|
u_minus + (blitz::cross(u_prime, temp_2));
|
||||||
const blitz::TinyVector<double, 3> u_new =
|
const blitz::TinyVector<double, 3> u_new =
|
||||||
u_plus + (acceleration * maximal_time_step_s_) / (2.);
|
u_plus + (acceleration * timestep) / (2.);
|
||||||
|
|
||||||
particle->velocity(CartesianVector(u_new));
|
particle->velocity(CartesianVector(u_new));
|
||||||
|
|
||||||
const CartesianCoordinate distance(u_new * timestep);
|
const CartesianCoordinate distance(u_new * timestep);
|
||||||
particle->move(distance);
|
particle->move(distance);
|
||||||
|
|
||||||
// moved_distance += std::sqrt(
|
|
||||||
// blitz::dot(distance.cartesianEntries(), distance.cartesianEntries()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -268,12 +279,17 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
GravityField* gravity_field) {
|
GravityField* gravity_field) {
|
||||||
double leftover_time = collision_time_s;
|
double leftover_time = collision_time_s;
|
||||||
|
|
||||||
auto old_position = particle->cartesianPosition();
|
// auto old_position = particle->cartesianPosition();
|
||||||
|
CartesianCoordinate old_position_cart = particle->cartesianPosition();
|
||||||
|
CylinderCoordinate old_position_cyl = particle->cylinderPosition();
|
||||||
|
|
||||||
auto old_velocity = particle->velocity();
|
auto old_velocity = particle->velocity();
|
||||||
double old_kinetic_energy = particle->kineticEnergy_eV();
|
double old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
|
|
||||||
double old_mu = kinematic::cosPitchAngle(
|
double old_mu = kinematic::cosPitchAngle(
|
||||||
magnetic_field->value(old_position).cartesianEntries(old_position),
|
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart),
|
||||||
old_velocity.cartesianEntries(old_position));
|
old_velocity.cartesianEntries());
|
||||||
|
double new_mu = old_mu;
|
||||||
|
|
||||||
bool changed_position_bin = false;
|
bool changed_position_bin = false;
|
||||||
bool changed_energy_bin = false;
|
bool changed_energy_bin = false;
|
||||||
@@ -283,29 +299,30 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
// -> add maximal timestep to time in bin and stop moving the particle
|
// -> add maximal timestep to time in bin and stop moving the particle
|
||||||
bool died_in_bin = false;
|
bool died_in_bin = false;
|
||||||
double max_time_alive =
|
double max_time_alive =
|
||||||
particle->specie()->dynamicDensityField()->physicalTime() -
|
particle->specie()->dynamicDensityField()->timeResolution() -
|
||||||
particle->timeAlive();
|
particle->timeAlive();
|
||||||
|
|
||||||
while (
|
while (
|
||||||
!(changed_position_bin || changed_energy_bin || changed_mu_bin
|
!(changed_position_bin || changed_energy_bin || changed_mu_bin
|
||||||
|| left_simulation_domain) &&
|
|| left_simulation_domain) &&
|
||||||
(leftover_time > 0.) && !(died_in_bin)) {
|
(leftover_time > 0.) && !(died_in_bin)) {
|
||||||
old_position = particle->cartesianPosition();
|
old_position_cart = particle->cartesianPosition();
|
||||||
|
old_position_cyl = particle->cylinderPosition();
|
||||||
old_velocity = particle->velocity();
|
old_velocity = particle->velocity();
|
||||||
|
|
||||||
old_kinetic_energy = particle->kineticEnergy_eV();
|
old_kinetic_energy = particle->kineticEnergy_eV();
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> force_over_charge =
|
blitz::TinyVector<double, 3> force_over_charge =
|
||||||
electric_field->value(old_position).cartesianEntries(old_position) +
|
electric_field->value(old_position_cyl).cartesianEntries(old_position_cart) +
|
||||||
gravity_field->value(old_position).cartesianEntries(old_position) *
|
gravity_field->value(old_position_cyl).cartesianEntries(old_position_cart) *
|
||||||
particle->mass_kg() / particle->charge_C();
|
particle->mass_kg() / particle->charge_C();
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> B =
|
const blitz::TinyVector<double, 3> B =
|
||||||
magnetic_field->value(old_position).cartesianEntries(old_position);
|
magnetic_field->value(old_position_cyl).cartesianEntries(old_position_cart);
|
||||||
const double B_norm = kinematic::norm(B);
|
const double B_norm = kinematic::norm(B);
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> gradB =
|
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
|
// Todo: add calculation of divB here
|
||||||
// use Kassiopeia paper for reference
|
// use Kassiopeia paper for reference
|
||||||
|
|
||||||
@@ -341,7 +358,7 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
v_perp_norm*v_perp_norm +
|
v_perp_norm*v_perp_norm +
|
||||||
v_drift_norm*v_drift_norm),
|
v_drift_norm*v_drift_norm),
|
||||||
max_time_alive);
|
max_time_alive);
|
||||||
timestep = std::min(timestep, collision_time_s);
|
timestep = std::min(timestep, leftover_time);
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> movement_parallel =
|
const blitz::TinyVector<double, 3> movement_parallel =
|
||||||
v_parallel * timestep;
|
v_parallel * timestep;
|
||||||
@@ -379,7 +396,7 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
// might be better to do after the actual movement and then just extract
|
// might be better to do after the actual movement and then just extract
|
||||||
// the position again from the particle
|
// the position again from the particle
|
||||||
const blitz::TinyVector<double, 3> new_position =
|
const blitz::TinyVector<double, 3> new_position =
|
||||||
old_position.cartesianEntries() + movement_parallel
|
old_position_cart.cartesianEntries() + movement_parallel
|
||||||
+ movement_drift + movement_around_gyro_center;
|
+ movement_drift + movement_around_gyro_center;
|
||||||
|
|
||||||
const blitz::TinyVector<double, 3> B_new =
|
const blitz::TinyVector<double, 3> B_new =
|
||||||
@@ -445,15 +462,15 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
|
|
||||||
changed_position_bin =
|
changed_position_bin =
|
||||||
particle->specie()->dynamicDensityField()->changedPositionBin(
|
particle->specie()->dynamicDensityField()->changedPositionBin(
|
||||||
old_position, new_position);
|
old_position_cyl, particle->cylinderPosition());
|
||||||
|
|
||||||
changed_energy_bin =
|
changed_energy_bin =
|
||||||
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
particle->specie()->dynamicDensityField()->changedEnergyBin(
|
||||||
old_kinetic_energy, particle->kineticEnergy_eV());
|
old_kinetic_energy, particle->kineticEnergy_eV());
|
||||||
|
|
||||||
const double new_mu = kinematic::cosPitchAngle(magnetic_field
|
new_mu = kinematic::cosPitchAngle(magnetic_field
|
||||||
->value(new_position).cartesianEntries(new_position),
|
->value(particle->cylinderPosition()).cartesianEntries(new_position),
|
||||||
particle->velocity().cartesianEntries(new_position));
|
particle->velocity().cartesianEntries());
|
||||||
|
|
||||||
changed_mu_bin = particle->specie()->dynamicDensityField()
|
changed_mu_bin = particle->specie()->dynamicDensityField()
|
||||||
->changedPitchAngleBin(old_mu, new_mu);
|
->changedPitchAngleBin(old_mu, new_mu);
|
||||||
@@ -469,14 +486,17 @@ void DriftMover::move(particle::Particle* particle,
|
|||||||
particle->specie()->terminator()->leftSimulationDomain(particle);
|
particle->specie()->terminator()->leftSimulationDomain(particle);
|
||||||
|
|
||||||
leftover_time -= timestep;
|
leftover_time -= timestep;
|
||||||
|
particle->reduceTimeUntilCollision(timestep);
|
||||||
}
|
}
|
||||||
|
|
||||||
// only log a particle in the bin where its movement ends, i.e. if
|
// only log a particle in the bin where its movement ends, i.e. if
|
||||||
// the particle reached the end of the timestep
|
// the particle reached the end of the timestep
|
||||||
if(died_in_bin)
|
if(died_in_bin && !left_simulation_domain) {
|
||||||
particle->specie()->dynamicDensityField()->logMovement(
|
particle->specie()->dynamicDensityField()->logMovement(
|
||||||
old_position, old_kinetic_energy, old_mu, particle->weight());
|
particle->cylinderPosition(), particle->kineticEnergy_eV(), new_mu,
|
||||||
particle->specie()->currentCollector()->collect(particle, old_position);
|
particle->weight());
|
||||||
|
}
|
||||||
|
particle->specie()->currentCollector()->collect(particle, old_position_cyl);
|
||||||
}
|
}
|
||||||
|
|
||||||
blitz::TinyVector<double, 3> DriftMover::driftVelocity(
|
blitz::TinyVector<double, 3> DriftMover::driftVelocity(
|
||||||
|
|||||||
@@ -26,3 +26,28 @@ void MpiCommunication::init(int argc, char* argv[]) {
|
|||||||
void MpiCommunication::finalize() {
|
void MpiCommunication::finalize() {
|
||||||
MPI_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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,6 +18,51 @@ 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,
|
Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
||||||
const Coordinate& position,
|
const Coordinate& position,
|
||||||
const Vector& velocity,
|
const Vector& velocity,
|
||||||
@@ -34,6 +79,37 @@ Particle::Particle(std::shared_ptr<species::TrackedSpecie> specie,
|
|||||||
last_id_++;
|
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;
|
long int Particle::last_id_ = 0;
|
||||||
|
|
||||||
double Particle::mass_kg() const {
|
double Particle::mass_kg() const {
|
||||||
@@ -115,12 +191,30 @@ double Particle::weight() const {
|
|||||||
return weight_;
|
return weight_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Particle::deposited() {
|
void Particle::deposited(bool truthValue) {
|
||||||
deposited_ = true;
|
deposited_ = truthValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Particle::wasDeposited() {
|
bool Particle::wasDeposited() {
|
||||||
return deposited_;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
particle::SerializedParticle Particle::serialize() {
|
||||||
|
return particle::SerializedParticle(weight_,
|
||||||
|
position_cart_.cartesianEntries(), velocity_.cartesianEntries(),
|
||||||
|
specie_->name(), index_next_interaction_, time_until_collision_);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace particle
|
} // namespace particle
|
||||||
|
|||||||
+146
-104
@@ -44,6 +44,18 @@ Simulation::Simulation(std::string parameter_filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::init(Parameter& 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);
|
magnetic_field_ = generator::magneticField(parameter);
|
||||||
electric_field_ = generator::electricField(parameter);
|
electric_field_ = generator::electricField(parameter);
|
||||||
gravity_field_ = generator::gravityField(parameter);
|
gravity_field_ = generator::gravityField(parameter);
|
||||||
@@ -86,7 +98,8 @@ void Simulation::init(Parameter& parameter) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Restart restarter = generator::buildRestart(parameter);
|
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
|
// poisson solver is restarted -> set the electric field from the potential
|
||||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||||
|
|
||||||
@@ -139,19 +152,17 @@ void Simulation::start() {
|
|||||||
"NumberTimesteps"}), 1);
|
"NumberTimesteps"}), 1);
|
||||||
|
|
||||||
// number of physical beta events defining the timescale through
|
// number of physical beta events defining the timescale through
|
||||||
// time_resolution_events/Activity
|
// dt = time_resolution_events/Activity
|
||||||
const double time_resolution_events =
|
const double time_resolution_events =
|
||||||
parameter_.doubleValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
parameter_.doubleValue(json_path({"Simulation", "TimeResolutionEvents"}),
|
||||||
MpiCommunication::mpiSize());
|
MpiCommunication::mpi_size);
|
||||||
|
|
||||||
// number of beta decay events per timestep and CPU (will get normalized s.t.
|
// number of beta decay events per timestep and CPU (will get normalized s.t.
|
||||||
// the physical number of particles is correct)
|
// the physical number of particles is correct)
|
||||||
const int beta_decay_events =
|
const int beta_decay_events =
|
||||||
parameter_.intValue(json_path{"Simulation", "BetaDecayEventsPerCPU"}, 1);
|
parameter_.intValue(json_path{"Simulation", "BetaDecayEventsPerCPU"}, 1);
|
||||||
|
|
||||||
// weight of a particle created through beta decay wrt a physical particle
|
injector_->setWeights(time_resolution_events, beta_decay_events);
|
||||||
const double beta_particle_weight = time_resolution_events/
|
|
||||||
static_cast<double>(beta_decay_events*MpiCommunication::mpiSize());
|
|
||||||
|
|
||||||
// number of density events per timestep and CPU
|
// number of density events per timestep and CPU
|
||||||
const int particles_per_bin =
|
const int particles_per_bin =
|
||||||
@@ -160,12 +171,15 @@ void Simulation::start() {
|
|||||||
|
|
||||||
// calculate a 'stride' for the density events s.t. the same number of syncs
|
// calculate a 'stride' for the density events s.t. the same number of syncs
|
||||||
// would be performed
|
// would be performed
|
||||||
const int density_stride = std::ceil(particles_per_bin *
|
int density_stride = particles_per_bin;
|
||||||
|
if(beta_decay_events != 0) {
|
||||||
|
density_stride = std::ceil(particles_per_bin *
|
||||||
(static_cast<double>(event_stride)/beta_decay_events));
|
(static_cast<double>(event_stride)/beta_decay_events));
|
||||||
|
}
|
||||||
// calculate the scaling factor for the particle weight for particles
|
// calculate the scaling factor for the particle weight for particles
|
||||||
// drawn from the density
|
// drawn from the density
|
||||||
const double density_weight_factor =
|
const double density_weight_factor =
|
||||||
1./(MpiCommunication::mpiSize()*particles_per_bin);
|
1./(MpiCommunication::mpi_size*particles_per_bin);
|
||||||
|
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
DEBUG_LEVEL_0("Number of particles per bin per CPU: " + std::to_string(particles_per_bin));
|
DEBUG_LEVEL_0("Number of particles per bin per CPU: " + std::to_string(particles_per_bin));
|
||||||
@@ -179,31 +193,16 @@ void Simulation::start() {
|
|||||||
|
|
||||||
const double delta_t = time_resolution_events*injector_->timePassed();
|
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);
|
timer_->setDeltaT(delta_t);
|
||||||
injector_->initInjectionTimeDistribution(delta_t);
|
injector_->initInjectionTimeDistribution(delta_t);
|
||||||
|
|
||||||
int num_cpu_syncs = 0;
|
int num_cpu_syncs = 0;
|
||||||
bool reset = true;
|
bool reset = true;
|
||||||
int timesteps = 0;
|
|
||||||
|
|
||||||
queue_.reserve(100);
|
|
||||||
|
|
||||||
timer_->increaseTimestep(delta_t);
|
timer_->increaseTimestep(delta_t);
|
||||||
|
|
||||||
while (timesteps < number_timesteps) {
|
while (timestep < number_timesteps) {
|
||||||
#if defined debug_level3
|
#if defined(debug_level3)
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "Timeinterval: " << timer_->time() << "s.";
|
out << "Timeinterval: " << timer_->time() << "s.";
|
||||||
DEBUG_LEVEL_3(out.str());
|
DEBUG_LEVEL_3(out.str());
|
||||||
@@ -221,19 +220,21 @@ void Simulation::start() {
|
|||||||
std::to_string(density_events_of_cycle));
|
std::to_string(density_events_of_cycle));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SIM_INFO("Processing timestep: " + std::to_string(timesteps));
|
if(timestep%(std::max(number_timesteps/100, 1)) == 0)
|
||||||
|
SIM_INFO("Processing timestep: " + std::to_string(timestep));
|
||||||
|
#ifdef debug
|
||||||
SIM_INFO("Leftover events this timestep this CPU: " +
|
SIM_INFO("Leftover events this timestep this CPU: " +
|
||||||
std::to_string(leftover_events_time_resolution));
|
std::to_string(leftover_events_time_resolution));
|
||||||
SIM_INFO("Leftover density events this timestep this CPU: " +
|
SIM_INFO("Leftover density events this timestep this CPU: " +
|
||||||
std::to_string(leftover_density_events));
|
std::to_string(leftover_density_events));
|
||||||
|
#endif
|
||||||
|
|
||||||
// process both density and beta events before a cpu synchronization
|
// process both density and beta events before a cpu synchronization
|
||||||
processDensityEvents(particles_per_bin, density_weight_factor);
|
processDensityEvents(particles_per_bin, density_weight_factor);
|
||||||
if(num_cpu_syncs == 0)
|
processEvents(events_of_cycle);
|
||||||
processEvents(events_of_cycle, beta_particle_weight);
|
|
||||||
|
|
||||||
#ifdef debug_level1
|
#if defined(debug_level1) || defined(debug_level2) || defined(debug_level3)
|
||||||
DEBUG_LEVEL_1("Processing timestep: " + std::to_string(timesteps));
|
DEBUG_LEVEL_1("Processing timestep: " + std::to_string(timestep));
|
||||||
DEBUG_LEVEL_1("Leftover events this timestep: " +
|
DEBUG_LEVEL_1("Leftover events this timestep: " +
|
||||||
std::to_string(leftover_events_time_resolution));
|
std::to_string(leftover_events_time_resolution));
|
||||||
#endif
|
#endif
|
||||||
@@ -243,7 +244,9 @@ void Simulation::start() {
|
|||||||
|
|
||||||
reset = !(leftover_events_time_resolution > 0);
|
reset = !(leftover_events_time_resolution > 0);
|
||||||
|
|
||||||
|
#ifdef debug
|
||||||
SIM_INFO("Cpu sync.");
|
SIM_INFO("Cpu sync.");
|
||||||
|
#endif
|
||||||
SimulationTimer::eventStartPoint(std::string("CpuSync"));
|
SimulationTimer::eventStartPoint(std::string("CpuSync"));
|
||||||
// 'reset' necessary as parameter to set the density for drawing
|
// 'reset' necessary as parameter to set the density for drawing
|
||||||
// otherwise it would be more difficult to set it... (cpu synchronizer
|
// otherwise it would be more difficult to set it... (cpu synchronizer
|
||||||
@@ -255,38 +258,52 @@ void Simulation::start() {
|
|||||||
|
|
||||||
// can probably be moved into the reset section and therefore
|
// can probably be moved into the reset section and therefore
|
||||||
// the parameter 'reset' could probably be removed
|
// the parameter 'reset' could probably be removed
|
||||||
|
#ifdef debug
|
||||||
SIM_INFO("Poisson step.");
|
SIM_INFO("Poisson step.");
|
||||||
|
#endif
|
||||||
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
|
SimulationTimer::eventStartPoint(std::string("PoissonStep"));
|
||||||
// only solves the potential anew if 'reset' is true
|
// only solves the potential anew if 'reset' is true
|
||||||
poisson_solver_->solvePotential(chargedensity(), reset);
|
poisson_solver_->solvePotential(chargedensity(), reset);
|
||||||
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
electric_field_->updateDynamicField(poisson_solver_->staticElectricField());
|
||||||
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
|
SimulationTimer::eventStopPoint(std::string("PoissonStep"));
|
||||||
|
|
||||||
|
#ifdef debug
|
||||||
SIM_INFO("Perform output.");
|
SIM_INFO("Perform output.");
|
||||||
|
#endif
|
||||||
SimulationTimer::eventStartPoint(std::string("Output"));
|
SimulationTimer::eventStartPoint(std::string("Output"));
|
||||||
|
// only write inactive queue, obvi not correct if written between timesteps
|
||||||
output_->writeSimulationData(num_cpu_syncs, tracked_species_, poisson_solver_.get(),
|
output_->writeSimulationData(num_cpu_syncs, tracked_species_, poisson_solver_.get(),
|
||||||
random_->engine());
|
random_->engine(), storage_queue_[inactive_storage],
|
||||||
|
timestep + 1 + injectionGroupOffset);
|
||||||
SimulationTimer::eventStopPoint(std::string("Output"));
|
SimulationTimer::eventStopPoint(std::string("Output"));
|
||||||
|
|
||||||
SimulationTimer::eventStartPoint("Reset");
|
SimulationTimer::eventStartPoint("Reset");
|
||||||
if(reset) {
|
if(reset) {
|
||||||
|
#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.");
|
SIM_INFO("Do resets and increase the timestep for timeresolution.");
|
||||||
|
#endif
|
||||||
|
active_storage = (active_storage + 1) % 2;
|
||||||
|
inactive_storage = (inactive_storage + 1) % 2;
|
||||||
|
|
||||||
for(auto& pair : tracked_species_) {
|
for(auto& pair : tracked_species_) {
|
||||||
pair.second->dynamicDensityField()->resetDynamicDensityField();
|
pair.second->dynamicDensityField()->resetDynamicDensityField();
|
||||||
|
|
||||||
pair.second->currentCollector()->resetCurrentCollector();
|
pair.second->currentCollector()->resetCurrentCollector();
|
||||||
|
|
||||||
pair.second->deletionLogger()->resetDeletionLogger();
|
pair.second->deletionLogger()->resetDeletionLogger();
|
||||||
|
|
||||||
// the density from which new particles are drawn is only updated after a timestep
|
|
||||||
pair.second->positionDistributionFromDensity()->setMaximumDensity();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
leftover_events_time_resolution = beta_decay_events;
|
leftover_events_time_resolution = beta_decay_events;
|
||||||
leftover_density_events = particles_per_bin;
|
leftover_density_events = particles_per_bin;
|
||||||
|
|
||||||
timer_->increaseTimestep(delta_t);
|
timer_->increaseTimestep(delta_t);
|
||||||
timesteps++;
|
timestep++;
|
||||||
}
|
}
|
||||||
SimulationTimer::eventStopPoint("Reset");
|
SimulationTimer::eventStopPoint("Reset");
|
||||||
}
|
}
|
||||||
@@ -296,7 +313,7 @@ int particleNumberFromQueue(int queue_length, RandomNumbers* random) {
|
|||||||
return random->rollUniform(0, queue_length);
|
return random->rollUniform(0, queue_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::processEvents(int events, const double beta_particle_weight) {
|
void Simulation::processEvents(int events) {
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
DEBUG_LEVEL_0("Processing events.");
|
DEBUG_LEVEL_0("Processing events.");
|
||||||
#endif
|
#endif
|
||||||
@@ -316,12 +333,11 @@ void Simulation::processEvents(int events, const double beta_particle_weight) {
|
|||||||
DEBUG_LEVEL_2("Inject particles to queue.");
|
DEBUG_LEVEL_2("Inject particles to queue.");
|
||||||
#endif
|
#endif
|
||||||
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
SimulationTimer::eventStartPoint(std::string("ParticleInjection"));
|
||||||
new_particles = determineInjectedParticles(random_.get(),
|
new_particles = injector_->rollNewParticles(random_->engine(), timestep + injectionGroupOffset);
|
||||||
beta_particle_weight);
|
|
||||||
// construction of stringstream can take up a lot of computation time
|
// construction of stringstream can take up a lot of computation time
|
||||||
// even if the debug output performs nothing therefore use the if defined
|
// even if the debug output performs nothing therefore use the if defined
|
||||||
// preprocessor directive
|
// preprocessor directive
|
||||||
#if defined debug_level3
|
#if defined(debug_level3)
|
||||||
for(auto& particle : new_particles) {
|
for(auto& particle : new_particles) {
|
||||||
std::stringstream output_ss;
|
std::stringstream output_ss;
|
||||||
output_ss << particle.specie()->name() << " with velocity (cart): ";
|
output_ss << particle.specie()->name() << " with velocity (cart): ";
|
||||||
@@ -336,7 +352,14 @@ void Simulation::processEvents(int events, const double beta_particle_weight) {
|
|||||||
#ifdef debug_level2
|
#ifdef debug_level2
|
||||||
DEBUG_LEVEL_2("Injected particles to queue.");
|
DEBUG_LEVEL_2("Injected particles to queue.");
|
||||||
#endif
|
#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(),
|
queue_.insert(queue_.end(), new_particles.begin(),
|
||||||
new_particles.end());
|
new_particles.end());
|
||||||
}
|
}
|
||||||
@@ -405,10 +428,12 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
|
|||||||
// if no new particles could be injected from the density, it is not possible
|
// if no new particles could be injected from the density, it is not possible
|
||||||
// that during another iteration cycle new particles will be injected
|
// that during another iteration cycle new particles will be injected
|
||||||
// (drawing field only changes after timesteps)
|
// (drawing field only changes after timesteps)
|
||||||
|
|
||||||
if(all_bins_done) {
|
if(all_bins_done) {
|
||||||
current_event += 1;
|
current_event += 1;
|
||||||
for(auto& element : tracked_species_) {
|
for(auto& element : tracked_species_) {
|
||||||
|
if(element.second->explicitlyStored()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
element.second->randomIndex()->reshuffle(random_->engine());
|
element.second->randomIndex()->reshuffle(random_->engine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -436,8 +461,7 @@ void Simulation::processDensityEvents(int particles_per_bin, const double weight
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::processUntilTermination(
|
void Simulation::processUntilTermination(particle::Particle& particle) {
|
||||||
particle::Particle& particle) {
|
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Process particle until termination");
|
DEBUG_LEVEL_3("Process particle until termination");
|
||||||
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
|
DEBUG_LEVEL_3("Weight of the particle: " + std::to_string(particle.weight()));
|
||||||
@@ -446,17 +470,25 @@ void Simulation::processUntilTermination(
|
|||||||
auto old_position = particle.cylinderPosition();
|
auto old_position = particle.cylinderPosition();
|
||||||
double old_energy = particle.kineticEnergy_eV();
|
double 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"));
|
#ifdef debug_level3
|
||||||
// const double mfp_m = meanFreePath(particle, random_.get(),
|
std::stringstream out_;
|
||||||
// macroscopic_cross_sections_m);
|
out_ << "Time until collision: " << particle.timeUntilCollision();
|
||||||
const double collision_time = collisionTime(particle, random_.get());
|
DEBUG_LEVEL_1(out_.str());
|
||||||
SimulationTimer::eventStopPoint(std::string("MFP calculation"));
|
#endif
|
||||||
|
|
||||||
SimulationTimer::eventStartPoint(std::string("Mover"));
|
SimulationTimer::eventStartPoint(std::string("Mover"));
|
||||||
particle.specie()->mover()->move(&particle, collision_time, electric_field_.get(),
|
particle.specie()->mover()->move(&particle,
|
||||||
magnetic_field_.get(), gravity_field_.get());
|
particle.timeUntilCollision(),
|
||||||
|
electric_field_.get(),
|
||||||
|
magnetic_field_.get(),
|
||||||
|
gravity_field_.get());
|
||||||
SimulationTimer::eventStopPoint(std::string("Mover"));
|
SimulationTimer::eventStopPoint(std::string("Mover"));
|
||||||
|
|
||||||
bool was_reflected = false;
|
bool was_reflected = false;
|
||||||
@@ -472,18 +504,14 @@ void Simulation::processUntilTermination(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
if (particle.specie()->terminator()->reachedMaxTimeAlive(
|
||||||
|
&particle) &&
|
||||||
|
!particle.specie()->terminator()->leftSimulationDomain(
|
||||||
&particle)) {
|
&particle)) {
|
||||||
|
// particle.invalidateNextInteraction();
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
|
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name() +
|
||||||
". Reached timeresolution.");
|
". Reached timeresolution.");
|
||||||
#endif
|
#endif
|
||||||
if(particle.specie()->deletionLogger()) {
|
|
||||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
|
||||||
DeletionType::max_time_alive);
|
|
||||||
if(particle.kineticEnergy_eV() > 2000) {
|
|
||||||
particle.specie()->deletionLogger()->logDeletion(particle.cartesianPosition(),
|
|
||||||
DeletionType::loss_above_2keV);
|
|
||||||
}
|
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
if(!particle.wasDeposited()) {
|
if(!particle.wasDeposited()) {
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
@@ -493,31 +521,40 @@ void Simulation::processUntilTermination(
|
|||||||
ERROR(out.str());
|
ERROR(out.str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
// particle terminated due to reaching time resolution alone -> needs
|
||||||
|
// to be stored (if it's an electron)
|
||||||
|
if(particle.specie()->explicitlyStored()) {
|
||||||
|
storage_queue_[inactive_storage].push_back(particle.serialize());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(particle.specie()->deletionLogger()) {
|
||||||
|
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
||||||
|
DeletionType::max_time_alive);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
} else if (particle.specie()->terminator()->leftSimulationDomain(
|
||||||
&particle)) {
|
&particle)) {
|
||||||
#if defined debug_level3
|
#if defined(debug)
|
||||||
DEBUG_LEVEL_1("Terminate particle " + particle.specie()->name()
|
DEBUG("Terminate particle " + particle.specie()->name()
|
||||||
+ ". Left simulation domain.");
|
+ ". Left simulation domain.");
|
||||||
std::stringstream output_ss;
|
// std::stringstream output_ss;
|
||||||
output_ss << "Position (cyl): " << particle.cylinderPosition().cylinderEntries();
|
// output_ss << "Position (cyl): " << particle.cylinderPosition().cylinderEntries();
|
||||||
output_ss << " (cart): " << particle.cartesianPosition().cartesianEntries();
|
// output_ss << " (cart): " << particle.cartesianPosition().cartesianEntries();
|
||||||
// ERROR(output_ss.str());
|
// ERROR(output_ss.str());
|
||||||
#endif
|
#endif
|
||||||
if (particle.specie()->deletionLogger()) {
|
if (particle.specie()->deletionLogger()) {
|
||||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
||||||
DeletionType::wall);
|
DeletionType::wall);
|
||||||
if(particle.kineticEnergy_eV() > 2000) {
|
particle.specie()->deletionLogger()->logDeletion(particle,
|
||||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
PhysicalDeletionType::wall);
|
||||||
DeletionType::loss_above_2keV);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
if(particle.wasDeposited()) {
|
if(particle.wasDeposited()) {
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "particle " << particle.specie()->name();
|
out << "particle " << particle.specie()->name();
|
||||||
out << " left simulation domain but still contributes to the density";
|
out << " left simulation domain but still contributes to the density";
|
||||||
|
out << "\nposition: " << particle.cylinderPosition().cylinderEntries();
|
||||||
|
out << "\nvelocity: " << particle.velocity().cartesianEntries();
|
||||||
ERROR(out.str());
|
ERROR(out.str());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -546,6 +583,22 @@ void Simulation::processUntilTermination(
|
|||||||
// macroscopic_cross_sections_m);
|
// macroscopic_cross_sections_m);
|
||||||
SimulationTimer::eventStopPoint(std::string("Interaction"));
|
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();
|
particle.increaseInteractionCounter();
|
||||||
|
|
||||||
for (auto& new_particle : output.newParticles()) {
|
for (auto& new_particle : output.newParticles()) {
|
||||||
@@ -560,6 +613,8 @@ void Simulation::processUntilTermination(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (particle.specie()->terminator()->reachedMaxInteractions(&particle)) {
|
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
|
#ifdef debug_level3
|
||||||
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
DEBUG_LEVEL_3("Terminate particle " + particle.specie()->name()
|
||||||
+ ". Reached max interactions.");
|
+ ". Reached max interactions.");
|
||||||
@@ -567,42 +622,18 @@ void Simulation::processUntilTermination(
|
|||||||
if (particle.specie()->deletionLogger()) {
|
if (particle.specie()->deletionLogger()) {
|
||||||
particle.specie()->deletionLogger()->logDeletion(
|
particle.specie()->deletionLogger()->logDeletion(
|
||||||
particle.cylinderPosition(), DeletionType::max_interactions);
|
particle.cylinderPosition(), DeletionType::max_interactions);
|
||||||
if(particle.kineticEnergy_eV() > 2000) {
|
|
||||||
particle.specie()->deletionLogger()->logDeletion(particle.cylinderPosition(),
|
|
||||||
DeletionType::loss_above_2keV);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double Simulation::meanFreePath(particle::Particle& particle,
|
particle.invalidateNextInteraction();
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe rewrite to s.t. the min_element part can be removed (together with the
|
// maybe rewrite to s.t. the min_element part can be removed (together with the
|
||||||
// algorithm lib)
|
// algorithm lib)
|
||||||
double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
void Simulation::collisionTime(particle::Particle& particle, RandomNumbers* random) {
|
||||||
std::vector<double> collision_times;
|
std::vector<double> collision_times;
|
||||||
double tmp;
|
double tmp;
|
||||||
|
|
||||||
@@ -614,6 +645,7 @@ double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* ra
|
|||||||
auto min_iterator = std::min_element(collision_times.begin(), collision_times.end());
|
auto min_iterator = std::min_element(collision_times.begin(), collision_times.end());
|
||||||
|
|
||||||
particle.indexNextInteration((min_iterator - collision_times.begin()));
|
particle.indexNextInteration((min_iterator - collision_times.begin()));
|
||||||
|
particle.timeUntilCollision(*min_iterator);
|
||||||
|
|
||||||
#ifdef debug_level3
|
#ifdef debug_level3
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
@@ -628,8 +660,6 @@ double Simulation::collisionTime(particle::Particle& particle, RandomNumbers* ra
|
|||||||
|
|
||||||
DEBUG_LEVEL_3(out.str());
|
DEBUG_LEVEL_3(out.str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *min_iterator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interaction::InteractionOutput Simulation::interact(
|
interaction::InteractionOutput Simulation::interact(
|
||||||
@@ -662,12 +692,6 @@ 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
|
// weight_factor has to be such that particleNumber * weight_factor = weight
|
||||||
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
||||||
RandomNumbers* random, const double weight_factor, const int current,
|
RandomNumbers* random, const double weight_factor, const int current,
|
||||||
@@ -680,12 +704,30 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
|||||||
" the new particles vector is not empty at initialization");
|
" the new particles vector is not empty at initialization");
|
||||||
}
|
}
|
||||||
|
|
||||||
const double injection_time = timer_->time() - timer_->getDeltaT();
|
|
||||||
|
|
||||||
bool tmp_done = false;
|
bool tmp_done = false;
|
||||||
all_bins_done = true;
|
all_bins_done = true;
|
||||||
|
|
||||||
for(auto& pair: tracked_species_) {
|
for(auto& pair: tracked_species_) {
|
||||||
|
// Note: takes the next particle in the storage queue regardless if
|
||||||
|
// that particle is a member of the current tracked_specie
|
||||||
|
if(pair.second->explicitlyStored()) {
|
||||||
|
// if the storage queue does not contain any more particles
|
||||||
|
// no new particles can be drawn
|
||||||
|
if(storage_queue_[active_storage].empty()) {
|
||||||
|
all_bins_done = all_bins_done && true;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
all_bins_done = false;
|
||||||
|
}
|
||||||
|
// take the last particle from the storage queue and extract it
|
||||||
|
particle::SerializedParticle new_sparticle =
|
||||||
|
storage_queue_[active_storage].back();
|
||||||
|
storage_queue_[active_storage].pop_back();
|
||||||
|
particle::Particle new_particle(new_sparticle, tracked_species_);
|
||||||
|
// "draw" the actual particle
|
||||||
|
new_particles.push_back(new_particle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
tmp_done = pair.second->randomIndex()->visited_all();
|
tmp_done = pair.second->randomIndex()->visited_all();
|
||||||
|
|
||||||
@@ -710,7 +752,7 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
|
|||||||
if(!tmp_done) {
|
if(!tmp_done) {
|
||||||
injector_->drawNewParticleFromDensityField(random->engine(),
|
injector_->drawNewParticleFromDensityField(random->engine(),
|
||||||
pair.second, new_particles, magnetic_field_,
|
pair.second, new_particles, magnetic_field_,
|
||||||
weight_factor, injection_time);
|
weight_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if species is not done tmp_done && ... = false
|
// if species is not done tmp_done && ... = false
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ TrackedSpecie::TrackedSpecie(
|
|||||||
std::string name,
|
std::string name,
|
||||||
double mass_kg,
|
double mass_kg,
|
||||||
double charge_C,
|
double charge_C,
|
||||||
|
bool explicitly_stored,
|
||||||
std::shared_ptr<Mover> mover,
|
std::shared_ptr<Mover> mover,
|
||||||
std::shared_ptr<Terminator> terminator,
|
std::shared_ptr<Terminator> terminator,
|
||||||
std::shared_ptr<Reflector> reflector,
|
std::shared_ptr<Reflector> reflector,
|
||||||
@@ -59,7 +60,8 @@ TrackedSpecie::TrackedSpecie(
|
|||||||
std::make_shared<PositionDistributionFromDensity>(density_for_drawing)),
|
std::make_shared<PositionDistributionFromDensity>(density_for_drawing)),
|
||||||
velocity_distribution_from_density_(
|
velocity_distribution_from_density_(
|
||||||
std::make_shared<VelocityDistributionFromDensityField>(
|
std::make_shared<VelocityDistributionFromDensityField>(
|
||||||
density_for_drawing, mass_kg)) {
|
density_for_drawing, mass_kg)),
|
||||||
|
explicitly_stored_(explicitly_stored) {
|
||||||
blitz::TinyVector<int, 5> num_bins;
|
blitz::TinyVector<int, 5> num_bins;
|
||||||
auto tmp = density_field->positionBinning()->numBins();
|
auto tmp = density_field->positionBinning()->numBins();
|
||||||
num_bins(0) = tmp(0); num_bins(1) = tmp(1); num_bins(2) = tmp(2);
|
num_bins(0) = tmp(0); num_bins(1) = tmp(1); num_bins(2) = tmp(2);
|
||||||
@@ -147,6 +149,10 @@ void TrackedSpecie::currentCollector(
|
|||||||
current_collector_ = new_collector;
|
current_collector_ = new_collector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TrackedSpecie::explicitlyStored() {
|
||||||
|
return explicitly_stored_;
|
||||||
|
}
|
||||||
|
|
||||||
BackgroundSpecie::BackgroundSpecie(
|
BackgroundSpecie::BackgroundSpecie(
|
||||||
ImplementedSpecies type,
|
ImplementedSpecies type,
|
||||||
std::string name,
|
std::string name,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ bool Terminator::reachedMaxInteractions(
|
|||||||
}
|
}
|
||||||
bool Terminator::reachedMaxTimeAlive(const particle::Particle* particle) const {
|
bool Terminator::reachedMaxTimeAlive(const particle::Particle* particle) const {
|
||||||
return particle->timeAlive() >= particle->specie()->dynamicDensityField()
|
return particle->timeAlive() >= particle->specie()->dynamicDensityField()
|
||||||
->physicalTime();
|
->timeResolution();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Terminator::leftSimulationDomain(
|
bool Terminator::leftSimulationDomain(
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ VelocityDistributionFromDensityField::VelocityDistributionFromDensityField(
|
|||||||
pitchAngleBinBorders_(density_field->pitchAngleBinning()->binBorders()),
|
pitchAngleBinBorders_(density_field->pitchAngleBinning()->binBorders()),
|
||||||
theta_distribution_(std::uniform_real_distribution<double>(0.,1.)),
|
theta_distribution_(std::uniform_real_distribution<double>(0.,1.)),
|
||||||
mass_kg_(mass_kg) {
|
mass_kg_(mass_kg) {
|
||||||
|
double maxAbsExponent = std::max(std::abs(std::log10(energyBinBorders_.front())),
|
||||||
|
std::abs(std::log10(energyBinBorders_.back())));
|
||||||
|
alpha_lower_limit = -300/maxAbsExponent;
|
||||||
|
alpha_upper_limit = 300/maxAbsExponent;
|
||||||
// necessary to include the underflow bin in the energy domain
|
// necessary to include the underflow bin in the energy domain
|
||||||
energyBinBorders_.insert(energyBinBorders_.begin(), 0);
|
energyBinBorders_.insert(energyBinBorders_.begin(), 0);
|
||||||
}
|
}
|
||||||
@@ -67,7 +71,7 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
|||||||
|
|
||||||
// draw pitch angle from DynamicDensityField
|
// draw pitch angle from DynamicDensityField
|
||||||
|
|
||||||
blitz::Array<float, 1> pitchAngleValues = density_field_->
|
blitz::Array<double, 1> pitchAngleValues = density_field_->
|
||||||
sliceTimeInBinArray(position, energy_eV);
|
sliceTimeInBinArray(position, energy_eV);
|
||||||
|
|
||||||
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
||||||
@@ -113,7 +117,7 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
|
|||||||
|
|
||||||
// draw pitch angle from DynamicDensityField
|
// draw pitch angle from DynamicDensityField
|
||||||
|
|
||||||
blitz::Array<float, 1> pitchAngleValues = density_field_->
|
blitz::Array<double, 1> pitchAngleValues = density_field_->
|
||||||
sliceTimeInBinArray(position, energy_eV);
|
sliceTimeInBinArray(position, energy_eV);
|
||||||
|
|
||||||
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
std::piecewise_constant_distribution<double> pitchAngle_dist(
|
||||||
@@ -210,8 +214,78 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
|
|||||||
const double pitch_angle_step = pitchAngleBinBorders_[index(3) + 1]
|
const double pitch_angle_step = pitchAngleBinBorders_[index(3) + 1]
|
||||||
- pitchAngleBinBorders_[index(3)];
|
- pitchAngleBinBorders_[index(3)];
|
||||||
|
|
||||||
double energy_eV = energyBinBorders_[index(4) + 1]
|
// double energy_eV = energyBinBorders_[index(4) + 1]
|
||||||
+ theta_distribution_(*engine)*energy_step;
|
// + theta_distribution_(*engine)*energy_step;
|
||||||
|
double energy_eV;
|
||||||
|
double alpha = 1;
|
||||||
|
if(index(4) == -1) {
|
||||||
|
// linear drawing inbetween E=0, N(0)=0 to E=Er and N(Er)=Nr
|
||||||
|
energy_eV = energyBinBorders_[index(4) + 2]*
|
||||||
|
std::sqrt(theta_distribution_(*engine));
|
||||||
|
// #ifdef debug
|
||||||
|
// std::stringstream out;
|
||||||
|
// out << "underflow bin.\n\tdrawn energy: " << energy_eV;
|
||||||
|
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||||
|
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||||
|
// DEBUG(out.str());
|
||||||
|
// #endif
|
||||||
|
} else {
|
||||||
|
double nl = density_field_->particleNumber(index);
|
||||||
|
double nr = density_field_->particleNumber(index +
|
||||||
|
blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||||
|
|
||||||
|
// double alpha;
|
||||||
|
// no reason for specific values, just to avoid these cases
|
||||||
|
if(nl == 0) {
|
||||||
|
alpha = 1;
|
||||||
|
} else if (nr == 0) {
|
||||||
|
alpha = -1;
|
||||||
|
} else if (nr == 0 && nl == 0) {
|
||||||
|
alpha = 0;
|
||||||
|
} else {
|
||||||
|
alpha = std::log(nr/nl)/std::log(energyBinBorders_[index(4) + 2]/
|
||||||
|
energyBinBorders_[index(4) + 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// alpha = std::abs(alpha) > 100 ?(alpha/std::abs(alpha))*100 : alpha;
|
||||||
|
alpha = std::min(std::max(alpha, alpha_lower_limit), alpha_upper_limit);
|
||||||
|
|
||||||
|
if(alpha == -1) {
|
||||||
|
energy_eV = std::pow(energyBinBorders_[index(4) + 2]
|
||||||
|
/ energyBinBorders_[index(4) + 1], theta_distribution_(*engine)) *
|
||||||
|
energyBinBorders_[index(4) + 1];
|
||||||
|
// energy_eV = (std::pow(2, theta_distribution_(*engine)) - 1)*energy_step
|
||||||
|
// + energyBinBorders_[index(4) + 1];
|
||||||
|
// #ifdef debug
|
||||||
|
// std::stringstream out;
|
||||||
|
// out << "alpha = -1\n\tdrawn energy: " << energy_eV;
|
||||||
|
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||||
|
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||||
|
// DEBUG(out.str());
|
||||||
|
// #endif
|
||||||
|
} else {
|
||||||
|
double xl_alphap1 = std::pow(energyBinBorders_[index(4) + 1], alpha + 1);
|
||||||
|
double xr_alphap1 = std::pow(energyBinBorders_[index(4) + 2], alpha + 1);
|
||||||
|
energy_eV = std::pow((xr_alphap1 - xl_alphap1)*
|
||||||
|
theta_distribution_(*engine) + xl_alphap1, 1/(alpha + 1));
|
||||||
|
// #ifdef debug
|
||||||
|
// if(std::abs(alpha) > 100) {
|
||||||
|
// std::stringstream out;
|
||||||
|
// out << "alpha: " << alpha;
|
||||||
|
// out << "\nxl_alphap1: " << xl_alphap1;
|
||||||
|
// out << "\nxr_alphap1: " << xr_alphap1;
|
||||||
|
// DEBUG(out.str());
|
||||||
|
// }
|
||||||
|
// #endif
|
||||||
|
// #ifdef debug
|
||||||
|
// std::stringstream out;
|
||||||
|
// out << "alpha = "<< alpha << "\n\tdrawn energy: " << energy_eV;
|
||||||
|
// out << "\n\tenergy value left: " << energyBinBorders_[index(4)+1];
|
||||||
|
// out << "\n\tenergy value right: " << energyBinBorders_[index(4)+2];
|
||||||
|
// DEBUG(out.str());
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double pitchAngle = pitchAngleBinBorders_[index(3)]
|
double pitchAngle = pitchAngleBinBorders_[index(3)]
|
||||||
+ theta_distribution_(*engine)*pitch_angle_step;
|
+ theta_distribution_(*engine)*pitch_angle_step;
|
||||||
@@ -221,6 +295,15 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
|
|||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
out << "pitchAngle: " << pitchAngle;
|
out << "pitchAngle: " << pitchAngle;
|
||||||
out << "\nenergy value: " << energy_eV;
|
out << "\nenergy value: " << energy_eV;
|
||||||
|
out << "\nalpha: " << alpha;
|
||||||
|
out << "\ncurrent index: " << index;
|
||||||
|
out << "\nNl: " << density_field_->particleNumber(index);
|
||||||
|
out << "\nNl: " << density_field_->particleNumber(index +
|
||||||
|
blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||||
|
out << "\nEl: " << energyBinBorders_[index(4) + 1];
|
||||||
|
out << "\nEr: " << energyBinBorders_[index(4) + 2];
|
||||||
|
out << "\nEl^(alpha+1): " << std::pow(energyBinBorders_[index(4) + 1], alpha + 1);
|
||||||
|
out << "\nEr^(alpha+1): " << std::pow(energyBinBorders_[index(4) + 2], alpha + 1);
|
||||||
// out << "\nenergy values: " << energyValues;
|
// out << "\nenergy values: " << energyValues;
|
||||||
// out << "\npitch angle values: " << pitchAngleValues;
|
// out << "\npitch angle values: " << pitchAngleValues;
|
||||||
out << "\nenergy bin borders: [ ";
|
out << "\nenergy bin borders: [ ";
|
||||||
@@ -231,6 +314,28 @@ CartesianVector VelocityDistributionFromDensityField::drawVelocity(
|
|||||||
|
|
||||||
ERROR(out.str());
|
ERROR(out.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if(std::isinf(energy_eV)) {
|
||||||
|
// std::stringstream out;
|
||||||
|
// out << "pitchAngle: " << pitchAngle;
|
||||||
|
// out << "\nenergy value: " << energy_eV;
|
||||||
|
// out << "\ncurrent index: " << index;
|
||||||
|
// out << "\nalpha: " << alpha;
|
||||||
|
// out << "\nNl: " << density_field_->particleNumber(index);
|
||||||
|
// out << "\nNl: " << density_field_->particleNumber(index +
|
||||||
|
// blitz::TinyVector<int, 5>(0,0,0,0,1));
|
||||||
|
// out << "\nEl: " << energyBinBorders_[index(4) + 1];
|
||||||
|
// out << "\nEr: " << energyBinBorders_[index(4) + 2];
|
||||||
|
// // out << "\nenergy values: " << energyValues;
|
||||||
|
// // out << "\npitch angle values: " << pitchAngleValues;
|
||||||
|
// out << "\nenergy bin borders: [ ";
|
||||||
|
// for(auto element : energyBinBorders_) {
|
||||||
|
// out << element << " ";
|
||||||
|
// }
|
||||||
|
// out << "]";
|
||||||
|
|
||||||
|
// ERROR(out.str());
|
||||||
|
// }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef debug_level2
|
#ifdef debug_level2
|
||||||
|
|||||||
Reference in New Issue
Block a user