Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync up with the changes to the Microphysics python build scripts #312

Merged
merged 1 commit into from Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions Exec/Make.Maestro
Expand Up @@ -213,15 +213,16 @@ $(MAESTROEX_AUTO_SOURCE_DIR)/extern_parameters.H: $(PROBIN_PARAMETERS) $(PROBIN_
# MAESTROeX C++ parameters
#------------------------------------------------------------------------------

AUTO_BUILD_SOURCES += $(MAESTROEX_AUTO_SOURCE_DIR)/maestro_params.H

CPP_PARAMETERS := $(TOP)/Source/param/_cpp_parameters
METH_PARAMS_TEMPLATE := $(TOP)/Source/param/meth_params.template

$(MAESTROEX_AUTO_SOURCE_DIR)/meth_params.F90: $(CPP_PARAMETERS) $(METH_PARAMS_TEMPLATE)
$(MAESTROEX_AUTO_SOURCE_DIR)/maestro_params.H: $(CPP_PARAMETERS)
@if [ ! -d $(MAESTROEX_AUTO_SOURCE_DIR) ]; then mkdir -p $(MAESTROEX_AUTO_SOURCE_DIR); fi
PYTHONPATH=$(MICROPHYSICS_HOME)/util/build_scripts $(TOP)/Source/param/parse_maestro_params.py -m $(METH_PARAMS_TEMPLATE) -o $(MAESTROEX_AUTO_SOURCE_DIR) $(CPP_PARAMETERS)
PYTHONPATH=$(MICROPHYSICS_HOME)/util/build_scripts $(TOP)/Source/param/parse_maestro_params.py -o $(MAESTROEX_AUTO_SOURCE_DIR) $(CPP_PARAMETERS)

# for debugging
test_cxx_params: $(MAESTROEX_AUTO_SOURCE_DIR)/meth_params.F90
test_cxx_params: $(MAESTROEX_AUTO_SOURCE_DIR)/maestro_params.H

#------------------------------------------------------------------------------
# state variable info
Expand Down
4 changes: 0 additions & 4 deletions Source/MaestroSetup.cpp
Expand Up @@ -27,10 +27,6 @@ void Maestro::Setup() {
// read in C++ parameters in maestro_queries.H using ParmParse pp("maestro");
ReadParameters();

// read in F90 parameters in meth_params.F90 that are defined
// in _cpp_parameters
read_method_params();

// Initialize the runtime parameters for any of the external microphysics
// (in extern.f90)
ExternInit();
Expand Down
1 change: 0 additions & 1 deletion Source/Make.package
Expand Up @@ -69,5 +69,4 @@ CEXE_headers += MaestroUtil.H
CEXE_headers += PhysBCFunctMaestro.H
CEXE_headers += state_indices.H

F90EXE_sources += meth_params.F90
FEXE_headers += Maestro_F.H
88 changes: 3 additions & 85 deletions Source/param/parse_maestro_params.py
@@ -1,10 +1,8 @@
#!/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 Maestro's C++ routines and (optionally) the Fortran routines
through meth_params_module.
"""This script parses the list of C++ runtime parameters and writes
the necessary header files to make them available in Maestro's C++
routines and (optionally)

parameters have the format:

Expand Down Expand Up @@ -54,12 +52,6 @@
this tests the current value against the default and outputs
into a file

we write out a single copy of:

-- meth_params.F90
does the parmparse query to override the default in Fortran,
and sets a number of other parameters specific to the F90 routinse

"""

import argparse
Expand All @@ -80,76 +72,6 @@
// mk_params.sh\n
"""

def write_meth_module(plist, meth_template, out_directory):
"""this writes the meth_params_module, starting with the meth_template
and inserting the runtime parameter declaration in the correct
place
"""

try:
mt = open(meth_template, "r")
except IOError:
sys.exit("invalid template file")

try:
mo = open(f"{out_directory}/meth_params.F90", "w")
except IOError:
sys.exit("unable to open meth_params.F90 for writing")

mo.write(FWARNING)

param_decls = [p.get_f90_decl_string() for p in plist if p.in_fortran == 1]
params = [p for p in plist if p.in_fortran == 1]

decls = ""

for p in param_decls:
decls += f" {p}"

for line in mt:
if line.find("@@f90_declarations@@") > 0:
mo.write(decls)

elif line.find("@@set_maestro_params@@") >= 0:

namespaces = {q.namespace for q in params}
print("namespaces: ", namespaces)
for nm in namespaces:
params_nm = [q for q in params if q.namespace == nm]

for p in params_nm:
mo.write(p.get_f90_default_string())

mo.write("\n")

mo.write(f' call amrex_parmparse_build(pp, "{nm}")\n')

for p in params_nm:
mo.write(p.get_query_string("F90"))

mo.write(' call amrex_parmparse_destroy(pp)\n')

mo.write("\n\n")

elif line.find("@@free_maestro_params@@") >= 0:

params_free = [q for q in params if q.in_fortran == 1]

for p in params_free:
if p.dtype != "string":
mo.write(f" if (allocated({p.name})) then\n")
mo.write(f" deallocate({p.name})\n")
mo.write(" end if\n")

mo.write("\n\n")

else:
mo.write(line)

mo.close()
mt.close()


def parse_params(infile, meth_template, out_directory):

params = []
Expand Down Expand Up @@ -221,7 +143,6 @@ def parse_params(infile, meth_template, out_directory):
cpp_var_name=cpp_var_name,
namespace=namespace,
debug_default=debug_default,
in_fortran=in_fortran,
ifdef=ifdef))

# output
Expand Down Expand Up @@ -310,9 +231,6 @@ def parse_params(infile, meth_template, out_directory):

jo.close()

# write the Fortran module
write_meth_module(params, meth_template, out_directory)


def main():
"""the main driver"""
Expand Down