File: | aimMesh.c |
Warning: | line 868, column 7 Array access (from variable 'volName') results in a null pointer dereference |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* | |||
2 | * CAPS: Computational Aircraft Prototype Syntheses | |||
3 | * | |||
4 | * AIM Volume Mesh Functions | |||
5 | * | |||
6 | * Copyright 2014-2022, Massachusetts Institute of Technology | |||
7 | * Licensed under The GNU Lesser General Public License, version 2.1 | |||
8 | * See http://www.opensource.org/licenses/lgpl-2.1.php | |||
9 | * | |||
10 | */ | |||
11 | ||||
12 | #include <string.h> | |||
13 | ||||
14 | #ifdef WIN32 | |||
15 | #include <Windows.h> | |||
16 | #include <direct.h> | |||
17 | #define strcasecmp stricmp | |||
18 | #define access _access | |||
19 | #define F_OK0 0 | |||
20 | #define SLASH'/' '\\' | |||
21 | #else | |||
22 | #include <dirent.h> | |||
23 | #include <dlfcn.h> | |||
24 | #include <unistd.h> | |||
25 | #define SLASH'/' '/' | |||
26 | #endif | |||
27 | ||||
28 | #include "aimUtil.h" | |||
29 | #include "aimMesh.h" | |||
30 | ||||
31 | /* used to preserve the indexing order when there is a mixture of | |||
32 | * solid/sheet/wire bodies | |||
33 | */ | |||
34 | #define CAPS_BODY_INDX"--CAPS-BODY-INDX--" "--CAPS-BODY-INDX--" | |||
35 | ||||
36 | ||||
37 | static /*@null@*/ DLLvoid * writerDLopen(const char *name) | |||
38 | { | |||
39 | int i, len; | |||
40 | DLLvoid * dll; | |||
41 | char *full, *env; | |||
42 | #ifdef WIN32 | |||
43 | WIN32_FIND_DATA ffd; | |||
44 | char dir[MAX_PATH]; | |||
45 | size_t length_of_arg; | |||
46 | HANDLE hFind = INVALID_HANDLE_VALUE; | |||
47 | #else | |||
48 | /*@-unrecog@*/ | |||
49 | char dir[PATH_MAX4096]; | |||
50 | /*@+unrecog@*/ | |||
51 | struct dirent *de; | |||
52 | DIR *dr; | |||
53 | #endif | |||
54 | ||||
55 | env = getenv("ESP_ROOT"); | |||
56 | if (env == NULL((void*)0)) { | |||
57 | printf(" Information: Could not find $ESP_ROOT\n"); | |||
58 | return NULL((void*)0); | |||
59 | } | |||
60 | ||||
61 | if (name == NULL((void*)0)) { | |||
62 | printf(" Information: Dynamic Loader invoked with NULL name!\n"); | |||
63 | return NULL((void*)0); | |||
64 | } | |||
65 | len = strlen(name); | |||
66 | full = (char *) malloc((len+5)*sizeof(char)); | |||
67 | if (full == NULL((void*)0)) { | |||
68 | printf(" Information: Dynamic Loader MALLOC Error!\n"); | |||
69 | return NULL((void*)0); | |||
70 | } | |||
71 | for (i = 0; i < len; i++) full[i] = name[i]; | |||
72 | full[len ] = '.'; | |||
73 | #ifdef WIN32 | |||
74 | full[len+1] = 'D'; | |||
75 | full[len+2] = 'L'; | |||
76 | full[len+3] = 'L'; | |||
77 | full[len+4] = 0; | |||
78 | _snprintf(dir, MAX_PATH, "%s\\lib\\*", env); | |||
79 | hFind = FindFirstFile(dir, &ffd); | |||
80 | if (INVALID_HANDLE_VALUE == hFind) { | |||
81 | printf(" Information: Dynamic Loader could not open %s\n", dir); | |||
82 | free(full); | |||
83 | return NULL((void*)0); | |||
84 | } | |||
85 | i = 0; | |||
86 | do { | |||
87 | if (strcasecmp(full, ffd.cFileName) == 0) i++; | |||
88 | } while (FindNextFile(hFind, &ffd) != 0); | |||
89 | FindClose(hFind); | |||
90 | if (i > 1) { | |||
91 | printf(" Information: Dynamic Loader more than 1 file: %s!\n", full); | |||
92 | free(full); | |||
93 | return NULL((void*)0); | |||
94 | } | |||
95 | ||||
96 | if (i == 1) { | |||
97 | hFind = FindFirstFile(dir, &ffd); | |||
98 | do { | |||
99 | if (strcasecmp(full, ffd.cFileName) == 0) break; | |||
100 | } while (FindNextFile(hFind, &ffd) != 0); | |||
101 | dll = LoadLibrary(ffd.cFileName); | |||
102 | FindClose(hFind); | |||
103 | } else { | |||
104 | dll = LoadLibrary(full); | |||
105 | } | |||
106 | ||||
107 | #else | |||
108 | ||||
109 | full[len+1] = 's'; | |||
110 | full[len+2] = 'o'; | |||
111 | full[len+3] = 0; | |||
112 | snprintf(dir, PATH_MAX4096, "%s/lib", env); | |||
113 | dr = opendir(dir); | |||
114 | if (dr == NULL((void*)0)) { | |||
115 | printf(" Information: Dynamic Loader could not open %s\n", dir); | |||
116 | free(full); | |||
117 | return NULL((void*)0); | |||
118 | } | |||
119 | i = 0; | |||
120 | while ((de = readdir(dr)) != NULL((void*)0)) | |||
121 | /*@-unrecog@*/ | |||
122 | if (strcasecmp(full, de->d_name) == 0) i++; | |||
123 | /*@+unrecog@*/ | |||
124 | closedir(dr); | |||
125 | if (i > 1) { | |||
126 | printf(" Information: Dynamic Loader more than 1 file: %s!\n", full); | |||
127 | free(full); | |||
128 | return NULL((void*)0); | |||
129 | } | |||
130 | ||||
131 | if (i == 1) { | |||
132 | dr = opendir(dir); | |||
133 | while ((de = readdir(dr)) != NULL((void*)0)) | |||
134 | if (strcasecmp(full, de->d_name) == 0) break; | |||
135 | /*@-nullderef@*/ | |||
136 | dll = dlopen(de->d_name, RTLD_NOW0x00002 | RTLD_NODELETE0x01000); | |||
137 | /*@-nullderef@*/ | |||
138 | closedir(dr); | |||
139 | } else { | |||
140 | dll = dlopen(full, RTLD_NOW0x00002 | RTLD_NODELETE0x01000); | |||
141 | } | |||
142 | #endif | |||
143 | ||||
144 | if (!dll) { | |||
145 | printf(" Information: Dynamic Loader Error for %s\n", full); | |||
146 | #ifndef WIN32 | |||
147 | /*@-mustfreefresh@*/ | |||
148 | printf(" %s\n", dlerror()); | |||
149 | /*@+mustfreefresh@*/ | |||
150 | #endif | |||
151 | free(full); | |||
152 | return NULL((void*)0); | |||
153 | } | |||
154 | free(full); | |||
155 | ||||
156 | return dll; | |||
157 | } | |||
158 | ||||
159 | ||||
160 | static void writerDLclose(/*@only@*/ DLLvoid * dll) | |||
161 | { | |||
162 | #ifdef WIN32 | |||
163 | FreeLibrary(dll); | |||
164 | #else | |||
165 | dlclose(dll); | |||
166 | #endif | |||
167 | } | |||
168 | ||||
169 | ||||
170 | static wrDLLFunc writerDLget(DLLvoid * dll, const char *symname) | |||
171 | { | |||
172 | wrDLLFunc data; | |||
173 | ||||
174 | #ifdef WIN32 | |||
175 | data = (wrDLLFunc) GetProcAddress(dll, symname); | |||
176 | #else | |||
177 | /*@-castfcnptr@*/ | |||
178 | data = (wrDLLFunc) dlsym(dll, symname); | |||
179 | /*@+castfcnptr@*/ | |||
180 | #endif | |||
181 | ||||
182 | return data; | |||
183 | } | |||
184 | ||||
185 | ||||
186 | static int writerDLoaded(writerContext cntxt, const char *name) | |||
187 | { | |||
188 | int i; | |||
189 | ||||
190 | for (i = 0; i < cntxt.aimWriterNum; i++) | |||
191 | if (strcasecmp(name, cntxt.aimWriterName[i]) == 0) return i; | |||
192 | ||||
193 | return -1; | |||
194 | } | |||
195 | ||||
196 | ||||
197 | static int writerDYNload(writerContext *cntxt, const char *name) | |||
198 | { | |||
199 | int i, len, ret; | |||
200 | DLLvoid * dll; | |||
201 | ||||
202 | if (cntxt->aimWriterNum >= MAXWRITER16) { | |||
203 | printf(" Information: Number of Writers > %d!\n", MAXWRITER16); | |||
204 | return EGADS_INDEXERR-5; | |||
205 | } | |||
206 | dll = writerDLopen(name); | |||
207 | if (dll == NULL((void*)0)) return EGADS_NULLOBJ-2; | |||
208 | ||||
209 | ret = cntxt->aimWriterNum; | |||
210 | cntxt->aimExtension[ret] = (AIMext) writerDLget(dll, "meshExtension"); | |||
211 | cntxt->aimWriter[ret] = (AIMwriter) writerDLget(dll, "meshWrite"); | |||
212 | if (cntxt->aimExtension[ret] == NULL((void*)0)) { | |||
213 | writerDLclose(dll); | |||
214 | printf(" Error: Missing symbol 'meshExtension' in %s\n", name); | |||
215 | return EGADS_EMPTY-13; | |||
216 | } | |||
217 | if (cntxt->aimWriter[ret] == NULL((void*)0)) { | |||
218 | writerDLclose(dll); | |||
219 | printf(" Error: Missing symbol 'meshWrite' in %s\n", name); | |||
220 | return EGADS_EMPTY-13; | |||
221 | } | |||
222 | ||||
223 | len = strlen(name) + 1; | |||
224 | cntxt->aimWriterName[ret] = (char *) EG_alloc(len*sizeof(char)); | |||
225 | if (cntxt->aimWriterName[ret] == NULL((void*)0)) { | |||
226 | writerDLclose(dll); | |||
227 | return EGADS_MALLOC-4; | |||
228 | } | |||
229 | for (i = 0; i < len; i++) cntxt->aimWriterName[ret][i] = name[i]; | |||
230 | cntxt->aimWriterDLL[ret] = dll; | |||
231 | cntxt->aimWriterNum++; | |||
232 | ||||
233 | return ret; | |||
234 | } | |||
235 | ||||
236 | ||||
237 | /*@null@*/ /*@dependent@*/ static const char * | |||
238 | aim_writerExtension(void *aimStruc, const char *writerName) | |||
239 | { | |||
240 | int i; | |||
241 | aimInfo *aInfo; | |||
242 | ||||
243 | aInfo = (aimInfo *) aimStruc; | |||
244 | i = writerDLoaded(aInfo->wCntxt, writerName); | |||
245 | if (i == -1) { | |||
246 | i = writerDYNload(&aInfo->wCntxt, writerName); | |||
247 | if (i < 0) return NULL((void*)0); | |||
248 | } | |||
249 | ||||
250 | return aInfo->wCntxt.aimExtension[i](); | |||
251 | } | |||
252 | ||||
253 | ||||
254 | static int | |||
255 | aim_writeMesh(void *aimStruc, const char *writerName, aimMesh *mesh) | |||
256 | { | |||
257 | int i; | |||
258 | aimInfo *aInfo; | |||
259 | ||||
260 | aInfo = (aimInfo *) aimStruc; | |||
261 | i = writerDLoaded(aInfo->wCntxt, writerName); | |||
262 | if (i == -1) { | |||
263 | i = writerDYNload(&aInfo->wCntxt, writerName); | |||
264 | if (i < 0) return i; | |||
265 | } | |||
266 | ||||
267 | return aInfo->wCntxt.aimWriter[i](aimStruc, mesh); | |||
268 | } | |||
269 | ||||
270 | ||||
271 | /* ************************* Exposed Functions **************************** */ | |||
272 | ||||
273 | int | |||
274 | aim_deleteMeshes(void *aimStruc, const aimMeshRef *meshRef) | |||
275 | { | |||
276 | int i; | |||
277 | #ifdef WIN32 | |||
278 | char file[MAX_PATH]; | |||
279 | #else | |||
280 | char file[PATH_MAX4096]; | |||
281 | #endif | |||
282 | const char *ext; | |||
283 | aimInfo *aInfo; | |||
284 | writerContext cntxt; | |||
285 | ||||
286 | aInfo = (aimInfo *) aimStruc; | |||
287 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
288 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
289 | cntxt = aInfo->wCntxt; | |||
290 | ||||
291 | for (i = 0; i < cntxt.aimWriterNum; i++) { | |||
292 | ext = aim_writerExtension(aimStruc, cntxt.aimWriterName[i]); | |||
293 | if (ext == NULL((void*)0)) continue; | |||
294 | #ifdef WIN32 | |||
295 | _snprintf(file, MAX_PATH, "%s%s", meshRef->fileName, ext); | |||
296 | _unlink(file); | |||
297 | #else | |||
298 | snprintf(file, PATH_MAX4096, "%s%s", meshRef->fileName, ext); | |||
299 | unlink(file); | |||
300 | #endif | |||
301 | } | |||
302 | ||||
303 | return CAPS_SUCCESS0; | |||
304 | } | |||
305 | ||||
306 | ||||
307 | int | |||
308 | aim_queryMeshes(void *aimStruc, int index, aimMeshRef *meshRef) | |||
309 | { | |||
310 | int i, j, k, ret, nWrite = 0; | |||
311 | char *writerName[MAXWRITER16]; | |||
312 | #ifdef WIN32 | |||
313 | char file[MAX_PATH]; | |||
314 | #else | |||
315 | char file[PATH_MAX4096]; | |||
316 | #endif | |||
317 | const char *ext; | |||
318 | aimInfo *aInfo; | |||
319 | capsObject *vobject, *source, *last; | |||
320 | capsProblem *problem; | |||
321 | capsAnalysis *analysis, *another; | |||
322 | capsValue *value; | |||
323 | ||||
324 | aInfo = (aimInfo *) aimStruc; | |||
325 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
326 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
327 | problem = aInfo->problem; | |||
328 | analysis = (capsAnalysis *) aInfo->analysis; | |||
329 | ||||
330 | if ((index < 1) || (index > analysis->nAnalysisOut)) return CAPS_BADINDEX-304; | |||
331 | vobject = analysis->analysisOut[index-1]; | |||
332 | if (vobject == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
333 | value = (capsValue *) vobject->blind; | |||
334 | if (value == NULL((void*)0)) return CAPS_NULLBLIND-321; | |||
335 | if (value->type != PointerMesh) return CAPS_BADTYPE-306; | |||
336 | ||||
337 | /* find all of our linked writers */ | |||
338 | for (i = 0; i < problem->nAnalysis; i++) { | |||
339 | if (problem->analysis[i] == NULL((void*)0)) continue; | |||
340 | if (problem->analysis[i]->blind == NULL((void*)0)) continue; | |||
341 | another = problem->analysis[i]->blind; | |||
342 | if (analysis == another) continue; | |||
343 | for (j = 0; j < another->nAnalysisIn; j++) { | |||
344 | source = another->analysisIn[j]; | |||
345 | last = NULL((void*)0); | |||
346 | do { | |||
347 | if (source->magicnumber != CAPSMAGIC1234321) break; | |||
348 | if (source->type != VALUE) break; | |||
349 | if (source->blind == NULL((void*)0)) break; | |||
350 | value = (capsValue *) source->blind; | |||
351 | if (value->link == another->analysisIn[j]) break; | |||
352 | last = source; | |||
353 | source = value->link; | |||
354 | } while (value->link != NULL((void*)0)); | |||
355 | if (last != vobject) continue; | |||
356 | /* we hit our object from a AnalysisIn link */ | |||
357 | value = (capsValue *) another->analysisIn[j]->blind; | |||
358 | if (value->meshWriter == NULL((void*)0)) { | |||
359 | printf(" CAPS Warning: Link found but NULL writer!\n"); | |||
360 | continue; | |||
361 | } | |||
362 | for (k = 0; k < nWrite; k++) | |||
363 | if (strcmp(writerName[k], value->meshWriter) == 0) break; | |||
364 | if (k != nWrite) continue; | |||
365 | writerName[nWrite] = value->meshWriter; | |||
366 | nWrite++; | |||
367 | } | |||
368 | } | |||
369 | if (nWrite == 0) return CAPS_NOTFOUND-303; | |||
370 | ||||
371 | /* look at the extensions for our files -- do they exist? */ | |||
372 | for (ret = i = 0; i < nWrite; i++) { | |||
373 | ext = aim_writerExtension(aimStruc, writerName[i]); | |||
374 | if (ext == NULL((void*)0)) continue; | |||
375 | #ifdef WIN32 | |||
376 | _snprintf(file, MAX_PATH, "%s%s", meshRef->fileName, ext); | |||
377 | if (_access(file, F_OK0) != 0) ret++; | |||
378 | #else | |||
379 | snprintf(file, PATH_MAX4096, "%s%s", meshRef->fileName, ext); | |||
380 | if (access(file, F_OK0) != 0) ret++; | |||
381 | #endif | |||
382 | } | |||
383 | ||||
384 | return ret; | |||
385 | } | |||
386 | ||||
387 | ||||
388 | int | |||
389 | aim_writeMeshes(void *aimStruc, int index, aimMesh *mesh) | |||
390 | { | |||
391 | int i, j, k, stat, nWrite = 0; | |||
392 | char *writerName[MAXWRITER16]; | |||
393 | #ifdef WIN32 | |||
394 | char file[MAX_PATH]; | |||
395 | #else | |||
396 | char file[PATH_MAX4096]; | |||
397 | #endif | |||
398 | const char *ext; | |||
399 | aimInfo *aInfo; | |||
400 | capsObject *vobject, *source, *last; | |||
401 | capsProblem *problem; | |||
402 | capsAnalysis *analysis, *another; | |||
403 | capsValue *value; | |||
404 | ||||
405 | aInfo = (aimInfo *) aimStruc; | |||
406 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
407 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
408 | problem = aInfo->problem; | |||
409 | analysis = (capsAnalysis *) aInfo->analysis; | |||
410 | ||||
411 | if ((index < 1) || (index > analysis->nAnalysisOut)) return CAPS_BADINDEX-304; | |||
412 | vobject = analysis->analysisOut[index-1]; | |||
413 | if (vobject == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
414 | value = (capsValue *) vobject->blind; | |||
415 | if (value == NULL((void*)0)) return CAPS_NULLBLIND-321; | |||
416 | if (value->type != PointerMesh) return CAPS_BADTYPE-306; | |||
417 | ||||
418 | /* find all of our linked writers */ | |||
419 | for (i = 0; i < problem->nAnalysis; i++) { | |||
420 | if (problem->analysis[i] == NULL((void*)0)) continue; | |||
421 | if (problem->analysis[i]->blind == NULL((void*)0)) continue; | |||
422 | another = problem->analysis[i]->blind; | |||
423 | if (analysis == another) continue; | |||
424 | for (j = 0; j < another->nAnalysisIn; j++) { | |||
425 | source = another->analysisIn[j]; | |||
426 | last = NULL((void*)0); | |||
427 | do { | |||
428 | if (source->magicnumber != CAPSMAGIC1234321) break; | |||
429 | if (source->type != VALUE) break; | |||
430 | if (source->blind == NULL((void*)0)) break; | |||
431 | value = (capsValue *) source->blind; | |||
432 | if (value->link == another->analysisIn[j]) break; | |||
433 | last = source; | |||
434 | source = value->link; | |||
435 | } while (value->link != NULL((void*)0)); | |||
436 | if (last != vobject) continue; | |||
437 | /* we hit our object from a AnalysisIn link */ | |||
438 | value = (capsValue *) another->analysisIn[j]->blind; | |||
439 | #ifdef DEBUG | |||
440 | printf(" *** Found Writer = %s ***\n", value->meshWriter); | |||
441 | #endif | |||
442 | if (value->meshWriter == NULL((void*)0)) { | |||
443 | printf(" CAPS Error: Link found but NULL writer!\n"); | |||
444 | return CAPS_NOTFOUND-303; | |||
445 | } | |||
446 | for (k = 0; k < nWrite; k++) | |||
447 | if (strcmp(writerName[k], value->meshWriter) == 0) break; | |||
448 | if (k != nWrite) continue; | |||
449 | writerName[nWrite] = value->meshWriter; | |||
450 | nWrite++; | |||
451 | } | |||
452 | } | |||
453 | if (nWrite == 0) return CAPS_NOTFOUND-303; | |||
454 | ||||
455 | /* write the files */ | |||
456 | for (i = 0; i < nWrite; i++) { | |||
457 | /* does the file exist? */ | |||
458 | ext = aim_writerExtension(aimStruc, writerName[i]); | |||
459 | if (ext == NULL((void*)0)) continue; | |||
460 | #ifdef WIN32 | |||
461 | _snprintf(file, MAX_PATH, "%s%s", mesh->meshRef->fileName, ext); | |||
462 | if (_access(file, F_OK0) == 0) continue; | |||
463 | #else | |||
464 | snprintf(file, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ext); | |||
465 | if (access(file, F_OK0) == 0) continue; | |||
466 | #endif | |||
467 | /* no -- write it */ | |||
468 | stat = aim_writeMesh(aimStruc, writerName[i], mesh); | |||
469 | if (stat != CAPS_SUCCESS0) { | |||
470 | printf(" CAPS Error: aim_writeMesh = %d for Writer = %s!\n", | |||
471 | stat, writerName[i]); | |||
472 | return stat; | |||
473 | } | |||
474 | } | |||
475 | ||||
476 | return CAPS_SUCCESS0; | |||
477 | } | |||
478 | ||||
479 | ||||
480 | int | |||
481 | aim_initMeshBnd(aimMeshBnd *meshBnd) | |||
482 | { | |||
483 | if (meshBnd == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
484 | ||||
485 | meshBnd->groupName = NULL((void*)0); | |||
486 | meshBnd->ID = 0; | |||
487 | ||||
488 | return CAPS_SUCCESS0; | |||
489 | } | |||
490 | ||||
491 | ||||
492 | int | |||
493 | aim_initMeshRef(aimMeshRef *meshRef) | |||
494 | { | |||
495 | if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
496 | ||||
497 | meshRef->nmap = 0; | |||
498 | meshRef->maps = NULL((void*)0); | |||
499 | meshRef->nbnd = 0; | |||
500 | meshRef->bnds = NULL((void*)0); | |||
501 | meshRef->fileName = NULL((void*)0); | |||
502 | meshRef->_delTess = (int)false0; | |||
503 | ||||
504 | return CAPS_SUCCESS0; | |||
505 | } | |||
506 | ||||
507 | ||||
508 | int | |||
509 | aim_freeMeshRef(/*@null@*/ aimMeshRef *meshRef) | |||
510 | { | |||
511 | int status = CAPS_SUCCESS0; | |||
512 | int i, state, nvert; | |||
513 | ego body; | |||
514 | ||||
515 | if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
516 | ||||
517 | if (meshRef->maps != NULL((void*)0)) | |||
518 | for (i = 0; i < meshRef->nmap; i++) { | |||
519 | AIM_FREE(meshRef->maps[i].map){ EG_free(meshRef->maps[i].map); meshRef->maps[i].map = ((void*)0); }; | |||
520 | ||||
521 | if (meshRef->_delTess == (int)true1) { | |||
522 | status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &nvert); | |||
523 | if (status != CAPS_SUCCESS0) return status; | |||
524 | ||||
525 | EG_deleteObject(meshRef->maps[i].tess); | |||
526 | EG_deleteObject(body); | |||
527 | } | |||
528 | } | |||
529 | ||||
530 | if (meshRef->bnds != NULL((void*)0)) | |||
531 | for (i = 0; i < meshRef->nbnd; i++) | |||
532 | AIM_FREE(meshRef->bnds[i].groupName){ EG_free(meshRef->bnds[i].groupName); meshRef->bnds[i] .groupName = ((void*)0); }; | |||
533 | ||||
534 | AIM_FREE(meshRef->maps){ EG_free(meshRef->maps); meshRef->maps = ((void*)0); }; | |||
535 | AIM_FREE(meshRef->bnds){ EG_free(meshRef->bnds); meshRef->bnds = ((void*)0); }; | |||
536 | AIM_FREE(meshRef->fileName){ EG_free(meshRef->fileName); meshRef->fileName = ((void *)0); }; | |||
537 | ||||
538 | aim_initMeshRef(meshRef); | |||
539 | ||||
540 | return CAPS_SUCCESS0; | |||
541 | } | |||
542 | ||||
543 | ||||
544 | int | |||
545 | aim_initMeshData(aimMeshData *meshData) | |||
546 | { | |||
547 | if (meshData == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
548 | ||||
549 | meshData->dim = 0; | |||
550 | ||||
551 | meshData->nVertex = 0; | |||
552 | meshData->verts = NULL((void*)0); | |||
553 | ||||
554 | meshData->nElemGroup = 0; | |||
555 | meshData->elemGroups = NULL((void*)0); | |||
556 | ||||
557 | meshData->nTotalElems = 0; | |||
558 | meshData->elemMap = NULL((void*)0); | |||
559 | ||||
560 | return CAPS_SUCCESS0; | |||
561 | } | |||
562 | ||||
563 | ||||
564 | int | |||
565 | aim_freeMeshData(/*@null@*/ aimMeshData *meshData) | |||
566 | { | |||
567 | int i; | |||
568 | if (meshData == NULL((void*)0)) return CAPS_SUCCESS0; | |||
569 | ||||
570 | AIM_FREE(meshData->verts){ EG_free(meshData->verts); meshData->verts = ((void*)0 ); }; | |||
571 | ||||
572 | for (i = 0; i < meshData->nElemGroup; i++) { | |||
573 | AIM_FREE(meshData->elemGroups[i].groupName){ EG_free(meshData->elemGroups[i].groupName); meshData-> elemGroups[i].groupName = ((void*)0); }; | |||
574 | AIM_FREE(meshData->elemGroups[i].elements){ EG_free(meshData->elemGroups[i].elements); meshData-> elemGroups[i].elements = ((void*)0); }; | |||
575 | } | |||
576 | AIM_FREE(meshData->elemGroups){ EG_free(meshData->elemGroups); meshData->elemGroups = ((void*)0); }; | |||
577 | ||||
578 | AIM_FREE(meshData->elemMap){ EG_free(meshData->elemMap); meshData->elemMap = ((void *)0); }; | |||
579 | ||||
580 | aim_initMeshData(meshData); | |||
581 | ||||
582 | return CAPS_SUCCESS0; | |||
583 | } | |||
584 | ||||
585 | ||||
586 | int | |||
587 | aim_addMeshElemGroup(void *aimStruc, | |||
588 | /*@null@*/ const char* groupName, | |||
589 | int ID, | |||
590 | enum aimMeshElem elementTopo, | |||
591 | int order, | |||
592 | int nPoint, | |||
593 | aimMeshData *meshData) | |||
594 | { | |||
595 | int status = CAPS_SUCCESS0; | |||
596 | ||||
597 | /* resize the element group */ | |||
598 | AIM_REALL(meshData->elemGroups, meshData->nElemGroup+1, aimMeshElemGroup, aimStruc, status){ size_t memorysize = meshData->nElemGroup+1; meshData-> elemGroups = (aimMeshElemGroup *) EG_reall(meshData->elemGroups , memorysize*sizeof(aimMeshElemGroup)); if (meshData->elemGroups == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c" , 598, __func__, 3, "AIM_REALL: %s size %zu type %s", "meshData->elemGroups" , memorysize, "aimMeshElemGroup"); goto cleanup; } }; | |||
599 | ||||
600 | meshData->elemGroups[meshData->nElemGroup].groupName = NULL((void*)0); | |||
601 | meshData->elemGroups[meshData->nElemGroup].ID = ID; | |||
602 | meshData->elemGroups[meshData->nElemGroup].elementTopo = elementTopo; | |||
603 | meshData->elemGroups[meshData->nElemGroup].order = order; | |||
604 | meshData->elemGroups[meshData->nElemGroup].nPoint = nPoint; | |||
605 | meshData->elemGroups[meshData->nElemGroup].nElems = 0; | |||
606 | meshData->elemGroups[meshData->nElemGroup].elements = NULL((void*)0); | |||
607 | ||||
608 | if (groupName != NULL((void*)0)) | |||
609 | AIM_STRDUP(meshData->elemGroups[meshData->nElemGroup].groupName, groupName, aimStruc, status){ if (meshData->elemGroups[meshData->nElemGroup].groupName != ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c" , 609, __func__, 1, "AIM_STRDUP: %s != NULL!", "meshData->elemGroups[meshData->nElemGroup].groupName" ); goto cleanup; } meshData->elemGroups[meshData->nElemGroup ].groupName = EG_strdup(groupName); if (meshData->elemGroups [meshData->nElemGroup].groupName == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 609, __func__, 2, "AIM_STRDUP: %s %s", "meshData->elemGroups[meshData->nElemGroup].groupName" , groupName); goto cleanup; } }; | |||
610 | ||||
611 | meshData->nElemGroup++; | |||
612 | ||||
613 | cleanup: | |||
614 | return status; | |||
615 | } | |||
616 | ||||
617 | ||||
618 | int | |||
619 | aim_addMeshElem(void *aimStruc, | |||
620 | int nElems, | |||
621 | aimMeshElemGroup *elemGroup) | |||
622 | { | |||
623 | int status = CAPS_SUCCESS0; | |||
624 | ||||
625 | /* resize the element group */ | |||
626 | AIM_REALL(elemGroup->elements, elemGroup->nPoint*(elemGroup->nElems + nElems), int, aimStruc, status){ size_t memorysize = elemGroup->nPoint*(elemGroup->nElems + nElems); elemGroup->elements = (int *) EG_reall(elemGroup ->elements, memorysize*sizeof(int)); if (elemGroup->elements == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c" , 626, __func__, 3, "AIM_REALL: %s size %zu type %s", "elemGroup->elements" , memorysize, "int"); goto cleanup; } }; | |||
627 | ||||
628 | elemGroup->nElems += nElems; | |||
629 | ||||
630 | cleanup: | |||
631 | return status; | |||
632 | } | |||
633 | ||||
634 | ||||
635 | int | |||
636 | aim_readBinaryUgridHeader(void *aimStruc, aimMeshRef *meshRef, | |||
637 | int *nVertex, int *nTri, int *nQuad, | |||
638 | int *nTet, int *nPyramid, int *nPrism, int *nHex) | |||
639 | { | |||
640 | int status = CAPS_SUCCESS0; | |||
641 | ||||
642 | char filename[PATH_MAX4096]; | |||
643 | FILE *fp = NULL((void*)0); | |||
644 | ||||
645 | if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
646 | if (meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
647 | ||||
648 | snprintf(filename, PATH_MAX4096, "%s%s", meshRef->fileName, ".lb8.ugrid"); | |||
649 | ||||
650 | fp = fopen(filename, "rb"); | |||
651 | if (fp == NULL((void*)0)) { | |||
652 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 652, __func__ , "Cannot open file: %s\n", filename); }; | |||
653 | status = CAPS_IOERR-332; | |||
654 | goto cleanup; | |||
655 | } | |||
656 | ||||
657 | /* read a binary UGRID file */ | |||
658 | status = fread(nVertex, sizeof(int), 1, fp); | |||
659 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 659 , __func__, 0); goto cleanup; }; } | |||
660 | status = fread(nTri, sizeof(int), 1, fp); | |||
661 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 661 , __func__, 0); goto cleanup; }; } | |||
662 | status = fread(nQuad, sizeof(int), 1, fp); | |||
663 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 663 , __func__, 0); goto cleanup; }; } | |||
664 | status = fread(nTet, sizeof(int), 1, fp); | |||
665 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 665 , __func__, 0); goto cleanup; }; } | |||
666 | status = fread(nPyramid, sizeof(int), 1, fp); | |||
667 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 667 , __func__, 0); goto cleanup; }; } | |||
668 | status = fread(nPrism, sizeof(int), 1, fp); | |||
669 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 669 , __func__, 0); goto cleanup; }; } | |||
670 | status = fread(nHex, sizeof(int), 1, fp); | |||
671 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 671 , __func__, 0); goto cleanup; }; } | |||
672 | ||||
673 | status = CAPS_SUCCESS0; | |||
674 | ||||
675 | cleanup: | |||
676 | /*@-dependenttrans@*/ | |||
677 | if (fp != NULL((void*)0)) fclose(fp); | |||
678 | /*@+dependenttrans@*/ | |||
679 | fp = NULL((void*)0); | |||
680 | return status; | |||
681 | } | |||
682 | ||||
683 | ||||
684 | static int | |||
685 | aim_readBinaryUgridElements(void *aimStruc, FILE *fp, /*@null@*/ FILE *fpMV, /*@null@*/ char **volName, | |||
686 | int nPoint, enum aimMeshElem elementTopo, int nElems, | |||
687 | int *elementIndex, aimMeshData *meshData) | |||
688 | { | |||
689 | int status = CAPS_SUCCESS0; | |||
690 | int i, j, ID, igroup; | |||
691 | int nMapGroupID = 0; | |||
692 | int *mapGroupID = NULL((void*)0); | |||
693 | ||||
694 | if (nElems > 0) { | |||
695 | ||||
696 | if (fpMV != NULL((void*)0)) { | |||
697 | AIM_NOTNULL(volName, aimStruc, status){ if (volName == ((void*)0)) { status = -307; aim_status(aimStruc , status, "aimMesh.c", 697, __func__, 1, "%s == NULL!", "volName" ); goto cleanup; } }; | |||
698 | ||||
699 | for (i = 0; i < nElems; i++) { | |||
700 | ||||
701 | /* read the volume ID */ | |||
702 | status = fread(&ID, sizeof(int), 1, fpMV); | |||
703 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 703 , __func__, 0); goto cleanup; }; } | |||
704 | if (ID <= 0) { | |||
705 | AIM_ERROR(aimStruc, "Volume ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 705, __func__ , "Volume ID must be a positive number: %d!", ID); }; | |||
706 | status = CAPS_IOERR-332; | |||
707 | goto cleanup; | |||
708 | } | |||
709 | ||||
710 | /* add the volume group if necessary */ | |||
711 | if (ID > nMapGroupID) { | |||
712 | AIM_REALL(mapGroupID, ID, int, aimStruc, status){ size_t memorysize = ID; mapGroupID = (int *) EG_reall(mapGroupID , memorysize*sizeof(int)); if (mapGroupID == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 712, __func__ , 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize , "int"); goto cleanup; } }; | |||
713 | for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1; | |||
714 | nMapGroupID = ID; | |||
715 | } | |||
716 | if (mapGroupID[ID-1] == -1) { | |||
717 | status = aim_addMeshElemGroup(aimStruc, volName[ID-1], ID, elementTopo, 1, nPoint, meshData); | |||
718 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 718 , __func__, 0); goto cleanup; }; | |||
719 | mapGroupID[ID-1] = meshData->nElemGroup-1; | |||
720 | } | |||
721 | ||||
722 | igroup = mapGroupID[ID-1]; | |||
723 | ||||
724 | /* add the element to the group */ | |||
725 | status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]); | |||
726 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 726 , __func__, 0); goto cleanup; }; | |||
727 | ||||
728 | /* read the element connectivity */ | |||
729 | status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems-1)], | |||
730 | sizeof(int), nPoint, fp); | |||
731 | if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 731 , __func__, 0); goto cleanup; }; } | |||
732 | ||||
733 | meshData->elemMap[*elementIndex][0] = igroup; | |||
734 | meshData->elemMap[*elementIndex][1] = meshData->elemGroups[igroup].nElems-1; | |||
735 | ||||
736 | *elementIndex += 1; | |||
737 | } | |||
738 | ||||
739 | } else { | |||
740 | ||||
741 | status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), 0, elementTopo, 1, nPoint, meshData); | |||
742 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 742 , __func__, 0); goto cleanup; }; | |||
743 | ||||
744 | igroup = meshData->nElemGroup-1; | |||
745 | ||||
746 | /* add the elements to the group */ | |||
747 | status = aim_addMeshElem(aimStruc, nElems, &meshData->elemGroups[igroup]); | |||
748 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 748 , __func__, 0); goto cleanup; }; | |||
749 | ||||
750 | /* read the element connectivity */ | |||
751 | status = fread(meshData->elemGroups[igroup].elements, | |||
752 | sizeof(int), nPoint*nElems, fp); | |||
753 | if (status != nPoint*nElems) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 753 , __func__, 0); goto cleanup; }; } | |||
754 | ||||
755 | for (i = 0; i < nElems; i++) { | |||
756 | meshData->elemMap[*elementIndex][0] = igroup; | |||
757 | meshData->elemMap[*elementIndex][1] = i; | |||
758 | ||||
759 | *elementIndex += 1; | |||
760 | } | |||
761 | } | |||
762 | } | |||
763 | ||||
764 | status = CAPS_SUCCESS0; | |||
765 | cleanup: | |||
766 | ||||
767 | AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); }; | |||
768 | ||||
769 | return status; | |||
770 | } | |||
771 | ||||
772 | ||||
773 | int | |||
774 | aim_readBinaryUgrid(void *aimStruc, aimMesh *mesh) | |||
775 | { | |||
776 | int status = CAPS_SUCCESS0; | |||
777 | ||||
778 | int nLine, nTri, nQuad; | |||
779 | int nTet, nPyramid, nPrism, nHex; | |||
780 | int i, j, elementIndex, nPoint, nElems, ID, igroup; | |||
781 | int line[2], *mapGroupID=NULL((void*)0), nMapGroupID=0; | |||
782 | int nRegion = 0, nVolName=0, nmap=0, nID; | |||
783 | enum aimMeshElem elementTopo; | |||
784 | char filename[PATH_MAX4096], groupName[PATH_MAX4096], **volName=NULL((void*)0); | |||
| ||||
785 | size_t len; | |||
786 | FILE *fp = NULL((void*)0), *fpID = NULL((void*)0), *fpMV=NULL((void*)0); | |||
787 | aimMeshData *meshData = NULL((void*)0); | |||
788 | ||||
789 | if (mesh == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
790 | if (mesh->meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
791 | if (mesh->meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
792 | ||||
793 | status = aim_freeMeshData(mesh->meshData); | |||
794 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 794 , __func__, 0); goto cleanup; }; | |||
795 | AIM_FREE(mesh->meshData){ EG_free(mesh->meshData); mesh->meshData = ((void*)0); }; | |||
796 | ||||
797 | AIM_ALLOC(meshData, 1, aimMeshData, aimStruc, status){ if (meshData != ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 797, __func__, 1, "AIM_ALLOC: %s != NULL" , "meshData"); goto cleanup; } size_t memorysize = 1; meshData = (aimMeshData *) EG_alloc(memorysize*sizeof(aimMeshData)); if (meshData == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 797, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "meshData", memorysize, "aimMeshData"); goto cleanup; } }; | |||
798 | status = aim_initMeshData(meshData); | |||
799 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 799 , __func__, 0); goto cleanup; }; | |||
800 | ||||
801 | snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".lb8.ugrid"); | |||
802 | ||||
803 | fp = fopen(filename, "rb"); | |||
804 | if (fp == NULL((void*)0)) { | |||
805 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 805, __func__ , "Cannot open file: %s\n", filename); }; | |||
806 | status = CAPS_IOERR-332; | |||
807 | goto cleanup; | |||
808 | } | |||
809 | ||||
810 | // Open a 2nd copy to read in the BC ID's | |||
811 | fpID = fopen(filename, "rb"); | |||
812 | if (fpID == NULL((void*)0)) { | |||
813 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 813, __func__ , "Cannot open file: %s\n", filename); }; | |||
814 | status = CAPS_IOERR-332; | |||
815 | goto cleanup; | |||
816 | } | |||
817 | ||||
818 | /* read a binary UGRID file */ | |||
819 | status = fread(&meshData->nVertex, sizeof(int), 1, fp); | |||
820 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 820 , __func__, 0); goto cleanup; }; } | |||
821 | status = fread(&nTri, sizeof(int), 1, fp); | |||
822 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 822 , __func__, 0); goto cleanup; }; } | |||
823 | status = fread(&nQuad, sizeof(int), 1, fp); | |||
824 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 824 , __func__, 0); goto cleanup; }; } | |||
825 | status = fread(&nTet, sizeof(int), 1, fp); | |||
826 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 826 , __func__, 0); goto cleanup; }; } | |||
827 | status = fread(&nPyramid, sizeof(int), 1, fp); | |||
828 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 828 , __func__, 0); goto cleanup; }; } | |||
829 | status = fread(&nPrism, sizeof(int), 1, fp); | |||
830 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 830 , __func__, 0); goto cleanup; }; } | |||
831 | status = fread(&nHex, sizeof(int), 1, fp); | |||
832 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 832 , __func__, 0); goto cleanup; }; } | |||
833 | ||||
834 | /* skip the header */ | |||
835 | status = fseek(fpID, 7*sizeof(int), SEEK_CUR1); | |||
836 | if (status != 0) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 836 , __func__, 0); goto cleanup; }; } | |||
837 | ||||
838 | /* | |||
839 | printf("\n Header from UGRID file: %d %d %d %d %d %d %d\n", numNode, | |||
840 | numTriangle, numQuadrilateral, numTetrahedral, numPyramid, numPrism, | |||
841 | numHexahedral); | |||
842 | */ | |||
843 | ||||
844 | snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".mapvol"); | |||
845 | ||||
846 | // File for volume IDs | |||
847 | fpMV = fopen(filename, "rb"); | |||
848 | if (fpMV != NULL((void*)0)) { | |||
849 | status = fread(&nRegion, sizeof(int), 1, fpMV); | |||
850 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 850 , __func__, 0); goto cleanup; }; } | |||
851 | ||||
852 | /* read the maximum ID value */ | |||
853 | status = fread(&nVolName, sizeof(int), 1, fpMV); | |||
854 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 854 , __func__, 0); goto cleanup; }; } | |||
855 | ||||
856 | if (nVolName > 0) { | |||
857 | AIM_ALLOC(volName, nVolName, char*, aimStruc, status){ if (volName != ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 857, __func__, 1, "AIM_ALLOC: %s != NULL" , "volName"); goto cleanup; } size_t memorysize = nVolName; volName = (char* *) EG_alloc(memorysize*sizeof(char*)); if (volName == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c" , 857, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "volName" , memorysize, "char*"); goto cleanup; } }; | |||
858 | for (i = 0; i < nVolName; i++) volName[i] = NULL((void*)0); | |||
859 | } | |||
860 | ||||
861 | for (i = 0; i < nRegion; i++) { | |||
862 | status = fread(&ID, sizeof(int), 1, fpMV); | |||
863 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 863 , __func__, 0); goto cleanup; }; } | |||
864 | ||||
865 | status = fread(&len, sizeof(size_t), 1, fpMV); | |||
866 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 866 , __func__, 0); goto cleanup; }; } | |||
867 | ||||
868 | AIM_ALLOC(volName[ID-1], len, char, aimStruc, status){ if (volName[ID-1] != ((void*)0)) { status = -4; aim_status( aimStruc, status, "aimMesh.c", 868, __func__, 1, "AIM_ALLOC: %s != NULL" , "volName[ID-1]"); goto cleanup; } size_t memorysize = len; volName [ID-1] = (char *) EG_alloc(memorysize*sizeof(char)); if (volName [ID-1] == ((void*)0)) { status = -4; aim_status(aimStruc, status , "aimMesh.c", 868, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "volName[ID-1]", memorysize, "char"); goto cleanup; } }; | |||
| ||||
869 | ||||
870 | status = fread(volName[ID-1], sizeof(char), len, fpMV); | |||
871 | if (status != len) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 871 , __func__, 0); goto cleanup; }; } | |||
872 | } | |||
873 | ||||
874 | status = fread(&nElems, sizeof(int), 1, fpMV); | |||
875 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 875 , __func__, 0); goto cleanup; }; } | |||
876 | ||||
877 | if (nElems != nTet+nPyramid+nPrism+nHex) { | |||
878 | AIM_ERROR(aimStruc, "Element count missmatch in mapvol file!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 878, __func__ , "Element count missmatch in mapvol file!"); }; | |||
879 | status = CAPS_IOERR-332; | |||
880 | goto cleanup; | |||
881 | } | |||
882 | } | |||
883 | ||||
884 | ||||
885 | AIM_ALLOC(meshData->verts, meshData->nVertex, aimMeshCoords, aimStruc, status){ if (meshData->verts != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 885, __func__, 1, "AIM_ALLOC: %s != NULL" , "meshData->verts"); goto cleanup; } size_t memorysize = meshData ->nVertex; meshData->verts = (aimMeshCoords *) EG_alloc (memorysize*sizeof(aimMeshCoords)); if (meshData->verts == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c" , 885, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshData->verts" , memorysize, "aimMeshCoords"); goto cleanup; } }; | |||
886 | ||||
887 | /* read all of the vertices */ | |||
888 | status = fread(meshData->verts, sizeof(aimMeshCoords), meshData->nVertex, fp); | |||
889 | if (status != meshData->nVertex) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 889 , __func__, 0); goto cleanup; }; } | |||
890 | ||||
891 | /* skip the verts */ | |||
892 | status = fseek(fpID, meshData->nVertex*sizeof(aimMeshCoords), SEEK_CUR1); | |||
893 | if (status != 0) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 893 , __func__, 0); goto cleanup; }; } | |||
894 | ||||
895 | ||||
896 | // Numbers | |||
897 | meshData->nTotalElems = nTri + | |||
898 | nQuad + | |||
899 | nTet + | |||
900 | nPyramid + | |||
901 | nPrism + | |||
902 | nHex; | |||
903 | ||||
904 | // allocate the element map that maps back to the original element numbering | |||
905 | AIM_ALLOC(meshData->elemMap, meshData->nTotalElems, aimMeshIndices, aimStruc, status){ if (meshData->elemMap != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 905, __func__, 1, "AIM_ALLOC: %s != NULL" , "meshData->elemMap"); goto cleanup; } size_t memorysize = meshData->nTotalElems; meshData->elemMap = (aimMeshIndices *) EG_alloc(memorysize*sizeof(aimMeshIndices)); if (meshData ->elemMap == ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 905, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "meshData->elemMap", memorysize, "aimMeshIndices"); goto cleanup; } }; | |||
906 | ||||
907 | /* | |||
908 | printf("Volume mesh:\n"); | |||
909 | printf("\tNumber of nodes = %d\n", meshData->nVertex); | |||
910 | printf("\tNumber of elements = %d\n", meshData->nTotalElems); | |||
911 | printf("\tNumber of triangles = %d\n", numTriangle); | |||
912 | printf("\tNumber of quadrilatarals = %d\n", numQuadrilateral); | |||
913 | printf("\tNumber of tetrahedrals = %d\n", numTetrahedral); | |||
914 | printf("\tNumber of pyramids = %d\n", numPyramid); | |||
915 | printf("\tNumber of prisms = %d\n", numPrism); | |||
916 | printf("\tNumber of hexahedrals = %d\n", numHexahedral); | |||
917 | */ | |||
918 | ||||
919 | /* skip the Tri+Quad elements for the ID */ | |||
920 | status = fseek(fpID, (3*nTri+4*nQuad)*sizeof(int), SEEK_CUR1); | |||
921 | if (status != 0) { status = CAPS_IOERR-332; goto cleanup; } | |||
922 | ||||
923 | /* Start of element index */ | |||
924 | elementIndex = 0; | |||
925 | ||||
926 | /* Elements triangles */ | |||
927 | nPoint = 3; | |||
928 | elementTopo = aimTri; | |||
929 | for (i = 0; i < nTri; i++) { | |||
930 | ||||
931 | /* read the BC ID */ | |||
932 | status = fread(&ID, sizeof(int), 1, fpID); | |||
933 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 933 , __func__, 0); goto cleanup; }; } | |||
934 | if (ID <= 0) { | |||
935 | AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 935, __func__ , "BC ID must be a positive number: %d!", ID); }; | |||
936 | status = CAPS_IOERR-332; | |||
937 | goto cleanup; | |||
938 | } | |||
939 | ||||
940 | /* add the BC group if necessary */ | |||
941 | if (ID > nMapGroupID) { | |||
942 | AIM_REALL(mapGroupID, ID, int, aimStruc, status){ size_t memorysize = ID; mapGroupID = (int *) EG_reall(mapGroupID , memorysize*sizeof(int)); if (mapGroupID == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 942, __func__ , 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize , "int"); goto cleanup; } }; | |||
943 | for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1; | |||
944 | nMapGroupID = ID; | |||
945 | } | |||
946 | if (mapGroupID[ID-1] == -1) { | |||
947 | status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData); | |||
948 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 948 , __func__, 0); goto cleanup; }; | |||
949 | mapGroupID[ID-1] = meshData->nElemGroup-1; | |||
950 | } | |||
951 | ||||
952 | igroup = mapGroupID[ID-1]; | |||
953 | ||||
954 | /* add the element to the group */ | |||
955 | status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]); | |||
956 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 956 , __func__, 0); goto cleanup; }; | |||
957 | ||||
958 | /* read the element connectivity */ | |||
959 | status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems-1)], | |||
960 | sizeof(int), nPoint, fp); | |||
961 | if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 961 , __func__, 0); goto cleanup; }; } | |||
962 | ||||
963 | meshData->elemMap[elementIndex][0] = igroup; | |||
964 | meshData->elemMap[elementIndex][1] = meshData->elemGroups[igroup].nElems-1; | |||
965 | ||||
966 | elementIndex += 1; | |||
967 | } | |||
968 | ||||
969 | /* Elements quadrilateral */ | |||
970 | nPoint = 4; | |||
971 | elementTopo = aimQuad; | |||
972 | for (i = 0; i < nQuad; i++) { | |||
973 | ||||
974 | /* read the BC ID */ | |||
975 | status = fread(&ID, sizeof(int), 1, fpID); | |||
976 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 976 , __func__, 0); goto cleanup; }; } | |||
977 | if (ID <= 0) { | |||
978 | AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 978, __func__ , "BC ID must be a positive number: %d!", ID); }; | |||
979 | status = CAPS_IOERR-332; | |||
980 | goto cleanup; | |||
981 | } | |||
982 | ||||
983 | /* add the BC group if necessary */ | |||
984 | if (ID > nMapGroupID) { | |||
985 | AIM_REALL(mapGroupID, ID, int, aimStruc, status){ size_t memorysize = ID; mapGroupID = (int *) EG_reall(mapGroupID , memorysize*sizeof(int)); if (mapGroupID == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 985, __func__ , 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize , "int"); goto cleanup; } }; | |||
986 | for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1; | |||
987 | nMapGroupID = ID; | |||
988 | } | |||
989 | if (mapGroupID[ID-1] == -1) { | |||
990 | status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData); | |||
991 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 991 , __func__, 0); goto cleanup; }; | |||
992 | mapGroupID[ID-1] = meshData->nElemGroup-1; | |||
993 | } | |||
994 | ||||
995 | igroup = mapGroupID[ID-1]; | |||
996 | ||||
997 | /* add the element to the group */ | |||
998 | status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]); | |||
999 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 999 , __func__, 0); goto cleanup; }; | |||
1000 | ||||
1001 | /* read the element connectivity */ | |||
1002 | status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems-1)], | |||
1003 | sizeof(int), nPoint, fp); | |||
1004 | if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1004 , __func__, 0); goto cleanup; }; } | |||
1005 | ||||
1006 | meshData->elemMap[elementIndex][0] = igroup; | |||
1007 | meshData->elemMap[elementIndex][1] = meshData->elemGroups[igroup].nElems-1; | |||
1008 | ||||
1009 | elementIndex += 1; | |||
1010 | } | |||
1011 | ||||
1012 | /*@-dependenttrans@*/ | |||
1013 | fclose(fpID); fpID = NULL((void*)0); | |||
1014 | /*@+dependenttrans@*/ | |||
1015 | ||||
1016 | /* read in the groupName from mapbc file */ | |||
1017 | snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".mapbc"); | |||
1018 | ||||
1019 | if (access(filename, F_OK0) == 0) { | |||
1020 | // Correct the groupID's to be consistent with groupMap | |||
1021 | fpID = fopen(filename, "r"); | |||
1022 | if (fpID == NULL((void*)0)) { | |||
1023 | AIM_ERROR(aimStruc, "Failed to open %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1023, __func__ , "Failed to open %s", filename); }; | |||
1024 | status = CAPS_IOERR-332; | |||
1025 | goto cleanup; | |||
1026 | } | |||
1027 | status = fscanf(fpID, "%d", &nmap); | |||
1028 | if (status != 1) { | |||
1029 | AIM_ERROR(aimStruc, "Failed to read %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1029, __func__ , "Failed to read %s", filename); }; | |||
1030 | status = CAPS_IOERR-332; | |||
1031 | goto cleanup; | |||
1032 | } | |||
1033 | ||||
1034 | nID = 0; | |||
1035 | for (i = 0; i < nMapGroupID; i++) | |||
1036 | if (mapGroupID[i] != -1) nID++; | |||
1037 | ||||
1038 | if (nmap != nID) { | |||
1039 | AIM_ERROR(aimStruc, "Number of maps in %s (%d) should be %d",{ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1040, __func__ , "Number of maps in %s (%d) should be %d", filename, nmap, nID ); } | |||
1040 | filename, nmap, nID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1040, __func__ , "Number of maps in %s (%d) should be %d", filename, nmap, nID ); }; | |||
1041 | status = CAPS_IOERR-332; | |||
1042 | goto cleanup; | |||
1043 | } | |||
1044 | ||||
1045 | for (i = 0; i < nmap; i++) { | |||
1046 | status = fscanf(fpID, "%d %d %s", &ID, &j, groupName); | |||
1047 | if (status != 3) { | |||
1048 | AIM_ERROR(aimStruc, "Failed to read %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1048, __func__ , "Failed to read %s", filename); }; | |||
1049 | status = CAPS_IOERR-332; | |||
1050 | goto cleanup; | |||
1051 | } | |||
1052 | ||||
1053 | if (ID <= 0 || nMapGroupID < ID) { | |||
1054 | AIM_ERROR(aimStruc, "ID (%d) in %s out of bounds [1,%d]", ID, filename, nMapGroupID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1054, __func__ , "ID (%d) in %s out of bounds [1,%d]", ID, filename, nMapGroupID ); }; | |||
1055 | status = CAPS_IOERR-332; | |||
1056 | goto cleanup; | |||
1057 | } | |||
1058 | ||||
1059 | if (mapGroupID[ID-1] == -1) { | |||
1060 | AIM_ERROR(aimStruc, "Unknown BC ID (%d) in %s", ID, filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1060, __func__ , "Unknown BC ID (%d) in %s", ID, filename); }; | |||
1061 | status = CAPS_IOERR-332; | |||
1062 | goto cleanup; | |||
1063 | } | |||
1064 | ||||
1065 | AIM_STRDUP(meshData->elemGroups[mapGroupID[ID-1]].groupName, groupName, aimStruc, status){ if (meshData->elemGroups[mapGroupID[ID-1]].groupName != ( (void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c" , 1065, __func__, 1, "AIM_STRDUP: %s != NULL!", "meshData->elemGroups[mapGroupID[ID-1]].groupName" ); goto cleanup; } meshData->elemGroups[mapGroupID[ID-1]]. groupName = EG_strdup(groupName); if (meshData->elemGroups [mapGroupID[ID-1]].groupName == ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1065, __func__, 2, "AIM_STRDUP: %s %s" , "meshData->elemGroups[mapGroupID[ID-1]].groupName", groupName ); goto cleanup; } }; | |||
1066 | } | |||
1067 | ||||
1068 | /*@-dependenttrans@*/ | |||
1069 | fclose(fpID); fpID = NULL((void*)0); | |||
1070 | /*@+dependenttrans@*/ | |||
1071 | } | |||
1072 | ||||
1073 | ||||
1074 | // skip face ID section of the file | |||
1075 | status = fseek(fp, (nTri + nQuad)*sizeof(int), SEEK_CUR1); | |||
1076 | if (status != 0) { status = CAPS_IOERR-332; goto cleanup; } | |||
1077 | ||||
1078 | nMapGroupID = 0; | |||
1079 | AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); }; | |||
1080 | ||||
1081 | // Elements Tetrahedral | |||
1082 | nPoint = 4; | |||
1083 | elementTopo = aimTet; | |||
1084 | nElems = nTet; | |||
1085 | ||||
1086 | status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName, | |||
1087 | nPoint, elementTopo, nElems, | |||
1088 | &elementIndex, meshData); | |||
1089 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1089 , __func__, 0); goto cleanup; }; | |||
1090 | ||||
1091 | // Elements Pyramid | |||
1092 | nPoint = 5; | |||
1093 | elementTopo = aimPyramid; | |||
1094 | nElems = nPyramid; | |||
1095 | ||||
1096 | status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName, | |||
1097 | nPoint, elementTopo, nElems, | |||
1098 | &elementIndex, meshData); | |||
1099 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1099 , __func__, 0); goto cleanup; }; | |||
1100 | ||||
1101 | // Elements Prism | |||
1102 | nPoint = 6; | |||
1103 | elementTopo = aimPrism; | |||
1104 | nElems = nPrism; | |||
1105 | ||||
1106 | status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName, | |||
1107 | nPoint, elementTopo, nElems, | |||
1108 | &elementIndex, meshData); | |||
1109 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1109 , __func__, 0); goto cleanup; }; | |||
1110 | ||||
1111 | // Elements Hex | |||
1112 | nPoint = 8; | |||
1113 | elementTopo = aimHex; | |||
1114 | nElems = nHex; | |||
1115 | ||||
1116 | status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName, | |||
1117 | nPoint, elementTopo, nElems, | |||
1118 | &elementIndex, meshData); | |||
1119 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1119 , __func__, 0); goto cleanup; }; | |||
1120 | ||||
1121 | // 2D grid | |||
1122 | if (nTet+nPyramid+nPrism+nHex == 0) { | |||
1123 | meshData->dim = 2; | |||
1124 | ||||
1125 | status = fread(&nLine, sizeof(int), 1, fp); | |||
1126 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1126 , __func__, 0); goto cleanup; }; } | |||
1127 | ||||
1128 | meshData->nTotalElems += nLine; | |||
1129 | AIM_REALL(meshData->elemMap, meshData->nTotalElems, aimMeshIndices, aimStruc, status){ size_t memorysize = meshData->nTotalElems; meshData-> elemMap = (aimMeshIndices *) EG_reall(meshData->elemMap, memorysize *sizeof(aimMeshIndices)); if (meshData->elemMap == ((void* )0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 1129, __func__, 3, "AIM_REALL: %s size %zu type %s", "meshData->elemMap" , memorysize, "aimMeshIndices"); goto cleanup; } }; | |||
1130 | ||||
1131 | // Elements Hex | |||
1132 | nPoint = 2; | |||
1133 | elementTopo = aimLine; | |||
1134 | nElems = nLine; | |||
1135 | ||||
1136 | for (i = 0; i < nElems; i++) { | |||
1137 | /* read the element connectivity */ | |||
1138 | status = fread(line, sizeof(int), nPoint, fp); | |||
1139 | if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1139 , __func__, 0); goto cleanup; }; } | |||
1140 | status = fread(&ID, sizeof(int), 1, fp); | |||
1141 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1141 , __func__, 0); goto cleanup; }; } | |||
1142 | if (ID <= 0) { | |||
1143 | AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1143, __func__ , "BC ID must be a positive number: %d!", ID); }; | |||
1144 | status = CAPS_IOERR-332; | |||
1145 | goto cleanup; | |||
1146 | } | |||
1147 | ||||
1148 | /* add the BC group if necessary */ | |||
1149 | if (ID > nMapGroupID) { | |||
1150 | AIM_REALL(mapGroupID, ID, int, aimStruc, status){ size_t memorysize = ID; mapGroupID = (int *) EG_reall(mapGroupID , memorysize*sizeof(int)); if (mapGroupID == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 1150, __func__ , 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize , "int"); goto cleanup; } }; | |||
1151 | for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1; | |||
1152 | nMapGroupID = ID; | |||
1153 | } | |||
1154 | if (mapGroupID[ID-1] == -1) { | |||
1155 | status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData); | |||
1156 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1156 , __func__, 0); goto cleanup; }; | |||
1157 | mapGroupID[ID-1] = meshData->nElemGroup-1; | |||
1158 | } | |||
1159 | ||||
1160 | igroup = mapGroupID[ID-1]; | |||
1161 | ||||
1162 | /* add the elements to the group */ | |||
1163 | status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]); | |||
1164 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1164 , __func__, 0); goto cleanup; }; | |||
1165 | ||||
1166 | meshData->elemGroups[igroup].elements[nPoint*meshData->elemGroups[igroup].nElems-2] = line[0]; | |||
1167 | meshData->elemGroups[igroup].elements[nPoint*meshData->elemGroups[igroup].nElems-1] = line[1]; | |||
1168 | ||||
1169 | meshData->elemMap[elementIndex][0] = igroup; | |||
1170 | meshData->elemMap[elementIndex][1] = i; | |||
1171 | ||||
1172 | elementIndex += 1; | |||
1173 | } | |||
1174 | ||||
1175 | } else { | |||
1176 | meshData->dim = 3; | |||
1177 | } | |||
1178 | ||||
1179 | mesh->meshData = meshData; | |||
1180 | meshData = NULL((void*)0); | |||
1181 | ||||
1182 | status = CAPS_SUCCESS0; | |||
1183 | ||||
1184 | cleanup: | |||
1185 | if (status != CAPS_SUCCESS0) { | |||
1186 | aim_freeMeshData(meshData); | |||
1187 | AIM_FREE(meshData){ EG_free(meshData); meshData = ((void*)0); }; | |||
1188 | } | |||
1189 | AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); }; | |||
1190 | ||||
1191 | if (volName != NULL((void*)0)) { | |||
1192 | for (i = 0; i < nVolName; i++) | |||
1193 | AIM_FREE(volName[i]){ EG_free(volName[i]); volName[i] = ((void*)0); }; | |||
1194 | AIM_FREE(volName){ EG_free(volName); volName = ((void*)0); }; | |||
1195 | } | |||
1196 | ||||
1197 | /*@-dependenttrans@*/ | |||
1198 | if (fp != NULL((void*)0)) fclose(fp); | |||
1199 | if (fpID != NULL((void*)0)) fclose(fpID); | |||
1200 | if (fpMV != NULL((void*)0)) fclose(fpMV); | |||
1201 | /*@+dependenttrans@*/ | |||
1202 | ||||
1203 | return status; | |||
1204 | } | |||
1205 | ||||
1206 | ||||
1207 | int | |||
1208 | aim_storeMeshRef(void *aimStruc, const aimMeshRef *meshRef, | |||
1209 | const char *meshextension) | |||
1210 | { | |||
1211 | int status = CAPS_SUCCESS0; | |||
1212 | ||||
1213 | int imap, ibnd, state, nvert; | |||
1214 | int i; | |||
1215 | char filename_src[PATH_MAX4096]; | |||
1216 | char filename_dst[PATH_MAX4096]; | |||
1217 | char aimFile[PATH_MAX4096]; | |||
1218 | const char *meshRefFile = "meshRef.dat"; | |||
1219 | const char *meshRefegads = "meshRef.egads"; | |||
1220 | FILE *fp = NULL((void*)0); | |||
1221 | aimInfo *aInfo; | |||
1222 | size_t len, strLen; | |||
1223 | ego model, body, *bodies = NULL((void*)0); | |||
1224 | ||||
1225 | aInfo = (aimInfo *) aimStruc; | |||
1226 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1227 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
1228 | ||||
1229 | if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1230 | if (meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1231 | ||||
1232 | if (meshextension == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1233 | ||||
1234 | // create the full filename to the mesh in the meshing AIM directory | |||
1235 | snprintf(filename_src, PATH_MAX4096, "%s%s", meshRef->fileName, meshextension); | |||
1236 | ||||
1237 | // get the mesh filename without the directory | |||
1238 | i = strlen(filename_src); | |||
1239 | while(i > 0 && filename_src[i] != SLASH'/') { i--; } | |||
1240 | if (i < 0) { status = CAPS_IOERR-332; goto cleanup; } | |||
1241 | strcpy(filename_dst, filename_src+i+1); | |||
1242 | ||||
1243 | // copy the mesh from the meshing AIM directory to the current AIM directory | |||
1244 | status = aim_cpFile(aimStruc, filename_src, filename_dst); | |||
1245 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1245 , __func__, 0); goto cleanup; }; | |||
1246 | ||||
1247 | // open the file to store the meshRef structure | |||
1248 | status = aim_file(aimStruc, meshRefFile, aimFile); | |||
1249 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1249 , __func__, 0); goto cleanup; }; | |||
1250 | ||||
1251 | fp = fopen(aimFile, "wb"); | |||
1252 | if (fp == NULL((void*)0)) { | |||
1253 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1253, __func__ , "Cannot open file: %s\n", aimFile); }; | |||
1254 | status = CAPS_IOERR-332; | |||
1255 | goto cleanup; | |||
1256 | } | |||
1257 | ||||
1258 | len = fwrite(&meshRef->nmap, sizeof(int), 1, fp); | |||
1259 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1259 , __func__, 0); goto cleanup; }; } | |||
1260 | ||||
1261 | AIM_ALLOC(bodies, 2*meshRef->nmap, ego, aimStruc, status){ if (bodies != ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 1261, __func__, 1, "AIM_ALLOC: %s != NULL" , "bodies"); goto cleanup; } size_t memorysize = 2*meshRef-> nmap; bodies = (ego *) EG_alloc(memorysize*sizeof(ego)); if ( bodies == ((void*)0)) { status = -4; aim_status(aimStruc, status , "aimMesh.c", 1261, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "bodies", memorysize, "ego"); goto cleanup; } }; | |||
1262 | ||||
1263 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1264 | status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert); | |||
1265 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1265 , __func__, 0); goto cleanup; }; | |||
1266 | ||||
1267 | // construct an egads file to write out the tessellation and the body | |||
1268 | status = EG_copyObject(body, NULL((void*)0), &bodies[imap]); | |||
1269 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1269 , __func__, 0); goto cleanup; }; | |||
1270 | status = EG_copyObject(meshRef->maps[imap].tess, bodies[imap], &bodies[imap+meshRef->nmap]); | |||
1271 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1271 , __func__, 0); goto cleanup; }; | |||
1272 | ||||
1273 | // store the body index | |||
1274 | status = EG_attributeAdd(bodies[imap], CAPS_BODY_INDX"--CAPS-BODY-INDX--", ATTRINT1, 1, &imap, NULL((void*)0), NULL((void*)0)); | |||
1275 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1275 , __func__, 0); goto cleanup; }; | |||
1276 | } | |||
1277 | ||||
1278 | status = EG_makeTopology(aInfo->problem->context, NULL((void*)0), MODEL26, 2*meshRef->nmap, | |||
1279 | NULL((void*)0), meshRef->nmap, bodies, NULL((void*)0), &model); | |||
1280 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1280 , __func__, 0); goto cleanup; }; | |||
1281 | ||||
1282 | status = aim_file(aimStruc, meshRefegads, aimFile); | |||
1283 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1283 , __func__, 0); goto cleanup; }; | |||
1284 | ||||
1285 | remove(aimFile); | |||
1286 | status = EG_saveModel(model, aimFile); | |||
1287 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1287 , __func__, 0); goto cleanup; }; | |||
1288 | ||||
1289 | EG_deleteObject(model); | |||
1290 | ||||
1291 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1292 | status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert); | |||
1293 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1293 , __func__, 0); goto cleanup; }; | |||
1294 | ||||
1295 | // write the surface to volume map | |||
1296 | len = fwrite(meshRef->maps[imap].map, sizeof(int), nvert, fp); | |||
1297 | if (len != nvert) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1297 , __func__, 0); goto cleanup; }; } | |||
1298 | } | |||
1299 | ||||
1300 | len = fwrite(&meshRef->nbnd, sizeof(int), 1, fp); | |||
1301 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1301 , __func__, 0); goto cleanup; }; } | |||
1302 | ||||
1303 | for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) { | |||
1304 | ||||
1305 | strLen = strlen(meshRef->bnds[ibnd].groupName)+1; | |||
1306 | ||||
1307 | len = fwrite(&strLen, sizeof(size_t), 1, fp); | |||
1308 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1308 , __func__, 0); goto cleanup; }; } | |||
1309 | ||||
1310 | len = fwrite(meshRef->bnds[ibnd].groupName, sizeof(char), strLen, fp); | |||
1311 | if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1311 , __func__, 0); goto cleanup; }; } | |||
1312 | ||||
1313 | len = fwrite(&meshRef->bnds[ibnd].ID, sizeof(int), 1, fp); | |||
1314 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1314 , __func__, 0); goto cleanup; }; } | |||
1315 | } | |||
1316 | ||||
1317 | // write meshRef->filename (i.e. filename_dst without the extension) | |||
1318 | strLen = strlen(filename_dst); | |||
1319 | filename_dst[strLen - strlen(meshextension)] = '\0'; | |||
1320 | status = aim_file(aimStruc, filename_dst, aimFile); | |||
1321 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1321 , __func__, 0); goto cleanup; }; | |||
1322 | ||||
1323 | strLen = strlen(aimFile)+1; | |||
1324 | ||||
1325 | len = fwrite(&strLen, sizeof(size_t), 1, fp); | |||
1326 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1326 , __func__, 0); goto cleanup; }; } | |||
1327 | ||||
1328 | len = fwrite(aimFile, sizeof(char), strLen, fp); | |||
1329 | if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1329 , __func__, 0); goto cleanup; }; } | |||
1330 | ||||
1331 | cleanup: | |||
1332 | /*@-dependenttrans@*/ | |||
1333 | if (fp != NULL((void*)0)) fclose(fp); | |||
1334 | /*@+dependenttrans@*/ | |||
1335 | AIM_FREE(bodies){ EG_free(bodies); bodies = ((void*)0); }; | |||
1336 | ||||
1337 | return status; | |||
1338 | } | |||
1339 | ||||
1340 | ||||
1341 | int | |||
1342 | aim_loadMeshRef(void *aimStruc, aimMeshRef *meshRef) | |||
1343 | { | |||
1344 | int status = CAPS_SUCCESS0; | |||
1345 | ||||
1346 | int j, imap, ibnd, state, nvert, nbody; | |||
1347 | int oclass, mtype, *senses, alen, atype; | |||
1348 | char aimFile[PATH_MAX4096]; | |||
1349 | double limits[4]; | |||
1350 | const int *aints=NULL((void*)0); | |||
1351 | const double *areals=NULL((void*)0); | |||
1352 | const char *astring=NULL((void*)0); | |||
1353 | const char *meshRefFile = "meshRef.dat"; | |||
1354 | const char *meshRefegads = "meshRef.egads"; | |||
1355 | FILE *fp = NULL((void*)0); | |||
1356 | aimInfo *aInfo; | |||
1357 | size_t len, strLen; | |||
1358 | ego geom, model, body, tessbody, *bodies; | |||
1359 | ||||
1360 | aInfo = (aimInfo *) aimStruc; | |||
1361 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1362 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
1363 | ||||
1364 | if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1365 | if (meshRef->nmap != 0 || | |||
1366 | meshRef->maps != NULL((void*)0) || | |||
1367 | meshRef->nbnd != 0 || | |||
1368 | meshRef->bnds != NULL((void*)0) || | |||
1369 | meshRef->fileName != NULL((void*)0) ) { | |||
1370 | AIM_ERROR(aimStruc, "meshRef members not initialized to NULL values!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1370, __func__ , "meshRef members not initialized to NULL values!"); }; | |||
1371 | status = CAPS_NULLOBJ-309; | |||
1372 | goto cleanup; | |||
1373 | } | |||
1374 | ||||
1375 | // open the file to read the meshRef structure | |||
1376 | status = aim_file(aimStruc, meshRefFile, aimFile); | |||
1377 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1377 , __func__, 0); goto cleanup; }; | |||
1378 | ||||
1379 | fp = fopen(aimFile, "rb"); | |||
1380 | if (fp == NULL((void*)0)) { | |||
1381 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1381, __func__ , "Cannot open file: %s\n", aimFile); }; | |||
1382 | status = CAPS_IOERR-332; | |||
1383 | goto cleanup; | |||
1384 | } | |||
1385 | ||||
1386 | len = fread(&meshRef->nmap, sizeof(int), 1, fp); | |||
1387 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1387 , __func__, 0); goto cleanup; }; } | |||
1388 | ||||
1389 | AIM_ALLOC(meshRef->maps, meshRef->nmap, aimMeshTessMap, aimStruc, status){ if (meshRef->maps != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1389, __func__, 1, "AIM_ALLOC: %s != NULL" , "meshRef->maps"); goto cleanup; } size_t memorysize = meshRef ->nmap; meshRef->maps = (aimMeshTessMap *) EG_alloc(memorysize *sizeof(aimMeshTessMap)); if (meshRef->maps == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 1389 , __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->maps" , memorysize, "aimMeshTessMap"); goto cleanup; } }; | |||
1390 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1391 | meshRef->maps[imap].tess = NULL((void*)0); | |||
1392 | meshRef->maps[imap].map = NULL((void*)0); | |||
1393 | } | |||
1394 | ||||
1395 | status = aim_file(aimStruc, meshRefegads, aimFile); | |||
1396 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1396 , __func__, 0); goto cleanup; }; | |||
1397 | ||||
1398 | status = EG_loadModel(aInfo->problem->context, 0, aimFile, &model); | |||
1399 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1399 , __func__, 0); goto cleanup; }; | |||
1400 | ||||
1401 | status = EG_getTopology(model, &geom, &oclass, &mtype, limits, | |||
1402 | &nbody, &bodies, &senses); | |||
1403 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1403 , __func__, 0); goto cleanup; }; | |||
1404 | ||||
1405 | if (nbody != meshRef->nmap) { | |||
1406 | AIM_ERROR(aimStruc, "Missmatch between %s and %s!", meshRefFile, meshRefegads){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1406, __func__ , "Missmatch between %s and %s!", meshRefFile, meshRefegads); }; | |||
1407 | status = CAPS_IOERR-332; | |||
1408 | goto cleanup; | |||
1409 | } | |||
1410 | ||||
1411 | // copy the body and tessellatoin out of the model | |||
1412 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1413 | status = EG_copyObject(bodies[imap], NULL((void*)0), &body); | |||
1414 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1414 , __func__, 0); goto cleanup; }; | |||
1415 | ||||
1416 | // get the original body index | |||
1417 | status = EG_attributeRet(body, CAPS_BODY_INDX"--CAPS-BODY-INDX--", &atype, &alen, &aints, &areals, &astring); | |||
1418 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1418 , __func__, 0); goto cleanup; }; | |||
1419 | AIM_NOTNULL(aints, aimStruc, status){ if (aints == ((void*)0)) { status = -307; aim_status(aimStruc , status, "aimMesh.c", 1419, __func__, 1, "%s == NULL!", "aints" ); goto cleanup; } }; | |||
1420 | ||||
1421 | status = EG_attributeDel(body, CAPS_BODY_INDX"--CAPS-BODY-INDX--"); | |||
1422 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1422 , __func__, 0); goto cleanup; }; | |||
1423 | ||||
1424 | // find the tessellation for this body | |||
1425 | for (j = 0; j < meshRef->nmap; j++) { | |||
1426 | status = EG_statusTessBody(bodies[j+meshRef->nmap], &tessbody, &state, &nvert); | |||
1427 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1427 , __func__, 0); goto cleanup; }; | |||
1428 | ||||
1429 | if (tessbody == bodies[imap]) { | |||
1430 | // copy the tessellation with the copied body | |||
1431 | status = EG_copyObject(bodies[j+meshRef->nmap], body, &meshRef->maps[aints[0]].tess); | |||
1432 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1432 , __func__, 0); goto cleanup; }; | |||
1433 | break; | |||
1434 | } | |||
1435 | } | |||
1436 | } | |||
1437 | ||||
1438 | // delete the model | |||
1439 | EG_deleteObject(model); | |||
1440 | ||||
1441 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1442 | // read the surface to volume map | |||
1443 | status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert); | |||
1444 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1444 , __func__, 0); goto cleanup; }; | |||
1445 | ||||
1446 | AIM_ALLOC(meshRef->maps[imap].map, nvert, int, aimStruc, status){ if (meshRef->maps[imap].map != ((void*)0)) { status = -4 ; aim_status(aimStruc, status, "aimMesh.c", 1446, __func__, 1 , "AIM_ALLOC: %s != NULL", "meshRef->maps[imap].map"); goto cleanup; } size_t memorysize = nvert; meshRef->maps[imap] .map = (int *) EG_alloc(memorysize*sizeof(int)); if (meshRef-> maps[imap].map == ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 1446, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "meshRef->maps[imap].map", memorysize, "int"); goto cleanup ; } }; | |||
1447 | ||||
1448 | len = fread(meshRef->maps[imap].map, sizeof(int), nvert, fp); | |||
1449 | if (len != nvert) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1449 , __func__, 0); goto cleanup; }; } | |||
1450 | } | |||
1451 | ||||
1452 | // read the bounds | |||
1453 | len = fread(&meshRef->nbnd, sizeof(int), 1, fp); | |||
1454 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1454 , __func__, 0); goto cleanup; }; } | |||
1455 | ||||
1456 | AIM_ALLOC(meshRef->bnds, meshRef->nbnd, aimMeshBnd, aimStruc, status){ if (meshRef->bnds != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1456, __func__, 1, "AIM_ALLOC: %s != NULL" , "meshRef->bnds"); goto cleanup; } size_t memorysize = meshRef ->nbnd; meshRef->bnds = (aimMeshBnd *) EG_alloc(memorysize *sizeof(aimMeshBnd)); if (meshRef->bnds == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 1456, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->bnds", memorysize , "aimMeshBnd"); goto cleanup; } }; | |||
1457 | for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) { | |||
1458 | meshRef->bnds[ibnd].groupName = NULL((void*)0); | |||
1459 | meshRef->bnds[ibnd].ID = 0; | |||
1460 | } | |||
1461 | ||||
1462 | for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) { | |||
1463 | ||||
1464 | len = fread(&strLen, sizeof(size_t), 1, fp); | |||
1465 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1465 , __func__, 0); goto cleanup; }; } | |||
1466 | ||||
1467 | AIM_ALLOC(meshRef->bnds[ibnd].groupName, strLen, char, aimStruc, status){ if (meshRef->bnds[ibnd].groupName != ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 1467, __func__ , 1, "AIM_ALLOC: %s != NULL", "meshRef->bnds[ibnd].groupName" ); goto cleanup; } size_t memorysize = strLen; meshRef->bnds [ibnd].groupName = (char *) EG_alloc(memorysize*sizeof(char)) ; if (meshRef->bnds[ibnd].groupName == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 1467, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->bnds[ibnd].groupName" , memorysize, "char"); goto cleanup; } }; | |||
1468 | ||||
1469 | len = fread(meshRef->bnds[ibnd].groupName, sizeof(char), strLen, fp); | |||
1470 | if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1470 , __func__, 0); goto cleanup; }; } | |||
1471 | ||||
1472 | len = fread(&meshRef->bnds[ibnd].ID, sizeof(int), 1, fp); | |||
1473 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1473 , __func__, 0); goto cleanup; }; } | |||
1474 | } | |||
1475 | ||||
1476 | // read meshRef->filename | |||
1477 | len = fread(&strLen, sizeof(size_t), 1, fp); | |||
1478 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1478 , __func__, 0); goto cleanup; }; } | |||
1479 | ||||
1480 | AIM_ALLOC(meshRef->fileName, strLen, char, aimStruc, status){ if (meshRef->fileName != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1480, __func__, 1, "AIM_ALLOC: %s != NULL" , "meshRef->fileName"); goto cleanup; } size_t memorysize = strLen; meshRef->fileName = (char *) EG_alloc(memorysize* sizeof(char)); if (meshRef->fileName == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 1480, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->fileName" , memorysize, "char"); goto cleanup; } }; | |||
1481 | ||||
1482 | len = fread(meshRef->fileName, sizeof(char), strLen, fp); | |||
1483 | if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1483 , __func__, 0); goto cleanup; }; } | |||
1484 | ||||
1485 | // indicate that the tessellation and body should be deleted | |||
1486 | meshRef->_delTess = (int)true1; | |||
1487 | ||||
1488 | cleanup: | |||
1489 | /*@-dependenttrans@*/ | |||
1490 | if (fp != NULL((void*)0)) fclose(fp); | |||
1491 | /*@+dependenttrans@*/ | |||
1492 | ||||
1493 | return status; | |||
1494 | } |