Skip to content

Commit

Permalink
Merge branch 'development' into clang-tidy-gravity
Browse files Browse the repository at this point in the history
  • Loading branch information
zingale authored Mar 26, 2024
2 parents bc4c68c + 760ecc4 commit 2484b73
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 88 deletions.
2 changes: 2 additions & 0 deletions Exec/Make.auto_source
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion Source/diffusion/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 0 additions & 7 deletions Source/diffusion/diffusion_params.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion Source/driver/Make.package
Original file line number Diff line number Diff line change
@@ -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 += runtime_params.cpp
CEXE_sources += Castro_advance.cpp
CEXE_sources += Castro_advance_ctu.cpp
ifeq ($(USE_TRUE_SDC), TRUE)
Expand Down
2 changes: 1 addition & 1 deletion Source/driver/castro_limits.H
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef CASTRO_LIMITS_H
#define CASTRO_LIMITS_H

#define MAX_LEV 15
constexpr int MAX_LEV{15};

#endif
100 changes: 58 additions & 42 deletions Source/driver/parse_castro_params.py
Original file line number Diff line number Diff line change
@@ -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 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.
parameters have the format:
Expand Down Expand Up @@ -41,16 +41,16 @@
-- 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++
-- name_job_info_tests.H
this tests the current value against the default and outputs
into a file
-- runtime_params.cpp
has the actual definition of the variables (without extern)
"""

import argparse
Expand Down Expand Up @@ -129,45 +129,19 @@ 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

# find all the namespaces
namespaces = {q.namespace for q in params}
namespaces = sorted({q.namespace for q in params})

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)

# 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")
Expand Down Expand Up @@ -238,7 +212,44 @@ def write_headers(params, out_directory, struct_name):

jo.close()

# 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 <AMReX_REAL.H>\n")
pf.write("#include <AMReX_Gpu.H>\n")
pf.write("#include <castro_limits.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")

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
# 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:
Expand All @@ -255,20 +266,25 @@ def write_headers(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 = sorted(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
Expand All @@ -295,7 +311,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()
6 changes: 0 additions & 6 deletions Source/driver/runparams_defaults.cpp

This file was deleted.

5 changes: 1 addition & 4 deletions Source/driver/sum_integrated_quantities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,7 @@ Castro::sum_integrated_quantities ()

log << std::setw(intwidth) << timestep;

if (time == 0.0_rt) {
log << std::fixed;
}
else if (time < 1.e-4_rt || time > 1.e4_rt) {
if (time < 1.e-4_rt || time > 1.e4_rt) {
log << std::scientific;
}
else {
Expand Down
1 change: 0 additions & 1 deletion Source/gravity/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions Source/gravity/gravity_params.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion Source/mhd/Castro_mhd.H
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

void
consup_mhd(const amrex::Box& bx, const Real dt,
amrex::Array4<amrex::Real> const& update,
amrex::Array4<amrex::Real> const& U_new,
amrex::Array4<amrex::Real const> const& flux0,
amrex::Array4<amrex::Real const> const& flux1,
amrex::Array4<amrex::Real const> const& flux2);
Expand Down
6 changes: 3 additions & 3 deletions Source/mhd/mhd_util.H
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ eos_soundspeed_mhd(Real& c, Real as, Real ca, Real bd) {

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void
qflux(Real* qflx, Real* flx, Real* q_zone) {
qflux(Real* qflx, const Real* flx, const Real* q_zone) {

// Calculate the C to P Jacobian applied to the fluxes

Expand Down Expand Up @@ -78,7 +78,7 @@ qflux(Real* qflx, Real* flx, Real* q_zone) {

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void
electric(Real* q_zone, Real& E_zone, const int comp) {
electric(const Real* q_zone, Real& E_zone, const int comp) {

// this takes the cell-center primitive state, q_zone, and computes the cell-center
// electric field, E_zone, using Faraday's law:
Expand All @@ -99,7 +99,7 @@ electric(Real* q_zone, Real& E_zone, const int comp) {

AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
void
ConsToPrim(Real* q_zone, Real* U_zone) {
ConsToPrim(Real* q_zone, const Real* U_zone) {

// calculate the primitive variables from the conserved
// U has NUM_STATE+3 components
Expand Down
1 change: 0 additions & 1 deletion Source/radiation/Make.package
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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.cpp
CEXE_sources += RadBndry.cpp
CEXE_sources += RadMultiGroup.cpp
Expand Down
9 changes: 0 additions & 9 deletions Source/radiation/radiation_params.cpp

This file was deleted.

3 changes: 3 additions & 0 deletions Source/sources/Castro_sources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,9 @@ Castro::post_advance_operators (Real time, Real dt)
{
advance_status status {};

amrex::ignore_unused(time);
amrex::ignore_unused(dt);

#ifndef TRUE_SDC
#ifdef REACTIONS
status = do_new_reactions(time, dt);
Expand Down
4 changes: 2 additions & 2 deletions Util/scripts/write_probdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def write_probin(prob_param_files, cxx_prefix):
size = p.size
if (size == "nspec"):
size = "NumSpec"
fout.write(f" for (int n = 0; n < {size}; n++) {{\n")
fout.write(f" problem::{p.name}[n] = {p.default_format(lang='C++')};\n")
fout.write(f" for (auto & e : problem::{p.name}) {{\n")
fout.write(f" e = {p.default_format(lang='C++')};\n")
fout.write(f" }}\n")
else:
fout.write(f" {p.get_default_string()}")
Expand Down

0 comments on commit 2484b73

Please sign in to comment.