Directory: | ./ |
---|---|
File: | Tools/fe_utilities.hpp |
Date: | 2024-04-14 07:32:34 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 22 | 24 | 91.7% |
Branches: | 13 | 22 | 59.1% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // ______ ______ _ _ _____ ______ | ||
2 | // | ____| ____| | (_)/ ____| | ____| | ||
3 | // | |__ | |__ | | _| (___ ___| |__ | ||
4 | // | __| | __| | | | |\___ \ / __| __| | ||
5 | // | | | |____| |____| |____) | (__| |____ | ||
6 | // |_| |______|______|_|_____/ \___|______| | ||
7 | // Finite Elements for Life Sciences and Engineering | ||
8 | // | ||
9 | // License: LGL2.1 License | ||
10 | // FELiScE default license: LICENSE in root folder | ||
11 | // | ||
12 | // Main authors: Vicente Mataix Ferrandiz | ||
13 | // | ||
14 | |||
15 | #ifndef _FE_UTILITIES_HPP | ||
16 | #define _FE_UTILITIES_HPP | ||
17 | |||
18 | // System includes | ||
19 | #include <vector> | ||
20 | #include <functional> | ||
21 | |||
22 | // External includes | ||
23 | |||
24 | // Project includes | ||
25 | #include "Geometry/geometricMeshRegion.hpp" | ||
26 | |||
27 | namespace felisce | ||
28 | { | ||
29 | |||
30 | namespace FEUtilities | ||
31 | { | ||
32 | /** | ||
33 | * @brief This method checks if the mesh is inverted | ||
34 | * @param rMesh The given mesh to generate to check | ||
35 | * @param rBagElement The element type to be considered | ||
36 | * @param pFunction The function to call for the element loop | ||
37 | * @tparam TFunction The type of function of pFunction | ||
38 | * @param pFunctionPreFE The function to call before the element loop | ||
39 | * @tparam TFunctionPreFE The type of function of pFunctionPreFE | ||
40 | * @param pFunctionPostFE The function to call after the element loop | ||
41 | * @tparam TFunctionPostFE The type of function of pFunctionPostFE | ||
42 | * @todo This function in the future can be adapted for STL loops | ||
43 | */ | ||
44 | template< | ||
45 | typename TFunction, | ||
46 | typename TFunctionPreFE = std::function<void(const GeometricMeshRegion::ElementType&)>, | ||
47 | typename TFunctionPostFE = std::function<void(const GeometricMeshRegion::ElementType&)> | ||
48 | > | ||
49 | 29 | inline double LoopOverElements( | |
50 | GeometricMeshRegion& rMesh, | ||
51 | const std::vector<GeometricMeshRegion::ElementType>& rBagElement, | ||
52 | const TFunction* pFunction, | ||
53 | const TFunctionPreFE* pFunctionPreFE = nullptr, | ||
54 | const TFunctionPostFE* pFunctionPostFE = nullptr | ||
55 | ) | ||
56 | { | ||
57 | // Auxiliary double | ||
58 | 29 | double auxiliary_double = 0.0; | |
59 | |||
60 | // Assemblyloop | ||
61 | GeometricMeshRegion::ElementType eltType; // Geometric element type in the mesh. | ||
62 | 29 | int numPointPerElt = 0; // Number of points per geometric element. | |
63 | 29 | felInt numEltPerLabel = 0; // Number of element for one label and one eltType. | |
64 | |||
65 | // Use to define a "global" numbering of element in the mesh. | ||
66 | felInt numElement[ GeometricMeshRegion::m_numTypesOfElement ]; | ||
67 |
2/2✓ Branch 0 taken 375 times.
✓ Branch 1 taken 15 times.
|
754 | for (int ityp=0; ityp<GeometricMeshRegion::m_numTypesOfElement; ityp++ ) { |
68 | 725 | numElement[static_cast<GeometricMeshRegion::ElementType>(ityp)] = 0; | |
69 | } | ||
70 | |||
71 | 29 | std::vector<Point*> elemPoint; | |
72 | 29 | std::vector<felInt> elemIdPoint; | |
73 | felInt ielSupportDof; | ||
74 | |||
75 | // Assembly loop. | ||
76 | // First loop on geometric type. | ||
77 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 2 taken 15 times.
|
54 | for (std::size_t i = 0; i < rBagElement.size(); ++i) { |
78 | 25 | eltType = rBagElement[i]; | |
79 | |||
80 | // Resize array. | ||
81 | 25 | numPointPerElt = GeometricMeshRegion::m_numPointsPerElt[eltType]; | |
82 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
25 | elemPoint.resize(numPointPerElt, nullptr); |
83 |
1/2✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
|
25 | elemIdPoint.resize(numPointPerElt, 0); |
84 | |||
85 | // Allocate array use for assemble with PETSc | ||
86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
25 | if (pFunctionPreFE) { |
87 | ✗ | (*pFunctionPreFE)(eltType); | |
88 | } | ||
89 | |||
90 | // Second loop on region of the mesh. | ||
91 |
2/2✓ Branch 4 taken 13 times.
✓ Branch 5 taken 13 times.
|
50 | for(auto itRef = rMesh.intRefToBegEndMaps[eltType].begin(); itRef != rMesh.intRefToBegEndMaps[eltType].end(); ++itRef) { |
92 | 25 | numEltPerLabel = itRef->second.second; | |
93 | |||
94 | // Third loop on element in the region with the type: eltType. ("real" loop on elements). | ||
95 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 13 times.
|
51 | for ( felInt iel = 0; iel < numEltPerLabel; iel++) { |
96 |
1/2✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
|
26 | auxiliary_double += (*pFunction)(eltType, numElement[eltType], elemPoint, elemIdPoint, ielSupportDof); |
97 | 26 | numElement[eltType]++; | |
98 | } | ||
99 | } | ||
100 | // Desallocate array use for assemble with PETSc | ||
101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
25 | if (pFunctionPostFE) { |
102 | ✗ | (*pFunctionPostFE)(eltType); | |
103 | } | ||
104 | } | ||
105 | |||
106 | 29 | return auxiliary_double; | |
107 | 29 | } | |
108 | |||
109 | /** | ||
110 | * @brief This method checks if the mesh is inverted | ||
111 | * @param rMesh The given mesh to generate to check | ||
112 | * @param jacobianCheck If the check is to be done considering the jacobian or the triple product check | ||
113 | */ | ||
114 | bool CheckVolumeIsInverted( | ||
115 | GeometricMeshRegion& rMesh, | ||
116 | const bool jacobianCheck = false | ||
117 | ); | ||
118 | } | ||
119 | |||
120 | } | ||
121 | |||
122 | #endif | ||
123 |