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

Add function for setting growth factor #3394

Merged
merged 1 commit into from
Jul 1, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}