35 #ifndef NEKTAR_LIB_UTILITIES_FOUNDATIONS_TIMEINTEGRATIONSCHEME_H 36 #define NEKTAR_LIB_UTILITIES_FOUNDATIONS_TIMEINTEGRATIONSCHEME_H 38 #include <boost/core/ignore_unused.hpp> 48 namespace LibUtilities
51 class TimeIntegrationScheme;
108 "NoTimeIntegrationMethod",
109 "AdamsBashforthOrder1",
110 "AdamsBashforthOrder2",
111 "AdamsBashforthOrder3",
112 "AdamsBashforthOrder4",
113 "AdamsMoultonOrder1",
114 "AdamsMoultonOrder2",
117 "ClassicalRungeKutta4",
121 "RungeKutta2_ImprovedEuler",
157 "NoTimeIntegrationSchemeType",
159 "DiagonallyImplicit",
175 typedef std::function< void (InArrayType&, OutArrayType&, const NekDouble) >
FunctorType1;
176 typedef std::function< void (InArrayType&, OutArrayType&, const NekDouble, const NekDouble) >
FunctorType2;
190 template<
typename FuncPo
interT,
typename ObjectPo
interT>
194 func, obj, std::placeholders::_1, std::placeholders::_2,
195 std::placeholders::_3);
198 template<
typename FuncPo
interT,
typename ObjectPo
interT>
202 func, obj, std::placeholders::_1, std::placeholders::_2,
203 std::placeholders::_3);
206 template<
typename FuncPo
interT,
typename ObjectPo
interT>
210 func, obj, std::placeholders::_1, std::placeholders::_2,
211 std::placeholders::_3);
214 template<
typename FuncPo
interT,
typename ObjectPo
interT>
218 func, obj, std::placeholders::_1, std::placeholders::_2,
219 std::placeholders::_3);
222 template<
typename FuncPo
interT,
typename ObjectPo
interT>
226 func, obj, std::placeholders::_1, std::placeholders::_2,
227 std::placeholders::_3, std::placeholders::_4);
232 OutArrayType &outarray,
240 OutArrayType &outarray,
243 ASSERTL1(
m_functors1[1],
"OdeExplicitRhs should be defined for this time integration scheme");
248 OutArrayType &outarray,
251 ASSERTL1(
m_functors1[2],
"OdeImplictRhs should be defined for this time integration scheme");
256 OutArrayType &outarray,
259 ASSERTL1(
m_functors1[3],
"Projection operation should be defined for this time integration scheme");
264 OutArrayType &outarray,
268 ASSERTL1(
m_functors2[0],
"ImplicitSolve should be defined for this time integration scheme");
326 return (*
this == *y);
331 return (!(*
this == y));
336 return (!(*
this == *y));
378 class TimeIntegrationScheme
388 typedef std::function< void (ConstDoubleArray&, DoubleArray&, const NekDouble) >
FunctorType1;
389 typedef std::function< void (ConstDoubleArray&, DoubleArray&, const NekDouble, const NekDouble) >
FunctorType2;
404 return m_schemeKey.GetIntegrationMethod();
412 inline NekDouble A(
const unsigned int i,
const unsigned int j)
const 417 inline NekDouble B(
const unsigned int i,
const unsigned int j)
const 422 inline NekDouble U(
const unsigned int i,
const unsigned int j)
const 427 inline NekDouble V(
const unsigned int i,
const unsigned int j)
const 454 return m_numMultiStepValues;
459 return m_numMultiStepDerivs;
496 ConstDoubleArray &y_0 ,
519 TimeIntegrationSolutionSharedPtr &y ,
524 return m_timeLevelOffset;
572 LIB_UTILITIES_EXPORT static std::shared_ptr<TimeIntegrationScheme> Create(
const TimeIntegrationSchemeKey &key);
574 TimeIntegrationScheme(
const TimeIntegrationSchemeKey &key);
584 boost::ignore_unused(in);
595 ConstTripleArray &y_old ,
596 ConstSingleArray &t_old ,
604 return y[0].num_elements();
609 return y[0][0].num_elements();
613 ConstTripleArray &y_old ,
614 ConstSingleArray &t_old ,
645 const DoubleArray& y,
650 const TripleArray& y,
654 unsigned int npoints);
664 return m_scheme->GetIntegrationSchemeKey();
669 return m_scheme->GetIntegrationMethod();
684 return m_solVector[0];
689 return m_solVector[0];
709 return m_scheme->GetNsteps();
714 return m_solVector[0].num_elements();
719 return m_solVector[0][0].num_elements();
726 return m_scheme->GetNmultiStepValues();
733 return m_scheme->GetNmultiStepDerivs();
740 return m_scheme->GetTimeLevelOffset();
745 inline DoubleArray&
GetValue(
const unsigned int timeLevelOffset)
747 int nMultiStepVals = m_scheme->GetNmultiStepValues();
750 for(
int i = 0; i < nMultiStepVals; i++)
752 if( timeLevelOffset == offsetvec[i] )
754 return m_solVector[i];
757 ASSERTL1(
false,
"The solution vector of this scheme does not contain a value at the requested time-level");
758 return m_solVector[0];
765 int nMultiStepVals = m_scheme->GetNmultiStepValues();
766 int size = m_scheme->GetNsteps();
769 for(
int i = nMultiStepVals; i < size; i++)
771 if( timeLevelOffset == offsetvec[i] )
773 return m_solVector[i];
776 ASSERTL1(
false,
"The solution vector of this scheme does not contain a derivative at the requested time-level");
777 return m_solVector[0];
784 int nMultiStepVals = m_scheme->GetNmultiStepValues();
787 for(
int i = 0; i < nMultiStepVals; i++)
789 if( timeLevelOffset == offsetvec[i] )
794 ASSERTL1(
false,
"The solution vector of this scheme does not contain a value at the requested time-level");
801 inline void SetValue(
const unsigned int timeLevelOffset,
const DoubleArray& y,
const NekDouble t)
803 int nMultiStepVals = m_scheme->GetNmultiStepValues();
806 for(
int i = 0; i < nMultiStepVals; i++)
808 if( timeLevelOffset == offsetvec[i] )
822 int nMultiStepVals = m_scheme->GetNmultiStepValues();
823 int size = m_scheme->GetNsteps();
826 for(
int i = nMultiStepVals; i < size; i++)
828 if( timeLevelOffset == offsetvec[i] )
840 m_solVector[Offset] = y;
848 int nMultiStepVals = m_scheme->GetNmultiStepValues();
849 int size = m_scheme->GetNsteps();
850 for(i = (nMultiStepVals-1); i > 0; i--)
852 m_solVector[i] = m_solVector[i-1];
855 for(i = (size-1); i > nMultiStepVals; i--)
857 m_solVector[i] = m_solVector[i-1];
878 #endif //NEKTAR_LIB_UTILITIES_FOUNDATIONS_TIMEINTEGRATIONSCHEME_H NekDouble A(const unsigned int i, const unsigned int j) const
NekDouble GetValueTime(const unsigned int timeLevelOffset)
TimeIntegrationSchemeKey(const TimeIntegrationMethod &method)
unsigned int GetNsteps(void) const
std::vector< TimeIntegrationSchemeSharedPtr > TimeIntegrationSchemeVector
NekDouble B(const unsigned int i, const unsigned int j) const
std::shared_ptr< TimeIntegrationScheme > TimeIntegrationSchemeSharedPtr
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
bool m_firstStageEqualsOldSolution
TimeIntegrationSchemeKey & operator=(const TimeIntegrationSchemeKey &key)
BDF multi-step scheme of order 1 (implicit)
Array< OneD, unsigned int > m_timeLevelOffset
Adams-Bashforth Forward multi-step scheme of order 2.
TimeIntegrationMethod GetIntegrationMethod() const
Array< OneD, Array< TwoD, NekDouble > > m_B
static const TimeIntegrationSchemeKey NullTimeIntegrationSchemeKey(eNoTimeIntegrationMethod)
void DoImplicitSolve(InArrayType &inarray, OutArrayType &outarray, const NekDouble time, const NekDouble lambda) const
int m_nvar
bool to identify if array has been initialised
void DefineImplicitSolve(FuncPointerT func, ObjectPointerT obj)
Runge-Kutta multi-stage scheme 4th order explicit (old name)
Implicit-Explicit Midpoint IMEX DIRK(1,2,2)
Array< OneD, NekDouble > & UpdateTimeVector()
unsigned int GetNvalues(void) const
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::function< void(InArrayType &, OutArrayType &, const NekDouble) > FunctorType1
const char *const TimeIntegrationSchemeTypeMap[]
void DoOdeRhs(InArrayType &inarray, OutArrayType &outarray, const NekDouble time) const
DoubleArray m_tmp
Array containing the stage values.
Array< OneD, FunctorType1 > FunctorType1Array
Array< OneD, NekDouble > SingleArray
NekDouble V(const unsigned int i, const unsigned int j) const
Classical RungeKutta4 method (new name for eClassicalRungeKutta4)
void DefineOdeExplicitRhs(FuncPointerT func, ObjectPointerT obj)
const TimeIntegrationSchemeKey & GetIntegrationSchemeKey() const
Formally explicit scheme.
NekDouble GetTime() const
L-stable, four stage, third order IMEX DIRK(4,4,3)
Forward-Backward Euler IMEX DIRK(1,2,1)
TimeIntegrationSchemeOperators(void)
void DefineOdeImplicitRhs(FuncPointerT func, ObjectPointerT obj)
bool operator==(const TimeIntegrationSchemeKey &key)
Implicit Explicit General Linear Method.
const char *const TimeIntegrationMethodMap[]
TimeIntegrationSchemeKey m_schemeKey
NekManager< TimeIntegrationSchemeKey, TimeIntegrationScheme, TimeIntegrationSchemeKey::opLess > TimeIntegrationSchemeManagerT
Nonlinear SSP RungeKutta3 explicit.
TimeIntegrationMethod GetIntegrationMethod() const
std::vector< TimeIntegrationSolutionSharedPtr >::iterator TimeIntegrationSolutionVectorIter
const DoubleArray & GetSolution() const
DoubleArray m_Y
The size of inner data which is stored for reuse.
bool operator!=(const BasisKey &x, const BasisKey &y)
TimeIntegrationSchemeManagerT & TimeIntegrationSchemeManager(void)
Adams-Moulton Forward multi-step scheme of order 2.
std::vector< TimeIntegrationSchemeSharedPtr >::iterator TimeIntegrationSchemeVectorIter
unsigned int GetNmultiStepValues(void) const
Adams-Bashforth Forward multi-step scheme of order 3.
NekDouble A_IMEX(const unsigned int i, const unsigned int j) const
bool operator==(const BasisKey &x, const BasisKey &y)
void SetValue(const unsigned int timeLevelOffset, const DoubleArray &y, const NekDouble t)
std::function< void(ConstDoubleArray &, DoubleArray &, const NekDouble, const NekDouble) > FunctorType2
Crank-Nicolson/Adams-Bashforth Order 2 (CNAB)
const Array< OneD, const Array< OneD, Array< OneD, NekDouble > > > ConstTripleArray
DoubleArray & GetDerivative(const unsigned int timeLevelOffset)
TimeIntegrationSchemeSharedPtr m_scheme
const FunctorType1 & ConstFunctorType1Ref
IMEX 2nd order scheme using Backward Different Formula & Extrapolation.
std::ostream & operator<<(std::ostream &os, const BasisKey &rhs)
const FunctorType2 & ConstFunctorType2Ref
TripleArray m_F
explicit right hand side of each stage equation
const Array< OneD, const NekDouble > & GetTimeVector() const
Diagonally implicit scheme (e.g. the DIRK schemes)
void DefineProjection(FuncPointerT func, ObjectPointerT obj)
Classical RungeKutta2 method (new name for eMidpoint)
TimeIntegrationSchemeType m_schemeType
const Array< OneD, const Array< OneD, NekDouble > > InArrayType
FunctorType2Array m_functors2
Adams-Moulton Forward multi-step scheme of order 1.
void SetDerivative(const unsigned int timeLevelOffset, const DoubleArray &y, const NekDouble timestep)
void DefineOdeRhs(FuncPointerT func, ObjectPointerT obj)
Adams-Bashforth Forward multi-step scheme of order 1.
virtual ~TimeIntegrationSchemeKey()
NekDouble U(const unsigned int i, const unsigned int j) const
#define LIB_UTILITIES_EXPORT
unsigned int GetNderivs(void) const
std::function< void(ConstDoubleArray &, DoubleArray &, const NekDouble) > FunctorType1
Array< OneD, Array< OneD, NekDouble > > DoubleArray
L-stable, three stage, third order IMEX DIRK(3,4,3)
TimeIntegrationSchemeKey(const TimeIntegrationSchemeKey &key)
void DoProjection(InArrayType &inarray, OutArrayType &outarray, const NekDouble time) const
int m_npoints
The number of variables in integration scheme.
Nonlinear SSP RungeKutta2 explicit (surrogate for eRungeKutta2_ImprovedEuler)
Improved RungeKutta2 explicit (old name meaning Heun's method)
unsigned int GetNstages(void) const
Forward-Backward Euler IMEX DIRK(1,1,1)
DoubleArray & UpdateSolution()
Array< OneD, Array< OneD, NekDouble > > DoubleArray
TimeIntegrationSchemeKey()
unsigned int GetNmultiStepDerivs(void) const
DoubleArray & GetValue(const unsigned int timeLevelOffset)
void SetSolVector(const int Offset, const DoubleArray &y)
void RotateSolutionVector()
NekDouble B_IMEX(const unsigned int i, const unsigned int j) const
TripleArray & UpdateSolutionVector()
bool operator<(const BasisKey &lhs, const BasisKey &rhs)
std::function< void(InArrayType &, OutArrayType &, const NekDouble, const NekDouble) > FunctorType2
TimeIntegrationSchemeType GetIntegrationSchemeType() const
unsigned int m_numMultiStepDerivs
FunctorType1Array m_functors1
unsigned int m_numMultiStepValues
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > TripleArray
Array< OneD, NekDouble > m_t
TimeIntegrationScheme(const TimeIntegrationScheme &in)
BDF multi-step scheme of order 2 (implicit)
L-stable, two stage, second order IMEX DIRK(2,2,2)
TimeIntegrationMethod m_method
integration method
void DoOdeExplicitRhs(InArrayType &inarray, OutArrayType &outarray, const NekDouble time) const
void DoOdeImplicitRhs(InArrayType &inarray, OutArrayType &outarray, const NekDouble time) const
const TripleArray & GetSolutionVector() const
Array< OneD, Array< OneD, NekDouble > > OutArrayType
Diagonally Implicit Runge Kutta scheme of order 2.
IMEX 3rd order scheme using Backward Different Formula & Extrapolation.
const Array< OneD, const NekDouble > ConstSingleArray
L-stable, three stage, third order IMEX DIRK(3,4,3)
Diagonally Implicit Runge Kutta scheme of order 3.
std::vector< TimeIntegrationSolutionSharedPtr > TimeIntegrationSolutionVector
const TimeIntegrationSchemeKey & GetIntegrationSchemeKey() const
TimeIntegrationMethod GetIntegrationMethod() const
const Array< OneD, const unsigned int > & GetTimeLevelOffset()
L-stable, two stage, third order IMEX DIRK(2,3,3)
IMEX 4th order scheme using Backward Different Formula & Extrapolation.
const TimeIntegrationSchemeSharedPtr & GetIntegrationScheme() const
bool m_lastStageEqualsNewSolution
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
int GetSecondDim(ConstTripleArray &y) const
Array< OneD, Array< TwoD, NekDouble > > m_A
Modified Crank-Nicolson/Adams-Bashforth Order 2 (MCNAB)
virtual ~TimeIntegrationScheme()
IMEX 1st order scheme using Euler Backwards/Euler Forwards.
midpoint method (old name)
const Array< OneD, const unsigned int > & GetTimeLevelOffset()
NekDouble m_T
Used to store the Explicit stage derivative of IMEX schemes.
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > TripleArray
std::shared_ptr< TimeIntegrationSolution > TimeIntegrationSolutionSharedPtr
Array< TwoD, NekDouble > m_U
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Adams-Bashforth Forward multi-step scheme of order 4.
TripleArray m_F_IMEX
Array corresponding to the stage Derivatives.
Array< OneD, FunctorType2 > FunctorType2Array
const Array< OneD, const Array< OneD, NekDouble > > ConstDoubleArray
int GetFirstDim(ConstTripleArray &y) const
TimeIntegrationSchemeType
Array< TwoD, NekDouble > m_V