Bugfixes;

Restarts now reproduce longer Sims
This commit is contained in:
2024-09-11 14:56:14 +02:00
parent 75bb2e4d85
commit b4cbd8c44c
9 changed files with 53 additions and 14 deletions
+5 -4
View File
@@ -10,10 +10,11 @@ static const double minimal_macroscopic_cross_section =
std::numeric_limits<double>::min() * 1E5; std::numeric_limits<double>::min() * 1E5;
static const double random_lower_limit = 1E-15; static const double random_lower_limit = 1E-15;
static const double compare_epsilon = 1E-10; static const double compare_epsilon = 1E-10;
// maximum length for the string produced by the "<<"-operator // engine state of mt19973 engine consists of 624 numbers (output seems to write 625)
// of the mt19973 engine. ("empirical" value, might be too low, // (assumed to be constant); each number is represented by a 32 bit word (2^32 = 4294967296)
// or depend on the system) // i.e. each number needs at most 10 digits; the numbers are seperated by whitespaces
static const size_t engine_string_length_max = 6730; // -> max length = 10*625 + 624 = 6874 (add one more digit to be on the safe side)
static const size_t engine_string_length_max = 6875;
} // namespace SimConstants } // namespace SimConstants
+3 -2
View File
@@ -214,8 +214,9 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) {
size_t size = H5Tget_size(dtype); size_t size = H5Tget_size(dtype);
if(size != SimConstants::engine_string_length_max) { if(size != SimConstants::engine_string_length_max) {
ERROR("Size of the string is not the required size of 6730, size of string: " ERROR("Size of the string is not the required size of " +
+ std::to_string(size)); std::to_string(SimConstants::engine_string_length_max) +
", size of string: " + std::to_string(size));
} }
DEBUG_LEVEL_3("RestartInfo: " + std::to_string(H5Tdetect_class(dtype, H5T_STRING))); DEBUG_LEVEL_3("RestartInfo: " + std::to_string(H5Tdetect_class(dtype, H5T_STRING)));
+5
View File
@@ -113,6 +113,11 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string
blitz::Array<long int, 4> deleted_particles = reader_.readD4LongInt(path_to_data); blitz::Array<long int, 4> deleted_particles = reader_.readD4LongInt(path_to_data);
field->restartDeletedParticlesArray(deleted_particles); field->restartDeletedParticlesArray(deleted_particles);
} }
// set the density distribution and calculate the density
{
field->setDensityDistribution();
}
return; return;
} }
+2 -1
View File
@@ -34,8 +34,9 @@ std::shared_ptr<Injector> buildInjector(
json_path_append(path_to_injector, {"CreatedSpecies", std::string(key), json_path_append(path_to_injector, {"CreatedSpecies", std::string(key),
"CreationVelocityDistribution"})); "CreationVelocityDistribution"}));
// missing a check if the value is positive
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. " +
specie_name + " multiplicity: " + std::to_string(info.multiplicity));
injector_infos.push_back(info); injector_infos.push_back(info);
} }
+3 -2
View File
@@ -7,11 +7,12 @@ namespace generator {
DEBUG_LEVEL_3("Build Restart."); DEBUG_LEVEL_3("Build Restart.");
bool do_restart = json_bool(json_object_by_path(object, {"Do"})); bool do_restart = json_bool(json_object_by_path(object, {"Do"}));
if (!do_restart) { if (!do_restart) {
DEBUG_LEVEL_3("No Restart desired"); DEBUG_LEVEL_0("No Restart desired.");
return Restart(false, "", ""); return Restart(false, "", "");
} }
std::string filepath = readAbsoluteFilename(json_object_by_path(object, {"PathToH5"})); std::string filepath = readAbsoluteFilename(json_object_by_path(object, {"PathToH5"}))
+ ".h5";
DEBUG_LEVEL_3("Restart: file path:" + filepath); DEBUG_LEVEL_3("Restart: file path:" + filepath);
std::string identifier; std::string identifier;
+9 -1
View File
@@ -364,10 +364,18 @@ void PoissonSolver::setPotential(blitz::Array<double, 3>& potential) {
out << ". But expected a size of " << potential_.length(); out << ". But expected a size of " << potential_.length();
ERROR(out.str()); ERROR(out.str());
} }
// necessary since it's not guaranteed (or even likely) that both arrays
// are indexed the same (i.e. potential_ is most likely starting from -1,
// while the parameter array is most likely starting from 0)
const int i_offset = potential.lbound(0) - potential_.lbound(0);
const int j_offset = potential.lbound(1) - potential_.lbound(1);
const int k_offset = potential.lbound(2) - potential_.lbound(2);
for(int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) { for(int i = potential_.lbound(0); i <= potential_.ubound(0); ++i) {
for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) { for(int j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
for(int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) { for(int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) {
potential_(i,j,k).value = potential(i,j,k); potential_(i,j,k).value = potential(i + i_offset,j + j_offset,k + k_offset);
} }
} }
} }
+4 -2
View File
@@ -248,6 +248,8 @@ blitz::TinyVector<double, 4> DynamicDensityField::drawPositionAndEnergy(
density_in_random_cell = density(CylinderCoordinate( density_in_random_cell = density(CylinderCoordinate(
blitz::TinyVector<double, 3> (random_r, random_phi, random_z))); blitz::TinyVector<double, 3> (random_r, random_phi, random_z)));
DEBUG_LEVEL_3("Density in drawn cell: " + std::to_string(density_in_random_cell));
DEBUG_LEVEL_3("drawn density: " + std::to_string(random_n));
} while (random_n >= density_in_random_cell); } while (random_n >= density_in_random_cell);
const blitz::TinyVector<int, 3> position_bin = const blitz::TinyVector<int, 3> position_bin =
@@ -343,7 +345,7 @@ void DynamicDensityField::restartTimeInBin(blitz::Array<double, 4> time_in_bin)
out << " for time_in_bin array"; out << " for time_in_bin array";
ERROR(out.str()); ERROR(out.str());
} }
time_in_bin_s_ = time_in_bin.copy(); time_in_bin_s_ = time_in_bin.copy().reindex(time_in_bin_s_.lbound());
} }
void DynamicDensityField::restartDeletedParticlesArray( void DynamicDensityField::restartDeletedParticlesArray(
@@ -355,7 +357,7 @@ void DynamicDensityField::restartDeletedParticlesArray(
out << " for deleted_particles array"; out << " for deleted_particles array";
ERROR(out.str()); ERROR(out.str());
} }
deleted_particles_ = deleted_particles.copy(); deleted_particles_ = deleted_particles.copy().reindex(deleted_particles_.lbound());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
+8 -1
View File
@@ -37,7 +37,14 @@ MaxwellBoltzmann::MaxwellBoltzmann(double temperature_K)
} }
double MaxwellBoltzmann::rollEnergy(std::mt19937* engine) { double MaxwellBoltzmann::rollEnergy(std::mt19937* engine) {
return distribution_(*engine); double value = distribution_(*engine);
// this makes (the test case) reproduceable through restart
// but it does impact the efficiency of the drawing (simple test
// resultet in about an increase of 50% for the function call)
// however, i think that that time increse is almost negligible
// compared to the rest of the operations in the simulation
distribution_.reset();
return value;
} }
Constant::Constant(double constant_eV) : constant_eV_(constant_eV) { Constant::Constant(double constant_eV) : constant_eV_(constant_eV) {
+13
View File
@@ -265,6 +265,16 @@ void Simulation::processEvents(int events, int density_events, int cpu_syncs) {
SimulationTimer::eventStartPoint(std::string("DensityParticleInjection")); SimulationTimer::eventStartPoint(std::string("DensityParticleInjection"));
new_particles = determineInjectedDensityParticles(random_.get(), density_events, current_density_event); new_particles = determineInjectedDensityParticles(random_.get(), density_events, current_density_event);
SimulationTimer::eventStopPoint(std::string("DensityParticleInjection")); SimulationTimer::eventStopPoint(std::string("DensityParticleInjection"));
#if defined debug_level3
for(auto& particle : new_particles) {
std::stringstream output_ss;
output_ss << particle.specie()->name() << " with velocity (cart): ";
output_ss << particle.velocity().cartesianEntries();
output_ss << " and position (cart)";
output_ss << particle.position().cartesianEntries();
DEBUG_LEVEL_3(output_ss.str());
}
#endif
current_density_event += 1; current_density_event += 1;
} }
if(new_particles.empty()) if(new_particles.empty())
@@ -442,6 +452,9 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
} }
const double injection_time = timer_->time() - timer_->getDeltaT(); const double injection_time = timer_->time() - timer_->getDeltaT();
for(auto& pair: tracked_species_) { for(auto& pair: tracked_species_) {
// not ideal, gets recalculated each time a new particle is drawn from the density,
// which does not change except after a timestep, but think the rejection method is
// much more time consuming anyways... might optimize in the future
// particle number of the denstiy, i.e. the integral over the density // particle number of the denstiy, i.e. the integral over the density
const double particleNumberDensity = const double particleNumberDensity =
pair.second->densityForDrawing()->particleNumber(); pair.second->densityForDrawing()->particleNumber();