39 #define TIMEADVANCE_H 1
46 #include <lifev/core/LifeV.hpp> 47 #include <lifev/core/util/Factory.hpp> 48 #include <lifev/core/util/FactorySingleton.hpp> 49 #include <lifev/core/array/VectorEpetra.hpp> 53 typedef boost::numeric::ublas::vector<Real> ScalarVector;
128 template<
typename feVectorType = VectorEpetra >
137 typedef feVectorType feVector_Type;
140 typedef ScalarVector container_Type;
143 typedef std::vector<feVector_Type> feVectorContainer_Type;
146 typedef std::vector<feVector_Type*> feVectorContainerPtr_Type;
149 typedef typename feVectorContainerPtr_Type::iterator feVectorContainerPtrIterate_Type;
152 typedef std::vector<std::shared_ptr<feVector_Type> > feVectorSharedPtrContainer_Type;
162 virtual ~TimeAdvance();
175 virtual void shiftRight (
const feVector_Type& solution ) = 0;
181 void updateRHSContribution (
const Real& timeStep);
193 virtual void RHSFirstDerivative (
const Real& timeStep, feVectorType& rhsContribution )
const = 0;
201 void updateRHSFirstDerivative (
const Real& timeStep = 1 );
209 virtual void updateRHSSecondDerivative (
const Real& timeStep = 1 ) = 0;
215 virtual void showMe (std::ostream& output = std::cout)
const = 0;
225 void spyStateVector();
246 void setup (
const UInt& orderDerivative )
248 M_orderDerivative = orderDerivative;
256 virtual void setup (
const UInt& order,
const UInt& orderDerivative ) = 0;
263 virtual void setup (
const std::vector<Real>& coefficients,
const UInt& orderDerivative ) = 0;
271 virtual void setInitialCondition (
const feVector_Type& x0) = 0;
280 virtual void setInitialCondition (
const feVector_Type& x0,
const feVector_Type& v0) = 0;
290 virtual void setInitialCondition (
const feVector_Type& x0,
const feVector_Type& v0,
const feVector_Type& w0) = 0;
298 virtual void setInitialCondition (
const feVectorSharedPtrContainer_Type& )
300 ERROR_MSG (
"this method is not implemented.");
309 void setInitialRHS (
const feVector_Type& rhs0 ) ;
315 void setTimeStep (
const Real& timeStep)
317 M_timeStep = timeStep;
330 Real coefficientFirstDerivative (
const UInt& i)
const;
337 inline Real coefficientSecondDerivative (
const UInt& i)
const;
344 virtual Real coefficientExtrapolation (
const UInt& i )
const = 0;
352 virtual Real coefficientExtrapolationFirstDerivative (
const UInt& i )
const = 0;
360 virtual void extrapolation (feVector_Type& extrapolation)
const = 0;
368 virtual void extrapolationFirstDerivative (feVector_Type& extrapolation)
const = 0;
375 inline const feVector_Type& singleElement (
const UInt& i)
const;
378 inline const feVector_Type& solution()
const;
380 void setSolution (
const feVector_Type& solution )
383 if (M_unknowns[0] != NULL )
385 *M_unknowns[0] = solution;
389 M_unknowns[0] =
new feVector_Type (solution);
397 virtual feVectorType firstDerivative()
const = 0;
406 feVectorType firstDerivative (
const feVector_Type& u)
const;
409 virtual feVectorType secondDerivative()
const = 0;
417 feVector_Type acceleration (feVector_Type& u)
const;
423 const feVector_Type& rhsContributionFirstDerivative()
const 425 return *M_rhsContribution[0];
432 const feVector_Type& rhsContributionSecondDerivative()
const 434 return *M_rhsContribution[1];
457 feVectorContainerPtr_Type& stencil()
471 UInt M_orderDerivative;
480 UInt M_firstOrderDerivativeSize;
483 UInt M_secondOrderDerivativeSize;
486 UInt M_coefficientsSize;
492 container_Type M_alpha;
495 container_Type M_beta;
498 container_Type M_betaFirstDerivative;
501 feVectorContainerPtr_Type M_unknowns;
504 feVectorContainerPtr_Type M_rhsContribution;
512 template<
typename feVectorType>
513 TimeAdvance<feVectorType>::TimeAdvance()
518 M_unknowns.reserve ( 1 );
519 M_rhsContribution.reserve (2);
523 template<
typename feVectorType>
524 TimeAdvance<feVectorType>::~TimeAdvance()
526 feVectorContainerPtrIterate_Type iter = M_unknowns.begin();
527 feVectorContainerPtrIterate_Type iter_end = M_unknowns.end();
529 for ( ; iter != iter_end; iter++ )
539 template<
typename feVectorType>
541 TimeAdvance<feVectorType>::
542 updateRHSContribution (
const Real& timeStep )
545 this->updateRHSFirstDerivative ( timeStep );
548 if ( M_orderDerivative == 2 )
550 this->updateRHSSecondDerivative ( timeStep );
555 template<
typename feVectorType>
557 TimeAdvance<feVectorType>::updateRHSFirstDerivative (
const Real& timeStep )
559 feVectorContainerPtrIterate_Type it =
this->M_rhsContribution.begin();
564 *it =
new feVector_Type (*
this->M_unknowns[ 0 ]);
568 **it = *
this->M_unknowns[ 0 ];
571 this->RHSFirstDerivative ( timeStep, **it );
575 template<
typename feVectorType>
577 TimeAdvance<feVectorType>::
580 static UInt saveUnknowns = 0;
581 std::string unknowns =
"unknowns";
583 for (
UInt i = 0 ; i < M_size ; i++ )
585 std::ostringstream j;
591 M_unknowns[i]->spy (unknowns + j.str() );
596 template<
typename feVectorType>
598 TimeAdvance<feVectorType>::
601 static UInt saveRhs = 0;
602 std::string rhs =
"rhs";
603 for (
UInt i = 0 ; i < 2 ; ++i )
605 std::ostringstream j;
610 M_rhsContribution[i]->spy (rhs + j.str() );
619 template<
typename feVectorType>
621 TimeAdvance<feVectorType>::setInitialRHS (
const feVector_Type& rhs )
623 for (
UInt i = 0; i < 2; ++i )
625 M_rhsContribution.push_back (
new feVector_Type (rhs) );
632 template<
typename feVectorType>
634 TimeAdvance<feVectorType>::coefficientFirstDerivative (
const UInt& i)
const 637 ASSERT ( i < M_coefficientsSize,
638 "Error in specification of the time derivative coefficient for the time scheme" );
642 template<
typename feVectorType>
644 TimeAdvance<feVectorType>::coefficientSecondDerivative (
const UInt& i )
const 647 ASSERT ( i < M_coefficientsSize,
648 "Error in specification of the time derivative coefficient for the time scheme" );
652 template<
typename feVectorType>
653 inline const feVectorType&
654 TimeAdvance<feVectorType>::solution()
const 656 return *M_unknowns[0];
660 template<
typename feVectorType>
661 inline const feVectorType&
662 TimeAdvance<feVectorType>::singleElement (
const UInt& i)
const 665 "Error there isn't unk(i), i must be shorter than M_size" );
667 return *M_unknowns[i];
670 template<
typename feVectorType>
672 TimeAdvance<feVectorType>::firstDerivative (
const feVector_Type& u )
const 674 feVector_Type vel ( u );
675 vel *= M_alpha[ 0 ] / M_timeStep;
676 vel -= (*
this->M_rhsContribution[ 0 ]);
681 template<
typename feVectorType>
683 TimeAdvance<feVectorType>::acceleration (feVector_Type& u)
const 685 feVector_Type accelerate (u);
686 accelerate *= M_xi[ 0 ] / (M_timeStep * M_timeStep );
687 accelerate -= (*
this->M_rhsContribution[1]);
696 typedef FactorySingleton< Factory < TimeAdvance<>, std::string> > TimeAdvanceFactory;
double Real
Generic real data.
uint32_type UInt
generic unsigned integer (used mainly for addressing)