GCC Code Coverage Report


Directory: ./
File: Core/solidToMaster.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 61 101 60.4%
Branches: 42 128 32.8%

Line Branch Exec Source
1 #if defined(FELISCE_WITH_PVM) || defined(FELISCE_WITH_ZEROMQ)
2 #include <Core/solidToMaster.hpp>
3 #include <cstdlib>
4
5 namespace felisce {
6
7 #ifdef FELISCE_WITH_PVM
8 #ifdef FELISCE_WITH_ZEROMQ
9 #error PVM and ZMQ cannot be combined.Please select one
10 #endif
11 #endif
12
13 #ifdef FELISCE_WITH_PVM
14 6 SolidToMaster::SolidToMaster(int fsiStatus, int nbinter, int nbcoor, Vector& lumpM, Vector& dispS, Vector& veloS, Vector& forceF, Vector& forceC)
15 #endif
16 #ifdef FELISCE_WITH_ZEROMQ
17 SolidToMaster::SolidToMaster(int fsiStatus, int nbinter, int nbcoor, Vector& lumpM, Vector& dispS, Vector& veloS, Vector& forceF, Vector& forceC, std::string socketTransport,std::string socketAddress,std::string socketPort)
18 #endif
19 6 :m_nbInter(nbinter),
20 6 m_nbCoor(nbcoor),
21 #ifdef FELISCE_WITH_PVM
22 6 m_masterID(0),
23 #endif
24 #ifdef FELISCE_WITH_ZEROMQ
25 m_socketTransport(socketTransport),
26 m_socketAddress(socketAddress),
27 m_socketPort(socketPort),
28 m_zmq_context(1),
29 m_socket(m_zmq_context, ZMQ_PAIR),
30 #endif
31 6 m_fsiStatus(fsiStatus),
32 6 m_lumpM(lumpM),
33 6 m_dispS(dispS),
34 6 m_veloS(veloS),
35 6 m_forceF(forceF),
36 6 m_forceC(forceC),
37 6 m_dt(0.0)
38 {
39
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 m_vec1_master.resize(3*nbinter);
40
1/2
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
6 m_vec2_master.resize(3*nbinter);
41
2/2
✓ Branch 0 taken 7740 times.
✓ Branch 1 taken 6 times.
7746 for(int i=0; i< 3*nbinter; ++i) {
42 7740 m_vec1_master[i] = 0.;
43 7740 m_vec2_master[i] = 0.;
44 }
45 6 m_hasEnergy = false;
46
47 6 }
48
49
50
51
52 3 void SolidToMaster::setMaster() {
53 #ifdef FELISCE_WITH_PVM
54 3 m_masterID = pvm_parent();
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if( m_masterID == PvmNoParent )
56 {
57 std::cout << " I am a poor lonesome job\n ";
58 exit(1);
59 }
60
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 else if( m_masterID == 0 )
61 {
62 std::cout << "PVM is not ok\n";
63 exit(1);
64 }
65
66 3 std::cout <<"%%%%%%%%%%% \n";
67 3 std::cout << " I am the slave " << pvm_mytid()<< std::endl;
68 3 std::cout << " My master is " << m_masterID << std::endl;
69 #endif
70 #ifdef FELISCE_WITH_ZEROMQ
71 std::string socket_endpoint;
72 if(m_socketPort != "")
73 socket_endpoint = m_socketTransport + "://" + m_socketAddress + ":" + m_socketPort;
74 else
75 socket_endpoint = m_socketTransport + "://" + m_socketAddress;
76
77 std::cout << "[ZeroMQ] Connect to " << socket_endpoint << std::endl;
78 if ( zmq_connect(m_socket,socket_endpoint.c_str()) != 0 ) {
79 std::cout << "Problem while connecting to : " << socket_endpoint << std::endl;
80 exit(1);
81 }
82 #endif
83 3 }
84
85
86 void SolidToMaster::setEnergy(double& energy) {
87 m_energy = &energy;
88 m_hasEnergy = true;
89 }
90
91 545 void SolidToMaster::sdToMasterFSI(int msg) {
92 545 int nbDOF = 3*m_nbInter;
93
94
3/6
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 545 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 545 times.
✗ Branch 8 not taken.
545 std::cout << "---> Solid sends data to Master message " << msg << "... ";
95
96 #ifdef FELISCE_WITH_PVM
97
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 545 times.
545 if (msg == 99 ) {
98 int lumpMdim, thickStruct;
99 lumpMdim = nbDOF;
100 thickStruct = 0;
101
102 pvm_initsend(PvmDataDefault);
103 pvm_pkint(&thickStruct,1,1);
104 pvm_pkint(&lumpMdim,1,1);
105
106 for(int i=0; i<m_nbInter; ++i)
107 for(int j=0; j<m_nbCoor; ++j)
108 m_vec1_master[3*i+j] = m_lumpM[m_nbCoor*i+j];
109 pvm_pkdouble(m_vec1_master.data(),lumpMdim,1);
110
111 pvm_pkint(&nbDOF,1,1);
112
113 for(int i=0; i<m_nbInter; ++i)
114 for(int j=0; j<m_nbCoor; ++j) {
115 m_vec1_master[3*i+j] = m_dispS[m_nbCoor*i+j];
116 m_vec2_master[3*i+j] = m_veloS[m_nbCoor*i+j];
117 }
118 pvm_pkdouble(m_vec1_master.data(),nbDOF,1);
119 pvm_pkdouble(m_vec2_master.data(),nbDOF,1);
120 pvm_send(m_masterID,100);
121 }
122
1/2
✓ Branch 0 taken 545 times.
✗ Branch 1 not taken.
545 if (msg == 100 ) {
123
1/2
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
545 pvm_initsend(PvmDataDefault);
124
1/2
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
545 pvm_pkint(&nbDOF,1,1);
125
2/2
✓ Branch 0 taken 64177 times.
✓ Branch 1 taken 545 times.
64722 for(int i=0; i<m_nbInter; ++i)
126
2/2
✓ Branch 0 taken 146722 times.
✓ Branch 1 taken 64177 times.
210899 for(int j=0; j<m_nbCoor; ++j) {
127 146722 m_vec1_master[3*i+j] = m_dispS[m_nbCoor*i+j];
128 146722 m_vec2_master[3*i+j] = m_veloS[m_nbCoor*i+j];
129 }
130
1/2
✓ Branch 2 taken 545 times.
✗ Branch 3 not taken.
545 pvm_pkdouble(m_vec1_master.data(),nbDOF,1);
131
1/2
✓ Branch 2 taken 545 times.
✗ Branch 3 not taken.
545 pvm_pkdouble(m_vec2_master.data(),nbDOF,1);
132
1/2
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
545 pvm_send(m_masterID,100);
133 }
134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 545 times.
545 if (msg == 1100 ) {
135 pvm_initsend(PvmDataDefault);
136 pvm_pkint(&nbDOF,1,1);
137 for(int i=0; i<m_nbInter; ++i)
138 for(int j=0; j<m_nbCoor; ++j) {
139 m_vec1_master[3*i+j] = m_dispS[m_nbCoor*i+j];
140 m_vec2_master[3*i+j] = m_veloS[m_nbCoor*i+j];
141 }
142 pvm_pkdouble(m_vec1_master.data(),nbDOF,1);
143 pvm_pkdouble(m_vec2_master.data(),nbDOF,1);
144 pvm_pkdouble(m_energy,1,1);
145 pvm_send(m_masterID,1100);
146 }
147 #endif
148 #ifdef FELISCE_WITH_ZEROMQ
149 if (msg == 99 ) {
150 int lumpMdim, thickStruct;
151 lumpMdim = nbDOF;
152 thickStruct = 0;
153 //
154 zmq::message_t msg1(1*sizeof(int));
155 memcpy(msg1.data(),&thickStruct,1*sizeof(int));
156 m_socket.send(msg1,zmq::send_flags::none);
157 //
158 zmq::message_t msg2(1*sizeof(int));
159 memcpy(msg2.data(),&lumpMdim,1*sizeof(int));
160 m_socket.send(msg2,zmq::send_flags::none);
161 //
162 for(int i=0; i<m_nbInter; ++i)
163 for(int j=0; j<m_nbCoor; ++j)
164 m_vec1_master[3*i+j] = m_lumpM[m_nbCoor*i+j];
165 //
166 zmq::message_t msg3(lumpMdim*sizeof(double));
167 memcpy(msg3.data(),m_vec1_master.data(),lumpMdim*sizeof(double));
168 m_socket.send(msg3,zmq::send_flags::none);
169 //
170 zmq::message_t msg4(1*sizeof(int));
171 memcpy(msg4.data(),&nbDOF,1*sizeof(int));
172 m_socket.send(msg4,zmq::send_flags::none);
173 //
174 for(int i=0; i<m_nbInter; ++i)
175 for(int j=0; j<m_nbCoor; ++j) {
176 m_vec1_master[3*i+j] = m_dispS[m_nbCoor*i+j];
177 m_vec2_master[3*i+j] = m_veloS[m_nbCoor*i+j];
178 }
179 zmq::message_t msg5;
180 recvZEROMQ_default(msg5, m_vec1_master.data(), nbDOF*sizeof(double));
181 // zmq::recv_result_t recvResult5 = m_socket.recv(msg5,zmq::recv_flags::none);
182 // FEL_ASSERT( recvResult5 == nbDOF*sizeof(double) );
183 // memcpy(m_vec1_master.data(),msg5.data(),nbDOF*sizeof(double));
184 //
185 zmq::message_t msg6;
186 recvZEROMQ_default(msg6, m_vec2_master.data(), nbDOF*sizeof(double));
187 // zmq::recv_result_t recvResult6 = m_socket.recv(msg6,zmq::recv_flags::none);
188 // FEL_ASSERT( recvResult6 == nbDOF*sizeof(double) );
189 // memcpy(m_vec2_master.data(),msg6.data(),nbDOF*sizeof(double));
190 //
191 }
192 if (msg == 100 ) {
193 zmq::message_t msg1(1*sizeof(int));
194 memcpy(msg1.data(),&nbDOF,1*sizeof(int));
195 m_socket.send(msg1,zmq::send_flags::none);
196 for(int i=0; i<m_nbInter; ++i)
197 for(int j=0; j<m_nbCoor; ++j) {
198 m_vec1_master[3*i+j] = m_dispS[m_nbCoor*i+j];
199 m_vec2_master[3*i+j] = m_veloS[m_nbCoor*i+j];
200 }
201 zmq::message_t msg2(nbDOF*sizeof(double));
202 memcpy(msg2.data(),m_vec1_master.data(),nbDOF*sizeof(double));
203 m_socket.send(msg2,zmq::send_flags::none);
204
205 zmq::message_t msg3(nbDOF*sizeof(double));
206 memcpy(msg3.data(),m_vec2_master.data(),nbDOF*sizeof(double));
207 m_socket.send(msg3,zmq::send_flags::none);
208 }
209 #endif
210
1/2
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
545 std::cout << " done.\n";
211 545 }
212
213 545 void SolidToMaster::rvFromMasterFSI(int msg) {
214
215
3/6
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 545 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 545 times.
✗ Branch 8 not taken.
545 std::cout << "Solid Receives Message " << msg << std::endl;
216 int dim;
217
218 #ifdef FELISCE_WITH_PVM
219
1/2
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
545 pvm_recv(m_masterID,130);
220
1/2
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
545 pvm_upkint(&m_fsiStatus,1,1);
221
3/6
✓ Branch 1 taken 545 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 545 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 545 times.
✗ Branch 8 not taken.
545 std::cout << "-----> fsiStatus = " << m_fsiStatus << std::endl;
222
223
2/2
✓ Branch 0 taken 542 times.
✓ Branch 1 taken 3 times.
545 if(m_fsiStatus != -1)
224 {
225
1/2
✓ Branch 1 taken 542 times.
✗ Branch 2 not taken.
542 pvm_upkdouble(&m_dt,1,1);
226
1/2
✓ Branch 1 taken 542 times.
✗ Branch 2 not taken.
542 pvm_upkint(&dim,1,1);
227
228
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 542 times.
542 if(dim != 3* m_nbInter)
229 std::cout << "rv: dim = " << dim << ", 3 * m_nbIner = " << 3 * m_nbInter << std::endl;
230
231
1/2
✓ Branch 2 taken 542 times.
✗ Branch 3 not taken.
542 pvm_upkdouble(m_vec1_master.data(),3*m_nbInter,1);
232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 542 times.
542 if ( msg == 1100 )
233 pvm_upkdouble(m_vec2_master.data(),3*m_nbInter,1);
234
235
2/2
✓ Branch 0 taken 62887 times.
✓ Branch 1 taken 542 times.
63429 for(int i=0; i<m_nbInter; ++i)
236
2/2
✓ Branch 0 taken 142994 times.
✓ Branch 1 taken 62887 times.
205881 for(int j=0; j<m_nbCoor; ++j)
237 142994 m_forceF[m_nbCoor*i+j] = m_vec1_master[3*i+j];
238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 542 times.
542 if ( msg == 1100 )
239 for(int i=0; i<m_nbInter; ++i)
240 for(int j=0; j<m_nbCoor; ++j)
241 m_forceC[m_nbCoor*i+j] = m_vec2_master[3*i+j];
242
243 }
244 #endif
245 #ifdef FELISCE_WITH_ZEROMQ
246 zmq::message_t msg1;
247 recvZEROMQ_default(msg1, &m_fsiStatus, 1*sizeof(int));
248 // zmq::recv_result_t recvResult1 = m_socket.recv(msg1,zmq::recv_flags::none);
249 // FEL_ASSERT( recvResult1 == sizeof(int) );
250 // memcpy(&m_fsiStatus,msg1.data(),1*sizeof(int));
251 std::cout << "-----> fsiStatus = " << m_fsiStatus << std::endl;
252
253 if(m_fsiStatus != -1){
254 zmq::message_t msg2;
255 recvZEROMQ_default(msg2, &m_dt, 1*sizeof(double));
256 // zmq::recv_result_t recvResult2 = m_socket.recv(msg2,zmq::recv_flags::none);
257 // FEL_ASSERT( recvResult2 == sizeof(double) );
258 // memcpy(&m_dt,msg2.data(),1*sizeof(double));
259 //
260 zmq::message_t msg3;
261 recvZEROMQ_default(msg3, &dim, 1*sizeof(int));
262 // zmq::recv_result_t recvResult3 = m_socket.recv(msg3,zmq::recv_flags::none);
263 // FEL_ASSERT( recvResult3 == sizeof(int) );
264 // memcpy(&dim,msg3.data(),1*sizeof(int));
265 //
266 if(dim != 3*m_nbInter)
267 std::cout << "rv: dim = " << dim << ", 3 * m_nbIner = " << 3 * m_nbInter << std::endl;
268 //
269 zmq::message_t msg4;
270 recvZEROMQ_default(msg4, m_vec1_master.data(), 3*m_nbInter*sizeof(double));
271 // zmq::recv_result_t recvResult4 = m_socket.recv(msg4,zmq::recv_flags::none);
272 // FEL_ASSERT( recvResult4 == 3*m_nbInter*sizeof(double) );
273 // memcpy(m_vec1_master.data(),msg4.data(),3*m_nbInter*sizeof(double));
274 //
275 for(int i=0; i<m_nbInter; ++i)
276 for(int j=0; j<m_nbCoor; ++j)
277 m_forceF[m_nbCoor*i+j] = m_vec1_master[3*i+j];
278 }
279 #endif
280 545 }
281
282 545 double SolidToMaster::timeStep() const {return m_dt;}
283
284 int SolidToMaster::hasLumpedMass() const {return m_hasLumpedMass;}
285
286 545 int SolidToMaster::status() const {return m_fsiStatus;}
287
288 #ifdef FELISCE_WITH_ZEROMQ
289 void SolidToMaster::recvZEROMQ_default(zmq::message_t &msg, void * data, std::size_t sizeData)
290 {
291 // default correspond to used the flags zmq::recv_flags::none
292 zmq::recv_result_t recvResult = m_socket.recv( msg, zmq::recv_flags::none);
293 memcpy( data, msg.data(),sizeData);
294 if( recvResult != sizeData){
295 FEL_ASSERT( recvResult == sizeData );
296 }
297 }
298 #endif
299
300 }
301 #endif
302