diff --git a/include/constants/sim_constants.h b/include/constants/sim_constants.h index 4f7277a..020f602 100755 --- a/include/constants/sim_constants.h +++ b/include/constants/sim_constants.h @@ -10,10 +10,11 @@ static const double minimal_macroscopic_cross_section = std::numeric_limits::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 diff --git a/src/IO/hdf5_reader.cpp b/src/IO/hdf5_reader.cpp index c404c33..c5c7afa 100755 --- a/src/IO/hdf5_reader.cpp +++ b/src/IO/hdf5_reader.cpp @@ -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))); diff --git a/src/IO/restart.cpp b/src/IO/restart.cpp index 2fa48d7..ce1cc55 100644 --- a/src/IO/restart.cpp +++ b/src/IO/restart.cpp @@ -113,6 +113,11 @@ void Restart::restartDrawingDensityField(DynamicDensityField* field, std::string blitz::Array deleted_particles = reader_.readD4LongInt(path_to_data); field->restartDeletedParticlesArray(deleted_particles); } + + // set the density distribution and calculate the density + { + field->setDensityDistribution(); + } return; } diff --git a/src/generators/injector_generator.cpp b/src/generators/injector_generator.cpp index 382f3ca..d9ee868 100755 --- a/src/generators/injector_generator.cpp +++ b/src/generators/injector_generator.cpp @@ -34,8 +34,9 @@ std::shared_ptr 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); } diff --git a/src/generators/restart_generator.cpp b/src/generators/restart_generator.cpp index 77582e8..5f6e97a 100644 --- a/src/generators/restart_generator.cpp +++ b/src/generators/restart_generator.cpp @@ -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; diff --git a/src/poisson_solver/poisson_solver.cpp b/src/poisson_solver/poisson_solver.cpp index 5d33727..ce553a7 100755 --- a/src/poisson_solver/poisson_solver.cpp +++ b/src/poisson_solver/poisson_solver.cpp @@ -364,10 +364,18 @@ void PoissonSolver::setPotential(blitz::Array& 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); } } } diff --git a/src/simulation/density_field.cpp b/src/simulation/density_field.cpp index eb2cbe8..8164a26 100755 --- a/src/simulation/density_field.cpp +++ b/src/simulation/density_field.cpp @@ -248,6 +248,8 @@ blitz::TinyVector DynamicDensityField::drawPositionAndEnergy( density_in_random_cell = density(CylinderCoordinate( blitz::TinyVector (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 position_bin = @@ -343,7 +345,7 @@ void DynamicDensityField::restartTimeInBin(blitz::Array 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()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/simulation/energy_distribution.cpp b/src/simulation/energy_distribution.cpp index 2335264..34fb52b 100755 --- a/src/simulation/energy_distribution.cpp +++ b/src/simulation/energy_distribution.cpp @@ -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) { diff --git a/src/simulation/simulation.cpp b/src/simulation/simulation.cpp index ce99555..a416d54 100755 --- a/src/simulation/simulation.cpp +++ b/src/simulation/simulation.cpp @@ -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 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();