Bug Summary

File:aimMesh.c
Warning:line 1555, column 11
The left operand of '==' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name aimMesh.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -D REVISION=7.7 -I /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/ESP/LINUX64/include -I ../include -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-dangling-else -Wno-parentheses -Wno-unused-result -Wno-format-truncation -fdebug-compilation-dir /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/CAPS/src -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/scanCAPS/2023-07-10-235512-80989-1 -x c aimMesh.c
1/*
2 * CAPS: Computational Aircraft Prototype Syntheses
3 *
4 * AIM Volume Mesh Functions
5 *
6 * * Copyright 2014-2023, 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
37static /*@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
160static void writerDLclose(/*@only@*/ DLLvoid * dll)
161{
162#ifdef WIN32
163 FreeLibrary(dll);
164#else
165 dlclose(dll);
166#endif
167}
168
169
170static 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
186static 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
197static 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 *
238aim_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
254static int
255aim_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
273int
274aim_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
307int
308aim_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
388int
389aim_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
480int
481aim_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
492int
493aim_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
508int
509aim_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
544int
545aim_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
564int
565aim_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
586int
587aim_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
613cleanup:
614 return status;
615}
616
617
618int
619aim_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
630cleanup:
631 return status;
632}
633
634
635int
636aim_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
675cleanup:
676/*@-dependenttrans@*/
677 if (fp != NULL((void*)0)) fclose(fp);
678/*@+dependenttrans@*/
679 fp = NULL((void*)0);
680 return status;
681}
682
683
684static int
685aim_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), 1, 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;
765cleanup:
766
767 AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); };
768
769 return status;
770}
771
772
773int
774aim_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 (nRegion+nVolName == 0) {
857 AIM_ERROR(aimStruc, "Ivnalid mapvol file with zero nRegion and nVolName!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 857, __func__
, "Ivnalid mapvol file with zero nRegion and nVolName!"); }
;
858 status = CAPS_IOERR-332;
859 goto cleanup;
860 }
861
862 AIM_ALLOC(volName, nVolName, char*, aimStruc, status){ if (volName != ((void*)0)) { status = -4; aim_status(aimStruc
, status, "aimMesh.c", 862, __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"
, 862, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "volName"
, memorysize, "char*"); goto cleanup; } }
;
863 for (i = 0; i < nVolName; i++) volName[i] = NULL((void*)0);
864
865 for (i = 0; i < nRegion; i++) {
866 status = fread(&ID, sizeof(int), 1, fpMV);
867 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 867
, __func__, 0); goto cleanup; }
; }
868
869 status = fread(&len, sizeof(size_t), 1, fpMV);
870 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 870
, __func__, 0); goto cleanup; }
; }
871
872 AIM_ALLOC(volName[ID-1], len, char, aimStruc, status){ if (volName[ID-1] != ((void*)0)) { status = -4; aim_status(
aimStruc, status, "aimMesh.c", 872, __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", 872, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "volName[ID-1]", memorysize, "char"); goto cleanup; } }
;
873
874 status = fread(volName[ID-1], sizeof(char), len, fpMV);
875 if (status != len) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 875
, __func__, 0); goto cleanup; }
; }
876 }
877
878 status = fread(&nElems, sizeof(int), 1, fpMV);
879 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 879
, __func__, 0); goto cleanup; }
; }
880
881 if (nElems != nTet+nPyramid+nPrism+nHex) {
882 AIM_ERROR(aimStruc, "Element count missmatch in mapvol file!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 882, __func__
, "Element count missmatch in mapvol file!"); }
;
883 status = CAPS_IOERR-332;
884 goto cleanup;
885 }
886 }
887
888
889 AIM_ALLOC(meshData->verts, meshData->nVertex, aimMeshCoords, aimStruc, status){ if (meshData->verts != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 889, __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"
, 889, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshData->verts"
, memorysize, "aimMeshCoords"); goto cleanup; } }
;
890
891 /* read all of the vertices */
892 status = fread(meshData->verts, sizeof(aimMeshCoords), meshData->nVertex, fp);
893 if (status != meshData->nVertex) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 893
, __func__, 0); goto cleanup; }
; }
894
895 /* skip the verts */
896 status = fseek(fpID, meshData->nVertex*sizeof(aimMeshCoords), SEEK_CUR1);
897 if (status != 0) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 897
, __func__, 0); goto cleanup; }
; }
898
899
900 // Numbers
901 meshData->nTotalElems = nTri +
902 nQuad +
903 nTet +
904 nPyramid +
905 nPrism +
906 nHex;
907
908 // allocate the element map that maps back to the original element numbering
909 AIM_ALLOC(meshData->elemMap, meshData->nTotalElems, aimMeshIndices, aimStruc, status){ if (meshData->elemMap != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 909, __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", 909, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "meshData->elemMap", memorysize, "aimMeshIndices"); goto
cleanup; } }
;
910
911 /*
912 printf("Volume mesh:\n");
913 printf("\tNumber of nodes = %d\n", meshData->nVertex);
914 printf("\tNumber of elements = %d\n", meshData->nTotalElems);
915 printf("\tNumber of triangles = %d\n", numTriangle);
916 printf("\tNumber of quadrilatarals = %d\n", numQuadrilateral);
917 printf("\tNumber of tetrahedrals = %d\n", numTetrahedral);
918 printf("\tNumber of pyramids = %d\n", numPyramid);
919 printf("\tNumber of prisms = %d\n", numPrism);
920 printf("\tNumber of hexahedrals = %d\n", numHexahedral);
921*/
922
923 /* skip the Tri+Quad elements for the ID */
924 status = fseek(fpID, (3*nTri+4*nQuad)*sizeof(int), SEEK_CUR1);
925 if (status != 0) { status = CAPS_IOERR-332; goto cleanup; }
926
927 /* Start of element index */
928 elementIndex = 0;
929
930 /* Elements triangles */
931 nPoint = 3;
932 elementTopo = aimTri;
933 for (i = 0; i < nTri; i++) {
934
935 /* read the BC ID */
936 status = fread(&ID, sizeof(int), 1, fpID);
937 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 937
, __func__, 0); goto cleanup; }
; }
938 if (ID <= 0) {
939 AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 939, __func__
, "BC ID must be a positive number: %d!", ID); }
;
940 status = CAPS_IOERR-332;
941 goto cleanup;
942 }
943
944 /* add the BC group if necessary */
945 if (ID > nMapGroupID) {
946 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", 946, __func__
, 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize
, "int"); goto cleanup; } }
;
947 for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1;
948 nMapGroupID = ID;
949 }
950 if (mapGroupID[ID-1] == -1) {
951 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData);
952 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 952
, __func__, 0); goto cleanup; }
;
953 mapGroupID[ID-1] = meshData->nElemGroup-1;
954 }
955
956 igroup = mapGroupID[ID-1];
957
958 /* add the element to the group */
959 status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]);
960 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 960
, __func__, 0); goto cleanup; }
;
961
962 /* read the element connectivity */
963 status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems-1)],
964 sizeof(int), nPoint, fp);
965 if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 965
, __func__, 0); goto cleanup; }
; }
966
967 meshData->elemMap[elementIndex][0] = igroup;
968 meshData->elemMap[elementIndex][1] = meshData->elemGroups[igroup].nElems-1;
969
970 elementIndex += 1;
971 }
972
973 /* Elements quadrilateral */
974 nPoint = 4;
975 elementTopo = aimQuad;
976 for (i = 0; i < nQuad; i++) {
977
978 /* read the BC ID */
979 status = fread(&ID, sizeof(int), 1, fpID);
980 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 980
, __func__, 0); goto cleanup; }
; }
981 if (ID <= 0) {
982 AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 982, __func__
, "BC ID must be a positive number: %d!", ID); }
;
983 status = CAPS_IOERR-332;
984 goto cleanup;
985 }
986
987 /* add the BC group if necessary */
988 if (ID > nMapGroupID) {
989 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", 989, __func__
, 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize
, "int"); goto cleanup; } }
;
990 for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1;
991 nMapGroupID = ID;
992 }
993 if (mapGroupID[ID-1] == -1) {
994 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData);
995 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 995
, __func__, 0); goto cleanup; }
;
996 mapGroupID[ID-1] = meshData->nElemGroup-1;
997 }
998
999 igroup = mapGroupID[ID-1];
1000
1001 /* add the element to the group */
1002 status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]);
1003 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1003
, __func__, 0); goto cleanup; }
;
1004
1005 /* read the element connectivity */
1006 status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems-1)],
1007 sizeof(int), nPoint, fp);
1008 if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1008
, __func__, 0); goto cleanup; }
; }
1009
1010 meshData->elemMap[elementIndex][0] = igroup;
1011 meshData->elemMap[elementIndex][1] = meshData->elemGroups[igroup].nElems-1;
1012
1013 elementIndex += 1;
1014 }
1015
1016 /*@-dependenttrans@*/
1017 fclose(fpID); fpID = NULL((void*)0);
1018 /*@+dependenttrans@*/
1019
1020 // skip face ID section of the file
1021 status = fseek(fp, (nTri + nQuad)*sizeof(int), SEEK_CUR1);
1022 if (status != 0) { status = CAPS_IOERR-332; goto cleanup; }
1023
1024 // Elements Tetrahedral
1025 nPoint = 4;
1026 elementTopo = aimTet;
1027 nElems = nTet;
1028
1029 status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName,
1030 nPoint, elementTopo, nElems,
1031 &elementIndex, meshData);
1032 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1032
, __func__, 0); goto cleanup; }
;
1033
1034 // Elements Pyramid
1035 nPoint = 5;
1036 elementTopo = aimPyramid;
1037 nElems = nPyramid;
1038
1039 status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName,
1040 nPoint, elementTopo, nElems,
1041 &elementIndex, meshData);
1042 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1042
, __func__, 0); goto cleanup; }
;
1043
1044 // Elements Prism
1045 nPoint = 6;
1046 elementTopo = aimPrism;
1047 nElems = nPrism;
1048
1049 status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName,
1050 nPoint, elementTopo, nElems,
1051 &elementIndex, meshData);
1052 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1052
, __func__, 0); goto cleanup; }
;
1053
1054 // Elements Hex
1055 nPoint = 8;
1056 elementTopo = aimHex;
1057 nElems = nHex;
1058
1059 status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName,
1060 nPoint, elementTopo, nElems,
1061 &elementIndex, meshData);
1062 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1062
, __func__, 0); goto cleanup; }
;
1063
1064 // 2D grid
1065 if (nTet+nPyramid+nPrism+nHex == 0) {
1066 meshData->dim = 2;
1067 AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); };
1068 nMapGroupID = 0;
1069
1070 status = fread(&nLine, sizeof(int), 1, fp);
1071 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1071
, __func__, 0); goto cleanup; }
; }
1072
1073 meshData->nTotalElems += nLine;
1074 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",
1074, __func__, 3, "AIM_REALL: %s size %zu type %s", "meshData->elemMap"
, memorysize, "aimMeshIndices"); goto cleanup; } }
;
1075
1076 // Elements Line
1077 nPoint = 2;
1078 elementTopo = aimLine;
1079 nElems = nLine;
1080
1081 for (i = 0; i < nElems; i++) {
1082 /* read the element connectivity */
1083 status = fread(line, sizeof(int), nPoint, fp);
1084 if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1084
, __func__, 0); goto cleanup; }
; }
1085 status = fread(&ID, sizeof(int), 1, fp);
1086 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1086
, __func__, 0); goto cleanup; }
; }
1087 if (ID <= 0) {
1088 AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1088, __func__
, "BC ID must be a positive number: %d!", ID); }
;
1089 status = CAPS_IOERR-332;
1090 goto cleanup;
1091 }
1092
1093 /* add the BC group if necessary */
1094 if (ID > nMapGroupID) {
1095 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", 1095, __func__
, 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize
, "int"); goto cleanup; } }
;
1096 for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1;
1097 nMapGroupID = ID;
1098 }
1099 if (mapGroupID[ID-1] == -1) {
1100 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData);
1101 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1101
, __func__, 0); goto cleanup; }
;
1102 mapGroupID[ID-1] = meshData->nElemGroup-1;
1103 }
1104
1105 igroup = mapGroupID[ID-1];
1106
1107 /* add the elements to the group */
1108 status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]);
1109 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1109
, __func__, 0); goto cleanup; }
;
1110
1111 meshData->elemGroups[igroup].elements[nPoint*meshData->elemGroups[igroup].nElems-2] = line[0];
1112 meshData->elemGroups[igroup].elements[nPoint*meshData->elemGroups[igroup].nElems-1] = line[1];
1113
1114 meshData->elemMap[elementIndex][0] = igroup;
1115 meshData->elemMap[elementIndex][1] = i;
1116
1117 elementIndex += 1;
1118 }
1119
1120 } else {
1121 meshData->dim = 3;
1122 }
1123
1124 /* read in the groupName from mapbc file */
1125 snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".mapbc");
1126
1127 if (access(filename, F_OK0) == 0) {
1128 // Correct the groupID's to be consistent with groupMap
1129 fpID = fopen(filename, "r");
1130 if (fpID == NULL((void*)0)) {
1131 AIM_ERROR(aimStruc, "Failed to open %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1131, __func__
, "Failed to open %s", filename); }
;
1132 status = CAPS_IOERR-332;
1133 goto cleanup;
1134 }
1135 status = fscanf(fpID, "%d", &nmap);
1136 if (status != 1) {
1137 AIM_ERROR(aimStruc, "Failed to read %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1137, __func__
, "Failed to read %s", filename); }
;
1138 status = CAPS_IOERR-332;
1139 goto cleanup;
1140 }
1141
1142 nID = 0;
1143 for (i = 0; i < nMapGroupID; i++)
1144 if (mapGroupID[i] != -1) nID++;
1145
1146 if (nmap != nID) {
1147 AIM_ERROR(aimStruc, "Number of maps in %s (%d) should be %d",{ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1148, __func__
, "Number of maps in %s (%d) should be %d", filename, nmap, nID
); }
1148 filename, nmap, nID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1148, __func__
, "Number of maps in %s (%d) should be %d", filename, nmap, nID
); }
;
1149 status = CAPS_IOERR-332;
1150 goto cleanup;
1151 }
1152
1153 for (i = 0; i < nmap; i++) {
1154 status = fscanf(fpID, "%d %d %s", &ID, &j, groupName);
1155 if (status != 3) {
1156 AIM_ERROR(aimStruc, "Failed to read %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1156, __func__
, "Failed to read %s", filename); }
;
1157 status = CAPS_IOERR-332;
1158 goto cleanup;
1159 }
1160
1161 if (ID <= 0 || nMapGroupID < ID) {
1162 AIM_ERROR(aimStruc, "ID (%d) in %s out of bounds [1,%d]", ID, filename, nMapGroupID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1162, __func__
, "ID (%d) in %s out of bounds [1,%d]", ID, filename, nMapGroupID
); }
;
1163 status = CAPS_IOERR-332;
1164 goto cleanup;
1165 }
1166
1167 if (mapGroupID[ID-1] == -1) {
1168 AIM_ERROR(aimStruc, "Unknown BC ID (%d) in %s", ID, filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1168, __func__
, "Unknown BC ID (%d) in %s", ID, filename); }
;
1169 status = CAPS_IOERR-332;
1170 goto cleanup;
1171 }
1172
1173 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"
, 1173, __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", 1173, __func__, 2, "AIM_STRDUP: %s %s"
, "meshData->elemGroups[mapGroupID[ID-1]].groupName", groupName
); goto cleanup; } }
;
1174 }
1175
1176 /*@-dependenttrans@*/
1177 fclose(fpID); fpID = NULL((void*)0);
1178 /*@+dependenttrans@*/
1179 }
1180
1181 mesh->meshData = meshData;
1182 meshData = NULL((void*)0);
1183
1184 status = CAPS_SUCCESS0;
1185
1186cleanup:
1187 if (status != CAPS_SUCCESS0) {
1188 aim_freeMeshData(meshData);
1189 AIM_FREE(meshData){ EG_free(meshData); meshData = ((void*)0); };
1190 }
1191 AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); };
1192
1193 if (volName != NULL((void*)0)) {
1194 for (i = 0; i < nVolName; i++)
1195 AIM_FREE(volName[i]){ EG_free(volName[i]); volName[i] = ((void*)0); };
1196 AIM_FREE(volName){ EG_free(volName); volName = ((void*)0); };
1197 }
1198
1199/*@-dependenttrans@*/
1200 if (fp != NULL((void*)0)) fclose(fp);
1201 if (fpID != NULL((void*)0)) fclose(fpID);
1202 if (fpMV != NULL((void*)0)) fclose(fpMV);
1203/*@+dependenttrans@*/
1204
1205 return status;
1206}
1207
1208
1209int
1210aim_storeMeshRef(void *aimStruc, const aimMeshRef *meshRef,
1211 const char *meshextension)
1212{
1213 int status = CAPS_SUCCESS0;
1214
1215 int imap, ibnd, state, nvert;
1216 int i;
1217 char filename_src[PATH_MAX4096];
1218 char filename_dst[PATH_MAX4096];
1219 char aimFile[PATH_MAX4096];
1220 const char *meshRefFile = "meshRef.dat";
1221 const char *meshRefegads = "meshRef.egads";
1222 FILE *fp = NULL((void*)0);
1223 aimInfo *aInfo;
1224 size_t len, strLen;
1225 ego model, body, *bodies = NULL((void*)0);
1226
1227 aInfo = (aimInfo *) aimStruc;
1228 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1229 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1230
1231 if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
1232 if (meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309;
1233
1234 if (meshextension == NULL((void*)0)) return CAPS_NULLOBJ-309;
1235
1236 // create the full filename to the mesh in the meshing AIM directory
1237 snprintf(filename_src, PATH_MAX4096, "%s%s", meshRef->fileName, meshextension);
1238
1239 // get the mesh filename without the directory
1240 i = strlen(filename_src);
1241 while(i > 0 && filename_src[i] != SLASH'/') { i--; }
1242 if (i < 0) { status = CAPS_IOERR-332; goto cleanup; }
1243 strcpy(filename_dst, filename_src+i+1);
1244
1245 // copy the mesh from the meshing AIM directory to the current AIM directory
1246 status = aim_cpFile(aimStruc, filename_src, filename_dst);
1247 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1247
, __func__, 0); goto cleanup; }
;
1248
1249 // open the file to store the meshRef structure
1250 status = aim_file(aimStruc, meshRefFile, aimFile);
1251 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1251
, __func__, 0); goto cleanup; }
;
1252
1253 fp = fopen(aimFile, "wb");
1254 if (fp == NULL((void*)0)) {
1255 AIM_ERROR(aimStruc, "Cannot open file: %s\n", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1255, __func__
, "Cannot open file: %s\n", aimFile); }
;
1256 status = CAPS_IOERR-332;
1257 goto cleanup;
1258 }
1259
1260 len = fwrite(&meshRef->nmap, sizeof(int), 1, fp);
1261 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1261
, __func__, 0); goto cleanup; }
; }
1262
1263 AIM_ALLOC(bodies, 2*meshRef->nmap, ego, aimStruc, status){ if (bodies != ((void*)0)) { status = -4; aim_status(aimStruc
, status, "aimMesh.c", 1263, __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", 1263, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "bodies", memorysize, "ego"); goto cleanup; } }
;
1264
1265 for (imap = 0; imap < meshRef->nmap; imap++) {
1266 status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert);
1267 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1267
, __func__, 0); goto cleanup; }
;
1268
1269 // construct an egads file to write out the tessellation and the body
1270 status = EG_copyObject(body, NULL((void*)0), &bodies[imap]);
1271 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1271
, __func__, 0); goto cleanup; }
;
1272 status = EG_copyObject(meshRef->maps[imap].tess, bodies[imap], &bodies[imap+meshRef->nmap]);
1273 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1273
, __func__, 0); goto cleanup; }
;
1274
1275 // store the body index
1276 status = EG_attributeAdd(bodies[imap], CAPS_BODY_INDX"--CAPS-BODY-INDX--", ATTRINT1, 1, &imap, NULL((void*)0), NULL((void*)0));
1277 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1277
, __func__, 0); goto cleanup; }
;
1278 }
1279
1280 status = EG_makeTopology(aInfo->problem->context, NULL((void*)0), MODEL26, 2*meshRef->nmap,
1281 NULL((void*)0), meshRef->nmap, bodies, NULL((void*)0), &model);
1282 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1282
, __func__, 0); goto cleanup; }
;
1283
1284 status = aim_file(aimStruc, meshRefegads, aimFile);
1285 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1285
, __func__, 0); goto cleanup; }
;
1286
1287 remove(aimFile);
1288 status = EG_saveModel(model, aimFile);
1289 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1289
, __func__, 0); goto cleanup; }
;
1290
1291 EG_deleteObject(model);
1292
1293 for (imap = 0; imap < meshRef->nmap; imap++) {
1294 status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert);
1295 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1295
, __func__, 0); goto cleanup; }
;
1296
1297 // write the surface to volume map
1298 len = fwrite(meshRef->maps[imap].map, sizeof(int), nvert, fp);
1299 if (len != nvert) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1299
, __func__, 0); goto cleanup; }
; }
1300 }
1301
1302 len = fwrite(&meshRef->nbnd, sizeof(int), 1, fp);
1303 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1303
, __func__, 0); goto cleanup; }
; }
1304
1305 for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) {
1306
1307 strLen = strlen(meshRef->bnds[ibnd].groupName)+1;
1308
1309 len = fwrite(&strLen, sizeof(size_t), 1, fp);
1310 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1310
, __func__, 0); goto cleanup; }
; }
1311
1312 len = fwrite(meshRef->bnds[ibnd].groupName, sizeof(char), strLen, fp);
1313 if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1313
, __func__, 0); goto cleanup; }
; }
1314
1315 len = fwrite(&meshRef->bnds[ibnd].ID, sizeof(int), 1, fp);
1316 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1316
, __func__, 0); goto cleanup; }
; }
1317 }
1318
1319 // write meshRef->filename (i.e. filename_dst without the extension)
1320 strLen = strlen(filename_dst);
1321 filename_dst[strLen - strlen(meshextension)] = '\0';
1322 status = aim_file(aimStruc, filename_dst, aimFile);
1323 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1323
, __func__, 0); goto cleanup; }
;
1324
1325 strLen = strlen(aimFile)+1;
1326
1327 len = fwrite(&strLen, sizeof(size_t), 1, fp);
1328 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1328
, __func__, 0); goto cleanup; }
; }
1329
1330 len = fwrite(aimFile, sizeof(char), strLen, fp);
1331 if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1331
, __func__, 0); goto cleanup; }
; }
1332
1333cleanup:
1334 /*@-dependenttrans@*/
1335 if (fp != NULL((void*)0)) fclose(fp);
1336 /*@+dependenttrans@*/
1337 AIM_FREE(bodies){ EG_free(bodies); bodies = ((void*)0); };
1338
1339 return status;
1340}
1341
1342
1343int
1344aim_loadMeshRef(void *aimStruc, aimMeshRef *meshRef)
1345{
1346 int status = CAPS_SUCCESS0;
1347
1348 int j, imap, ibnd, state, nvert, nbody;
1349 int oclass, mtype, *senses, alen, atype;
1350 char aimFile[PATH_MAX4096];
1351 double limits[4];
1352 const int *aints=NULL((void*)0);
1353 const double *areals=NULL((void*)0);
1354 const char *astring=NULL((void*)0);
1355 const char *meshRefFile = "meshRef.dat";
1356 const char *meshRefegads = "meshRef.egads";
1357 FILE *fp = NULL((void*)0);
1358 aimInfo *aInfo;
1359 size_t len, strLen;
1360 ego geom, model, body, tessbody, *bodies;
1361
1362 aInfo = (aimInfo *) aimStruc;
1363 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1364 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1365
1366 if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
1367 if (meshRef->nmap != 0 ||
1368 meshRef->maps != NULL((void*)0) ||
1369 meshRef->nbnd != 0 ||
1370 meshRef->bnds != NULL((void*)0) ||
1371 meshRef->fileName != NULL((void*)0) ) {
1372 AIM_ERROR(aimStruc, "meshRef members not initialized to NULL values!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1372, __func__
, "meshRef members not initialized to NULL values!"); }
;
1373 status = CAPS_NULLOBJ-309;
1374 goto cleanup;
1375 }
1376
1377 // open the file to read the meshRef structure
1378 status = aim_file(aimStruc, meshRefFile, aimFile);
1379 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1379
, __func__, 0); goto cleanup; }
;
1380
1381 fp = fopen(aimFile, "rb");
1382 if (fp == NULL((void*)0)) {
1383 AIM_ERROR(aimStruc, "Cannot open file: %s\n", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1383, __func__
, "Cannot open file: %s\n", aimFile); }
;
1384 status = CAPS_IOERR-332;
1385 goto cleanup;
1386 }
1387
1388 len = fread(&meshRef->nmap, sizeof(int), 1, fp);
1389 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1389
, __func__, 0); goto cleanup; }
; }
1390
1391 AIM_ALLOC(meshRef->maps, meshRef->nmap, aimMeshTessMap, aimStruc, status){ if (meshRef->maps != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 1391, __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", 1391
, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->maps"
, memorysize, "aimMeshTessMap"); goto cleanup; } }
;
1392 for (imap = 0; imap < meshRef->nmap; imap++) {
1393 meshRef->maps[imap].tess = NULL((void*)0);
1394 meshRef->maps[imap].map = NULL((void*)0);
1395 }
1396
1397 status = aim_file(aimStruc, meshRefegads, aimFile);
1398 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1398
, __func__, 0); goto cleanup; }
;
1399
1400 status = EG_loadModel(aInfo->problem->context, 0, aimFile, &model);
1401 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1401
, __func__, 0); goto cleanup; }
;
1402
1403 status = EG_getTopology(model, &geom, &oclass, &mtype, limits,
1404 &nbody, &bodies, &senses);
1405 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1405
, __func__, 0); goto cleanup; }
;
1406
1407 if (nbody != meshRef->nmap) {
1408 AIM_ERROR(aimStruc, "Missmatch between %s and %s!", meshRefFile, meshRefegads){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1408, __func__
, "Missmatch between %s and %s!", meshRefFile, meshRefegads);
}
;
1409 status = CAPS_IOERR-332;
1410 goto cleanup;
1411 }
1412
1413 // copy the body and tessellatoin out of the model
1414 for (imap = 0; imap < meshRef->nmap; imap++) {
1415 status = EG_copyObject(bodies[imap], NULL((void*)0), &body);
1416 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1416
, __func__, 0); goto cleanup; }
;
1417
1418 // get the original body index
1419 status = EG_attributeRet(body, CAPS_BODY_INDX"--CAPS-BODY-INDX--", &atype, &alen, &aints, &areals, &astring);
1420 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1420
, __func__, 0); goto cleanup; }
;
1421 AIM_NOTNULL(aints, aimStruc, status){ if (aints == ((void*)0)) { status = -307; aim_status(aimStruc
, status, "aimMesh.c", 1421, __func__, 1, "%s == NULL!", "aints"
); goto cleanup; } }
;
1422
1423 status = EG_attributeDel(body, CAPS_BODY_INDX"--CAPS-BODY-INDX--");
1424 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1424
, __func__, 0); goto cleanup; }
;
1425
1426 // find the tessellation for this body
1427 for (j = 0; j < meshRef->nmap; j++) {
1428 status = EG_statusTessBody(bodies[j+meshRef->nmap], &tessbody, &state, &nvert);
1429 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1429
, __func__, 0); goto cleanup; }
;
1430
1431 if (tessbody == bodies[imap]) {
1432 // copy the tessellation with the copied body
1433 status = EG_copyObject(bodies[j+meshRef->nmap], body, &meshRef->maps[aints[0]].tess);
1434 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1434
, __func__, 0); goto cleanup; }
;
1435 break;
1436 }
1437 }
1438 }
1439
1440 // delete the model
1441 EG_deleteObject(model);
1442
1443 for (imap = 0; imap < meshRef->nmap; imap++) {
1444 // read the surface to volume map
1445 status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert);
1446 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1446
, __func__, 0); goto cleanup; }
;
1447
1448 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", 1448, __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", 1448, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "meshRef->maps[imap].map", memorysize, "int"); goto cleanup
; } }
;
1449
1450 len = fread(meshRef->maps[imap].map, sizeof(int), nvert, fp);
1451 if (len != nvert) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1451
, __func__, 0); goto cleanup; }
; }
1452 }
1453
1454 // read the bounds
1455 len = fread(&meshRef->nbnd, sizeof(int), 1, fp);
1456 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1456
, __func__, 0); goto cleanup; }
; }
1457
1458 AIM_ALLOC(meshRef->bnds, meshRef->nbnd, aimMeshBnd, aimStruc, status){ if (meshRef->bnds != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 1458, __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", 1458, __func__
, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->bnds", memorysize
, "aimMeshBnd"); goto cleanup; } }
;
1459 for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) {
1460 meshRef->bnds[ibnd].groupName = NULL((void*)0);
1461 meshRef->bnds[ibnd].ID = 0;
1462 }
1463
1464 for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) {
1465
1466 len = fread(&strLen, sizeof(size_t), 1, fp);
1467 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1467
, __func__, 0); goto cleanup; }
; }
1468
1469 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", 1469, __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", 1469, __func__
, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->bnds[ibnd].groupName"
, memorysize, "char"); goto cleanup; } }
;
1470
1471 len = fread(meshRef->bnds[ibnd].groupName, sizeof(char), strLen, fp);
1472 if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1472
, __func__, 0); goto cleanup; }
; }
1473
1474 len = fread(&meshRef->bnds[ibnd].ID, sizeof(int), 1, fp);
1475 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1475
, __func__, 0); goto cleanup; }
; }
1476 }
1477
1478 // read meshRef->filename
1479 len = fread(&strLen, sizeof(size_t), 1, fp);
1480 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1480
, __func__, 0); goto cleanup; }
; }
1481
1482 AIM_ALLOC(meshRef->fileName, strLen, char, aimStruc, status){ if (meshRef->fileName != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 1482, __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", 1482, __func__
, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->fileName"
, memorysize, "char"); goto cleanup; } }
;
1483
1484 len = fread(meshRef->fileName, sizeof(char), strLen, fp);
1485 if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1485
, __func__, 0); goto cleanup; }
; }
1486
1487 // indicate that the tessellation and body should be deleted
1488 meshRef->_delTess = (int)true1;
1489
1490cleanup:
1491 /*@-dependenttrans@*/
1492 if (fp != NULL((void*)0)) fclose(fp);
1493 /*@+dependenttrans@*/
1494
1495 return status;
1496}
1497
1498
1499// Map the old surface tessellation on to the new bodies
1500int aim_morphMeshUpdate(void *aimInfo, aimMeshRef *meshRef, int numBody, ego *bodies)
1501{
1502 int status = CAPS_SUCCESS0;
1503 int i=0,j, localIndex, topoIndex, iglobal_old, iglobal_new;
1504 int state, numVert, aType, alen, *map_old=NULL((void*)0);
1505 const int *nMap, *eMap, *fMap;
1
'eMap' declared without an initial value
1506 ego body, tessbody;
1507 ego tess;
1508
1509 // Have the number of bodies changed?
1510 if (meshRef->nmap != numBody) {
2
Assuming 'numBody' is equal to field 'nmap'
3
Taking false branch
1511 AIM_ERROR(aimInfo, "The number of original surface meshes does NOT equal the number of current bodies!\n"){ aim_message(aimInfo, CERROR, 0 , "aimMesh.c", 1511, __func__
, "The number of original surface meshes does NOT equal the number of current bodies!\n"
); }
;
1512 status = CAPS_MISMATCH-324;
1513 goto cleanup;
1514 }
1515
1516 // Are the bodies topological equivalent?
1517 for (i = 0; i < meshRef->nmap; i++) {
4
Assuming 'i' is < field 'nmap'
5
Loop condition is true. Entering loop body
10
Assuming 'i' is >= field 'nmap'
11
Loop condition is false. Execution continues on line 1530
1518
1519 status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &numVert);
1520 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1520
, __func__, 0); goto cleanup; }
;
6
Assuming 'status' is equal to 0
7
Taking false branch
1521
1522 status = EG_mapBody(body, bodies[i], "_faceID", &bodies[i]); // "_faceID" - same as in OpenCSM
1523 if (status != EGADS_SUCCESS0) {
8
Assuming 'status' is equal to EGADS_SUCCESS
9
Taking false branch
1524 AIM_ERROR(aimInfo, "New and old body %d (of %d) do not appear to be topologically equivalent!", i+1, meshRef->nmap){ aim_message(aimInfo, CERROR, 0 , "aimMesh.c", 1524, __func__
, "New and old body %d (of %d) do not appear to be topologically equivalent!"
, i+1, meshRef->nmap); }
;
1525 goto cleanup;
1526 }
1527 }
1528
1529 // Now lets "tweak" the surface tessellation - map the old tessellation to the new bodies
1530 for (i = 0; i < meshRef->nmap; i++) {
12
Loop condition is true. Entering loop body
1531
1532 status = EG_statusTessBody(meshRef->maps[i].tess, &tessbody, &state, &numVert);
1533 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1533
, __func__, 0); goto cleanup; }
;
13
Assuming 'status' is equal to 0
14
Taking false branch
1534
1535 // nothing to do if bodies are the same
1536 if (tessbody == bodies[i]) continue;
15
Assuming the condition is false
16
Taking false branch
1537
1538 printf("Projecting tessellation %d (of %d) on to new body\n", i+1, meshRef->nmap);
1539
1540 status = EG_mapTessBody(meshRef->maps[i].tess,
1541 bodies[i],
1542 &tess);
1543 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1543
, __func__, 0); goto cleanup; }
;
17
Assuming 'status' is equal to 0
18
Taking false branch
1544
1545 status = EG_attributeRet(bodies[i], ".fMap", &aType, &alen, &fMap, NULL((void*)0), NULL((void*)0));
1546 if (status == EGADS_SUCCESS0) {
19
Assuming 'status' is not equal to EGADS_SUCCESS
20
Taking false branch
1547 status = EG_attributeRet(bodies[i], ".eMap", &aType, &alen, &eMap, NULL((void*)0), NULL((void*)0));
1548 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1548
, __func__, 0); goto cleanup; }
;
1549 status = EG_attributeRet(bodies[i], ".nMap", &aType, &alen, &nMap, NULL((void*)0), NULL((void*)0));
1550 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1550
, __func__, 0); goto cleanup; }
;
1551 }
1552
1553 // update the surface to volume mapping
1554 if (fMap != NULL((void*)0)) {
21
Assuming 'fMap' is not equal to NULL
22
Taking true branch
1555 AIM_NOTNULL(eMap, aimInfo, status){ if (eMap == ((void*)0)) { status = -307; aim_status(aimInfo
, status, "aimMesh.c", 1555, __func__, 1, "%s == NULL!", "eMap"
); goto cleanup; } }
;
23
The left operand of '==' is a garbage value
1556 AIM_NOTNULL(nMap, aimInfo, status){ if (nMap == ((void*)0)) { status = -307; aim_status(aimInfo
, status, "aimMesh.c", 1556, __func__, 1, "%s == NULL!", "nMap"
); goto cleanup; } }
;
1557
1558 // update the mapping into the volume
1559 map_old = meshRef->maps[i].map;
1560 meshRef->maps[i].map = NULL((void*)0);
1561
1562 AIM_ALLOC(meshRef->maps[i].map, numVert, int, aimInfo, status){ if (meshRef->maps[i].map != ((void*)0)) { status = -4; aim_status
(aimInfo, status, "aimMesh.c", 1562, __func__, 1, "AIM_ALLOC: %s != NULL"
, "meshRef->maps[i].map"); goto cleanup; } size_t memorysize
= numVert; meshRef->maps[i].map = (int *) EG_alloc(memorysize
*sizeof(int)); if (meshRef->maps[i].map == ((void*)0)) { status
= -4; aim_status(aimInfo, status, "aimMesh.c", 1562, __func__
, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->maps[i].map"
, memorysize, "int"); goto cleanup; } }
;
1563
1564 // Find the boundary mesh in the global tessellation
1565 for (j = 0; j < numVert; j++) {
1566
1567 iglobal_old = j+1;
1568 // Get the local indexes
1569 status = EG_getGlobal(meshRef->maps[i].tess, iglobal_old,
1570 &localIndex, &topoIndex, NULL((void*)0));
1571 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1571
, __func__, 0); goto cleanup; }
;
1572
1573 // Get the global index in the new tess
1574 if (localIndex == 0) {
1575 status = EG_localToGlobal(tess, localIndex, nMap[topoIndex-1], &iglobal_new);
1576 AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", nMap[topoIndex-1], localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1576
, __func__, 3, "ptype = %d, pindex = %d", nMap[topoIndex-1], localIndex
); goto cleanup; }
;
1577 } else if (localIndex > 0) {
1578 status = EG_localToGlobal(tess, -eMap[topoIndex-1], localIndex, &iglobal_new);
1579 AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", eMap[topoIndex-1], localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1579
, __func__, 3, "ptype = %d, pindex = %d", eMap[topoIndex-1], localIndex
); goto cleanup; }
;
1580 } else {
1581 status = EG_localToGlobal(tess, fMap[topoIndex-1], -localIndex, &iglobal_new);
1582 AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", fMap[topoIndex-1], -localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1582
, __func__, 3, "ptype = %d, pindex = %d", fMap[topoIndex-1], -
localIndex); goto cleanup; }
;
1583 }
1584
1585 meshRef->maps[i].map[iglobal_new-1] = map_old[iglobal_old-1];
1586 }
1587 }
1588
1589 // store the new tessellation
1590 if (meshRef->_delTess == (int)true1) {
1591 EG_deleteObject(meshRef->maps[i].tess);
1592 EG_deleteObject(tessbody);
1593 }
1594 meshRef->maps[i].tess = tess;
1595 status = aim_newTess(aimInfo, tess);
1596 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1596
, __func__, 0); goto cleanup; }
;
1597
1598 AIM_FREE(map_old){ EG_free(map_old); map_old = ((void*)0); };
1599 }
1600
1601 meshRef->_delTess = (int)false0;
1602
1603cleanup:
1604 AIM_FREE(map_old){ EG_free(map_old); map_old = ((void*)0); };
1605 return status;
1606}