From bc01cf291fe5d4a1474e0b16dd54f2b0cf97becc Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sun, 24 Mar 2024 16:30:12 -0400 Subject: [PATCH 01/10] remove static headers --- Source/diffusion/diffusion_params.cpp | 7 ------- Source/driver/Make.package | 2 +- Source/driver/runparams_defaults.cpp | 6 ------ Source/gravity/gravity_params.cpp | 9 --------- Source/radiation/Make.package | 1 + Source/radiation/radiation_params.cpp | 9 --------- 6 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 Source/diffusion/diffusion_params.cpp delete mode 100644 Source/driver/runparams_defaults.cpp delete mode 100644 Source/gravity/gravity_params.cpp delete mode 100644 Source/radiation/radiation_params.cpp 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..fc6e0896b3 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 += castro_params.cpp CEXE_sources += Castro_advance.cpp CEXE_sources += Castro_advance_ctu.cpp ifeq ($(USE_TRUE_SDC), TRUE) 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/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/radiation/Make.package b/Source/radiation/Make.package index 5a0023f4da..86ce992039 100644 --- a/Source/radiation/Make.package +++ b/Source/radiation/Make.package @@ -6,6 +6,7 @@ CEXE_sources += HypreMultiABec.cpp CEXE_sources += HypreABec.cpp CEXE_sources += Radiation.cpp CEXE_sources += radiation_params.cpp +CEXE_sources += radsolve_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 From 7dd8e15e12086064958dc71e628e10e30e4f10dd Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sun, 24 Mar 2024 19:06:47 -0400 Subject: [PATCH 02/10] almost there... --- Source/driver/parse_castro_params.py | 70 ++++++++++++++-------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index aedeea6624..914ed9050e 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 souce 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 + -- name_params.cpp + has the actual definition of the variables (without extern) + """ import argparse @@ -129,7 +129,7 @@ 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 @@ -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,6 +212,32 @@ def write_headers(params, out_directory, struct_name): jo.close() + # write the C++ source file that actually defines the parameters + try: + pf = open(f"{out_directory}/{nm}_params.cpp", "w", encoding="UTF-8") + except OSError: + sys.exit(f"unable to open {nm}_params.cpp") + + pf.write("#include \n") + pf.write("#include \n") + pf.write("#include \n\n") + pf.write(f"#include <{nm}_params.H>\n\n") + + 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 try: sf = open(f"{out_directory}/{struct_name}_type.H", "w", encoding="UTF-8") @@ -295,7 +295,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() From 63dfc98ecc277b9c515d48d0342f7132c9e55913 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Sun, 24 Mar 2024 19:25:40 -0400 Subject: [PATCH 03/10] this seems to work --- Exec/Make.auto_source | 2 ++ Source/diffusion/Make.package | 1 - Source/driver/Make.package | 2 +- Source/driver/parse_castro_params.py | 29 ++++++++++++++++++---------- Source/gravity/Make.package | 1 - Source/radiation/Make.package | 2 -- 6 files changed, 22 insertions(+), 15 deletions(-) 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/driver/Make.package b/Source/driver/Make.package index fc6e0896b3..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 += castro_params.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/parse_castro_params.py b/Source/driver/parse_castro_params.py index 914ed9050e..06b966b77f 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -212,16 +212,25 @@ def write_headers_and_source(params, out_directory, struct_name): jo.close() - # write the C++ source file that actually defines the parameters - try: - pf = open(f"{out_directory}/{nm}_params.cpp", "w", encoding="UTF-8") - except OSError: - sys.exit(f"unable to open {nm}_params.cpp") + # 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") - pf.write("#include \n") - pf.write("#include \n") - pf.write("#include \n\n") - pf.write(f"#include <{nm}_params.H>\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") @@ -236,7 +245,7 @@ def write_headers_and_source(params, out_directory, struct_name): pf.write("#endif\n") pf.write("}\n\n") - pf.close() + pf.close() # now write a single file that contains all of the parameter structs try: 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/radiation/Make.package b/Source/radiation/Make.package index 86ce992039..dfaa525b1b 100644 --- a/Source/radiation/Make.package +++ b/Source/radiation/Make.package @@ -5,8 +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_params.cpp CEXE_sources += RadSolve.cpp CEXE_sources += RadBndry.cpp CEXE_sources += RadMultiGroup.cpp From 437ebcb19c190ebdcd2151a58b3953944519ef64 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Mon, 25 Mar 2024 07:58:00 -0400 Subject: [PATCH 04/10] fix spelling --- Source/driver/parse_castro_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index 06b966b77f..600284275c 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """This script parses the list of C++ runtime parameters and writes -the necessary header and souce files to make them available in +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. From 40b05b9c42715222469911e158d8d1177570d8d2 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Mon, 25 Mar 2024 08:37:08 -0400 Subject: [PATCH 05/10] sort the struct entries by type to reduce padding --- Source/driver/parse_castro_params.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index 600284275c..b4e7945ff6 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -248,6 +248,8 @@ def write_headers_and_source(params, out_directory, struct_name): 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: @@ -264,20 +266,25 @@ def write_headers_and_source(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 = 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 From bfb0df67613d362eaceaee31d04bf9e5e91f6535 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 26 Mar 2024 14:40:39 -0400 Subject: [PATCH 06/10] Update Source/driver/parse_castro_params.py Co-authored-by: Eric T. Johnson --- Source/driver/parse_castro_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index b4e7945ff6..6842052ae4 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -270,7 +270,7 @@ def write_headers_and_source(params, out_directory, struct_name): print("namespace = ", nm) for ifdef in ifdefs: params_if = [q for q in params_nm if q.ifdef == ifdef] - types = set(q.dtype for q in params_if) + types = sorted(set(q.dtype for q in params_if)) if ifdef is None: for tt in types: From 18372bbcea25ac41ff1f35a4d19536bd8f496fdf Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 26 Mar 2024 14:50:44 -0400 Subject: [PATCH 07/10] sort namespaces --- Source/driver/parse_castro_params.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index 6842052ae4..8812d1e381 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -136,7 +136,7 @@ def write_headers_and_source(params, out_directory, struct_name): # find all the namespaces namespaces = {q.namespace for q in params} - for nm in namespaces: + for nm in sorted(namespaces): params_nm = [q for q in params if q.namespace == nm] # sort by repr since None may be present @@ -227,7 +227,7 @@ def write_headers_and_source(params, out_directory, struct_name): pf.write(f"#include <{nm}_params.H>\n") pf.write("\n") - for nm in namespaces: + for nm in sorted(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) @@ -261,7 +261,7 @@ def write_headers_and_source(params, out_directory, struct_name): sf.write("#include \n\n") - for nm in namespaces: + for nm in sorted(namespaces): params_nm = [q for q in params if q.namespace == nm] # sort by repr since None may be present From c1dfb7b7b6557c1368650ee39c6e87a7042d840a Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 26 Mar 2024 14:51:39 -0400 Subject: [PATCH 08/10] fix name --- Source/driver/parse_castro_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index 8812d1e381..f2cc4d2472 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -48,7 +48,7 @@ this tests the current value against the default and outputs into a file - -- name_params.cpp + -- runtime_params.cpp has the actual definition of the variables (without extern) """ From faa69e2fe2fea9eec181f3ab2d792b324c6cb278 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 26 Mar 2024 15:03:30 -0400 Subject: [PATCH 09/10] Update Source/driver/parse_castro_params.py Co-authored-by: Eric T. Johnson --- Source/driver/parse_castro_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index f2cc4d2472..9436a592f1 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -134,7 +134,7 @@ 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 sorted(namespaces): From 650e7e265c58248ac9dc214842df2cd664cf1173 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 26 Mar 2024 15:04:37 -0400 Subject: [PATCH 10/10] remove redundant sorts --- Source/driver/parse_castro_params.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/driver/parse_castro_params.py b/Source/driver/parse_castro_params.py index 9436a592f1..89f91a8ea7 100755 --- a/Source/driver/parse_castro_params.py +++ b/Source/driver/parse_castro_params.py @@ -136,7 +136,7 @@ def write_headers_and_source(params, out_directory, struct_name): # find all the namespaces namespaces = sorted({q.namespace for q in params}) - for nm in sorted(namespaces): + for nm in namespaces: params_nm = [q for q in params if q.namespace == nm] # sort by repr since None may be present @@ -227,7 +227,7 @@ def write_headers_and_source(params, out_directory, struct_name): pf.write(f"#include <{nm}_params.H>\n") pf.write("\n") - for nm in sorted(namespaces): + 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) @@ -261,7 +261,7 @@ def write_headers_and_source(params, out_directory, struct_name): sf.write("#include \n\n") - for nm in sorted(namespaces): + for nm in namespaces: params_nm = [q for q in params if q.namespace == nm] # sort by repr since None may be present