GCC Code Coverage Report


Directory: ./
File: DegreeOfFreedom/boundaryCondition.hpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 59 63 93.7%
Branches: 26 58 44.8%

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: J. Foulon & J-F. Gerbeau
13 //
14
15 #ifndef _BOUNDARYCONDITION_HPP
16 #define _BOUNDARYCONDITION_HPP
17
18 // System includes
19 #include <string>
20 #include <unordered_map>
21 #include <unordered_set>
22 #include <utility>
23
24 // External includes
25
26 // Project includes
27 #include "Core/shared_pointers.hpp"
28 #include "DegreeOfFreedom/variable.hpp"
29 #include "Geometry/geometricMeshRegion.hpp"
30 #include "Solver/linearProblem.hpp"
31
32 namespace felisce
33 {
34 ///@name felisce Globals
35 ///@{
36
37 ///@}
38 ///@name Type Definitions
39 ///@{
40
41 ///@}
42 ///@name Enum's
43 ///@{
44
45 ///@}
46 ///@name Functions
47 ///@{
48
49 ///@}
50 ///@name felisce Classes
51 ///@{
52 class BoundaryCondition
53 {
54 public:
55 ///@name Type Definitions
56 ///@{
57
58 /// Pointer definition of Point
59 FELISCE_CLASS_POINTER_DEFINITION(BoundaryCondition);
60
61 /// Function definition
62 typedef double (* BoundaryConditionfunction_pointer)(double x, double y, double z, double t);
63
64 /// The element type definition
65 typedef GeometricMeshRegion::ElementType ElementType;
66
67 ///@}
68 ///@name Life Cycle
69 ///@{
70
71 /// Default constructor
72 BoundaryCondition(
73 const TypeOfBoundaryCondition& typeBoundaryCondition,
74 const TypeValueOfBoundaryCondition& typeValueBoundaryCondition,
75 const int label,
76 const Variable& variable,
77 const Component& component
78 );
79
80 /// Constructor name label
81 BoundaryCondition(
82 const TypeOfBoundaryCondition& typeBoundaryCondition,
83 const TypeValueOfBoundaryCondition& typeValueBoundaryCondition,
84 const std::string& nameLabel,
85 const Variable& variable,
86 const Component& component
87 );
88
89 /// Constructor label
90 BoundaryCondition(
91 const std::string& typeBoundaryCondition,
92 const std::string& typeValueBoundaryCondition,
93 const int label,
94 const Variable& variable,
95 const std::string& component
96 );
97
98 /// Constructor label vector
99 BoundaryCondition(
100 const std::string& typeBoundaryCondition,
101 const std::string& typeValueBoundaryCondition,
102 const std::vector<int>& label,
103 const Variable& variable,
104 const std::string& component
105 );
106
107 /// Constructor with name label
108 BoundaryCondition(
109 const std::string& typeBoundaryCondition,
110 const std::string& typeValueBoundaryCondition,
111 const std::string& nameLabel,
112 const Variable& variable,
113 const std::string& component
114 );
115
116 /// default destructor
117 1198 ~BoundaryCondition() = default;
118
119 ///@}
120 ///@name Operators
121 ///@{
122
123 ///@}
124 ///@name Operations
125 ///@{
126
127 void determineComponent();
128
129 static int determineNumComponent(const std::string& cp);
130
131 void initMap();
132
133 /**
134 * @brief Set the value for constant (in time AND space) BC.
135 * @param[in] value The array with the constant value for each component of the BC
136 */
137 void setValue(const std::vector<double>& value);
138
139 template <class FunctorXYZ>
140 void setValue(LinearProblem* linearProblem, const FunctorXYZ& functorXYZ);
141
142 template <class FunctorXYZ>
143 void setValueVec(LinearProblem* linearProblem, const FunctorXYZ& functorXYZ);
144
145 template <class FunctorXYZ>
146 void setValueVec(LinearProblem* linearProblem, const FunctorXYZ& functorXYZ, double param);
147
148 template <class FunctorXYZT>
149 void setValue(LinearProblem* linearProblem, const FunctorXYZT& functorXYZT, double t);
150
151 template <class FunctorT>
152 void setValueT(LinearProblem* linearProblem, const FunctorT& functorT, double t);
153
154 1150 void setUnknown(const int iUnknown) {
155 1150 m_idUnknown = iUnknown;
156 1150 }
157
158 ///@}
159 ///@name Access
160 ///@{
161
162 1198 inline const TypeOfBoundaryCondition& typeBC() const {
163 1198 return m_typeBC;
164 }
165
166 16049 inline const TypeValueOfBoundaryCondition& typeValueBC() const {
167 16049 return m_typeValueBC;
168 }
169
170 773926 inline const Variable& getVariable() const {
171 773926 return m_variable;
172 }
173
174 53912 inline const int& getUnknown() const {
175 53912 return m_idUnknown;
176 }
177
178 769962 inline int& getUnknown() {
179 769962 return m_idUnknown;
180 }
181
182 inline const std::string& nameLabel() const {
183 return m_nameLabel;
184 }
185
186 inline const std::unordered_set<int>& listLabel() const {
187 return m_listLabel;
188 }
189
190 6728179 inline std::unordered_set<int>& listLabel() {
191 6728179 return m_listLabel;
192 }
193
194 22284619 inline const std::set<int>& getComp() const {
195 22284619 return m_numComp;
196 }
197
198 1934533 inline const std::vector<double>& ValueBCInSupportDof() const {
199 1934533 return m_valueBCInSupportDof;
200 }
201
202 493042 inline std::vector<double>& ValueBCInSupportDof() {
203 493042 return m_valueBCInSupportDof;
204 }
205
206 16996424 inline const std::vector< std::pair<felInt,felInt> >& idEltAndIdSupport() const {
207 16996424 return m_idEltAndIdSupport;
208 }
209 1086525 inline std::vector< std::pair<felInt,felInt> >& idEltAndIdSupport() {
210 1086525 return m_idEltAndIdSupport;
211 }
212
213 ///@}
214 ///@name Inquiry
215 ///@{
216
217 ///@}
218 ///@name Input and output
219 ///@{
220
221 void print(int verbose = 0, std::ostream& outstr = std::cout) const;
222
223 ///@}
224 ///@name Friends
225 ///@{
226
227 ///@}
228 ///@name Member Variables
229 ///@{
230
231 std::unordered_map<std::string, TypeOfBoundaryCondition > nameTypeBCToEnumTypeBC; /// The name type to enum
232 std::unordered_map<std::string, TypeValueOfBoundaryCondition > nameValueTypeBCToEnumValueTypeBC; /// Value type to enum
233 std::unordered_map<std::string, Component > nameComponentBCToEnumComponentBC; /// Name component type to enum
234
235 ///@}
236 protected:
237 ///@name Protected static Member Variables
238 ///@{
239
240 ///@}
241 ///@name Protected member Variables
242 ///@{
243
244 ///@}
245 ///@name Protected Operators
246 ///@{
247
248 ///@}
249 ///@name Protected Operations
250 ///@{
251
252 ///@}
253 ///@name Protected Access
254 ///@{
255
256 ///@}
257 ///@name Protected Inquiry
258 ///@{
259
260 ///@}
261 ///@name Protected LifeCycle
262 ///@{
263
264 ///@}
265 private:
266 ///@name Private static Member Variables
267 ///@{
268
269 ///@}
270 ///@name Private member Variables
271 ///@{
272
273 TypeOfBoundaryCondition m_typeBC; /// Dirichlet, Neumann, NeumannNormal, Robin, RobinNormal, EmbedFSI, EssentialLumpedModelBC, NaturalLumpedModelBC, BackflowStab
274 TypeValueOfBoundaryCondition m_typeValueBC; /// Constant, Vector, FunctionS, FunctionT, FunctionTS, EnsightFile
275 std::unordered_set<int> m_listLabel; /// List of labels
276 std::string m_nameLabel; /// Label name
277 Variable m_variable; /// Variable concern by this BoundaryCondition
278 int m_idUnknown; /// Id of the unknown concern by the variable
279 Component m_component; /// Component
280 std::set<int> m_numComp; /// List of components concern for this variable
281 std::vector<std::pair<felInt,felInt>> m_idEltAndIdSupport; /// Support list
282 std::vector<double> m_valueBCInSupportDof; /// Value in support DoF
283 };
284 ///@}
285 ///@name Type Definitions
286 ///@{
287
288 template <class FunctorXYZ>
289 void BoundaryCondition::setValue(LinearProblem* linearProblem, const FunctorXYZ& functorXYZ) {
290 FEL_CHECK(m_typeValueBC == FunctionS, "Error: the type of this BC should be a FunctionS")
291 Point pt;
292 m_valueBCInSupportDof.resize(m_idEltAndIdSupport.size(), 0.);
293 for (std::size_t iSupportDofBC = 0; iSupportDofBC < m_idEltAndIdSupport.size(); iSupportDofBC++) {
294 linearProblem->getSupportCoordinate(m_idEltAndIdSupport[iSupportDofBC].first,
295 m_idEltAndIdSupport[iSupportDofBC].second,
296 m_idUnknown, pt);
297 m_valueBCInSupportDof[iSupportDofBC] = functorXYZ(pt.x(), pt.y(), pt.z());
298 }
299 }
300
301 /***********************************************************************************/
302 /***********************************************************************************/
303
304 template <class FunctorXYZ>
305 168 void BoundaryCondition::setValueVec(LinearProblem* linearProblem, const FunctorXYZ& functorXYZ) {
306
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 136 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
168 FEL_CHECK(m_typeValueBC == FunctionS, "Error: the type of this BC should be a FunctionS")
307 Point pt;
308 168 m_valueBCInSupportDof.clear();
309
2/2
✓ Branch 1 taken 776 times.
✓ Branch 2 taken 136 times.
1216 for (std::size_t iSupportDofBC = 0; iSupportDofBC < m_idEltAndIdSupport.size(); iSupportDofBC++) {
310
1/2
✓ Branch 2 taken 776 times.
✗ Branch 3 not taken.
1048 linearProblem->getSupportCoordinate(m_idEltAndIdSupport[iSupportDofBC].first,
311 1048 m_idEltAndIdSupport[iSupportDofBC].second,
312 m_idUnknown, pt);
313
2/2
✓ Branch 3 taken 2280 times.
✓ Branch 4 taken 776 times.
4096 for(auto it_comp = m_numComp.begin(); it_comp != m_numComp.end(); it_comp++) {
314
2/4
✓ Branch 5 taken 2280 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2280 times.
✗ Branch 9 not taken.
3048 m_valueBCInSupportDof.push_back(functorXYZ(*it_comp,pt.x(), pt.y(), pt.z()));
315 }
316 }
317 168 }
318
319 /***********************************************************************************/
320 /***********************************************************************************/
321
322 template <class FunctorXYZ>
323 210 void BoundaryCondition::setValueVec(LinearProblem* linearProblem, const FunctorXYZ& functorXYZ, double param) {
324 // If one uses param as the time, this template can be use as a setValueVec for FunctorXYZT aswell
325
2/10
✓ Branch 0 taken 210 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 210 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
210 FEL_CHECK(m_typeValueBC == FunctionS || m_typeValueBC == FunctionTS , "Error: the type of this BC should be a FunctionS or a FunctionTS")
326 Point pt;
327 210 m_valueBCInSupportDof.clear();
328
2/2
✓ Branch 1 taken 5847 times.
✓ Branch 2 taken 210 times.
6057 for (std::size_t iSupportDofBC = 0; iSupportDofBC < m_idEltAndIdSupport.size(); iSupportDofBC++) {
329
1/2
✓ Branch 2 taken 5847 times.
✗ Branch 3 not taken.
5847 linearProblem->getSupportCoordinate(m_idEltAndIdSupport[iSupportDofBC].first,
330 5847 m_idEltAndIdSupport[iSupportDofBC].second,
331 m_idUnknown, pt);
332
2/2
✓ Branch 3 taken 14829 times.
✓ Branch 4 taken 5847 times.
20676 for(auto it_comp = m_numComp.begin(); it_comp != m_numComp.end(); it_comp++) {
333
1/2
✓ Branch 6 taken 14829 times.
✗ Branch 7 not taken.
14829 m_valueBCInSupportDof.push_back(functorXYZ(*it_comp,pt.x(), pt.y(), pt.z(), param));
334 }
335 }
336 210 }
337
338 /***********************************************************************************/
339 /***********************************************************************************/
340
341 template <class FunctorXYZT>
342 6172 void BoundaryCondition::setValue(LinearProblem* linearProblem, const FunctorXYZT& functorXYZT, double t) {
343
2/10
✓ Branch 0 taken 3838 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3838 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
6172 FEL_CHECK(m_typeValueBC == FunctionS || m_typeValueBC == FunctionTS , "Error: the type of this BC should be a FunctionS or a FunctionTS")
344 Point pt;
345
1/2
✓ Branch 2 taken 3838 times.
✗ Branch 3 not taken.
6172 m_valueBCInSupportDof.resize(m_idEltAndIdSupport.size(), 0.);
346
2/2
✓ Branch 1 taken 2278436 times.
✓ Branch 2 taken 3838 times.
4505008 for (std::size_t iSupportDofBC = 0; iSupportDofBC < m_idEltAndIdSupport.size(); iSupportDofBC++) {
347
1/2
✓ Branch 2 taken 2278436 times.
✗ Branch 3 not taken.
4498836 linearProblem->getSupportCoordinate(m_idEltAndIdSupport[iSupportDofBC].first,
348 4498836 m_idEltAndIdSupport[iSupportDofBC].second,
349 m_idUnknown, pt);
350 4498836 m_valueBCInSupportDof[iSupportDofBC] = functorXYZT(pt.x(), pt.y(), pt.z(), t);
351 }
352 6172 }
353
354 /***********************************************************************************/
355 /***********************************************************************************/
356
357 template <class FunctorT>
358 728 void BoundaryCondition::setValueT(LinearProblem* linearProblem, const FunctorT& functorT, double t) {
359 IGNORE_UNUSED_ARGUMENT(linearProblem);
360
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 364 times.
728 FEL_CHECK( m_typeValueBC == FunctionT , "Error: the type of this BC should be a FunctionT")
361 728 const double value = functorT(t) ;
362
1/2
✓ Branch 2 taken 364 times.
✗ Branch 3 not taken.
728 m_valueBCInSupportDof.resize(m_idEltAndIdSupport.size(), 0.);
363
2/2
✓ Branch 1 taken 7280 times.
✓ Branch 2 taken 364 times.
15288 for (std::size_t iSupportDofBC = 0; iSupportDofBC < m_idEltAndIdSupport.size(); iSupportDofBC++)
364 14560 m_valueBCInSupportDof[iSupportDofBC] = value ;
365 728 }
366
367 ///@}
368 } /* namespace felisce.*/
369
370 #endif
371