40 #ifndef VENANTKIRCHHOFFVISCOELASTICSOLVER_H_ 41 #define VENANTKIRCHHOFFVISCOELASTICSOLVER_H_ 1
44 #include <Epetra_Vector.h> 45 #include <EpetraExt_MatrixMatrix.h> 47 #include<boost/scoped_ptr.hpp> 50 #include <lifev/core/array/MatrixElemental.hpp> 51 #include <lifev/core/array/VectorElemental.hpp> 52 #include <lifev/core/array/MatrixEpetra.hpp> 53 #include <lifev/core/array/VectorEpetra.hpp> 55 #include <lifev/core/fem/AssemblyElemental.hpp> 56 #include <lifev/core/fem/Assembly.hpp> 57 #include <lifev/core/fem/BCManage.hpp> 58 #include <lifev/core/fem/FESpace.hpp> 60 #include <lifev/core/util/LifeChrono.hpp> 62 #include <lifev/core/algorithm/SolverAztecOO.hpp> 64 #include <lifev/structure/solver/VenantKirchhoffViscoelasticData.hpp> 65 #include <lifev/core/util/Displayer.hpp> 84 template <
typename Mesh,
85 typename SolverType = LifeV::SolverAztecOO >
134 void setup ( std::shared_ptr<data_type> data,
135 const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
136 std::shared_ptr<Epetra_Comm>& comm
146 void setup ( std::shared_ptr<data_type> data,
147 const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
149 std::shared_ptr<Epetra_Comm>& comm
161 virtual void setup ( std::shared_ptr<data_type> data,
162 const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
163 std::shared_ptr<Epetra_Comm>& comm,
164 const std::shared_ptr<
const MapEpetra>& epetraMap,
204 const Real& alpha = 0 );
236 M_displayer->leaderPrint (
" P- Updating right hand side... ");
242 M_rhsNoBC->globalAssemble();
245 M_displayer->leaderPrintMax (
"done in ", chrono.diff() );
534 template <
typename Mesh,
typename SolverType>
570 template <
typename Mesh,
typename SolverType>
573 std::shared_ptr<data_type> data,
574 const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
575 std::shared_ptr<Epetra_Comm>& comm,
576 const std::shared_ptr<
const MapEpetra>& epetraMap,
582 M_displayer.reset (
new Displayer (comm) );
583 M_me = comm->MyPID();
584 M_elmatK.reset (
new MatrixElemental ( M_FESpace->fe().nbFEDof(), nDimensions, nDimensions ) );
585 M_elmatM.reset (
new MatrixElemental ( M_FESpace->fe().nbFEDof(), nDimensions, nDimensions ) );
586 M_elmatC.reset (
new MatrixElemental ( M_FESpace->fe().nbFEDof(), nDimensions, nDimensions ) );
587 M_elmatD.reset (
new MatrixElemental ( M_FESpace->fe().nbFEDof(), nDimensions, nDimensions ) );
588 M_localMap = epetraMap;
589 M_solution.reset (
new vector_type (*M_localMap) );
590 M_rhsNoBC.reset (
new vector_type (*M_localMap) );
591 M_matrMass.reset (
new matrix_type (*M_localMap) );
592 M_matrLinearStiffness.reset (
new matrix_type (*M_localMap) );
593 M_matrDamping.reset (
new matrix_type (*M_localMap) );
594 M_matrSystem.reset (
new matrix_type (*M_localMap) );
598 template <
typename Mesh,
typename SolverType>
601 std::shared_ptr<data_type> data,
602 const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
603 std::shared_ptr<Epetra_Comm>& comm
606 setup ( data, feSpace, comm, feSpace->mapPtr(), (UInt) 0 );
607 M_rhs.reset (
new vector_type (*M_localMap) );
608 M_residual.reset (
new vector_type (*M_localMap) );
609 M_linearSolver.reset (
new SolverType ( comm ) );
613 template <
typename Mesh,
typename SolverType>
616 std::shared_ptr<data_type> data,
617 const std::shared_ptr< FESpace<Mesh, MapEpetra> >& feSpace,
619 std::shared_ptr<Epetra_Comm>& comm
622 setup (data, feSpace, comm);
626 template <
typename Mesh,
typename SolverType>
630 M_linearSolver->setDataFromGetPot ( dataFile,
"problem/solver" );
631 M_linearSolver->setupPreconditioner (dataFile,
"problem/prec");
634 template <
typename Mesh,
typename SolverType>
639 M_displayer->leaderPrint (
" P- Computing constant matrices ... ");
646 if (M_data->damping() )
648 M_matrDamping.reset (
new matrix_type (*M_localMap) );
651 M_matrSystem->globalAssemble();
654 M_displayer->leaderPrintMax (
"done in ", chrono.diff() );
657 template <
typename Mesh,
typename SolverType>
662 M_displayer->leaderPrint (
"P- Building the system ... ");
670 for (
UInt iVol = 0; iVol <
this->M_FESpace->mesh()->numVolumes(); ++iVol )
672 this->M_FESpace->fe().updateFirstDeriv (
this->M_FESpace->mesh()->element ( iVol ) );
674 Int marker =
this->M_FESpace->mesh()->volumeList ( iVol ).markerID();
676 this->M_elmatK->zero();
677 this->M_elmatM->zero();
680 AssemblyElemental::stiff_strain ( 2 * M_data->mu (marker), *
this->M_elmatK,
this->M_FESpace->fe() );
681 AssemblyElemental::stiff_div ( M_data->lambda (marker), *
this->M_elmatK, M_FESpace->fe() );
683 this->M_elmatC->mat() =
this->M_elmatK->mat();
687 AssemblyElemental::mass ( xi * M_data->rho(), *
this->M_elmatM,
this->M_FESpace->fe(), 0, 0, nDimensions );
689 this->M_elmatC->mat() +=
this->M_elmatM->mat();
692 this->M_elmatM->zero();
693 AssemblyElemental::mass (M_data->rho(), *
this->M_elmatM,
this->M_FESpace->fe(), 0, 0, nDimensions );
695 assembleMatrix ( *M_matrLinearStiffness,
697 this->M_FESpace->fe(),
698 this->M_FESpace->fe(),
699 this->M_FESpace->dof(),
700 this->M_FESpace->dof(),
703 assembleMatrix ( *matrSystem,
705 this->M_FESpace->fe(),
706 this->M_FESpace->fe(),
707 this->M_FESpace->dof(),
708 this->M_FESpace->dof(),
711 assembleMatrix ( *
this->M_matrMass,
713 this->M_FESpace->fe(),
714 this->M_FESpace->fe(),
715 this->M_FESpace->dof(),
716 this->M_FESpace->dof(),
720 M_matrMass->globalAssemble();
721 M_matrLinearStiffness->globalAssemble();
723 M_displayer->leaderPrintMax (
"done in ", chrono.diff() );
727 template <
typename Mesh,
typename SolverType>
734 M_displayer->leaderPrint (
"P- Building the system Damping matrix ... ");
738 for (
UInt iVol = 0; iVol <
this->M_FESpace->mesh()->numVolumes(); ++iVol )
740 this->M_FESpace->fe().updateFirstDeriv (
this->M_FESpace->mesh()->element ( iVol ) );
742 Int marker =
this->M_FESpace->mesh()->volumeList ( iVol ).markerID();
744 Real gamma = M_data->gamma (marker);
745 Real beta = M_data->beta (marker);
749 this->M_elmatD->zero();
751 AssemblyElemental::stiff_strain ( 2.0 * M_data->mu (marker) * gamma , *
this->M_elmatD,
this->M_FESpace->fe() );
752 AssemblyElemental::stiff_div ( M_data->lambda (marker) * gamma, *
this->M_elmatD,
this->M_FESpace->fe() );
753 AssemblyElemental::mass ( beta * M_data->rho(), *
this->M_elmatD,
this->M_FESpace->fe(), 0, 0);
755 assembleMatrix ( *damping,
757 this->M_FESpace->fe(),
758 this->M_FESpace->fe(),
759 this->M_FESpace->dof(),
760 this->M_FESpace->dof(),
764 *M_matrSystem += *damping * alpha;
765 *M_matrDamping = *damping;
767 M_matrDamping->globalAssemble();
768 M_displayer->leaderPrintMax (
" done in ", chrono.diff() );
771 template <
typename Mesh,
typename SolverType>
782 if (xi == 0 & alpha == 0 )
784 M_displayer->leaderPrint (
"P - use the same System matrix ... \n ");
788 M_displayer->leaderPrint (
"P - updating the System matrix .... ");
794 *M_matrSystem += *M_matrMass * xi;
799 *M_matrSystem += *M_matrDamping * alpha;
802 M_matrSystem->GlobalAssemble();
805 M_displayer->leaderPrintMax (
"done in ", chrono.diff() );
810 template <
typename Mesh,
typename SolverType>
818 std::string precType =
"Ifpack" ;
820 prec.reset ( PRECFactory::instance().createObject (precType) );
824 Real condest = prec->Condest();
826 M_linearSolver->setPreconditioner (prec);
828 M_linearSolver->setMatrix (*M_matrMass);
830 Int numIter = M_linearSolver->solve (solution, rhs);
833 template <
typename Mesh,
typename SolverType>
837 M_displayer->leaderPrint (
"P - updating the Source Term.... ");
841 for (
UInt iVol = 0; iVol <
this->M_FESpace->mesh()->numVolumes(); ++iVol )
846 UInt i, inod, ig, ic;
847 UInt eleID =
this->M_FESpace->fe().currentLocalId();
851 for ( ig = 0; ig <
this->M_FESpace->fe().nbQuadPt(); ++ig )
853 this->M_FESpace->fe().coorQuadPt ( x, y, z, ig );
854 f = M_source (M_data->dataTime()->time(), x, y, z, iComp + 1 );
857 for ( i = 0; i < M_FESpace->fe().nbFEDof(); ++i )
859 inod =
this->M_FESpace->dof().localToGlobalMap ( eleID, i ) + iComp *
this->M_FESpace->dof().numTotalDof();
860 u_ig = f *
this->M_FESpace->fe().phi ( i, ig );
861 source.sumIntoGlobalValues (inod, u_ig *
this->M_FESpace->fe().weightDet ( ig ) );
866 source.GlobalAssemble();
869 M_displayer->leaderPrintMax (
"done on ", chrono.diff() );
872 template <
typename Mesh,
typename SolverType>
879 M_displayer->leaderPrint (
" P- Solving the system ... \n");
883 matrix_ptrtype matrFull (
new matrix_type (*M_localMap, M_matrSystem->meanNumEntries() ) );
884 *matrFull += *M_matrSystem;
886 M_rhsNoBC->globalAssemble();
891 M_displayer->leaderPrint (
" P- Applying boundary conditions ... ");
894 this->applyBoundaryConditions (*matrFull, rhsFull, bch);
898 M_displayer->leaderPrintMax (
"done in " , chrono.diff() );
900 M_linearSolver->resetPreconditioner();
904 M_linearSolver->setMatrix (*matrFull);
905 Real numIter = M_linearSolver->solveSystem ( rhsFull, *M_solution, matrFull);
907 numIter = std::abs (numIter);
914 *M_residual = *M_matrSystem * ( *M_solution);
915 *M_residual -= *M_rhsNoBC;
923 template<
typename Mesh,
typename SolverType>
932 BCh.setOffset (offset);
935 if ( !BCh.bcUpdateDone() )
937 BCh.bcUpdate ( *
this->M_FESpace->mesh(),
this->M_FESpace->feBd(),
this->M_FESpace->dof() );
942 bcManage ( matrix, rhsFull, *
this->M_FESpace->mesh(),
this->M_FESpace->dof(), BCh,
this->M_FESpace->feBd(), 1., M_data->dataTime()->time() );
VenantKirchhoffViscoelasticData data_type
std::shared_ptr< MatrixElemental > M_elmatK
linear stiffness
std::shared_ptr< const MapEpetra > M_localMap
Epetra map need to define the VectorEpetra;.
std::unique_ptr< Displayer > M_displayer
displayer
bool M_reusePrec
true if reuse the preconditonar
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > source_type
matrix_ptrtype const matrSystem() const
Return the damping matrix.
std::shared_ptr< solver_type > M_linearSolver
data for solving tangent problem with aztec
void resetPrec()
reset the Prec
Displayer const & displayer() const
Return the map.
vector_ptrtype M_rhs
right hand side
matrix_type const matrMass() const
Return the mass matrix.
FESpace - Short description here please!
UInt M_maxIterSolver
maximum number of iteration for solver method
std::shared_ptr< MatrixElemental > M_elmatD
damping
vector_ptrtype & solution()
Return the solution.
SolverType::prec_raw_type prec_raw_type
matrix_ptrtype M_matrLinearStiffness
Matrix stiffness linear.
virtual void setup(std::shared_ptr< data_type > data, const std::shared_ptr< FESpace< Mesh, MapEpetra > > &feSpace, std::shared_ptr< Epetra_Comm > &comm, const std::shared_ptr< const MapEpetra > &epetraMap, UInt offset=0)
class setup
std::shared_ptr< MatrixElemental > M_elmatM
mass
void setSourceTerm(source_type const &source)
Sets source term.
std::shared_ptr< data_type > M_data
data of problem
void setup(std::shared_ptr< data_type > data, const std::shared_ptr< FESpace< Mesh, MapEpetra > > &feSpace, bchandler_type &BCh, std::shared_ptr< Epetra_Comm > &comm)
class setup
void buildDamping(matrix_ptrtype damping, const Real &alpha)
build Damping matrix
matrix_ptrtype const matrLinearStiff() const
Return the Stiffness matrix.
int32_type Int
Generic integer data.
void setDataFromGetPot(const GetPot &dataFile)
Set parameters.
UInt M_maxIterForReuse
max number of iteration before to update preconditonator
matrix_ptrtype M_matrSystem
Matrix System.
void setup(std::shared_ptr< data_type > data, const std::shared_ptr< FESpace< Mesh, MapEpetra > > &feSpace, std::shared_ptr< Epetra_Comm > &comm)
class setup
MapEpetra const & map() const
Return the map.
matrix_ptrtype M_matrMass
Matrix mass.
SolverType::prec_type prec_type
Epetra_Import const & importer()
Getter for the Epetra_Import.
std::shared_ptr< MatrixElemental > M_elmatC
mass+ linear stiffness
std::shared_ptr< matrix_type > matrix_ptrtype
BCHandler bchandler_raw_type
std::shared_ptr< vector_type > M_residual
residual
virtual ~VenantKirchhoffViscoelasticSolver()
virtual Destructor
solver_type::matrix_type matrix_type
void computeStartValue(vector_type &solution, const bchandler_raw_type &bch, const vector_type &rhs)
compute the start solution
std::shared_ptr< vector_type > vector_ptrtype
FESpace< Mesh, MapEpetra > & feSpace()
Return FESpace.
vector_ptrtype M_rhsNoBC
right hand side without boundary condition
void buildSystem(matrix_ptrtype matrix, const Real &xi)
buildSystem
void buildSystem(const Real &xi=1, const Real &alpha=0)
buildSystem
std::shared_ptr< FESpace< Mesh, MapEpetra > > M_FESpace
feSpace
vector_ptrtype & residual()
Return residual.
double Real
Generic real data.
matrix_ptrtype M_matrDamping
Matrix Damping .
std::shared_ptr< bchandler_raw_type > bchandler_type
void updateSystem(const vector_type &rhs, const Real &xi=0, const Real &alpha=0)
updateSystem with coefficients of time advance methods
vector_ptrtype & rhsContributionSecondDerivativeithoutBC()
Return right hand side without boundary conditions.
const UInt nDimensions(NDIM)
solver_type::vector_type vector_type
BCHandler const & BChandler() const
BCHandler getter and setter.
void updateSourceTerm(const vector_type &source)
update source term
void applyBoundaryConditions(matrix_type &matrix, vector_type &rhs, bchandler_raw_type &BCh, UInt offset=0)
apply boundary condition
void iterate(bchandler_raw_type &bch)
Solve the system.
matrix_ptrtype const matrDamping() const
Return the damping matrix.
VenantKirchhoffViscoelasticSolver()
Constructor.
source_type M_source
source term
uint32_type UInt
generic unsigned integer (used mainly for addressing)
void updateRHS(const vector_type &rhs)
updateRHS
bchandler_type M_BCh
boundary condition
vector_ptrtype M_solution
unknowns vector
bool M_resetPrec
reset preconditionator