LifeV
MultiscaleModelFSI1D.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
29  * @brief File containing the Multiscale Model 1D
30  *
31  * @version 1.1
32  * @date 26-02-2010
33  * @author Gilles Fourestey <gilles.fourestey@epfl.ch>
34  *
35  * @version 1.2 and subsequents
36  * @date 23-04-2010
37  * @author Cristiano Malossi <cristiano.malossi@epfl.ch>
38  *
39  * @maintainer Cristiano Malossi <cristiano.malossi@epfl.ch>
40  */
41 
42 #ifndef MultiscaleModelFSI1D_H
43 #define MultiscaleModelFSI1D_H 1
44 
45 // Jacobian coefficient approximation
46 #define JACOBIAN_WITH_FINITEDIFFERENCE
47 
48 // Matlab post-processing
49 #define HAVE_MATLAB_POSTPROCESSING 1
50 
51 #include <lifev/one_d_fsi/fem/OneDFSIBCHandler.hpp>
52 #include <lifev/one_d_fsi/solver/OneDFSIPhysicsLinear.hpp>
53 #include <lifev/one_d_fsi/solver/OneDFSIPhysicsNonLinear.hpp>
54 #include <lifev/one_d_fsi/solver/OneDFSIFluxLinear.hpp>
55 #include <lifev/one_d_fsi/solver/OneDFSIFluxNonLinear.hpp>
56 #include <lifev/one_d_fsi/solver/OneDFSISourceLinear.hpp>
57 #include <lifev/one_d_fsi/solver/OneDFSISourceNonLinear.hpp>
58 #include <lifev/one_d_fsi/solver/OneDFSISolver.hpp>
59 
60 #include <lifev/bc_interface/1D/bc/BCInterface1D.hpp>
61 
62 #include <lifev/core/fem/FESpace.hpp>
63 #ifdef HAVE_HDF5
64 #include <lifev/core/filter/ExporterHDF5.hpp>
65 #endif
66 
67 #include <lifev/multiscale/models/MultiscaleModel.hpp>
68 #include <lifev/multiscale/framework/MultiscaleInterface.hpp>
69 
70 namespace LifeV
71 {
72 namespace Multiscale
73 {
74 
75 //! MultiscaleModelFSI1D - Multiscale model for 1D Fluid simulations
76 /*!
77  * @author Gilles Fourestey, Cristiano Malossi
78  *
79  * @see Full description of the Geometrical Multiscale Framework: \cite Malossi-Thesis
80  * @see Methodology: \cite Malossi2011Algorithms \cite Malossi2011Algorithms1D \cite Malossi2011Algorithms3D1DFSI \cite BlancoMalossi2012
81  * @see Applications: \cite Malossi2011Algorithms3D1DFSIAortaIliac \cite LassilaMalossi2012IdealLeftVentricle \cite BonnemainMalossi2012LVAD
82  *
83  * The MultiscaleModelFSI1D class is an implementation of the multiscaleModel_Type
84  * for 1D Fluid problem.
85  */
87  public virtual MultiscaleInterface
88 {
89 public:
90 
91  //! @name Type definitions
92  //@{
93 
96 
99 
102 
105 
106  typedef solver_Type::data_Type data_Type;
107  typedef solver_Type::mesh_Type mesh_Type;
108  typedef solver_Type::vector_Type vector_Type;
109  typedef solver_Type::vectorPtr_Type vectorPtr_Type;
110  typedef solver_Type::solution_Type solution_Type;
111  typedef solver_Type::solutionPtr_Type solutionPtr_Type;
112  typedef solver_Type::solutionConstIterator_Type solutionConstIterator_Type;
113  typedef solver_Type::linearSolver_Type linearSolver_Type;
114 
115  typedef solver_Type::feSpace_Type feSpace_Type;
116  typedef solver_Type::feSpacePtr_Type feSpacePtr_Type;
117 
122 
124 
125  typedef OneDFSI::bcType_Type bcType_Type;
126  typedef OneDFSI::bcSide_Type bcSide_Type;
127  typedef OneDFSI::bcLine_Type bcLine_Type;
128 
129 #ifdef HAVE_HDF5
132 #endif
133 
134  //@}
135 
136 
137  //! @name Constructors & Destructor
138  //@{
139 
140  //! Constructor
141  explicit MultiscaleModelFSI1D();
142 
143  //! Destructor
144  virtual ~MultiscaleModelFSI1D() {}
145 
146  //@}
147 
148 
149  //! @name MultiscaleModel Methods
150  //@{
151 
152  //! Setup the data of the model.
153  /*!
154  * @param fileName Name of data file.
155  */
156  void setupData ( const std::string& fileName );
157 
158  //! Setup the model.
159  void setupModel();
160 
161  //! Build the initial model.
162  void buildModel();
163 
164  //! Update the model.
165  void updateModel();
166 
167  //! Solve the model.
168  void solveModel();
169 
170  //! Update the solution.
171  void updateSolution();
172 
173  //! Save the solution
174  void saveSolution();
175 
176  //! Display some information about the model.
177  void showMe();
178 
179  //! Return a specific scalar quantity to be used for a comparison with a reference value.
180  /*!
181  * This method is meant to be used for night checks.
182  * @return reference quantity.
183  */
184  Real checkSolution() const;
185 
186  //@}
187 
188 
189  //! @name MultiscaleInterface Methods
190  //@{
191 
192 
193  //! Impose the flow rate on a specific interface of the model
194  /*!
195  * @param boundaryID ID of the boundary interface
196  * @param function boundary condition function
197  */
198  void imposeBoundaryFlowRate ( const multiscaleID_Type& boundaryID, const function_Type& function );
199 
200  //! Impose the integral of the mean normal stress on a specific boundary interface of the model
201  /*!
202  * @param boundaryID ID of the boundary interface
203  * @param function boundary condition function
204  */
205  void imposeBoundaryMeanNormalStress ( const multiscaleID_Type& boundaryID, const function_Type& function );
206 
207  //! Impose the integral of the mean total normal stress on a specific boundary interface of the model
208  /*!
209  * Note: mean total normal stress cannot be imposed at the interfaces of this model.
210  *
211  * @param boundaryID ID of the boundary interface
212  * @param function boundary condition function
213  */
214  void imposeBoundaryMeanTotalNormalStress ( const multiscaleID_Type& /*boundaryID*/, const function_Type& /*function*/ )
215  {
216  multiscaleErrorCheck ( ModelInterface, "Invalid interface [MeanTotalNormalStress] for model type [" + enum2String ( M_type, multiscaleModelsMap ) + "]", M_comm->MyPID() == 0 );
217  }
218 
219  //! Impose the area on a specific boundary interface of the model
220  /*!
221  * TODO The area can be imposed to the 1-D model: need to be coded
222  *
223  * @param boundaryID ID of the boundary interface
224  * @param function boundary condition function
225  */
226  void imposeBoundaryArea ( const multiscaleID_Type& /*boundaryID*/, const function_Type& /*function*/ )
227  {
228  multiscaleErrorCheck ( ModelInterface, "Invalid interface [Area] for model type [" + enum2String ( M_type, multiscaleModelsMap ) + "]", M_comm->MyPID() == 0 );
229  }
230 
231  //! Get the flow rate on a specific boundary interface of the model
232  /*!
233  * @param boundaryID ID of the boundary interface
234  * @return flow rate value
235  */
236  Real boundaryFlowRate ( const multiscaleID_Type& boundaryID ) const
237  {
238  return M_solver->boundaryValue ( *M_solution, OneDFSI::Q, flagConverter ( boundaryID ) );
239  }
240 
241  //! Get the integral of the mean normal stress on a specific boundary interface of the model
242  /*!
243  * @param boundaryID ID of the boundary interface
244  * @return mean normal stress value
245  */
246  Real boundaryMeanNormalStress ( const multiscaleID_Type& boundaryID ) const
247  {
248  return M_solver->boundaryValue ( *M_solution, OneDFSI::S, flagConverter ( boundaryID ) );
249  }
250 
251  //! Get the integral of the mean total normal stress on a specific boundary interface of the model
252  /*!
253  * @param boundaryID ID of the boundary interface
254  * @return mean total normal stress value
255  */
257  {
258  return M_solver->boundaryValue ( *M_solution, OneDFSI::T, flagConverter ( boundaryID ) );
259  }
260 
261  //! Get the area on a specific boundary interface of the model
262  /*!
263  * @param boundaryID ID of the boundary interface
264  * @return area value
265  */
266  Real boundaryArea ( const multiscaleID_Type& boundaryID ) const
267  {
268  return M_solver->boundaryValue ( *M_solution, OneDFSI::A, flagConverter ( boundaryID ) );
269  }
270 
271  //! Get the variation of the flow rate (on a specific boundary interface) using the linear model
272  /*!
273  * @param boundaryID ID of the boundary interface
274  * @param solveLinearSystem a flag to which determine if the linear system has to be solved
275  * @return variation of the flow rate
276  */
277  Real boundaryDeltaFlowRate ( const multiscaleID_Type& boundaryID, bool& solveLinearSystem );
278 
279  //! Get the variation of the integral of the mean normal stress (on a specific boundary interface) using the linear model
280  /*!
281  * @param boundaryID ID of the boundary interface
282  * @param solveLinearSystem a flag to which determine if the linear system has to be solved
283  * @return variation of the mean normal stress
284  */
285  Real boundaryDeltaMeanNormalStress ( const multiscaleID_Type& boundaryID, bool& solveLinearSystem );
286 
287  //! Get the variation of the integral of the total normal stress (on a specific boundary face)
288  /*!
289  * @param boundaryID ID of the boundary interface
290  * @param solveLinearSystem a flag to which determine if the linear system has to be solved
291  * @return variation of the mean total normal stress
292  */
293  Real boundaryDeltaMeanTotalNormalStress ( const multiscaleID_Type& boundaryID, bool& solveLinearSystem );
294 
295  //! Get the variation of the integral of the area (on a specific boundary interface) using the linear model
296  /*!
297  * @param boundaryID ID of the boundary interface
298  * @param solveLinearSystem a flag to which determine if the linear system has to be solved
299  * @return variation of the area
300  */
301  Real boundaryDeltaArea ( const multiscaleID_Type& boundaryID, bool& solveLinearSystem );
302 
303  //@}
304 
305 
306  //! @name Get Methods
307  //@{
308 
309  //! Get the BC handler container of the boundary conditions of the model
310  /*!
311  * @return BC handler
312  */
313  bc_Type& bc() const
314  {
315  return * ( M_bc->handler() );
316  }
317 
318  //! Get the BCInterface container of the boundary conditions of the model
319  /*!
320  * @return BCInterface container
321  */
323  {
324  return *M_bc;
325  }
326 
327  //! Get the density on a specific boundary face of the model
328  /*!
329  * @return density value
330  */
332  {
333  return M_data->densityRho();
334  }
335 
336  //! Get the viscosity on a specific boundary face of the model
337  /*!
338  * @return viscosity value
339  */
341  {
342  return M_data->viscosity();
343  }
344 
345  //! Get the integral of the pressure (on a specific boundary face)
346  /*!
347  * @param boundaryID ID of the boundary interface
348  * @return pressure value
349  */
350  Real boundaryPressure ( const multiscaleID_Type& boundaryID ) const
351  {
352  return M_solver->boundaryValue ( *M_solution, OneDFSI::P, flagConverter ( boundaryID ) );
353  }
354 
355  //! Get the data container of the 1D model.
356  /*!
357  * @return 1D Model data container.
358  */
359  data_Type& data() const
360  {
361  return *M_data;
362  }
363 
364  //! Get the Physics of the 1D model.
365  /*!
366  * @return 1D Model physics.
367  */
369  {
370  return M_physics;
371  }
372 
373  //! Get the Flux of the 1D model.
374  /*!
375  * @return 1D Model Flux.
376  */
378  {
379  return M_flux;
380  }
381 
382  //! Get the Source of the 1D model.
383  /*!
384  * @return 1D Model Source.
385  */
387  {
388  return M_source;
389  }
390 
391  //! Get the FESpace of the 1D model.
392  /*!
393  * @return 1D model FESpace
394  */
395  feSpacePtr_Type feSpace() const
396  {
397  return M_feSpace;
398  }
399 
400  //! Get the Solver of the 1D model.
401  /*!
402  * @return 1D model solver.
403  */
405  {
406  return M_solver;
407  }
408 
409  //! Get the solution container of the 1D model.
410  /*!
411  * @return 1D model solution.
412  */
413  const solutionPtr_Type& solution() const
414  {
415  return M_solution;
416  }
417 
418  //! Get a specific quantity of the solution container of the 1D model.
419  /*!
420  * @param quantity solution quantity.
421  * @return 1D model solution.
422  */
423  const vectorPtr_Type& solution ( const std::string& quantity) const
424  {
425  return (*M_solution) [quantity];
426  }
427 
428  //@}
429 
430 private:
431 
432  //! @name Unimplemented Methods
433  //@{
434 
436 
438 
439  //@}
440 
441 
442  //! @name Private Methods
443  //@{
444 
445  //! Setup the global data of the model.
446  /*!
447  * In particular, it replaces the default local values with the ones in the global container.
448  * If a value is already specified in the data file, do not perform the replacement.
449  *
450  * @param fileName File name of the specific model.
451  */
452  void setupGlobalData ( const std::string& fileName );
453 
454  //! Initialize the solution.
455  void initializeSolution();
456 
457  //! Setup the FE space for pressure and velocity
458  void setupFESpace();
459 
460  //! Copy the solution (solution2 = solution1)
461  /*!
462  * NOTE: if the size of the two vector is different due to the presence of ghost nodes
463  * the method automatically add/remove them from the resulting vector.
464  * @param solution1 solution to be copied.
465  * @param solution2 copy of solution1.
466  */
467  void copySolution ( const solution_Type& solution1, solution_Type& solution2 );
468 
469  //! Update BCInterface physical solver variables
471 
472  //! Solve the 1D hyperbolic problem
473  /*!
474  * @param bc BCInterface container.
475  * @param solution solution container.
476  * @param solverType string containing the prefix ID to display when solving the system.
477  */
478  void solve ( bc_Type& bc, solution_Type& solution, const std::string& solverType = " 1D-" );
479 
480  //! Convert the boundaryID to a bcSide type
481  /*!
482  * @param boundaryID ID of the boundary interface
483  * @return boundary condition side.
484  */
485  bcSide_Type flagConverter ( const multiscaleID_Type& boundaryID ) const
486  {
487  return ( boundaryFlag ( boundaryID ) == 0) ? OneDFSI::left : OneDFSI::right;
488  }
489 
491 
492  //! Update linear BC
493  void createLinearBC();
494 
495  //! Update linear BC
496  void updateLinearBC ( const solution_Type& solution );
497 
498  //! Setup the linear model
499  void setupLinearModel();
500 
501  //! Update the linear system matrix and vectors
502  void updateLinearModel();
503 
504  //! Solve the linear problem
505  void solveLinearModel ( bool& solveLinearSystem );
506 
507  //! Impose the coupling perturbation on the correct BC inside the BCHandler
508  void imposePerturbation();
509 
510  //! Reset all the coupling perturbations imposed on the BCHandler
511  void resetPerturbation();
512 
513  Real bcFunctionDelta ( const Real& t );
514 
515 #else
516 
517  //! Compute Jacobian coefficients using tangent problem formulation
518  /*!
519  * @param bcOutputSide side of the quantity to be computed.
520  * @param bcOutputType type of the quantity to be computed.
521  * @return Jacobian coefficient.
522  */
524 
525  //! Solve the tangent problem formulation
526  /*!
527  * @param flowRate rhs for the tangent problem.
528  * @param bcNode node of the quantity to be computed.
529  * @return solution of the tangent problem at specific node.
530  */
532 
533 #endif
534  //@}
535 
536 #ifdef HAVE_HDF5
539 
542 #endif
543 
545  // Linear BC
547 
548  solutionPtr_Type M_linearSolution; // Solution of the perturbed problem
549 
550  // BC perturbation
552 
553  // BC Functions for tangent problem
555 
557  bcType_Type M_bcDeltaType;
558  bcSide_Type M_bcDeltaSide;
559 #endif
560 
561  // 1D problem
568 
569  // Linear solver
572 
573  // FE spaces
575 
576  solutionPtr_Type M_solution_tn; // Solution at time t_n
577  solutionPtr_Type M_solution; // Solution at time t_n+1
578 
579 };
580 
581 //! Factory create function
583 {
584  return new MultiscaleModelFSI1D();
585 }
586 
587 } // Namespace multiscale
588 } // Namespace LifeV
589 
590 #endif /* MultiscaleModelFSI1D_H */
std::function< Real(const Real &, const Real &, const Real &, const Real &, const ID &) > function_Type
bc_Type & bc() const
Get the BC handler container of the boundary conditions of the model.
std::shared_ptr< feSpace_Type > M_feSpace
BCInterface1D< bc_Type, solver_Type > bcInterface_Type
void imposeBoundaryFlowRate(const multiscaleID_Type &boundaryID, const function_Type &function)
Impose the flow rate on a specific interface of the model.
SolverAmesos linearSolver_Type
OneDFSIPhysics - Base class providing physical operations for the 1D model data.
std::shared_ptr< solver_Type > solverPtr_Type
std::shared_ptr< solution_Type > solutionPtr_Type
void createLinearBC()
Update linear BC.
std::shared_ptr< linearSolver_Type > M_linearViscoelasticSolver
void setupLinearModel()
Setup the linear model.
Real boundaryDensity() const
Get the density on a specific boundary face of the model.
fluxPtr_Type flux() const
Get the Flux of the 1D model.
#define JACOBIAN_WITH_FINITEDIFFERENCE
std::shared_ptr< vector_Type > vectorPtr_Type
solution_Type::const_iterator solutionConstIterator_Type
OneDFSIFlux - Base class for the flux term of the 1D hyperbolic problem.
Definition: OneDFSIFlux.hpp:63
void setupFESpace()
Setup the FE space for pressure and velocity.
OneDFSISource - Base class for the source term of the 1D hyperbolic problem.
BCInterface1D - LifeV interface to load boundary conditions for 1D problems completely from a GetPot ...
void updateInverseJacobian(const UInt &iQuadPt)
std::vector< std::map< bcSide_Type, std::map< bcType_Type, Real > > > M_bcPreviousTimeSteps
OneDFSIFunction - Base class for 1D BC Functions.
MultiscaleModelFSI1D(const MultiscaleModelFSI1D &model)
sourcePtr_Type source() const
Get the Source of the 1D model.
linearSolver_Type::vector_type vector_Type
physicsPtr_Type physics() const
Get the Physics of the 1D model.
Real boundaryDeltaArea(const multiscaleID_Type &boundaryID, bool &solveLinearSystem)
Get the variation of the integral of the area (on a specific boundary interface) using the linear mod...
Real boundaryMeanTotalNormalStress(const multiscaleID_Type &boundaryID) const
Get the integral of the mean total normal stress on a specific boundary interface of the model...
void copySolution(const solution_Type &solution1, solution_Type &solution2)
Copy the solution (solution2 = solution1)
void updateLinearModel()
Update the linear system matrix and vectors.
Real boundaryDeltaFlowRate(const multiscaleID_Type &boundaryID, bool &solveLinearSystem)
Get the variation of the flow rate (on a specific boundary interface) using the linear model...
MultiscaleModel multiscaleModel_Type
Real boundaryMeanNormalStress(const multiscaleID_Type &boundaryID) const
Get the integral of the mean normal stress on a specific boundary interface of the model...
void initializeSolution()
Initialize the solution.
std::shared_ptr< linearSolver_Type > M_linearSolver
void buildModel()
Build the initial model.
const solutionPtr_Type & solution() const
Get the solution container of the 1D model.
OneDFSIBCHandler - Class featuring methods to handle boundary conditions.
bcInterface_Type & bcInterface() const
Get the BCInterface container of the boundary conditions of the model.
void imposeBoundaryArea(const multiscaleID_Type &, const function_Type &)
Impose the area on a specific boundary interface of the model.
solverPtr_Type solver() const
Get the Solver of the 1D model.
Real boundaryFlowRate(const multiscaleID_Type &boundaryID) const
Get the flow rate on a specific boundary interface of the model.
void solveLinearModel(bool &solveLinearSystem)
Solve the linear problem.
double Real
Generic real data.
Definition: LifeV.hpp:175
std::map< std::string, vectorPtr_Type > solution_Type
void imposePerturbation()
Impose the coupling perturbation on the correct BC inside the BCHandler.
Real checkSolution() const
Return a specific scalar quantity to be used for a comparison with a reference value.
void updateLinearBC(const solution_Type &solution)
Update linear BC.
Real boundaryPressure(const multiscaleID_Type &boundaryID) const
Get the integral of the pressure (on a specific boundary face)
Real boundaryArea(const multiscaleID_Type &boundaryID) const
Get the area on a specific boundary interface of the model.
void showMe()
Display some information about the model.
OneDFSISolver - Solver class for the 1D model.
FESpace< mesh_Type, MapEpetra > feSpace_Type
void imposeBoundaryMeanTotalNormalStress(const multiscaleID_Type &, const function_Type &)
Impose the integral of the mean total normal stress on a specific boundary interface of the model...
data_Type & data() const
Get the data container of the 1D model.
bcSide_Type flagConverter(const multiscaleID_Type &boundaryID) const
Convert the boundaryID to a bcSide type.
Real boundaryDeltaMeanTotalNormalStress(const multiscaleID_Type &boundaryID, bool &solveLinearSystem)
Get the variation of the integral of the total normal stress (on a specific boundary face) ...
std::shared_ptr< physics_Type > physicsPtr_Type
void imposeBoundaryMeanNormalStress(const multiscaleID_Type &boundaryID, const function_Type &function)
Impose the integral of the mean normal stress on a specific boundary interface of the model...
Real boundaryDeltaMeanNormalStress(const multiscaleID_Type &boundaryID, bool &solveLinearSystem)
Get the variation of the integral of the mean normal stress (on a specific boundary interface) using ...
MultiscaleInterface - The multiscale interface for fluid problems.
std::shared_ptr< feSpace_Type > feSpacePtr_Type
void resetPerturbation()
Reset all the coupling perturbations imposed on the BCHandler.
void updateBCPhysicalSolverVariables()
Update BCInterface physical solver variables.
multiscaleModel_Type * createMultiscaleModelFSI1D()
Factory create function.
Real boundaryViscosity() const
Get the viscosity on a specific boundary face of the model.
std::shared_ptr< bcInterface_Type > bcInterfacePtr_Type
feSpacePtr_Type feSpace() const
Get the FESpace of the 1D model.
MultiscaleModelFSI1D & operator=(const MultiscaleModelFSI1D &model)
std::shared_ptr< source_Type > sourcePtr_Type