From f82cb68763cc13f3a1db578f34207359e1ffd0a0 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 19 Dec 2023 14:11:13 -0500 Subject: [PATCH 1/3] start of moving runtime parameters to structs --- Source/driver/parse_castro_params.py | 53 ++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index cfa2ebb30c..75e9fd24f2 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -7,7 +7,7 @@ parameters have the format: - name type default need-in-fortran? ifdef + name type default ifdef the first three (name, type, default) are mandatory: @@ -22,8 +22,6 @@ the next are optional: - need-in-fortran: no longer used - ifdef: only define this parameter if the name provided is #ifdef-ed Any line beginning with a "#" is ignored @@ -131,7 +129,7 @@ def read_param_file(infile): return params -def write_headers(params, out_directory): +def write_headers(params, out_directory, struct_name): # output @@ -196,7 +194,7 @@ def write_headers(params, out_directory): cp.write("#endif\n") cp.close() - # write castro_queries.H + # write name_queries.H try: cq = open(f"{out_directory}/{nm}_queries.H", "w", encoding="UTF-8") except OSError: @@ -238,19 +236,62 @@ def write_headers(params, out_directory): jo.close() + # now write a single file that contains all of the parameter structs + try: + sf = open(f"{out_directory}/{struct_name}_type.H", "w", encoding="UTF-8") + except OSError: + sys.exit(f"unable to open {struct_name}_type.H for writing") + + sf.write(CWARNING) + sf.write(f"#ifndef {struct_name.upper()}_TYPE_H\n") + sf.write(f"#define {struct_name.upper()}_TYPE_H\n\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) + + sf.write(f"struct {nm}_t {{\n") + print("namespace = ", nm) + for ifdef in ifdefs: + if ifdef is None: + for p in [q for q in params_nm if q.ifdef is None]: + 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()) + sf.write("#endif\n") + + + sf.write("};\n\n") + + # now the parent struct + + sf.write(f"struct {struct_name}_t {{\n") + for nm in namespaces: + sf.write(f" {nm}_t {nm};\n") + sf.write("};\n\n") + + sf.write("#endif\n") + sf.close() + def main(): """the main driver""" parser = argparse.ArgumentParser() parser.add_argument("-o", type=str, default=None, 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("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(p, args.o) + write_headers(p, args.o, args.s) if __name__ == "__main__": main() From 14a53bef2b859620c0616730de8b482e5c563e5d Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 19 Dec 2023 15:45:47 -0500 Subject: [PATCH 2/3] hook in the struct --- Source/driver/Castro.H | 5 ++++- Source/driver/parse_castro_params.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/driver/Castro.H b/Source/driver/Castro.H index bd1374dcef..1c8b7725f8 100644 --- a/Source/driver/Castro.H +++ b/Source/driver/Castro.H @@ -48,6 +48,8 @@ constexpr int PSTAR_BISECT_FACTOR = 5; #include #include +#include + using std::istream; using std::ostream; @@ -535,7 +537,6 @@ public: #include #endif - /// /// Estimate time step. /// @@ -1408,6 +1409,8 @@ protected: static int lastDtPlotLimited; static amrex::Real lastDtBeforePlotLimiting; + static params_t params; + int in_retry; int num_subcycles_taken; diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index 75e9fd24f2..3fe6ac6799 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -246,6 +246,8 @@ def write_headers(params, out_directory, struct_name): sf.write(f"#ifndef {struct_name.upper()}_TYPE_H\n") sf.write(f"#define {struct_name.upper()}_TYPE_H\n\n") + sf.write("#include \n\n") + for nm in namespaces: params_nm = [q for q in params if q.namespace == nm] From 56729e23eec650f17e087943701ce12a7f950d3a Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 19 Dec 2023 17:11:15 -0500 Subject: [PATCH 3/3] add the queries --- Source/driver/Castro.H | 8 ++++++-- Source/driver/Castro.cpp | 2 ++ Source/driver/parse_castro_params.py | 6 ++++-- Util/scripts/write_probdata.py | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Source/driver/Castro.H b/Source/driver/Castro.H index 1c8b7725f8..5edfa811d3 100644 --- a/Source/driver/Castro.H +++ b/Source/driver/Castro.H @@ -1199,6 +1199,12 @@ public: static Vector > data_logs; static Vector > problem_data_logs; +/// +/// runtime parameters +// + static params_t params; + + protected: @@ -1409,8 +1415,6 @@ protected: static int lastDtPlotLimited; static amrex::Real lastDtBeforePlotLimiting; - static params_t params; - int in_retry; int num_subcycles_taken; diff --git a/Source/driver/Castro.cpp b/Source/driver/Castro.cpp index 8c6724d621..7b10b86912 100644 --- a/Source/driver/Castro.cpp +++ b/Source/driver/Castro.cpp @@ -76,6 +76,8 @@ int Castro::NUM_GROW_SRC = -1; int Castro::lastDtPlotLimited = 0; Real Castro::lastDtBeforePlotLimiting = 0.0; +params_t Castro::params; + Real Castro::num_zones_advanced = 0.0; Vector Castro::source_names; diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index 3fe6ac6799..aedeea6624 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -206,13 +206,15 @@ def write_headers(params, out_directory, struct_name): 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("C++")) + cq.write(p.get_query_string()) + cq.write(p.get_query_struct_string(struct_name=struct_name, class_name="Castro")) 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("C++")) + cq.write(p.get_query_string()) + cq.write(p.get_query_struct_string(struct_name=struct_name, class_name="Castro")) cq.write("\n") cq.write("#endif\n") cq.write("\n") diff --git a/Util/scripts/write_probdata.py b/Util/scripts/write_probdata.py index 2e44621cdc..68cb716aac 100755 --- a/Util/scripts/write_probdata.py +++ b/Util/scripts/write_probdata.py @@ -244,7 +244,7 @@ def write_probin(prob_param_files, cxx_prefix): fout.write(f" {p.get_default_string()}") if p.in_namelist: - fout.write(f" {p.get_query_string('C++')}") + fout.write(f" {p.get_query_string()}") fout.write("\n") fout.write(" }\n")