LifeV
InitPolicyProjection.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file InitPolicyProjection class
29  @brief This class is a strategy to initialize a Navier-Stokes problem
30 
31  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
32  @date 11-12-2012
33  */
34 
35 #ifndef INITPOLICYPROJECTION_HPP
36 #define INITPOLICYPROJECTION_HPP
37 
38 #include <iostream>
39 #include <boost/shared_ptr.hpp>
40 
41 
42 #ifdef HAVE_MPI
43 #include <Epetra_MpiComm.h>
44 #else
45 #include <Epetra_SerialComm.h>
46 #endif
47 
48 #include <Teuchos_ParameterList.hpp>
49 #include <Teuchos_XMLParameterListHelpers.hpp>
50 #include <Teuchos_RCP.hpp>
51 
52 
53 #include <lifev/core/LifeV.hpp>
54 #include <lifev/core/array/VectorEpetra.hpp>
55 #include <lifev/core/array/MatrixEpetra.hpp>
56 #include <lifev/core/util/Displayer.hpp>
57 #include <lifev/core/mesh/RegionMesh.hpp>
58 #include <lifev/core/fem/FESpace.hpp>
59 #include <lifev/core/fem/TimeAdvanceBDF.hpp>
60 #include <lifev/core/fem/BCHandler.hpp>
61 // #include <lifev/navier_stokes/algorithm/PreconditionerPCD.hpp>
62 #include <lifev/navier_stokes/solver/NavierStokesSolver/NavierStokesProblem.hpp>
63 #include <lifev/navier_stokes/solver/NavierStokesSolver/SolverPolicyLinearSolver.hpp>
64 #include <lifev/navier_stokes/solver/NavierStokesSolver/AssemblyPolicyStokes.hpp>
65 
66 
67 namespace LifeV
68 {
69 
70 template< class mesh_Type, class SolverPolicy = SolverPolicyLinearSolver >
71 struct InitPolicyProjection : public virtual SolverPolicy, public AssemblyPolicyStokes< mesh_Type >
72 {
77  typedef MeshPartitioner< mesh_Type > meshPartitioner_Type;
80  typedef FESpace< mesh_Type, map_Type > fespace_Type;
82  typedef TimeAdvanceBDF<vector_Type> bdf_Type;
87 
89  virtual ~InitPolicyProjection() {}
90 
91  void setupInit ( Teuchos::ParameterList& list );
92 
93  void initSimulation ( bcContainerPtr_Type bchandler,
94  vectorPtr_Type solution );
95 
96 private:
98 
99  virtual Displayer displayer() = 0;
100  virtual fespacePtr_Type uFESpace() const = 0;
101  virtual fespacePtr_Type pFESpace() const = 0;
102  virtual Real timestep() const = 0;
103  virtual Real initialTime() const = 0;
104  virtual bdfPtr_Type bdf() const = 0;
105  virtual NSProblemPtr_Type problem() const = 0;
106 
107 };
108 
109 template< class mesh_Type, class SolverPolicy >
110 void
111 InitPolicyProjection< mesh_Type, SolverPolicy >::
112 setupInit ( Teuchos::ParameterList& list )
113 {
114  Teuchos::ParameterList assemblyList = list.sublist ( "Assembly: Parameter list" );
115  M_list = list;
116 }
117 
118 template< class mesh_Type, class SolverPolicy >
119 void
120 InitPolicyProjection< mesh_Type, SolverPolicy >::
122  vectorPtr_Type solution )
123 {
124  ASSERT ( problem()->hasExactSolution(), "Error: You cannot use the projection method if the problem has not an analytical solution." );
125 
126  Real currentTime = initialTime() - timestep() * bdf()->order();
127  UInt pressureOffset = uFESpace()->fieldDim() * uFESpace()->dof().numTotalDof();
128 
129  vectorPtr_Type rhs;
130  rhs.reset ( new vector_Type ( uFESpace()->map() + pFESpace()->map(), Unique ) );
131 
132  vectorPtr_Type velocity;
133  velocity.reset ( new vector_Type ( uFESpace()->map(), Unique ) );
134 
135  vectorPtr_Type pressure;
136  pressure.reset ( new vector_Type ( pFESpace()->map(), Unique ) );
137 
138  // Create a first solution
139  uFESpace()->interpolate ( problem()->uexact(), *velocity, currentTime );
140  pFESpace()->interpolate ( problem()->pexact(), *pressure, currentTime );
141  *solution = 0.0;
142  solution->add ( *velocity );
143  solution->add ( *pressure, pressureOffset );
144  bdf()->setInitialCondition ( *solution );
145  currentTime += timestep(); // we just added a first solution with interpolation
146 
147  AssemblyPolicyStokes< mesh_Type >::initAssembly ( M_list );
148 
149  displayer().leaderPrint ( "Creating the mass matrix... " );
150  map_Type solutionMap ( uFESpace()->map() + pFESpace()->map() );
151  matrixPtr_Type massMatrix;
152  massMatrix.reset ( new matrix_Type ( solutionMap ) );
153  massMatrix->zero();
154  AssemblyPolicyStokes< mesh_Type >::M_assembler->addMass ( *massMatrix, 1.0 );
155  massMatrix->globalAssemble();
156  displayer().leaderPrint ( "done\n" );
157 
158  matrixPtr_Type systemMatrix;
159 
160  for ( ; currentTime <= initialTime() + timestep() / 2.0; currentTime += timestep() )
161  {
162  *rhs = 0.0;
163  *solution = 0.0;
164  *velocity = 0.0;
165  *pressure = 0.0;
166 
167  uFESpace()->interpolate ( problem()->uexact(), *velocity, currentTime );
168  pFESpace()->interpolate ( problem()->pexact(), *pressure, currentTime );
169  solution->add ( *velocity );
170  solution->add ( *pressure, pressureOffset );
171 
172  uFESpace()->interpolate ( problem()->uderexact(), *rhs, currentTime );
173  rhs->globalAssemble();
174  *rhs *= -1.;
175  *rhs = ( *massMatrix ) * ( *rhs );
176 
177  displayer().leaderPrint ( "Updating the system... " );
178  systemMatrix.reset ( new matrix_Type ( solutionMap ) );
179  AssemblyPolicyStokes< mesh_Type >::assembleSystem ( systemMatrix, rhs, solution, SolverPolicy::preconditioner() );
180 
181  // We deal as in the semi-implicit way
182  AssemblyPolicyStokes< mesh_Type >::M_assembler->addConvection ( *systemMatrix, 1.0, *solution );
183 
184  if ( SolverPolicy::preconditioner()->preconditionerType() == "PCD" )
185  {
186  vector_Type beta ( systemMatrix->map(), Repeated );
187  beta += *solution;
188  PreconditionerPCD* pcdPtr = dynamic_cast<PreconditionerPCD*> ( SolverPolicy::preconditioner().get() );
189  pcdPtr->updateBeta ( beta );
190  }
191 
192  displayer().leaderPrint ( "done\n" );
193 
194  LifeChrono imposingBCChrono;
195  imposingBCChrono.start();
196  bcManage ( *systemMatrix, *rhs, *uFESpace()->mesh(), uFESpace()->dof(), *bchandler, uFESpace()->feBd(), 1.0, currentTime );
197  imposingBCChrono.stop();
198  displayer().leaderPrintMax ( "Time to impose BC: ", imposingBCChrono.diff(), " s.\n" );
199 
200  systemMatrix->globalAssemble();
201 
202  displayer().leaderPrint ( "Solving the system... \n" );
203  *solution = 0.0;
204  SolverPolicy::solve ( systemMatrix, rhs, solution );
205 
206  // Updating bdf
207  bdf()->shiftRight ( *solution );
208  }
209 }
210 
211 } // namespace LifeV
212 
213 #endif /* INITPOLICYPROJECTION_HPP */
VectorEpetra - The Epetra Vector format Wrapper.
PreconditionerPCD(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
default constructor
std::shared_ptr< bcContainer_Type > bcContainerPtr_Type
void start()
Start the timer.
Definition: LifeChrono.hpp:93
std::shared_ptr< bdf_Type > bdfPtr_Type
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
BCHandler - class for handling boundary conditions.
Definition: BCHandler.hpp:100
virtual Real initialTime() const =0
virtual bdfPtr_Type bdf() const =0
virtual Displayer displayer()=0
virtual fespacePtr_Type pFESpace() const =0
void updateInverseJacobian(const UInt &iQuadPt)
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
virtual NSProblemPtr_Type problem() const =0
Real diff()
Compute the difference in time between start and stop.
Definition: LifeChrono.hpp:111
virtual Real timestep() const =0
std::shared_ptr< matrix_Type > matrixPtr_Type
void setupInit(Teuchos::ParameterList &list)
std::shared_ptr< fespace_Type > fespacePtr_Type
TimeAdvanceBDF< vector_Type > bdf_Type
double Real
Generic real data.
Definition: LifeV.hpp:175
std::shared_ptr< NavierStokesProblem< mesh_Type > > NSProblemPtr_Type
std::shared_ptr< map_Type > mapPtr_Type
FESpace< mesh_Type, map_Type > fespace_Type
void stop()
Stop the timer.
Definition: LifeChrono.hpp:100
void initSimulation(bcContainerPtr_Type bchandler, vectorPtr_Type solution)
virtual fespacePtr_Type uFESpace() const =0
MeshPartitioner< mesh_Type > meshPartitioner_Type
void updateBeta(const vector_Type &beta)
Update the vector beta of the convective term in Fp.
Displayer - This class is used to display messages in parallel simulations.
Definition: Displayer.hpp:62
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
std::shared_ptr< vector_Type > vectorPtr_Type