From a835196d062f56ab653de82adf8b0b81a8a5648e Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 5 Jun 2025 17:37:06 -0400 Subject: [PATCH 1/7] psc_shock: double and mirror domain instead of reflecting --- src/psc_shock.cxx | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index ad70b0b53..c8c461597 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -148,16 +148,16 @@ Grid_t* setupGrid() { // FIXME add a check to catch mismatch between Dim and n grid points early auto domain = - Grid_t::Domain{{nx, ny, nz}, // n grid points - {len_x, len_y, len_z}, // physical lengths - {0, 0, 0}, // location of lower corner - {n_patches_x, n_patches_y, n_patches_z}}; // n patches + Grid_t::Domain{{nx, 2 * ny, nz}, // n grid points + {len_x, 2 * len_y, len_z}, // physical lengths + {0, 0, 0}, // location of lower corner + {n_patches_x, 2 * n_patches_y, n_patches_z}}; // n patches auto bc = - psc::grid::BC{{BND_FLD_PERIODIC, BND_FLD_CONDUCTING_WALL, BND_FLD_PERIODIC}, - {BND_FLD_PERIODIC, BND_FLD_CONDUCTING_WALL, BND_FLD_PERIODIC}, - {BND_PRT_PERIODIC, BND_PRT_REFLECTING, BND_PRT_PERIODIC}, - {BND_PRT_PERIODIC, BND_PRT_REFLECTING, BND_PRT_PERIODIC}}; + psc::grid::BC{{BND_FLD_PERIODIC, BND_FLD_PERIODIC, BND_FLD_PERIODIC}, + {BND_FLD_PERIODIC, BND_FLD_PERIODIC, BND_FLD_PERIODIC}, + {BND_PRT_PERIODIC, BND_PRT_PERIODIC, BND_PRT_PERIODIC}, + {BND_PRT_PERIODIC, BND_PRT_PERIODIC, BND_PRT_PERIODIC}}; auto kinds = Grid_t::Kinds(NR_KINDS); kinds[KIND_ELECTRON] = {-1.0, electron_mass, "e"}; @@ -198,12 +198,13 @@ void initializeParticles(Balance& balance, Grid_t*& grid_ptr, Mparticles& mprts) double temperature = np.kind == KIND_ION ? ion_temperature : electron_temperature; np.n = 1.0; - np.p = setup_particles.createMaxwellian( - {np.kind, - np.n, - {v_upstream_x, v_upstream_y, v_upstream_z}, - {temperature, temperature, temperature}, - np.tag}); + double vy = (crd[1] > len_y ? -1 : 1) * v_upstream_y; + np.p = + setup_particles.createMaxwellian({np.kind, + np.n, + {v_upstream_x, vy, v_upstream_z}, + {temperature, temperature, temperature}, + np.tag}); }; partitionAndSetupParticles(setup_particles, balance, grid_ptr, mprts, @@ -229,7 +230,7 @@ void initializeFields(MfieldsState& mflds) switch (component) { case EX: return e_x; case EY: return e_y; - case EZ: return e_z; + case EZ: return (coords[1] > ny ? -1 : coords[1] == ny ? 0 : 1) * e_z; case HX: return b_x; case HY: return b_y; case HZ: return b_z; From 4fbf549aac2929339dfdf09415a041eae431f479 Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 5 Jun 2025 17:38:00 -0400 Subject: [PATCH 2/7] psc_shock: -BGK fields --- src/psc_shock.cxx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index c8c461597..5883c03ff 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -25,7 +25,6 @@ using PscConfig = PscConfig1vbecDouble; // ---------------------------------------------------------------------- -using BgkMfields = PscConfig::Mfields; using MfieldsState = PscConfig::MfieldsState; using Mparticles = PscConfig::Mparticles; using Balance = PscConfig::Balance; @@ -258,9 +257,6 @@ static void run(int argc, char** argv) auto& grid = *grid_ptr; MfieldsState mflds{grid}; Mparticles mprts{grid}; - BgkMfields phi{grid, 1, mflds.ibn()}; - BgkMfields gradPhi{grid, 3, mflds.ibn()}; - BgkMfields divGradPhi{grid, 1, mflds.ibn()}; // ---------------------------------------------------------------------- // Set up various objects needed to run this case From 47c7e78f87f99794b34ecd5339657dced895bf7a Mon Sep 17 00:00:00 2001 From: James McClung Date: Thu, 5 Jun 2025 17:40:16 -0400 Subject: [PATCH 3/7] psc_shock: reenable proper checks --- src/psc_shock.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index 5883c03ff..08e9abb20 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -276,8 +276,7 @@ static void run(int argc, char** argv) // -- Checks ChecksParams checks_params{}; checks_params.gauss.check_interval = out_interval; - // checks_params.gauss.dump_always = true; - checks_params.gauss.err_threshold = 1e-5; + checks_params.continuity.check_interval = out_interval; Checks checks{grid, MPI_COMM_WORLD, checks_params}; From ea0c83a984a2c4c8725cf4ce3a39a01ab3c68dd0 Mon Sep 17 00:00:00 2001 From: James McClung Date: Wed, 11 Jun 2025 13:35:20 -0400 Subject: [PATCH 4/7] psc_shock: fix mirrored ez --- src/psc_shock.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index 08e9abb20..08ec15345 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -229,7 +229,7 @@ void initializeFields(MfieldsState& mflds) switch (component) { case EX: return e_x; case EY: return e_y; - case EZ: return (coords[1] > ny ? -1 : coords[1] == ny ? 0 : 1) * e_z; + case EZ: return (coords[1] > len_y ? -1 : 1) * e_z; case HX: return b_x; case HY: return b_y; case HZ: return b_z; From b76c7e6697b90363b7f28a9e1d85045de724b812 Mon Sep 17 00:00:00 2001 From: James McClung Date: Wed, 11 Jun 2025 13:38:54 -0400 Subject: [PATCH 5/7] psc_shock: +mirrored_domain param --- src/psc_shock.cxx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index 08ec15345..f05285794 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -72,6 +72,8 @@ double len_z; int out_interval; +bool mirrored_domain; + } // namespace // ====================================================================== @@ -130,6 +132,8 @@ void setupParameters(int argc, char** argv) int n_writes = parsedParams.getOrDefault("n_writes", 100); out_interval = psc_params.nmax / n_writes; + mirrored_domain = parsedParams.getOrDefault("mirrored_domain", false); + std::ifstream src(path_to_params, std::ios::binary); std::ofstream dst("params_record.txt", std::ios::binary); dst << src.rdbuf(); From 80160225df5853a0bb37425710822d08bde498b8 Mon Sep 17 00:00:00 2001 From: James McClung Date: Wed, 11 Jun 2025 13:42:08 -0400 Subject: [PATCH 6/7] psc_shock: use mirrored_domain param --- src/psc_shock.cxx | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index f05285794..d51fe5d41 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -150,17 +150,19 @@ void setupParameters(int argc, char** argv) Grid_t* setupGrid() { // FIXME add a check to catch mismatch between Dim and n grid points early - auto domain = - Grid_t::Domain{{nx, 2 * ny, nz}, // n grid points - {len_x, 2 * len_y, len_z}, // physical lengths - {0, 0, 0}, // location of lower corner - {n_patches_x, 2 * n_patches_y, n_patches_z}}; // n patches - - auto bc = - psc::grid::BC{{BND_FLD_PERIODIC, BND_FLD_PERIODIC, BND_FLD_PERIODIC}, - {BND_FLD_PERIODIC, BND_FLD_PERIODIC, BND_FLD_PERIODIC}, - {BND_PRT_PERIODIC, BND_PRT_PERIODIC, BND_PRT_PERIODIC}, - {BND_PRT_PERIODIC, BND_PRT_PERIODIC, BND_PRT_PERIODIC}}; + int y_mult = mirrored_domain ? 2 : 1; + auto domain = Grid_t::Domain{ + {nx, y_mult * ny, nz}, // n grid points + {len_x, y_mult * len_y, len_z}, // physical lengths + {0, 0, 0}, // location of lower corner + {n_patches_x, y_mult * n_patches_y, n_patches_z}}; // n patches + + auto BND_FLD_Y = mirrored_domain ? BND_FLD_PERIODIC : BND_FLD_CONDUCTING_WALL; + auto BND_PRT_Y = mirrored_domain ? BND_PRT_PERIODIC : BND_PRT_REFLECTING; + auto bc = psc::grid::BC{{BND_FLD_PERIODIC, BND_FLD_Y, BND_FLD_PERIODIC}, + {BND_FLD_PERIODIC, BND_FLD_Y, BND_FLD_PERIODIC}, + {BND_PRT_PERIODIC, BND_PRT_Y, BND_PRT_PERIODIC}, + {BND_PRT_PERIODIC, BND_PRT_Y, BND_PRT_PERIODIC}}; auto kinds = Grid_t::Kinds(NR_KINDS); kinds[KIND_ELECTRON] = {-1.0, electron_mass, "e"}; @@ -201,13 +203,13 @@ void initializeParticles(Balance& balance, Grid_t*& grid_ptr, Mparticles& mprts) double temperature = np.kind == KIND_ION ? ion_temperature : electron_temperature; np.n = 1.0; - double vy = (crd[1] > len_y ? -1 : 1) * v_upstream_y; - np.p = - setup_particles.createMaxwellian({np.kind, - np.n, - {v_upstream_x, vy, v_upstream_z}, - {temperature, temperature, temperature}, - np.tag}); + double vy_coef = mirrored_domain && crd[1] > len_y ? -1 : 1; + np.p = setup_particles.createMaxwellian( + {np.kind, + np.n, + {v_upstream_x, vy_coef * v_upstream_y, v_upstream_z}, + {temperature, temperature, temperature}, + np.tag}); }; partitionAndSetupParticles(setup_particles, balance, grid_ptr, mprts, @@ -230,10 +232,11 @@ void fillGhosts(MF& mfld, int compBegin, int compEnd) void initializeFields(MfieldsState& mflds) { setupFields(mflds, [&](int component, double coords[3]) { + double e_coef = mirrored_domain && coords[1] > len_y ? -1 : 1; switch (component) { - case EX: return e_x; - case EY: return e_y; - case EZ: return (coords[1] > len_y ? -1 : 1) * e_z; + case EX: return e_coef * e_x; + case EY: return e_coef * e_y; + case EZ: return e_coef * e_z; case HX: return b_x; case HY: return b_y; case HZ: return b_z; From f77176a4f248daa08ac23eda7b5448aa84b411a5 Mon Sep 17 00:00:00 2001 From: James McClung Date: Wed, 11 Jun 2025 13:46:45 -0400 Subject: [PATCH 7/7] psc_shock: rename to mirror_domain --- src/psc_shock.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/psc_shock.cxx b/src/psc_shock.cxx index d51fe5d41..0ccc42478 100644 --- a/src/psc_shock.cxx +++ b/src/psc_shock.cxx @@ -72,7 +72,7 @@ double len_z; int out_interval; -bool mirrored_domain; +bool mirror_domain; } // namespace @@ -132,7 +132,7 @@ void setupParameters(int argc, char** argv) int n_writes = parsedParams.getOrDefault("n_writes", 100); out_interval = psc_params.nmax / n_writes; - mirrored_domain = parsedParams.getOrDefault("mirrored_domain", false); + mirror_domain = parsedParams.getOrDefault("mirror_domain", false); std::ifstream src(path_to_params, std::ios::binary); std::ofstream dst("params_record.txt", std::ios::binary); @@ -150,15 +150,15 @@ void setupParameters(int argc, char** argv) Grid_t* setupGrid() { // FIXME add a check to catch mismatch between Dim and n grid points early - int y_mult = mirrored_domain ? 2 : 1; + int y_mult = mirror_domain ? 2 : 1; auto domain = Grid_t::Domain{ {nx, y_mult * ny, nz}, // n grid points {len_x, y_mult * len_y, len_z}, // physical lengths {0, 0, 0}, // location of lower corner {n_patches_x, y_mult * n_patches_y, n_patches_z}}; // n patches - auto BND_FLD_Y = mirrored_domain ? BND_FLD_PERIODIC : BND_FLD_CONDUCTING_WALL; - auto BND_PRT_Y = mirrored_domain ? BND_PRT_PERIODIC : BND_PRT_REFLECTING; + auto BND_FLD_Y = mirror_domain ? BND_FLD_PERIODIC : BND_FLD_CONDUCTING_WALL; + auto BND_PRT_Y = mirror_domain ? BND_PRT_PERIODIC : BND_PRT_REFLECTING; auto bc = psc::grid::BC{{BND_FLD_PERIODIC, BND_FLD_Y, BND_FLD_PERIODIC}, {BND_FLD_PERIODIC, BND_FLD_Y, BND_FLD_PERIODIC}, {BND_PRT_PERIODIC, BND_PRT_Y, BND_PRT_PERIODIC}, @@ -203,7 +203,7 @@ void initializeParticles(Balance& balance, Grid_t*& grid_ptr, Mparticles& mprts) double temperature = np.kind == KIND_ION ? ion_temperature : electron_temperature; np.n = 1.0; - double vy_coef = mirrored_domain && crd[1] > len_y ? -1 : 1; + double vy_coef = mirror_domain && crd[1] > len_y ? -1 : 1; np.p = setup_particles.createMaxwellian( {np.kind, np.n, @@ -232,7 +232,7 @@ void fillGhosts(MF& mfld, int compBegin, int compEnd) void initializeFields(MfieldsState& mflds) { setupFields(mflds, [&](int component, double coords[3]) { - double e_coef = mirrored_domain && coords[1] > len_y ? -1 : 1; + double e_coef = mirror_domain && coords[1] > len_y ? -1 : 1; switch (component) { case EX: return e_coef * e_x; case EY: return e_coef * e_y;