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;
static const double random_lower_limit = 1E-15;
static const double compare_epsilon = 1E-10;
// maximum length for the string produced by the "<<"-operator
// of the mt19973 engine. ("empirical" value, might be too low,
// or depend on the system)
static const size_t engine_string_length_max = 6730;
// engine state of mt19973 engine consists of 624 numbers (output seems to write 625)
// (assumed to be constant); each number is represented by a 32 bit word (2^32 = 4294967296)
// i.e. each number needs at most 10 digits; the numbers are seperated by whitespaces
// -> 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
+3 -2
View File
@@ -214,8 +214,9 @@ std::stringstream Hdf5Reader::readEngineString(std::string path) {
size_t size = H5Tget_size(dtype);
if(size != SimConstants::engine_string_length_max) {
ERROR("Size of the string is not the required size of 6730, size of string: "
+ std::to_string(size));
ERROR("Size of the string is not the required size of " +
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)));
+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);
field->restartDeletedParticlesArray(deleted_particles);
}
// set the density distribution and calculate the density
{
field->setDensityDistribution();
}
return;
}
+2 -1
View File
@@ -34,8 +34,9 @@ std::shared_ptr<Injector> buildInjector(
json_path_append(path_to_injector, {"CreatedSpecies", std::string(key),
"CreationVelocityDistribution"}));
// missing a check if the value is positive
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);
}
+3 -2
View File
@@ -7,11 +7,12 @@ namespace generator {
DEBUG_LEVEL_3("Build Restart.");
bool do_restart = json_bool(json_object_by_path(object, {"Do"}));
if (!do_restart) {
DEBUG_LEVEL_3("No Restart desired");
DEBUG_LEVEL_0("No Restart desired.");
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);
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();
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 j = potential_.lbound(1); j <= potential_.ubound(1); ++j) {
for(int k = potential_.lbound(2); k <= potential_.ubound(2); ++k) {
potential_(i,j,k).value = potential(i,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(
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);
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";
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(
@@ -355,7 +357,7 @@ void DynamicDensityField::restartDeletedParticlesArray(
out << " for deleted_particles array";
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) {
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) {
+14 -1
View File
@@ -260,11 +260,21 @@ void Simulation::processEvents(int events, int density_events, int cpu_syncs) {
} else {
DEBUG_LEVEL_2("Current density event: " +
std::to_string(current_density_event));
std::to_string(current_density_event));
//maybe use a different event name?
SimulationTimer::eventStartPoint(std::string("DensityParticleInjection"));
new_particles = determineInjectedDensityParticles(random_.get(), density_events, current_density_event);
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;
}
if(new_particles.empty())
@@ -442,6 +452,9 @@ std::vector<particle::Particle> Simulation::determineInjectedDensityParticles(
}
const double injection_time = timer_->time() - timer_->getDeltaT();
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
const double particleNumberDensity =
pair.second->densityForDrawing()->particleNumber();