LifeV
HarmonicExtensionSolver.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  @file
28  @brief Classes to hold algorithms for the mesh motion, for instance, involved in a ALE formulation.
29  @author G. Fourestey
30  @date 01-10-2007
31 
32  @contributor Simone Deparis <simone.deparis@epfl.ch>
33  @maintainer Simone Deparis <simone.deparis@epfl.ch>
34 
35  This file contains classes which may be used to compute the extension inside the reference domain of a given
36  displacement at a specified interface
37 
38 */
39 
40 #ifndef HARMONICEXTENSIONSOLVER_H_
41 #define HARMONICEXTENSIONSOLVER_H_
42 
43 #include <lifev/core/LifeV.hpp>
44 #include <lifev/core/fem/DOF.hpp>
45 #include <lifev/core/array/MatrixElemental.hpp>
46 #include <lifev/core/fem/AssemblyElemental.hpp>
47 #include <lifev/core/fem/Assembly.hpp>
48 #include <lifev/core/fem/BCManage.hpp>
49 #include <lifev/core/fem/FESpace.hpp>
50 
51 
52 namespace LifeV
53 {
54 /*!
55  \class HarmonicExtension
56 
57  Base class which provides the harmonic extension of a given displacement on a specified part
58  of the mesh boundary
59 
60  In order to deal with harmonic extensions, we have to provide a mesh (to be moved), the parameters
61  involved in the laplacian discretization: viscosity, quadrature rules and boundary conditions.
62  This class contains a PhysVectUnknown objet wich will hold the extension of the interface displacement.
63  The constructor of the class built the global matrix of the discretized laplacian. The extension of the
64  displacement is computed by calling the public method update. Finally, this extension can be recovered by
65  calling method getDisplacement.
66 
67 */
68 
69 template < typename Mesh,
70  typename SolverType = LifeV::SolverAztecOO >
71 class HarmonicExtensionSolver
72 {
73 public:
74 
75  //! @name Public Types
76  //@{
77 
78  typedef SolverType solver_Type;
79  typedef std::shared_ptr<solver_Type> solverPtr_Type;
80 
81  typedef typename solver_Type::matrix_type matrix_Type;
82  typedef typename solver_Type::matrix_ptrtype matrixPtr_Type;
83  typedef typename solver_Type::vector_type vector_Type;
84  typedef typename solver_Type::vector_ptrtype vectorPtr_Type;
85 
86  // OBSOLETE typedefs
87  typedef SolverType solver_type;
88 
89  typedef typename solver_type::matrix_type matrix_type;
90  typedef typename solver_type::vector_type vector_type;
91 
92  //@}
93 
94 
95  //! @name Constructor & Destructor
96  //@{
97 
98  //! Constructors for an harmonics extensions
99  /*!
100  \param mmFESpace the FEspace that describes the problem
101  \param comm the Epetra_Comm to be used for communication
102  */
103 
104  HarmonicExtensionSolver ( FESpace<Mesh, MapEpetra>& mmFESpace,
105  std::shared_ptr<Epetra_Comm> comm);
106 
107  //! Constructors for an harmonics extensions with offset
108  /*!
109  \param mmFESpace the FEspace that describes the problem
110  \param comm the Epetra_Comm to be used for communication
111  \param localMap use localMap instead of M_FESpace.map()
112  \param offset use this offset to fill the matrix (both: row and column offset)
113  */
114  HarmonicExtensionSolver ( FESpace<Mesh, MapEpetra>& mmFESpace,
115  std::shared_ptr<Epetra_Comm> comm,
116  MapEpetra& localMap,
117  UInt offset = 0
118  );
119 
120  //! virtual destructor
121  virtual ~HarmonicExtensionSolver() {};
122 
123  //@}
124 
125  //! @name Methods
126  //@{
127 
128  //! Set up data from GetPot
129  /*!
130  @param dataFile GetPot object
131  */
132  void setUp ( const GetPot& dataFile );
133 
134  //! Update convective term, boundary condition and solve the linearized ns system
135  /*!
136  @param bcHandler BC handler
137  */
138  void iterate (BCHandler& BCh);
139 
140  //! returns wheter this processor is the leader.
141  bool isLeader() const
142  {
143  return comm().MyPID() == 0;
144  }
145 
146  //! prepare to recompute the preconditioner.
147  void resetPrec (bool reset = true)
148  {
149  if (reset)
150  {
151  M_linearSolver->precReset();
152  }
153  }
154 
155  //! manually rescale the system matrix by dt
156  void rescaleMatrix (Real& dt)
157  {
158  *M_matrHE *= dt;
159  }
160 
161  //! Adds the system matrix to the argument
162  void addSystemMatrixTo (matrixPtr_Type matr) const
163  {
164  *matr += *M_matrHE;
165  }
166 
167  //! Apply boundary conditions.
168  /*!
169  @param rightHandSide
170  @param bcHandler
171  */
172  void applyBoundaryConditions (vector_Type& rhs, BCHandler& BCh);
173 
174  void computeMatrix();
175  void updateDispDiff();
176 
177  //@}
178 
179 
180  //! @name Get Methods
181  //@{
182  vector_Type const& disp() const
183  {
184  return *M_disp;
185  }
186  vector_Type& disp()
187  {
188  return *M_disp;
189  }
190 
191  MapEpetra const& getMap() const
192  {
193  return M_localMap;
194  }
195 
196  FESpace<Mesh, MapEpetra> const& mFESpace() const
197  {
198  return M_FESpace;
199  }
200 
201  const std::shared_ptr<Epetra_Comm>& comm() const
202  {
203  return M_displayer.comm();
204  }
205  //@}
206 
207 private:
208 
209  //! Finite Element Space
210 
211  FESpace<Mesh, MapEpetra>& M_FESpace;
212 
213  //! local map
214  MapEpetra M_localMap;
215 
216  //! The matrix holding the values
217  matrixPtr_Type M_matrHE;
218 
219  Displayer M_displayer;
220  int M_me;
221  bool M_verbose;
222 
223  //! Elementary matrix : 3 blocks
224  MatrixElemental M_elmat;
225 
226  //! The actual extension of the displacement
227  vectorPtr_Type M_disp;
228 
229  //! Auxiliary vector holding the second right hand of the system
230  vectorPtr_Type M_secondRHS;
231 
232  //! The linear solver
233  solverPtr_Type M_linearSolver;
234 
235  //! Diffusion coefficient for the laplacian operator
236  Real M_diffusion;
237 
238  UInt M_offset;
239 };
240 
241 // ===================================================
242 // Constructors & Destructor
243 // ===================================================
244 
245 
246 template <typename Mesh, typename SolverType>
247 HarmonicExtensionSolver<Mesh, SolverType>::
248 HarmonicExtensionSolver ( FESpace<Mesh, MapEpetra>& mmFESpace,
249  std::shared_ptr<Epetra_Comm> comm ) :
250  M_FESpace ( mmFESpace ),
251  M_localMap ( M_FESpace.map() ),
252  M_matrHE ( new matrix_Type (M_localMap ) ),
253  M_displayer ( comm ),
254  M_me ( comm->MyPID() ),
255  M_verbose ( M_me == 0 ),
256  M_elmat ( M_FESpace.fe().nbFEDof(), nDimensions, nDimensions ),
257  M_disp ( ),
258  M_secondRHS ( ),
259  M_linearSolver ( ),
260  M_diffusion ( 1. ),
261  M_offset (0)
262 {
263 }
264 
265 template <typename Mesh, typename SolverType>
266 HarmonicExtensionSolver<Mesh, SolverType>::
267 HarmonicExtensionSolver ( FESpace<Mesh, MapEpetra>& mmFESpace,
268  std::shared_ptr<Epetra_Comm> comm ,
269  MapEpetra& localMap,
270  UInt offset) :
271  M_FESpace ( mmFESpace ),
272  M_localMap ( localMap),
273  M_matrHE ( new matrix_Type (M_localMap ) ),
274  M_displayer ( comm ),
275  M_me ( comm->MyPID() ),
276  M_verbose ( M_me == 0 ),
277  M_elmat ( M_FESpace.fe().nbFEDof(), nDimensions, nDimensions ),
278  M_secondRHS ( ),
279  M_linearSolver ( ),
280  M_diffusion ( 1. ),
281  M_offset (offset)
282 {
283 }
284 
285 // ===================================================
286 // Methods
287 // ===================================================
288 
289 
290 template <typename Mesh, typename SolverType>
291 void HarmonicExtensionSolver<Mesh, SolverType>::setUp ( const GetPot& dataFile )
292 {
293  M_linearSolver.reset (new solver_Type (M_displayer.comm() ) );
294  M_linearSolver->setDataFromGetPot ( dataFile, "mesh_motion/solver" );
295  M_linearSolver->setupPreconditioner (dataFile, "mesh_motion/prec");
296 
297  M_diffusion = dataFile ("mesh_motion/diffusion", 1.0);
298 
299  computeMatrix( );
300  M_linearSolver->setMatrix ( *M_matrHE );
301  M_secondRHS.reset (new vector_Type (M_FESpace.map() ) );
302  M_disp.reset (new vector_Type (M_FESpace.map() ) );
303 } // end setUp
304 
305 
306 template <typename Mesh, typename SolverType>
307 void
308 HarmonicExtensionSolver<Mesh, SolverType>::iterate ( BCHandler& BCh )
309 {
310  LifeChrono chrono;
311 
312  // matrix and vector assembling communication
313  M_displayer.leaderPrint (" HE- Applying boundary conditions ... ");
314  chrono.start();
315 
316  *M_secondRHS *= 0.;
317  applyBoundaryConditions (*M_secondRHS, BCh);
318 
319  chrono.stop();
320  M_displayer.leaderPrintMax ("done in " , chrono.diff() );
321 
322  // solving the system. Note: setMatrix(M_matrHE) done in setUp()
323  M_linearSolver->solveSystem ( *M_secondRHS, *M_disp, M_matrHE );
324 }
325 
326 template <typename Mesh, typename SolverType>
327 void
328 HarmonicExtensionSolver<Mesh, SolverType>::applyBoundaryConditions (vector_Type& rhs, BCHandler& BCh)
329 {
330 
331  // CHANGED BY S. QUINODOZ !
332  // "if" exchanged
333 
334  if ( ! BCh.bcUpdateDone() )
335  {
336  // BC boundary information update
337  BCh.bcUpdate ( *M_FESpace.mesh(), M_FESpace.feBd(), M_FESpace.dof() );
338  }
339 
340  if (M_offset) //mans that this is the fullMonolithic case
341  {
342  BCh.setOffset (M_offset);
343  }
344  else
345  {
346  bcManageRhs (rhs, *M_FESpace.mesh(), M_FESpace.dof(), BCh, M_FESpace.feBd(), 1., 0.0);
347  }
348 
349  bcManageMatrix ( *M_matrHE, *M_FESpace.mesh(), M_FESpace.dof(), BCh, M_FESpace.feBd(), 1.0, 0. );
350 }
351 
352 template <typename Mesh, typename SolverType>
353 void HarmonicExtensionSolver<Mesh, SolverType>::computeMatrix( )
354 {
355  LifeChrono chrono;
356  chrono.start();
357  M_displayer.leaderPrint (" HE- Computing constant matrices ... ");
358 
359  M_matrHE.reset ( new matrix_Type (M_localMap ) );
360 
361  UInt totalDof = M_FESpace.dof().numTotalDof();
362  // Loop on elements
363  for ( UInt i = 0; i < M_FESpace.mesh()->numVolumes(); ++i )
364  {
365  // Updating derivatives
366  M_FESpace.fe().updateFirstDerivQuadPt ( M_FESpace.mesh()->volumeList ( i ) );
367  M_elmat.zero();
368  AssemblyElemental::stiff ( M_diffusion, M_elmat, M_FESpace.fe(), 0, 0, 3 );
369  // Assembling
370  for ( UInt j = 0; j < M_FESpace.fieldDim(); ++j )
371  {
372  assembleMatrix ( *M_matrHE, M_elmat, M_FESpace.fe(), M_FESpace.dof(), j, j, j * totalDof + M_offset, j * totalDof + M_offset );
373  }
374  }
375 
376  M_matrHE->globalAssemble();
377 
378  chrono.stop();
379  M_displayer.leaderPrintMax ("done in " , chrono.diff() );
380 
381 }
382 
383 
384 } // namespace LifeV
385 #endif // HARMONICEXTENSIONSOLVER_H_
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
double operator()(const char *VarName, const double &Default) const
Definition: GetPot.hpp:2033
FESpace - Short description here please!
Definition: FESpace.hpp:78
double Real
Generic real data.
Definition: LifeV.hpp:175
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191