LifeV
FastAssemblerNS.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 the LifeV library
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
21  License along with this library; if not, see <http://www.gnu.org/licenses/>
22 
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /*!
29  * @file
30  @brief This file contains the definition of the FastAssembler class.
31 
32  This function is used to perform an efficient assembly of FE matrices
33  where the test and trial functions are the same. This class is experimental
34  and must be used with a lot of care.
35 
36  \warning All the routines contained here are supposted to be used/expanded by experts of LifeV
37  since they contain a much faster way of assembling matrices stemming from the discretized
38  NS equations (either in the fully-implicit or semi-implicit case).
39 
40  Preliminary tests
41  showed that the assemblers coded here are roughly 20 times faster then
42  ETA based ones. The assembly is done "by hands" and the code is quite
43  hard to be understood.
44 
45  To use this class one has first to allocate the memory required and then
46  just call the routines required for the assembly.
47 
48  @date 06/2016
49  @author Davide Forti <davide.forti@epfl.ch>
50  */
51 
52 #ifndef FASTASSEMBLERNS_HPP
53 #define FASTASSEMBLERNS_HPP
54 
55 #include <lifev/core/LifeV.hpp>
56 #include <lifev/core/mesh/RegionMesh.hpp>
57 #include <lifev/core/array/VectorEpetra.hpp>
58 #include <lifev/core/array/MatrixEpetra.hpp>
59 #include <lifev/core/fem/QuadratureRule.hpp>
60 #include <lifev/core/fem/ReferenceFE.hpp>
61 #include <lifev/core/fem/CurrentFE.hpp>
62 #include <lifev/core/fem/FESpace.hpp>
63 
64 namespace LifeV
65 {
66 
67 class FastAssemblerNS
68 {
69 public:
70 
71  typedef RegionMesh< LinearTetra > mesh_Type;
72  typedef std::shared_ptr<mesh_Type> meshPtr_Type;
73 
74  typedef VectorEpetra vector_Type;
75  typedef std::shared_ptr<vector_Type> vectorPtr_Type;
76 
77  typedef MatrixEpetra<Real> matrix_Type;
78  typedef std::shared_ptr<matrix_Type> matrixPtr_Type;
79 
80  typedef Epetra_Comm comm_Type;
81  typedef std::shared_ptr< comm_Type > commPtr_Type;
82 
83  typedef QuadratureRule qr_Type;
84  typedef std::shared_ptr< qr_Type > qrPtr_Type;
85 
86  typedef FESpace<mesh_Type, MapEpetra> fespace_Type;
87  typedef std::shared_ptr<fespace_Type> fespacePtr_Type;
88 
89 
90  //! Constructor
91  /*!
92  * @param mesh - input mesh
93  * @param comm - communicator
94  * @param refFE_velocity - reference FE space velocity
95  * @param refFE_pressure - reference FE space pressure
96  * @param fespace_velocity -
97  * @param fespace_pressure -
98  * @param qr - quadrature rule to be used for the integration
99  */
100  FastAssemblerNS( const meshPtr_Type& mesh, const commPtr_Type& comm,
101  const ReferenceFE* refFE_velocity, const ReferenceFE* refFE_pressure,
102  const fespacePtr_Type& fespace_velocity, const fespacePtr_Type& fespace_pressure,
103  const qr_Type* qr );
104 
105  //! Destructor
106  ~FastAssemblerNS();
107 
108  //! @name Methods
109  //@{
110 
111  //! Set physical parameters for NS
112  /*!
113  * @param density - density of the fluid
114  * @param viscosity - viscosity of the fluid
115  * @param timestep - timestep for the simulation
116  * @param orderBDF - order time integrator BDF
117  * @param C_I - is 30 for P1 and 60 for P2
118  */
119  void setConstants_NavierStokes( const Real& density, const Real& viscosity, const Real& timestep, const Real& orderBDF, const Real& C_I );
120 
121  //! Set physical parameters for NS
122  /*!
123  * @param density - density of the fluid
124  * @param viscosity - viscosity of the fluid
125  * @param timestep - timestep for the simulation
126  * @param orderBDF - order time integrator BDF
127  * @param C_I - is 30 for P1 and 60 for P2
128  * @param alpha - coefficient BDF in front of u_{n+1}
129  */
130  void setConstants_NavierStokes( const Real& density, const Real& viscosity, const Real& timestep, const Real& orderBDF, const Real& C_I, const Real& alpha );
131 
132  //! Allocate space for members before the assembly
133  /*!
134  * @param current_fe_velocity - current FE space velocity
135  */
136  void allocateSpace( CurrentFE* current_fe_velocity, const bool& use_supg );
137 
138  //! Assemble constant terms NS
139  /*!
140  * @param mass - mass matrix
141  * @param stiffness - stiffness matrix
142  * @param grad - block01
143  * @param div - block10
144  */
145  void assemble_constant_terms( matrixPtr_Type& mass, matrixPtr_Type& stiffness, matrixPtr_Type& grad, matrixPtr_Type& div );
146 
147  //! FE Assembly of NS constant terms (no scaling by coefficients like viscosity)
148  /*!
149  * @param matrix - global matrix
150  * @param u_h - velocity vector
151  */
152  void assembleConvective( matrixPtr_Type& matrix, const vector_Type& u_h );
153 
154  //! FE Assembly of NS nonlinear term
155  /*!
156  * @param matrix - matrix
157  * @param u_h - velocity vector previous Newton step
158  */
159  void jacobianNS( matrixPtr_Type& matrix, const vector_Type& u_h );
160 
161  //! Assemble SUPG terms
162  /*!
163  * @param block00 - block00 stabilization
164  * @param block01 - block01 stabilization
165  * @param block10 - block10 stabilization
166  * @param block11 - block11 stabilization
167  */
168  void assemble_supg_terms( matrixPtr_Type& block00, matrixPtr_Type& block01, matrixPtr_Type& block10, matrixPtr_Type& block11, const vector_Type& u_h );
169 
170  //! Assemble SUPG terms fully implicit for FSI
171  /*!
172  * @param block00 - block00 stabilization
173  * @param block01 - block01 stabilization
174  * @param block10 - block10 stabilization
175  * @param block11 - block11 stabilization
176  * @param beta_km1 - vector: fluid_velocity - ale_velocity
177  * @param u_km1 - velocity previous Newton step
178  * @param p_km1 - pressure previous Newton step
179  * @param u_bdf - vector time discretization fluid velocity
180  */
181  void supg_FI_FSI_terms ( matrixPtr_Type& block00,
182  matrixPtr_Type& block01,
183  matrixPtr_Type& block10,
184  matrixPtr_Type& block11,
185  const vector_Type& beta_km1,
186  const vector_Type& u_km1,
187  const vector_Type& p_km1,
188  const vector_Type& u_bdf);
189 
190  //! Assemble VMSLES terms
191  /*!
192  * @param block00 - block00 stabilization
193  * @param block01 - block01 stabilization
194  * @param block10 - block10 stabilization
195  * @param block11 - block11 stabilization
196  * @param fine_scale - fine scale vector
197  * @param u_extr - velocity extrapolated
198  */
199  void vmsles_semi_implicit_terms ( matrixPtr_Type& block00,
200  matrixPtr_Type& block01,
201  matrixPtr_Type& block10,
202  matrixPtr_Type& block11,
203  const std::vector<std::vector<VectorSmall<3>>>& fine_scale,
204  const vector_Type& u_extr);
205 
206  //! Assemble VMSLES terms when using P1-P1 for the fluid
207  /*!
208  * @param block00 - block00 stabilization
209  * @param block01 - block01 stabilization
210  * @param block10 - block10 stabilization
211  * @param block11 - block11 stabilization
212  * @param fine_scale - fine scale vector
213  * @param u_extr - velocity extrapolated
214  */
215  void vmsles_semi_implicit_termsP1P1 ( matrixPtr_Type& block00,
216  matrixPtr_Type& block01,
217  matrixPtr_Type& block10,
218  matrixPtr_Type& block11,
219  const std::vector<std::vector<VectorSmall<3>>>& fine_scale,
220  const vector_Type& u_extr);
221 
222  //! Assemble SUPG terms fully implicit for FSI
223  /*!
224  * @param current_fe_velocity - current FE needed to update geom quantities (for FSI when moving mesh)
225  */
226 
227  void updateGeoQuantities ( CurrentFE* current_fe );
228 
229  //! Set alpha
230  /*!
231  * @param alpha - time advance coefficient
232  */
233 
234  void setAlpha ( const Real& alpha ) { M_alpha = alpha; };
235 
236  //! Set time step
237  /*!
238  * @param timestep - time step of the simulation
239  */
240 
241  void setTimeStep ( const Real& timestep ) { M_timestep = timestep; };
242 
243  //@}
244 
245 private:
246 
247  meshPtr_Type M_mesh;
248  commPtr_Type M_comm;
249 
250  int M_numElements;
251  int M_numScalarDofs;
252 
253  double * M_detJacobian;
254  double *** M_invJacobian;
255 
256  double ** M_phi_velocity;
257  double ** M_phi_pressure;
258  double *** M_dphi_velocity;
259  double *** M_dphi_pressure;
260  double **** M_d2phi_velocity;
261  double ** M_elements_velocity;
262  double ** M_elements_pressure;
263 
264  const qr_Type* M_qr;
265  const ReferenceFE* M_referenceFE_velocity;
266  const ReferenceFE* M_referenceFE_pressure;
267  const std::shared_ptr<FESpace<mesh_Type, MapEpetra>> M_fespace_velocity;
268  const std::shared_ptr<FESpace<mesh_Type, MapEpetra>> M_fespace_pressure;
269 
270  double*** M_vals_00;
271  double*** M_vals_01;
272  double*** M_vals_10;
273  double*** M_vals_11;
274  double***** M_vals_supg;
275  double**** M_vals_supg_01;
276  double**** M_vals_supg_10;
277  int** M_rows_velocity;
278  int** M_rows_pressure;
279  int** M_cols_velocity;
280  int** M_cols_pressure;
281  int** M_rows_tmp;
282  int** M_cols_tmp;
283 
284  bool M_useSUPG;
285  double *** M_G; // metric tensor
286  double ** M_g; // metric vector
287  double ** M_Tau_M; // coefficient Tau_M
288  double ** M_Tau_C; // coefficient Tau_C
289  double ** M_Tau_M_hat; // coefficient Tau_M_hat for VMSLES at quadrature
290 
291  double M_density;
292  double M_viscosity;
293  double M_timestep;
294  double M_orderBDF;
295  double M_C_I;
296  double M_alpha;
297 };
298 
299 } // Namespace LifeV
300 
301 #endif // FASTASSEMBLERNS_HPP
VectorEpetra - The Epetra Vector format Wrapper.
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
void updateInverseJacobian(const UInt &iQuadPt)
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
double Real
Generic real data.
Definition: LifeV.hpp:175
CurrentFE - A primordial class for the assembly of the local matrices/vectors retaining the values on...
Definition: CurrentFE.hpp:243
The class for a reference Lagrangian finite element.
QuadratureRule - The basis class for storing and accessing quadrature rules.