Skip to content

Commit

Permalink
Updates TimeStepManager (#273)
Browse files Browse the repository at this point in the history
* updates coordinator to match changes in TSM
* adds scripts, makes plist names consistent (e.g. all others use timestep)
* minor fixes for converter, better comments to show what is going on in BDF, tweaks to test_manager to write out failed tests
* changes all time step --> timestep, revisions on timestep control for putting responsibility for recovering from event-based dt reductions on TimestepController
* changes to BDF API to allow it to be constructed in setup, not in init, and to alloc less memory
* time step --> timestep
* moves ats-regression-tests pointer
  • Loading branch information
ecoon authored Oct 18, 2024
1 parent 3e0d817 commit 5cdea9a
Show file tree
Hide file tree
Showing 69 changed files with 380 additions and 327 deletions.
2 changes: 1 addition & 1 deletion docs/documentation/source/developer/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ guidelines when using these levels in your code:

- `Teuchos::VERB_NONE` Really, don't ever use this. Don't do output at all.

- `Teuchos::VERB_LOW` Should be used by time step-level work only. It
- `Teuchos::VERB_LOW` Should be used by timestep-level work only. It
should print a message saying "start a timestep" and the result of
that timestep (success/fail). So really almost exclusively in a
PK's AdvanceStep() and ValidStep() methods, if they exist.
Expand Down
34 changes: 17 additions & 17 deletions docs/tutorial/session5-sampling/test7-v_fwd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<Parameter name="primary variable" type="string" value="precipitation_snow" />
<Parameter name="conserved quantity key" type="string" value="precipitation_snow" />
<Parameter name="domain name" type="string" value="surface" />
<Parameter name="initial time step" type="double" value="86400.0" />
<Parameter name="initial timestep" type="double" value="86400.0" />
<Parameter name="upwind conductivity method" type="string" value="upwind by potential difference" />
<ParameterList name="precipitation function" type="ParameterList">
<ParameterList name="function-tabular" type="ParameterList">
Expand Down Expand Up @@ -164,10 +164,10 @@
<ParameterList name="timestep controller smarter parameters" type="ParameterList">
<Parameter name="max iterations" type="int" value="18" />
<Parameter name="min iterations" type="int" value="10" />
<Parameter name="time step reduction factor" type="double" value="0.25" />
<Parameter name="time step increase factor" type="double" value="1.5" />
<Parameter name="max time step" type="double" value="100000000.0" />
<Parameter name="min time step" type="double" value="1e-10" />
<Parameter name="timestep reduction factor" type="double" value="0.25" />
<Parameter name="timestep increase factor" type="double" value="1.5" />
<Parameter name="max timestep" type="double" value="100000000.0" />
<Parameter name="min timestep" type="double" value="1e-10" />
<Parameter name="growth wait after fail" type="int" value="2" />
<Parameter name="count before increasing increase factor" type="int" value="2" />
</ParameterList>
Expand Down Expand Up @@ -250,10 +250,10 @@
<ParameterList name="timestep controller smarter parameters" type="ParameterList">
<Parameter name="max iterations" type="int" value="18" />
<Parameter name="min iterations" type="int" value="10" />
<Parameter name="time step reduction factor" type="double" value="0.5" />
<Parameter name="time step increase factor" type="double" value="1.5" />
<Parameter name="max time step" type="double" value="100000000.0" />
<Parameter name="min time step" type="double" value="1e-10" />
<Parameter name="timestep reduction factor" type="double" value="0.5" />
<Parameter name="timestep increase factor" type="double" value="1.5" />
<Parameter name="max timestep" type="double" value="100000000.0" />
<Parameter name="min timestep" type="double" value="1e-10" />
<Parameter name="growth wait after fail" type="int" value="2" />
<Parameter name="count before increasing increase factor" type="int" value="2" />
</ParameterList>
Expand All @@ -270,8 +270,8 @@
<Parameter name="primary variable" type="string" value="snow_depth" />
<Parameter name="conserved quantity key" type="string" value="snow_depth" />
<Parameter name="domain name" type="string" value="surface" />
<Parameter name="initial time step" type="double" value="86400.0" />
<Parameter name="max time step" type="double" value="86400.0" />
<Parameter name="initial timestep" type="double" value="86400.0" />
<Parameter name="max timestep" type="double" value="86400.0" />
<Parameter name="snow-ground transitional depth" type="double" value="0.05" />
<Parameter name="wind speed reference height [m]" type="double" value="2.0" />
<ParameterList name="VerboseObject" type="ParameterList">
Expand Down Expand Up @@ -360,9 +360,9 @@
<Parameter name="source term" type="bool" value="true" />
<Parameter name="clobber surface rel perm" type="bool" value="true" />
<Parameter name="limit correction to pressure change [Pa]" type="double" value="400000.0" />
<Parameter name="max valid change in saturation in a time step [-]" type="double" value="0.1" />
<Parameter name="max valid change in ice saturation in a time step [-]" type="double" value="0.1" />
<Parameter name="initial time step" type="double" value="86400.0" />
<Parameter name="max valid change in saturation in a timestep [-]" type="double" value="0.1" />
<Parameter name="max valid change in ice saturation in a timestep [-]" type="double" value="0.1" />
<Parameter name="initial timestep" type="double" value="86400.0" />
<Parameter name="relative permeability method" type="string" value="upwind with Darcy flux" />
<Parameter name="permeability rescaling" type="double" value="10000000.0" />
<Parameter name="debug cells" type="Array(int)" value="{3423}" />
Expand Down Expand Up @@ -440,7 +440,7 @@
<Parameter name="primary variable" type="string" value="surface-pressure" />
<Parameter name="domain name" type="string" value="surface" />
<Parameter name="source term" type="bool" value="true" />
<Parameter name="initial time step" type="double" value="86400.0" />
<Parameter name="initial timestep" type="double" value="86400.0" />
<ParameterList name="VerboseObject" type="ParameterList">
<Parameter name="Verbosity Level" type="string" value="high" />
</ParameterList>
Expand Down Expand Up @@ -486,7 +486,7 @@
<Parameter name="source term" type="bool" value="false" />
<Parameter name="supress advective terms in preconditioner" type="bool" value="true" />
<Parameter name="limit correction to temperature change [K]" type="double" value="1.0" />
<Parameter name="initial time step" type="double" value="86400.0" />
<Parameter name="initial timestep" type="double" value="86400.0" />
<Parameter name="debug cells" type="Array(int)" value="{3423}" />
<ParameterList name="VerboseObject" type="ParameterList">
<Parameter name="Verbosity Level" type="string" value="high" />
Expand Down Expand Up @@ -573,7 +573,7 @@
<Parameter name="flux key" type="string" value="surface-mass_flux" />
<Parameter name="supress advective terms in preconditioner" type="bool" value="false" />
<Parameter name="upwind conductivity method" type="string" value="arithmetic mean" />
<Parameter name="initial time step" type="double" value="86400.0" />
<Parameter name="initial timestep" type="double" value="86400.0" />
<ParameterList name="VerboseObject" type="ParameterList">
<Parameter name="Verbosity Level" type="string" value="high" />
</ParameterList>
Expand Down
4 changes: 2 additions & 2 deletions src/constitutive_relations/eos/vapor_pressure_water.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ VaporPressureWater::SaturatedVaporPressure(double T)
{
if (T < 100. || T > 373.0) {
std::cout << "Invalid temperature, T = " << T << std::endl;
Exceptions::amanzi_throw(Errors::CutTimeStep());
Exceptions::amanzi_throw(Errors::CutTimestep());
}
return 100.0 * exp(ka0_ + ka_ / T + (kb_ + kc_ * T) * T + kd_ * log(T));
};
Expand All @@ -45,7 +45,7 @@ VaporPressureWater::DSaturatedVaporPressureDT(double T)
{
if (T < 100. || T > 373.0) {
std::cout << "Invalid temperature, T = " << T << std::endl;
Errors::Message m("Cut time step");
Errors::Message m("Cut timestep");
Exceptions::amanzi_throw(m);
}
return SaturatedVaporPressure(T) * (-ka_ / (T * T) + kb_ + 2.0 * kc_ * T + kd_ / T);
Expand Down
2 changes: 1 addition & 1 deletion src/constitutive_relations/eos/viscosity_water.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ViscosityWater::Viscosity(double T)

if (visc < 1.e-16) {
std::cout << "Invalid temperature, T = " << T << std::endl;
Exceptions::amanzi_throw(Errors::CutTimeStep());
Exceptions::amanzi_throw(Errors::CutTimestep());
}
return visc;
};
Expand Down
2 changes: 1 addition & 1 deletion src/executables/ats_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ ATSDriver::cycle_driver()
} // while not finished

#if !DEBUG_MODE
} catch (Errors::TimeStepCrash& e) {
} catch (Errors::TimestepCrash& e) {
// write one more vis for help debugging
S_->advance_cycle(Amanzi::Tags::NEXT);
visualize(true); // force vis
Expand Down
2 changes: 1 addition & 1 deletion src/executables/ats_driver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ simulation, including starting and ending times and restart options.
Note: Either `"end cycle`" or `"end time`" are required, and if
both are present, the simulation will stop with whichever arrives
first. An `"end cycle`" is commonly used to ensure that, in the case
of a time step crash, we do not continue on forever spewing output.
of a timestep crash, we do not continue on forever spewing output.
Example:
Expand Down
19 changes: 9 additions & 10 deletions src/executables/coordinator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,17 @@ Coordinator::Coordinator(const Teuchos::RCP<Teuchos::ParameterList>& plist,
}
}

// create the time step manager, register assorted timestep control events
tsm_ = Teuchos::rcp(new Amanzi::TimeStepManager());
checkpoint_->RegisterWithTimeStepManager(tsm_.ptr());
for (const auto& obs : observations_) obs->RegisterWithTimeStepManager(tsm_.ptr());
for (const auto& vis : visualization_) vis->RegisterWithTimeStepManager(tsm_.ptr());
// create the timestep manager, register assorted timestep control events
tsm_ = Teuchos::rcp(new Amanzi::Utils::TimeStepManager(coordinator_list_->sublist("timestep manager")));
checkpoint_->RegisterWithTimeStepManager(*tsm_);
for (const auto& obs : observations_) obs->RegisterWithTimeStepManager(*tsm_);
for (const auto& vis : visualization_) vis->RegisterWithTimeStepManager(*tsm_);
tsm_->RegisterTimeEvent(t1_);

if (coordinator_list_->isSublist("required times")) {
Teuchos::ParameterList& sublist = coordinator_list_->sublist("required times");
Amanzi::IOEvent pause_times(sublist);
pause_times.RegisterWithTimeStepManager(tsm_.ptr());
Amanzi::Utils::IOEvent pause_times(sublist);
pause_times.RegisterWithTimeStepManager(*tsm_);
}
}
if (vo_->os_OK(Teuchos::VERB_LOW)) {
Expand Down Expand Up @@ -502,8 +502,8 @@ Coordinator::initializeFromPlist_()
}
t1_ = units.ConvertTime(t1_, t1_units, "s", success);

max_dt_ = coordinator_list_->get<double>("max time step size [s]", 1.0e99);
min_dt_ = coordinator_list_->get<double>("min time step size [s]", 1.0e-12);
max_dt_ = coordinator_list_->get<double>("max timestep size [s]", 1.0e99);
min_dt_ = coordinator_list_->get<double>("min timestep size [s]", 1.0e-12);
cycle0_ = coordinator_list_->get<int>("start cycle", -1);
cycle1_ = coordinator_list_->get<int>("end cycle", -1);
duration_ = coordinator_list_->get<double>("wallclock duration [hrs]", -1.0);
Expand Down Expand Up @@ -554,7 +554,6 @@ Coordinator::advance()
double t_new = S_->get_time(Amanzi::Tags::NEXT);

bool fail = pk_->AdvanceStep(t_old, t_new, false);
if (!fail) fail |= !pk_->ValidStep();

// write state post-advance, if extreme
WriteStateStatistics(*S_, *vo_, Teuchos::VERB_EXTREME);
Expand Down
6 changes: 4 additions & 2 deletions src/executables/coordinator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "VerboseObject.hh"

namespace Amanzi {
namespace Utils {
class TimeStepManager;
} // namespace Utils
class Visualization;
class Checkpoint;
class State;
Expand Down Expand Up @@ -66,8 +68,8 @@ class Coordinator {
Teuchos::RCP<Amanzi::State> S_;
Teuchos::RCP<Amanzi::TreeVector> soln_;

// time step manager
Teuchos::RCP<Amanzi::TimeStepManager> tsm_;
// timestep manager
Teuchos::RCP<Amanzi::Utils::TimeStepManager> tsm_;

// misc setup information
Teuchos::RCP<Teuchos::ParameterList> plist_;
Expand Down
11 changes: 6 additions & 5 deletions src/executables/test/executable_coupled_water1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@
</ParameterList>
</ParameterList>
<ParameterList name="timestep controller smarter parameters" type="ParameterList">
<Parameter name="initial timestep [s]" type="double" value="1" />
<Parameter name="max iterations" type="int" value="18" />
<Parameter name="min iterations" type="int" value="10" />
<Parameter name="time step reduction factor" type="double" value="0.5" />
<Parameter name="time step increase factor" type="double" value="1.25" />
<Parameter name="max time step" type="double" value="600" />
<Parameter name="min time step" type="double" value="1e-10" />
<Parameter name="timestep reduction factor" type="double" value="0.5" />
<Parameter name="timestep increase factor" type="double" value="1.25" />
<Parameter name="max timestep" type="double" value="600" />
<Parameter name="min timestep" type="double" value="1e-10" />
<Parameter name="growth wait after fail" type="int" value="2" />
<Parameter name="count before increasing increase factor" type="int" value="2" />
</ParameterList>
Expand All @@ -127,7 +128,7 @@
<Parameter name="primary variable key" type="string" value="pressure" />
<Parameter name="relative permeability method" type="string" value="upwind with Darcy flux" />
<Parameter name="permeability rescaling" type="double" value="10000000" />
<Parameter name="max valid change in saturation in a time step [-]" type="double" value="0.1" />
<Parameter name="max valid change in saturation in a timestep [-]" type="double" value="0.1" />
<Parameter name="debug cells" type="Array(int)" value="{0}" />
<ParameterList name="verbose object" type="ParameterList">
<Parameter name="verbosity level" type="string" value="high" />
Expand Down
11 changes: 6 additions & 5 deletions src/executables/test/executable_coupled_water2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@
</ParameterList>
</ParameterList>
<ParameterList name="timestep controller smarter parameters" type="ParameterList">
<Parameter name="initial timestep [s]" type="double" value="1" />
<Parameter name="max iterations" type="int" value="18" />
<Parameter name="min iterations" type="int" value="10" />
<Parameter name="time step reduction factor" type="double" value="0.5" />
<Parameter name="time step increase factor" type="double" value="1.25" />
<Parameter name="max time step" type="double" value="600" />
<Parameter name="min time step" type="double" value="1e-10" />
<Parameter name="timestep reduction factor" type="double" value="0.5" />
<Parameter name="timestep increase factor" type="double" value="1.25" />
<Parameter name="max timestep" type="double" value="600" />
<Parameter name="min timestep" type="double" value="1e-10" />
<Parameter name="growth wait after fail" type="int" value="2" />
<Parameter name="count before increasing increase factor" type="int" value="2" />
</ParameterList>
Expand All @@ -127,7 +128,7 @@
<Parameter name="primary variable key" type="string" value="pressure" />
<Parameter name="relative permeability method" type="string" value="upwind with Darcy flux" />
<Parameter name="permeability rescaling" type="double" value="10000000" />
<Parameter name="max valid change in saturation in a time step [-]" type="double" value="0.1" />
<Parameter name="max valid change in saturation in a timestep [-]" type="double" value="0.1" />
<Parameter name="debug cells" type="Array(int)" value="{0}" />
<ParameterList name="verbose object" type="ParameterList">
<Parameter name="verbosity level" type="string" value="high" />
Expand Down
11 changes: 6 additions & 5 deletions src/executables/test/executable_coupled_water3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@
</ParameterList>
</ParameterList>
<ParameterList name="timestep controller smarter parameters" type="ParameterList">
<Parameter name="initial timestep [s]" type="double" value="1" />
<Parameter name="max iterations" type="int" value="18" />
<Parameter name="min iterations" type="int" value="10" />
<Parameter name="time step reduction factor" type="double" value="0.5" />
<Parameter name="time step increase factor" type="double" value="1.25" />
<Parameter name="max time step" type="double" value="600" />
<Parameter name="min time step" type="double" value="1e-10" />
<Parameter name="timestep reduction factor" type="double" value="0.5" />
<Parameter name="timestep increase factor" type="double" value="1.25" />
<Parameter name="max timestep" type="double" value="600" />
<Parameter name="min timestep" type="double" value="1e-10" />
<Parameter name="growth wait after fail" type="int" value="2" />
<Parameter name="count before increasing increase factor" type="int" value="2" />
</ParameterList>
Expand All @@ -127,7 +128,7 @@
<Parameter name="primary variable key" type="string" value="pressure" />
<Parameter name="relative permeability method" type="string" value="upwind with Darcy flux" />
<Parameter name="permeability rescaling" type="double" value="10000000" />
<Parameter name="max valid change in saturation in a time step [-]" type="double" value="0.1" />
<Parameter name="max valid change in saturation in a timestep [-]" type="double" value="0.1" />
<Parameter name="debug cells" type="Array(int)" value="{0}" />
<ParameterList name="verbose object" type="ParameterList">
<Parameter name="verbosity level" type="string" value="high" />
Expand Down
10 changes: 5 additions & 5 deletions src/pks/biogeochemistry/bgc_simple/PFT.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ class PFT {
double Jmax25; //umol electron/m2 leaf/s
double GDDleafon; //growing degree days for leaf on
double GDD; //growing degree days
double mResp; //maintanence respiration, kg C/grid cell /time step
double gResp; //maintanence respiration, kg C/grid cell /time step
double mResp; //maintanence respiration, kg C/grid cell /timestep
double gResp; //maintanence respiration, kg C/grid cell /timestep
double GDDbase; //growing degree days base temperature
double annNPP;
double GPP; //gross primary proeduction; kg C/grid cell /time step
double NPP; //net primary proeduction; kg C/grid cell/time step
double ET; //Transpiration; kg water/time step/grid cell
double GPP; //gross primary proeduction; kg C/grid cell /timestep
double NPP; //net primary proeduction; kg C/grid cell/timestep
double ET; //Transpiration; kg water/timestep/grid cell
int leafstatus; //1=off; 2==on
bool evergreen; //1=yes; 0=no
double LUE; //light use efficiency
Expand Down
2 changes: 1 addition & 1 deletion src/pks/biogeochemistry/bgc_simple/bgc_simple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ BGCSimple::BGCSimple(Teuchos::ParameterList& pk_tree,
Keys::readKey(*plist_, domain_surf_, "total leaf area index", "total_leaf_area_index");

// initial timestep
dt_ = plist_->get<double>("initial time step", 1.);
dt_ = plist_->get<double>("initial timestep", 1.);

// Create the additional, non-managed data structures
num_pools_ = plist_->get<int>("number of carbon pools", 7);
Expand Down
2 changes: 1 addition & 1 deletion src/pks/biogeochemistry/bgc_simple/bgc_simple.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ that build_columns in the subsurface Mesh_ spec has been supplied.
.. _bgc-simple-spec:
.. admonition:: bgc-simple-spec
* `"initial time step`" ``[double]`` **1.0** Initial time step size `[s]`
* `"initial timestep`" ``[double]`` **1.0** Initial timestep size `[s]`
* `"number of carbon pools`" ``[int]`` **7** Unclear whether this can actually change?
Expand Down
Loading

0 comments on commit 5cdea9a

Please sign in to comment.