MCPcopy Create free account
hub / github.com/AMReX-Astro/Castro / write_probin

Function write_probin

Util/scripts/write_probdata.py:149–251  ·  view source on GitHub ↗

write_probin will read through the list of parameter files and C++ header and source files to manage the runtime parameters

(prob_param_files, cxx_prefix)

Source from the content-addressed store, hash-verified

147
148
149def write_probin(prob_param_files, cxx_prefix):
150 """write_probin will read through the list of parameter files and
151 C++ header and source files to manage the runtime parameters"""
152
153 params = []
154
155 print(" ")
156 print(f"write_probdata.py: creating prob_param C++ files")
157
158 # read the parameters defined in the parameter files
159
160 for f in prob_param_files:
161 err = parse_param_file(params, f)
162 if err:
163 abort(f"Error parsing {f}")
164
165
166 # now handle the C++ -- we need to write a header and a .cpp file
167 # for the parameters
168
169 cxx_base = os.path.basename(cxx_prefix)
170
171 ofile = f"{cxx_prefix}_parameters.H"
172 with open(ofile, "w") as fout:
173 fout.write(CXX_HEADER)
174
175 fout.write(f" void init_{cxx_base}_parameters();\n\n")
176
177 fout.write(" namespace problem {\n\n")
178
179 for p in params:
180 if p.dtype == "string":
181 fout.write(f" extern std::string {p.name};\n\n")
182 else:
183 if p.is_array():
184 if p.size == "nspec":
185 fout.write(f" extern AMREX_GPU_MANAGED {p.get_cxx_decl()} {p.name}[NumSpec];\n\n")
186 else:
187 fout.write(f" extern AMREX_GPU_MANAGED {p.get_cxx_decl()} {p.name}[{p.size}];\n\n")
188 else:
189 fout.write(f" extern AMREX_GPU_MANAGED {p.get_cxx_decl()} {p.name};\n\n")
190
191 fout.write(" }\n\n")
192
193 fout.write(CXX_FOOTER)
194
195 # now the C++ job_info tests
196 ofile = f"{cxx_prefix}_job_info_tests.H"
197 with open(ofile, "w") as fout:
198 for p in params:
199 if not p.is_array():
200 if p.in_namelist:
201 fout.write(p.get_job_info_test())
202
203 # now the C++ initialization routines
204 ofile = f"{cxx_prefix}_parameters.cpp"
205 with open(ofile, "w") as fout:
206 fout.write(f"#include <{cxx_base}_parameters.H>\n")

Callers 1

mainFunction · 0.85

Calls 2

parse_param_fileFunction · 0.85
abortFunction · 0.85

Tested by

no test coverage detected