36 #ifndef INTEGRATE_MATRIX_VOLUME_ID_HPP 37 #define INTEGRATE_MATRIX_VOLUME_ID_HPP 39 #include <lifev/core/LifeV.hpp> 41 #include <lifev/core/fem/QuadratureRule.hpp> 42 #include <lifev/core/mesh/RegionMesh.hpp> 43 #include <lifev/eta/fem/ETCurrentFE.hpp> 44 #include <lifev/eta/fem/MeshGeometricMap.hpp> 45 #include <lifev/eta/fem/QRAdapterBase.hpp> 47 #include <lifev/eta/expression/ExpressionToEvaluation.hpp> 49 #include <lifev/eta/array/ETMatrixElemental.hpp> 51 #include <boost/shared_ptr.hpp> 58 namespace ExpressionAssembly
70 template <
typename MeshType,
71 typename TestSpaceType,
72 typename SolutionSpaceType,
73 typename ExpressionType,
74 typename QRAdapterType >
75 class IntegrateMatrixVolumeID
83 typedef typename ExpressionToEvaluation < ExpressionType,
84 TestSpaceType::field_dim,
85 SolutionSpaceType::field_dim,
86 3 >::evaluation_Type evaluation_Type;
88 typedef typename MeshType::element_Type element_Type;
90 typedef std::shared_ptr<std::vector<element_Type*> > vectorVolumesPtr_Type;
91 typedef std::shared_ptr<std::vector<UInt> > vectorIndexPtr_Type;
100 IntegrateMatrixVolumeID (
const vectorVolumesPtr_Type volumeList,
101 const vectorIndexPtr_Type indexList,
102 const QRAdapterType& qrAdapter,
103 const std::shared_ptr<TestSpaceType>& testSpace,
104 const std::shared_ptr<SolutionSpaceType>& solutionSpace,
105 const ExpressionType& expression);
108 IntegrateMatrixVolumeID (
const IntegrateMatrixVolumeID < MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, QRAdapterType>& integrator);
111 ~IntegrateMatrixVolumeID();
120 template <
typename MatrixType>
121 inline void operator>> (MatrixType& mat)
127 template <
typename MatrixType>
128 inline void operator>> (std::shared_ptr<MatrixType> mat)
140 void check (std::ostream& out = std::cout);
150 template <
typename MatrixType>
151 void addTo (MatrixType& mat);
153 template <
typename MatrixType>
154 inline void addTo (std::shared_ptr<MatrixType> mat)
156 ASSERT (mat != 0,
" Cannot assemble with an empty matrix");
168 IntegrateMatrixVolumeID();
173 vectorVolumesPtr_Type M_volumeList;
174 vectorIndexPtr_Type M_indexList;
177 QRAdapterType M_qrAdapter;
180 std::shared_ptr<TestSpaceType> M_testSpace;
181 std::shared_ptr<SolutionSpaceType> M_solutionSpace;
184 evaluation_Type M_evaluation;
186 ETCurrentFE<3, 1>* M_globalCFE_std;
187 ETCurrentFE<3, 1>* M_globalCFE_adapted;
189 ETCurrentFE<3, TestSpaceType::field_dim>* M_testCFE_std;
190 ETCurrentFE<3, TestSpaceType::field_dim>* M_testCFE_adapted;
192 ETCurrentFE<3, SolutionSpaceType::field_dim>* M_solutionCFE_std;
193 ETCurrentFE<3, SolutionSpaceType::field_dim>* M_solutionCFE_adapted;
195 ETMatrixElemental M_elementalMatrix;
207 template <
typename MeshType,
typename TestSpaceType,
typename SolutionSpaceType,
typename ExpressionType,
typename QRAdapterType>
208 IntegrateMatrixVolumeID<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, QRAdapterType>::
209 IntegrateMatrixVolumeID (
const vectorVolumesPtr_Type volumeList,
210 const vectorIndexPtr_Type indexList,
211 const QRAdapterType& qrAdapter,
212 const std::shared_ptr<TestSpaceType>& testSpace,
213 const std::shared_ptr<SolutionSpaceType>& solutionSpace,
214 const ExpressionType& expression)
215 : M_volumeList ( volumeList ),
216 M_indexList ( indexList ),
217 M_qrAdapter (qrAdapter),
218 M_testSpace (testSpace),
219 M_solutionSpace (solutionSpace),
220 M_evaluation (expression),
222 M_globalCFE_std (
new ETCurrentFE<3, 1> (feTetraP0, geometricMapFromMesh<MeshType>(), qrAdapter.standardQR() ) ),
223 M_globalCFE_adapted (
new ETCurrentFE<3, 1> (feTetraP0, geometricMapFromMesh<MeshType>(), qrAdapter.standardQR() ) ),
225 M_testCFE_std (
new ETCurrentFE<3, TestSpaceType::field_dim> (testSpace->refFE(), testSpace->geoMap(), qrAdapter.standardQR() ) ),
226 M_testCFE_adapted (
new ETCurrentFE<3, TestSpaceType::field_dim> (testSpace->refFE(), testSpace->geoMap(), qrAdapter.standardQR() ) ),
228 M_solutionCFE_std (
new ETCurrentFE<3, SolutionSpaceType::field_dim> (solutionSpace->refFE(), testSpace->geoMap(), qrAdapter.standardQR() ) ),
229 M_solutionCFE_adapted (
new ETCurrentFE<3, SolutionSpaceType::field_dim> (solutionSpace->refFE(), testSpace->geoMap(), qrAdapter.standardQR() ) ),
231 M_elementalMatrix (TestSpaceType::field_dim * testSpace->refFE().nbDof(),
232 SolutionSpaceType::field_dim * solutionSpace->refFE().nbDof() )
234 M_evaluation.setQuadrature (qrAdapter.standardQR() );
235 M_evaluation.setGlobalCFE (M_globalCFE_std);
236 M_evaluation.setTestCFE (M_testCFE_std);
237 M_evaluation.setSolutionCFE (M_solutionCFE_std);
240 template <
typename MeshType,
typename TestSpaceType,
typename SolutionSpaceType,
typename ExpressionType,
typename QRAdapterType>
241 IntegrateMatrixVolumeID<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, QRAdapterType>::
242 IntegrateMatrixVolumeID (
const IntegrateMatrixVolumeID<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, QRAdapterType>& integrator)
243 : M_volumeList (integrator.M_volumeList),
244 M_indexList (integrator.M_indexList),
245 M_qrAdapter (integrator.M_qrAdapter),
246 M_testSpace (integrator.M_testSpace),
247 M_solutionSpace (integrator.M_solutionSpace),
248 M_evaluation (integrator.M_evaluation),
250 M_globalCFE_std (
new ETCurrentFE<3, 1> (feTetraP0, geometricMapFromMesh<MeshType>(), integrator.M_qrAdapter.standardQR() ) ),
251 M_globalCFE_adapted (
new ETCurrentFE<3, 1> (feTetraP0, geometricMapFromMesh<MeshType>(), integrator.M_qrAdapter.standardQR() ) ),
253 M_testCFE_std (
new ETCurrentFE<3, TestSpaceType::field_dim> (M_testSpace->refFE(), M_testSpace->geoMap(), integrator.M_qrAdapter.standardQR() ) ),
254 M_testCFE_adapted (
new ETCurrentFE<3, TestSpaceType::field_dim> (M_testSpace->refFE(), M_testSpace->geoMap(), integrator.M_qrAdapter.standardQR() ) ),
256 M_solutionCFE_std (
new ETCurrentFE<3, SolutionSpaceType::field_dim> (M_solutionSpace->refFE(), M_solutionSpace->geoMap(), integrator.M_qrAdapter.standardQR() ) ),
257 M_solutionCFE_adapted (
new ETCurrentFE<3, SolutionSpaceType::field_dim> (M_solutionSpace->refFE(), M_solutionSpace->geoMap(), integrator.M_qrAdapter.standardQR() )
260 M_elementalMatrix (integrator.M_elementalMatrix)
262 M_evaluation.setQuadrature (integrator.M_qrAdapter.standardQR() );
263 M_evaluation.setGlobalCFE (M_globalCFE_std);
264 M_evaluation.setTestCFE (M_testCFE_std);
265 M_evaluation.setSolutionCFE (M_solutionCFE_std);
268 template <
typename MeshType,
typename TestSpaceType,
typename SolutionSpaceType,
typename ExpressionType,
typename QRAdapterType>
269 IntegrateMatrixVolumeID<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, QRAdapterType>::
270 ~IntegrateMatrixVolumeID()
272 delete M_globalCFE_std;
273 delete M_globalCFE_adapted;
274 delete M_testCFE_std;
275 delete M_testCFE_adapted;
276 delete M_solutionCFE_std;
277 delete M_solutionCFE_adapted;
285 template <
typename MeshType,
typename TestSpaceType,
typename SolutionSpaceType,
typename ExpressionType,
typename QRAdapterType>
287 IntegrateMatrixVolumeID<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, QRAdapterType>::
288 check (std::ostream& out)
290 out <<
" Checking the integration : " << std::endl;
291 M_evaluation.display (out);
293 out <<
" Elemental matrix : " << std::endl;
294 M_elementalMatrix.showMe (out);
299 template <
typename MeshType,
typename TestSpaceType,
typename SolutionSpaceType,
typename ExpressionType,
typename QRAdapterType>
300 template <
typename MatrixType>
302 IntegrateMatrixVolumeID<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, QRAdapterType>::
303 addTo (MatrixType& mat)
306 bool isPreviousAdapted (
true);
309 UInt nbElements ( (*M_volumeList).size() );
310 UInt nbIndexes ( (*M_indexList).size() );
312 ASSERT ( nbElements == nbIndexes,
"The number of indexes is different from the number of volumes!!!");
314 UInt nbQuadPt_std (M_qrAdapter.standardQR().nbQuadPt() );
315 UInt nbTestDof (M_testSpace->refFE().nbDof() );
316 UInt nbSolutionDof (M_solutionSpace->refFE().nbDof() );
318 for (UInt iElement (0); iElement < nbElements; ++iElement)
321 M_elementalMatrix.zero();
324 M_qrAdapter.update ( (*M_indexList) [iElement] );
326 if (M_qrAdapter.isAdaptedElement() )
329 M_evaluation.setQuadrature ( M_qrAdapter.adaptedQR() );
330 M_globalCFE_adapted -> setQuadratureRule ( M_qrAdapter.adaptedQR() );
331 M_testCFE_adapted -> setQuadratureRule ( M_qrAdapter.adaptedQR() );
332 M_solutionCFE_adapted -> setQuadratureRule ( M_qrAdapter.adaptedQR() );
335 M_evaluation.setGlobalCFE ( M_globalCFE_adapted );
336 M_evaluation.setTestCFE ( M_testCFE_adapted );
337 M_evaluation.setSolutionCFE ( M_solutionCFE_adapted );
339 M_evaluation.update ( (*M_indexList) [iElement] );
342 M_globalCFE_adapted->update (* ( (*M_volumeList) [iElement]), evaluation_Type::S_globalUpdateFlag | ET_UPDATE_WDET);
343 M_testCFE_adapted->update (* ( (*M_volumeList) [iElement]), evaluation_Type::S_testUpdateFlag);
344 M_solutionCFE_adapted->update (* ( (*M_volumeList) [iElement]), evaluation_Type::S_solutionUpdateFlag);
348 for (UInt iblock (0); iblock < TestSpaceType::field_dim; ++iblock)
350 for (UInt jblock (0); jblock < SolutionSpaceType::field_dim; ++jblock)
354 for (UInt i (0); i < nbTestDof; ++i)
356 M_elementalMatrix.setRowIndex
357 (i + iblock * nbTestDof,
358 M_testSpace->dof().localToGlobalMap ( (*M_indexList) [iElement], i) + iblock * M_testSpace->dof().numTotalDof() );
362 for (UInt j (0); j < nbSolutionDof; ++j)
364 M_elementalMatrix.setColumnIndex
365 (j + jblock * nbSolutionDof,
366 M_solutionSpace->dof().localToGlobalMap ( (*M_indexList) [iElement], j) + jblock * M_solutionSpace->dof().numTotalDof() );
369 for (UInt iQuadPt (0); iQuadPt < M_qrAdapter.adaptedQR().nbQuadPt(); ++iQuadPt)
371 for (UInt i (0); i < nbTestDof; ++i)
373 for (UInt j (0); j < nbSolutionDof; ++j)
375 M_elementalMatrix.element (i + iblock * nbTestDof, j + jblock * nbSolutionDof) +=
376 M_evaluation.value_qij (iQuadPt, i + iblock * nbTestDof, j + jblock * nbSolutionDof)
377 * M_globalCFE_adapted->wDet (iQuadPt);
385 isPreviousAdapted =
true;
391 if (isPreviousAdapted)
393 M_evaluation.setQuadrature ( M_qrAdapter.standardQR() );
394 M_evaluation.setGlobalCFE ( M_globalCFE_std );
395 M_evaluation.setTestCFE ( M_testCFE_std );
396 M_evaluation.setSolutionCFE ( M_solutionCFE_std );
398 isPreviousAdapted =
false;
402 M_globalCFE_std->update (* ( (*M_volumeList) [iElement]), evaluation_Type::S_globalUpdateFlag | ET_UPDATE_WDET);
403 M_testCFE_std->update (* ( (*M_volumeList) [iElement]), evaluation_Type::S_testUpdateFlag);
404 M_solutionCFE_std->update (* ( (*M_volumeList) [iElement]), evaluation_Type::S_solutionUpdateFlag);
407 M_evaluation.update ( (*M_indexList) [iElement] );
411 for (UInt iblock (0); iblock < TestSpaceType::field_dim; ++iblock)
413 for (UInt jblock (0); jblock < SolutionSpaceType::field_dim; ++jblock)
417 for (UInt i (0); i < nbTestDof; ++i)
419 M_elementalMatrix.setRowIndex
420 (i + iblock * nbTestDof,
421 M_testSpace->dof().localToGlobalMap ( (*M_indexList) [iElement], i) + iblock * M_testSpace->dof().numTotalDof() );
425 for (UInt j (0); j < nbSolutionDof; ++j)
427 M_elementalMatrix.setColumnIndex
428 (j + jblock * nbSolutionDof,
429 M_solutionSpace->dof().localToGlobalMap ( (*M_indexList) [iElement], j) + jblock * M_solutionSpace->dof().numTotalDof() );
432 for (UInt iQuadPt (0); iQuadPt < nbQuadPt_std; ++iQuadPt)
434 for (UInt i (0); i < nbTestDof; ++i)
436 for (UInt j (0); j < nbSolutionDof; ++j)
438 M_elementalMatrix.element (i + iblock * nbTestDof, j + jblock * nbSolutionDof) +=
439 M_evaluation.value_qij (iQuadPt, i + iblock * nbTestDof, j + jblock * nbSolutionDof)
440 * M_globalCFE_std->wDet (iQuadPt);
450 M_elementalMatrix.pushToGlobal (mat);