Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow the exact_riemann test to work with Castro runtime parameters #2892

Merged
merged 10 commits into from
Jul 1, 2024
8 changes: 7 additions & 1 deletion Exec/Make.auto_source
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ CPP_PARAMETERS := $(TOP)/Source/driver/_cpp_parameters

$(CASTRO_AUTO_SOURCE_DIR)/runtime_params.cpp: $(CASTRO_AUTO_SOURCE_DIR)/castro_params.H

STRUCT_USE_CASTRO_CLASS ?= TRUE
PARSE_ARGS :=
ifneq ($(STRUCT_USE_CASTRO_CLASS), TRUE)
PARSE_ARGS += --without-castro-class
endif

$(CASTRO_AUTO_SOURCE_DIR)/castro_params.H: $(CPP_PARAMETERS)
@if [ ! -d $(CASTRO_AUTO_SOURCE_DIR) ]; then mkdir -p $(CASTRO_AUTO_SOURCE_DIR); fi
PYTHONPATH=$(MICROPHYSICS_HOME)/util/build_scripts $(TOP)/Source/driver/parse_castro_params.py -o $(CASTRO_AUTO_SOURCE_DIR) $(CPP_PARAMETERS)
PYTHONPATH=$(MICROPHYSICS_HOME)/util/build_scripts $(TOP)/Source/driver/parse_castro_params.py $(PARSE_ARGS) -o $(CASTRO_AUTO_SOURCE_DIR) $(CPP_PARAMETERS)

# for debugging
test_cxx_params: $(CASTRO_AUTO_SOURCE_DIR)/castro_params.H
Expand Down
13 changes: 9 additions & 4 deletions Source/driver/parse_castro_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def read_param_file(infile):

return params

def write_headers_and_source(params, out_directory, struct_name):
def write_headers_and_source(params, out_directory, struct_name, without_castro_class):

# output

Expand Down Expand Up @@ -176,19 +176,23 @@ def write_headers_and_source(params, out_directory, struct_name):

cq.write(CWARNING)

class_name = "Castro"
if without_castro_class:
class_name = None

for ifdef in ifdefs:
if ifdef is None:
for p in [q for q in params_nm if q.ifdef is None]:
cq.write(p.get_default_string())
cq.write(p.get_query_string())
cq.write(p.get_query_struct_string(struct_name=struct_name, class_name="Castro"))
cq.write(p.get_query_struct_string(struct_name=struct_name, class_name=class_name))
cq.write("\n")
else:
cq.write(f"#ifdef {ifdef}\n")
for p in [q for q in params_nm if q.ifdef == ifdef]:
cq.write(p.get_default_string())
cq.write(p.get_query_string())
cq.write(p.get_query_struct_string(struct_name=struct_name, class_name="Castro"))
cq.write(p.get_query_struct_string(struct_name=struct_name, class_name=class_name))
cq.write("\n")
cq.write("#endif\n")
cq.write("\n")
Expand Down Expand Up @@ -305,13 +309,14 @@ def main():
help="output directory for the generated files")
parser.add_argument("-s", type=str, default="params",
help="name for the name struct that will hold the parameters")
parser.add_argument("--without-castro-class", action="store_true", help="don't include Castro:: in the struct namespace")
parser.add_argument("input_file", type=str, nargs=1,
help="input file containing the list of parameters we will define")

args = parser.parse_args()

p = read_param_file(args.input_file[0])
write_headers_and_source(p, args.o, args.s)
write_headers_and_source(p, args.o, args.s, args.without_castro_class)

if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions Util/exact_riemann/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ EOS_DIR := helmholtz
NETWORK_DIR := general_null
NETWORK_INPUTS = ignition.net

# for the Castro runtime parameters, we don't want to use Castro::
STRUCT_USE_CASTRO_CLASS := FALSE

EXTERN_SEARCH += .

Bpack := ./Make.package
Blocs := .

# we explicitly want runtime_parameters.H so we have access to
# Castro's runtime parameter system
Blocs += $(CASTRO_HOME)/Source/driver

include $(CASTRO_HOME)/Exec/Make.Castro
3 changes: 3 additions & 0 deletions Util/exact_riemann/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ CEXE_headers += riemann_sample.H
CEXE_headers += riemann_support.H
CEXE_sources += extern_parameters.cpp
CEXE_headers += extern_parameters.H

# automatically generated in tmp_build_dir
CEXE_sources += runtime_params.cpp
2 changes: 0 additions & 2 deletions Util/exact_riemann/_prob_params
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ t real 0.2d0 y
npts integer 128 y

use_Tinit integer 0 y

initial_temp_guess real 1.0d5 y
5 changes: 3 additions & 2 deletions Util/exact_riemann/exact_riemann.H
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

#include <fstream>

#include <castro_params.H>

#include <riemann_sample.H>
#include <riemann_star_state.H>
#include <riemann_support.H>

using namespace amrex::literals;

Expand Down Expand Up @@ -88,7 +89,7 @@ exact_riemann() {
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn_s[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down
4 changes: 2 additions & 2 deletions Util/exact_riemann/inputs.stellarcollapse
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ problem.T_r = 5.e10

problem.use_Tinit = 1

problem.initial_temp_guess = 1.e5

problem.riemann_max_iter = 20

problem.xmin = 0.0
Expand All @@ -20,5 +18,7 @@ problem.t = 1.e-6

problem.npts = 128

castro.T_guess = 1.e5

eos.eos_file = LS220_240r_140t_50y_analmu_20120628_SVNr28.h5

1 change: 1 addition & 0 deletions Util/exact_riemann/inputs.test1.helm
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ problem.t = 0.0008

problem.npts = 128

castro.T_guess = 1.e5
11 changes: 11 additions & 0 deletions Util/exact_riemann/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@

#include <exact_riemann.H>

#include <castro_params.H>
#include <params_type.H>

// a global struct to hold the params
#include <struct_params.H>

int main(int argc, char *argv[]) {

amrex::Initialize(argc, argv);

std::cout << "starting the exact Riemann solver..." << std::endl;

// initialize the Castro runtime parameters

amrex::ParmParse pp("castro");
#include <castro_queries.H>

// initialize the external runtime parameters in C++

init_prob_parameters();
Expand Down
8 changes: 4 additions & 4 deletions Util/exact_riemann/riemann_rarefaction.H
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ rarefaction(const amrex::Real pstar,
// initial guess at integration step
amrex::Real dp = (pstar - p_s) / static_cast<amrex::Real>(100);

amrex::Real T = problem::initial_temp_guess;
amrex::Real T = castro::T_guess;

// adaptive RK4 loop

Expand Down Expand Up @@ -253,7 +253,7 @@ rarefaction(const amrex::Real pstar,
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down Expand Up @@ -311,7 +311,7 @@ rarefaction_to_u(const amrex::Real rho_s, const amrex::Real u_s, const amrex::Re
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down Expand Up @@ -389,7 +389,7 @@ rarefaction_to_u(const amrex::Real rho_s, const amrex::Real u_s, const amrex::Re
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down
6 changes: 3 additions & 3 deletions Util/exact_riemann/riemann_sample.H
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ riemann_sample(const amrex::Real rho_l, const amrex::Real u_l, const amrex::Real
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn_l[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand All @@ -36,7 +36,7 @@ riemann_sample(const amrex::Real rho_l, const amrex::Real u_l, const amrex::Real
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn_r[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down Expand Up @@ -129,7 +129,7 @@ riemann_sample(const amrex::Real rho_l, const amrex::Real u_l, const amrex::Real
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down
4 changes: 2 additions & 2 deletions Util/exact_riemann/riemann_shock.H
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ W_s_shock(const amrex::Real W_s, const amrex::Real pstar,
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down Expand Up @@ -113,7 +113,7 @@ shock(const amrex::Real pstar,
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down
4 changes: 2 additions & 2 deletions Util/exact_riemann/riemann_star_state.H
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ riemann_star_state(const amrex::Real rho_l, const amrex::Real u_l, const amrex::
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn_l[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand All @@ -42,7 +42,7 @@ riemann_star_state(const amrex::Real rho_l, const amrex::Real u_l, const amrex::
for (int n = 0; n < NumSpec; ++n) {
eos_state.xn[n] = xn_r[n];
}
eos_state.T = problem::initial_temp_guess;
eos_state.T = castro::T_guess;

eos(eos_input_rp, eos_state);

Expand Down
8 changes: 8 additions & 0 deletions Util/exact_riemann/struct_params.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef STRUCT_PARAMS_H
#define STRUCT_PARAMS_H

#include <params_type.H>

inline params_t params;

#endif