diff --git a/util/build_scripts/runtime_parameters.py b/util/build_scripts/runtime_parameters.py index d44d18bed0..6480376765 100755 --- a/util/build_scripts/runtime_parameters.py +++ b/util/build_scripts/runtime_parameters.py @@ -99,7 +99,6 @@ def get_struct_entry(self, indent=4): ostr = "" - print("here: ", self.cpp_var_name) if not self.debug_default is None: ostr += "#ifdef AMREX_DEBUG\n" ostr += f"{' '*indent}{self.get_cxx_decl()} {self.cpp_var_name}{{{self.default_format(lang='C++', debug=True)}}};\n" @@ -128,27 +127,51 @@ def get_default_string(self): return ostr - def get_query_string(self, language): + def get_query_string(self): """this is the line that queries the ParmParse object to get the value of the runtime parameter from the inputs file. This goes into, e.g., castro_queries.H included into Castro.cpp""" ostr = "" - if language == "C++": - if self.is_array(): - # we need to create an amrex::Vector to read and then - # copy into our managed array - ostr += "\n" - ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format(lang='C++')});\n" - ostr += f" if (pp.queryarr(\"{self.name}\", {self.name}_tmp, 0, {self.size})) {{\n" - ostr += f" for (int n = 0; n < {self.size}; n++) {{\n" - ostr += f" {self.nm_pre}{self.cpp_var_name}[n] = {self.name}_tmp[n];\n" - ostr += " }\n\n" - ostr += " }\n\n" - else: - ostr += f"pp.query(\"{self.name}\", {self.nm_pre}{self.cpp_var_name});\n" + if self.is_array(): + # we need to create an amrex::Vector to read and then + # copy into our managed array + ostr += "\n" + ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format(lang='C++')});\n" + ostr += f" if (pp.queryarr(\"{self.name}\", {self.name}_tmp, 0, {self.size})) {{\n" + ostr += f" for (int n = 0; n < {self.size}; n++) {{\n" + ostr += f" {self.nm_pre}{self.cpp_var_name}[n] = {self.name}_tmp[n];\n" + ostr += " }\n\n" + ostr += " }\n\n" else: - sys.exit("invalid language choice in get_query_string") + ostr += f"pp.query(\"{self.name}\", {self.nm_pre}{self.cpp_var_name});\n" + + return ostr + + def get_query_struct_string(self, struct_name="params", class_name=None): + """this is the line that queries the ParmParse object to get + the value of the runtime parameter from the inputs file. + This is intended to use when we have a struct holding the runtime parameters, + and will have the form class_name::struct_name.namespace.param""" + + if class_name is None: + cname = "" + else: + cname = f"{class_name}::" + + ostr = "" + if self.is_array(): + # we need to create an amrex::Vector to read and then + # copy into our managed array + ostr += "\n" + ostr += f" amrex::Vector<{self.get_cxx_decl()}> {self.name}_tmp({self.size}, {self.default_format(lang='C++')});\n" + ostr += f" if (pp.queryarr(\"{self.name}\", {self.name}_tmp, 0, {self.size})) {{\n" + ostr += f" for (int n = 0; n < {self.size}; n++) {{\n" + ostr += f" {cname}{struct_name}.{self.namespace}{self.namespace_suffix}.{self.cpp_var_name}[n] = {self.name}_tmp[n];\n" + ostr += " }\n\n" + ostr += " }\n\n" + else: + ostr += f"pp.query(\"{self.name}\", {cname}{struct_name}.{self.namespace}{self.namespace_suffix}.{self.cpp_var_name});\n" return ostr diff --git a/util/build_scripts/write_probin.py b/util/build_scripts/write_probin.py index 1852b97c54..1b2371cc3d 100755 --- a/util/build_scripts/write_probin.py +++ b/util/build_scripts/write_probin.py @@ -255,7 +255,7 @@ def write_probin(param_files, fout.write(f" amrex::ParmParse pp(\"{nm}\");\n") for p in params_nm: fout.write(f" {p.get_default_string()}") - fout.write(f" {p.get_query_string('C++')}\n") + fout.write(f" {p.get_query_string()}\n") fout.write(" }\n") fout.write(" }\n")