Skip to content

Commit

Permalink
add function for setting growth factor
Browse files Browse the repository at this point in the history
  • Loading branch information
atmyers committed Jun 30, 2023
1 parent 9c256b1 commit 6a4df9b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
6 changes: 6 additions & 0 deletions Src/Base/AMReX_PODVector.H
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ namespace amrex
{
extern AMREX_EXPORT Real growth_factor;
inline Real GetGrowthFactor () { return growth_factor; }
inline void SetGrowthFactor (Real a_factor);

namespace detail
{
void ValidateUserInput ();
}

void Initialize ();
}
Expand Down
48 changes: 30 additions & 18 deletions Src/Base/AMReX_PODVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,40 @@ namespace amrex::VectorGrowthStrategy
{
Real growth_factor = 1.5_rt;

void Initialize () {
ParmParse pp("amrex");
pp.queryAdd("vector_growth_factor", growth_factor);

// clamp user input to reasonable values
constexpr Real min_factor = 1.05_rt;
constexpr Real max_factor = 4._rt;
// clamp user input to reasonable values
constexpr Real min_factor = 1.001_rt;
constexpr Real max_factor = 4._rt;

if (growth_factor < min_factor) {
if (Verbose()) {
amrex::Print() << "Warning: user-provided vector growth factor is too small."
<< " Clamping to " << min_factor << ". \n";
namespace detail
{
void ValidateUserInput() {
if (growth_factor < min_factor) {
if (Verbose()) {
amrex::Print() << "Warning: user-provided vector growth factor is too small."
<< " Clamping to " << min_factor << ". \n";
}
growth_factor = min_factor;
}
growth_factor = min_factor;
}

if (growth_factor > max_factor) {
if (Verbose()) {
amrex::Print() << "Warning: user-provided vector growth factor is too large."
<< " Clamping to " << max_factor << ". \n";
if (growth_factor > max_factor) {
if (Verbose()) {
amrex::Print() << "Warning: user-provided vector growth factor is too large."
<< " Clamping to " << max_factor << ". \n";
}
growth_factor = max_factor;
}
growth_factor = max_factor;
}
}

void Initialize () {
ParmParse pp("amrex");
pp.queryAdd("vector_growth_factor", growth_factor);

detail::ValidateUserInput();
}

void SetGrowthFactor (Real a_factor) {
growth_factor = a_factor;
detail::ValidateUserInput();
}
}

0 comments on commit 6a4df9b

Please sign in to comment.