LifeV
AssemblyPolicyStokes.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 AssemblyPolicyStokes class
29  @brief This class contains all the informations necessary
30  to assemble a Stokes problem
31 
32  @author Gwenol Grandperrin <gwenol.grandperrin@epfl.ch>
33  @date 05-12-2012
34  */
35 
36 #ifndef ASSEMBLYPOLICYSTOKES_HPP
37 #define ASSEMBLYPOLICYSTOKES_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/util/LifeChrono.hpp>
63 #include <lifev/core/algorithm/Preconditioner.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 
92  enum { BDFOrder = 1 };
93 
94  void initAssembly ( Teuchos::ParameterList& list );
95 
96  void assembleSystem ( matrixPtr_Type systemMatrix,
97  vectorPtr_Type rhs,
98  vectorPtr_Type solution,
99  preconditionerPtr_Type preconditioner );
100 
103 
104  virtual Displayer displayer() = 0;
105  virtual Real currentTime() const = 0;
106  virtual fespacePtr_Type uFESpace() const = 0;
107  virtual fespacePtr_Type pFESpace() const = 0;
108  virtual NSProblemPtr_Type problem() const = 0;
109 };
110 
111 template< class mesh_Type >
112 void
113 AssemblyPolicyStokes< mesh_Type >::initAssembly ( Teuchos::ParameterList& list )
114 {
115  // Loading the parameters
116  std::string diffusionType = list.get ( "Diffusion type", "Viscous stress" );
117  bool useMinusDiv = list.get ( "Use minus divergence", true );
118 
119  // +-----------------------------------------------+
120  // | Matrices Assembly |
121  // +-----------------------------------------------+
122  displayer().leaderPrint ( "\n[Matrices Assembly]\n" );
123 
124  LifeChrono assemblyChrono;
125  assemblyChrono.start();
126 
127  displayer().leaderPrint ( "Setting up assembler... " );
128  M_assembler.reset ( new assembler_Type );
129  M_assembler->setup ( uFESpace(), pFESpace() );
130  displayer().leaderPrint ( "done\n" );
131 
132  displayer().leaderPrint ( "Defining the matrices... " );
133  map_Type solutionMap ( uFESpace()->map() + pFESpace()->map() );
134  M_stokesMatrix.reset ( new matrix_Type ( solutionMap ) );
135  M_stokesMatrix->zero();
136  displayer().leaderPrint ( "done\n" );
137 
138  // Perform the assembly of the matrix
139  if ( diffusionType == "Viscous stress" )
140  {
141  displayer().leaderPrint ( "Adding the viscous stress... " );
142  M_assembler->addViscousStress ( *M_stokesMatrix, problem()->viscosity() / problem()->density() );
143  displayer().leaderPrint ( "done\n" );
144  }
145  else if ( diffusionType == "Stiff strain" )
146  {
147  displayer().leaderPrint ( "Adding the stiff strain... " );
148  M_assembler->addStiffStrain ( *M_stokesMatrix, problem()->viscosity() / problem()->density() );
149  displayer().leaderPrint ( "done\n" );
150  }
151  else
152  {
153  displayer().leaderPrint ( "[Error] Diffusion type unknown\n" );
154  exit ( 1 );
155  }
156 
157  displayer().leaderPrint ( "Adding the gradient of the pressure... " );
158  M_assembler->addGradPressure ( *M_stokesMatrix );
159  displayer().leaderPrint ( "done\n" );
160 
161  displayer().leaderPrint ( "Adding the divergence free constraint... " );
162  if ( useMinusDiv )
163  {
164  M_assembler->addDivergence ( *M_stokesMatrix, -1.0 );
165  }
166  else
167  {
168  M_assembler->addDivergence ( *M_stokesMatrix, 1.0 );
169  }
170  displayer().leaderPrint ( "done\n" );
171 
172  displayer().leaderPrint ( "Closing the matrices... " );
173  M_stokesMatrix->globalAssemble();
174  displayer().leaderPrint ( "done\n" );
175 
176  assemblyChrono.stop();
177  displayer().leaderPrintMax ("Matrices assembly time: ", assemblyChrono.diff(), " s.\n");
178 }
179 
180 template< class mesh_Type >
181 void
183  vectorPtr_Type rhs,
184  vectorPtr_Type /*solution*/,
185  preconditionerPtr_Type /*preconditioner*/ )
186 {
187  *systemMatrix += *M_stokesMatrix;
188 
189  M_assembler->addMassRhs ( *rhs, problem()->force(), currentTime() );
190 }
191 
192 } // namespace LifeV
193 
194 #endif /* ASSEMBLYPOLICYSTOKES_HPP */
void assembleSystem(matrixPtr_Type systemMatrix, vectorPtr_Type rhs, vectorPtr_Type solution, preconditionerPtr_Type preconditioner)
VectorEpetra - The Epetra Vector format Wrapper.
std::shared_ptr< assembler_Type > assemblerPtr_Type
void start()
Start the timer.
Definition: LifeChrono.hpp:93
virtual fespacePtr_Type uFESpace() const =0
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
virtual Real currentTime() const =0
std::shared_ptr< map_Type > mapPtr_Type
void initAssembly(Teuchos::ParameterList &list)
std::shared_ptr< NavierStokesProblem< mesh_Type > > NSProblemPtr_Type
OseenAssembler< mesh_Type, matrix_Type, vector_Type > assembler_Type
void updateInverseJacobian(const UInt &iQuadPt)
FESpace< mesh_Type, map_Type > fespace_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
std::shared_ptr< preconditioner_Type > preconditionerPtr_Type
std::shared_ptr< VectorEpetra > vectorPtr_Type
std::shared_ptr< bdf_Type > bdfPtr_Type
Real diff()
Compute the difference in time between start and stop.
Definition: LifeChrono.hpp:111
std::shared_ptr< fespace_Type > fespacePtr_Type
MeshPartitioner< mesh_Type > meshPartitioner_Type
double Real
Generic real data.
Definition: LifeV.hpp:175
virtual NSProblemPtr_Type problem() const =0
Preconditioner - Abstract preconditioner class.
std::shared_ptr< matrix_Type > matrixPtr_Type
void stop()
Stop the timer.
Definition: LifeChrono.hpp:100
virtual fespacePtr_Type pFESpace() const =0
TimeAdvanceBDF< vector_Type > bdf_Type
virtual Displayer displayer()=0
Displayer - This class is used to display messages in parallel simulations.
Definition: Displayer.hpp:62