File: | aimMesh.c |
Warning: | line 1294, column 16 Dereference of null pointer |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | ||||
37 | static /*@null@*/ DLLvoid * writerDLopen(const char *name) | |||
38 | { | |||
39 | int i, len; | |||
40 | DLLvoid * dll; | |||
41 | char *full, *env; | |||
42 | #ifdef WIN32 | |||
43 | WIN32_FIND_DATA ffd; | |||
44 | char dir[MAX_PATH]; | |||
45 | size_t length_of_arg; | |||
46 | HANDLE hFind = INVALID_HANDLE_VALUE; | |||
47 | #else | |||
48 | /*@-unrecog@*/ | |||
49 | char dir[PATH_MAX4096]; | |||
50 | /*@+unrecog@*/ | |||
51 | struct dirent *de; | |||
52 | DIR *dr; | |||
53 | #endif | |||
54 | ||||
55 | env = getenv("ESP_ROOT"); | |||
56 | if (env == NULL((void*)0)) { | |||
57 | printf(" Information: Could not find $ESP_ROOT\n"); | |||
58 | return NULL((void*)0); | |||
59 | } | |||
60 | ||||
61 | if (name == NULL((void*)0)) { | |||
62 | printf(" Information: Dynamic Loader invoked with NULL name!\n"); | |||
63 | return NULL((void*)0); | |||
64 | } | |||
65 | len = strlen(name); | |||
66 | full = (char *) malloc((len+5)*sizeof(char)); | |||
67 | if (full == NULL((void*)0)) { | |||
68 | printf(" Information: Dynamic Loader MALLOC Error!\n"); | |||
69 | return NULL((void*)0); | |||
70 | } | |||
71 | for (i = 0; i < len; i++) full[i] = name[i]; | |||
72 | full[len ] = '.'; | |||
73 | #ifdef WIN32 | |||
74 | full[len+1] = 'D'; | |||
75 | full[len+2] = 'L'; | |||
76 | full[len+3] = 'L'; | |||
77 | full[len+4] = 0; | |||
78 | _snprintf(dir, MAX_PATH, "%s\\lib\\*", env); | |||
79 | hFind = FindFirstFile(dir, &ffd); | |||
80 | if (INVALID_HANDLE_VALUE == hFind) { | |||
81 | printf(" Information: Dynamic Loader could not open %s\n", dir); | |||
82 | free(full); | |||
83 | return NULL((void*)0); | |||
84 | } | |||
85 | i = 0; | |||
86 | do { | |||
87 | if (strcasecmp(full, ffd.cFileName) == 0) i++; | |||
88 | } while (FindNextFile(hFind, &ffd) != 0); | |||
89 | FindClose(hFind); | |||
90 | if (i > 1) { | |||
91 | printf(" Information: Dynamic Loader more than 1 file: %s!\n", full); | |||
92 | free(full); | |||
93 | return NULL((void*)0); | |||
94 | } | |||
95 | ||||
96 | if (i == 1) { | |||
97 | hFind = FindFirstFile(dir, &ffd); | |||
98 | do { | |||
99 | if (strcasecmp(full, ffd.cFileName) == 0) break; | |||
100 | } while (FindNextFile(hFind, &ffd) != 0); | |||
101 | dll = LoadLibrary(ffd.cFileName); | |||
102 | FindClose(hFind); | |||
103 | } else { | |||
104 | dll = LoadLibrary(full); | |||
105 | } | |||
106 | ||||
107 | #else | |||
108 | ||||
109 | full[len+1] = 's'; | |||
110 | full[len+2] = 'o'; | |||
111 | full[len+3] = 0; | |||
112 | snprintf(dir, PATH_MAX4096, "%s/lib", env); | |||
113 | dr = opendir(dir); | |||
114 | if (dr == NULL((void*)0)) { | |||
115 | printf(" Information: Dynamic Loader could not open %s\n", dir); | |||
116 | free(full); | |||
117 | return NULL((void*)0); | |||
118 | } | |||
119 | i = 0; | |||
120 | while ((de = readdir(dr)) != NULL((void*)0)) | |||
121 | /*@-unrecog@*/ | |||
122 | if (strcasecmp(full, de->d_name) == 0) i++; | |||
123 | /*@+unrecog@*/ | |||
124 | closedir(dr); | |||
125 | if (i > 1) { | |||
126 | printf(" Information: Dynamic Loader more than 1 file: %s!\n", full); | |||
127 | free(full); | |||
128 | return NULL((void*)0); | |||
129 | } | |||
130 | ||||
131 | if (i == 1) { | |||
132 | dr = opendir(dir); | |||
133 | while ((de = readdir(dr)) != NULL((void*)0)) | |||
134 | if (strcasecmp(full, de->d_name) == 0) break; | |||
135 | /*@-nullderef@*/ | |||
136 | dll = dlopen(de->d_name, RTLD_NOW0x00002 | RTLD_NODELETE0x01000); | |||
137 | /*@-nullderef@*/ | |||
138 | closedir(dr); | |||
139 | } else { | |||
140 | dll = dlopen(full, RTLD_NOW0x00002 | RTLD_NODELETE0x01000); | |||
141 | } | |||
142 | #endif | |||
143 | ||||
144 | if (!dll) { | |||
145 | printf(" Information: Dynamic Loader Error for %s\n", full); | |||
146 | #ifndef WIN32 | |||
147 | /*@-mustfreefresh@*/ | |||
148 | printf(" %s\n", dlerror()); | |||
149 | /*@+mustfreefresh@*/ | |||
150 | #endif | |||
151 | free(full); | |||
152 | return NULL((void*)0); | |||
153 | } | |||
154 | free(full); | |||
155 | ||||
156 | return dll; | |||
157 | } | |||
158 | ||||
159 | ||||
160 | static void writerDLclose(/*@only@*/ DLLvoid * dll) | |||
161 | { | |||
162 | #ifdef WIN32 | |||
163 | FreeLibrary(dll); | |||
164 | #else | |||
165 | dlclose(dll); | |||
166 | #endif | |||
167 | } | |||
168 | ||||
169 | ||||
170 | static wrDLLFunc writerDLget(DLLvoid * dll, const char *symname) | |||
171 | { | |||
172 | wrDLLFunc data; | |||
173 | ||||
174 | #ifdef WIN32 | |||
175 | data = (wrDLLFunc) GetProcAddress(dll, symname); | |||
176 | #else | |||
177 | /*@-castfcnptr@*/ | |||
178 | data = (wrDLLFunc) dlsym(dll, symname); | |||
179 | /*@+castfcnptr@*/ | |||
180 | #endif | |||
181 | ||||
182 | return data; | |||
183 | } | |||
184 | ||||
185 | ||||
186 | static int writerDLoaded(writerContext cntxt, const char *name) | |||
187 | { | |||
188 | int i; | |||
189 | ||||
190 | for (i = 0; i < cntxt.aimWriterNum; i++) | |||
191 | if (strcasecmp(name, cntxt.aimWriterName[i]) == 0) return i; | |||
192 | ||||
193 | return -1; | |||
194 | } | |||
195 | ||||
196 | ||||
197 | static int writerDYNload(writerContext *cntxt, const char *name) | |||
198 | { | |||
199 | int i, len, ret; | |||
200 | DLLvoid * dll; | |||
201 | ||||
202 | if (cntxt->aimWriterNum >= MAXWRITER16) { | |||
203 | printf(" Information: Number of Writers > %d!\n", MAXWRITER16); | |||
204 | return EGADS_INDEXERR-5; | |||
205 | } | |||
206 | dll = writerDLopen(name); | |||
207 | if (dll == NULL((void*)0)) return EGADS_NULLOBJ-2; | |||
208 | ||||
209 | ret = cntxt->aimWriterNum; | |||
210 | cntxt->aimExtension[ret] = (AIMext) writerDLget(dll, "meshExtension"); | |||
211 | cntxt->aimWriter[ret] = (AIMwriter) writerDLget(dll, "meshWrite"); | |||
212 | if (cntxt->aimExtension[ret] == NULL((void*)0)) { | |||
213 | writerDLclose(dll); | |||
214 | printf(" Error: Missing symbol 'meshExtension' in %s\n", name); | |||
215 | return EGADS_EMPTY-13; | |||
216 | } | |||
217 | if (cntxt->aimWriter[ret] == NULL((void*)0)) { | |||
218 | writerDLclose(dll); | |||
219 | printf(" Error: Missing symbol 'meshWrite' in %s\n", name); | |||
220 | return EGADS_EMPTY-13; | |||
221 | } | |||
222 | ||||
223 | len = strlen(name) + 1; | |||
224 | cntxt->aimWriterName[ret] = (char *) EG_alloc(len*sizeof(char)); | |||
225 | if (cntxt->aimWriterName[ret] == NULL((void*)0)) { | |||
226 | writerDLclose(dll); | |||
227 | return EGADS_MALLOC-4; | |||
228 | } | |||
229 | for (i = 0; i < len; i++) cntxt->aimWriterName[ret][i] = name[i]; | |||
230 | cntxt->aimWriterDLL[ret] = dll; | |||
231 | cntxt->aimWriterNum++; | |||
232 | ||||
233 | return ret; | |||
234 | } | |||
235 | ||||
236 | ||||
237 | /*@null@*/ /*@dependent@*/ static const char * | |||
238 | aim_writerExtension(void *aimStruc, const char *writerName) | |||
239 | { | |||
240 | int i; | |||
241 | aimInfo *aInfo; | |||
242 | ||||
243 | aInfo = (aimInfo *) aimStruc; | |||
244 | i = writerDLoaded(aInfo->wCntxt, writerName); | |||
245 | if (i == -1) { | |||
246 | i = writerDYNload(&aInfo->wCntxt, writerName); | |||
247 | if (i < 0) return NULL((void*)0); | |||
248 | } | |||
249 | ||||
250 | return aInfo->wCntxt.aimExtension[i](); | |||
251 | } | |||
252 | ||||
253 | ||||
254 | static int | |||
255 | aim_writeMesh(void *aimStruc, const char *writerName, aimMesh *mesh) | |||
256 | { | |||
257 | int i; | |||
258 | aimInfo *aInfo; | |||
259 | ||||
260 | aInfo = (aimInfo *) aimStruc; | |||
261 | i = writerDLoaded(aInfo->wCntxt, writerName); | |||
262 | if (i == -1) { | |||
263 | i = writerDYNload(&aInfo->wCntxt, writerName); | |||
264 | if (i < 0) return i; | |||
265 | } | |||
266 | ||||
267 | return aInfo->wCntxt.aimWriter[i](aimStruc, mesh); | |||
268 | } | |||
269 | ||||
270 | ||||
271 | /* ************************* Exposed Functions **************************** */ | |||
272 | ||||
273 | int | |||
274 | aim_deleteMeshes(void *aimStruc, const aimMeshRef *meshRef) | |||
275 | { | |||
276 | int i; | |||
277 | #ifdef WIN32 | |||
278 | char file[MAX_PATH]; | |||
279 | #else | |||
280 | char file[PATH_MAX4096]; | |||
281 | #endif | |||
282 | const char *ext; | |||
283 | aimInfo *aInfo; | |||
284 | writerContext cntxt; | |||
285 | ||||
286 | aInfo = (aimInfo *) aimStruc; | |||
287 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
288 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
289 | cntxt = aInfo->wCntxt; | |||
290 | ||||
291 | for (i = 0; i < cntxt.aimWriterNum; i++) { | |||
292 | ext = aim_writerExtension(aimStruc, cntxt.aimWriterName[i]); | |||
293 | if (ext == NULL((void*)0)) continue; | |||
294 | #ifdef WIN32 | |||
295 | _snprintf(file, MAX_PATH, "%s%s", meshRef->fileName, ext); | |||
296 | _unlink(file); | |||
297 | #else | |||
298 | snprintf(file, PATH_MAX4096, "%s%s", meshRef->fileName, ext); | |||
299 | unlink(file); | |||
300 | #endif | |||
301 | } | |||
302 | ||||
303 | return CAPS_SUCCESS0; | |||
304 | } | |||
305 | ||||
306 | ||||
307 | int | |||
308 | aim_queryMeshes(void *aimStruc, int index, aimMeshRef *meshRef) | |||
309 | { | |||
310 | int i, j, k, ret, nWrite = 0; | |||
311 | char *writerName[MAXWRITER16]; | |||
312 | #ifdef WIN32 | |||
313 | char file[MAX_PATH]; | |||
314 | #else | |||
315 | char file[PATH_MAX4096]; | |||
316 | #endif | |||
317 | const char *ext; | |||
318 | aimInfo *aInfo; | |||
319 | capsObject *vobject, *source, *last; | |||
320 | capsProblem *problem; | |||
321 | capsAnalysis *analysis, *another; | |||
322 | capsValue *value; | |||
323 | ||||
324 | aInfo = (aimInfo *) aimStruc; | |||
325 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
326 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
327 | problem = aInfo->problem; | |||
328 | analysis = (capsAnalysis *) aInfo->analysis; | |||
329 | ||||
330 | if ((index < 1) || (index > analysis->nAnalysisOut)) return CAPS_BADINDEX-304; | |||
331 | vobject = analysis->analysisOut[index-1]; | |||
332 | if (vobject == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
333 | value = (capsValue *) vobject->blind; | |||
334 | if (value == NULL((void*)0)) return CAPS_NULLBLIND-321; | |||
335 | if (value->type != PointerMesh) return CAPS_BADTYPE-306; | |||
336 | ||||
337 | /* find all of our linked writers */ | |||
338 | for (i = 0; i < problem->nAnalysis; i++) { | |||
339 | if (problem->analysis[i] == NULL((void*)0)) continue; | |||
340 | if (problem->analysis[i]->blind == NULL((void*)0)) continue; | |||
341 | another = problem->analysis[i]->blind; | |||
342 | if (analysis == another) continue; | |||
343 | for (j = 0; j < another->nAnalysisIn; j++) { | |||
344 | source = another->analysisIn[j]; | |||
345 | last = NULL((void*)0); | |||
346 | do { | |||
347 | if (source->magicnumber != CAPSMAGIC1234321) break; | |||
348 | if (source->type != VALUE) break; | |||
349 | if (source->blind == NULL((void*)0)) break; | |||
350 | value = (capsValue *) source->blind; | |||
351 | if (value->link == another->analysisIn[j]) break; | |||
352 | last = source; | |||
353 | source = value->link; | |||
354 | } while (value->link != NULL((void*)0)); | |||
355 | if (last != vobject) continue; | |||
356 | /* we hit our object from a AnalysisIn link */ | |||
357 | value = (capsValue *) another->analysisIn[j]->blind; | |||
358 | if (value->meshWriter == NULL((void*)0)) { | |||
359 | /* printf(" CAPS Warning: Link found but NULL writer!\n"); */ | |||
360 | continue; | |||
361 | } | |||
362 | for (k = 0; k < nWrite; k++) | |||
363 | if (strcmp(writerName[k], value->meshWriter) == 0) break; | |||
364 | if (k != nWrite) continue; | |||
365 | writerName[nWrite] = value->meshWriter; | |||
366 | nWrite++; | |||
367 | } | |||
368 | } | |||
369 | if (nWrite == 0) return CAPS_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 | ||||
388 | int | |||
389 | aim_writeMeshes(void *aimStruc, int index, aimMesh *mesh) | |||
390 | { | |||
391 | int i, j, k, stat, nWrite = 0; | |||
392 | char *writerName[MAXWRITER16]; | |||
393 | #ifdef WIN32 | |||
394 | char file[MAX_PATH]; | |||
395 | #else | |||
396 | char file[PATH_MAX4096]; | |||
397 | #endif | |||
398 | const char *ext; | |||
399 | aimInfo *aInfo; | |||
400 | capsObject *vobject, *source, *last; | |||
401 | capsProblem *problem; | |||
402 | capsAnalysis *analysis, *another; | |||
403 | capsValue *value; | |||
404 | ||||
405 | aInfo = (aimInfo *) aimStruc; | |||
406 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
407 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
408 | problem = aInfo->problem; | |||
409 | analysis = (capsAnalysis *) aInfo->analysis; | |||
410 | ||||
411 | if ((index < 1) || (index > analysis->nAnalysisOut)) return CAPS_BADINDEX-304; | |||
412 | vobject = analysis->analysisOut[index-1]; | |||
413 | if (vobject == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
414 | value = (capsValue *) vobject->blind; | |||
415 | if (value == NULL((void*)0)) return CAPS_NULLBLIND-321; | |||
416 | if (value->type != PointerMesh) return CAPS_BADTYPE-306; | |||
417 | ||||
418 | /* find all of our linked writers */ | |||
419 | for (i = 0; i < problem->nAnalysis; i++) { | |||
420 | if (problem->analysis[i] == NULL((void*)0)) continue; | |||
421 | if (problem->analysis[i]->blind == NULL((void*)0)) continue; | |||
422 | another = problem->analysis[i]->blind; | |||
423 | if (analysis == another) continue; | |||
424 | for (j = 0; j < another->nAnalysisIn; j++) { | |||
425 | source = another->analysisIn[j]; | |||
426 | last = NULL((void*)0); | |||
427 | do { | |||
428 | if (source->magicnumber != CAPSMAGIC1234321) break; | |||
429 | if (source->type != VALUE) break; | |||
430 | if (source->blind == NULL((void*)0)) break; | |||
431 | value = (capsValue *) source->blind; | |||
432 | if (value->link == another->analysisIn[j]) break; | |||
433 | last = source; | |||
434 | source = value->link; | |||
435 | } while (value->link != NULL((void*)0)); | |||
436 | if (last != vobject) continue; | |||
437 | /* we hit our object from a AnalysisIn link */ | |||
438 | value = (capsValue *) another->analysisIn[j]->blind; | |||
439 | #ifdef DEBUG | |||
440 | printf(" *** Found Writer = %s ***\n", value->meshWriter); | |||
441 | #endif | |||
442 | if (value->meshWriter == NULL((void*)0)) { | |||
443 | printf(" CAPS Error: Link found but NULL writer!\n"); | |||
444 | return CAPS_NOTFOUND-303; | |||
445 | } | |||
446 | for (k = 0; k < nWrite; k++) | |||
447 | if (strcmp(writerName[k], value->meshWriter) == 0) break; | |||
448 | if (k != nWrite) continue; | |||
449 | writerName[nWrite] = value->meshWriter; | |||
450 | nWrite++; | |||
451 | } | |||
452 | } | |||
453 | if (nWrite == 0) return CAPS_NOTFOUND-303; | |||
454 | ||||
455 | /* write the files */ | |||
456 | for (i = 0; i < nWrite; i++) { | |||
457 | /* does the file exist? */ | |||
458 | ext = aim_writerExtension(aimStruc, writerName[i]); | |||
459 | if (ext == NULL((void*)0)) continue; | |||
460 | #ifdef WIN32 | |||
461 | _snprintf(file, MAX_PATH, "%s%s", mesh->meshRef->fileName, ext); | |||
462 | if (_access(file, F_OK0) == 0) continue; | |||
463 | #else | |||
464 | snprintf(file, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ext); | |||
465 | if (access(file, F_OK0) == 0) continue; | |||
466 | #endif | |||
467 | /* no -- write it */ | |||
468 | stat = aim_writeMesh(aimStruc, writerName[i], mesh); | |||
469 | if (stat != CAPS_SUCCESS0) { | |||
470 | printf(" CAPS Error: aim_writeMesh = %d for Writer = %s!\n", | |||
471 | stat, writerName[i]); | |||
472 | return stat; | |||
473 | } | |||
474 | } | |||
475 | ||||
476 | return CAPS_SUCCESS0; | |||
477 | } | |||
478 | ||||
479 | ||||
480 | int | |||
481 | aim_initMeshBnd(aimMeshBnd *meshBnd) | |||
482 | { | |||
483 | if (meshBnd == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
484 | ||||
485 | meshBnd->groupName = NULL((void*)0); | |||
486 | meshBnd->ID = 0; | |||
487 | ||||
488 | return CAPS_SUCCESS0; | |||
489 | } | |||
490 | ||||
491 | ||||
492 | int | |||
493 | aim_initMeshRef(aimMeshRef *meshRef, 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 | ||||
509 | int | |||
510 | aim_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 | ||||
545 | int | |||
546 | aim_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 | ||||
565 | int | |||
566 | aim_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 | ||||
587 | int | |||
588 | aim_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 | ||||
614 | cleanup: | |||
615 | return status; | |||
616 | } | |||
617 | ||||
618 | ||||
619 | int | |||
620 | aim_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 | ||||
631 | cleanup: | |||
632 | return status; | |||
633 | } | |||
634 | ||||
635 | ||||
636 | int | |||
637 | aim_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 | ||||
807 | cleanup: | |||
808 | return status; | |||
809 | } | |||
810 | ||||
811 | ||||
812 | int | |||
813 | aim_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 | ||||
852 | cleanup: | |||
853 | /*@-dependenttrans@*/ | |||
854 | if (fp != NULL((void*)0)) fclose(fp); | |||
855 | /*@+dependenttrans@*/ | |||
856 | fp = NULL((void*)0); | |||
857 | return status; | |||
858 | } | |||
859 | ||||
860 | ||||
861 | typedef struct | |||
862 | { | |||
863 | char *name; | |||
864 | int ID; | |||
865 | } NameID; | |||
866 | ||||
867 | ||||
868 | static int | |||
869 | aim_readBinaryUgridElements(void *aimStruc, FILE *fp, /*@null@*/ FILE *fpMV, | |||
870 | int nName, /*@null@*/ NameID *names, | |||
871 | int nPoint, enum aimMeshElem elementTopo, int nElems, | |||
872 | int *elementIndex, aimMeshData *meshData) | |||
873 | { | |||
874 | int status = CAPS_SUCCESS0; | |||
875 | int i, j, ID, igroup; | |||
876 | int nMapGroupID = 0; | |||
877 | int *mapGroupID = NULL((void*)0), *IDs = NULL((void*)0); | |||
878 | char *name = NULL((void*)0); | |||
879 | ||||
880 | if (nElems > 0) { | |||
881 | ||||
882 | if (fpMV != NULL((void*)0)) { | |||
883 | AIM_ALLOC(IDs, nElems, int, aimStruc, status){ if (IDs != ((void*)0)) { status = -4; aim_status(aimStruc, status , "aimMesh.c", 883, __func__, 1, "AIM_ALLOC: %s != NULL", "IDs" ); goto cleanup; } size_t memorysize = nElems; IDs = (int *) EG_alloc (memorysize*sizeof(int)); if (IDs == ((void*)0)) { status = - 4; aim_status(aimStruc, status, "aimMesh.c", 883, __func__, 3 , "AIM_ALLOC: %s size %zu type %s", "IDs", memorysize, "int") ; goto cleanup; } }; | |||
884 | ||||
885 | for (i = 0; i < nElems; i++) { | |||
886 | ||||
887 | /* read the volume ID */ | |||
888 | status = fread(&ID, sizeof(int), 1, fpMV); | |||
889 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 889 , __func__, 0); goto cleanup; }; } | |||
890 | if (ID <= 0) { | |||
891 | AIM_ERROR(aimStruc, "ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 891, __func__ , "ID must be a positive number: %d!", ID); }; | |||
892 | status = CAPS_IOERR-332; | |||
893 | goto cleanup; | |||
894 | } | |||
895 | ||||
896 | /* add the volume group if necessary */ | |||
897 | if (ID > nMapGroupID) { | |||
898 | 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", 898, __func__ , 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize , "int"); goto cleanup; } }; | |||
899 | for (j = nMapGroupID; j < ID; j++) mapGroupID[j] = -1; | |||
900 | nMapGroupID = ID; | |||
901 | } | |||
902 | if (mapGroupID[ID-1] == -1) { | |||
903 | if (names != NULL((void*)0)) { | |||
904 | j = 0; | |||
905 | while (names[j].ID != ID) { | |||
906 | j++; | |||
907 | if (nName == j) { | |||
908 | AIM_ERROR(aimStruc, "Failed to find 'name' for ID %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 908, __func__ , "Failed to find 'name' for ID %d!", ID); }; | |||
909 | status = CAPS_IOERR-332; | |||
910 | goto cleanup; | |||
911 | } | |||
912 | } | |||
913 | name = names[j].name; | |||
914 | } | |||
915 | status = aim_addMeshElemGroup(aimStruc, name, ID, elementTopo, 1, nPoint, meshData); | |||
916 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 916 , __func__, 0); goto cleanup; }; | |||
917 | mapGroupID[ID-1] = meshData->nElemGroup-1; | |||
918 | } | |||
919 | ||||
920 | igroup = mapGroupID[ID-1]; | |||
921 | ||||
922 | IDs[i] = ID; | |||
923 | ||||
924 | /* add the element to the group */ | |||
925 | meshData->elemGroups[igroup].nElems++; | |||
926 | } | |||
927 | ||||
928 | for (ID = 0; ID < nMapGroupID; ID++) { | |||
929 | igroup = mapGroupID[ID]; | |||
930 | if (igroup == -1) continue; | |||
931 | ||||
932 | /* resize the element group */ | |||
933 | AIM_REALL(meshData->elemGroups[igroup].elements, meshData->elemGroups[igroup].nPoint*(meshData->elemGroups[igroup].nElems), int, aimStruc, status){ size_t memorysize = meshData->elemGroups[igroup].nPoint* (meshData->elemGroups[igroup].nElems); meshData->elemGroups [igroup].elements = (int *) EG_reall(meshData->elemGroups[ igroup].elements, memorysize*sizeof(int)); if (meshData->elemGroups [igroup].elements == ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 933, __func__, 3, "AIM_REALL: %s size %zu type %s" , "meshData->elemGroups[igroup].elements", memorysize, "int" ); goto cleanup; } }; | |||
934 | meshData->elemGroups[igroup].nElems = 0; | |||
935 | } | |||
936 | ||||
937 | for (i = 0; i < nElems; i++) { | |||
938 | ||||
939 | /* get the volume group */ | |||
940 | igroup = mapGroupID[IDs[i]-1]; | |||
941 | ||||
942 | /* read the element connectivity */ | |||
943 | status = fread(&meshData->elemGroups[igroup].elements[nPoint*(meshData->elemGroups[igroup].nElems)], | |||
944 | sizeof(int), nPoint, fp); | |||
945 | if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 945 , __func__, 0); goto cleanup; }; } | |||
946 | ||||
947 | meshData->elemMap[*elementIndex][0] = igroup; | |||
948 | meshData->elemMap[*elementIndex][1] = meshData->elemGroups[igroup].nElems; | |||
949 | ||||
950 | meshData->elemGroups[igroup].nElems += 1; | |||
951 | *elementIndex += 1; | |||
952 | } | |||
953 | ||||
954 | } else { | |||
955 | ||||
956 | status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), 1, elementTopo, 1, nPoint, meshData); | |||
957 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 957 , __func__, 0); goto cleanup; }; | |||
958 | ||||
959 | igroup = meshData->nElemGroup-1; | |||
960 | ||||
961 | /* add the elements to the group */ | |||
962 | status = aim_addMeshElem(aimStruc, nElems, &meshData->elemGroups[igroup]); | |||
963 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 963 , __func__, 0); goto cleanup; }; | |||
964 | ||||
965 | /* read the element connectivity */ | |||
966 | status = fread(meshData->elemGroups[igroup].elements, | |||
967 | sizeof(int), nPoint*nElems, fp); | |||
968 | if (status != nPoint*nElems) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 968 , __func__, 0); goto cleanup; }; } | |||
969 | ||||
970 | for (i = 0; i < nElems; i++) { | |||
971 | meshData->elemMap[*elementIndex][0] = igroup; | |||
972 | meshData->elemMap[*elementIndex][1] = i; | |||
973 | ||||
974 | *elementIndex += 1; | |||
975 | } | |||
976 | } | |||
977 | } | |||
978 | ||||
979 | status = CAPS_SUCCESS0; | |||
980 | cleanup: | |||
981 | ||||
982 | AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); }; | |||
983 | AIM_FREE(IDs){ EG_free(IDs); IDs = ((void*)0); }; | |||
984 | ||||
985 | return status; | |||
986 | } | |||
987 | ||||
988 | ||||
989 | int | |||
990 | aim_readBinaryUgrid(void *aimStruc, aimMesh *mesh) | |||
991 | { | |||
992 | int status = CAPS_SUCCESS0; | |||
993 | ||||
994 | int nLine, nTri, nQuad; | |||
995 | int nTet, nPyramid, nPrism, nHex; | |||
996 | int i, j, elementIndex, nPoint, nElems, ID, igroup; | |||
997 | int line[2]; | |||
998 | int nRegion = 0, nVolName=0, nBCName=0; | |||
999 | int nMapGroupID = 0, *mapGroupID = NULL((void*)0); | |||
1000 | enum aimMeshElem elementTopo; | |||
1001 | char filename[PATH_MAX4096], groupName[PATH_MAX4096]; | |||
1002 | NameID *volName=NULL((void*)0), *bcName=NULL((void*)0); | |||
| ||||
1003 | size_t len; | |||
1004 | FILE *fp = NULL((void*)0), *fpID = NULL((void*)0), *fpMV=NULL((void*)0); | |||
1005 | aimMeshData *meshData = NULL((void*)0); | |||
1006 | ||||
1007 | if (mesh == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1008 | if (mesh->meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1009 | if (mesh->meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1010 | ||||
1011 | status = aim_freeMeshData(mesh->meshData); | |||
1012 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1012 , __func__, 0); goto cleanup; }; | |||
1013 | AIM_FREE(mesh->meshData){ EG_free(mesh->meshData); mesh->meshData = ((void*)0); }; | |||
1014 | ||||
1015 | AIM_ALLOC(meshData, 1, aimMeshData, aimStruc, status){ if (meshData != ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 1015, __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", 1015, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "meshData", memorysize, "aimMeshData"); goto cleanup; } }; | |||
1016 | status = aim_initMeshData(meshData); | |||
1017 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1017 , __func__, 0); goto cleanup; }; | |||
1018 | ||||
1019 | /* read in the groupName from mapbc file */ | |||
1020 | snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".mapbc"); | |||
1021 | ||||
1022 | if (access(filename, F_OK0) == 0) { | |||
1023 | // Correct the groupID's to be consistent with groupMap | |||
1024 | fpID = fopen(filename, "r"); | |||
1025 | if (fpID == NULL((void*)0)) { | |||
1026 | AIM_ERROR(aimStruc, "Failed to open %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1026, __func__ , "Failed to open %s", filename); }; | |||
1027 | status = CAPS_IOERR-332; | |||
1028 | goto cleanup; | |||
1029 | } | |||
1030 | status = fscanf(fpID, "%d", &nBCName); | |||
1031 | if (status != 1) { | |||
1032 | AIM_ERROR(aimStruc, "Failed to read %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1032, __func__ , "Failed to read %s", filename); }; | |||
1033 | status = CAPS_IOERR-332; | |||
1034 | goto cleanup; | |||
1035 | } | |||
1036 | ||||
1037 | AIM_ALLOC(bcName, nBCName, NameID, aimStruc, status){ if (bcName != ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 1037, __func__, 1, "AIM_ALLOC: %s != NULL" , "bcName"); goto cleanup; } size_t memorysize = nBCName; bcName = (NameID *) EG_alloc(memorysize*sizeof(NameID)); if (bcName == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c" , 1037, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "bcName" , memorysize, "NameID"); goto cleanup; } }; | |||
1038 | for (i = 0; i < nBCName; i++) { bcName[i].name = NULL((void*)0); bcName[i].ID = 0; } | |||
1039 | ||||
1040 | for (i = 0; i < nBCName; i++) { | |||
1041 | status = fscanf(fpID, "%d %d %s", &bcName[i].ID, &j, groupName); | |||
1042 | if (status != 3) { | |||
1043 | AIM_ERROR(aimStruc, "Failed to read %s", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1043, __func__ , "Failed to read %s", filename); }; | |||
1044 | status = CAPS_IOERR-332; | |||
1045 | goto cleanup; | |||
1046 | } | |||
1047 | ||||
1048 | AIM_STRDUP(bcName[i].name, groupName, aimStruc, status){ if (bcName[i].name != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1048, __func__, 1, "AIM_STRDUP: %s != NULL!" , "bcName[i].name"); goto cleanup; } bcName[i].name = EG_strdup (groupName); if (bcName[i].name == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c", 1048, __func__, 2, "AIM_STRDUP: %s %s", "bcName[i].name", groupName); goto cleanup ; } }; | |||
1049 | } | |||
1050 | ||||
1051 | /*@-dependenttrans@*/ | |||
1052 | fclose(fpID); fpID = NULL((void*)0); | |||
1053 | /*@+dependenttrans@*/ | |||
1054 | } | |||
1055 | ||||
1056 | ||||
1057 | snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".lb8.ugrid"); | |||
1058 | ||||
1059 | fp = fopen(filename, "rb"); | |||
1060 | if (fp == NULL((void*)0)) { | |||
1061 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1061, __func__ , "Cannot open file: %s\n", filename); }; | |||
1062 | status = CAPS_IOERR-332; | |||
1063 | goto cleanup; | |||
1064 | } | |||
1065 | ||||
1066 | // Open a 2nd copy to read in the BC ID's | |||
1067 | fpID = fopen(filename, "rb"); | |||
1068 | if (fpID == NULL((void*)0)) { | |||
1069 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", filename){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1069, __func__ , "Cannot open file: %s\n", filename); }; | |||
1070 | status = CAPS_IOERR-332; | |||
1071 | goto cleanup; | |||
1072 | } | |||
1073 | ||||
1074 | /* read a binary UGRID file */ | |||
1075 | status = fread(&meshData->nVertex, sizeof(int), 1, fp); | |||
1076 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1076 , __func__, 0); goto cleanup; }; } | |||
1077 | status = fread(&nTri, sizeof(int), 1, fp); | |||
1078 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1078 , __func__, 0); goto cleanup; }; } | |||
1079 | status = fread(&nQuad, sizeof(int), 1, fp); | |||
1080 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1080 , __func__, 0); goto cleanup; }; } | |||
1081 | status = fread(&nTet, sizeof(int), 1, fp); | |||
1082 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1082 , __func__, 0); goto cleanup; }; } | |||
1083 | status = fread(&nPyramid, sizeof(int), 1, fp); | |||
1084 | if (status != 1) { 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(&nPrism, 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 | status = fread(&nHex, sizeof(int), 1, fp); | |||
1088 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1088 , __func__, 0); goto cleanup; }; } | |||
1089 | ||||
1090 | /* skip the header */ | |||
1091 | status = fseek(fpID, 7*sizeof(int), SEEK_CUR1); | |||
1092 | if (status != 0) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1092 , __func__, 0); goto cleanup; }; } | |||
1093 | ||||
1094 | /* | |||
1095 | printf("\n Header from UGRID file: %d %d %d %d %d %d %d\n", numNode, | |||
1096 | numTriangle, numQuadrilateral, numTetrahedral, numPyramid, numPrism, | |||
1097 | numHexahedral); | |||
1098 | */ | |||
1099 | ||||
1100 | snprintf(filename, PATH_MAX4096, "%s%s", mesh->meshRef->fileName, ".mapvol"); | |||
1101 | ||||
1102 | // File for volume IDs | |||
1103 | fpMV = fopen(filename, "rb"); | |||
1104 | if (fpMV != NULL((void*)0)) { | |||
1105 | status = fread(&nRegion, sizeof(int), 1, fpMV); | |||
1106 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1106 , __func__, 0); goto cleanup; }; } | |||
1107 | ||||
1108 | /* read the maximum ID value */ | |||
1109 | status = fread(&nVolName, sizeof(int), 1, fpMV); | |||
1110 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1110 , __func__, 0); goto cleanup; }; } | |||
1111 | ||||
1112 | if (nRegion+nVolName == 0) { | |||
1113 | AIM_ERROR(aimStruc, "Invalid mapvol file with zero nRegion and nVolName!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1113, __func__ , "Invalid mapvol file with zero nRegion and nVolName!"); }; | |||
1114 | status = CAPS_IOERR-332; | |||
1115 | goto cleanup; | |||
1116 | } | |||
1117 | ||||
1118 | AIM_ALLOC(volName, nVolName, NameID, aimStruc, status){ if (volName != ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 1118, __func__, 1, "AIM_ALLOC: %s != NULL" , "volName"); goto cleanup; } size_t memorysize = nVolName; volName = (NameID *) EG_alloc(memorysize*sizeof(NameID)); if (volName == ((void*)0)) { status = -4; aim_status(aimStruc, status, "aimMesh.c" , 1118, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "volName" , memorysize, "NameID"); goto cleanup; } }; | |||
1119 | for (i = 0; i < nVolName; i++) { volName[i].name = NULL((void*)0); volName[i].ID = 0; } | |||
1120 | ||||
1121 | for (i = 0; i < nRegion; i++) { | |||
1122 | status = fread(&volName[i].ID, sizeof(int), 1, fpMV); | |||
1123 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1123 , __func__, 0); goto cleanup; }; } | |||
1124 | ||||
1125 | status = fread(&len, sizeof(size_t), 1, fpMV); | |||
1126 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1126 , __func__, 0); goto cleanup; }; } | |||
1127 | ||||
1128 | AIM_ALLOC(volName[i].name, len, char, aimStruc, status){ if (volName[i].name != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1128, __func__, 1, "AIM_ALLOC: %s != NULL" , "volName[i].name"); goto cleanup; } size_t memorysize = len ; volName[i].name = (char *) EG_alloc(memorysize*sizeof(char) ); if (volName[i].name == ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1128, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "volName[i].name", memorysize, "char"); goto cleanup; } }; | |||
1129 | ||||
1130 | status = fread(volName[i].name, sizeof(char), len, fpMV); | |||
1131 | if (status != len) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1131 , __func__, 0); goto cleanup; }; } | |||
1132 | } | |||
1133 | ||||
1134 | status = fread(&nElems, sizeof(int), 1, fpMV); | |||
1135 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1135 , __func__, 0); goto cleanup; }; } | |||
1136 | ||||
1137 | if (nElems != nTet+nPyramid+nPrism+nHex) { | |||
1138 | AIM_ERROR(aimStruc, "Element count missmatch in mapvol file!"){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1138, __func__ , "Element count missmatch in mapvol file!"); }; | |||
1139 | status = CAPS_IOERR-332; | |||
1140 | goto cleanup; | |||
1141 | } | |||
1142 | } | |||
1143 | ||||
1144 | AIM_ALLOC(meshData->verts, meshData->nVertex, aimMeshCoords, aimStruc, status){ if (meshData->verts != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1144, __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" , 1144, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshData->verts" , memorysize, "aimMeshCoords"); goto cleanup; } }; | |||
1145 | ||||
1146 | /* read all of the vertices */ | |||
1147 | status = fread(meshData->verts, sizeof(aimMeshCoords), meshData->nVertex, fp); | |||
1148 | if (status != meshData->nVertex) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1148 , __func__, 0); goto cleanup; }; } | |||
1149 | ||||
1150 | /* skip the verts */ | |||
1151 | status = fseek(fpID, meshData->nVertex*sizeof(aimMeshCoords), SEEK_CUR1); | |||
1152 | if (status != 0) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1152 , __func__, 0); goto cleanup; }; } | |||
1153 | ||||
1154 | ||||
1155 | // Numbers | |||
1156 | meshData->nTotalElems = nTri + | |||
1157 | nQuad + | |||
1158 | nTet + | |||
1159 | nPyramid + | |||
1160 | nPrism + | |||
1161 | nHex; | |||
1162 | ||||
1163 | // allocate the element map that maps back to the original element numbering | |||
1164 | AIM_ALLOC(meshData->elemMap, meshData->nTotalElems, aimMeshIndices, aimStruc, status){ if (meshData->elemMap != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1164, __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", 1164, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "meshData->elemMap", memorysize, "aimMeshIndices"); goto cleanup; } }; | |||
1165 | ||||
1166 | /* | |||
1167 | printf("Volume mesh:\n"); | |||
1168 | printf("\tNumber of nodes = %d\n", meshData->nVertex); | |||
1169 | printf("\tNumber of elements = %d\n", meshData->nTotalElems); | |||
1170 | printf("\tNumber of triangles = %d\n", numTriangle); | |||
1171 | printf("\tNumber of quadrilatarals = %d\n", numQuadrilateral); | |||
1172 | printf("\tNumber of tetrahedrals = %d\n", numTetrahedral); | |||
1173 | printf("\tNumber of pyramids = %d\n", numPyramid); | |||
1174 | printf("\tNumber of prisms = %d\n", numPrism); | |||
1175 | printf("\tNumber of hexahedrals = %d\n", numHexahedral); | |||
1176 | */ | |||
1177 | ||||
1178 | /* skip the Tri+Quad elements for the ID */ | |||
1179 | status = fseek(fpID, (3*nTri+4*nQuad)*sizeof(int), SEEK_CUR1); | |||
1180 | if (status != 0) { status = CAPS_IOERR-332; goto cleanup; } | |||
1181 | ||||
1182 | /* Start of element index */ | |||
1183 | elementIndex = 0; | |||
1184 | ||||
1185 | /* Elements triangles */ | |||
1186 | nPoint = 3; | |||
1187 | elementTopo = aimTri; | |||
1188 | nElems = nTri; | |||
1189 | ||||
1190 | status = aim_readBinaryUgridElements(aimStruc, fp, fpID, | |||
1191 | nBCName, nTet+nPyramid+nPrism+nHex == 0 ? NULL((void*)0) : bcName, | |||
1192 | nPoint, elementTopo, nElems, | |||
1193 | &elementIndex, meshData); | |||
1194 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1194 , __func__, 0); goto cleanup; }; | |||
1195 | ||||
1196 | /* Elements quadrilateral */ | |||
1197 | nPoint = 4; | |||
1198 | elementTopo = aimQuad; | |||
1199 | nElems = nQuad; | |||
1200 | ||||
1201 | status = aim_readBinaryUgridElements(aimStruc, fp, fpID, | |||
1202 | nBCName, nTet+nPyramid+nPrism+nHex == 0 ? NULL((void*)0) : bcName, | |||
1203 | nPoint, elementTopo, nElems, | |||
1204 | &elementIndex, meshData); | |||
1205 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1205 , __func__, 0); goto cleanup; }; | |||
1206 | ||||
1207 | /*@-dependenttrans@*/ | |||
1208 | fclose(fpID); fpID = NULL((void*)0); | |||
1209 | /*@+dependenttrans@*/ | |||
1210 | ||||
1211 | // skip face ID section of the file | |||
1212 | status = fseek(fp, (nTri + nQuad)*sizeof(int), SEEK_CUR1); | |||
1213 | if (status != 0) { status = CAPS_IOERR-332; goto cleanup; } | |||
1214 | ||||
1215 | // Elements Tetrahedral | |||
1216 | nPoint = 4; | |||
1217 | elementTopo = aimTet; | |||
1218 | nElems = nTet; | |||
1219 | ||||
1220 | status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, | |||
1221 | nVolName, volName, | |||
1222 | nPoint, elementTopo, nElems, | |||
1223 | &elementIndex, meshData); | |||
1224 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1224 , __func__, 0); goto cleanup; }; | |||
1225 | ||||
1226 | // Elements Pyramid | |||
1227 | nPoint = 5; | |||
1228 | elementTopo = aimPyramid; | |||
1229 | nElems = nPyramid; | |||
1230 | ||||
1231 | status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, | |||
1232 | nVolName, volName, | |||
1233 | nPoint, elementTopo, nElems, | |||
1234 | &elementIndex, meshData); | |||
1235 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1235 , __func__, 0); goto cleanup; }; | |||
1236 | ||||
1237 | // Elements Prism | |||
1238 | nPoint = 6; | |||
1239 | elementTopo = aimPrism; | |||
1240 | nElems = nPrism; | |||
1241 | ||||
1242 | status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, | |||
1243 | nVolName, volName, | |||
1244 | nPoint, elementTopo, nElems, | |||
1245 | &elementIndex, meshData); | |||
1246 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1246 , __func__, 0); goto cleanup; }; | |||
1247 | ||||
1248 | // Elements Hex | |||
1249 | nPoint = 8; | |||
1250 | elementTopo = aimHex; | |||
1251 | nElems = nHex; | |||
1252 | ||||
1253 | status = aim_readBinaryUgridElements(aimStruc, fp, fpMV, | |||
1254 | nVolName, volName, | |||
1255 | nPoint, elementTopo, nElems, | |||
1256 | &elementIndex, meshData); | |||
1257 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1257 , __func__, 0); goto cleanup; }; | |||
1258 | ||||
1259 | // 2D grid | |||
1260 | if (nTet+nPyramid+nPrism+nHex == 0) { | |||
1261 | meshData->dim = 2; | |||
1262 | ||||
1263 | status = fread(&nLine, sizeof(int), 1, fp); | |||
1264 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1264 , __func__, 0); goto cleanup; }; } | |||
1265 | ||||
1266 | meshData->nTotalElems += nLine; | |||
1267 | 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", 1267, __func__, 3, "AIM_REALL: %s size %zu type %s", "meshData->elemMap" , memorysize, "aimMeshIndices"); goto cleanup; } }; | |||
1268 | ||||
1269 | // Elements Line | |||
1270 | nPoint = 2; | |||
1271 | elementTopo = aimLine; | |||
1272 | nElems = nLine; | |||
1273 | ||||
1274 | for (i = 0; i < nElems; i++) { | |||
1275 | /* read the element connectivity */ | |||
1276 | status = fread(line, sizeof(int), nPoint, fp); | |||
1277 | if (status != nPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1277 , __func__, 0); goto cleanup; }; } | |||
1278 | status = fread(&ID, sizeof(int), 1, fp); | |||
1279 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1279 , __func__, 0); goto cleanup; }; } | |||
1280 | if (ID <= 0) { | |||
1281 | AIM_ERROR(aimStruc, "BC ID must be a positive number: %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1281, __func__ , "BC ID must be a positive number: %d!", ID); }; | |||
1282 | status = CAPS_IOERR-332; | |||
1283 | goto cleanup; | |||
1284 | } | |||
1285 | ||||
1286 | /* add the BC group if necessary */ | |||
1287 | if (ID
| |||
1288 | 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", 1288, __func__ , 3, "AIM_REALL: %s size %zu type %s", "mapGroupID", memorysize , "int"); goto cleanup; } }; | |||
1289 | for (j = nMapGroupID; j
| |||
1290 | nMapGroupID = ID; | |||
1291 | } | |||
1292 | if (mapGroupID[ID-1] == -1) { | |||
1293 | j = 0; | |||
1294 | while (bcName[j].ID != ID) { | |||
| ||||
1295 | j++; | |||
1296 | if (nBCName == j) { | |||
1297 | AIM_ERROR(aimStruc, "Failed to find 'name' for ID %d!", ID){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1297, __func__ , "Failed to find 'name' for ID %d!", ID); }; | |||
1298 | status = CAPS_IOERR-332; | |||
1299 | goto cleanup; | |||
1300 | } | |||
1301 | } | |||
1302 | status = aim_addMeshElemGroup(aimStruc, NULL((void*)0), ID, elementTopo, 1, nPoint, meshData); | |||
1303 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1303 , __func__, 0); goto cleanup; }; | |||
1304 | mapGroupID[ID-1] = meshData->nElemGroup-1; | |||
1305 | } | |||
1306 | ||||
1307 | igroup = mapGroupID[ID-1]; | |||
1308 | ||||
1309 | /* add the elements to the group */ | |||
1310 | status = aim_addMeshElem(aimStruc, 1, &meshData->elemGroups[igroup]); | |||
1311 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1311 , __func__, 0); goto cleanup; }; | |||
1312 | ||||
1313 | meshData->elemGroups[igroup].elements[nPoint*meshData->elemGroups[igroup].nElems-2] = line[0]; | |||
1314 | meshData->elemGroups[igroup].elements[nPoint*meshData->elemGroups[igroup].nElems-1] = line[1]; | |||
1315 | ||||
1316 | meshData->elemMap[elementIndex][0] = igroup; | |||
1317 | meshData->elemMap[elementIndex][1] = i; | |||
1318 | ||||
1319 | elementIndex += 1; | |||
1320 | } | |||
1321 | ||||
1322 | } else { | |||
1323 | meshData->dim = 3; | |||
1324 | } | |||
1325 | ||||
1326 | mesh->meshData = meshData; | |||
1327 | meshData = NULL((void*)0); | |||
1328 | ||||
1329 | status = CAPS_SUCCESS0; | |||
1330 | ||||
1331 | cleanup: | |||
1332 | if (status != CAPS_SUCCESS0) { | |||
1333 | aim_freeMeshData(meshData); | |||
1334 | AIM_FREE(meshData){ EG_free(meshData); meshData = ((void*)0); }; | |||
1335 | } | |||
1336 | AIM_FREE(mapGroupID){ EG_free(mapGroupID); mapGroupID = ((void*)0); }; | |||
1337 | ||||
1338 | if (volName != NULL((void*)0)) { | |||
1339 | for (i = 0; i < nVolName; i++) | |||
1340 | AIM_FREE(volName[i].name){ EG_free(volName[i].name); volName[i].name = ((void*)0); }; | |||
1341 | AIM_FREE(volName){ EG_free(volName); volName = ((void*)0); }; | |||
1342 | } | |||
1343 | ||||
1344 | if (bcName != NULL((void*)0)) { | |||
1345 | for (i = 0; i < nBCName; i++) | |||
1346 | AIM_FREE(bcName[i].name){ EG_free(bcName[i].name); bcName[i].name = ((void*)0); }; | |||
1347 | AIM_FREE(bcName){ EG_free(bcName); bcName = ((void*)0); }; | |||
1348 | } | |||
1349 | ||||
1350 | /*@-dependenttrans@*/ | |||
1351 | if (fp != NULL((void*)0)) fclose(fp); | |||
1352 | if (fpID != NULL((void*)0)) fclose(fpID); | |||
1353 | if (fpMV != NULL((void*)0)) fclose(fpMV); | |||
1354 | /*@+dependenttrans@*/ | |||
1355 | ||||
1356 | return status; | |||
1357 | } | |||
1358 | ||||
1359 | ||||
1360 | int | |||
1361 | aim_storeMeshRef(void *aimStruc, const aimMeshRef *meshRef, | |||
1362 | const char *meshextension) | |||
1363 | { | |||
1364 | int status = CAPS_SUCCESS0; | |||
1365 | ||||
1366 | int imap, ibnd, state, nvert; | |||
1367 | int i; | |||
1368 | char filename_src[PATH_MAX4096]; | |||
1369 | char filename_dst[PATH_MAX4096]; | |||
1370 | char aimFile[PATH_MAX4096]; | |||
1371 | const char *meshRefFile = "meshRef.dat"; | |||
1372 | const char *meshRefegads = "meshRef.egads"; | |||
1373 | FILE *fp = NULL((void*)0); | |||
1374 | aimInfo *aInfo; | |||
1375 | size_t len, strLen = 0; | |||
1376 | ego model, body, *bodies = NULL((void*)0); | |||
1377 | ||||
1378 | aInfo = (aimInfo *) aimStruc; | |||
1379 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1380 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
1381 | ||||
1382 | if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1383 | ||||
1384 | if (meshextension != NULL((void*)0)) { | |||
1385 | if (meshRef->fileName == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1386 | ||||
1387 | // create the full filename to the mesh in the meshing AIM directory | |||
1388 | snprintf(filename_src, PATH_MAX4096, "%s%s", meshRef->fileName, meshextension); | |||
1389 | ||||
1390 | // get the mesh filename without the directory | |||
1391 | i = strlen(filename_src); | |||
1392 | while(i > 0 && filename_src[i] != SLASH'/') { i--; } | |||
1393 | if (i < 0) { status = CAPS_IOERR-332; goto cleanup; } | |||
1394 | strcpy(filename_dst, filename_src+i+1); | |||
1395 | ||||
1396 | // copy the mesh from the meshing AIM directory to the current AIM directory | |||
1397 | status = aim_cpFile(aimStruc, filename_src, filename_dst); | |||
1398 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1398 , __func__, 0); goto cleanup; }; | |||
1399 | } | |||
1400 | ||||
1401 | // open the file to store the meshRef structure | |||
1402 | status = aim_file(aimStruc, meshRefFile, aimFile); | |||
1403 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1403 , __func__, 0); goto cleanup; }; | |||
1404 | ||||
1405 | fp = fopen(aimFile, "wb"); | |||
1406 | if (fp == NULL((void*)0)) { | |||
1407 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1407, __func__ , "Cannot open file: %s\n", aimFile); }; | |||
1408 | status = CAPS_IOERR-332; | |||
1409 | goto cleanup; | |||
1410 | } | |||
1411 | ||||
1412 | len = fwrite(&meshRef->type, sizeof(int), 1, fp); | |||
1413 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1413 , __func__, 0); goto cleanup; }; } | |||
1414 | ||||
1415 | len = fwrite(&meshRef->nmap, sizeof(int), 1, fp); | |||
1416 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1416 , __func__, 0); goto cleanup; }; } | |||
1417 | ||||
1418 | AIM_ALLOC(bodies, 2*meshRef->nmap, ego, aimStruc, status){ if (bodies != ((void*)0)) { status = -4; aim_status(aimStruc , status, "aimMesh.c", 1418, __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", 1418, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "bodies", memorysize, "ego"); goto cleanup; } }; | |||
1419 | ||||
1420 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1421 | status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert); | |||
1422 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1422 , __func__, 0); goto cleanup; }; | |||
1423 | ||||
1424 | // construct an egads file to write out the tessellation and the body | |||
1425 | status = EG_copyObject(body, NULL((void*)0), &bodies[imap]); | |||
1426 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1426 , __func__, 0); goto cleanup; }; | |||
1427 | status = EG_copyObject(meshRef->maps[imap].tess, bodies[imap], &bodies[imap+meshRef->nmap]); | |||
1428 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1428 , __func__, 0); goto cleanup; }; | |||
1429 | ||||
1430 | // store the body index | |||
1431 | status = EG_attributeAdd(bodies[imap], CAPS_BODY_INDX"--CAPS-BODY-INDX--", ATTRINT1, 1, &imap, NULL((void*)0), NULL((void*)0)); | |||
1432 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1432 , __func__, 0); goto cleanup; }; | |||
1433 | } | |||
1434 | ||||
1435 | status = EG_makeTopology(aInfo->problem->context, NULL((void*)0), MODEL26, 2*meshRef->nmap, | |||
1436 | NULL((void*)0), meshRef->nmap, bodies, NULL((void*)0), &model); | |||
1437 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1437 , __func__, 0); goto cleanup; }; | |||
1438 | ||||
1439 | status = aim_file(aimStruc, meshRefegads, aimFile); | |||
1440 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1440 , __func__, 0); goto cleanup; }; | |||
1441 | ||||
1442 | remove(aimFile); | |||
1443 | status = EG_saveModel(model, aimFile); | |||
1444 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1444 , __func__, 0); goto cleanup; }; | |||
1445 | ||||
1446 | EG_deleteObject(model); | |||
1447 | ||||
1448 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1449 | status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert); | |||
1450 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1450 , __func__, 0); goto cleanup; }; | |||
1451 | ||||
1452 | // write the surface to volume map | |||
1453 | len = fwrite(meshRef->maps[imap].map, sizeof(int), nvert, fp); | |||
1454 | if (len != nvert) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1454 , __func__, 0); goto cleanup; }; } | |||
1455 | } | |||
1456 | ||||
1457 | len = fwrite(&meshRef->nbnd, sizeof(int), 1, fp); | |||
1458 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1458 , __func__, 0); goto cleanup; }; } | |||
1459 | ||||
1460 | for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) { | |||
1461 | ||||
1462 | strLen = strlen(meshRef->bnds[ibnd].groupName)+1; | |||
1463 | ||||
1464 | len = fwrite(&strLen, sizeof(size_t), 1, fp); | |||
1465 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1465 , __func__, 0); goto cleanup; }; } | |||
1466 | ||||
1467 | len = fwrite(meshRef->bnds[ibnd].groupName, sizeof(char), strLen, fp); | |||
1468 | if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1468 , __func__, 0); goto cleanup; }; } | |||
1469 | ||||
1470 | len = fwrite(&meshRef->bnds[ibnd].ID, sizeof(int), 1, fp); | |||
1471 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1471 , __func__, 0); goto cleanup; }; } | |||
1472 | } | |||
1473 | ||||
1474 | // write meshRef->filename (i.e. filename_dst without the extension) | |||
1475 | if (meshRef->fileName != NULL((void*)0)) { | |||
1476 | strLen = strlen(filename_dst); | |||
1477 | if (meshextension != NULL((void*)0)) | |||
1478 | filename_dst[strLen - strlen(meshextension)] = '\0'; | |||
1479 | status = aim_file(aimStruc, filename_dst, aimFile); | |||
1480 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1480 , __func__, 0); goto cleanup; }; | |||
1481 | ||||
1482 | strLen = strlen(aimFile)+1; | |||
1483 | } | |||
1484 | ||||
1485 | len = fwrite(&strLen, sizeof(size_t), 1, fp); | |||
1486 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1486 , __func__, 0); goto cleanup; }; } | |||
1487 | ||||
1488 | len = fwrite(aimFile, sizeof(char), strLen, fp); | |||
1489 | if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1489 , __func__, 0); goto cleanup; }; } | |||
1490 | ||||
1491 | cleanup: | |||
1492 | /*@-dependenttrans@*/ | |||
1493 | if (fp != NULL((void*)0)) fclose(fp); | |||
1494 | /*@+dependenttrans@*/ | |||
1495 | AIM_FREE(bodies){ EG_free(bodies); bodies = ((void*)0); }; | |||
1496 | ||||
1497 | return status; | |||
1498 | } | |||
1499 | ||||
1500 | ||||
1501 | int | |||
1502 | aim_loadMeshRef(void *aimStruc, aimMeshRef *meshRef) | |||
1503 | { | |||
1504 | int status = CAPS_SUCCESS0; | |||
1505 | ||||
1506 | int j, imap, ibnd, state, nvert, nbody; | |||
1507 | int oclass, mtype, *senses, alen, atype; | |||
1508 | char aimFile[PATH_MAX4096]; | |||
1509 | double limits[4]; | |||
1510 | const int *aints=NULL((void*)0); | |||
1511 | const double *areals=NULL((void*)0); | |||
1512 | const char *astring=NULL((void*)0); | |||
1513 | const char *meshRefFile = "meshRef.dat"; | |||
1514 | const char *meshRefegads = "meshRef.egads"; | |||
1515 | FILE *fp = NULL((void*)0); | |||
1516 | aimInfo *aInfo; | |||
1517 | size_t len, strLen; | |||
1518 | ego geom, model, body, tessbody, *bodies; | |||
1519 | ||||
1520 | aInfo = (aimInfo *) aimStruc; | |||
1521 | if (aInfo == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1522 | if (aInfo->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310; | |||
1523 | ||||
1524 | if (meshRef == NULL((void*)0)) return CAPS_NULLOBJ-309; | |||
1525 | ||||
1526 | // delete the old mesh reference if necessary | |||
1527 | status = aim_freeMeshRef(meshRef); | |||
1528 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1528 , __func__, 0); goto cleanup; }; | |||
1529 | ||||
1530 | // open the file to read the meshRef structure | |||
1531 | status = aim_file(aimStruc, meshRefFile, aimFile); | |||
1532 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1532 , __func__, 0); goto cleanup; }; | |||
1533 | ||||
1534 | fp = fopen(aimFile, "rb"); | |||
1535 | if (fp == NULL((void*)0)) { | |||
1536 | AIM_ERROR(aimStruc, "Cannot open file: %s\n", aimFile){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1536, __func__ , "Cannot open file: %s\n", aimFile); }; | |||
1537 | status = CAPS_IOERR-332; | |||
1538 | goto cleanup; | |||
1539 | } | |||
1540 | ||||
1541 | len = fread(&meshRef->type, sizeof(int), 1, fp); | |||
1542 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1542 , __func__, 0); goto cleanup; }; } | |||
1543 | ||||
1544 | len = fread(&meshRef->nmap, sizeof(int), 1, fp); | |||
1545 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1545 , __func__, 0); goto cleanup; }; } | |||
1546 | ||||
1547 | AIM_ALLOC(meshRef->maps, meshRef->nmap, aimMeshTessMap, aimStruc, status){ if (meshRef->maps != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1547, __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", 1547 , __func__, 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->maps" , memorysize, "aimMeshTessMap"); goto cleanup; } }; | |||
1548 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1549 | meshRef->maps[imap].tess = NULL((void*)0); | |||
1550 | meshRef->maps[imap].map = NULL((void*)0); | |||
1551 | } | |||
1552 | ||||
1553 | status = aim_file(aimStruc, meshRefegads, aimFile); | |||
1554 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1554 , __func__, 0); goto cleanup; }; | |||
1555 | ||||
1556 | status = EG_loadModel(aInfo->problem->context, 0, aimFile, &model); | |||
1557 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1557 , __func__, 0); goto cleanup; }; | |||
1558 | ||||
1559 | status = EG_getTopology(model, &geom, &oclass, &mtype, limits, | |||
1560 | &nbody, &bodies, &senses); | |||
1561 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1561 , __func__, 0); goto cleanup; }; | |||
1562 | ||||
1563 | if (nbody != meshRef->nmap) { | |||
1564 | AIM_ERROR(aimStruc, "Missmatch between %s and %s!", meshRefFile, meshRefegads){ aim_message(aimStruc, CERROR, 0 , "aimMesh.c", 1564, __func__ , "Missmatch between %s and %s!", meshRefFile, meshRefegads); }; | |||
1565 | status = CAPS_IOERR-332; | |||
1566 | goto cleanup; | |||
1567 | } | |||
1568 | ||||
1569 | // copy the body and tessellatoin out of the model | |||
1570 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1571 | status = EG_copyObject(bodies[imap], NULL((void*)0), &body); | |||
1572 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1572 , __func__, 0); goto cleanup; }; | |||
1573 | ||||
1574 | // get the original body index | |||
1575 | status = EG_attributeRet(body, CAPS_BODY_INDX"--CAPS-BODY-INDX--", &atype, &alen, &aints, &areals, &astring); | |||
1576 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1576 , __func__, 0); goto cleanup; }; | |||
1577 | AIM_NOTNULL(aints, aimStruc, status){ if (aints == ((void*)0)) { status = -307; aim_status(aimStruc , status, "aimMesh.c", 1577, __func__, 1, "%s == NULL!", "aints" ); goto cleanup; } }; | |||
1578 | ||||
1579 | status = EG_attributeDel(body, CAPS_BODY_INDX"--CAPS-BODY-INDX--"); | |||
1580 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1580 , __func__, 0); goto cleanup; }; | |||
1581 | ||||
1582 | // find the tessellation for this body | |||
1583 | for (j = 0; j < meshRef->nmap; j++) { | |||
1584 | status = EG_statusTessBody(bodies[j+meshRef->nmap], &tessbody, &state, &nvert); | |||
1585 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1585 , __func__, 0); goto cleanup; }; | |||
1586 | ||||
1587 | if (tessbody == bodies[imap]) { | |||
1588 | // copy the tessellation with the copied body | |||
1589 | status = EG_copyObject(bodies[j+meshRef->nmap], body, &meshRef->maps[aints[0]].tess); | |||
1590 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1590 , __func__, 0); goto cleanup; }; | |||
1591 | break; | |||
1592 | } | |||
1593 | } | |||
1594 | } | |||
1595 | ||||
1596 | // delete the model | |||
1597 | EG_deleteObject(model); | |||
1598 | ||||
1599 | for (imap = 0; imap < meshRef->nmap; imap++) { | |||
1600 | // read the surface to volume map | |||
1601 | status = EG_statusTessBody(meshRef->maps[imap].tess, &body, &state, &nvert); | |||
1602 | AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1602 , __func__, 0); goto cleanup; }; | |||
1603 | ||||
1604 | 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", 1604, __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", 1604, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "meshRef->maps[imap].map", memorysize, "int"); goto cleanup ; } }; | |||
1605 | ||||
1606 | len = fread(meshRef->maps[imap].map, sizeof(int), nvert, fp); | |||
1607 | if (len != nvert) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1607 , __func__, 0); goto cleanup; }; } | |||
1608 | } | |||
1609 | ||||
1610 | // read the bounds | |||
1611 | len = fread(&meshRef->nbnd, sizeof(int), 1, fp); | |||
1612 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1612 , __func__, 0); goto cleanup; }; } | |||
1613 | ||||
1614 | AIM_ALLOC(meshRef->bnds, meshRef->nbnd, aimMeshBnd, aimStruc, status){ if (meshRef->bnds != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1614, __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", 1614, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->bnds", memorysize , "aimMeshBnd"); goto cleanup; } }; | |||
1615 | for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) { | |||
1616 | meshRef->bnds[ibnd].groupName = NULL((void*)0); | |||
1617 | meshRef->bnds[ibnd].ID = 0; | |||
1618 | } | |||
1619 | ||||
1620 | for (ibnd = 0; ibnd < meshRef->nbnd; ibnd++) { | |||
1621 | ||||
1622 | len = fread(&strLen, sizeof(size_t), 1, fp); | |||
1623 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1623 , __func__, 0); goto cleanup; }; } | |||
1624 | ||||
1625 | 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", 1625, __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", 1625, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->bnds[ibnd].groupName" , memorysize, "char"); goto cleanup; } }; | |||
1626 | ||||
1627 | len = fread(meshRef->bnds[ibnd].groupName, sizeof(char), strLen, fp); | |||
1628 | if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1628 , __func__, 0); goto cleanup; }; } | |||
1629 | ||||
1630 | len = fread(&meshRef->bnds[ibnd].ID, sizeof(int), 1, fp); | |||
1631 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1631 , __func__, 0); goto cleanup; }; } | |||
1632 | } | |||
1633 | ||||
1634 | // read meshRef->filename | |||
1635 | len = fread(&strLen, sizeof(size_t), 1, fp); | |||
1636 | if (len != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1636 , __func__, 0); goto cleanup; }; } | |||
1637 | ||||
1638 | if (strLen > 0) { | |||
1639 | AIM_ALLOC(meshRef->fileName, strLen, char, aimStruc, status){ if (meshRef->fileName != ((void*)0)) { status = -4; aim_status (aimStruc, status, "aimMesh.c", 1639, __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", 1639, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->fileName" , memorysize, "char"); goto cleanup; } }; | |||
1640 | ||||
1641 | len = fread(meshRef->fileName, sizeof(char), strLen, fp); | |||
1642 | if (len != strLen) { status = CAPS_IOERR-332; AIM_STATUS(aimStruc, status)if (status != 0) { aim_status(aimStruc, status, "aimMesh.c", 1642 , __func__, 0); goto cleanup; }; } | |||
1643 | } | |||
1644 | ||||
1645 | // indicate that the tessellation and body should be deleted | |||
1646 | meshRef->_delTess = (int)true1; | |||
1647 | ||||
1648 | cleanup: | |||
1649 | /*@-dependenttrans@*/ | |||
1650 | if (fp != NULL((void*)0)) fclose(fp); | |||
1651 | /*@+dependenttrans@*/ | |||
1652 | ||||
1653 | return status; | |||
1654 | } | |||
1655 | ||||
1656 | ||||
1657 | // Map the old surface tessellation on to the new bodies | |||
1658 | int aim_morphMeshUpdate(void *aimInfo, aimMeshRef *meshRef, int numBody, ego *bodies) | |||
1659 | { | |||
1660 | int status = CAPS_SUCCESS0; | |||
1661 | int i=0,j, localIndex, topoIndex, iglobal_old, iglobal_new; | |||
1662 | int state, numVert, aType, alen, *map_old=NULL((void*)0); | |||
1663 | const int *nMap=NULL((void*)0), *eMap=NULL((void*)0), *fMap=NULL((void*)0); | |||
1664 | ego body, tessbody; | |||
1665 | ego tess; | |||
1666 | ||||
1667 | // Have the number of bodies changed? | |||
1668 | if (meshRef->nmap != numBody) { | |||
1669 | 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", 1669, __func__ , "The number of original surface meshes does NOT equal the number of current bodies!\n" ); }; | |||
1670 | status = CAPS_MISMATCH-324; | |||
1671 | goto cleanup; | |||
1672 | } | |||
1673 | ||||
1674 | // Are the bodies topological equivalent? | |||
1675 | for (i = 0; i < meshRef->nmap; i++) { | |||
1676 | ||||
1677 | status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &numVert); | |||
1678 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1678 , __func__, 0); goto cleanup; }; | |||
1679 | ||||
1680 | status = EG_mapBody(body, bodies[i], "_faceID", &bodies[i]); // "_faceID" - same as in OpenCSM | |||
1681 | if (status != EGADS_SUCCESS0) { | |||
1682 | 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", 1682, __func__ , "New and old body %d (of %d) do not appear to be topologically equivalent!" , i+1, meshRef->nmap); }; | |||
1683 | goto cleanup; | |||
1684 | } | |||
1685 | } | |||
1686 | ||||
1687 | // Now lets "tweak" the surface tessellation - map the old tessellation to the new bodies | |||
1688 | for (i = 0; i < meshRef->nmap; i++) { | |||
1689 | ||||
1690 | status = EG_statusTessBody(meshRef->maps[i].tess, &tessbody, &state, &numVert); | |||
1691 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1691 , __func__, 0); goto cleanup; }; | |||
1692 | ||||
1693 | // nothing to do if bodies are the same | |||
1694 | if (tessbody == bodies[i]) continue; | |||
1695 | ||||
1696 | printf("Projecting tessellation %d (of %d) on to new body\n", i+1, meshRef->nmap); | |||
1697 | ||||
1698 | status = EG_mapTessBody(meshRef->maps[i].tess, | |||
1699 | bodies[i], | |||
1700 | &tess); | |||
1701 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1701 , __func__, 0); goto cleanup; }; | |||
1702 | ||||
1703 | status = EG_attributeRet(bodies[i], ".fMap", &aType, &alen, &fMap, NULL((void*)0), NULL((void*)0)); | |||
1704 | if (status == EGADS_SUCCESS0) { | |||
1705 | status = EG_attributeRet(bodies[i], ".eMap", &aType, &alen, &eMap, NULL((void*)0), NULL((void*)0)); | |||
1706 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1706 , __func__, 0); goto cleanup; }; | |||
1707 | status = EG_attributeRet(bodies[i], ".nMap", &aType, &alen, &nMap, NULL((void*)0), NULL((void*)0)); | |||
1708 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1708 , __func__, 0); goto cleanup; }; | |||
1709 | } | |||
1710 | ||||
1711 | // update the surface to volume mapping | |||
1712 | if (fMap != NULL((void*)0)) { | |||
1713 | AIM_NOTNULL(eMap, aimInfo, status){ if (eMap == ((void*)0)) { status = -307; aim_status(aimInfo , status, "aimMesh.c", 1713, __func__, 1, "%s == NULL!", "eMap" ); goto cleanup; } }; | |||
1714 | AIM_NOTNULL(nMap, aimInfo, status){ if (nMap == ((void*)0)) { status = -307; aim_status(aimInfo , status, "aimMesh.c", 1714, __func__, 1, "%s == NULL!", "nMap" ); goto cleanup; } }; | |||
1715 | ||||
1716 | // update the mapping into the volume | |||
1717 | map_old = meshRef->maps[i].map; | |||
1718 | meshRef->maps[i].map = NULL((void*)0); | |||
1719 | ||||
1720 | 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", 1720, __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", 1720, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "meshRef->maps[i].map" , memorysize, "int"); goto cleanup; } }; | |||
1721 | ||||
1722 | // Find the boundary mesh in the global tessellation | |||
1723 | for (j = 0; j < numVert; j++) { | |||
1724 | ||||
1725 | iglobal_old = j+1; | |||
1726 | // Get the local indexes | |||
1727 | status = EG_getGlobal(meshRef->maps[i].tess, iglobal_old, | |||
1728 | &localIndex, &topoIndex, NULL((void*)0)); | |||
1729 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1729 , __func__, 0); goto cleanup; }; | |||
1730 | ||||
1731 | // Get the global index in the new tess | |||
1732 | if (localIndex == 0) { | |||
1733 | status = EG_localToGlobal(tess, localIndex, nMap[topoIndex-1], &iglobal_new); | |||
1734 | AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", nMap[topoIndex-1], localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1734 , __func__, 3, "ptype = %d, pindex = %d", nMap[topoIndex-1], localIndex ); goto cleanup; }; | |||
1735 | } else if (localIndex > 0) { | |||
1736 | status = EG_localToGlobal(tess, -eMap[topoIndex-1], localIndex, &iglobal_new); | |||
1737 | AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", eMap[topoIndex-1], localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1737 , __func__, 3, "ptype = %d, pindex = %d", eMap[topoIndex-1], localIndex ); goto cleanup; }; | |||
1738 | } else { | |||
1739 | status = EG_localToGlobal(tess, fMap[topoIndex-1], -localIndex, &iglobal_new); | |||
1740 | AIM_STATUS(aimInfo, status, "ptype = %d, pindex = %d", fMap[topoIndex-1], -localIndex)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1740 , __func__, 3, "ptype = %d, pindex = %d", fMap[topoIndex-1], - localIndex); goto cleanup; }; | |||
1741 | } | |||
1742 | ||||
1743 | meshRef->maps[i].map[iglobal_new-1] = map_old[iglobal_old-1]; | |||
1744 | } | |||
1745 | } | |||
1746 | ||||
1747 | // store the new tessellation | |||
1748 | if (meshRef->_delTess == (int)true1) { | |||
1749 | EG_deleteObject(meshRef->maps[i].tess); | |||
1750 | EG_deleteObject(tessbody); | |||
1751 | } | |||
1752 | meshRef->maps[i].tess = tess; | |||
1753 | status = aim_newTess(aimInfo, tess); | |||
1754 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "aimMesh.c", 1754 , __func__, 0); goto cleanup; }; | |||
1755 | ||||
1756 | AIM_FREE(map_old){ EG_free(map_old); map_old = ((void*)0); }; | |||
1757 | } | |||
1758 | ||||
1759 | meshRef->_delTess = (int)false0; | |||
1760 | ||||
1761 | cleanup: | |||
1762 | AIM_FREE(map_old){ EG_free(map_old); map_old = ((void*)0); }; | |||
1763 | return status; | |||
1764 | } |