36 #ifndef INTEGRATE_MATRIX_ELEMENT_LS_ADAPTED_HPP 37 #define INTEGRATE_MATRIX_ELEMENT_LS_ADAPTED_HPP 39 #include <lifev/core/LifeV.hpp> 41 #include <lifev/level_set/fem/LevelSetQRAdapter.hpp> 42 #include <lifev/eta/fem/ETCurrentFE.hpp> 43 #include <lifev/eta/fem/MeshGeometricMap.hpp> 45 #include <lifev/eta/expression/ExpressionToEvaluation.hpp> 47 #include <lifev/eta/array/ETMatrixElemental.hpp> 49 #include <boost/shared_ptr.hpp> 56 namespace ExpressionAssembly
72 template <
typename MeshType,
73 typename TestSpaceType,
74 typename SolutionSpaceType,
75 typename ExpressionType,
76 typename LSFESpaceType,
77 typename LSVectorType >
78 class IntegrateMatrixElementLSAdapted
86 typedef typename ExpressionToEvaluation < ExpressionType,
87 TestSpaceType::S_fieldDim,
88 SolutionSpaceType::S_fieldDim,
89 3 >::evaluation_Type evaluation_Type;
92 typedef LevelSetQRAdapter<LSFESpaceType, LSVectorType> QRAdapter_Type;
101 IntegrateMatrixElementLSAdapted (
const std::shared_ptr<MeshType>& mesh,
102 const QRAdapter_Type& QRAdapter,
103 const std::shared_ptr<TestSpaceType>& testSpace,
104 const std::shared_ptr<SolutionSpaceType>& solutionSpace,
105 const ExpressionType& expression);
108 IntegrateMatrixElementLSAdapted (
const IntegrateMatrixElementLSAdapted
109 < MeshType, TestSpaceType, SolutionSpaceType,
110 ExpressionType, LSFESpaceType, LSVectorType > & integrator);
113 ~IntegrateMatrixElementLSAdapted();
122 template <
typename MatrixType>
123 inline void operator>> (MatrixType& mat)
128 template <
typename MatrixType>
129 inline void operator>> (std::shared_ptr<MatrixType> mat)
142 void check (std::ostream& out = std::cout);
152 template <
typename MatrixType>
153 void addTo (MatrixType& mat);
165 template <
typename MatrixType>
166 inline void addTo (std::shared_ptr<MatrixType> mat)
168 ASSERT (mat != 0,
" Cannot assemble with an empty matrix");
180 IntegrateMatrixElementLSAdapted();
185 std::shared_ptr<MeshType> M_mesh;
188 QRAdapter_Type M_QRAdapter;
191 std::shared_ptr<TestSpaceType> M_testSpace;
192 std::shared_ptr<SolutionSpaceType> M_solutionSpace;
195 evaluation_Type M_evaluation;
198 ETCurrentFE<3, 1>* M_globalCFE_unadapted;
199 ETCurrentFE<3, 1>* M_globalCFE_adapted;
201 ETCurrentFE<3, TestSpaceType::S_fieldDim>* M_testCFE_unadapted;
202 ETCurrentFE<3, TestSpaceType::S_fieldDim>* M_testCFE_adapted;
204 ETCurrentFE<3, SolutionSpaceType::S_fieldDim>* M_solutionCFE_unadapted;
205 ETCurrentFE<3, SolutionSpaceType::S_fieldDim>* M_solutionCFE_adapted;
207 ETMatrixElemental M_elementalMatrix;
219 template <
typename MeshType,
220 typename TestSpaceType,
221 typename SolutionSpaceType,
222 typename ExpressionType,
223 typename LSFESpaceType,
224 typename LSVectorType >
225 IntegrateMatrixElementLSAdapted<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, LSFESpaceType, LSVectorType>::
226 IntegrateMatrixElementLSAdapted (
const std::shared_ptr<MeshType>& mesh,
227 const QRAdapter_Type& QRAdapter,
228 const std::shared_ptr<TestSpaceType>& testSpace,
229 const std::shared_ptr<SolutionSpaceType>& solutionSpace,
230 const ExpressionType& expression)
232 M_QRAdapter (QRAdapter),
233 M_testSpace (testSpace),
234 M_solutionSpace (solutionSpace),
235 M_evaluation (expression),
237 M_globalCFE_unadapted (
new ETCurrentFE<3, 1> (feTetraP0, geometricMapFromMesh<MeshType>(), QRAdapter.standardQR() ) ),
238 M_globalCFE_adapted (
new ETCurrentFE<3, 1> (feTetraP0, geometricMapFromMesh<MeshType>(), QRAdapter.standardQR() ) ),
240 M_testCFE_unadapted (
new ETCurrentFE<3, TestSpaceType::S_fieldDim> (testSpace->refFE(), testSpace->geoMap(), QRAdapter.standardQR() ) ),
241 M_testCFE_adapted (
new ETCurrentFE<3, TestSpaceType::S_fieldDim> (testSpace->refFE(), testSpace->geoMap(), QRAdapter.standardQR() ) ),
243 M_solutionCFE_unadapted (
new ETCurrentFE<3, SolutionSpaceType::S_fieldDim> (solutionSpace->refFE(), testSpace->geoMap(), QRAdapter.standardQR() ) ),
244 M_solutionCFE_adapted (
new ETCurrentFE<3, SolutionSpaceType::S_fieldDim> (solutionSpace->refFE(), testSpace->geoMap(), QRAdapter.standardQR() ) ),
246 M_elementalMatrix (TestSpaceType::S_fieldDim * testSpace->refFE().nbDof(),
247 SolutionSpaceType::S_fieldDim * solutionSpace->refFE().nbDof() )
249 M_evaluation.setQuadrature ( M_QRAdapter.standardQR() );
250 M_evaluation.setGlobalCFE ( M_globalCFE_unadapted );
251 M_evaluation.setTestCFE ( M_testCFE_unadapted );
252 M_evaluation.setSolutionCFE ( M_solutionCFE_unadapted );
255 template <
typename MeshType,
256 typename TestSpaceType,
257 typename SolutionSpaceType,
258 typename ExpressionType,
259 typename LSFESpaceType,
260 typename LSVectorType >
261 IntegrateMatrixElementLSAdapted<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, LSFESpaceType, LSVectorType>::
262 IntegrateMatrixElementLSAdapted (
const IntegrateMatrixElementLSAdapted < MeshType, TestSpaceType, SolutionSpaceType,
263 ExpressionType, LSFESpaceType, LSVectorType > & integrator)
264 : M_mesh (integrator.M_mesh),
265 M_QRAdapter (integrator.M_QRAdapter),
266 M_testSpace (integrator.M_testSpace),
267 M_solutionSpace (integrator.M_solutionSpace),
268 M_evaluation (integrator.M_evaluation),
270 M_globalCFE_unadapted (
new ETCurrentFE<3, 1> (feTetraP0, geometricMapFromMesh<MeshType>(), M_QRAdapter.standardQR() ) ),
271 M_globalCFE_adapted (
new ETCurrentFE<3, 1> (feTetraP0, geometricMapFromMesh<MeshType>(), M_QRAdapter.standardQR() ) ),
273 M_testCFE_unadapted (
new ETCurrentFE<3, TestSpaceType::S_fieldDim> (M_testSpace->refFE(), M_testSpace->geoMap(), M_QRAdapter.standardQR() ) ),
274 M_testCFE_adapted (
new ETCurrentFE<3, TestSpaceType::S_fieldDim> (M_testSpace->refFE(), M_testSpace->geoMap(), M_QRAdapter.standardQR() ) ),
276 M_solutionCFE_unadapted (
new ETCurrentFE<3, SolutionSpaceType::S_fieldDim> (M_solutionSpace->refFE(), M_solutionSpace->geoMap(), M_QRAdapter.standardQR() ) ),
277 M_solutionCFE_adapted (
new ETCurrentFE<3, SolutionSpaceType::S_fieldDim> (M_solutionSpace->refFE(), M_solutionSpace->geoMap(), M_QRAdapter.standardQR() ) ),
280 M_elementalMatrix (integrator.M_elementalMatrix)
282 M_evaluation.setQuadrature (M_QRAdapter.standardQR() );
283 M_evaluation.setGlobalCFE ( M_globalCFE_unadapted );
284 M_evaluation.setTestCFE ( M_testCFE_unadapted );
285 M_evaluation.setSolutionCFE ( M_solutionCFE_unadapted );
288 template <
typename MeshType,
289 typename TestSpaceType,
290 typename SolutionSpaceType,
291 typename ExpressionType,
292 typename LSFESpaceType,
293 typename LSVectorType >
294 IntegrateMatrixElementLSAdapted<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, LSFESpaceType, LSVectorType>::
295 ~IntegrateMatrixElementLSAdapted()
297 delete M_globalCFE_unadapted;
298 delete M_globalCFE_adapted;
299 delete M_testCFE_unadapted;
300 delete M_testCFE_adapted;
301 delete M_solutionCFE_unadapted;
302 delete M_solutionCFE_adapted;
309 template <
typename MeshType,
310 typename TestSpaceType,
311 typename SolutionSpaceType,
312 typename ExpressionType,
313 typename LSFESpaceType,
314 typename LSVectorType >
316 IntegrateMatrixElementLSAdapted<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, LSFESpaceType, LSVectorType>::
317 check (std::ostream& out)
319 out <<
" Checking the integration : " << std::endl;
320 M_evaluation.display (out);
322 out <<
" Elemental matrix : " << std::endl;
323 M_elementalMatrix.showMe (out);
327 template <
typename MeshType,
328 typename TestSpaceType,
329 typename SolutionSpaceType,
330 typename ExpressionType,
331 typename LSFESpaceType,
332 typename LSVectorType >
333 template <
typename MatrixType>
335 IntegrateMatrixElementLSAdapted<MeshType, TestSpaceType, SolutionSpaceType, ExpressionType, LSFESpaceType, LSVectorType>::
336 addTo (MatrixType& mat)
338 const UInt nbElements (M_mesh->numElements() );
339 const UInt nbQuadPt_unadapted (M_QRAdapter.standardQR().nbQuadPt() );
340 const UInt nbTestDof (M_testSpace->refFE().nbDof() );
341 const UInt nbSolutionDof (M_solutionSpace->refFE().nbDof() );
343 bool isPreviousAdapted (
true);
345 for (UInt iElement (0); iElement < nbElements; ++iElement)
348 M_elementalMatrix.zero();
351 M_QRAdapter.update (iElement);
354 if ( M_QRAdapter.isAdaptedElement() )
357 M_globalCFE_adapted->setQuadratureRule ( M_QRAdapter.adaptedQR() );
358 M_testCFE_adapted->setQuadratureRule ( M_QRAdapter.adaptedQR() );
359 M_solutionCFE_adapted->setQuadratureRule ( M_QRAdapter.adaptedQR() );
362 M_evaluation.setGlobalCFE ( M_globalCFE_adapted );
363 M_evaluation.setTestCFE ( M_testCFE_adapted );
364 M_evaluation.setSolutionCFE ( M_solutionCFE_adapted );
366 M_evaluation.setQuadrature ( M_QRAdapter.adaptedQR() );
369 M_globalCFE_adapted->update (M_mesh->element (iElement), evaluation_Type::S_globalUpdateFlag | ET_UPDATE_WDET);
370 M_testCFE_adapted->update (M_mesh->element (iElement), evaluation_Type::S_testUpdateFlag);
371 M_solutionCFE_adapted->update (M_mesh->element (iElement), evaluation_Type::S_solutionUpdateFlag);
374 M_evaluation.update (iElement);
378 for (UInt iblock (0); iblock < TestSpaceType::S_fieldDim; ++iblock)
380 for (UInt jblock (0); jblock < SolutionSpaceType::S_fieldDim; ++jblock)
384 for (UInt i (0); i < nbTestDof; ++i)
386 M_elementalMatrix.setRowIndex
387 (i + iblock * nbTestDof,
388 M_testSpace->dof().localToGlobalMap (iElement, i) + iblock * M_testSpace->dof().numTotalDof() );
392 for (UInt j (0); j < nbSolutionDof; ++j)
394 M_elementalMatrix.setColumnIndex
395 (j + jblock * nbSolutionDof,
396 M_solutionSpace->dof().localToGlobalMap (iElement, j) + jblock * M_solutionSpace->dof().numTotalDof() );
399 for (UInt iQuadPt (0); iQuadPt < M_QRAdapter.adaptedQR().nbQuadPt(); ++iQuadPt)
401 for (UInt i (0); i < nbTestDof; ++i)
403 for (UInt j (0); j < nbSolutionDof; ++j)
405 M_elementalMatrix.element (i + iblock * nbTestDof, j + jblock * nbSolutionDof) +=
406 M_evaluation.value_qij (iQuadPt, i + iblock * nbTestDof, j + jblock * nbSolutionDof)
407 * M_globalCFE_adapted->wDet (iQuadPt);
415 isPreviousAdapted =
true;
419 if (isPreviousAdapted)
422 M_evaluation.setGlobalCFE ( M_globalCFE_unadapted );
423 M_evaluation.setTestCFE ( M_testCFE_unadapted );
424 M_evaluation.setSolutionCFE ( M_solutionCFE_unadapted );
426 M_evaluation.setQuadrature ( M_QRAdapter.standardQR() );
431 M_globalCFE_unadapted->update (M_mesh->element (iElement), evaluation_Type::S_globalUpdateFlag | ET_UPDATE_WDET);
432 M_testCFE_unadapted->update (M_mesh->element (iElement), evaluation_Type::S_testUpdateFlag);
433 M_solutionCFE_unadapted->update (M_mesh->element (iElement), evaluation_Type::S_solutionUpdateFlag);
436 M_evaluation.update (iElement);
440 for (UInt iblock (0); iblock < TestSpaceType::S_fieldDim; ++iblock)
442 for (UInt jblock (0); jblock < SolutionSpaceType::S_fieldDim; ++jblock)
446 for (UInt i (0); i < nbTestDof; ++i)
448 M_elementalMatrix.setRowIndex
449 (i + iblock * nbTestDof,
450 M_testSpace->dof().localToGlobalMap (iElement, i) + iblock * M_testSpace->dof().numTotalDof() );
454 for (UInt j (0); j < nbSolutionDof; ++j)
456 M_elementalMatrix.setColumnIndex
457 (j + jblock * nbSolutionDof,
458 M_solutionSpace->dof().localToGlobalMap (iElement, j) + jblock * M_solutionSpace->dof().numTotalDof() );
461 for (UInt iQuadPt (0); iQuadPt < nbQuadPt_unadapted; ++iQuadPt)
463 for (UInt i (0); i < nbTestDof; ++i)
465 for (UInt j (0); j < nbSolutionDof; ++j)
467 M_elementalMatrix.element (i + iblock * nbTestDof, j + jblock * nbSolutionDof) +=
468 M_evaluation.value_qij (iQuadPt, i + iblock * nbTestDof, j + jblock * nbSolutionDof)
469 * M_globalCFE_unadapted->wDet (iQuadPt);
478 isPreviousAdapted =
false;
482 M_elementalMatrix.pushToGlobal (mat);