GCC Code Coverage Report


Directory: ./
File: DegreeOfFreedom/listVariable.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 28 37 75.7%
Branches: 22 32 68.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
13 //
14
15 // System includes
16
17 // External includes
18
19 // Project includes
20 #include "DegreeOfFreedom/listVariable.hpp"
21
22 namespace felisce {
23
24 1509 ListVariable::ListVariable()
25 = default;
26
27 889 void ListVariable::addVariable( const PhysicalVariable& variableName, std::size_t nComp, std::size_t instanceIndex) {
28
1/2
✓ Branch 1 taken 889 times.
✗ Branch 2 not taken.
889 Variable v;
29
1/2
✓ Branch 1 taken 889 times.
✗ Branch 2 not taken.
889 auto& r_instance = FelisceParam::instance(instanceIndex);
30
31 // number of variables = size of nameVariable vector.
32
2/2
✓ Branch 1 taken 1831 times.
✓ Branch 2 taken 889 times.
2720 for (std::size_t iVar = 0; iVar < r_instance.nameVariable.size(); iVar++ )
33
2/2
✓ Branch 1 taken 889 times.
✓ Branch 2 taken 942 times.
1831 if ( variableName == r_instance.physicalVariable[iVar] ) {
34
1/2
✓ Branch 1 taken 889 times.
✗ Branch 2 not taken.
889 v.initialize(iVar, instanceIndex);
35
1/2
✓ Branch 1 taken 889 times.
✗ Branch 2 not taken.
889 v.setNumComponent(nComp);
36
1/2
✓ Branch 2 taken 889 times.
✗ Branch 3 not taken.
889 v.setMeshId(r_instance.idMesh[iVar]);
37
1/2
✓ Branch 1 taken 889 times.
✗ Branch 2 not taken.
889 m_listVariable.push_back(v);
38
1/2
✓ Branch 1 taken 889 times.
✗ Branch 2 not taken.
889 m_listIdUnknownOfVariable.push_back(-1);
39 }
40 889 }
41
42
43 void ListVariable::addVariable( const Variable& var) {
44 m_listVariable.push_back(var);
45 }
46
47 //! Print function
48 262 void ListVariable::print(int verbose, std::ostream& outstr) const {
49
2/2
✓ Branch 0 taken 260 times.
✓ Branch 1 taken 2 times.
262 if (verbose > 0 ) {
50 260 outstr << "\n/======list of variables========/\n";
51
2/2
✓ Branch 1 taken 455 times.
✓ Branch 2 taken 260 times.
715 for ( unsigned int iVar = 0; iVar < m_listVariable.size(); iVar++)
52 455 m_listVariable[iVar].print(verbose,outstr);
53 260 outstr << std::endl;
54 }
55 262 }
56
57 /*!
58 \brief Find the position of one variable in the vector with its name.
59 Useful to generalize Felisce Library utilisation.
60 \param[in] variable Variable considered
61 */
62 813817 int ListVariable::getVariableIdList( PhysicalVariable variable ) const {
63
2/2
✓ Branch 1 taken 1193024 times.
✓ Branch 2 taken 144 times.
1193168 for ( unsigned int iVar = 0; iVar < m_listVariable.size(); iVar++)
64
2/2
✓ Branch 2 taken 813673 times.
✓ Branch 3 taken 379351 times.
1193024 if (m_listVariable[iVar].physicalVariable() == variable)
65 813673 return static_cast<int>(iVar);
66
67 144 return -1;
68 }
69
70 /*!
71 \brief Find the position of one variable in the vector with its std::string name.
72 Useful to generalize Felisce Library utilisation.
73 \param[in] nameVariable name of the variable research
74 */
75 1488 int ListVariable::getVariableIdList( std::string nameVariable ) const {
76
1/2
✓ Branch 1 taken 2319 times.
✗ Branch 2 not taken.
2319 for ( unsigned int iVar = 0; iVar < m_listVariable.size(); iVar++)
77
2/2
✓ Branch 5 taken 1488 times.
✓ Branch 6 taken 831 times.
2319 if ( !strcmp(m_listVariable[iVar].name().c_str(), nameVariable.c_str()))
78 1488 return static_cast<int>(iVar);
79
80 return -1;
81 }
82
83 /*!
84 \brief Find one variable in the vector with its name.
85 Useful to generalize Felisce Library utilisation.
86 \param[in] variable Variable considered
87 */
88 Variable* ListVariable::getVariable( PhysicalVariable variable ) {
89 int id = getVariableIdList(variable);
90 return &m_listVariable[id];
91 }
92
93 /*!
94 \brief Find one variable in the vector with its std::string name.
95 Useful to generalize Felisce Library utilisation.
96 \param[in] nameVariable name of the variable research
97 */
98 Variable* ListVariable::getVariable( std::string nameVariable ) {
99 int id = getVariableIdList(nameVariable);
100 return &m_listVariable[id];
101 }
102 }
103