From 4ce25453b4a9f5d1324d4738d1a0b809acceb4bc Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 1 Nov 2024 09:54:48 -0400 Subject: [PATCH 1/4] use the same compressible external source function for RK and SDC solvers --- pyro/compressible_fv4/simulation.py | 34 ++++++++++++++--------------- pyro/compressible_rk/simulation.py | 19 +++++----------- 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/pyro/compressible_fv4/simulation.py b/pyro/compressible_fv4/simulation.py index b47d19821..81785c2d9 100644 --- a/pyro/compressible_fv4/simulation.py +++ b/pyro/compressible_fv4/simulation.py @@ -1,5 +1,6 @@ import pyro.compressible_fv4.fluxes as flx from pyro import compressible_rk +from pyro.compressible import get_external_sources from pyro.mesh import fv, integration @@ -17,24 +18,23 @@ def substep(self, myd): """ myg = myd.grid - grav = self.rp.get_param("compressible.grav") - # compute the source terms -- we need to do these to 4th - # order. Start by evaluating the sources using the - # cell-center quantities (including one ghost cell. - dens_cc = myd.to_centers("density") - ymom_cc = myd.to_centers("y-momentum") + # compute the source terms -- we need to do this first + # using the cell-center data and then convert it back to + # averages - ymom_src = myg.scratch_array() - ymom_src.v(buf=1)[:, :] = dens_cc.v(buf=1)[:, :]*grav + U_cc = myg.scratch_array(nvar=self.ivars.nvar) + for n in range(self.ivars.nvar): + U_cc[:, :, n] = myd.to_centers(myg.get_var_by_index(n)) - E_src = myg.scratch_array() - E_src.v(buf=1)[:, :] = ymom_cc.v(buf=1)[:, :]*grav + # cell-centered sources + S = get_external_sources(self.cc_data.t, self.dt, U_cc, + self.ivars, self.rp, myg) - # now bring back to averages -- we only need this in the - # interior (no ghost cells) - ymom_src.v()[:, :] = ymom_src.v()[:, :] - myg.dx**2*ymom_src.lap()/24.0 - E_src.v()[:, :] = E_src.v()[:, :] - myg.dx**2*E_src.lap()/24.0 + # bring the sources back to averages -- we only care about + # the interior (no ghost cells) + for n in range(self.ivars.nvar): + S.v(n=n)[:, :] -= myg.dx**2 * S.lap(n=n) / 24.0 k = myg.scratch_array(nvar=self.ivars.nvar) @@ -43,10 +43,8 @@ def substep(self, myd): for n in range(self.ivars.nvar): k.v(n=n)[:, :] = \ (flux_x.v(n=n) - flux_x.ip(1, n=n))/myg.dx + \ - (flux_y.v(n=n) - flux_y.jp(1, n=n))/myg.dy - - k.v(n=self.ivars.iymom)[:, :] += ymom_src.v()[:, :] - k.v(n=self.ivars.iener)[:, :] += E_src.v()[:, :] + (flux_y.v(n=n) - flux_y.jp(1, n=n))/myg.dy + \ + S.v(n=n) return k diff --git a/pyro/compressible_rk/simulation.py b/pyro/compressible_rk/simulation.py index 56be8d8f8..8fe5465bd 100644 --- a/pyro/compressible_rk/simulation.py +++ b/pyro/compressible_rk/simulation.py @@ -16,17 +16,10 @@ def substep(self, myd): """ myg = myd.grid - grav = self.rp.get_param("compressible.grav") - # compute the source terms - dens = myd.get_var("density") - ymom = myd.get_var("y-momentum") - - ymom_src = myg.scratch_array() - ymom_src.v()[:, :] = dens.v()[:, :]*grav - - E_src = myg.scratch_array() - E_src.v()[:, :] = ymom.v()[:, :]*grav + # source terms + S = compressible.get_external_sources(self.cc_data.t, self.dt, self.cc_data.data, + self.ivars, self.rp, myg) k = myg.scratch_array(nvar=self.ivars.nvar) @@ -36,10 +29,8 @@ def substep(self, myd): for n in range(self.ivars.nvar): k.v(n=n)[:, :] = \ (flux_x.v(n=n) - flux_x.ip(1, n=n))/myg.dx + \ - (flux_y.v(n=n) - flux_y.jp(1, n=n))/myg.dy - - k.v(n=self.ivars.iymom)[:, :] += ymom_src.v()[:, :] - k.v(n=self.ivars.iener)[:, :] += E_src.v()[:, :] + (flux_y.v(n=n) - flux_y.jp(1, n=n))/myg.dy + \ + S.v(n=n) return k From f40525fca1742780552da1c5cc355bcc9e5b1cf0 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 1 Nov 2024 09:58:05 -0400 Subject: [PATCH 2/4] fix flake8 --- pyro/compressible_fv4/simulation.py | 3 +-- pyro/compressible_rk/simulation.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pyro/compressible_fv4/simulation.py b/pyro/compressible_fv4/simulation.py index 81785c2d9..ba013cfbc 100644 --- a/pyro/compressible_fv4/simulation.py +++ b/pyro/compressible_fv4/simulation.py @@ -43,8 +43,7 @@ def substep(self, myd): for n in range(self.ivars.nvar): k.v(n=n)[:, :] = \ (flux_x.v(n=n) - flux_x.ip(1, n=n))/myg.dx + \ - (flux_y.v(n=n) - flux_y.jp(1, n=n))/myg.dy + \ - S.v(n=n) + (flux_y.v(n=n) - flux_y.jp(1, n=n))/myg.dy + S.v(n=n) return k diff --git a/pyro/compressible_rk/simulation.py b/pyro/compressible_rk/simulation.py index 8fe5465bd..e186abd0d 100644 --- a/pyro/compressible_rk/simulation.py +++ b/pyro/compressible_rk/simulation.py @@ -29,8 +29,7 @@ def substep(self, myd): for n in range(self.ivars.nvar): k.v(n=n)[:, :] = \ (flux_x.v(n=n) - flux_x.ip(1, n=n))/myg.dx + \ - (flux_y.v(n=n) - flux_y.jp(1, n=n))/myg.dy + \ - S.v(n=n) + (flux_y.v(n=n) - flux_y.jp(1, n=n))/myg.dy + S.v(n=n) return k From e3e2ad7caf06fa2e5231cbea8f8d740233f3180d Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 1 Nov 2024 10:03:20 -0400 Subject: [PATCH 3/4] fix crash --- pyro/compressible_fv4/simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyro/compressible_fv4/simulation.py b/pyro/compressible_fv4/simulation.py index ba013cfbc..53aa70adf 100644 --- a/pyro/compressible_fv4/simulation.py +++ b/pyro/compressible_fv4/simulation.py @@ -25,7 +25,7 @@ def substep(self, myd): U_cc = myg.scratch_array(nvar=self.ivars.nvar) for n in range(self.ivars.nvar): - U_cc[:, :, n] = myd.to_centers(myg.get_var_by_index(n)) + U_cc[:, :, n] = myd.to_centers(self.cc_data.names[n]) # cell-centered sources S = get_external_sources(self.cc_data.t, self.dt, U_cc, From f3cbca1201a63ce26cdb66f7348fefb2716fd3d3 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 1 Nov 2024 10:22:57 -0400 Subject: [PATCH 4/4] fix stage data --- pyro/compressible_fv4/simulation.py | 4 ++-- pyro/compressible_rk/simulation.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pyro/compressible_fv4/simulation.py b/pyro/compressible_fv4/simulation.py index 53aa70adf..5f096be68 100644 --- a/pyro/compressible_fv4/simulation.py +++ b/pyro/compressible_fv4/simulation.py @@ -25,10 +25,10 @@ def substep(self, myd): U_cc = myg.scratch_array(nvar=self.ivars.nvar) for n in range(self.ivars.nvar): - U_cc[:, :, n] = myd.to_centers(self.cc_data.names[n]) + U_cc[:, :, n] = myd.to_centers(myd.names[n]) # cell-centered sources - S = get_external_sources(self.cc_data.t, self.dt, U_cc, + S = get_external_sources(myd.t, self.dt, U_cc, self.ivars, self.rp, myg) # bring the sources back to averages -- we only care about diff --git a/pyro/compressible_rk/simulation.py b/pyro/compressible_rk/simulation.py index e186abd0d..a4d5aad35 100644 --- a/pyro/compressible_rk/simulation.py +++ b/pyro/compressible_rk/simulation.py @@ -17,8 +17,9 @@ def substep(self, myd): myg = myd.grid - # source terms - S = compressible.get_external_sources(self.cc_data.t, self.dt, self.cc_data.data, + # source terms -- note: this dt is the entire dt, not the + # stage's dt + S = compressible.get_external_sources(myd.t, self.dt, myd.data, self.ivars, self.rp, myg) k = myg.scratch_array(nvar=self.ivars.nvar)