43 #ifndef _BDF_VARIABLE_TIMESTEP_H 44 #define _BDF_VARIABLE_TIMESTEP_H 46 #include <lifev/core/LifeV.hpp> 47 #include <lifev/core/array/VectorEpetra.hpp> 96 template<
typename FEVectorType = VectorEpetra >
172 template<
typename FunctionType,
typename FESpaceType>
331 template<
typename FEVectorType>
341 template<
typename FEVectorType>
348 template<
typename FEVectorType>
352 M_alpha.resize ( M_order + 1 );
353 M_beta.resize ( M_order );
358 std::ostringstream errorMessage;
359 errorMessage <<
"Error: wrong BDF order\n" 360 <<
" you want to use BDF order " << order <<
"\n" 361 <<
" we support BDF order from 1 to " << bdfMaxOrder <<
"\n";
362 throw std::invalid_argument ( errorMessage.str() );
365 M_unknowns.reserve ( order );
369 template<
typename FEVectorType>
372 M_unknowns.resize ( 0 );
376 M_unknowns.push_back ( feVectorPtr );
394 template<
typename FEVectorType>
397 UInt n0 ( u0s.size() );
399 ASSERT ( n0 >= M_order,
"Initial data are not enough for the selected BDF" );
401 M_unknowns.resize (0);
402 for ( UInt i = 0; i < M_order; i++ )
404 feVectorPtr_Type tmp (
new feVector_Type ( u0s[ i ] ) );
405 M_unknowns.push_back ( tmp );
406 M_timeStep[ i ] = timeStep;
409 computeCoefficient();
414 std::cout <<
"The initial data set is larger than needed by the BDF." 416 std::cout <<
"Only the first " << M_order <<
" data will be considered. " 424 template<
typename FEVectorType>
425 template<
typename FunctionType,
typename FESpaceType>
427 FESpaceType& feSpace,
Real t0,
Real timeStep )
429 M_unknowns.resize ( 0 );
434 M_unknowns.push_back ( tmp );
435 feSpace.interpolate (
static_cast<
typename FESpaceType::function_Type> ( u0Function ), *
M_unknowns[ i ], t0 - i * timeStep );
446 template<
typename FEVectorType>
458 return uTimeDerivative;
462 template<
typename FEVectorType>
467 uTimeDerivative *=
M_alpha[ 1 ] / timeStep;
474 return uTimeDerivative;
478 template<
typename FEVectorType>
483 uExtrapolated *=
M_beta[ 0 ];
490 return uExtrapolated;
494 template<
typename FEVectorType>
498 typedef typename feVectorPtrContainer_Type::iterator bdfContainerIterator_Type;
499 bdfContainerIterator_Type it = M_unknowns.end() - 1;
500 bdfContainerIterator_Type itMinusOne = M_unknowns.end() - 1;
501 bdfContainerIterator_Type itBegin = M_unknowns.begin();
503 for ( ; it != itBegin; --it )
519 template<
typename FEVectorType>
524 typedef typename feVectorPtrContainer_Type::iterator bdfContainerIterator_Type;
525 bdfContainerIterator_Type it = M_unknowns.end() - 1;
526 bdfContainerIterator_Type itMinusOne = M_unknowns.end() - 1;
527 bdfContainerIterator_Type itBegin = M_unknowns.begin();
529 for ( ; it != itBegin; --it )
547 template<
typename FEVectorType>
550 typedef typename feVectorPtrContainer_Type::iterator bdfContainerIterator_Type;
552 M_unknownsBack.resize ( 0 );
553 for (bdfContainerIterator_Type it = M_unknowns.begin(); it < M_unknowns.end(); ++it)
555 M_unknownsBack.push_back (
new feVectorPtr_Type ( **it ) );
562 template<
typename FEVectorType>
565 typedef typename feVectorPtrContainer_Type::iterator bdfContainerIterator_Type;
567 M_unknowns.resize ( 0 );
568 for ( bdfContainerIterator_Type it = M_unknownsBack.begin(); it < M_unknownsBack.end(); ++it )
570 M_unknowns.push_back (
new feVectorPtr_Type ( **it ) );
579 template<
typename FEVectorType>
582 typedef typename feVectorPtrContainer_Type::iterator bdfContainerIterator_Type;
584 M_unknowns.resize ( 0 );
585 for ( bdfContainerIterator_Type it = M_unknownsBack.begin(); it < M_unknownsBack.end(); ++it )
587 M_unknowns.push_back (
new feVectorPtr_Type ( **it ) );
596 template<
typename FEVectorType>
600 std::cout <<
"*** BDF Time discretization of order " << M_order <<
" ***" 602 std::cout <<
" Coefficients: " << std::endl;
603 for ( UInt i = 0; i < M_order + 1; ++i )
604 std::cout <<
" alpha(" << i <<
") = " << M_alpha[ i ]
606 for ( UInt i = 0; i < M_order; ++i )
607 std::cout <<
" beta (" << i <<
") = " << M_beta[ i ]
616 template<
typename FEVectorType>
626 template<
typename FEVectorType>
632 "Error in specification of the time derivative coefficient for the BDF formula (out of range error)" );
637 template<
typename FEVectorType>
643 "Error in specification of the time derivative coefficient for the BDF formula (out of range error)" );
648 template<
typename FEVectorType>
654 "Error in specification of the time derivative coefficient for the BDF formula (out of range error)" );
661 template<
typename FEVectorType>
667 std::partial_sum ( M_timeStep.begin(), M_timeStep.end(), cumulativeSumTimeStep.begin() );
669 std::transform ( rho.begin(), rho.end(), cumulativeSumTimeStep.begin(),
670 rho.begin(), std::divides<
double>() );
672 M_alpha[ 0 ] = boost::numeric::ublas::sum ( rho );
684 tmp *= ( 1 - rho[ kk ] / rho[ j ] );
687 M_alpha[ j + 1 ] = rho[ j ] / tmp;
void shiftRight(feVector_Type const &uCurrent, Real timeStepNew)
Update the vectors of the previous time steps by shifting on the right the old values.
feVector_Type extrapolateSolution() const
Compute the polynomial extrapolation approximation of order n-1 of u^{n+1} defined by the n stored st...
void restoreSolution()
Restore the vector M_unknowns and the vector M_timeStep with the ones saved with store_unk() ...
void setInitialCondition(std::vector< feVector_Type > u0s, Real const timeStep)
Initialize all the entries of the unknown vector to be derived with a set of vectors u0s...
void setup(const UInt order)
Setup the TimeAdvanceBDFVariableStep with order n.
void storeSolution()
Save the current vector M_unknowns and the current vector M_timeStep.
UInt M_order
Order of the BDF derivative/extrapolation: the time-derivative coefficients vector has size n+1...
container_Type M_beta
Coefficients of the extrapolation.
const feVectorPtrContainer_Type & stateVectorBack() const
std::vector< feVectorPtr_Type > feVectorPtrContainer_Type
void setTimeStep(Real timeStep)
Replace the current time-step with timeStep and computes the coefficients a_i and beta_i as functions...
Real coefficientDerivativeOverTimeStep(UInt i) const
Return the i-th coefficient of the time derivative alpha_i divided by dt.
void restoreSolution(Real timeStep)
It is equivalent to do : storeSolution() + setTimeStep()
container_Type M_timeStepBack
container_Type M_timeStep
container_Type of time intervals
TimeAdvanceBDFVariableStep - Backward differencing formula time discretization with non-uniform time ...
FEVectorType feVector_Type
feVectorPtrContainer_Type M_unknownsBack
const Real & coefficientExtrapolation(UInt i) const
Return the i-th coefficient of the time extrapolation beta_i.
feVectorPtrContainer_Type M_unknowns
Last n state vectors.
void showMe() const
Show informations about the BDF.
TimeAdvanceBDFVariableStep()
Empty constructor.
~TimeAdvanceBDFVariableStep()
Destructor.
const feVectorPtrContainer_Type & stateVector() const
Return a vector with the last n state vectors.
double Real
Generic real data.
feVector_Type rhsContributionTimeStep(Real timeStep=1) const
Returns the right hand side of the time derivative formula divided by timeStep (backward compatibili...
container_Type M_alpha
Coefficients of the time bdf discretization.
void computeCoefficient()
Private methods.
const container_Type & timeStepVector() const
Return the vector of the time steps, ordered starting from the most recent one.
void setInitialCondition(feVector_Type u0, Real const timeStep, bool startup=0)
Initialize all the entries of the unknown vector to be derived with the vector u0 (duplicated if star...
boost::numeric::ublas::vector< Real > ScalarVector
const Real & coefficientDerivative(UInt i) const
Return the i-th coefficient of the time derivative alpha_i.
std::shared_ptr< feVector_Type > feVectorPtr_Type
void shiftRight(feVector_Type const &uCurrent)
Update the vectors of the previous time steps by shifting on the right the old values.
ScalarVector container_Type
feVector_Type rhsContribution() const
Returns the right hand side of the time derivative formula divided by dt.
void setInitialCondition(const FunctionType &u0Function, feVector_Type &u0Vector, FESpaceType &feSpace, Real t0, Real timeStep)
Initialize all the entries of the unknonwn vectors with a given function.
uint32_type UInt
generic unsigned integer (used mainly for addressing)