LifeV
IntegrateValueElementLSAdapted.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 class IntegrateValueElementLSAdapted
30 
31  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
32  @date 21 Dec 2011
33 
34 
35  */
36 
37 #ifndef INTEGRATEVALUEELEMENTLSADAPTED_H
38 #define INTEGRATEVALUEELEMENTLSADAPTED_H 1
39 
40 #include <lifev/core/LifeV.hpp>
41 
42 #include <lifev/level_set/fem/LevelSetQRAdapter.hpp>
43 #include <lifev/eta/fem/ETCurrentFE.hpp>
44 #include <lifev/eta/fem/MeshGeometricMap.hpp>
45 
46 #include <lifev/eta/expression/ExpressionToEvaluation.hpp>
47 
48 #include <boost/shared_ptr.hpp>
49 
50 namespace LifeV
51 {
52 
53 namespace ExpressionAssembly
54 {
55 
56 //! IntegrateValueElementLSAdapted - Class to integrate a value using a quadrature conforming to a level set
57 /*!
58  @author Samuel Quinodoz
59  @see Reference to papers (if available)
60 
61  */
62 
63 template< typename MeshType, typename ExpressionType, typename LSFESpaceType, typename VectorType>
64 class IntegrateValueElementLSAdapted
65 {
66 public:
67 
68  //! @name Public Types
69  //@{
70 
71  typedef typename ExpressionToEvaluation < ExpressionType,
72  0,
73  0,
74  3 >::evaluation_Type evaluation_Type;
75 
76  typedef LevelSetQRAdapter<LSFESpaceType, VectorType> QRAdapter_Type;
77 
78 
79  //@}
80 
81 
82  //! @name Constructor & Destructor
83  //@{
84 
85  IntegrateValueElementLSAdapted ( const std::shared_ptr<MeshType>& mesh,
86  const QRAdapter_Type& QRAdapter,
87  const ExpressionType& expression);
88 
89  IntegrateValueElementLSAdapted ( const IntegrateValueElementLSAdapted
90  <MeshType, ExpressionType, LSFESpaceType, VectorType>& integrator);
91 
92  ~IntegrateValueElementLSAdapted();
93 
94 
95  //@}
96 
97 
98  //! @name Operators
99  //@{
100 
101  inline void operator>> (Real& value)
102  {
103  addTo (value);
104  }
105 
106  //@}
107 
108 
109  //! @name Methods
110  //@{
111 
112  void addTo (Real& value);
113 
114  //@}
115 
116 private:
117 
118  //! @name Private Methods
119  //@{
120 
121  IntegrateValueElementLSAdapted();
122 
123  //@}
124 
125  // Mesh
126  std::shared_ptr<MeshType> M_mesh;
127 
128  // Quadrature Adapter
129  QRAdapter_Type M_QRAdapter;
130 
131  // Evaluation tree
132  evaluation_Type M_evaluation;
133 
134  // CurrentFE
135  ETCurrentFE<3, 1>* M_globalCFE_unadapted;
136  ETCurrentFE<3, 1>* M_globalCFE_adapted;
137 
138 };
139 
140 
141 template< typename MeshType, typename ExpressionType, typename LSFESpaceType, typename VectorType>
142 IntegrateValueElementLSAdapted<MeshType, ExpressionType, LSFESpaceType, VectorType>::
143 IntegrateValueElementLSAdapted ( const std::shared_ptr<MeshType>& mesh,
144  const QRAdapter_Type& QRAdapter,
145  const ExpressionType& expression)
146  :
147  M_mesh (mesh),
148  M_QRAdapter (QRAdapter),
149  M_evaluation (expression),
150 
151  M_globalCFE_unadapted ( new ETCurrentFE<3, 1> ( feTetraP0, geometricMapFromMesh<MeshType>(), QRAdapter.standardQR() ) ),
152  M_globalCFE_adapted ( new ETCurrentFE<3, 1> ( feTetraP0, geometricMapFromMesh<MeshType>(), QRAdapter.standardQR() ) )
153 {
154  M_evaluation.setQuadrature ( QRAdapter.standardQR() );
155  M_evaluation.setGlobalCFE (M_globalCFE_unadapted);
156 }
157 
158 template< typename MeshType, typename ExpressionType, typename LSFESpaceType, typename VectorType>
159 IntegrateValueElementLSAdapted<MeshType, ExpressionType, LSFESpaceType, VectorType>::
160 IntegrateValueElementLSAdapted ( const IntegrateValueElementLSAdapted
161  <MeshType, ExpressionType, LSFESpaceType, VectorType>& integrator)
162  :
163  M_mesh ( integrator.M_mesh ),
164  M_QRAdapter ( integrator.M_QRAdapter ),
165  M_evaluation ( integrator.M_evaluation ),
166 
167  M_globalCFE_unadapted ( new ETCurrentFE<3, 1> ( feTetraP0, geometricMapFromMesh<MeshType>(), M_QRAdapter.standardQR() ) ),
168  M_globalCFE_adapted ( new ETCurrentFE<3, 1> ( feTetraP0, geometricMapFromMesh<MeshType>(), M_QRAdapter.standardQR() ) )
169 {
170  M_evaluation.setQuadrature (M_QRAdapter.standardQR() );
171  M_evaluation.setGlobalCFE (M_globalCFE_unadapted);
172 }
173 
174 
175 template< typename MeshType, typename ExpressionType, typename LSFESpaceType, typename VectorType>
176 IntegrateValueElementLSAdapted<MeshType, ExpressionType, LSFESpaceType, VectorType>::
177 ~IntegrateValueElementLSAdapted()
178 {
179  delete M_globalCFE_unadapted;
180  delete M_globalCFE_adapted;
181 }
182 
183 template< typename MeshType, typename ExpressionType, typename LSFESpaceType, typename VectorType>
184 void
185 IntegrateValueElementLSAdapted<MeshType, ExpressionType, LSFESpaceType, VectorType>::
186 addTo (Real& value)
187 {
188  const UInt nbElements (M_mesh->numElements() );
189  const UInt nbQuadPt_unadapted (M_QRAdapter.standardQR().nbQuadPt() );
190 
191  // Even if this is not the case, this
192  // prevents many potentially buggy behaviours
193  // and does not harm.
194  bool isPreviousAdapted (true);
195 
196 
197  for (UInt iElement (0); iElement < nbElements; ++iElement)
198  {
199  M_QRAdapter.update (iElement);
200 
201  if ( M_QRAdapter.isAdaptedElement() )
202  {
203  // Set the new QR everywhere
204  M_evaluation.setQuadrature ( M_QRAdapter.adaptedQR() );
205  M_globalCFE_adapted->setQuadratureRule ( M_QRAdapter.adaptedQR() );
206 
207  M_evaluation.setGlobalCFE ( M_globalCFE_adapted );
208 
209  // Update the currentFEs
210  M_globalCFE_adapted->update (M_mesh->element (iElement), evaluation_Type::S_globalUpdateFlag | ET_UPDATE_WDET);
211 
212  // Update the evaluation
213  M_evaluation.update (iElement);
214 
215  // Make the assembly
216  for (UInt iQuadPt (0); iQuadPt < M_QRAdapter.adaptedQR().nbQuadPt(); ++iQuadPt)
217  {
218  value += M_evaluation.value_q (iQuadPt)
219  * M_globalCFE_adapted->wDet (iQuadPt);
220  }
221 
222  isPreviousAdapted = true;
223  }
224  else
225  {
226  // if the previous element was adapted, reset the QR
227  if (isPreviousAdapted)
228  {
229  M_evaluation.setQuadrature ( M_QRAdapter.standardQR() );
230  M_evaluation.setGlobalCFE ( M_globalCFE_unadapted );
231  }
232 
233  // Update the currentFEs
234  M_globalCFE_unadapted->update (M_mesh->element (iElement), evaluation_Type::S_globalUpdateFlag | ET_UPDATE_WDET);
235 
236  // Update the evaluation
237  M_evaluation.update (iElement);
238 
239 
240  // Make the assembly
241  for (UInt iQuadPt (0); iQuadPt < nbQuadPt_unadapted; ++iQuadPt)
242  {
243  value += M_evaluation.value_q (iQuadPt)
244  * M_globalCFE_unadapted->wDet (iQuadPt);
245  }
246 
247  isPreviousAdapted = false;
248  }
249  }
250 }
251 
252 
253 } // Namespace ExpressionAssembly
254 
255 } // Namespace LifeV
256 
257 #endif /* INTEGRATEVALUEELEMENTLSADAPTED_H */