diff --git a/Exec/Make.auto_source b/Exec/Make.auto_source index 178e0f43e2..596542809d 100644 --- a/Exec/Make.auto_source +++ b/Exec/Make.auto_source @@ -67,6 +67,8 @@ AUTO_BUILD_SOURCES += $(CASTRO_AUTO_SOURCE_DIR)/castro_params.H CPP_PARAMETERS := $(TOP)/Source/driver/_cpp_parameters +$(CASTRO_AUTO_SOURCE_DIR)/runtime_params.cpp: $(CASTRO_AUTO_SOURCE_DIR)/castro_params.H + $(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) diff --git a/Source/diffusion/Make.package b/Source/diffusion/Make.package index d39ddec718..be1fe61fbe 100644 --- a/Source/diffusion/Make.package +++ b/Source/diffusion/Make.package @@ -8,5 +8,4 @@ CEXE_sources += diffusion_util.cpp CEXE_sources += Castro_diffusion.cpp CEXE_sources += Diffusion.cpp -CEXE_sources += diffusion_params.cpp CEXE_headers += Diffusion.H diff --git a/Source/diffusion/diffusion_params.cpp b/Source/diffusion/diffusion_params.cpp deleted file mode 100644 index 2518c14740..0000000000 --- a/Source/diffusion/diffusion_params.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include - -#include - -#include - -#include diff --git a/Source/driver/Make.package b/Source/driver/Make.package index c4ca1e4313..85febd5698 100644 --- a/Source/driver/Make.package +++ b/Source/driver/Make.package @@ -1,7 +1,7 @@ # these are the files that should be needed for any Castro build CEXE_sources += Castro.cpp -CEXE_sources += runparams_defaults.cpp +CEXE_sources += runtime_params.cpp CEXE_sources += Castro_advance.cpp CEXE_sources += Castro_advance_ctu.cpp ifeq ($(USE_TRUE_SDC), TRUE) diff --git a/Source/driver/castro_limits.H b/Source/driver/castro_limits.H index 0111b43432..31ddeb93a9 100644 --- a/Source/driver/castro_limits.H +++ b/Source/driver/castro_limits.H @@ -1,6 +1,6 @@ #ifndef CASTRO_LIMITS_H #define CASTRO_LIMITS_H -#define MAX_LEV 15 +constexpr int MAX_LEV{15}; #endif diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index aedeea6624..89f91a8ea7 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -1,9 +1,9 @@ #!/usr/bin/env python3 -""" -This script parses the list of C++ runtime parameters and writes the -necessary header files and Fortran routines to make them available -in Castro's C++ routines. +"""This script parses the list of C++ runtime parameters and writes +the necessary header and source files to make them available in +Castro's C++ routines. They are available in 2 ways: as global +parameter and in the form of a single struct. parameters have the format: @@ -41,9 +41,6 @@ -- name_params.H (for castro, included in Castro.H): sets up the namespace and extern parameters - -- name_declares.H (for castro, included in Castro.cpp): - declares the runtime parameters - -- name_queries.H (for castro, included in Castro.cpp): does the parmparse query to override the default in C++ @@ -51,6 +48,9 @@ this tests the current value against the default and outputs into a file + -- runtime_params.cpp + has the actual definition of the variables (without extern) + """ import argparse @@ -129,12 +129,12 @@ def read_param_file(infile): return params -def write_headers(params, out_directory, struct_name): +def write_headers_and_source(params, out_directory, struct_name): # output # find all the namespaces - namespaces = {q.namespace for q in params} + namespaces = sorted({q.namespace for q in params}) for nm in namespaces: @@ -142,32 +142,6 @@ def write_headers(params, out_directory, struct_name): # sort by repr since None may be present ifdefs = sorted({q.ifdef for q in params_nm}, key=repr) - # write name_declares.H - try: - cd = open(f"{out_directory}/{nm}_declares.H", "w", encoding="UTF-8") - except OSError: - sys.exit(f"unable to open {nm}_declares.H for writing") - - cd.write(CWARNING) - cd.write(f"#ifndef {nm.upper()}_DECLARES_H\n") - cd.write(f"#define {nm.upper()}_DECLARES_H\n") - - cd.write("\n") - cd.write(f"namespace {nm} {{\n") - - for ifdef in ifdefs: - if ifdef is None: - for p in [q for q in params_nm if q.ifdef is None]: - cd.write(p.get_declare_string()) - else: - cd.write(f"#ifdef {ifdef}\n") - for p in [q for q in params_nm if q.ifdef == ifdef]: - cd.write(p.get_declare_string()) - cd.write("#endif\n") - cd.write("}\n\n") - cd.write("#endif\n") - cd.close() - # write name_params.H try: cp = open(f"{out_directory}/{nm}_params.H", "w", encoding="UTF-8") @@ -238,7 +212,44 @@ def write_headers(params, out_directory, struct_name): jo.close() + # write a single C++ source file that actually defines the parameters + # (one file for all namespaces) + try: + pf = open(f"{out_directory}/runtime_params.cpp", "w", encoding="UTF-8") + except OSError: + sys.exit(f"unable to open runtime_params.cpp") + + pf.write("#include \n") + pf.write("#include \n") + pf.write("#include \n\n") + + for nm in namespaces: + pf.write(f"#include <{nm}_params.H>\n") + pf.write("\n") + + for nm in namespaces: + params_nm = [q for q in params if q.namespace == nm] + # sort by repr since None may be present + ifdefs = sorted({q.ifdef for q in params_nm}, key=repr) + + pf.write(f"namespace {nm} {{\n") + + for ifdef in ifdefs: + if ifdef is None: + for p in [q for q in params_nm if q.ifdef is None]: + pf.write(p.get_declare_string()) + else: + pf.write(f"#ifdef {ifdef}\n") + for p in [q for q in params_nm if q.ifdef == ifdef]: + pf.write(p.get_declare_string()) + pf.write("#endif\n") + pf.write("}\n\n") + + pf.close() + # now write a single file that contains all of the parameter structs + # to minimize padding, we want to sort on type + try: sf = open(f"{out_directory}/{struct_name}_type.H", "w", encoding="UTF-8") except OSError: @@ -255,20 +266,25 @@ def write_headers(params, out_directory, struct_name): params_nm = [q for q in params if q.namespace == nm] # sort by repr since None may be present ifdefs = sorted({q.ifdef for q in params_nm}, key=repr) - sf.write(f"struct {nm}_t {{\n") print("namespace = ", nm) for ifdef in ifdefs: + params_if = [q for q in params_nm if q.ifdef == ifdef] + types = sorted(set(q.dtype for q in params_if)) + if ifdef is None: - for p in [q for q in params_nm if q.ifdef is None]: - sf.write(p.get_struct_entry()) + for tt in types: + params_type = [q for q in params_if if q.dtype == tt] + for p in params_type: + sf.write(p.get_struct_entry()) else: sf.write(f"#ifdef {ifdef}\n") - for p in [q for q in params_nm if q.ifdef == ifdef]: - sf.write(p.get_struct_entry()) + for tt in types: + params_type = [q for q in params_if if q.dtype == tt] + for p in params_type: + sf.write(p.get_struct_entry()) sf.write("#endif\n") - sf.write("};\n\n") # now the parent struct @@ -295,7 +311,7 @@ def main(): args = parser.parse_args() p = read_param_file(args.input_file[0]) - write_headers(p, args.o, args.s) + write_headers_and_source(p, args.o, args.s) if __name__ == "__main__": main() diff --git a/Source/driver/runparams_defaults.cpp b/Source/driver/runparams_defaults.cpp deleted file mode 100644 index c9f5ed1de6..0000000000 --- a/Source/driver/runparams_defaults.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -#include - -#include - diff --git a/Source/driver/sum_integrated_quantities.cpp b/Source/driver/sum_integrated_quantities.cpp index 1a38867a05..a92c65d885 100644 --- a/Source/driver/sum_integrated_quantities.cpp +++ b/Source/driver/sum_integrated_quantities.cpp @@ -511,10 +511,7 @@ Castro::sum_integrated_quantities () log << std::setw(intwidth) << timestep; - if (time == 0.0_rt) { - log << std::fixed; - } - else if (time < 1.e-4_rt || time > 1.e4_rt) { + if (time < 1.e-4_rt || time > 1.e4_rt) { log << std::scientific; } else { diff --git a/Source/gravity/Make.package b/Source/gravity/Make.package index f94894307f..6708aab63d 100644 --- a/Source/gravity/Make.package +++ b/Source/gravity/Make.package @@ -2,7 +2,6 @@ # this is included if USE_GRAV = TRUE CEXE_sources += Gravity.cpp -CEXE_sources += gravity_params.cpp CEXE_headers += Gravity.H CEXE_headers += Gravity_util.H CEXE_headers += Castro_gravity.H diff --git a/Source/gravity/gravity_params.cpp b/Source/gravity/gravity_params.cpp deleted file mode 100644 index c80baeadc7..0000000000 --- a/Source/gravity/gravity_params.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#include - -#include - -#include - - diff --git a/Source/mhd/Castro_mhd.H b/Source/mhd/Castro_mhd.H index 3451fefe37..a15a323207 100644 --- a/Source/mhd/Castro_mhd.H +++ b/Source/mhd/Castro_mhd.H @@ -31,7 +31,7 @@ void consup_mhd(const amrex::Box& bx, const Real dt, - amrex::Array4 const& update, + amrex::Array4 const& U_new, amrex::Array4 const& flux0, amrex::Array4 const& flux1, amrex::Array4 const& flux2); diff --git a/Source/mhd/mhd_util.H b/Source/mhd/mhd_util.H index 7b7cce3eba..7f9097e4f5 100644 --- a/Source/mhd/mhd_util.H +++ b/Source/mhd/mhd_util.H @@ -23,7 +23,7 @@ eos_soundspeed_mhd(Real& c, Real as, Real ca, Real bd) { AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void -qflux(Real* qflx, Real* flx, Real* q_zone) { +qflux(Real* qflx, const Real* flx, const Real* q_zone) { // Calculate the C to P Jacobian applied to the fluxes @@ -78,7 +78,7 @@ qflux(Real* qflx, Real* flx, Real* q_zone) { AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void -electric(Real* q_zone, Real& E_zone, const int comp) { +electric(const Real* q_zone, Real& E_zone, const int comp) { // this takes the cell-center primitive state, q_zone, and computes the cell-center // electric field, E_zone, using Faraday's law: @@ -99,7 +99,7 @@ electric(Real* q_zone, Real& E_zone, const int comp) { AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void -ConsToPrim(Real* q_zone, Real* U_zone) { +ConsToPrim(Real* q_zone, const Real* U_zone) { // calculate the primitive variables from the conserved // U has NUM_STATE+3 components diff --git a/Source/radiation/Make.package b/Source/radiation/Make.package index 5a0023f4da..dfaa525b1b 100644 --- a/Source/radiation/Make.package +++ b/Source/radiation/Make.package @@ -5,7 +5,6 @@ CEXE_sources += HypreExtMultiABec.cpp CEXE_sources += HypreMultiABec.cpp CEXE_sources += HypreABec.cpp CEXE_sources += Radiation.cpp -CEXE_sources += radiation_params.cpp CEXE_sources += RadSolve.cpp CEXE_sources += RadBndry.cpp CEXE_sources += RadMultiGroup.cpp diff --git a/Source/radiation/radiation_params.cpp b/Source/radiation/radiation_params.cpp deleted file mode 100644 index 5c10888946..0000000000 --- a/Source/radiation/radiation_params.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#include - -#include - -#include - -#include diff --git a/Source/sources/Castro_sources.cpp b/Source/sources/Castro_sources.cpp index f99aac52dc..fc5dddce4f 100644 --- a/Source/sources/Castro_sources.cpp +++ b/Source/sources/Castro_sources.cpp @@ -606,6 +606,9 @@ Castro::post_advance_operators (Real time, Real dt) { advance_status status {}; + amrex::ignore_unused(time); + amrex::ignore_unused(dt); + #ifndef TRUE_SDC #ifdef REACTIONS status = do_new_reactions(time, dt); diff --git a/Util/scripts/write_probdata.py b/Util/scripts/write_probdata.py index 68cb716aac..2cd7cdd398 100755 --- a/Util/scripts/write_probdata.py +++ b/Util/scripts/write_probdata.py @@ -237,8 +237,8 @@ def write_probin(prob_param_files, cxx_prefix): size = p.size if (size == "nspec"): size = "NumSpec" - fout.write(f" for (int n = 0; n < {size}; n++) {{\n") - fout.write(f" problem::{p.name}[n] = {p.default_format(lang='C++')};\n") + fout.write(f" for (auto & e : problem::{p.name}) {{\n") + fout.write(f" e = {p.default_format(lang='C++')};\n") fout.write(f" }}\n") else: fout.write(f" {p.get_default_string()}")