Advanced Multi-Physics (AMP)
On-Line Documentation
BDFIntegrator.h
Go to the documentation of this file.
1#ifndef included_BDFIntegrator_h_
2#define included_BDFIntegrator_h_
3
4#include <limits>
5#include <list>
6
7#include "AMP/time_integrators/ImplicitIntegrator.h"
8
9#ifdef ENABLE_RESTART
10class RestartData;
11#endif
12
13namespace AMP {
14class Database;
15namespace Operator {
16class Operator;
17}
18
19namespace TimeIntegrator {
20
21using DataManagerCallBack = std::function<void( std::shared_ptr<AMP::LinearAlgebra::Vector> )>;
22
24{
25public:
28
29 static std::unique_ptr<AMP::TimeIntegrator::TimeIntegrator> createTimeIntegrator(
30 std::shared_ptr<AMP::TimeIntegrator::TimeIntegratorParameters> parameters );
31
34
36 double getTimeOperatorScaling( void );
37
46 void setInitialGuess( const bool first_step,
47 const double current_time,
48 const double current_dt,
49 const double old_dt ) override;
50
52
57
62
63 void setIterationCounts( const int nli, const int li );
64
70 void reset(
71 std::shared_ptr<const AMP::TimeIntegrator::TimeIntegratorParameters> parameters ) override;
72
74 void printStatistics( std::ostream &os = AMP::pout ) override;
75
76 int
78 const bool first_step,
79 std::shared_ptr<AMP::LinearAlgebra::Vector> in,
80 std::shared_ptr<AMP::LinearAlgebra::Vector> out ) override;
81
86
88
89 double getGamma( void ) override;
90
91 std::vector<double> getTimeHistoryScalings( void ) override;
92
93 size_t sizeOfTimeHistory() const override { return d_max_integrator_index + 1; }
94
95 const auto &getTimeHistoryVectors() { return d_prev_solutions; }
96
97 std::shared_ptr<AMP::LinearAlgebra::Vector> getTimeHistorySourceTerm() override
98 {
100 }
101
102 std::string type() const override { return "BDFIntegrator"; }
103
104public: // Write/read restart data
111
117 void writeRestart( int64_t fid ) const override;
118
126
127protected:
128 /*
129 * Helper functions.
130 */
131
135 void getFromInput( std::shared_ptr<AMP::Database> input_db );
136
146 const int solver_retcode ) override;
147
149 double getNextDtPredefined( const bool good_solution, const int solver_retcode );
150 double getNextDtConstant( const bool good_solution, const int solver_retcode );
151 double getNextDtFinalConstant( const bool good_solution, const int solver_retcode );
152
153 void integratorSpecificInitialize( void ) override;
154
155 // int integratorSpecificAdvanceSolution( const double dt, const bool first_step ) override;
156
164
172 void integratorSpecificUpdateSolution( const double new_time ) override;
173
177
180
184
186 void evaluatePredictor( void );
187
190
194
197
201
204
207
210
213
219
223 void calculateScaledLTENorm( std::shared_ptr<AMP::LinearAlgebra::Vector> x,
224 std::shared_ptr<AMP::LinearAlgebra::Vector> y,
225 std::vector<double> &norms );
230
235 void printVectorComponentNorms( const std::shared_ptr<AMP::LinearAlgebra::Vector> &vec,
236 const std::string &prefix,
237 const std::string &postfix,
238 const std::string &norm );
239
240 void setTimeHistoryScalings() override;
241
242 void setPredictorType( const std::string &predictor = "" );
243
248
250
251#ifdef ENABLE_RESTART
252 std::shared_ptr<RestartData> d_restart_data;
253#endif
254
257 std::vector<std::shared_ptr<AMP::LinearAlgebra::Vector>> d_prev_solutions;
258
261 std::shared_ptr<AMP::LinearAlgebra::Vector> d_integrator_source_vector = nullptr;
262
264 std::shared_ptr<AMP::LinearAlgebra::Vector> d_predictor_vector = nullptr;
265
267 std::shared_ptr<AMP::LinearAlgebra::Vector> d_timederivative_vector = nullptr;
268
270 std::shared_ptr<AMP::LinearAlgebra::Vector> d_scratch_vector = nullptr;
271
273 std::shared_ptr<AMP::LinearAlgebra::Vector> d_scratch_function_vector = nullptr;
274
276 std::shared_ptr<AMP::LinearAlgebra::Vector> d_current_function_vector = nullptr;
277
279 std::shared_ptr<AMP::LinearAlgebra::Vector> d_prev_function_vector = nullptr;
280
282 std::shared_ptr<AMP::LinearAlgebra::Vector> d_old_td_vector = nullptr;
283
285 std::vector<int> d_nonlinearIterations;
286
288 std::vector<int> d_linearIterations;
289
291 std::vector<int> d_step_accepted;
292
294 std::vector<std::vector<double>> d_LTE;
295
297 std::vector<double> d_timesteps;
298
300 std::vector<double> d_times;
301
303 std::vector<double> d_integrator_order;
304
306 std::vector<double> d_integrator_steps;
307
309 std::vector<std::string> d_integrator_names;
310
312 std::vector<std::string> d_vector_names;
313
315 std::vector<std::string> d_var_names;
316
318 std::vector<double> d_a;
319
321 std::string d_timeTruncationErrorNormType = "l2Norm";
322
324 std::string d_implicit_integrator = "BDF2";
325
327 std::string d_bdf_starting_integrator = "CN";
328
331 std::string d_timestep_strategy = "truncationErrorStrategy";
332
334 std::string d_pi_controller_type = "PC.4.7";
335
338 std::string d_time_error_scaling = "fixed_scaling";
339
341 std::string d_predictor_type = "leapfrog";
342
344 std::string d_initial_predictor_type = "forward_euler";
345
346 std::list<double> d_l2errorNorms_E;
347 std::list<double> d_l2errorNorms_T;
348
350 std::vector<double> d_problem_scales;
351
353 double d_new_time = std::numeric_limits<double>::signaling_NaN();
354
356 double d_first_initial_dt = 0.0;
357
359 double d_alpha = 1.0;
360
362 double d_DtCutLowerBound = std::numeric_limits<double>::signaling_NaN();
363
365 double d_DtGrowthUpperBound = std::numeric_limits<double>::signaling_NaN();
366
368 double d_time_atol = std::numeric_limits<double>::signaling_NaN();
369
371 double d_time_rtol = std::numeric_limits<double>::signaling_NaN();
372
375
378
381
385
387 double d_gamma = 0.0;
388
390 size_t d_max_integrator_index = static_cast<size_t>( -1 );
391
394
397
400
403
406
409
412
415
418
421
425
429
432
436
438 bool d_log_statistics = true;
439
441 bool d_is_after_regrid = false;
442
444 bool d_is_new_timestep = true;
445
448
451
453 bool d_use_predictor = true;
454
458
462
465
468
471
474
477
480};
481
482} // namespace TimeIntegrator
483} // namespace AMP
484
485#endif
Class to manage reading/writing restart data.
std::vector< double > d_integrator_order
truncation error order for time integrators
void setIterationCounts(const int nli, const int li)
void integratorSpecificInitialize(void) override
void writeRestart(int64_t fid) const override
Write restart data to file.
int integratorSpecificAdvanceSolution(const double dt, const bool first_step, std::shared_ptr< AMP::LinearAlgebra::Vector > in, std::shared_ptr< AMP::LinearAlgebra::Vector > out) override
int d_linear_iterations
records number of linear iterations at current timestep
std::shared_ptr< AMP::LinearAlgebra::Vector > d_scratch_vector
the next vector is used for scratch or intermediate storage
void reset(std::shared_ptr< const AMP::TimeIntegrator::TimeIntegratorParameters > parameters) override
void estimateBETimeDerivative(void)
estimates the BE time derivative using the approach in Gresho and Sani
int d_solver_converged_reason
convergence reason returned by solver
bool integratorSpecificCheckNewSolution(const int solver_retcode) override
std::shared_ptr< AMP::LinearAlgebra::Vector > d_integrator_source_vector
int d_enable_picontrol_regrid_steps
the number of timesteps after a regrid before the pi controller is enabled
double d_timeErrorEstimateRatio
truncation error ratio to previous step
int getNumberOfStepRejections(void)
returns the total number of timestep rejections
double getNextDtConstant(const bool good_solution, const int solver_retcode)
bool d_is_new_timestep
boolean flag to determine if a new timestep has started
bool d_vectors_registered_for_mgmt
boolean to ensure registerVectorsForMemoryManagement is called once
int d_evaluatefunction_count
counter to track number of nonlinear function calls
void evaluatePredictor(void)
evaluates the predictor and stores in the predictor energy and temperature variables
void printVectorComponentNorms(const std::shared_ptr< AMP::LinearAlgebra::Vector > &vec, const std::string &prefix, const std::string &postfix, const std::string &norm)
std::shared_ptr< AMP::LinearAlgebra::Vector > getTimeHistorySourceTerm() override
static std::unique_ptr< AMP::TimeIntegrator::TimeIntegrator > createTimeIntegrator(std::shared_ptr< AMP::TimeIntegrator::TimeIntegratorParameters > parameters)
void initializeVariables(bool is_from_restart)
std::vector< std::shared_ptr< AMP::LinearAlgebra::Vector > > d_prev_solutions
std::shared_ptr< AMP::LinearAlgebra::Vector > d_prev_function_vector
the next vector will store the old rhs at the previous time level
bool d_use_predictor
boolean flag to use a predictor for the initial guess at each timestep
std::string type() const override
Return the name of the TimeIntegrator.
std::vector< double > getTimeHistoryScalings(void) override
Scaling factors for previous time history vectors.
bool d_use_constant_time_interpolation
boolean flag used to do constant time interpolation, used after regrids
size_t d_integrator_index
index into d_integrator_names showing what is the current integrator
BDFIntegrator(int64_t fid, AMP::IO::RestartManager *manager)
Read restart data to file.
double d_time_rtol
relative tolerance for the truncation error based strategy
double getNextDtFinalConstant(const bool good_solution, const int solver_retcode)
std::string d_pi_controller_type
type of PI controller, current options are "H211b", "PI.4.7", and "Deadbeat"
double d_time_atol
absolute tolerance for the truncation error based strategy
std::vector< std::string > d_var_names
names of variables to associate with different components of a vector
int d_current_steprejects
keeps track of successive step rejections at a given timestep
void setPredictorType(const std::string &predictor="")
double estimateDtWithTruncationErrorEstimates(double current_dt, bool good_solution)
estimate timestep based on truncation error estimates
std::shared_ptr< AMP::LinearAlgebra::Vector > d_timederivative_vector
the next vector will store the current estimate for the time derivative
bool d_reset_after_restart
boolean flag to detect a call to reset immediately following restart
std::shared_ptr< AMP::LinearAlgebra::Vector > d_predictor_vector
the next vector will store the predictor for the next timestep
std::vector< int > d_nonlinearIterations
vector to keep track of the number of nonlinear iterations
double d_prevTimeTruncationErrorEstimate
truncation error estimate at previous step
double getGamma(void) override
bool d_use_pi_controller
boolean flag to enable or disable the use of a PI based timestep controller
void calculateScaledLTENorm(std::shared_ptr< AMP::LinearAlgebra::Vector > x, std::shared_ptr< AMP::LinearAlgebra::Vector > y, std::vector< double > &norms)
void registerDataManagerCallback(DataManagerCallBack callBackFn)
bool d_is_after_regrid
state of simulation, whether it is immediately after a regrid
std::vector< double > d_times
vector to the store the simulation times
std::string d_bdf_starting_integrator
the one step method used to start up BDF2, options are "Backward Euler" or "CN"
double d_DtGrowthUpperBound
upper bound on factor by which timestep can be increased
double d_DtCutLowerBound
max factor to cut timestep by when a timestep is rejected
double getNextDtTruncationError(const bool good_solution, const int solver_retcode)
double d_alpha
ratio of current to previous timestep
std::shared_ptr< AMP::LinearAlgebra::Vector > d_old_td_vector
the next vector will store the old time derivative at previous time level
void estimateCNTimeDerivative(void)
estimates the CN time derivative using the approach in Gresho and Sani
std::vector< int > d_linearIterations
vector to keep track of the number of linear iterations
size_t d_max_integrator_index
index into d_integrator_names that shows what is the max BDF order
double d_gamma
factor to multiply rhs by
int d_bdf1_eps_regrid_steps
number of steps to use bdf1 error estimator after regrid
bool d_control_timestep_variation
boolean to minimize the number of timestep changes in the truncation error strategy
void setInitialGuess(const bool first_step, const double current_time, const double current_dt, const double old_dt) override
void setRegridStatus(bool is_after_regrid)
std::string d_timeTruncationErrorNormType
norm type used for truncation error calculation
double d_new_time
double containing t_{n+1}
std::vector< std::string > d_integrator_names
names of time integrators
void printStatistics(std::ostream &os=AMP::pout) override
print the statistics on the implicit equations
bool d_log_statistics
whether to log statistics about time integrator
double getNextDtPredefined(const bool good_solution, const int solver_retcode)
void getFromInput(std::shared_ptr< AMP::Database > input_db)
int d_current_stepaccepts
keeps track of successive step acceptances
std::vector< double > d_integrator_steps
vector of previous timesteps
double getTimeOperatorScaling(void)
return the factor getGamma() used to scale the rhs operator
double d_timeTruncationErrorEstimate
truncation error estimate in time over both E and T
std::vector< int > d_step_accepted
vector to keep track of whether the step is accepted
std::shared_ptr< AMP::LinearAlgebra::Vector > d_current_function_vector
the next vector will store the rhs at the current time level
std::shared_ptr< AMP::LinearAlgebra::Vector > d_scratch_function_vector
the next vector is used for scratch or intermediate storage for rhs
int d_nonlinear_iterations
records number of nonlinear iterations at current timestep
void integratorSpecificUpdateSolution(const double new_time) override
std::string d_implicit_integrator
string for the time integrator being used, options are "Backward Euler", "BDF2", or "CN"
std::vector< std::vector< double > > d_LTE
vector of vectors to store the local truncation errors for components
DataManagerCallBack d_registerVectorForManagement
bool d_calculateTimeTruncError
calculate time truncation error if enabled
std::vector< double > d_problem_scales
fixed used defined scales for time error scaling
std::vector< std::string > d_vector_names
names of variables to associate with different vectors
void evaluateBDFInterpolantPredictor(void)
evaluates a predictor based on an interpolating polynomial
bool d_combine_timestep_estimators
boolean flag to combine different time error estimators
std::string d_initial_predictor_type
initial predictor type
bool d_auto_component_scaling
enable auto scaling if true
std::vector< double > d_a
time history scalings
BDFIntegrator(AMP::TimeIntegrator::TimeIntegratorParameters::shared_ptr)
bool d_prevSuccessiveRejects
boolean flag to keep track of successive time step rejections
std::string d_predictor_type
predictor to use with predictor corrector approach
void estimateTimeDerivative(void)
wrapper for estimating the time derivative after a succesful step
void evaluateAB2Predictor(void)
evaluates the AB2 predictor and stores in the predictor energy and temperature variables
double integratorSpecificGetNextDt(const bool good_solution, const int solver_retcode) override
double d_first_initial_dt
double storing the first dt before any restart
int d_timesteps_after_regrid
keeps track of the number of timesteps after the last regrid
void estimateBDF2TimeDerivative(void)
estimates the BDF2 time derivative using the approach in Gresho and Sani
void registerChildObjects(AMP::IO::RestartManager *manager) const override
Register any child objects.
std::vector< double > d_timesteps
vector to store the timesteps
size_t sizeOfTimeHistory() const override
Manage implicit time integration.
std::shared_ptr< AMP::TimeIntegrator::TimeIntegratorParameters > shared_ptr
Convience typedef.
Abstract base class for time integration.
std::shared_ptr< AMP::TimeIntegrator::TimeIntegrator > shared_ptr
Convience typedef.
std::function< void(std::shared_ptr< AMP::LinearAlgebra::Vector >)> DataManagerCallBack
constexpr double norm(const std::array< double, N > &x)
std::ostream pout



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page