Feel++ 0.111.0-preview.14
Finite Element Embedded Library in C++
Feel::Bdf< SpaceType > Class Template Reference

Backward differencing formula time discretization. More...

+ Inheritance diagram for Feel::Bdf< SpaceType >:
+ Collaboration diagram for Feel::Bdf< SpaceType >:

Public Types

typedef std::shared_ptr< bdf_type > bdf_ptrtype
 
typedef Bdf< SpaceType > bdf_type
 
typedef space_type::element_ptrtype element_ptrtype
 
typedef space_type::element_type element_type
 
typedef node< value_type >::type node_type
 
typedef space_type::return_type return_type
 
typedef std::shared_ptr< space_type > space_ptrtype
 
typedef SpaceType space_type
 
typedef super::time_iterator time_iterator
 
typedef std::vector< element_ptrtype > unknowns_type
 
typedef element_type::value_type value_type
 
- Public Types inherited from Feel::TSBase
typedef std::vector< double >::const_iterator time_const_iterator
 
typedef std::vector< double >::iterator time_iterator
 
typedef std::vector< double > time_values_map_type
 

Public Member Functions

void applyRemesh (space_ptrtype const &space, std::shared_ptr< MatrixSparse< double > > const &matInterp)
 apply a remesh by given the new functionspace and the interpolation matrix between previous and new function space
 
 Bdf (Bdf const &b)
 copy operator
 
 Bdf (space_ptrtype const &__space, std::string const &name, std::string const &prefix, po::variables_map const &vm, int order, double ti, double tf, double dt, bool steady, bool reverse, bool restart, std::string const &restart_path, bool restart_at_last_save, bool save, int freq, bool rank_proc_in_files_name, std::string const &format, int n_consecutive_save)
 
 Bdf (space_ptrtype const &space, std::string const &name, std::string const &prefix="", po::variables_map const &vm=Environment::vm())
 Constructor. More...
 
int bdfOrder () const
 return the order in time
 
std::string bdfPrefix () const
 return the prefix
 
bdf_ptrtype deepCopy () const
 return a deep copy of the bdf object
 
space_ptrtype const & functionSpace () const
 
void initialize (element_type const &u0)
 Initialize all the entries of the unknown vector to be derived with the vector u0 (duplicated)
 
void initialize (unknowns_type const &uv0)
 Initialize all the entries of the unknown vector to be derived with a set of vectors uv0.
 
void loadCurrent ()
 Load current unknown in a file (hdf5, binary, ...) More...
 
double next () const override
 Move to next time step (solution not shifted). More...
 
template<typename container_type >
double next (typename space_type::template Element< value_type, container_type > const &u_curr)
 Move to next time step with solution shift.
 
int numberOfConsecutiveSave () const
 return number of consecutive save
 
int numberOfIterationsBetweenOrderChange () const
 return the number of iterations between order change
 
int numberOfIterationsSinceOrderChange () const
 return the number of iterations since last order change
 
element_type const & poly () const
 Compute the polynomial extrapolation approximation of order n-1 of u^{n+1} defined by the n stored state vectors.
 
double polyCoefficient (int i) const
 Return \( \alpha_i \).
 
element_type const & polyDeriv () const
 Returns the right hand side \( \bar{p} \) of the time derivative formula.
 
double polyDerivCoefficient (int i) const
 Return \( \frac{\alpha_i}{\Delta t} \).
 
element_ptrtype const & polyDerivPtr () const
 Returns the right hand side \( \bar{p} \) of the time derivative formula.
 
element_ptrtype const & polyPtr () const
 Compute the polynomial extrapolation approximation of order n-1 of u^{n+1} defined by the n stored state vectors.
 
void print () const override
 
element_type & prior ()
 
element_type const & prior () const
 
std::map< int, double > priorTimes () const override
 return a vector of the times prior to timeInitial() (included) More...
 
double restart ()
 restart the bdf
 
void setNumberOfConsecutiveSave (int n)
 set number of consecutive save
 
void setOrder (int order)
 
void setTimeOrder (int order)
 
template<typename container_type >
void setUnknown (int i, typename space_type::template Element< value_type, container_type > const &e)
 
template<typename container_type >
void shiftRight (typename space_type::template Element< value_type, container_type > const &u_curr)
 Update the vectors of the previous time steps by shifting on the right the old values. More...
 
void showMe (std::ostream &__out=std::cout) const
 
double start ()
 start the bdf
 
double start (element_type const &u0)
 
double start (unknowns_type const &uv0)
 
int timeOrder () const
 return the curent order used at current time time
 
element_type & unknown (int i)
 Return the previous element at previous time i-1.
 
element_ptrtype unknownPtr (int i)
 Return the previous element at previous time i-1.
 
unknowns_type & unknowns ()
 Return a vector with the last n state vectors.
 
unknowns_type const & unknowns () const
 Return a vector with the last n state vectors.
 
void updateDerivative (element_type &u, int i=0) const
 update field \u with derivative at previous time indexed by \i (i.e. curent_time - i - 1)
 
- Public Member Functions inherited from Feel::TSBase
bool doRestartAtLastSave () const
 return value of do restart at last save
 
std::string fileFormat () const
 return file format saved and loaded : binary or hdf5
 
bool isFinished () const
 return true if Bdf is finished, false otherwise
 
bool isRestart () const
 return the value of the bool restart
 
bool isReverse () const
 return the reverse time loop state.
 
bool isReverseLoad () const
 return the reverse time loop state.
 
bool isRunning () const
 
bool isSteady () const
 
bool isStopped () const
 
int iteration () const
 return the current iteration
 
const int iterationNumber () const
 return the number of iteration
 
virtual double next () const
 advance in time More...
 
int nRestart () const
 return the number of restarts
 
TSBase & operator= (TSBase const &b)
 
fs::path path ()
 return the relative path where the bdf data is stored
 
std::string const & prefix () const
 
virtual void print () const
 
virtual std::map< int, double > priorTimes () const
 
bool rankProcInNameOfFiles () const
 
double realTimePerIteration () const
 return the real time in seconds spent in the iteration
 
void reloadMetaData ()
 reload metadata to get all time step already done
 
double restart ()
 restart the bdf
 
fs::path restartPath ()
 
int restartStepBeforeLastSave () const
 return the step index before the last used to restart
 
int saveFreq () const
 
bool saveInFile () const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 save/load Bdf metadata
 
void setfileFormat (std::string s)
 
void setPathSave (std::string s)
 
void setRankProcInNameOfFiles (bool b)
 
void setRestart (bool doRestart)
 
void setRestartAtLastSave (bool b)
 
void setRestartPath (std::string const &s)
 
void setReverse (bool reverse=false)
 Reverse time (iteration always start at 0!)
 
void setReverseLoad (bool reverseLoad=false)
 Load saved unknown beginning from last iteration. In bdf, solutions are saved from Ti (iter 0) ->Tf (iter N) in hdf5 files indexed by the iteration. If we reverse bdf, it runs from Tf (iter 0) -> Ti (iter N). To read hdf5 solution from files, we have to load the file N at Ti. Therefore reversing iteration index to load the correct file. Note: it is not required if the solution has to be saved.
 
void setSaveFreq (int v)
 
void setSaveInFile (bool b)
 
void setSteady (bool steady=true)
 
void setTimeFinal (double T)
 
void setTimeInitial (double ti)
 
void setTimeStep (double dt)
 
virtual void shiftRight ()
 
double start ()
 start the bdf
 
TSState state () const
 return the state of the BDF
 
TSStragegy strategy () const
 
double time () const
 return the current time
 
double timeFinal () const
 return the final time
 
double timeInitial () const
 return the initial time
 
double timeStep () const
 return the final step
 
time_values_map_type timeValues () const
 return vector of time
 
 TSBase (std::string name, std::string const &prefix, WorldComm const &worldComm, po::variables_map const &vm, double ti, double tf, double dt, bool steady, bool reverse, bool restart, std::string const &restart_path, bool restart_at_last_save, bool save, int freq, bool rank_proc_in_files_name, std::string const &format)
 
 TSBase (std::string name, std::string const &prefix, WorldComm const &worldComm, po::variables_map const &vm=Environment::vm())
 
 TSBase (std::string name, WorldComm const &worldComm)
 
 TSBase (TSBase const &b)
 
virtual void update ()
 
WorldComm const & worldComm () const
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Protected Member Functions inherited from Feel::TSBase
void init ()
 
- Protected Attributes inherited from Feel::TSBase
bool M_displayStats
 indicates if display stat is enabled
 
double M_dt
 timestep
 
std::string M_fileFormat
 file format saved and loaded : binary or hdf5
 
int M_iteration
 iteration
 
int M_n_restart
 restart
 
std::string M_name
 name of the file holding the bdf data
 
fs::path M_path_save
 path to the directory to store the functions
 
std::string M_prefix
 
bool M_rankProcInNameOfFiles
 put the rank of the processor in generated files
 
double M_real_time_per_iteration
 real time spent per iteration (in seconds)
 
bool M_restart
 do a restart
 
bool M_restartAtLastSave
 do restart with ti the last save
 
fs::path M_restartPath
 restart path
 
int M_restartStepBeforeLastSave
 do restart with the ieme step before the last save
 
bool M_reverse
 is reversed
 
bool M_reverseLoad
 is file load from reverse
 
int M_saveFreq
 frequence of save solutions
 
bool M_saveInFile
 Save solutions in file after each step.
 
TSState M_state
 state of the time stepping algorithm
 
bool M_steady
 is steady
 
double M_Tf
 final time
 
double M_Ti
 initial time to start
 
double M_time
 time
 
time_values_map_type M_time_values_map
 vector that holds the time order at each bdf step More...
 
Feel::Timer M_timer
 timer for real time per iteration
 
WorldComm M_worldComm
 mpi communicator tool
 

Detailed Description

template<typename SpaceType>
class Feel::Bdf< SpaceType >

Backward differencing formula time discretization.

A differential equation of the form

\( M u' = A u + f \)

is discretized in time as

\( M p'(t_{k+1}) = A u_{k+1} + f_{k+1} \)

where p denotes the polynomial of order n in t that interpolates \( (t_i,u_i) \) for \( i = k-n+1,...,k+1\).

The approximative time derivative \( p'(t_{k+1}) \) is a linear combination of state vectors \(u_i\):

\( p'(t_{k+1}) = \frac{1}{\Delta t} (\alpha_0 u_{k+1} - \sum_{i=0}^n \alpha_i u_{k+1-i} )\)

Thus we have

\( \frac{\alpha_0}{\Delta t} M u_{k+1} = A u_{k+1} + f + M \bar{p} \)

with

\( \bar{p} = \frac{1}{\Delta t} \sum_{i=1}^n \alpha_i u_{k+1-i} \)

This class stores the n last state vectors in order to be able to calculate \( \bar{p} \). It also provides \( \alpha_i \) and can extrapolate the new state from the n last states with a polynomial of order n-1:

\( u_{k+1} \approx \sum_{i=0}^{n-1} \beta_i u_{k-i} \)

Constructor & Destructor Documentation

◆ Bdf()

template<typename SpaceType >
Feel::Bdf< SpaceType >::Bdf ( space_ptrtype const &  space,
std::string const &  name,
std::string const &  prefix = "",
po::variables_map const &  vm = Environment::vm() 
)

Constructor.

Parameters
spaceapproximation space
namename of the BDF

Member Function Documentation

◆ functionSpace()

template<typename SpaceType >
space_ptrtype const & Feel::Bdf< SpaceType >::functionSpace ( ) const
Returns
the FunctionSpace associated to BDF

◆ loadCurrent()

template<typename SpaceType >
void Feel::Bdf< SpaceType >::loadCurrent

Load current unknown in a file (hdf5, binary, ...)

Load current unknown in a file (hdf5, binary, ...) The filename depends on the bdf name and the time iteration.

Notes:

  • that if bdf is set to setReverse(true), the iteration 0 will be loaded.
  • You might desire to read a bdf backward. Then you have to pass setReverseLoad(true) to load existing unknowns from last iteration! It is require after a restart if time loop sense changed.

◆ next()

template<typename SpaceType >
double Feel::Bdf< SpaceType >::next ( ) const
overridevirtual

Move to next time step (solution not shifted).

Reimplemented from Feel::TSBase.

◆ print()

template<typename SpaceType >
void Feel::Bdf< SpaceType >::print ( ) const
overridevirtual

Reimplemented from Feel::TSBase.

◆ priorTimes()

template<typename SpaceType >
std::map< int, double > Feel::Bdf< SpaceType >::priorTimes ( ) const
overridevirtual

return a vector of the times prior to timeInitial() (included)

Reimplemented from Feel::TSBase.

◆ shiftRight()

template<typename SpaceType >
template<typename container_type >
void Feel::Bdf< SpaceType >::shiftRight ( typename space_type::template Element< value_type, container_type > const &  u_curr)

Update the vectors of the previous time steps by shifting on the right the old values.

Parameters
u_currcurrent (new) value of the state vector

Referenced by Feel::Bdf< SpaceType >::polyCoefficient().