Skip to content

Commit

Permalink
more struct support
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale committed Dec 19, 2023
1 parent b3cbc19 commit e077152
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
55 changes: 39 additions & 16 deletions util/build_scripts/runtime_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion util/build_scripts/write_probin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e077152

Please sign in to comment.