Skip to content

Commit

Permalink
Merge pull request #70 from GRTLCollaboration/enhancement/default_par…
Browse files Browse the repository at this point in the history
…am_pp_table

GRParmParse: Add default values to the ParmParse table
  • Loading branch information
julianakwan authored Jul 19, 2024
2 parents 599ecf7 + 1fad2da commit 16b212b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Source/GRTeclynCore/BoundaryConditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ BoundaryConditions::params_t::params_t()
}

void BoundaryConditions::params_t::set_is_periodic(
const std::array<bool, AMREX_SPACEDIM> &a_is_periodic)
const std::array<int, AMREX_SPACEDIM> &a_is_periodic_int)
{
is_periodic = a_is_periodic;
FOR (idir)
{
is_periodic[idir] = static_cast<bool>(a_is_periodic_int[idir]);
if (!is_periodic[idir])
{
nonperiodic_boundaries_exist = true;
Expand Down Expand Up @@ -115,11 +115,11 @@ void BoundaryConditions::params_t::read_params(GRParmParse &pp)

// still load even if not contained, to ensure printout saying parameters
// were set to their default values
std::array<bool, AMREX_SPACEDIM> isPeriodic{};
pp.load("isPeriodic", isPeriodic, is_periodic);
std::array<int, AMREX_SPACEDIM> is_periodic_int{AMREX_D_DECL(1, 1, 1)};
pp.load("isPeriodic", is_periodic_int, is_periodic_int);
if (pp.contains("isPeriodic"))
{
set_is_periodic(isPeriodic);
set_is_periodic(is_periodic_int);
}

std::array<int, AMREX_SPACEDIM> hiBoundary{};
Expand Down
4 changes: 2 additions & 2 deletions Source/GRTeclynCore/BoundaryConditions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class BoundaryConditions
std::map<int, int> mixed_bc_vars_map;
int extrapolation_order{1};
params_t(); // sets the defaults
void
set_is_periodic(const std::array<bool, AMREX_SPACEDIM> &a_is_periodic);
void set_is_periodic(
const std::array<int, AMREX_SPACEDIM> &a_is_periodic_int);
void
set_hi_boundary(const std::array<int, AMREX_SPACEDIM> &a_hi_boundary);
void
Expand Down
11 changes: 7 additions & 4 deletions Source/utils/GRParmParse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ class GRParmParse : public amrex::ParmParse
/// Loads a value from the parameter file, if the value isn't defined it
/// sets to the supplied default
template <class data_t>
void load(const char *name, data_t &parameter,
const data_t default_value) const
void load(const char *name, data_t &parameter, const data_t default_value)
{
if (contains(name))
{
Expand All @@ -95,6 +94,8 @@ class GRParmParse : public amrex::ParmParse
else
{
parameter = default_value;
// Add the default value to the ParmParse table
this->queryAdd(name, parameter);
default_message(name, default_value);
}
}
Expand All @@ -103,7 +104,7 @@ class GRParmParse : public amrex::ParmParse
/// vector isn't defined, it is set to the supplied default
template <class data_t>
void load(const char *name, std::vector<data_t> &vector, const int num_comp,
const std::vector<data_t> &default_vector) const
const std::vector<data_t> &default_vector)
{
if (contains(name))
{
Expand All @@ -112,6 +113,8 @@ class GRParmParse : public amrex::ParmParse
else
{
vector = default_vector;
// Add the default value to the ParmParse table
this->queryAdd(name, vector);
default_message(name, default_vector);
}
}
Expand All @@ -120,7 +123,7 @@ class GRParmParse : public amrex::ParmParse
/// vector isn't defined it sets all components to the supplied default
template <class data_t>
void load(const char *name, std::vector<data_t> &vector, const int num_comp,
const data_t default_value) const
const data_t default_value)
{
load(name, vector, num_comp,
std::vector<data_t>(num_comp, default_value));
Expand Down

0 comments on commit 16b212b

Please sign in to comment.