GCC Code Coverage Report


Directory: ./
File: CommunicationInterfaces/M1gInterface.cpp
Date: 2024-04-14 07:32:34
Exec Total Coverage
Lines: 0 106 0.0%
Branches: 0 84 0.0%

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: D. C. Corti
13 //
14
15 /*!
16 \file M1gInterface.hpp
17 \authors D. C. Corti
18 \date 00/00/2022
19 \brief interface for M1G module in libXfm
20 */
21
22 // System includes
23
24 // External includes
25
26 // Project includes
27 #include "CommunicationInterfaces/M1gInterface.hpp"
28
29 namespace felisce {
30
31 M1gInterface::M1gInterface()
32 {
33 #ifdef FELISCE_WITH_LIBXFM
34
35 m_M1gData = nullptr;
36
37 m_iteration = 0;
38 m_dim = 3;
39
40 m_numVerMsh = 0;
41 m_numEltMsh = 0;
42
43 m_m1g = nullptr;
44
45 m_isM1GInit = false;
46 m_writeM1Gmeshes = false;
47
48 m_listVertices = nullptr;
49 m_listVerticesInitial = nullptr;
50 m_listElements = nullptr;
51
52 m_nbrVerMsh = 0;
53 m_crdMsh = nullptr;
54
55 m_nbrEltMsh = 0;
56 m_eltMsh = nullptr;
57
58 #endif
59 }
60
61 /***********************************************************************************/
62 /***********************************************************************************/
63
64 M1gInterface::~M1gInterface()
65 {
66 #ifdef FELISCE_WITH_LIBXFM
67
68 if(m_isM1GInit)
69 m_m1g = M1G_FreeLibrary(m_m1g);
70
71 if( MpiInfo::rankProc() != 0 ){
72
73 if(m_crdMsh != nullptr)
74 delete [] m_crdMsh;
75
76 if(m_eltMsh != nullptr)
77 delete [] m_eltMsh;
78 }
79
80 if(m_listVertices != nullptr)
81 delete [] m_listVertices;
82
83 if(m_listVerticesInitial != nullptr)
84 delete [] m_listVerticesInitial;
85
86 if(m_listElements != nullptr)
87 delete [] m_listElements;
88
89 #endif
90 }
91
92 /***********************************************************************************/
93 /***********************************************************************************/
94
95 void M1gInterface::initialize(const GeometricMeshRegion& mesh)
96 {
97 #ifdef FELISCE_WITH_LIBXFM
98
99 //- Only proc 0 can manage this library
100 if ( MpiInfo::rankProc() != 0 )
101 return;
102
103 if( m_isM1GInit )
104 FEL_ERROR("M1gInterface already initialized");
105
106
107 //--- Initialize interface
108 m_m1g = M1G_NewLibrary(m_dim, m_meshName.data(), m_M1gData->verbose, 0);
109 m_isM1GInit = true;
110
111
112 //--- Initialize mesh in M1G library: points and elements
113 const GeometricMeshRegion::ElementType eltType = GeometricMeshRegion::Seg2;
114 const int numPointsPerElt = GeometricMeshRegion::m_numPointsPerElt[eltType];
115
116 m_listVertices = new double3d[mesh.numPoints() + 1];
117 m_listVerticesInitial = new double3d[mesh.numPoints() + 1];
118 m_listElements = new int3d[mesh.numElements(eltType) + 1];
119
120 m_listVertices[0][0] = m_listVertices[0][1] = m_listVertices[0][2] = 0;
121 m_listVerticesInitial[0][0] = m_listVerticesInitial[0][1] = m_listVerticesInitial[0][2] = 0;
122 m_listElements[0][0] = m_listElements[0][1] = m_listElements[0][2] = 0;
123
124 // Copy points
125 auto& listPnt = mesh.listPoints();
126 m_numVerMsh = static_cast<int1d>(listPnt.size());
127 for (std::size_t iPnt = 0; iPnt < listPnt.size(); ++iPnt) {
128 for (std::size_t iCoor = 0; iCoor < 3; ++iCoor) {
129 m_listVertices[iPnt+1][iCoor] = listPnt[iPnt][iCoor];
130 m_listVerticesInitial[iPnt+1][iCoor] = listPnt[iPnt][iCoor];
131 }
132 }
133
134 // Copy elements
135 auto* listElt = mesh.listElements(eltType);
136 m_numEltMsh = static_cast<int1d>(mesh.numElements(eltType));
137 for (felInt iElt = 0; iElt < mesh.numElements(eltType); ++iElt) {
138 for (int iPnt = 0; iPnt < numPointsPerElt; ++iPnt) {
139 m_listElements[iElt+1][iPnt] = static_cast<int1d>(listElt[numPointsPerElt*iElt+iPnt] + 1);
140 }
141 m_listElements[iElt+1][numPointsPerElt] = static_cast<int1d>(0);
142 }
143
144 M1G_LibraryInitialization_Array_Mesh(m_m1g, m_numVerMsh, m_listVertices, m_numEltMsh, m_listElements);
145
146
147 //--- Set germs for triangles and for 123 algorithm
148 auto& triLst = m_M1gData->triLst;
149 auto& verLst = m_M1gData->verLst;
150 int1d tmp_nbrTri = static_cast<int1d>(triLst.size()/3);
151 int1d tmp_nbrVer = static_cast<int1d>(verLst.size());
152
153 std::vector<int1d> tmp_triLst(triLst.size());
154 std::transform(triLst.begin(),triLst.end(), tmp_triLst.begin(), [&](auto ive){ return static_cast<int1d>(ive); } );
155
156 std::vector<int1d> tmp_verLst(verLst.size());
157 std::transform(verLst.begin(),verLst.end(), tmp_verLst.begin(), [&](auto ive){ return static_cast<int1d>(ive); } );
158
159 M1G_LibrarySetGermVertices(m_m1g, tmp_nbrTri, tmp_triLst.data(), tmp_nbrVer, tmp_verLst.data());
160
161
162 //--- Set option writeM1Gmeshes
163 m_writeM1Gmeshes = m_M1gData->writeM1Gmeshes;
164
165 #else
166
167 IGNORE_UNUSED_ARGUMENT(mesh);
168 FEL_ERROR("You need to compile felisce with libXfm to use this function");
169
170 #endif
171 }
172
173 /***********************************************************************************/
174 /***********************************************************************************/
175
176 void M1gInterface::updateMeshPosition(const std::vector<double>& dispArray)
177 {
178 #ifdef FELISCE_WITH_LIBXFM
179
180 if (MpiInfo::rankProc() == 0){
181 for(int1d i = 1; i <= m_numVerMsh; ++i) {
182 for(std::size_t j = 0; j < 3; ++j)
183 m_listVertices[i][j] = m_listVerticesInitial[i][j] + dispArray[j + 3*(i-1)];
184 }
185
186 M1G_LibraryUpdateCoordinates(m_m1g, m_numVerMsh, m_listVertices);
187 }
188
189 #else
190
191 IGNORE_UNUSED_ARGUMENT(dispArray);
192 FEL_ERROR("You need to compile felisce with libXfm to use this function");
193
194 #endif
195 }
196
197 /***********************************************************************************/
198 /***********************************************************************************/
199
200 void M1gInterface::mesh123Gen()
201 {
202 #ifdef FELISCE_WITH_LIBXFM
203
204 if ( MpiInfo::rankProc() == 0 ) {
205
206 // Mesh hole
207 M1G_LibraryMesh123Generator(m_m1g);
208
209 // Get new mesh
210 M1G_LibraryReturnMeshData(m_m1g, &m_nbrVerMsh, &m_crdMsh, &m_nbrEltMsh, &m_eltMsh);
211
212 if ( m_writeM1Gmeshes ){
213 std::string name = m_M1gData->outdir+m_meshName+std::to_string(m_iteration);
214
215 M1G_LibraryWriteMesh(m_m1g, name.data());
216 }
217 }
218
219 MPI_Bcast(&m_nbrVerMsh, 1, MPI_INT, 0, MpiInfo::petscComm());
220 MPI_Bcast(&m_nbrEltMsh, 1, MPI_INT, 0, MpiInfo::petscComm());
221 if( MpiInfo::rankProc() != 0 ) {
222 m_crdMsh = (double3d*)realloc(m_crdMsh, sizeof(double3d)*(m_nbrVerMsh+1));
223 m_eltMsh = (int4d*) realloc(m_eltMsh, sizeof(int4d) *(m_nbrEltMsh+1));
224 }
225 MPI_Bcast(m_crdMsh, 3*(m_nbrVerMsh+1), MPI_DOUBLE, 0, MpiInfo::petscComm());
226 MPI_Bcast(m_eltMsh, 4*(m_nbrEltMsh+1), MPI_INT, 0, MpiInfo::petscComm());
227
228 #else
229
230 FEL_ERROR("You need to compile felisce with libXfm to use this function");
231
232 #endif
233 }
234
235 /***********************************************************************************/
236 /***********************************************************************************/
237
238 felInt M1gInterface::getNbrPoints() const
239 {
240 #ifdef FELISCE_WITH_LIBXFM
241
242 return static_cast<felInt>(m_nbrVerMsh);
243
244 #else
245
246 FEL_ERROR("You need to compile felisce with libXfm to use this function");
247 return static_cast<felInt>(1);
248
249 #endif
250 }
251
252 /***********************************************************************************/
253 /***********************************************************************************/
254
255 felInt M1gInterface::getNbrElements() const
256 {
257 #ifdef FELISCE_WITH_LIBXFM
258
259 return static_cast<felInt>(m_nbrEltMsh);
260
261 #else
262
263 FEL_ERROR("You need to compile felisce with libXfm to use this function");
264 return static_cast<felInt>(1);
265
266 #endif
267 }
268
269 /***********************************************************************************/
270 /***********************************************************************************/
271
272 void M1gInterface::getPointCrd(const felInt iPt, Point& point) const
273 {
274 #ifdef FELISCE_WITH_LIBXFM
275
276 for(std::size_t i = 0; i < 3; ++i)
277 point[i] = m_crdMsh[iPt+1][i];
278
279 #else
280
281 IGNORE_UNUSED_ARGUMENT(iPt);
282 IGNORE_UNUSED_ARGUMENT(point);
283 FEL_ERROR("You need to compile felisce with libXfm to use this function");
284
285 #endif
286 }
287
288 /***********************************************************************************/
289 /***********************************************************************************/
290
291 void M1gInterface::getElementPt(const felInt iEl, std::vector<felInt>& element) const
292 {
293 #ifdef FELISCE_WITH_LIBXFM
294
295 for(std::size_t i = 0; i < 3; ++i)
296 element[i] = static_cast<felInt>(m_eltMsh[iEl+1][i]-1);
297
298 #else
299
300 IGNORE_UNUSED_ARGUMENT(iEl);
301 IGNORE_UNUSED_ARGUMENT(element);
302 FEL_ERROR("You need to compile felisce with libXfm to use this function");
303
304 #endif
305 }
306
307 /***********************************************************************************/
308 /***********************************************************************************/
309
310 felInt M1gInterface::getElementTag(const felInt iEl) const
311 {
312 #ifdef FELISCE_WITH_LIBXFM
313
314 return static_cast<felInt>(m_eltMsh[iEl+1][3]);
315
316 #else
317
318 IGNORE_UNUSED_ARGUMENT(iEl);
319 FEL_ERROR("You need to compile felisce with libXfm to use this function");
320 return static_cast<felInt>(1);
321
322 #endif
323 }
324
325 /***********************************************************************************/
326 /***********************************************************************************/
327
328 void M1gInterface::setMeshName(const std::string name)
329 {
330 #ifdef FELISCE_WITH_LIBXFM
331
332 m_meshName = name;
333
334 #else
335
336 IGNORE_UNUSED_ARGUMENT(name);
337 FEL_ERROR("You need to compile felisce with libXfm to use this function");
338
339 #endif
340 }
341
342 /***********************************************************************************/
343 /***********************************************************************************/
344
345 void M1gInterface::setData(M1G* m1gStruct)
346 {
347 #ifdef FELISCE_WITH_LIBXFM
348
349 m_M1gData = m1gStruct;
350
351 #else
352
353 IGNORE_UNUSED_ARGUMENT(m1gStruct);
354 FEL_ERROR("You need to compile felisce with libXfm to use this function");
355
356 #endif
357 }
358
359 /***********************************************************************************/
360 /***********************************************************************************/
361
362 void M1gInterface::setIteration(const felInt iteration)
363 {
364 #ifdef FELISCE_WITH_LIBXFM
365
366 m_iteration = iteration;
367
368 #else
369
370 IGNORE_UNUSED_ARGUMENT(iteration);
371 FEL_ERROR("You need to compile felisce with libXfm to use this function");
372
373 #endif
374 }
375
376 }
377
378
379