Bug Summary

File:src/aimMesh.c
Warning:line 1503, column 27
Null pointer passed to 1st parameter expecting 'nonnull'

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-09-12-170855-27566-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_SUCCESS0;
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, const enum aimMeshType type)
494{
495 if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
496
497 meshRef->type = type;
498 meshRef->nmap = 0;
499 meshRef->maps = NULL((void*)0);
500 meshRef->nbnd = 0;
501 meshRef->bnds = NULL((void*)0);
502 meshRef->fileName = NULL((void*)0);
503 meshRef->_delTess = (int)false0;
504
505 return CAPS_SUCCESS0;
506}
507
508
509int
510aim_freeMeshRef(/*@null@*/ aimMeshRef *meshRef)
511{
512 int status = CAPS_SUCCESS0;
513 int i, state, nvert;
514 ego body;
515
516 if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
517
518 if (meshRef->maps != NULL((void*)0))
519 for (i = 0; i < meshRef->nmap; i++) {
520 AIM_FREE(meshRef->maps[i].map){ EG_free(meshRef->maps[i].map); meshRef->maps[i].map =
((void*)0); }
;
521
522 if (meshRef->_delTess == (int)true1) {
523 status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &nvert);
524 if (status != CAPS_SUCCESS0) return status;
525
526 EG_deleteObject(meshRef->maps[i].tess);
527 EG_deleteObject(body);
528 }
529 }
530
531 if (meshRef->bnds != NULL((void*)0))
532 for (i = 0; i < meshRef->nbnd; i++)
533 AIM_FREE(meshRef->bnds[i].groupName){ EG_free(meshRef->bnds[i].groupName); meshRef->bnds[i]
.groupName = ((void*)0); }
;
534
535 AIM_FREE(meshRef->maps){ EG_free(meshRef->maps); meshRef->maps = ((void*)0); };
536 AIM_FREE(meshRef->bnds){ EG_free(meshRef->bnds); meshRef->bnds = ((void*)0); };
537 AIM_FREE(meshRef->fileName){ EG_free(meshRef->fileName); meshRef->fileName = ((void
*)0); }
;
538
539 aim_initMeshRef(meshRef, aimUnknownMeshType);
540
541 return CAPS_SUCCESS0;
542}
543
544
545int
546aim_initMeshData(aimMeshData *meshData)
547{
548 if (meshData == NULL((void*)0)) return CAPS_NULLOBJ-309;
549
550 meshData->dim = 0;
551
552 meshData->nVertex = 0;
553 meshData->verts = NULL((void*)0);
554
555 meshData->nElemGroup = 0;
556 meshData->elemGroups = NULL((void*)0);
557
558 meshData->nTotalElems = 0;
559 meshData->elemMap = NULL((void*)0);
560
561 return CAPS_SUCCESS0;
562}
563
564
565int
566aim_freeMeshData(/*@null@*/ aimMeshData *meshData)
567{
568 int i;
569 if (meshData == NULL((void*)0)) return CAPS_SUCCESS0;
570
571 AIM_FREE(meshData->verts){ EG_free(meshData->verts); meshData->verts = ((void*)0
); }
;
572
573 for (i = 0; i < meshData->nElemGroup; i++) {
574 AIM_FREE(meshData->elemGroups[i].groupName){ EG_free(meshData->elemGroups[i].groupName); meshData->
elemGroups[i].groupName = ((void*)0); }
;
575 AIM_FREE(meshData->elemGroups[i].elements){ EG_free(meshData->elemGroups[i].elements); meshData->
elemGroups[i].elements = ((void*)0); }
;
576 }
577 AIM_FREE(meshData->elemGroups){ EG_free(meshData->elemGroups); meshData->elemGroups =
((void*)0); }
;
578
579 AIM_FREE(meshData->elemMap){ EG_free(meshData->elemMap); meshData->elemMap = ((void
*)0); }
;
580
581 aim_initMeshData(meshData);
582
583 return CAPS_SUCCESS0;
584}
585
586
587int
588aim_addMeshElemGroup(void *aimStruc,
589 /*@null@*/ const char* groupName,
590 int ID,
591 enum aimMeshElem elementTopo,
592 int order,
593 int nPoint,
594 aimMeshData *meshData)
595{
596 int status = CAPS_SUCCESS0;
597
598 /* resize the element group */
599 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"
, 599, __func__, 3, "AIM_REALL: %s size %zu type %s", "meshData->elemGroups"
, memorysize, "aimMeshElemGroup"); goto cleanup; } }
;
600
601 meshData->elemGroups[meshData->nElemGroup].groupName = NULL((void*)0);
602 meshData->elemGroups[meshData->nElemGroup].ID = ID;
603 meshData->elemGroups[meshData->nElemGroup].elementTopo = elementTopo;
604 meshData->elemGroups[meshData->nElemGroup].order = order;
605 meshData->elemGroups[meshData->nElemGroup].nPoint = nPoint;
606 meshData->elemGroups[meshData->nElemGroup].nElems = 0;
607 meshData->elemGroups[meshData->nElemGroup].elements = NULL((void*)0);
608
609 if (groupName != NULL((void*)0))
610 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"
, 610, __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", 610, __func__,
2, "AIM_STRDUP: %s %s", "meshData->elemGroups[meshData->nElemGroup].groupName"
, groupName); goto cleanup; } }
;
611
612 meshData->nElemGroup++;
613
614cleanup:
615 return status;
616}
617
618
619int
620aim_addMeshElem(void *aimStruc,
621 int nElems,
622 aimMeshElemGroup *elemGroup)
623{
624 int status = CAPS_SUCCESS0;
625
626 /* resize the element group */
627 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"
, 627, __func__, 3, "AIM_REALL: %s size %zu type %s", "elemGroup->elements"
, memorysize, "int"); goto cleanup; } }
;
628
629 elemGroup->nElems += nElems;
630
631cleanup:
632 return status;
633}
634
635
636int
637aim_surfaceMeshData(void *aimStruc, aimMesh *mesh)
638{
639 int status = CAPS_SUCCESS0;
640
641 //int nLine=0, nTri=0, nQuad=0;
642 int i, j, ivert, nPoint;
643 int nEdge, iedge, nFace, iface;
644 int ptype, pindex, plen, tlen;
645 int nglobal, state, elem[4];
646 int edgeOffset, faceOffset;
647 const double *points, *uv, *t;
648 const int *ptypes, *pindexs, *tris, *tric;
649 double xyz[3];
650 enum aimMeshElem elementTopo;
651 aimMeshData *meshData = NULL((void*)0);
652 aimMeshRef *meshRef = NULL((void*)0);
653 ego body, *edges;
654
655 if (mesh == NULL((void*)0)) return CAPS_NULLOBJ-309;
656 if (mesh->meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
657 if (mesh->meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309;
658
659 meshRef = mesh->meshRef;
660
661 status = aim_freeMeshData(mesh->meshData);
662 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 662
, __func__, 0); goto cleanup; }
;
663 AIM_FREE(mesh->meshData){ EG_free(mesh->meshData); mesh->meshData = ((void*)0);
}
;
664
665 AIM_ALLOC(meshData, 1, aimMeshData, aimStruc, status){ if (meshData != ((void*)0)) { status = -4; aim_status(aimStruc
, status, "aimMesh.c", 665, __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", 665, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "meshData", memorysize, "aimMeshData"); goto cleanup; } }
;
666 status = aim_initMeshData(meshData);
667 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 667
, __func__, 0); goto cleanup; }
;
668
669 meshData->dim = 3;
670
671 for (i = 0; i < meshRef->nmap; i++) {
672 status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &nglobal);
673 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 673
, __func__, 0); goto cleanup; }
;
674 meshData->nVertex += nglobal;
675
676 status = EG_getBodyTopos(body, NULL((void*)0), EDGE21, &nEdge, &edges);
677 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 677
, __func__, 0); goto cleanup; }
;
678
679 for (iedge = 0; iedge < nEdge; iedge++) {
680 if (edges[iedge]->mtype == DEGENERATE5) continue;
681 status = EG_getTessEdge(meshRef->maps[i].tess, iedge + 1, &plen, &points, &t);
682 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 682
, __func__, 0); goto cleanup; }
;
683 //nLine += plen-1;
684 }
685 AIM_FREE(edges){ EG_free(edges); edges = ((void*)0); };
686
687 status = EG_getBodyTopos(body, NULL((void*)0), FACE23, &nFace, NULL((void*)0));
688 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 688
, __func__, 0); goto cleanup; }
;
689
690 for (iface = 0; iface < nFace; iface++) {
691 status = EG_getTessFace(meshRef->maps[i].tess, iface + 1, &plen, &points, &uv, &ptypes, &pindexs,
692 &tlen, &tris, &tric);
693 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 693
, __func__, 0); goto cleanup; }
;
694 //nTri += tlen;
695 }
696 }
697
698 AIM_ALLOC(meshData->verts, meshData->nVertex, aimMeshCoords, aimStruc, status){ if (meshData->verts != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 698, __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"
, 698, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshData->verts"
, memorysize, "aimMeshCoords"); goto cleanup; } }
;
699
700 // Get vertex values
701 ivert = 0;
702 for (i = 0; i < meshRef->nmap; i++) {
703 status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &nglobal);
704 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 704
, __func__, 0); goto cleanup; }
;
705
706 for (j = 0; j < nglobal; j++) {
707 status = EG_getGlobal(meshRef->maps[i].tess, j + 1, &ptype, &pindex, xyz);
708 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 708
, __func__, 0); goto cleanup; }
;
709
710 meshData->verts[ivert][0] = xyz[0];
711 meshData->verts[ivert][1] = xyz[1];
712 meshData->verts[ivert][2] = xyz[2];
713 ivert++;
714 }
715 }
716
717 // Get line elements on each edge
718 nPoint = 2;
719 elementTopo = aimLine;
720 ivert = edgeOffset = 0;
721 for (i = 0; i < meshRef->nmap; i++) {
722 status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &nglobal);
723 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 723
, __func__, 0); goto cleanup; }
;
724
725 status = EG_getBodyTopos(body, NULL((void*)0), EDGE21, &nEdge, NULL((void*)0));
726 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 726
, __func__, 0); goto cleanup; }
;
727
728 for (iedge = 0; iedge < nEdge; iedge++) {
729 status = EG_getTessEdge(meshRef->maps[i].tess, iedge + 1, &plen, &points, &t);
730 if (status == EGADS_DEGEN-24) continue;
731 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 731
, __func__, 0); goto cleanup; }
;
732
733 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), iedge+edgeOffset+1, elementTopo, 1, nPoint, meshData);
734 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 734
, __func__, 0); goto cleanup; }
;
735
736 /* add the element to the group */
737 status = aim_addMeshElem(aimStruc, plen-1, &meshData->elemGroups[iedge+edgeOffset]);
738 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 738
, __func__, 0); goto cleanup; }
;
739
740 for (j = 0; j < plen-1; j++) {
741 status = EG_localToGlobal(meshRef->maps[i].tess, -(iedge + 1), j + 1, &elem[0]);
742 if (status == EGADS_DEGEN-24) continue;
743 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 743
, __func__, 0); goto cleanup; }
;
744
745 status = EG_localToGlobal(meshRef->maps[i].tess, -(iedge + 1), j + 2, &elem[1]);
746 if (status == EGADS_DEGEN-24) continue;
747 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 747
, __func__, 0); goto cleanup; }
;
748
749 meshData->elemGroups[iedge+edgeOffset].elements[nPoint*j + 0] = elem[0] + ivert;
750 meshData->elemGroups[iedge+edgeOffset].elements[nPoint*j + 1] = elem[1] + ivert;
751 }
752 }
753
754 edgeOffset += nEdge;
755 ivert += nglobal;
756 }
757
758
759 // Get tri elements on each face
760 nPoint = 3;
761 elementTopo = aimTri;
762 ivert = 0;
763 faceOffset = edgeOffset;
764 for (i = 0; i < meshRef->nmap; i++) {
765 status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &nglobal);
766 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 766
, __func__, 0); goto cleanup; }
;
767
768 status = EG_getBodyTopos(body, NULL((void*)0), FACE23, &nFace, NULL((void*)0));
769 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 769
, __func__, 0); goto cleanup; }
;
770
771 for (iface = 0; iface < nFace; iface++) {
772 status = EG_getTessFace(meshRef->maps[i].tess, iface + 1, &plen, &points, &uv, &ptypes, &pindexs,
773 &tlen, &tris, &tric);
774 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 774
, __func__, 0); goto cleanup; }
;
775
776 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), iface+faceOffset+1, elementTopo, 1, nPoint, meshData);
777 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 777
, __func__, 0); goto cleanup; }
;
778
779 /* add the element to the group */
780 status = aim_addMeshElem(aimStruc, tlen, &meshData->elemGroups[iface+faceOffset]);
781 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 781
, __func__, 0); goto cleanup; }
;
782
783 for (j = 0; j < tlen; j++) {
784 status = EG_localToGlobal(meshRef->maps[i].tess, iface + 1, tris[3*j + 0], &elem[0]);
785 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 785
, __func__, 0); goto cleanup; }
;
786 status = EG_localToGlobal(meshRef->maps[i].tess, iface + 1, tris[3*j + 1], &elem[1]);
787 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 787
, __func__, 0); goto cleanup; }
;
788 status = EG_localToGlobal(meshRef->maps[i].tess, iface + 1, tris[3*j + 2], &elem[2]);
789 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 789
, __func__, 0); goto cleanup; }
;
790
791
792 meshData->elemGroups[iface+faceOffset].elements[nPoint*j + 0] = elem[0] + ivert;
793 meshData->elemGroups[iface+faceOffset].elements[nPoint*j + 1] = elem[1] + ivert;
794 meshData->elemGroups[iface+faceOffset].elements[nPoint*j + 2] = elem[2] + ivert;
795 }
796 }
797
798 faceOffset += nFace;
799 ivert += nglobal;
800 }
801
802 mesh->meshData = meshData;
803 meshData = NULL((void*)0);
804
805 status = CAPS_SUCCESS0;
806
807cleanup:
808 return status;
809}
810
811
812int
813aim_readBinaryUgridHeader(void *aimStruc, aimMeshRef *meshRef,
814 int *nVertex, int *nTri, int *nQuad,
815 int *nTet, int *nPyramid, int *nPrism, int *nHex)
816{
817 int status = CAPS_SUCCESS0;
818
819 char filename[PATH_MAX4096];
820 FILE *fp = NULL((void*)0);
821
822 if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
823 if (meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309;
824
825 snprintf(filename, PATH_MAX4096, "%s%s", meshRef->fileName, ".lb8.ugrid");
826
827 fp = fopen(filename, "rb");
828 if (fp == NULL((void*)0)) {
829 AIM_ERROR(aimStruc, "Cannot open file: %s\n", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 829, __func__
, "Cannot open file: %s\n", filename); }
;
830 status = CAPS_IOERR-332;
831 goto cleanup;
832 }
833
834 /* read a binary UGRID file */
835 status = fread(nVertex, sizeof(int), 1, fp);
836 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 836
, __func__, 0); goto cleanup; }
; }
837 status = fread(nTri, sizeof(int), 1, fp);
838 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 838
, __func__, 0); goto cleanup; }
; }
839 status = fread(nQuad, sizeof(int), 1, fp);
840 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 840
, __func__, 0); goto cleanup; }
; }
841 status = fread(nTet, sizeof(int), 1, fp);
842 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 842
, __func__, 0); goto cleanup; }
; }
843 status = fread(nPyramid, sizeof(int), 1, fp);
844 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 844
, __func__, 0); goto cleanup; }
; }
845 status = fread(nPrism, sizeof(int), 1, fp);
846 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 846
, __func__, 0); goto cleanup; }
; }
847 status = fread(nHex, sizeof(int), 1, fp);
848 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 848
, __func__, 0); goto cleanup; }
; }
849
850 status = CAPS_SUCCESS0;
851
852cleanup:
853/*@-dependenttrans@*/
854 if (fp != NULL((void*)0)) fclose(fp);
855/*@+dependenttrans@*/
856 fp = NULL((void*)0);
857 return status;
858}
859
860
861static int
862aim_readBinaryUgridElements(void *aimStruc, FILE *fp, /*@null@*/ FILE *fpMV, /*@null@*/ char **volName,
863 int nPoint, enum aimMeshElem elementTopo, int nElems,
864 int *elementIndex, aimMeshData *meshData)
865{
866 int status = CAPS_SUCCESS0;
867 int i, j, ID, igroup;
868 int nMapGroupID = 0;
869 int *mapGroupID = NULL((void*)0);
870
871 if (nElems > 0) {
872
873 if (fpMV != NULL((void*)0)) {
874 AIM_NOTNULL(volName, aimStruc, status){ if (volName == ((void*)0)) { status = -307; aim_status(aimStruc
, status, "aimMesh.c", 874, __func__, 1, "%s == NULL!", "volName"
); goto cleanup; } }
;
875
876 for (i = 0; i < nElems; i++) {
877
878 /* read the volume ID */
879 status = fread(&ID, sizeof(int), 1, fpMV);
880 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 880
, __func__, 0); goto cleanup; }
; }
881 if (ID <= 0) {
882 AIM_ERROR(aimStruc, "Volume ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 882, __func__
, "Volume ID must be a positive number: %d!", ID); }
;
883 status = CAPS_IOERR-332;
884 goto cleanup;
885 }
886
887 /* add the volume group if necessary */
888 if (ID > nMapGroupID) {
889 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", 889, __func__
, 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize
, "int"); goto cleanup; } }
;
890 for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1;
891 nMapGroupID = ID;
892 }
893 if (mapGroupID[ID-1] == -1) {
894 status = aim_addMeshElemGroup(aimStruc, volName[ID-1], ID, elementTopo, 1, nPoint, meshData);
895 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 895
, __func__, 0); goto cleanup; }
;
896 mapGroupID[ID-1] = meshData->nElemGroup-1;
897 }
898
899 igroup = mapGroupID[ID-1];
900
901 /* add the element to the group */
902 status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]);
903 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 903
, __func__, 0); goto cleanup; }
;
904
905 /* read the element connectivity */
906 status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems-1)],
907 sizeof(int), nPoint, fp);
908 if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 908
, __func__, 0); goto cleanup; }
; }
909
910 meshData->elemMap[*elementIndex][0] = igroup;
911 meshData->elemMap[*elementIndex][1] = meshData->elemGroups[igroup].nElems-1;
912
913 *elementIndex += 1;
914 }
915
916 } else {
917
918 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), 1, elementTopo, 1, nPoint, meshData);
919 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 919
, __func__, 0); goto cleanup; }
;
920
921 igroup = meshData->nElemGroup-1;
922
923 /* add the elements to the group */
924 status = aim_addMeshElem(aimStruc, nElems, &meshData->elemGroups[igroup]);
925 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 925
, __func__, 0); goto cleanup; }
;
926
927 /* read the element connectivity */
928 status = fread(meshData->elemGroups[igroup].elements,
929 sizeof(int), nPoint*nElems, fp);
930 if (status != nPoint*nElems) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 930
, __func__, 0); goto cleanup; }
; }
931
932 for (i = 0; i < nElems; i++) {
933 meshData->elemMap[*elementIndex][0] = igroup;
934 meshData->elemMap[*elementIndex][1] = i;
935
936 *elementIndex += 1;
937 }
938 }
939 }
940
941 status = CAPS_SUCCESS0;
942cleanup:
943
944 AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); };
945
946 return status;
947}
948
949
950int
951aim_readBinaryUgrid(void *aimStruc, aimMesh *mesh)
952{
953 int status = CAPS_SUCCESS0;
954
955 int nLine, nTri, nQuad;
956 int nTet, nPyramid, nPrism, nHex;
957 int i, j, elementIndex, nPoint, nElems, ID, igroup;
958 int line[2], *mapGroupID=NULL((void*)0), nMapGroupID=0;
959 int nRegion = 0, nVolName=0, nmap=0, nID;
960 enum aimMeshElem elementTopo;
961 char filename[PATH_MAX4096], groupName[PATH_MAX4096], **volName=NULL((void*)0);
962 size_t len;
963 FILE *fp = NULL((void*)0), *fpID = NULL((void*)0), *fpMV=NULL((void*)0);
964 aimMeshData *meshData = NULL((void*)0);
965
966 if (mesh == NULL((void*)0)) return CAPS_NULLOBJ-309;
967 if (mesh->meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
968 if (mesh->meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309;
969
970 status = aim_freeMeshData(mesh->meshData);
971 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 971
, __func__, 0); goto cleanup; }
;
972 AIM_FREE(mesh->meshData){ EG_free(mesh->meshData); mesh->meshData = ((void*)0);
}
;
973
974 AIM_ALLOC(meshData, 1, aimMeshData, aimStruc, status){ if (meshData != ((void*)0)) { status = -4; aim_status(aimStruc
, status, "aimMesh.c", 974, __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", 974, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "meshData", memorysize, "aimMeshData"); goto cleanup; } }
;
975 status = aim_initMeshData(meshData);
976 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 976
, __func__, 0); goto cleanup; }
;
977
978 snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".lb8.ugrid");
979
980 fp = fopen(filename, "rb");
981 if (fp == NULL((void*)0)) {
982 AIM_ERROR(aimStruc, "Cannot open file: %s\n", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 982, __func__
, "Cannot open file: %s\n", filename); }
;
983 status = CAPS_IOERR-332;
984 goto cleanup;
985 }
986
987 // Open a 2nd copy to read in the BC ID's
988 fpID = fopen(filename, "rb");
989 if (fpID == NULL((void*)0)) {
990 AIM_ERROR(aimStruc, "Cannot open file: %s\n", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 990, __func__
, "Cannot open file: %s\n", filename); }
;
991 status = CAPS_IOERR-332;
992 goto cleanup;
993 }
994
995 /* read a binary UGRID file */
996 status = fread(&meshData->nVertex, sizeof(int), 1, fp);
997 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 997
, __func__, 0); goto cleanup; }
; }
998 status = fread(&nTri, sizeof(int), 1, fp);
999 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 999
, __func__, 0); goto cleanup; }
; }
1000 status = fread(&nQuad, sizeof(int), 1, fp);
1001 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1001
, __func__, 0); goto cleanup; }
; }
1002 status = fread(&nTet, sizeof(int), 1, fp);
1003 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1003
, __func__, 0); goto cleanup; }
; }
1004 status = fread(&nPyramid, sizeof(int), 1, fp);
1005 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1005
, __func__, 0); goto cleanup; }
; }
1006 status = fread(&nPrism, sizeof(int), 1, fp);
1007 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1007
, __func__, 0); goto cleanup; }
; }
1008 status = fread(&nHex, sizeof(int), 1, fp);
1009 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1009
, __func__, 0); goto cleanup; }
; }
1010
1011 /* skip the header */
1012 status = fseek(fpID, 7*sizeof(int), SEEK_CUR1);
1013 if (status != 0) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1013
, __func__, 0); goto cleanup; }
; }
1014
1015 /*
1016 printf("\n Header from UGRID file: %d %d %d %d %d %d %d\n", numNode,
1017 numTriangle, numQuadrilateral, numTetrahedral, numPyramid, numPrism,
1018 numHexahedral);
1019 */
1020
1021 snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".mapvol");
1022
1023 // File for volume IDs
1024 fpMV = fopen(filename, "rb");
1025 if (fpMV != NULL((void*)0)) {
1026 status = fread(&nRegion, sizeof(int), 1, fpMV);
1027 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1027
, __func__, 0); goto cleanup; }
; }
1028
1029 /* read the maximum ID value */
1030 status = fread(&nVolName, sizeof(int), 1, fpMV);
1031 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1031
, __func__, 0); goto cleanup; }
; }
1032
1033 if (nRegion+nVolName == 0) {
1034 AIM_ERROR(aimStruc, "Ivnalid mapvol file with zero nRegion and nVolName!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1034, __func__
, "Ivnalid mapvol file with zero nRegion and nVolName!"); }
;
1035 status = CAPS_IOERR-332;
1036 goto cleanup;
1037 }
1038
1039 AIM_ALLOC(volName, nVolName, char*, aimStruc, status){ if (volName != ((void*)0)) { status = -4; aim_status(aimStruc
, status, "aimMesh.c", 1039, __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"
, 1039, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "volName"
, memorysize, "char*"); goto cleanup; } }
;
1040 for (i = 0; i < nVolName; i++) volName[i] = NULL((void*)0);
1041
1042 for (i = 0; i < nRegion; i++) {
1043 status = fread(&ID, sizeof(int), 1, fpMV);
1044 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1044
, __func__, 0); goto cleanup; }
; }
1045
1046 status = fread(&len, sizeof(size_t), 1, fpMV);
1047 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1047
, __func__, 0); goto cleanup; }
; }
1048
1049 AIM_ALLOC(volName[ID-1], len, char, aimStruc, status){ if (volName[ID-1] != ((void*)0)) { status = -4; aim_status(
aimStruc, status, "aimMesh.c", 1049, __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", 1049, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "volName[ID-1]", memorysize, "char"); goto cleanup; } }
;
1050
1051 status = fread(volName[ID-1], sizeof(char), len, fpMV);
1052 if (status != len) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1052
, __func__, 0); goto cleanup; }
; }
1053 }
1054
1055 status = fread(&nElems, sizeof(int), 1, fpMV);
1056 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1056
, __func__, 0); goto cleanup; }
; }
1057
1058 if (nElems != nTet+nPyramid+nPrism+nHex) {
1059 AIM_ERROR(aimStruc, "Element count missmatch in mapvol file!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1059, __func__
, "Element count missmatch in mapvol file!"); }
;
1060 status = CAPS_IOERR-332;
1061 goto cleanup;
1062 }
1063 }
1064
1065
1066 AIM_ALLOC(meshData->verts, meshData->nVertex, aimMeshCoords, aimStruc, status){ if (meshData->verts != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 1066, __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"
, 1066, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshData->verts"
, memorysize, "aimMeshCoords"); goto cleanup; } }
;
1067
1068 /* read all of the vertices */
1069 status = fread(meshData->verts, sizeof(aimMeshCoords), meshData->nVertex, fp);
1070 if (status != meshData->nVertex) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1070
, __func__, 0); goto cleanup; }
; }
1071
1072 /* skip the verts */
1073 status = fseek(fpID, meshData->nVertex*sizeof(aimMeshCoords), SEEK_CUR1);
1074 if (status != 0) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1074
, __func__, 0); goto cleanup; }
; }
1075
1076
1077 // Numbers
1078 meshData->nTotalElems = nTri +
1079 nQuad +
1080 nTet +
1081 nPyramid +
1082 nPrism +
1083 nHex;
1084
1085 // allocate the element map that maps back to the original element numbering
1086 AIM_ALLOC(meshData->elemMap, meshData->nTotalElems, aimMeshIndices, aimStruc, status){ if (meshData->elemMap != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 1086, __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", 1086, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "meshData->elemMap", memorysize, "aimMeshIndices"); goto
cleanup; } }
;
1087
1088 /*
1089 printf("Volume mesh:\n");
1090 printf("\tNumber of nodes = %d\n", meshData->nVertex);
1091 printf("\tNumber of elements = %d\n", meshData->nTotalElems);
1092 printf("\tNumber of triangles = %d\n", numTriangle);
1093 printf("\tNumber of quadrilatarals = %d\n", numQuadrilateral);
1094 printf("\tNumber of tetrahedrals = %d\n", numTetrahedral);
1095 printf("\tNumber of pyramids = %d\n", numPyramid);
1096 printf("\tNumber of prisms = %d\n", numPrism);
1097 printf("\tNumber of hexahedrals = %d\n", numHexahedral);
1098*/
1099
1100 /* skip the Tri+Quad elements for the ID */
1101 status = fseek(fpID, (3*nTri+4*nQuad)*sizeof(int), SEEK_CUR1);
1102 if (status != 0) { status = CAPS_IOERR-332; goto cleanup; }
1103
1104 /* Start of element index */
1105 elementIndex = 0;
1106
1107 /* Elements triangles */
1108 nPoint = 3;
1109 elementTopo = aimTri;
1110 for (i = 0; i < nTri; i++) {
1111
1112 /* read the BC ID */
1113 status = fread(&ID, sizeof(int), 1, fpID);
1114 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1114
, __func__, 0); goto cleanup; }
; }
1115 if (ID <= 0) {
1116 AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1116, __func__
, "BC ID must be a positive number: %d!", ID); }
;
1117 status = CAPS_IOERR-332;
1118 goto cleanup;
1119 }
1120
1121 /* add the BC group if necessary */
1122 if (ID > nMapGroupID) {
1123 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", 1123, __func__
, 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize
, "int"); goto cleanup; } }
;
1124 for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1;
1125 nMapGroupID = ID;
1126 }
1127 if (mapGroupID[ID-1] == -1) {
1128 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData);
1129 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1129
, __func__, 0); goto cleanup; }
;
1130 mapGroupID[ID-1] = meshData->nElemGroup-1;
1131 }
1132
1133 igroup = mapGroupID[ID-1];
1134
1135 /* add the element to the group */
1136 status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]);
1137 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1137
, __func__, 0); goto cleanup; }
;
1138
1139 /* read the element connectivity */
1140 status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems-1)],
1141 sizeof(int), nPoint, fp);
1142 if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1142
, __func__, 0); goto cleanup; }
; }
1143
1144 meshData->elemMap[elementIndex][0] = igroup;
1145 meshData->elemMap[elementIndex][1] = meshData->elemGroups[igroup].nElems-1;
1146
1147 elementIndex += 1;
1148 }
1149
1150 /* Elements quadrilateral */
1151 nPoint = 4;
1152 elementTopo = aimQuad;
1153 for (i = 0; i < nQuad; i++) {
1154
1155 /* read the BC ID */
1156 status = fread(&ID, sizeof(int), 1, fpID);
1157 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1157
, __func__, 0); goto cleanup; }
; }
1158 if (ID <= 0) {
1159 AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1159, __func__
, "BC ID must be a positive number: %d!", ID); }
;
1160 status = CAPS_IOERR-332;
1161 goto cleanup;
1162 }
1163
1164 /* add the BC group if necessary */
1165 if (ID > nMapGroupID) {
1166 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", 1166, __func__
, 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize
, "int"); goto cleanup; } }
;
1167 for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1;
1168 nMapGroupID = ID;
1169 }
1170 if (mapGroupID[ID-1] == -1) {
1171 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData);
1172 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1172
, __func__, 0); goto cleanup; }
;
1173 mapGroupID[ID-1] = meshData->nElemGroup-1;
1174 }
1175
1176 igroup = mapGroupID[ID-1];
1177
1178 /* add the element to the group */
1179 status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]);
1180 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1180
, __func__, 0); goto cleanup; }
;
1181
1182 /* read the element connectivity */
1183 status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems-1)],
1184 sizeof(int), nPoint, fp);
1185 if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1185
, __func__, 0); goto cleanup; }
; }
1186
1187 meshData->elemMap[elementIndex][0] = igroup;
1188 meshData->elemMap[elementIndex][1] = meshData->elemGroups[igroup].nElems-1;
1189
1190 elementIndex += 1;
1191 }
1192
1193 /*@-dependenttrans@*/
1194 fclose(fpID); fpID = NULL((void*)0);
1195 /*@+dependenttrans@*/
1196
1197 // skip face ID section of the file
1198 status = fseek(fp, (nTri + nQuad)*sizeof(int), SEEK_CUR1);
1199 if (status != 0) { status = CAPS_IOERR-332; goto cleanup; }
1200
1201 // Elements Tetrahedral
1202 nPoint = 4;
1203 elementTopo = aimTet;
1204 nElems = nTet;
1205
1206 status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName,
1207 nPoint, elementTopo, nElems,
1208 &elementIndex, meshData);
1209 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1209
, __func__, 0); goto cleanup; }
;
1210
1211 // Elements Pyramid
1212 nPoint = 5;
1213 elementTopo = aimPyramid;
1214 nElems = nPyramid;
1215
1216 status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName,
1217 nPoint, elementTopo, nElems,
1218 &elementIndex, meshData);
1219 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1219
, __func__, 0); goto cleanup; }
;
1220
1221 // Elements Prism
1222 nPoint = 6;
1223 elementTopo = aimPrism;
1224 nElems = nPrism;
1225
1226 status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName,
1227 nPoint, elementTopo, nElems,
1228 &elementIndex, meshData);
1229 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1229
, __func__, 0); goto cleanup; }
;
1230
1231 // Elements Hex
1232 nPoint = 8;
1233 elementTopo = aimHex;
1234 nElems = nHex;
1235
1236 status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, volName,
1237 nPoint, elementTopo, nElems,
1238 &elementIndex, meshData);
1239 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1239
, __func__, 0); goto cleanup; }
;
1240
1241 // 2D grid
1242 if (nTet+nPyramid+nPrism+nHex == 0) {
1243 meshData->dim = 2;
1244 AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); };
1245 nMapGroupID = 0;
1246
1247 status = fread(&nLine, sizeof(int), 1, fp);
1248 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1248
, __func__, 0); goto cleanup; }
; }
1249
1250 meshData->nTotalElems += nLine;
1251 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",
1251, __func__, 3, "AIM_REALL: %s size %zu type %s", "meshData->elemMap"
, memorysize, "aimMeshIndices"); goto cleanup; } }
;
1252
1253 // Elements Line
1254 nPoint = 2;
1255 elementTopo = aimLine;
1256 nElems = nLine;
1257
1258 for (i = 0; i < nElems; i++) {
1259 /* read the element connectivity */
1260 status = fread(line, sizeof(int), nPoint, fp);
1261 if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1261
, __func__, 0); goto cleanup; }
; }
1262 status = fread(&ID, sizeof(int), 1, fp);
1263 if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1263
, __func__, 0); goto cleanup; }
; }
1264 if (ID <= 0) {
1265 AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1265, __func__
, "BC ID must be a positive number: %d!", ID); }
;
1266 status = CAPS_IOERR-332;
1267 goto cleanup;
1268 }
1269
1270 /* add the BC group if necessary */
1271 if (ID > nMapGroupID) {
1272 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", 1272, __func__
, 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize
, "int"); goto cleanup; } }
;
1273 for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1;
1274 nMapGroupID = ID;
1275 }
1276 if (mapGroupID[ID-1] == -1) {
1277 status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData);
1278 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1278
, __func__, 0); goto cleanup; }
;
1279 mapGroupID[ID-1] = meshData->nElemGroup-1;
1280 }
1281
1282 igroup = mapGroupID[ID-1];
1283
1284 /* add the elements to the group */
1285 status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]);
1286 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1286
, __func__, 0); goto cleanup; }
;
1287
1288 meshData->elemGroups[igroup].elements[nPoint*meshData->elemGroups[igroup].nElems-2] = line[0];
1289 meshData->elemGroups[igroup].elements[nPoint*meshData->elemGroups[igroup].nElems-1] = line[1];
1290
1291 meshData->elemMap[elementIndex][0] = igroup;
1292 meshData->elemMap[elementIndex][1] = i;
1293
1294 elementIndex += 1;
1295 }
1296
1297 } else {
1298 meshData->dim = 3;
1299 }
1300
1301 /* read in the groupName from mapbc file */
1302 snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".mapbc");
1303
1304 if (access(filename, F_OK0) == 0) {
1305 // Correct the groupID's to be consistent with groupMap
1306 fpID = fopen(filename, "r");
1307 if (fpID == NULL((void*)0)) {
1308 AIM_ERROR(aimStruc, "Failed to open %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1308, __func__
, "Failed to open %s", filename); }
;
1309 status = CAPS_IOERR-332;
1310 goto cleanup;
1311 }
1312 status = fscanf(fpID, "%d", &nmap);
1313 if (status != 1) {
1314 AIM_ERROR(aimStruc, "Failed to read %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1314, __func__
, "Failed to read %s", filename); }
;
1315 status = CAPS_IOERR-332;
1316 goto cleanup;
1317 }
1318
1319 nID = 0;
1320 for (i = 0; i < nMapGroupID; i++)
1321 if (mapGroupID[i] != -1) nID++;
1322
1323 if (nmap != nID) {
1324 AIM_ERROR(aimStruc, "Number of maps in %s (%d) should be %d",{ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1325, __func__
, "Number of maps in %s (%d) should be %d", filename, nmap, nID
); }
1325 filename, nmap, nID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1325, __func__
, "Number of maps in %s (%d) should be %d", filename, nmap, nID
); }
;
1326 status = CAPS_IOERR-332;
1327 goto cleanup;
1328 }
1329
1330 for (i = 0; i < nmap; i++) {
1331 status = fscanf(fpID, "%d %d %s", &ID, &j, groupName);
1332 if (status != 3) {
1333 AIM_ERROR(aimStruc, "Failed to read %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1333, __func__
, "Failed to read %s", filename); }
;
1334 status = CAPS_IOERR-332;
1335 goto cleanup;
1336 }
1337
1338 if (ID <= 0 || nMapGroupID < ID) {
1339 AIM_ERROR(aimStruc, "ID (%d) in %s out of bounds [1,%d]", ID, filename, nMapGroupID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1339, __func__
, "ID (%d) in %s out of bounds [1,%d]", ID, filename, nMapGroupID
); }
;
1340 status = CAPS_IOERR-332;
1341 goto cleanup;
1342 }
1343
1344 if (mapGroupID[ID-1] == -1) {
1345 AIM_ERROR(aimStruc, "Unknown BC ID (%d) in %s", ID, filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1345, __func__
, "Unknown BC ID (%d) in %s", ID, filename); }
;
1346 status = CAPS_IOERR-332;
1347 goto cleanup;
1348 }
1349
1350 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"
, 1350, __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", 1350, __func__, 2, "AIM_STRDUP: %s %s"
, "meshData->elemGroups[mapGroupID[ID-1]].groupName", groupName
); goto cleanup; } }
;
1351 }
1352
1353 /*@-dependenttrans@*/
1354 fclose(fpID); fpID = NULL((void*)0);
1355 /*@+dependenttrans@*/
1356 }
1357
1358 mesh->meshData = meshData;
1359 meshData = NULL((void*)0);
1360
1361 status = CAPS_SUCCESS0;
1362
1363cleanup:
1364 if (status != CAPS_SUCCESS0) {
1365 aim_freeMeshData(meshData);
1366 AIM_FREE(meshData){ EG_free(meshData); meshData = ((void*)0); };
1367 }
1368 AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); };
1369
1370 if (volName != NULL((void*)0)) {
1371 for (i = 0; i < nVolName; i++)
1372 AIM_FREE(volName[i]){ EG_free(volName[i]); volName[i] = ((void*)0); };
1373 AIM_FREE(volName){ EG_free(volName); volName = ((void*)0); };
1374 }
1375
1376/*@-dependenttrans@*/
1377 if (fp != NULL((void*)0)) fclose(fp);
1378 if (fpID != NULL((void*)0)) fclose(fpID);
1379 if (fpMV != NULL((void*)0)) fclose(fpMV);
1380/*@+dependenttrans@*/
1381
1382 return status;
1383}
1384
1385
1386int
1387aim_storeMeshRef(void *aimStruc, const aimMeshRef *meshRef,
1388 const char *meshextension)
1389{
1390 int status = CAPS_SUCCESS0;
1391
1392 int imap, ibnd, state, nvert;
1393 int i;
1394 char filename_src[PATH_MAX4096];
1395 char filename_dst[PATH_MAX4096];
1396 char aimFile[PATH_MAX4096];
1397 const char *meshRefFile = "meshRef.dat";
1398 const char *meshRefegads = "meshRef.egads";
1399 FILE *fp = NULL((void*)0);
1400 aimInfo *aInfo;
1401 size_t len, strLen = 0;
1402 ego model, body, *bodies = NULL((void*)0);
1403
1404 aInfo = (aimInfo *) aimStruc;
1405 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1
Assuming 'aInfo' is not equal to NULL
2
Taking false branch
1406 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
3
Assuming field 'magicnumber' is equal to CAPSMAGIC
4
Taking false branch
1407
1408 if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
5
Assuming 'meshRef' is not equal to NULL
6
Taking false branch
1409
1410 if (meshextension != NULL((void*)0)) {
7
Assuming 'meshextension' is equal to NULL
8
Taking false branch
1411 if (meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309;
1412
1413 // create the full filename to the mesh in the meshing AIM directory
1414 snprintf(filename_src, PATH_MAX4096, "%s%s", meshRef->fileName, meshextension);
1415
1416 // get the mesh filename without the directory
1417 i = strlen(filename_src);
1418 while(i > 0 && filename_src[i] != SLASH'/') { i--; }
1419 if (i < 0) { status = CAPS_IOERR-332; goto cleanup; }
1420 strcpy(filename_dst, filename_src+i+1);
1421
1422 // copy the mesh from the meshing AIM directory to the current AIM directory
1423 status = aim_cpFile(aimStruc, filename_src, filename_dst);
1424 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1424
, __func__, 0); goto cleanup; }
;
1425 }
1426
1427 // open the file to store the meshRef structure
1428 status = aim_file(aimStruc, meshRefFile, aimFile);
1429 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1429
, __func__, 0); goto cleanup; }
;
9
Assuming 'status' is equal to 0
10
Taking false branch
1430
1431 fp = fopen(aimFile, "wb");
1432 if (fp == NULL((void*)0)) {
11
Assuming 'fp' is not equal to NULL
12
Taking false branch
1433 AIM_ERROR(aimStruc, "Cannot open file: %s\n", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1433, __func__
, "Cannot open file: %s\n", aimFile); }
;
1434 status = CAPS_IOERR-332;
1435 goto cleanup;
1436 }
1437
1438 len = fwrite(&meshRef->type, sizeof(int), 1, fp);
1439 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1439
, __func__, 0); goto cleanup; }
; }
13
Assuming 'len' is equal to 1
14
Taking false branch
1440
1441 len = fwrite(&meshRef->nmap, sizeof(int), 1, fp);
1442 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1442
, __func__, 0); goto cleanup; }
; }
15
Assuming 'len' is equal to 1
16
Taking false branch
1443
1444 AIM_ALLOC(bodies, 2*meshRef->nmap, ego, aimStruc, status){ if (bodies != ((void*)0)) { status = -4; aim_status(aimStruc
, status, "aimMesh.c", 1444, __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", 1444, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "bodies", memorysize, "ego"); goto cleanup; } }
;
17
Taking false branch
18
Assuming 'bodies' is not equal to null
19
Taking false branch
1445
1446 for (imap = 0; imap < meshRef->nmap; imap++) {
20
Assuming 'imap' is >= field 'nmap'
21
Loop condition is false. Execution continues on line 1461
1447 status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert);
1448 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1448
, __func__, 0); goto cleanup; }
;
1449
1450 // construct an egads file to write out the tessellation and the body
1451 status = EG_copyObject(body, NULL((void*)0), &bodies[imap]);
1452 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1452
, __func__, 0); goto cleanup; }
;
1453 status = EG_copyObject(meshRef->maps[imap].tess, bodies[imap], &bodies[imap+meshRef->nmap]);
1454 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1454
, __func__, 0); goto cleanup; }
;
1455
1456 // store the body index
1457 status = EG_attributeAdd(bodies[imap], CAPS_BODY_INDX"--CAPS-BODY-INDX--", ATTRINT1, 1, &imap, NULL((void*)0), NULL((void*)0));
1458 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1458
, __func__, 0); goto cleanup; }
;
1459 }
1460
1461 status = EG_makeTopology(aInfo->problem->context, NULL((void*)0), MODEL26, 2*meshRef->nmap,
1462 NULL((void*)0), meshRef->nmap, bodies, NULL((void*)0), &model);
1463 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1463
, __func__, 0); goto cleanup; }
;
22
Assuming 'status' is equal to 0
23
Taking false branch
1464
1465 status = aim_file(aimStruc, meshRefegads, aimFile);
1466 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1466
, __func__, 0); goto cleanup; }
;
24
Assuming 'status' is equal to 0
25
Taking false branch
1467
1468 remove(aimFile);
1469 status = EG_saveModel(model, aimFile);
1470 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1470
, __func__, 0); goto cleanup; }
;
26
Assuming 'status' is equal to 0
27
Taking false branch
1471
1472 EG_deleteObject(model);
1473
1474 for (imap = 0; imap
27.1
'imap' is >= field 'nmap'
< meshRef->nmap; imap++) {
28
Loop condition is false. Execution continues on line 1483
1475 status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert);
1476 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1476
, __func__, 0); goto cleanup; }
;
1477
1478 // write the surface to volume map
1479 len = fwrite(meshRef->maps[imap].map, sizeof(int), nvert, fp);
1480 if (len != nvert) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1480
, __func__, 0); goto cleanup; }
; }
1481 }
1482
1483 len = fwrite(&meshRef->nbnd, sizeof(int), 1, fp);
1484 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1484
, __func__, 0); goto cleanup; }
; }
29
Assuming 'len' is equal to 1
30
Taking false branch
1485
1486 for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) {
31
Assuming 'ibnd' is >= field 'nbnd'
32
Loop condition is false. Execution continues on line 1501
1487
1488 strLen = strlen(meshRef->bnds[ibnd].groupName)+1;
1489
1490 len = fwrite(&strLen, sizeof(size_t), 1, fp);
1491 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1491
, __func__, 0); goto cleanup; }
; }
1492
1493 len = fwrite(meshRef->bnds[ibnd].groupName, sizeof(char), strLen, fp);
1494 if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1494
, __func__, 0); goto cleanup; }
; }
1495
1496 len = fwrite(&meshRef->bnds[ibnd].ID, sizeof(int), 1, fp);
1497 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1497
, __func__, 0); goto cleanup; }
; }
1498 }
1499
1500 // write meshRef->filename (i.e. filename_dst without the extension)
1501 if (meshRef->fileName != NULL((void*)0)) {
33
Assuming field 'fileName' is not equal to NULL
34
Taking true branch
1502 strLen = strlen(filename_dst);
1503 filename_dst[strLen - strlen(meshextension)] = '\0';
35
Null pointer passed to 1st parameter expecting 'nonnull'
1504 status = aim_file(aimStruc, filename_dst, aimFile);
1505 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1505
, __func__, 0); goto cleanup; }
;
1506
1507 strLen = strlen(aimFile)+1;
1508 }
1509
1510 len = fwrite(&strLen, sizeof(size_t), 1, fp);
1511 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1511
, __func__, 0); goto cleanup; }
; }
1512
1513 len = fwrite(aimFile, sizeof(char), strLen, fp);
1514 if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1514
, __func__, 0); goto cleanup; }
; }
1515
1516cleanup:
1517 /*@-dependenttrans@*/
1518 if (fp != NULL((void*)0)) fclose(fp);
1519 /*@+dependenttrans@*/
1520 AIM_FREE(bodies){ EG_free(bodies); bodies = ((void*)0); };
1521
1522 return status;
1523}
1524
1525
1526int
1527aim_loadMeshRef(void *aimStruc, aimMeshRef *meshRef)
1528{
1529 int status = CAPS_SUCCESS0;
1530
1531 int j, imap, ibnd, state, nvert, nbody;
1532 int oclass, mtype, *senses, alen, atype;
1533 char aimFile[PATH_MAX4096];
1534 double limits[4];
1535 const int *aints=NULL((void*)0);
1536 const double *areals=NULL((void*)0);
1537 const char *astring=NULL((void*)0);
1538 const char *meshRefFile = "meshRef.dat";
1539 const char *meshRefegads = "meshRef.egads";
1540 FILE *fp = NULL((void*)0);
1541 aimInfo *aInfo;
1542 size_t len, strLen;
1543 ego geom, model, body, tessbody, *bodies;
1544
1545 aInfo = (aimInfo *) aimStruc;
1546 if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309;
1547 if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1548
1549 if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309;
1550
1551 // delete the old mesh reference if necessary
1552 status = aim_freeMeshRef(meshRef);
1553 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1553
, __func__, 0); goto cleanup; }
;
1554
1555 // open the file to read the meshRef structure
1556 status = aim_file(aimStruc, meshRefFile, aimFile);
1557 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1557
, __func__, 0); goto cleanup; }
;
1558
1559 fp = fopen(aimFile, "rb");
1560 if (fp == NULL((void*)0)) {
1561 AIM_ERROR(aimStruc, "Cannot open file: %s\n", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1561, __func__
, "Cannot open file: %s\n", aimFile); }
;
1562 status = CAPS_IOERR-332;
1563 goto cleanup;
1564 }
1565
1566 len = fread(&meshRef->type, sizeof(int), 1, fp);
1567 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1567
, __func__, 0); goto cleanup; }
; }
1568
1569 len = fread(&meshRef->nmap, sizeof(int), 1, fp);
1570 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1570
, __func__, 0); goto cleanup; }
; }
1571
1572 AIM_ALLOC(meshRef->maps, meshRef->nmap, aimMeshTessMap, aimStruc, status){ if (meshRef->maps != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 1572, __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", 1572
, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->maps"
, memorysize, "aimMeshTessMap"); goto cleanup; } }
;
1573 for (imap = 0; imap < meshRef->nmap; imap++) {
1574 meshRef->maps[imap].tess = NULL((void*)0);
1575 meshRef->maps[imap].map = NULL((void*)0);
1576 }
1577
1578 status = aim_file(aimStruc, meshRefegads, aimFile);
1579 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1579
, __func__, 0); goto cleanup; }
;
1580
1581 status = EG_loadModel(aInfo->problem->context, 0, aimFile, &model);
1582 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1582
, __func__, 0); goto cleanup; }
;
1583
1584 status = EG_getTopology(model, &geom, &oclass, &mtype, limits,
1585 &nbody, &bodies, &senses);
1586 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1586
, __func__, 0); goto cleanup; }
;
1587
1588 if (nbody != meshRef->nmap) {
1589 AIM_ERROR(aimStruc, "Missmatch between %s and %s!", meshRefFile, meshRefegads){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1589, __func__
, "Missmatch between %s and %s!", meshRefFile, meshRefegads);
}
;
1590 status = CAPS_IOERR-332;
1591 goto cleanup;
1592 }
1593
1594 // copy the body and tessellatoin out of the model
1595 for (imap = 0; imap < meshRef->nmap; imap++) {
1596 status = EG_copyObject(bodies[imap], NULL((void*)0), &body);
1597 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1597
, __func__, 0); goto cleanup; }
;
1598
1599 // get the original body index
1600 status = EG_attributeRet(body, CAPS_BODY_INDX"--CAPS-BODY-INDX--", &atype, &alen, &aints, &areals, &astring);
1601 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1601
, __func__, 0); goto cleanup; }
;
1602 AIM_NOTNULL(aints, aimStruc, status){ if (aints == ((void*)0)) { status = -307; aim_status(aimStruc
, status, "aimMesh.c", 1602, __func__, 1, "%s == NULL!", "aints"
); goto cleanup; } }
;
1603
1604 status = EG_attributeDel(body, CAPS_BODY_INDX"--CAPS-BODY-INDX--");
1605 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1605
, __func__, 0); goto cleanup; }
;
1606
1607 // find the tessellation for this body
1608 for (j = 0; j < meshRef->nmap; j++) {
1609 status = EG_statusTessBody(bodies[j+meshRef->nmap], &tessbody, &state, &nvert);
1610 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1610
, __func__, 0); goto cleanup; }
;
1611
1612 if (tessbody == bodies[imap]) {
1613 // copy the tessellation with the copied body
1614 status = EG_copyObject(bodies[j+meshRef->nmap], body, &meshRef->maps[aints[0]].tess);
1615 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1615
, __func__, 0); goto cleanup; }
;
1616 break;
1617 }
1618 }
1619 }
1620
1621 // delete the model
1622 EG_deleteObject(model);
1623
1624 for (imap = 0; imap < meshRef->nmap; imap++) {
1625 // read the surface to volume map
1626 status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert);
1627 AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1627
, __func__, 0); goto cleanup; }
;
1628
1629 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", 1629, __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", 1629, __func__, 3, "AIM_ALLOC: %s size %zu type %s"
, "meshRef->maps[imap].map", memorysize, "int"); goto cleanup
; } }
;
1630
1631 len = fread(meshRef->maps[imap].map, sizeof(int), nvert, fp);
1632 if (len != nvert) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1632
, __func__, 0); goto cleanup; }
; }
1633 }
1634
1635 // read the bounds
1636 len = fread(&meshRef->nbnd, sizeof(int), 1, fp);
1637 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1637
, __func__, 0); goto cleanup; }
; }
1638
1639 AIM_ALLOC(meshRef->bnds, meshRef->nbnd, aimMeshBnd, aimStruc, status){ if (meshRef->bnds != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 1639, __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", 1639, __func__
, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->bnds", memorysize
, "aimMeshBnd"); goto cleanup; } }
;
1640 for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) {
1641 meshRef->bnds[ibnd].groupName = NULL((void*)0);
1642 meshRef->bnds[ibnd].ID = 0;
1643 }
1644
1645 for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) {
1646
1647 len = fread(&strLen, sizeof(size_t), 1, fp);
1648 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1648
, __func__, 0); goto cleanup; }
; }
1649
1650 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", 1650, __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", 1650, __func__
, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->bnds[ibnd].groupName"
, memorysize, "char"); goto cleanup; } }
;
1651
1652 len = fread(meshRef->bnds[ibnd].groupName, sizeof(char), strLen, fp);
1653 if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1653
, __func__, 0); goto cleanup; }
; }
1654
1655 len = fread(&meshRef->bnds[ibnd].ID, sizeof(int), 1, fp);
1656 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1656
, __func__, 0); goto cleanup; }
; }
1657 }
1658
1659 // read meshRef->filename
1660 len = fread(&strLen, sizeof(size_t), 1, fp);
1661 if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1661
, __func__, 0); goto cleanup; }
; }
1662
1663 if (strLen > 0) {
1664 AIM_ALLOC(meshRef->fileName, strLen, char, aimStruc, status){ if (meshRef->fileName != ((void*)0)) { status = -4; aim_status
(aimStruc, status, "aimMesh.c", 1664, __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", 1664, __func__
, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->fileName"
, memorysize, "char"); goto cleanup; } }
;
1665
1666 len = fread(meshRef->fileName, sizeof(char), strLen, fp);
1667 if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1667
, __func__, 0); goto cleanup; }
; }
1668 }
1669
1670 // indicate that the tessellation and body should be deleted
1671 meshRef->_delTess = (int)true1;
1672
1673cleanup:
1674 /*@-dependenttrans@*/
1675 if (fp != NULL((void*)0)) fclose(fp);
1676 /*@+dependenttrans@*/
1677
1678 return status;
1679}
1680
1681
1682// Map the old surface tessellation on to the new bodies
1683int aim_morphMeshUpdate(void *aimInfo, aimMeshRef *meshRef, int numBody, ego *bodies)
1684{
1685 int status = CAPS_SUCCESS0;
1686 int i=0,j, localIndex, topoIndex, iglobal_old, iglobal_new;
1687 int state, numVert, aType, alen, *map_old=NULL((void*)0);
1688 const int *nMap=NULL((void*)0), *eMap=NULL((void*)0), *fMap=NULL((void*)0);
1689 ego body, tessbody;
1690 ego tess;
1691
1692 // Have the number of bodies changed?
1693 if (meshRef->nmap != numBody) {
1694 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", 1694, __func__
, "The number of original surface meshes does NOT equal the number of current bodies!\n"
); }
;
1695 status = CAPS_MISMATCH-324;
1696 goto cleanup;
1697 }
1698
1699 // Are the bodies topological equivalent?
1700 for (i = 0; i < meshRef->nmap; i++) {
1701
1702 status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &numVert);
1703 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1703
, __func__, 0); goto cleanup; }
;
1704
1705 status = EG_mapBody(body, bodies[i], "_faceID", &bodies[i]); // "_faceID" - same as in OpenCSM
1706 if (status != EGADS_SUCCESS0) {
1707 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", 1707, __func__
, "New and old body %d (of %d) do not appear to be topologically equivalent!"
, i+1, meshRef->nmap); }
;
1708 goto cleanup;
1709 }
1710 }
1711
1712 // Now lets "tweak" the surface tessellation - map the old tessellation to the new bodies
1713 for (i = 0; i < meshRef->nmap; i++) {
1714
1715 status = EG_statusTessBody(meshRef->maps[i].tess, &tessbody, &state, &numVert);
1716 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1716
, __func__, 0); goto cleanup; }
;
1717
1718 // nothing to do if bodies are the same
1719 if (tessbody == bodies[i]) continue;
1720
1721 printf("Projecting tessellation %d (of %d) on to new body\n", i+1, meshRef->nmap);
1722
1723 status = EG_mapTessBody(meshRef->maps[i].tess,
1724 bodies[i],
1725 &tess);
1726 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1726
, __func__, 0); goto cleanup; }
;
1727
1728 status = EG_attributeRet(bodies[i], ".fMap", &aType, &alen, &fMap, NULL((void*)0), NULL((void*)0));
1729 if (status == EGADS_SUCCESS0) {
1730 status = EG_attributeRet(bodies[i], ".eMap", &aType, &alen, &eMap, NULL((void*)0), NULL((void*)0));
1731 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1731
, __func__, 0); goto cleanup; }
;
1732 status = EG_attributeRet(bodies[i], ".nMap", &aType, &alen, &nMap, NULL((void*)0), NULL((void*)0));
1733 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1733
, __func__, 0); goto cleanup; }
;
1734 }
1735
1736 // update the surface to volume mapping
1737 if (fMap != NULL((void*)0)) {
1738 AIM_NOTNULL(eMap, aimInfo, status){ if (eMap == ((void*)0)) { status = -307; aim_status(aimInfo
, status, "aimMesh.c", 1738, __func__, 1, "%s == NULL!", "eMap"
); goto cleanup; } }
;
1739 AIM_NOTNULL(nMap, aimInfo, status){ if (nMap == ((void*)0)) { status = -307; aim_status(aimInfo
, status, "aimMesh.c", 1739, __func__, 1, "%s == NULL!", "nMap"
); goto cleanup; } }
;
1740
1741 // update the mapping into the volume
1742 map_old = meshRef->maps[i].map;
1743 meshRef->maps[i].map = NULL((void*)0);
1744
1745 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", 1745, __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", 1745, __func__
, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->maps[i].map"
, memorysize, "int"); goto cleanup; } }
;
1746
1747 // Find the boundary mesh in the global tessellation
1748 for (j = 0; j < numVert; j++) {
1749
1750 iglobal_old = j+1;
1751 // Get the local indexes
1752 status = EG_getGlobal(meshRef->maps[i].tess, iglobal_old,
1753 &localIndex, &topoIndex, NULL((void*)0));
1754 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1754
, __func__, 0); goto cleanup; }
;
1755
1756 // Get the global index in the new tess
1757 if (localIndex == 0) {
1758 status = EG_localToGlobal(tess, localIndex, nMap[topoIndex-1], &iglobal_new);
1759 AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", nMap[topoIndex-1], localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1759
, __func__, 3, "ptype = %d, pindex = %d", nMap[topoIndex-1], localIndex
); goto cleanup; }
;
1760 } else if (localIndex > 0) {
1761 status = EG_localToGlobal(tess, -eMap[topoIndex-1], localIndex, &iglobal_new);
1762 AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", eMap[topoIndex-1], localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1762
, __func__, 3, "ptype = %d, pindex = %d", eMap[topoIndex-1], localIndex
); goto cleanup; }
;
1763 } else {
1764 status = EG_localToGlobal(tess, fMap[topoIndex-1], -localIndex, &iglobal_new);
1765 AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", fMap[topoIndex-1], -localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1765
, __func__, 3, "ptype = %d, pindex = %d", fMap[topoIndex-1], -
localIndex); goto cleanup; }
;
1766 }
1767
1768 meshRef->maps[i].map[iglobal_new-1] = map_old[iglobal_old-1];
1769 }
1770 }
1771
1772 // store the new tessellation
1773 if (meshRef->_delTess == (int)true1) {
1774 EG_deleteObject(meshRef->maps[i].tess);
1775 EG_deleteObject(tessbody);
1776 }
1777 meshRef->maps[i].tess = tess;
1778 status = aim_newTess(aimInfo, tess);
1779 AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1779
, __func__, 0); goto cleanup; }
;
1780
1781 AIM_FREE(map_old){ EG_free(map_old); map_old = ((void*)0); };
1782 }
1783
1784 meshRef->_delTess = (int)false0;
1785
1786cleanup:
1787 AIM_FREE(map_old){ EG_free(map_old); map_old = ((void*)0); };
1788 return status;
1789}