GCC Code Coverage Report


Directory: ./
File: Solver/lumpedModelBC.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 65 113 57.5%
Branches: 65 160 40.6%

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-F. Gerbeau
13 //
14
15 // System includes
16
17 // External includes
18
19 // Project includes
20 #include "Core/felisceTools.hpp"
21 #include "Solver/lumpedModelBC.hpp"
22
23 namespace felisce {
24
25 20 LumpedModelBC::LumpedModelBC(FelisceTransient::Pointer fstransient):
26 20 m_fstransient(fstransient)
27 {
28
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_size = FelisceParam::instance().lumpedModelBCLabel.size();
29
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_Rd.resize(m_size);
30
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_Rp.resize(m_size);
31
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_C.resize(m_size);
32
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_Pv.resize(m_size);
33
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_Pd0.resize(m_size);
34
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_Q.resize(m_size);
35
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_Pd.resize(m_size);
36
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_PdOld.resize(m_size);
37
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_Pp.resize(m_size);
38
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_PpOld.resize(m_size);
39
1/2
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
20 m_name.resize(m_size);
40
41
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 20 times.
60 for(std::size_t i=0; i<m_size; i++) {
42
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 m_Rp[i] = FelisceParam::instance().lumpedModelBC_Rprox[i];
43
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 m_C[i] = FelisceParam::instance().lumpedModelBC_C[i];
44
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 m_Pv[i] = FelisceParam::instance().lumpedModelBC_Pvenous[i];
45
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 m_Pd0[i] = FelisceParam::instance().lumpedModelBC_Pdist_init[i];
46 40 m_Q[i] = 0.;
47 40 m_Pd[i] = m_Pd0[i];
48 40 m_PdOld[i] = 0.;
49 40 m_Pp[i] = m_Pd0[i];
50
2/5
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
40 switch ( FelisceParam::instance().lumpedModelBCType[i] ) {
51 40 case 1: // RCR
52
1/2
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
40 m_Rd[i] = FelisceParam::instance().lumpedModelBC_Rdist[i];
53 40 break;
54 case 2: // RC
55 if ( Tools::notEqual(FelisceParam::instance().lumpedModelBC_Rdist[i],0.) )
56 FEL_WARNING("RC lumpedModelBC bc used but Rd is not equal to 0 for all the outlet\n");
57 break;
58 }
59
2/4
✓ Branch 1 taken 40 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 40 times.
✗ Branch 7 not taken.
40 m_name[i] = FelisceParam::instance().lumpedModelBCName[i];
60 }
61
62
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 20 times.
20 if ( FelisceParam::instance().lumpedModelBC_C_type == 2 ) { // non linear compliance : C=C(V)
63 m_volume_n_1 = FelisceParam::instance().lumpedModelBC_volume0 ;
64 m_volumeMax = FelisceParam::instance().lumpedModelBC_volumeMax ;
65 m_volumeMin = FelisceParam::instance().lumpedModelBC_volumeMin ;
66 m_volume0 = FelisceParam::instance().lumpedModelBC_volume0 ;
67 m_volume0ref = FelisceParam::instance().lumpedModelBC_referenceVolume0 ;
68 m_powerNonLinearCompliance = FelisceParam::instance().powerNonLinearCompliance ;
69 }
70 20 }
71
72
73
74 284 void LumpedModelBC::iterate() {
75 //
76 // update the m_Q[i] before
77 //
78 284 double dt = m_fstransient->timeStep;
79 double tau;
80
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 284 times.
284 if ( FelisceParam::instance().lumpedModelBC_C_type == 2 ) { // non linear compliance : C=C(V)
81 for( std::size_t idBCwindk=0 ; idBCwindk<m_size ; idBCwindk++ ) {
82 m_C[idBCwindk] = computeNonLinearCompliance(idBCwindk);
83 }
84 }
85
86
2/2
✓ Branch 0 taken 568 times.
✓ Branch 1 taken 284 times.
852 for(std::size_t i=0; i<m_size; i++) {
87 568 m_PdOld[i] = m_Pd[i];
88 568 m_PpOld[i] = m_Pp[i];
89
1/3
✓ Branch 2 taken 568 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
568 switch ( FelisceParam::instance().lumpedModelBCType[i] ) {
90 568 case 1: // RCR
91 568 tau = m_Rd[i]*m_C[i];
92 568 m_Pd[i]= ((tau/dt) * m_PdOld[i] + ( m_Pv[i] + m_Rd[i] * m_Q[i]) ) / (1+tau/dt);
93 568 break;
94 case 2: // RC
95 m_Pd[i]= m_PdOld[i] + (dt/m_C[i]) * m_Q[i] ;
96 break;
97 }
98 568 m_Pp[i] = m_Pd[i] + m_Rp[i]*m_Q[i];
99 }
100 284 }
101
102 void LumpedModelBC::print(int verbose,std::ostream& c) const {
103 IGNORE_UNUSED_VERBOSE;
104 for(std::size_t i=0; i<m_size; i++) {
105 c << "LumpedModelBC " << i << std::endl;
106 c << " Type lumpedModelBC = " ;
107 switch ( FelisceParam::instance().lumpedModelBCType[i] ) {
108 case 1: // RCR
109 c << "RCR or R" << std::endl;
110 break;
111 case 2: // RC
112 c << "RC" << std::endl;
113 break;
114 }
115 c << " Algo lumpedModelBC = " ;
116 switch ( FelisceParam::instance().lumpedModelBCAlgo[i]) {
117 case 1:
118 c << "explicit" << std::endl;
119 break;
120 case 2:
121 c << "implicit" << std::endl;
122 break;
123 }
124
125 c << "LumpedModelBC " << i << std::endl;
126 c << " Rd = " << m_Rd[i] << std::endl;
127 c << " Rp = " << m_Rp[i] << std::endl;
128 c << " C = " << m_C[i] << std::endl;
129 c << " Pv = " << m_Pv[i] << std::endl;
130 c << " Pd0 = " << m_Pd0[i] << std::endl;
131 }
132
133 }
134
135 // non linear compliance
136 //======================
137
138 double LumpedModelBC::computeNonLinearCompliance(std::size_t& idBCwindk) {
139 m_volumeMaxTilde = 2*m_volume0ref - m_volumeMin;
140 m_volumeMinTilde = 2*m_volume0ref - m_volumeMax;
141 if ( ( m_volumeMin <= m_volume_n_1 ) && ( m_volume_n_1 <= m_volume0ref ) ) {
142 return FelisceParam::instance().lumpedModelBC_C[idBCwindk] * std::pow( ((m_volumeMaxTilde - m_volume_n_1 )*( m_volume_n_1 - m_volumeMin )) / ( ( m_volumeMaxTilde - m_volume0ref )*( m_volume0ref - m_volumeMin ) ) ,m_powerNonLinearCompliance);
143 } else if ( (m_volumeMax > m_volume_n_1) && (m_volume_n_1 > m_volume0ref) ) {
144 return FelisceParam::instance().lumpedModelBC_C[idBCwindk] * std::pow( ((m_volumeMax - m_volume_n_1 )* (m_volume_n_1 - m_volumeMinTilde )) / ( ( m_volumeMax - m_volume0ref )*( m_volume0ref - m_volumeMinTilde ) ) , m_powerNonLinearCompliance);
145 } else {
146 return 0.;
147 }
148 }
149
150 50 void LumpedModelBC::write(std::string filename) const {
151 static int init = 1;
152
4/8
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 50 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 50 times.
✗ Branch 11 not taken.
50 std::cout << "Write lumped parameter model on '" << filename << "'"<< std::endl;
153
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 std::ofstream outputfile;
154
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 47 times.
50 if(init) {
155
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 outputfile.open((filename.c_str()));
156
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 outputfile << "# 1:time ";
157 3 int j=2;
158
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(std::size_t i=0; i<m_size; i++) {
159
4/8
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
6 outputfile << j << ":Q_" << m_name[i] << " ";
160 6 j++;
161
4/8
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
6 outputfile << j << ":Pp_" << m_name[i] << " ";
162 6 j++;
163
4/8
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 6 times.
✗ Branch 12 not taken.
6 outputfile << j << ":Pd_" << m_name[i] << " ";
164 6 j++;
165 }
166
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 outputfile << std::endl;
167 } else {
168
1/2
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
47 outputfile.open((filename.c_str()),std::ios::app);
169 }
170
2/4
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 50 times.
✗ Branch 6 not taken.
50 outputfile << m_fstransient->time << " ";
171
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 50 times.
150 for(std::size_t i=0; i<m_size; i++) {
172
6/12
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 100 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 100 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 100 times.
✗ Branch 13 not taken.
✓ Branch 16 taken 100 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 100 times.
✗ Branch 20 not taken.
100 outputfile << m_Q[i] << " " << m_Pp[i] << " " << m_Pd[i] << " ";
173 }
174
1/2
✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
50 outputfile << std::endl;
175 50 init = 0;
176 50 }
177 }
178
179