Skip to content

Commit

Permalink
Add function for setting growth factor (#3394)
Browse files Browse the repository at this point in the history
Add the ability to set the custom vector growth factor through a
function, instead of only as a runtime input.

Also reducing the min allowed factor, as there seems to be demand for
that.
  • Loading branch information
atmyers committed Jul 1, 2023
1 parent e8120c8 commit 97724eb
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 97724eb

Please sign in to comment.