LifeV
MultiscaleModel.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 Physical Model
30  *
31  * @date 12-03-2009
32  * @author Cristiano Malossi <cristiano.malossi@epfl.ch>
33  *
34  * @maintainer Cristiano Malossi <cristiano.malossi@epfl.ch>
35  */
36 
37 #ifndef MultiscaleModel_H
38 #define MultiscaleModel_H 1
39 
40 #include <lifev/multiscale/framework/MultiscaleDefinitions.hpp>
41 #include <lifev/multiscale/framework/MultiscaleGlobalData.hpp>
42 #include <lifev/multiscale/couplings/MultiscaleCoupling.hpp>
43 #include <array>
44 
45 namespace LifeV
46 {
47 namespace Multiscale
48 {
49 
50 //! MultiscaleModel - The Multiscale Physical Model
51 /*!
52  * @author Cristiano Malossi
53  *
54  * @see Full description of the Geometrical Multiscale Framework: \cite Malossi-Thesis
55  * @see Methodology: \cite Malossi2011Algorithms \cite Malossi2011Algorithms1D \cite Malossi2011Algorithms3D1DFSI \cite BlancoMalossi2012
56  * @see Applications: \cite Malossi2011Algorithms3D1DFSIAortaIliac \cite LassilaMalossi2012IdealLeftVentricle \cite BonnemainMalossi2012LVAD
57  *
58  * The MultiscaleModel class provides a general interface between the
59  * MS_Algorithm and all the other models. Moreover it provides internal methods
60  * for accessing general information and model related couplings.
61  */
63 {
64 public:
65 
66  //! @name Constructors & Destructor
67  //@{
68 
69  //! The main constructor.
70  /*!
71  * All the derived classes has to
72  * be constructed using an empty constructor which calls (as first operation)
73  * this empty constructor.
74  */
75  explicit MultiscaleModel();
76 
77  //! Destructor
78  virtual ~MultiscaleModel() {}
79 
80  //@}
81 
82 
83  //! @name Multiscale PhysicalModel Virtual Methods
84  //@{
85 
86  //! Setup the data of the model.
87  /*!
88  * This method is called only once at the beginning of the simulation.
89  * It is designed for the following operations:
90  * <ol>
91  * <li> read data from files;
92  * <li> set global parameter for the MS simulation (viscosity, time, ...);
93  * <li> perform preliminary operations which do not depend on the couplings.
94  * </ol>
95  *
96  * @param fileName Name of data file.
97  */
98  virtual void setupData ( const std::string& fileName );
99 
100  //! Setup the model.
101  /*!
102  * In particular it does the following operations:
103  * <ol>
104  * <li> initialize the model object;
105  * <li> initialize all the other private objects;
106  * <li> perform preliminary operations which depend on the couplings.
107  * </ol>
108  */
109  virtual void setupModel() = 0;
110 
111  //! Build the initial model.
112  /*!
113  * This method is alternative to updateModel and should be called only once at the fist timestep.
114  * This method is reserved for the construction of:
115  * <ol>
116  * <li> objects that are constant (with respect to the time);
117  * <li> objects that are required for the first time step and should not be updated during subiterations.
118  * </ol>
119  */
120  virtual void buildModel() = 0;
121 
122  //! Update the model.
123  /*!
124  * This method is alternative to buildModel and should be called from the second timestep.
125  * This method is reserved for the update of:
126  * <ol>
127  * <li> objects that are not constant with respect to the time but should not be updated during subiterations.
128  * </ol>
129  */
130  virtual void updateModel() = 0;
131 
132  //! Solve the System.
133  /*!
134  * This method is called once for each subiteration (in the case of implicit coupling).
135  * It computes the solution at time t_n+1.
136  */
137  virtual void solveModel() = 0;
138 
139  //! Update the solution.
140  /*!
141  * This method is called after the last call to solveModel.
142  * It updates the solution both for the next time step and for the call to saveSolution.
143  */
144  virtual void updateSolution() = 0;
145 
146  //! Save the solution.
147  /*!
148  * This method wrote to file the solution computed during the last call of solveModel.
149  */
150  virtual void saveSolution() = 0;
151 
152  //! Display some information about the model.
153  virtual void showMe();
154 
155  //! Return a specific scalar quantity to be used for a comparison with a reference value.
156  /*!
157  * This method is meant to be used for night checks.
158  * @return reference quantity.
159  */
160  virtual Real checkSolution() const = 0;
161 
162  //@}
163 
164 
165  //! @name Methods
166  //@{
167 
168  //! Clear the list of pointers to the couplings.
169  /*!
170  * This method has to be called before the automatic destructor, in order
171  * to disconnect the coupling classes from the model classes.
172  */
174  {
175  M_couplings.clear();
176  }
177 
178  //@}
179 
180 
181  //! @name Set Methods
182  //@{
183 
184  //! Set the global ID of the model
185  /*!
186  * @param id Model ID
187  */
188  void setID ( const UInt& id )
189  {
190  M_ID = id;
191  }
192 
193  //! Set the number of couplings attached to this model
194  /*!
195  * @param couplingsNumber number of couplings attached to this model
196  */
197  void setCouplingsNumber ( const UInt& couplingsNumber )
198  {
199  M_couplings.resize ( couplingsNumber );
200  }
201 
202  //! Add a pointer to one of the couplings attached to this model
203  /*!
204  * @param localCouplingID local coupling ID
205  * @param coupling shared_ptr of the coupling
206  */
207  void setCoupling ( const UInt& localCouplingID, const multiscaleCouplingPtr_Type& coupling )
208  {
209  M_couplings[localCouplingID] = coupling ;
210  }
211 
212  //! Add a pointer to one of the couplings which couple the model
213  /*!
214  * @param coupling shared_ptr of the coupling
215  */
216  void addCoupling ( const multiscaleCouplingPtr_Type& coupling )
217  {
218  M_couplings.push_back ( coupling );
219  }
220 
221  //! Setup the global data of the model.
222  /*!
223  * In particular, it can be used to replace the local values specified in
224  * the model data file, with the ones in the global container.
225  *
226  * @param globalData Global data container.
227  */
228  void setGlobalData ( const multiscaleDataPtr_Type& globalData )
229  {
230  M_globalData = globalData;
231  }
232 
233  //! Scale, rotate and translate the Model in the 3D space
234  /*!
235  * This method apply directly to the mesh before its partitioning.
236  * @param scale Vector (Sx,Sy,Sz) of scale factors
237  * @param rotate Vector (Rx,Ry,Rz) of angles for rotation (degree units)
238  * @param translate Vector (Tx,Ty,Tz) of offset for position
239  */
240  void setGeometry ( const std::array< Real, NDIM >& scale,
241  const std::array< Real, NDIM >& rotate,
242  const std::array< Real, NDIM >& translate );
243 
244  //! Set the epetra communicator for the model
245  /*!
246  * @param comm Epetra communicator
247  */
249  {
250  M_comm = comm;
251  }
252 
253  //@}
254 
255 
256  //! @name Get Methods
257  //@{
258 
259  //! Get the global ID of the model
260  /*!
261  * @return global ID of the model
262  */
263  const UInt& ID() const
264  {
265  return M_ID;
266  }
267 
268  //! Get the type of the model
269  /*!
270  * @return type of the model
271  */
272  const models_Type& type() const
273  {
274  return M_type;
275  }
276 
277  //! Get one available flag by id
278  /*!
279  * @param id id of the boundary flag
280  * @return flag
281  */
282  const multiscaleID_Type& boundaryFlag ( const multiscaleID_Type& boundaryID ) const
283  {
284  return M_boundaryFlags[boundaryID];
285  }
286 
287  //! Get the name of the model
288  /*!
289  * @return name of the model
290  */
291  const std::string& modelName() const
292  {
293  return M_modelName;
294  }
295 
296  //! Get the number of couplings connecting the model
297  /*!
298  * @return number of couplings connecting the model
299  */
301  {
302  return static_cast< UInt > ( M_couplings.size() );
303  }
304 
305  //! Get the coupling local ID through global ID
306  /*!
307  * @param ID global ID of the coupling
308  * @return local ID of the coupling
309  */
310  UInt couplingLocalID ( const UInt& ID ) const;
311 
312  //! Get the coupling through local ID
313  /*!
314  * @param ID local ID of the coupling
315  * @return Pointer to the coupling
316  */
317  multiscaleCouplingPtr_Type coupling ( const UInt& localID ) const
318  {
319  return M_couplings[localID];
320  }
321 
322  //! Get the global data of the model.
323  /*!
324  * @return Global data container.
325  */
327  {
328  return M_globalData;
329  }
330 
331  //! Get the communicator of the model.
332  /*!
333  * @return Communicator of the model.
334  */
336  {
337  return M_comm;
338  }
339 
340  //@}
341 
342 protected:
343 
344  //! Display model ID and name with a user provided tag.
345  /*!
346  * @param tag user provided tag.
347  */
348  void displayModelStatus ( const std::string& tag ) const;
349 
350  UInt M_ID; // Global ID of the model
351  models_Type M_type; // Type of the model (depends on the derived class)
352 
353  multiscaleCouplingsContainer_Type M_couplings; // Container for the couplings
354  std::string M_modelName; // Name of the model
355  multiscaleIDContainer_Type M_boundaryFlags; // Free flags, available for the couplings
356 
357  multiscaleDataPtr_Type M_globalData; // GlobalDataContainer
358 
359  std::array< Real, NDIM > M_geometryScale; // Global geometrical scale
360  std::array< Real, NDIM > M_geometryRotate; // Global geometrical rotation
361  std::array< Real, NDIM > M_geometryTranslate; // Global geometrical translation
362 
364 
365 private:
366 
367  //! @name Unimplemented Methods
368  //@{
369 
370  MultiscaleModel ( const MultiscaleModel& model );
371 
372  MultiscaleModel& operator= ( const MultiscaleModel& model );
373 
374  //@}
375 };
376 
377 // ===================================================
378 // Protected Inline Methods
379 // ===================================================
380 inline void
381 MultiscaleModel::displayModelStatus ( const std::string& tag ) const
382 {
383  if ( M_comm->MyPID() == 0 )
384  {
385  std::cout << " MS- " << tag << " model " << M_ID << " - " << M_modelName << std::endl;
386  }
387 }
388 
389 } // Namespace multiscale
390 } // Namespace LifeV
391 
392 #endif /* MultiscaleModel_H */
virtual void setupModel()=0
Setup the model.
virtual void buildModel()=0
Build the initial model.
std::shared_ptr< multiscaleCoupling_Type > multiscaleCouplingPtr_Type
Displayer::commPtr_Type multiscaleCommPtr_Type
virtual void updateModel()=0
Update the model.
UInt couplingLocalID(const UInt &ID) const
Get the coupling local ID through global ID.
MultiscaleModel()
The main constructor.
std::shared_ptr< multiscaleData_Type > multiscaleDataPtr_Type
void setGeometry(const std::array< Real, NDIM > &scale, const std::array< Real, NDIM > &rotate, const std::array< Real, NDIM > &translate)
Scale, rotate and translate the Model in the 3D space.
const multiscaleCommPtr_Type & communicator() const
Get the communicator of the model.
virtual void solveModel()=0
Solve the System.
const models_Type & type() const
Get the type of the model.
virtual Real checkSolution() const =0
Return a specific scalar quantity to be used for a comparison with a reference value.
void updateInverseJacobian(const UInt &iQuadPt)
void setCommunicator(const multiscaleCommPtr_Type &comm)
Set the epetra communicator for the model.
#define NDIM
Definition: LifeV.hpp:265
std::array< Real, NDIM > M_geometryTranslate
void setCoupling(const UInt &localCouplingID, const multiscaleCouplingPtr_Type &coupling)
Add a pointer to one of the couplings attached to this model.
std::array< Real, NDIM > M_geometryRotate
multiscaleCouplingsContainer_Type M_couplings
void setGlobalData(const multiscaleDataPtr_Type &globalData)
Setup the global data of the model.
const multiscaleID_Type & boundaryFlag(const multiscaleID_Type &boundaryID) const
Get one available flag by id.
virtual void showMe()
Display some information about the model.
virtual ~MultiscaleModel()
Destructor.
multiscaleIDContainer_Type M_boundaryFlags
std::array< Real, NDIM > M_geometryScale
const std::string & modelName() const
Get the name of the model.
MultiscaleModel(const MultiscaleModel &model)
void addCoupling(const multiscaleCouplingPtr_Type &coupling)
Add a pointer to one of the couplings which couple the model.
std::vector< multiscaleCouplingPtr_Type > multiscaleCouplingsContainer_Type
double Real
Generic real data.
Definition: LifeV.hpp:175
std::vector< multiscaleID_Type > multiscaleIDContainer_Type
MultiscaleModel & operator=(const MultiscaleModel &model)
UInt couplingsNumber() const
Get the number of couplings connecting the model.
const multiscaleDataPtr_Type & globalData() const
Get the global data of the model.
virtual void saveSolution()=0
Save the solution.
multiscaleCouplingPtr_Type coupling(const UInt &localID) const
Get the coupling through local ID.
const UInt & ID() const
Get the global ID of the model.
void setCouplingsNumber(const UInt &couplingsNumber)
Set the number of couplings attached to this model.
void clearCouplingsList()
Clear the list of pointers to the couplings.
void setID(const UInt &id)
Set the global ID of the model.
MultiscaleModel - The Multiscale Physical Model.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
virtual void updateSolution()=0
Update the solution.