From ba7b32ea92062794880c4812dcc71942309ecc34 Mon Sep 17 00:00:00 2001 From: David Grote Date: Mon, 11 Nov 2024 15:29:18 -0800 Subject: [PATCH 1/5] Add staggering shift when calculating field location --- Source/BoundaryConditions/PEC_Insulator.cpp | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Source/BoundaryConditions/PEC_Insulator.cpp b/Source/BoundaryConditions/PEC_Insulator.cpp index df411f8e908..8dbd87668fa 100644 --- a/Source/BoundaryConditions/PEC_Insulator.cpp +++ b/Source/BoundaryConditions/PEC_Insulator.cpp @@ -426,10 +426,13 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::ignore_unused(j, k); amrex::IntVect const iv(AMREX_D_DECL(i, j, k)); - amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_x.x + (iv[0] - lo_x[0])*dx[0] : 0._rt); - amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_x.y + (iv[1] - lo_x[1])*dx[1] : 0._rt); + amrex::Real const shiftx = (Fx_nodal[0] ? 0._rt : 0.5_rt); + amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_x.x + (iv[0] - lo_x[0] + shiftx)*dx[0] : 0._rt); + amrex::Real const shifty = (Fx_nodal[1] ? 0._rt : 0.5_rt); + amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_x.y + (iv[1] - lo_x[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) - amrex::Real const z = xyzmin_x.z + (iv[WARPX_ZINDEX] - lo_x[WARPX_ZINDEX])*dx[2]; + amrex::Real const shiftz = (Fx_nodal[2] ? 0._rt : 0.5_rt); + amrex::Real const z = xyzmin_x.z + (iv[WARPX_ZINDEX] - lo_x[WARPX_ZINDEX] + shiftz)*dx[2]; #endif amrex::IntVect is_insulator_lo; @@ -471,10 +474,13 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::ignore_unused(j, k); amrex::IntVect const iv(AMREX_D_DECL(i, j, k)); - amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_y.x + (iv[0] - lo_y[0])*dx[0] : 0._rt); - amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_y.y + (iv[1] - lo_y[1])*dx[1] : 0._rt); + amrex::Real const shiftx = (Fy_nodal[0] ? 0._rt : 0.5_rt); + amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_y.x + (iv[0] - lo_y[0] + shiftx)*dx[0] : 0._rt); + amrex::Real const shifty = (Fy_nodal[1] ? 0._rt : 0.5_rt); + amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_y.y + (iv[1] - lo_y[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) - amrex::Real const z = xyzmin_y.z + (iv[WARPX_ZINDEX] - lo_y[WARPX_ZINDEX])*dx[2]; + amrex::Real const shiftz = (Fy_nodal[2] ? 0._rt : 0.5_rt); + amrex::Real const z = xyzmin_y.z + (iv[WARPX_ZINDEX] - lo_y[WARPX_ZINDEX] + shiftz)*dx[2]; #endif amrex::IntVect is_insulator_lo; @@ -516,10 +522,13 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::ignore_unused(j, k); amrex::IntVect const iv(AMREX_D_DECL(i, j, k)); - amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_z.x + (iv[0] - lo_z[0])*dx[0] : 0._rt); - amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_z.y + (iv[1] - lo_z[1])*dx[1] : 0._rt); + amrex::Real const shiftx = (Fz_nodal[0] ? 0._rt : 0.5_rt); + amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_z.x + (iv[0] - lo_z[0] + shiftx)*dx[0] : 0._rt); + amrex::Real const shifty = (Fz_nodal[1] ? 0._rt : 0.5_rt); + amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_z.y + (iv[1] - lo_z[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) - amrex::Real const z = xyzmin_z.z + (iv[WARPX_ZINDEX] - lo_z[WARPX_ZINDEX])*dx[2]; + amrex::Real const shiftz = (Fz_nodal[2] ? 0._rt : 0.5_rt); + amrex::Real const z = xyzmin_z.z + (iv[WARPX_ZINDEX] - lo_z[WARPX_ZINDEX] + shiftz)*dx[2]; #endif amrex::IntVect is_insulator_lo; From c560a95e6be10fd517085001513128d7622798c5 Mon Sep 17 00:00:00 2001 From: David Grote Date: Mon, 11 Nov 2024 16:30:44 -0800 Subject: [PATCH 2/5] Make BC name consistent with the documentation --- Examples/Tests/pec/inputs_test_2d_pec_field_insulator | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Tests/pec/inputs_test_2d_pec_field_insulator b/Examples/Tests/pec/inputs_test_2d_pec_field_insulator index 68a8df1b600..912b77efcf6 100644 --- a/Examples/Tests/pec/inputs_test_2d_pec_field_insulator +++ b/Examples/Tests/pec/inputs_test_2d_pec_field_insulator @@ -15,7 +15,7 @@ geometry.prob_hi = 1.e-2 3.e-2 # Boundary condition boundary.field_lo = neumann periodic -boundary.field_hi = PECInsulator periodic +boundary.field_hi = pec_insulator periodic warpx.serialize_initial_conditions = 1 From 847c7ea18016197ceb29032c6e33e8e30d14554b Mon Sep 17 00:00:00 2001 From: David Grote Date: Tue, 12 Nov 2024 11:07:39 -0800 Subject: [PATCH 3/5] Change index 2 to WARPX_ZINDEX --- Source/BoundaryConditions/PEC_Insulator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/BoundaryConditions/PEC_Insulator.cpp b/Source/BoundaryConditions/PEC_Insulator.cpp index 8dbd87668fa..ea47e2280e7 100644 --- a/Source/BoundaryConditions/PEC_Insulator.cpp +++ b/Source/BoundaryConditions/PEC_Insulator.cpp @@ -431,7 +431,7 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::Real const shifty = (Fx_nodal[1] ? 0._rt : 0.5_rt); amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_x.y + (iv[1] - lo_x[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) - amrex::Real const shiftz = (Fx_nodal[2] ? 0._rt : 0.5_rt); + amrex::Real const shiftz = (Fx_nodal[WARPX_ZINDEX] ? 0._rt : 0.5_rt); amrex::Real const z = xyzmin_x.z + (iv[WARPX_ZINDEX] - lo_x[WARPX_ZINDEX] + shiftz)*dx[2]; #endif @@ -479,7 +479,7 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::Real const shifty = (Fy_nodal[1] ? 0._rt : 0.5_rt); amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_y.y + (iv[1] - lo_y[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) - amrex::Real const shiftz = (Fy_nodal[2] ? 0._rt : 0.5_rt); + amrex::Real const shiftz = (Fy_nodal[WARPX_ZINDEX] ? 0._rt : 0.5_rt); amrex::Real const z = xyzmin_y.z + (iv[WARPX_ZINDEX] - lo_y[WARPX_ZINDEX] + shiftz)*dx[2]; #endif @@ -527,7 +527,7 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::Real const shifty = (Fz_nodal[1] ? 0._rt : 0.5_rt); amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_z.y + (iv[1] - lo_z[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) - amrex::Real const shiftz = (Fz_nodal[2] ? 0._rt : 0.5_rt); + amrex::Real const shiftz = (Fz_nodal[WARPX_ZINDEX] ? 0._rt : 0.5_rt); amrex::Real const z = xyzmin_z.z + (iv[WARPX_ZINDEX] - lo_z[WARPX_ZINDEX] + shiftz)*dx[2]; #endif From 0181794a22a58a2275bb1366fab0810d03c5fa97 Mon Sep 17 00:00:00 2001 From: David Grote Date: Tue, 12 Nov 2024 11:18:17 -0800 Subject: [PATCH 4/5] Avoid accessing out of bounds nodal flag in 1D --- Source/BoundaryConditions/PEC_Insulator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/BoundaryConditions/PEC_Insulator.cpp b/Source/BoundaryConditions/PEC_Insulator.cpp index ea47e2280e7..cfcd718c21c 100644 --- a/Source/BoundaryConditions/PEC_Insulator.cpp +++ b/Source/BoundaryConditions/PEC_Insulator.cpp @@ -428,7 +428,7 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::IntVect const iv(AMREX_D_DECL(i, j, k)); amrex::Real const shiftx = (Fx_nodal[0] ? 0._rt : 0.5_rt); amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_x.x + (iv[0] - lo_x[0] + shiftx)*dx[0] : 0._rt); - amrex::Real const shifty = (Fx_nodal[1] ? 0._rt : 0.5_rt); + amrex::Real const shifty = (AMREX_SPACEDIM == 3 ? (Fx_nodal[1] ? 0._rt : 0.5_rt) : 0._rt); amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_x.y + (iv[1] - lo_x[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) amrex::Real const shiftz = (Fx_nodal[WARPX_ZINDEX] ? 0._rt : 0.5_rt); @@ -476,7 +476,7 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::IntVect const iv(AMREX_D_DECL(i, j, k)); amrex::Real const shiftx = (Fy_nodal[0] ? 0._rt : 0.5_rt); amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_y.x + (iv[0] - lo_y[0] + shiftx)*dx[0] : 0._rt); - amrex::Real const shifty = (Fy_nodal[1] ? 0._rt : 0.5_rt); + amrex::Real const shifty = (AMREX_SPACEDIM == 3 ? (Fy_nodal[1] ? 0._rt : 0.5_rt) : 0._rt); amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_y.y + (iv[1] - lo_y[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) amrex::Real const shiftz = (Fy_nodal[WARPX_ZINDEX] ? 0._rt : 0.5_rt); @@ -524,7 +524,7 @@ PEC_Insulator::ApplyPEC_InsulatortoField ( amrex::IntVect const iv(AMREX_D_DECL(i, j, k)); amrex::Real const shiftx = (Fz_nodal[0] ? 0._rt : 0.5_rt); amrex::Real const x = (AMREX_SPACEDIM > 1 ? xyzmin_z.x + (iv[0] - lo_z[0] + shiftx)*dx[0] : 0._rt); - amrex::Real const shifty = (Fz_nodal[1] ? 0._rt : 0.5_rt); + amrex::Real const shifty = (AMREX_SPACEDIM == 3 ? (Fz_nodal[1] ? 0._rt : 0.5_rt) : 0._rt); amrex::Real const y = (AMREX_SPACEDIM == 3 ? xyzmin_z.y + (iv[1] - lo_z[1] + shifty)*dx[1] : 0._rt); #if (AMREX_SPACEDIM > 1) amrex::Real const shiftz = (Fz_nodal[WARPX_ZINDEX] ? 0._rt : 0.5_rt); From 0641cb3bfd90ab1e716dbff381df595b9e8b0b32 Mon Sep 17 00:00:00 2001 From: David Grote Date: Thu, 14 Nov 2024 10:58:26 -0800 Subject: [PATCH 5/5] Update CI benchmarks for test_2d_pec_field_insulator --- .../benchmarks_json/test_2d_pec_field_insulator.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Regression/Checksum/benchmarks_json/test_2d_pec_field_insulator.json b/Regression/Checksum/benchmarks_json/test_2d_pec_field_insulator.json index ca6f38977ae..622cb5e5d30 100644 --- a/Regression/Checksum/benchmarks_json/test_2d_pec_field_insulator.json +++ b/Regression/Checksum/benchmarks_json/test_2d_pec_field_insulator.json @@ -1,13 +1,13 @@ { "lev=0": { "Bx": 0.0, - "By": 0.34938851065132936, + "By": 0.33065279639752304, "Bz": 0.0, - "Ex": 31871402.236828588, + "Ex": 31873416.396984838, "Ey": 0.0, - "Ez": 104908439.18998256, + "Ez": 99285542.27022335, "jx": 0.0, "jy": 0.0, "jz": 0.0 } -} \ No newline at end of file +}