From 3028d2b52587185d710c9973ee32097063c094e6 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 9 Feb 2026 17:41:15 -0500 Subject: [PATCH 1/3] random pool is now std::optional --- pgens/accretion/pgen.hpp | 4 ++-- pgens/reconnection/pgen.hpp | 4 ++-- pgens/turbulence/pgen.hpp | 2 +- src/archetypes/particle_injector.h | 4 ++-- src/archetypes/utils.h | 4 ++-- src/engines/srpic.hpp | 2 +- src/framework/domain/domain.h | 17 ++++++++++++++--- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/pgens/accretion/pgen.hpp b/pgens/accretion/pgen.hpp index 2266f4e1..42690f04 100644 --- a/pgens/accretion/pgen.hpp +++ b/pgens/accretion/pgen.hpp @@ -231,7 +231,7 @@ namespace user { inline void InitPrtls(Domain& local_domain) { const auto energy_dist = arch::Maxwellian(local_domain.mesh.metric, - local_domain.random_pool, + local_domain.random_pool(), temperature); const auto spatial_dist = PointDistribution(xi_min, xi_max, @@ -252,7 +252,7 @@ namespace user { void CustomPostStep(std::size_t, long double time, Domain& local_domain) { const auto energy_dist = arch::Maxwellian(local_domain.mesh.metric, - local_domain.random_pool, + local_domain.random_pool(), temperature); const auto spatial_dist = PointDistribution(xi_min, xi_max, diff --git a/pgens/reconnection/pgen.hpp b/pgens/reconnection/pgen.hpp index b446c11f..d152b578 100644 --- a/pgens/reconnection/pgen.hpp +++ b/pgens/reconnection/pgen.hpp @@ -212,7 +212,7 @@ namespace user { // current layer auto edist_cs = arch::Maxwellian(local_domain.mesh.metric, - local_domain.random_pool, + local_domain.random_pool(), cs_temperature, { ZERO, ZERO, cs_drift_u }); const auto sdist_cs = CurrentLayer(local_domain.mesh.metric, @@ -239,7 +239,7 @@ namespace user { } const auto energy_dist = arch::Maxwellian(domain.mesh.metric, - domain.random_pool, + domain.random_pool(), bg_temperature); const auto dx = domain.mesh.metric.template sqrt_h_<1, 1>({}); diff --git a/pgens/turbulence/pgen.hpp b/pgens/turbulence/pgen.hpp index e8001b09..dce59f02 100644 --- a/pgens/turbulence/pgen.hpp +++ b/pgens/turbulence/pgen.hpp @@ -398,7 +398,7 @@ namespace user { // particle escape (resample velocities) const auto energy_dist = arch::Maxwellian(domain.mesh.metric, - domain.random_pool, + domain.random_pool(), temperature); for (const auto& sp : { 0, 1 }) { if (domain.species[sp].npld_r() > 1) { diff --git a/src/archetypes/particle_injector.h b/src/archetypes/particle_injector.h index 79743ce6..24af5996 100644 --- a/src/archetypes/particle_injector.h +++ b/src/archetypes/particle_injector.h @@ -254,7 +254,7 @@ namespace arch { energy_dists.first, energy_dists.second, ONE / params.template get("scales.V0"), - domain.random_pool)); + domain.random_pool())); domain.species[species.first - 1].set_npart( domain.species[species.first - 1].npart() + nparticles); domain.species[species.second - 1].set_npart( @@ -372,7 +372,7 @@ namespace arch { energy_dists.second, spatial_dist, ONE / params.template get("scales.V0"), - domain.random_pool); + domain.random_pool()); Kokkos::parallel_for("InjectNonUniformNumberDensity", cell_range, injector_kernel); diff --git a/src/archetypes/utils.h b/src/archetypes/utils.h index 3447558f..b1a29cb7 100644 --- a/src/archetypes/utils.h +++ b/src/archetypes/utils.h @@ -53,11 +53,11 @@ namespace arch { const auto temperature_2 = temperatures.second / mass_2; const auto maxwellian_1 = arch::Maxwellian(domain.mesh.metric, - domain.random_pool, + domain.random_pool(), temperature_1, drift_four_vels.first); const auto maxwellian_2 = arch::Maxwellian(domain.mesh.metric, - domain.random_pool, + domain.random_pool(), temperature_2, drift_four_vels.second); diff --git a/src/engines/srpic.hpp b/src/engines/srpic.hpp index 9a4ec31f..0dad75e9 100644 --- a/src/engines/srpic.hpp +++ b/src/engines/srpic.hpp @@ -1291,7 +1291,7 @@ namespace ntt { } const auto maxwellian = arch::Maxwellian { domain.mesh.metric, - domain.random_pool, + domain.random_pool(), temp }; if (dim == in::x1) { diff --git a/src/framework/domain/domain.h b/src/framework/domain/domain.h index b6cbb985..8338fc51 100644 --- a/src/framework/domain/domain.h +++ b/src/framework/domain/domain.h @@ -53,6 +53,7 @@ #include #include +#include #include #include @@ -65,7 +66,6 @@ namespace ntt { Mesh mesh; Fields fields; std::vector> species; - random_number_pool_t random_pool; /** * @brief constructor for "empty" allocation of non-local domain placeholders @@ -81,7 +81,6 @@ namespace ntt { : mesh { ncells, extent, metric_params } , fields {} , species {} - , random_pool { constant::RandomSeed } , m_index { index } , m_offset_ndomains { offset_ndomains } , m_offset_ncells { offset_ncells } {} @@ -96,7 +95,8 @@ namespace ntt { : mesh { ncells, extent, metric_params } , fields { ncells } , species { species_params.begin(), species_params.end() } - , random_pool { constant::RandomSeed + static_cast(index) } + , m_random_number_pool { constant::RandomSeed + + static_cast(index) } , m_index { index } , m_offset_ndomains { offset_ndomains } , m_offset_ncells { offset_ncells } {} @@ -145,6 +145,14 @@ namespace ntt { return fields.memory_footprint() == 0 and sp_footprint == 0; } + [[nodiscard]] + auto random_pool() -> random_number_pool_t& { + raise::ErrorIf(not m_random_number_pool.has_value(), + "random_pool() called on a placeholder domain", + HERE); + return m_random_number_pool.value(); + } + /* setters -------------------------------------------------------------- */ auto set_neighbor_idx(const dir::direction_t& dir, unsigned int idx) -> void { m_neighbor_idx[dir] = idx; @@ -161,6 +169,9 @@ namespace ntt { dir::map_t m_neighbor_idx; // MPI rank of the domain (used only when MPI enabled) int m_mpi_rank; + + // random number pool for the domain + std::optional m_random_number_pool; }; template From fe3fea11b241b157d3efb89bf906956ed6ddbaf2 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 9 Feb 2026 17:47:38 -0500 Subject: [PATCH 2/3] CPUTEST From 09b177b82dddcd036ff4f86ba5a44e5e3add55c2 Mon Sep 17 00:00:00 2001 From: haykh Date: Mon, 9 Feb 2026 17:54:34 -0500 Subject: [PATCH 3/3] bump cmake + order of variables in domain constructor --- CMakeLists.txt | 2 +- src/framework/domain/domain.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbe64dd8..fad95b10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(PROJECT_NAME entity) project( ${PROJECT_NAME} - VERSION 1.3.2 + VERSION 1.3.3 LANGUAGES CXX C) add_compile_options("-D ENTITY_VERSION=\"${PROJECT_VERSION}\"") set(hash_cmd "git diff --quiet src/ && echo $(git rev-parse HEAD) ") diff --git a/src/framework/domain/domain.h b/src/framework/domain/domain.h index 8338fc51..ca59b74e 100644 --- a/src/framework/domain/domain.h +++ b/src/framework/domain/domain.h @@ -95,11 +95,11 @@ namespace ntt { : mesh { ncells, extent, metric_params } , fields { ncells } , species { species_params.begin(), species_params.end() } - , m_random_number_pool { constant::RandomSeed + - static_cast(index) } , m_index { index } , m_offset_ndomains { offset_ndomains } - , m_offset_ncells { offset_ncells } {} + , m_offset_ncells { offset_ncells } + , m_random_number_pool { constant::RandomSeed + + static_cast(index) } {} #if defined(MPI_ENABLED) [[nodiscard]]