LifeV
AssemblyPolicyGeneralizedStokes.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 AssemblyPolicyGeneralizedStokes class
29  @brief This class contains all the informations necessary
30  to assemble a Generalized Stokes
31 
32  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
33  @date 11-12-2012
34  */
35 
36 #ifndef ASSEMBLYPOLICYGENERALIZEDSTOKES_HPP
37 #define ASSEMBLYPOLICYGENERALIZEDSTOKES_HPP
38 
39 #include <iostream>
40 #include <string>
41 #include <boost/shared_ptr.hpp>
42 
43 
44 #ifdef HAVE_MPI
45 #include <Epetra_MpiComm.h>
46 #else
47 #include <Epetra_SerialComm.h>
48 #endif
49 
50 #include <Teuchos_ParameterList.hpp>
51 #include <Teuchos_XMLParameterListHelpers.hpp>
52 #include <Teuchos_RCP.hpp>
53 
54 
55 #include <lifev/core/LifeV.hpp>
56 #include <lifev/core/array/MatrixEpetra.hpp>
57 #include <lifev/core/array/VectorEpetra.hpp>
58 #include <lifev/core/util/Displayer.hpp>
59 #include <lifev/core/mesh/RegionMesh.hpp>
60 #include <lifev/core/fem/FESpace.hpp>
61 #include <lifev/core/fem/TimeAdvanceBDF.hpp>
62 #include <lifev/core/algorithm/Preconditioner.hpp>
63 #include <lifev/core/util/LifeChrono.hpp>
64 #include <lifev/navier_stokes/solver/OseenAssembler.hpp>
65 
66 #include <lifev/navier_stokes/solver/NavierStokesSolver/NavierStokesProblem.hpp>
67 
68 
69 namespace LifeV
70 {
71 
72 template< class mesh_Type >
74 {
80  typedef MeshPartitioner< mesh_Type > meshPartitioner_Type;
83  typedef FESpace< mesh_Type, map_Type > fespace_Type;
85  typedef TimeAdvanceBDF<vector_Type> bdf_Type;
87  typedef OseenAssembler< mesh_Type, matrix_Type, vector_Type > assembler_Type;
91 
94 
95  enum { BDFOrder = 1 };
96 
97  void initAssembly ( Teuchos::ParameterList& list );
98 
99  void assembleSystem ( matrixPtr_Type systemMatrix,
100  vectorPtr_Type rhs,
101  vectorPtr_Type solution,
102  preconditionerPtr_Type preconditioner );
103 
106 
107  virtual Displayer displayer() = 0;
108  virtual Real currentTime() const = 0;
109  virtual fespacePtr_Type uFESpace() const = 0;
110  virtual fespacePtr_Type pFESpace() const = 0;
111  virtual NSProblemPtr_Type problem() const = 0;
112  virtual Real timestep() const = 0;
113 };
114 
115 template< class mesh_Type >
116 void
117 AssemblyPolicyGeneralizedStokes< mesh_Type >::initAssembly ( Teuchos::ParameterList& list )
118 {
119  // Loading the parameters
120  std::string diffusionType = list.get ( "Diffusion type", "Viscous stress" );
121  bool useMinusDiv = list.get ( "Use minus divergence", true );
122 
123  // +-----------------------------------------------+
124  // | Matrices Assembly |
125  // +-----------------------------------------------+
126  displayer().leaderPrint ( "\n[Matrices Assembly]\n" );
127 
128  LifeChrono assemblyChrono;
129  assemblyChrono.start();
130 
131  displayer().leaderPrint ( "Setting up assembler... " );
132  M_assembler.reset ( new assembler_Type );
133  M_assembler->setup ( uFESpace(), pFESpace() );
134  displayer().leaderPrint ( "done\n" );
135 
136  displayer().leaderPrint ( "Defining the matrices... " );
137  map_Type solutionMap ( uFESpace()->map() + pFESpace()->map() );
138  M_stokesMatrix.reset ( new matrix_Type ( solutionMap ) );
139  M_stokesMatrix->zero();
140  displayer().leaderPrint ( "done\n" );
141 
142  // Perform the assembly of the matrix
143  if ( diffusionType == "Viscous stress" )
144  {
145  displayer().leaderPrint ( "Adding the viscous stress... " );
146  M_assembler->addViscousStress ( *M_stokesMatrix, problem()->viscosity() / problem()->density() );
147  displayer().leaderPrint ( "done\n" );
148  }
149  else if ( diffusionType == "Stiff strain" )
150  {
151  displayer().leaderPrint ( "Adding the stiff strain... " );
152  M_assembler->addStiffStrain ( *M_stokesMatrix, problem()->viscosity() / problem()->density() );
153  displayer().leaderPrint ( "done\n" );
154  }
155  else
156  {
157  displayer().leaderPrint ( "[Error] Diffusion type unknown\n" );
158  exit ( 1 );
159  }
160 
161  displayer().leaderPrint ( "Adding the gradient of the pressure... " );
162  M_assembler->addGradPressure ( *M_stokesMatrix );
163  displayer().leaderPrint ( "done\n" );
164 
165  displayer().leaderPrint ( "Adding the divergence free constraint... " );
166  if ( useMinusDiv )
167  {
168  M_assembler->addDivergence ( *M_stokesMatrix, -1.0 );
169  }
170  else
171  {
172  M_assembler->addDivergence ( *M_stokesMatrix, 1.0 );
173  }
174  displayer().leaderPrint ( "done\n" );
175 
176  displayer().leaderPrint ( "Adding the mass... " );
177  M_assembler->addMass ( *M_stokesMatrix, 1.0 / timestep() );
178  displayer().leaderPrint ( "done\n" );
179 
180  displayer().leaderPrint ( "Closing the matrices... " );
181  M_stokesMatrix->globalAssemble();
182  displayer().leaderPrint ( "done\n" );
183 
184  assemblyChrono.stop();
185  displayer().leaderPrintMax ("Matrices assembly time: ", assemblyChrono.diff(), " s.\n");
186 }
187 
188 template< class mesh_Type >
189 void
191  vectorPtr_Type rhs,
192  vectorPtr_Type /*solution*/,
193  preconditionerPtr_Type /*preconditioner*/ )
194 {
195  *systemMatrix += *M_stokesMatrix;
196 
197  M_assembler->addMassRhs ( *rhs, problem()->force(), currentTime() );
198 }
199 
200 } // namespace LifeV
201 
202 #endif /* ASSEMBLYPOLICYGENERALIZEDSTOKES_HPP */
VectorEpetra - The Epetra Vector format Wrapper.
void start()
Start the timer.
Definition: LifeChrono.hpp:93
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
void updateInverseJacobian(const UInt &iQuadPt)
virtual Real timestep() const =0
virtual fespacePtr_Type pFESpace() const =0
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
Real diff()
Compute the difference in time between start and stop.
Definition: LifeChrono.hpp:111
std::shared_ptr< preconditioner_Type > preconditionerPtr_Type
virtual fespacePtr_Type uFESpace() const =0
OseenAssembler< mesh_Type, matrix_Type, vector_Type > assembler_Type
std::shared_ptr< NavierStokesProblem< mesh_Type > > NSProblemPtr_Type
double Real
Generic real data.
Definition: LifeV.hpp:175
Preconditioner - Abstract preconditioner class.
void stop()
Stop the timer.
Definition: LifeChrono.hpp:100
virtual Real currentTime() const =0
void assembleSystem(matrixPtr_Type systemMatrix, vectorPtr_Type rhs, vectorPtr_Type solution, preconditionerPtr_Type preconditioner)
virtual NSProblemPtr_Type problem() const =0
Displayer - This class is used to display messages in parallel simulations.
Definition: Displayer.hpp:62