From 4fdc98e72830880f09223994fe18ef330ab01c27 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sun, 17 Sep 2023 13:19:30 -0400 Subject: [PATCH 1/6] add a 3D slice plot for the subchandra run --- .../subchandra/analysis/subch_slice_3d.py | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 Exec/science/subchandra/analysis/subch_slice_3d.py diff --git a/Exec/science/subchandra/analysis/subch_slice_3d.py b/Exec/science/subchandra/analysis/subch_slice_3d.py new file mode 100755 index 0000000000..b9baf0b52e --- /dev/null +++ b/Exec/science/subchandra/analysis/subch_slice_3d.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 + +import os +import sys +from functools import reduce + +import matplotlib +import matplotlib.pyplot as plt +import numpy as np +from mpl_toolkits.axes_grid1 import ImageGrid + +import yt +from yt.frontends.boxlib.api import CastroDataset +# assume that our data is in CGS +from yt.units import amu, cm + +matplotlib.use('agg') + + + + +plotfile = sys.argv[1] +ds = CastroDataset(plotfile) + +domain_frac = 0.2 + +xmin = ds.domain_left_edge[0] +xmax = ds.domain_right_edge[0] +xctr = 0.5 * (xmin + xmax) +L_x = xmax - xmin +xmin = xctr - 0.5 * domain_frac * L_x +xmax = xctr + 0.5 * domain_frac * L_x +L_x = xmax - xmin + +ymin = ds.domain_left_edge[1] +ymax = ds.domain_right_edge[1] +yctr = 0.5 * (ymin + ymax) +L_y = ymax - ymin +ymin = yctr - 0.5 * domain_frac * L_y +ymax = yctr + 0.5 * domain_frac * L_y +L_y = ymax - ymin + +zmin = ds.domain_left_edge[2] +zmax = ds.domain_right_edge[2] +zctr = 0.5 * (zmin + zmax) +L_z = zmax - zmin +zmin = zctr - 0.5 * domain_frac * L_z +zmax = zctr + 0.5 * domain_frac * L_z +L_z = zmax - zmin + +fig = plt.figure() + + +fields = ["Temp", "abar", "enuc"] + +grid = ImageGrid(fig, 111, nrows_ncols=(1, len(fields)), + axes_pad=0.75, cbar_pad=0.05, label_mode="L", cbar_mode="each") + + +for i, f in enumerate(fields): + + sp = yt.SlicePlot(ds, "y", f, + center=[xctr, yctr, zctr], width=[L_x, L_z], + fontsize="12") + + sp.set_buff_size((2400,2400)) + sp.swap_axes() + + if f == "Temp": + sp.set_zlim(f, 5.e7, 4e9) + sp.set_cmap(f, "magma_r") + elif f == "enuc": + sp.set_log(f, True, linthresh=1.e18) + sp.set_zlim(f, -1.e22, 1.e22) + sp.set_cmap(f, "bwr") + elif f == "density": + sp.set_zlim(f, 1.e-3, 5.e8) + elif f == "z_velocity": + sp.set_zlim(f, -2.e8, 2.e8) + sp.set_log(f, False) + sp.set_cmap(f, "bwr") + elif f == "abar": + sp.set_zlim(f, 4, 28) + sp.set_log(f, False) + sp.set_cmap(f, "plasma_r") + + sp.set_axes_unit("cm") + + plot = sp.plots[f] + plot.figure = fig + plot.axes = grid[i].axes + plot.cax = grid.cbar_axes[i] + if i < len(fields)-1: + grid[i].axes.xaxis.offsetText.set_visible(False) + + sp._setup_plots() + +fig.text(0.02, 0.02, "time = {:8.5f} s".format(float(ds.current_time)), transform=fig.transFigure) + +fig.set_size_inches(19.2, 10.8) +plt.tight_layout() +plt.savefig("{}_slice.png".format(os.path.basename(plotfile))) From 2498b01523a44643902ec3ec140eb342cbc79b76 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Thu, 21 Sep 2023 12:35:49 -0400 Subject: [PATCH 2/6] react_state says it returns bool, but we always return an int shouldn't matter, but this makes it consistent --- Source/reactions/Castro_react.H | 10 +++++----- Source/reactions/Castro_react.cpp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/reactions/Castro_react.H b/Source/reactions/Castro_react.H index 12d1dc320b..2d9190b0a3 100644 --- a/Source/reactions/Castro_react.H +++ b/Source/reactions/Castro_react.H @@ -16,11 +16,11 @@ /// @param time current time /// @param dt reaction timestep /// - bool react_state(amrex::MultiFab& state, - amrex::MultiFab& reactions, - amrex::Real time, - amrex::Real dt, - const int strang_half); + int react_state(amrex::MultiFab& state, + amrex::MultiFab& reactions, + amrex::Real time, + amrex::Real dt, + const int strang_half); /// /// Simplified SDC version of react_state. Reacts the current state through a single timestep. diff --git a/Source/reactions/Castro_react.cpp b/Source/reactions/Castro_react.cpp index 580516f722..45cf62c139 100644 --- a/Source/reactions/Castro_react.cpp +++ b/Source/reactions/Castro_react.cpp @@ -20,7 +20,7 @@ Castro::do_old_reactions (Real time, Real dt) advance_status status {}; #ifndef SIMPLIFIED_SDC - bool burn_success = true; + int burn_success{1}; MultiFab& R_old = get_old_data(Reactions_Type); MultiFab& R_new = get_new_data(Reactions_Type); @@ -57,7 +57,7 @@ Castro::do_new_reactions (Real time, Real dt) advance_status status {}; - bool burn_success = true; + int burn_success{1}; MultiFab& R_new = get_new_data(Reactions_Type); MultiFab& S_new = get_new_data(State_Type); @@ -129,7 +129,7 @@ Castro::do_new_reactions (Real time, Real dt) // Strang version -bool +int Castro::react_state(MultiFab& s, MultiFab& r, Real time, Real dt, const int strang_half) { From 9a504147bd350e51f5f68b480bc0c50b38e895e2 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Thu, 21 Sep 2023 12:37:23 -0400 Subject: [PATCH 3/6] Delete Exec/science/subchandra/analysis/subch_slice_3d.py --- .../subchandra/analysis/subch_slice_3d.py | 102 ------------------ 1 file changed, 102 deletions(-) delete mode 100755 Exec/science/subchandra/analysis/subch_slice_3d.py diff --git a/Exec/science/subchandra/analysis/subch_slice_3d.py b/Exec/science/subchandra/analysis/subch_slice_3d.py deleted file mode 100755 index b9baf0b52e..0000000000 --- a/Exec/science/subchandra/analysis/subch_slice_3d.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python3 - -import os -import sys -from functools import reduce - -import matplotlib -import matplotlib.pyplot as plt -import numpy as np -from mpl_toolkits.axes_grid1 import ImageGrid - -import yt -from yt.frontends.boxlib.api import CastroDataset -# assume that our data is in CGS -from yt.units import amu, cm - -matplotlib.use('agg') - - - - -plotfile = sys.argv[1] -ds = CastroDataset(plotfile) - -domain_frac = 0.2 - -xmin = ds.domain_left_edge[0] -xmax = ds.domain_right_edge[0] -xctr = 0.5 * (xmin + xmax) -L_x = xmax - xmin -xmin = xctr - 0.5 * domain_frac * L_x -xmax = xctr + 0.5 * domain_frac * L_x -L_x = xmax - xmin - -ymin = ds.domain_left_edge[1] -ymax = ds.domain_right_edge[1] -yctr = 0.5 * (ymin + ymax) -L_y = ymax - ymin -ymin = yctr - 0.5 * domain_frac * L_y -ymax = yctr + 0.5 * domain_frac * L_y -L_y = ymax - ymin - -zmin = ds.domain_left_edge[2] -zmax = ds.domain_right_edge[2] -zctr = 0.5 * (zmin + zmax) -L_z = zmax - zmin -zmin = zctr - 0.5 * domain_frac * L_z -zmax = zctr + 0.5 * domain_frac * L_z -L_z = zmax - zmin - -fig = plt.figure() - - -fields = ["Temp", "abar", "enuc"] - -grid = ImageGrid(fig, 111, nrows_ncols=(1, len(fields)), - axes_pad=0.75, cbar_pad=0.05, label_mode="L", cbar_mode="each") - - -for i, f in enumerate(fields): - - sp = yt.SlicePlot(ds, "y", f, - center=[xctr, yctr, zctr], width=[L_x, L_z], - fontsize="12") - - sp.set_buff_size((2400,2400)) - sp.swap_axes() - - if f == "Temp": - sp.set_zlim(f, 5.e7, 4e9) - sp.set_cmap(f, "magma_r") - elif f == "enuc": - sp.set_log(f, True, linthresh=1.e18) - sp.set_zlim(f, -1.e22, 1.e22) - sp.set_cmap(f, "bwr") - elif f == "density": - sp.set_zlim(f, 1.e-3, 5.e8) - elif f == "z_velocity": - sp.set_zlim(f, -2.e8, 2.e8) - sp.set_log(f, False) - sp.set_cmap(f, "bwr") - elif f == "abar": - sp.set_zlim(f, 4, 28) - sp.set_log(f, False) - sp.set_cmap(f, "plasma_r") - - sp.set_axes_unit("cm") - - plot = sp.plots[f] - plot.figure = fig - plot.axes = grid[i].axes - plot.cax = grid.cbar_axes[i] - if i < len(fields)-1: - grid[i].axes.xaxis.offsetText.set_visible(False) - - sp._setup_plots() - -fig.text(0.02, 0.02, "time = {:8.5f} s".format(float(ds.current_time)), transform=fig.transFigure) - -fig.set_size_inches(19.2, 10.8) -plt.tight_layout() -plt.savefig("{}_slice.png".format(os.path.basename(plotfile))) From d2219a8d0cc93d8e358535a80df202c37cfb62eb Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 Sep 2023 07:59:22 -0400 Subject: [PATCH 4/6] more fixes --- Source/reactions/Castro_react.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Source/reactions/Castro_react.cpp b/Source/reactions/Castro_react.cpp index 45cf62c139..62edeb4c04 100644 --- a/Source/reactions/Castro_react.cpp +++ b/Source/reactions/Castro_react.cpp @@ -29,7 +29,7 @@ Castro::do_old_reactions (Real time, Real dt) // The result of the reactions is added directly to Sborder. burn_success = react_state(Sborder, R_old, time, 0.5 * dt, 0); - if (!burn_success) { + if (burn_success != 1) { status.success = false; status.reason = "burn unsuccessful"; @@ -73,7 +73,7 @@ Castro::do_new_reactions (Real time, Real dt) burn_success = react_state(time, dt); - if (!burn_success) { + if (burn_success != 1) { status.success = false; status.reason = "burn unsuccessful"; @@ -107,7 +107,7 @@ Castro::do_new_reactions (Real time, Real dt) burn_success = react_state(S_new, R_new, time - 0.5 * dt, 0.5 * dt, 1); - if (!burn_success) { + if (burn_success != 1) { status.success = false; status.reason = "burn unsuccessful"; @@ -452,7 +452,7 @@ Castro::react_state(MultiFab& s, MultiFab& r, Real time, Real dt, const int stra #ifdef SIMPLIFIED_SDC // Simplified SDC version -bool +int Castro::react_state(Real time, Real dt) { @@ -804,7 +804,9 @@ Castro::react_state(Real time, Real dt) ReduceTuple hv = reduce_data.value(); Real burn_failed = amrex::get<0>(hv); - if (burn_failed != 0.0) burn_success = 0; + if (burn_failed != 0.0) { + burn_success = 0; + } ParallelDescriptor::ReduceIntMin(burn_success); @@ -843,11 +845,7 @@ Castro::react_state(Real time, Real dt) } - if (burn_success) { - return true; - } else { - return false; - } + return burn_success == 1; } #endif From 4de392e484cdc428a272e2a1641a45a3dd98a6c5 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 22 Sep 2023 13:20:05 -0400 Subject: [PATCH 5/6] fix --- Source/reactions/Castro_react.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/reactions/Castro_react.H b/Source/reactions/Castro_react.H index 2d9190b0a3..815e0a2774 100644 --- a/Source/reactions/Castro_react.H +++ b/Source/reactions/Castro_react.H @@ -28,7 +28,7 @@ /// @param time current time /// @param dt timestep /// - bool react_state(amrex::Real time, amrex::Real dt); + int react_state(amrex::Real time, amrex::Real dt); /// /// Are there any zones in ``State`` that can burn? From 6fa4b0c4ebcaa2a8ae0e53da8c06374553841051 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sat, 23 Sep 2023 18:26:21 -0400 Subject: [PATCH 6/6] fix --- Source/reactions/Castro_react.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/reactions/Castro_react.cpp b/Source/reactions/Castro_react.cpp index 62edeb4c04..9c87344d07 100644 --- a/Source/reactions/Castro_react.cpp +++ b/Source/reactions/Castro_react.cpp @@ -845,7 +845,7 @@ Castro::react_state(Real time, Real dt) } - return burn_success == 1; + return burn_success; } #endif