Bug Summary

File:src/capsAnalysis.c
Warning:line 1361, column 9
Value stored to 'stat' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name capsAnalysis.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=none -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib/llvm-10/lib/clang/10.0.0 -D REVISION=7.6 -I ../include -I /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/ESP/LINUX64/include -I . -I /usr/include/udunits2 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-10/lib/clang/10.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-dangling-else -Wno-parentheses -Wno-unused-result -Wno-format-truncation -fdebug-compilation-dir /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/CAPS/src -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -o /home/jenkins/workspace/ESP_Stanalizer/LINUX64/CAPS/scan-build/scanCAPS/2022-02-21-093618-41363-1 -x c capsAnalysis.c
1/*
2 * CAPS: Computational Aircraft Prototype Syntheses
3 *
4 * Analysis Object Functions
5 *
6 * Copyright 2014-2022, Massachusetts Institute of Technology
7 * Licensed under The GNU Lesser General Public License, version 2.1
8 * See http://www.opensource.org/licenses/lgpl-2.1.php
9 *
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <math.h>
16
17#ifdef WIN32
18#define snprintf _snprintf
19#define strtok_r strtok_s
20#define PATH_MAX4096 _MAX_PATH
21#else
22#include <unistd.h>
23#include <limits.h>
24#endif
25
26#include "capsBase.h"
27#include "capsAIM.h"
28#include "prm.h"
29
30/* OpenCSM Defines & Includes */
31#include "common.h"
32#include "OpenCSM.h"
33
34#include "egadsTris.h"
35
36#define NOTFILLED-1 -1
37#define CROSS(a,b,c)a[0] = (b[1]*c[2]) - (b[2]*c[1]); a[1] = (b[2]*c[0]) - (b[0]*
c[2]); a[2] = (b[0]*c[1]) - (b[1]*c[0])
a[0] = (b[1]*c[2]) - (b[2]*c[1]);\
38 a[1] = (b[2]*c[0]) - (b[0]*c[2]);\
39 a[2] = (b[0]*c[1]) - (b[1]*c[0])
40#define DOT(a,b)(a[0]*b[0] + a[1]*b[1] + a[2]*b[2]) (a[0]*b[0] + a[1]*b[1] + a[2]*b[2])
41
42
43typedef struct {
44 ego geom; /* geometry object */
45 int gIndex; /* geometry object index */
46 int n; /* number of objects */
47 ego *objs; /* objects */
48 int *indices; /* markers */
49} bodyObjs;
50
51
52extern /*@null@*/ /*@only@*/
53 char *EG_strdup(/*@null@*/ const char *str);
54extern void EG_makeConnect(int k1, int k2, int *tri, int *kedge, int *ntable,
55 connect *etable, int face);
56extern int caps_statFile(const char *path);
57extern int caps_mkDir(const char *path);
58extern int caps_rmDir(const char *path);
59extern int caps_rename(const char *src, const char *dst);
60extern int caps_isNameOK(const char *name);
61extern int caps_writeProblem(const capsObject *pobject);
62extern int caps_dumpAnalysis(capsProblem *problem, capsObject *aobject);
63extern int caps_writeBound(const capsObject *bobject);
64extern int caps_writeVertexSet(capsObject *vobject);
65extern int caps_writeDataSet(capsObject *dobject);
66extern int caps_writeValueObj(capsProblem *problem, capsObject *valobj);
67extern void caps_jrnlWrite(int funID, capsProblem *problem, capsObject *obj, int status,
68 int nargs, capsJrnl *args, CAPSLONGunsigned long sNum0,
69 CAPSLONGunsigned long sNum);
70extern int caps_jrnlEnd(capsProblem *problem);
71extern int caps_jrnlRead(int funID, capsProblem *problem, capsObject *obj, int nargs,
72 capsJrnl *args, CAPSLONGunsigned long *sNum, int *status);
73
74extern int caps_dupValues(capsValue *val1, capsValue *val2);
75extern int caps_transferValueX(capsObject *source, enum capstMethod method,
76 capsObject *trgt, int *nErr, capsErrs **errs);
77extern int caps_snDataSets(const capsObject *aobject, int flag, CAPSLONGunsigned long *sn);
78extern int caps_fillCoeff2D(int nrank, int nux, int nvx, double *fit,
79 double *coeff, double *r);
80extern int caps_Aprx1DFree(/*@only@*/ capsAprx1D *approx);
81extern int caps_Aprx2DFree(/*@only@*/ capsAprx2D *approx);
82extern int caps_invInterpolate1D(capsAprx1D *interp, double *sv, double *t);
83extern int caps_invInterpolate2D(capsAprx2D *interp, double *sv, double *uv);
84extern int caps_build(capsObject *pobject, int *nErr, capsErrs **errors);
85extern int caps_freeError(/*@only@*/ capsErrs *errs);
86extern int caps_checkValueObj(capsObject *object);
87extern int caps_getDataX(capsObject *dobject, int *npts, int *rank,
88 double **data, char **units, int *nErr,
89 capsErrs **errors);
90
91
92
93void
94caps_concatErrs(/*@null@*/ capsErrs *errs, capsErrs **errors)
95{
96 int i, n;
97 capsErrs *oldErrs;
98 capsError *newErr;
99
100 if (errs == NULL((void*)0)) return;
101 if (*errors == NULL((void*)0)) {
102 *errors = errs;
103 return;
104 }
105
106 /* merge the Errors */
107 oldErrs = *errors;
108 n = errs->nError + oldErrs->nError;
109 newErr = (capsError *) EG_reall(errs->errors, n*sizeof(capsError));
110 if (newErr == NULL((void*)0)) {
111 printf(" CAPS Internal: MALLOC on %d Errors (caps_concatErrs)!\n", n);
112 caps_freeError(errs);
113 return;
114 }
115 for (i = 0; i < oldErrs->nError; i++)
116 newErr[i+errs->nError] = oldErrs->errors[i];
117 EG_free(oldErrs->errors);
118 oldErrs->errors = newErr;
119 oldErrs->nError = n;
120 EG_free(errs);
121}
122
123
124void
125caps_getAIMerrs(capsAnalysis *analysis, int *nErr, capsErrs **errors)
126{
127 capsErrs *errs;
128
129 *nErr = 0;
130 *errors = NULL((void*)0);
131 if (analysis->info.errs.nError == 0) return;
132
133 errs = (capsErrs *) EG_alloc(sizeof(capsErrs));
134 if (errs == NULL((void*)0)) {
135 printf(" CAPS Warning: Allocation Error (caps_getAIMerrs)\n");
136 return;
137 }
138 *nErr = analysis->info.errs.nError;
139 errs->nError = *nErr;
140 errs->errors = analysis->info.errs.errors;
141 *errors = errs;
142 analysis->info.errs.nError = 0;
143 analysis->info.errs.errors = NULL((void*)0);
144}
145
146
147int
148caps_queryAnalysis(capsObject *pobject, const char *aname, int *nIn, int *nOut,
149 int *execute)
150{
151 int nField, major, minor, *ranks, *fInOut;
152 char **fields;
153 void *instStore = NULL((void*)0);
154 capsProblem *problem;
155
156 if (pobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
157 if (pobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
158 if (pobject->type != PROBLEM) return CAPS_BADTYPE-306;
159 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
160 if (aname == NULL((void*)0)) return CAPS_NULLNAME-308;
161 problem = (capsProblem *) pobject->blind;
162 problem->funID = CAPS_QUERYANALYSIS40;
163
164 major = CAPSMAJOR1;
165 minor = CAPSMINOR21;
166
167 /* try to load the AIM and get the info */
168 *execute = 1;
169 return aim_Initialize(&problem->aimFPTR, aname, execute, NULL((void*)0), NULL((void*)0), &major,
170 &minor, nIn, nOut, &nField, &fields, &ranks, &fInOut,
171 &instStore);
172}
173
174
175int
176caps_getInput(capsObject *pobject, const char *aname, int index, char **ainame,
177 capsValue *defaults)
178{
179 int stat;
180 capsProblem *problem;
181
182 if (pobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
183 if (pobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
184 if (pobject->type != PROBLEM) return CAPS_BADTYPE-306;
185 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
186 if (aname == NULL((void*)0)) return CAPS_NULLNAME-308;
187 problem = (capsProblem *) pobject->blind;
188 problem->funID = CAPS_GETINPUT42;
189
190 defaults->length = defaults->nrow = defaults->ncol = 1;
191 defaults->type = Integer;
192 defaults->dim = defaults->pIndex = defaults->index = 0;
193 defaults->lfixed = defaults->sfixed = Fixed;
194 defaults->nullVal = NotAllowed;
195 defaults->units = NULL((void*)0);
196 defaults->meshWriter = NULL((void*)0);
197 defaults->link = NULL((void*)0);
198 defaults->vals.integer = 0;
199 defaults->limits.dlims[0] = defaults->limits.dlims[1] = 0.0;
200 defaults->linkMethod = Copy;
201 defaults->gInType = 0;
202 defaults->partial = NULL((void*)0);
203 defaults->nderiv = 0;
204 defaults->derivs = NULL((void*)0);
205
206 stat = aim_Inputs(problem->aimFPTR, aname, NULL((void*)0), NULL((void*)0), index, ainame,
207 defaults);
208 if (stat == CAPS_SUCCESS0) defaults->length = defaults->ncol*defaults->nrow;
209 return stat;
210}
211
212
213int
214caps_getOutput(capsObject *pobject, const char *aname, int index, char **aoname,
215 capsValue *form)
216{
217 int stat;
218 capsProblem *problem;
219
220 if (pobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
221 if (pobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
222 if (pobject->type != PROBLEM) return CAPS_BADTYPE-306;
223 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
224 if (aname == NULL((void*)0)) return CAPS_NULLNAME-308;
225 problem = (capsProblem *) pobject->blind;
226 problem->funID = CAPS_GETOUTPUT43;
227
228 form->length = form->nrow = form->ncol = 1;
229 form->type = Integer;
230 form->dim = form->pIndex = form->index = 0;
231 form->lfixed = form->sfixed = Fixed;
232 form->nullVal = NotAllowed;
233 form->units = NULL((void*)0);
234 form->meshWriter = NULL((void*)0);
235 form->link = NULL((void*)0);
236 form->vals.integer = 0;
237 form->limits.dlims[0] = form->limits.dlims[1] = 0.0;
238 form->linkMethod = Copy;
239 form->gInType = 0;
240 form->partial = NULL((void*)0);
241 form->nderiv = 0;
242 form->derivs = NULL((void*)0);
243
244 stat = aim_Outputs(problem->aimFPTR, aname, NULL((void*)0), NULL((void*)0), index, aoname, form);
245 if (stat == CAPS_SUCCESS0) form->length = form->ncol*form->nrow;
246 return stat;
247}
248
249
250int
251caps_AIMbackdoor(capsObject *aobject, const char *JSONin, char **JSONout)
252{
253 int stat, ret;
254 capsObject *pobject;
255 capsProblem *problem;
256 capsAnalysis *analysis;
257 CAPSLONGunsigned long sNum;
258 capsJrnl args[1];
259
260 *JSONout = NULL((void*)0);
261 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
262 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
263 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
264 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
265 if (aobject->parent == NULL((void*)0)) return CAPS_NULLOBJ-309;
266 pobject = (capsObject *) aobject->parent;
267 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
268 analysis = (capsAnalysis *) aobject->blind;
269 problem = (capsProblem *) pobject->blind;
270
271 args[0].type = jString;
272 if (problem->dbFlag == 0) {
273 stat = caps_jrnlRead(CAPS_AIMBACKDOOR59, problem, aobject, 1, args, &sNum, &ret);
274 if (stat == CAPS_JOURNALERR-343) return stat;
275 if (stat == CAPS_JOURNAL-342) {
276 *JSONout = EG_strdup(args[0].members.string);
277 return ret;
278 }
279 }
280
281 ret = aim_Backdoor(problem->aimFPTR, analysis->loadName, analysis->instStore,
282 &analysis->info, JSONin, JSONout);
283 if (problem->dbFlag == 1) return ret;
284 args[0].members.string = *JSONout;
285 caps_jrnlWrite(CAPS_AIMBACKDOOR59, problem, aobject, ret, 1, args, problem->sNum, problem->sNum);
286
287 return ret;
288}
289
290
291int
292caps_system(capsObject *aobject, /*@null@*/ const char *rpath,
293 const char *command)
294{
295 size_t status, len;
296 int stat, ret;
297 char *fullcommand;
298 capsObject *pobject;
299 capsProblem *problem;
300 capsAnalysis *analysis;
301 CAPSLONGunsigned long sNum;
302 capsJrnl args[1]; /* not really used */
303
304 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
305 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
306 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
307 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
308 if (aobject->parent == NULL((void*)0)) return CAPS_NULLOBJ-309;
309 pobject = (capsObject *) aobject->parent;
310 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
311 analysis = (capsAnalysis *) aobject->blind;
312 problem = (capsProblem *) pobject->blind;
313 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
314
315 args[0].type = jString;
316 stat = caps_jrnlRead(CAPS_SYSTEM54, problem, aobject, 0, args, &sNum, &ret);
317 if (stat == CAPS_JOURNALERR-343) return stat;
318 if (stat == CAPS_JOURNAL-342) return ret;
319
320 sNum = problem->sNum;
321 args[0].members.string = NULL((void*)0);
322 if (analysis->pre.sNum < aobject->last.sNum) {
323 ret = CAPS_CLEAN-336;
324 caps_jrnlWrite(CAPS_SYSTEM54, problem, aobject, ret, 0, args, sNum, problem->sNum);
325 return ret;
326 }
327 len = 9 + strlen(problem->root) + 1 + strlen(analysis->path) +
328 4 + strlen(command) + 3;
329 if (rpath == NULL((void*)0)) {
330 fullcommand = EG_alloc(len*sizeof(char));
331 if (fullcommand == NULL((void*)0)) return EGADS_MALLOC-4;
332#ifdef WIN32
333 status = snprintf(fullcommand, len, "%c: && cd \"%s\\%s\" && %s",
334 problem->root[0], &problem->root[2], analysis->path,
335 command);
336#else
337 status = snprintf(fullcommand, len, "cd '%s/%s' && %s",
338 problem->root, analysis->path, command);
339#endif
340 } else {
341 len += strlen(rpath) + 1;
342 fullcommand = EG_alloc(len*sizeof(char));
343 if (fullcommand == NULL((void*)0)) return EGADS_MALLOC-4;
344#ifdef WIN32
345 status = snprintf(fullcommand, len, "%c: && cd \"%s\\%s\\%s\" && %s",
346 problem->root[0], &problem->root[2], analysis->path,
347 rpath, command);
348#else
349 status = snprintf(fullcommand, len, "cd '%s/%s/%s' && %s",
350 problem->root, analysis->path, rpath, command);
351#endif
352 }
353 if (status >= len) {
354 EG_free(fullcommand);
355 return CAPS_BADVALUE-311;
356 }
357 status = system(fullcommand);
358 ret = CAPS_SUCCESS0;
359 if (status != 0) {
360 printf( "Failed to execute! (caps_system): %s\n",fullcommand);
361 ret = CAPS_EXECERR-335;
362 } else {
363 problem->sNum += 1;
364 }
365 EG_free(fullcommand);
366 caps_jrnlWrite(CAPS_SYSTEM54, problem, aobject, ret, 0, args, sNum, problem->sNum);
367
368 return ret;
369}
370
371
372static int
373caps_makeAnalysiX(capsObject *pobject, const char *aname,
374 /*@null@*/ const char *name, /*@null@*/ const char *unitSys,
375 /*@null@*/ const char *intents, int *exec,
376 capsObject **aobject, int *nErr, capsErrs **errors)
377{
378 int i, j, status, nIn, nOut, *ranks, *fInOut, eFlag, nField = 0;
379 int major, minor, index, len = 0;
380 char dirName[PATH_MAX4096], filename[PATH_MAX4096], temp[PATH_MAX4096];
381 char **fields = NULL((void*)0), *apath = NULL((void*)0);
382 void *instStore;
383 capsObject *object, **tmp;
384 capsProblem *problem;
385 capsAnalysis *analy, *analysis = NULL((void*)0);
386 capsValue *value;
387 FILE *fp;
388
389 problem = (capsProblem *) pobject->blind;
390 problem->funID = CAPS_MAKEANALYSIS44;
391
392 /* is the name unique? */
393 if (name != NULL((void*)0)) {
394 status = caps_isNameOK(name);
395 if (status != CAPS_SUCCESS0) return status;
396 apath = EG_strdup(name);
397 if (apath == NULL((void*)0)) return EGADS_MALLOC-4;
398 } else {
399 index = aim_Index(problem->aimFPTR, aname);
400 if (index < 0) {
401 j = 0;
402 } else {
403 j = problem->aimFPTR.aim_nInst[index];
404 }
405 len = strlen(aname) + 8;
406 apath = (char *) EG_alloc(len*sizeof(char));
407 if (apath == NULL((void*)0)) return EGADS_MALLOC-4;
408 snprintf(apath, len, "%s%d", aname, j);
409 }
410 for (i = 0; i < problem->nAnalysis; i++) {
411 if (problem->analysis[i] == NULL((void*)0)) continue;
412 if (problem->analysis[i]->name == NULL((void*)0)) continue;
413 if (strcmp(apath, problem->analysis[i]->name) == 0) {
414 status = CAPS_BADNAME-317;
415 goto cleanup;
416 }
417 }
418#ifdef WIN32
419 snprintf(dirName, PATH_MAX4096, "%s\\%s", problem->root, apath);
420#else
421 snprintf(dirName, PATH_MAX4096, "%s/%s", problem->root, apath);
422#endif
423 status = caps_statFile(dirName);
424 if (status != EGADS_NOTFOUND-1) {
425 snprintf(temp, PATH_MAX4096, "%s already exists in the phase (makeAnalysis)!",
426 apath);
427 caps_makeSimpleErr(pobject, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
428 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
429 status = CAPS_DIRERR-333;
430 goto cleanup;
431 }
432
433 /* initialize the analysis structure */
434 analysis = (capsAnalysis *) EG_alloc(sizeof(capsAnalysis));
435 if (analysis == NULL((void*)0)) {
436 status = EGADS_MALLOC-4;
437 goto cleanup;
438 }
439
440 analysis->loadName = EG_strdup(aname);
441 analysis->fullPath = EG_strdup(dirName);
442 analysis->path = apath;
443 analysis->unitSys = EG_strdup(unitSys);
444 analysis->major = CAPSMAJOR1;
445 analysis->minor = CAPSMINOR21;
446 analysis->instStore = NULL((void*)0);
447 analysis->autoexec = 0;
448 analysis->eFlag = 0;
449 analysis->intents = EG_strdup(intents);
450 analysis->nField = 0;
451 analysis->fields = NULL((void*)0);
452 analysis->ranks = NULL((void*)0);
453 analysis->fInOut = NULL((void*)0);
454 analysis->nAnalysisIn = 0;
455 analysis->analysisIn = NULL((void*)0);
456 analysis->nAnalysisOut = 0;
457 analysis->analysisOut = NULL((void*)0);
458 analysis->nAnalysisDynO = 0;
459 analysis->analysisDynO = NULL((void*)0);
460 analysis->nBody = 0;
461 analysis->bodies = NULL((void*)0);
462 analysis->nTess = 0;
463 analysis->tess = NULL((void*)0);
464 analysis->pre.index = -1;
465 analysis->pre.pname = NULL((void*)0);
466 analysis->pre.pID = NULL((void*)0);
467 analysis->pre.user = NULL((void*)0);
468 analysis->pre.sNum = 0;
469 analysis->info.magicnumber = CAPSMAGIC1234321;
470 analysis->info.instance = -1;
471 analysis->info.inPost = 0;
472 analysis->info.problem = problem;
473 analysis->info.analysis = analysis;
474 analysis->info.pIndex = 0;
475 analysis->info.irow = 0;
476 analysis->info.icol = 0;
477 analysis->info.errs.nError = 0;
478 analysis->info.errs.errors = NULL((void*)0);
479 analysis->info.wCntxt.aimWriterNum = 0;
480 for (i = 0; i < 6; i++) analysis->pre.datetime[i] = 0;
481
482 apath = NULL((void*)0);
483
484 /* try to load the AIM */
485 eFlag = 0;
486 nField = 0;
487 fields = NULL((void*)0);
488 ranks = NULL((void*)0);
489 fInOut = NULL((void*)0);
490 major = CAPSMAJOR1;
491 minor = CAPSMINOR21;
492 instStore = NULL((void*)0);
493 status = aim_Initialize(&problem->aimFPTR, aname, &eFlag, unitSys,
494 &analysis->info, &major, &minor, &nIn, &nOut,
495 &nField, &fields, &ranks, &fInOut, &instStore);
496 if (status < CAPS_SUCCESS0) goto cleanup;
497 if (nIn <= 0) {
498 status = CAPS_BADINIT-338;
499 goto cleanup;
500 }
501
502 analysis->major = major;
503 analysis->minor = minor;
504 analysis->instStore = instStore;
505 analysis->eFlag = eFlag;
506 analysis->nField = nField;
507 analysis->fields = fields;
508 analysis->ranks = ranks;
509 analysis->fInOut = fInOut;
510 analysis->nAnalysisIn = nIn;
511 analysis->nAnalysisOut = nOut;
512 if ((*exec == 1) && (eFlag == 1)) analysis->autoexec = 1;
513 analysis->info.instance = status;
514
515 *exec = eFlag;
516 instStore = NULL((void*)0);
517 fields = NULL((void*)0);
518 ranks = NULL((void*)0);
519 fInOut = NULL((void*)0);
520
521 /* allocate the objects for input */
522 if (nIn != 0) {
523 analysis->analysisIn = (capsObject **) EG_alloc(nIn*sizeof(capsObject *));
524 if (analysis->analysisIn == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
525 for (i = 0; i < nIn; i++) analysis->analysisIn[i] = NULL((void*)0);
526 value = (capsValue *) EG_alloc(nIn*sizeof(capsValue));
527 if (value == NULL((void*)0)) {
528 EG_free(analysis->analysisIn);
529 status = EGADS_MALLOC-4;
530 goto cleanup;
531 }
532 problem->sNum += 1;
533 for (i = 0; i < nIn; i++) {
534 value[i].length = value[i].nrow = value[i].ncol = 1;
535 value[i].type = Integer;
536 value[i].dim = value[i].pIndex = value[i].index = 0;
537 value[i].lfixed = value[i].sfixed = Fixed;
538 value[i].nullVal = NotAllowed;
539 value[i].units = NULL((void*)0);
540 value[i].meshWriter = NULL((void*)0);
541 value[i].link = NULL((void*)0);
542 value[i].vals.reals = NULL((void*)0);
543 value[i].limits.dlims[0] = value[i].limits.dlims[1] = 0.0;
544 value[i].linkMethod = Copy;
545 value[i].gInType = 0;
546 value[i].partial = NULL((void*)0);
547 value[i].nderiv = 0;
548 value[i].derivs = NULL((void*)0);
549
550 status = caps_makeObject(&object);
551 if (status != CAPS_SUCCESS0) {
552 EG_free(value);
553 status = EGADS_MALLOC-4;
554 goto cleanup;
555 }
556 if (i == 0) object->blind = value;
557 object->parent = NULL((void*)0);
558 object->name = NULL((void*)0);
559 object->type = VALUE;
560 object->subtype = ANALYSISIN;
561 object->last.sNum = problem->sNum;
562/*@-immediatetrans@*/
563 object->blind = &value[i];
564/*@+immediatetrans@*/
565 analysis->analysisIn[i] = object;
566 }
567
568 for (i = 0; i < nIn; i++) {
569 status = aim_Inputs(problem->aimFPTR, aname, analysis->instStore,
570 &analysis->info, i+1, &analysis->analysisIn[i]->name,
571 &value[i]);
572 if (status != CAPS_SUCCESS0) goto cleanup;
573 value[i].index = i+1;
574
575 status = caps_checkValueObj(analysis->analysisIn[i]);
576 if (status != CAPS_SUCCESS0) {
577 snprintf(temp, PATH_MAX4096, "Check Analysis '%s' Inputs Value Object %d!",
578 aname, status);
579 caps_makeSimpleErr(pobject, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
580 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
581 goto cleanup;
582 }
583 }
584 }
585
586 /* allocate the objects for output */
587 if (nOut != 0) {
588 analysis->analysisOut = (capsObject **) EG_alloc(nOut*sizeof(capsObject *));
589 if (analysis->analysisOut == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
590 for (i = 0; i < nOut; i++) analysis->analysisOut[i] = NULL((void*)0);
591
592 value = (capsValue *) EG_alloc(nOut*sizeof(capsValue));
593 if (value == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
594
595 problem->sNum += 1;
596 for (i = 0; i < nOut; i++) {
597 value[i].length = value[i].nrow = value[i].ncol = 1;
598 value[i].type = Integer;
599 value[i].dim = value[i].pIndex = value[i].index = 0;
600 value[i].lfixed = value[i].sfixed = Fixed;
601 value[i].nullVal = NotAllowed;
602 value[i].units = NULL((void*)0);
603 value[i].meshWriter = NULL((void*)0);
604 value[i].link = NULL((void*)0);
605 value[i].vals.reals = NULL((void*)0);
606 value[i].limits.dlims[0] = value[i].limits.dlims[1] = 0.0;
607 value[i].linkMethod = Copy;
608 value[i].gInType = 0;
609 value[i].partial = NULL((void*)0);
610 value[i].nderiv = 0;
611 value[i].derivs = NULL((void*)0);
612
613 status = caps_makeObject(&object);
614 if (status != CAPS_SUCCESS0) {
615 EG_free(value);
616 status = EGADS_MALLOC-4;
617 goto cleanup;
618 }
619 if (i == 0) object->blind = value;
620 object->parent = NULL((void*)0);
621 object->name = NULL((void*)0);
622 object->type = VALUE;
623 object->subtype = ANALYSISOUT;
624 object->last.sNum = problem->sNum;
625/*@-immediatetrans@*/
626 object->blind = &value[i];
627/*@+immediatetrans@*/
628 analysis->analysisOut[i] = object;
629 }
630
631 for (i = 0; i < nOut; i++) {
632 status = aim_Outputs(problem->aimFPTR, aname, analysis->instStore,
633 &analysis->info, i+1,
634 &analysis->analysisOut[i]->name, &value[i]);
635 if (status != CAPS_SUCCESS0) goto cleanup;
636 value[i].index = i+1;
637
638 status = caps_checkValueObj(analysis->analysisOut[i]);
639 if (status != CAPS_SUCCESS0) {
640 snprintf(temp, PATH_MAX4096, "Check Analysis '%s' Outputs Value Object %d!",
641 aname, status);
642 caps_makeSimpleErr(pobject, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
643 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
644 goto cleanup;
645 }
646 }
647 }
648
649 /* get a place in the problem to store the data away */
650 if (problem->analysis == NULL((void*)0)) {
651 problem->analysis = (capsObject **) EG_alloc(sizeof(capsObject *));
652 if (problem->analysis == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
653 } else {
654 tmp = (capsObject **) EG_reall( problem->analysis,
655 (problem->nAnalysis+1)*sizeof(capsObject *));
656 if (tmp == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
657 problem->analysis = tmp;
658 }
659
660 /* make the directory */
661 status = caps_mkDir(dirName);
662 if (status != EGADS_SUCCESS0) {
663 snprintf(temp, PATH_MAX4096, "Cannot make %s (caps_makeAnalysis)", dirName);
664 caps_makeSimpleErr(pobject, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
665 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
666 status = CAPS_DIRERR-333;
667 goto cleanup;
668 }
669
670 /* get the analysis object */
671 status = caps_makeObject(&object);
672 if (status != CAPS_SUCCESS0) goto cleanup;
673
674 /* leave sNum 0 to flag we are unexecuted */
675 object->parent = pobject;
676 object->name = EG_strdup(analysis->path);
677 if (object->name == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
678 object->type = ANALYSIS;
679 object->blind = analysis;
680/*@-nullderef@*/
681/*@-kepttrans@*/
682 for (i = 0; i < nIn; i++) analysis->analysisIn[i]->parent = object;
683 for (i = 0; i < nOut; i++) analysis->analysisOut[i]->parent = object;
684/*@+kepttrans@*/
685/*@+nullderef@*/
686 *aobject = object;
687 analysis = NULL((void*)0);
688
689 problem->analysis[problem->nAnalysis] = object;
690 problem->nAnalysis += 1;
691
692 /* setup for restarts */
693#ifdef WIN32
694 snprintf(filename, PATH_MAX4096, "%s\\capsRestart\\analy.txt", problem->root);
695 snprintf(temp, PATH_MAX4096, "%s\\capsRestart\\xxTempxx", problem->root);
696#else
697 snprintf(filename, PATH_MAX4096, "%s/capsRestart/analy.txt", problem->root);
698 snprintf(temp, PATH_MAX4096, "%s/capsRestart/xxTempxx", problem->root);
699#endif
700 fp = fopen(temp, "w");
701 if (fp == NULL((void*)0)) {
702 printf(" CAPS Warning: Cannot open %s (caps_makeAnalysis)\n", filename);
703 } else {
704 fprintf(fp, "%d\n", problem->nAnalysis);
705 if (problem->analysis != NULL((void*)0))
706 for (i = 0; i < problem->nAnalysis; i++) {
707 nIn = nOut = 0;
708 analy = (capsAnalysis *) problem->analysis[i]->blind;
709 if (analy != NULL((void*)0)) {
710 nIn = analy->nAnalysisIn;
711 nOut = analy->nAnalysisOut;
712 }
713 fprintf(fp, "%d %d %s\n", nIn, nOut, problem->analysis[i]->name);
714 }
715 fclose(fp);
716 status = caps_rename(temp, filename);
717 if (status != CAPS_SUCCESS0)
718 printf(" CAPS Warning: Cannot rename %s!\n", filename);
719 }
720#ifdef WIN32
721 snprintf(filename, PATH_MAX4096, "%s\\capsRestart\\AN-%s",
722 problem->root, object->name);
723#else
724 snprintf(filename, PATH_MAX4096, "%s/capsRestart/AN-%s",
725 problem->root, object->name);
726#endif
727 status = caps_mkDir(filename);
728 if (status != CAPS_SUCCESS0) {
729 printf(" CAPS Warning: Cant make dir %s (caps_makeAnalysis)\n", filename);
730 status = CAPS_SUCCESS0;
731 goto cleanup;
732 } else {
733 status = caps_dumpAnalysis(problem, object);
734 if (status != CAPS_SUCCESS0) {
735 printf(" CAPS Warning: caps_dumpAnalysis = %d (caps_makeAnalysis)\n",
736 status);
737 status = CAPS_SUCCESS0;
738 goto cleanup;
739 }
740 }
741
742cleanup:
743 EG_free(apath);
744 if (fields != NULL((void*)0)) {
745 for (i = 0; i < nField; i++) EG_free(fields[i]);
746 EG_free(fields);
747 }
748
749 if (status != CAPS_SUCCESS0) {
750 if (analysis != NULL((void*)0)) caps_freeAnalysis(0, analysis);
751 } else {
752 caps_getAIMerrs((capsAnalysis *) object->blind, nErr, errors);
753 }
754
755 return status;
756}
757
758
759int
760caps_makeAnalysis(capsObject *pobject, const char *aname,
761 /*@null@*/ const char *name, /*@null@*/ const char *unitSys,
762 /*@null@*/ const char *intents, int *exec,
763 capsObject **aobject, int *nErr, capsErrs **errors)
764{
765 int stat, ret;
766 CAPSLONGunsigned long sNum;
767 capsProblem *problem;
768 capsJrnl args[4];
769
770 *aobject = NULL((void*)0);
771 *nErr = 0;
772 *errors = NULL((void*)0);
773 if (pobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
774 if (pobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
775 if (pobject->type != PROBLEM) return CAPS_BADTYPE-306;
776 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
777 if (aname == NULL((void*)0)) return CAPS_NULLNAME-308;
778 problem = (capsProblem *) pobject->blind;
779 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
780
781 args[0].type = jObject;
782 args[1].type = jInteger;
783 args[2].type = jInteger;
784 args[3].type = jErr;
785 stat = caps_jrnlRead(CAPS_MAKEANALYSIS44, problem, *aobject, 4, args, &sNum, &ret);
786 if (stat == CAPS_JOURNALERR-343) return stat;
787 if (stat == CAPS_JOURNAL-342) {
788 *aobject = args[0].members.obj;
789 *exec = args[1].members.integer;
790 *nErr = args[2].members.integer;
791 *errors = args[3].members.errs;
792 return ret;
793 }
794
795 sNum = problem->sNum;
796 ret = caps_makeAnalysiX(pobject, aname, name, unitSys, intents, exec,
797 aobject, nErr, errors);
798 args[0].members.obj = *aobject;
799 args[1].members.integer = *exec;
800 args[2].members.integer = *nErr;
801 args[3].members.errs = *errors;
802 caps_jrnlWrite(CAPS_MAKEANALYSIS44, problem, *aobject, ret, 4, args, sNum, problem->sNum);
803
804 return ret;
805}
806
807
808static int
809caps_dupAnalysiX(capsObject *from, const char *name, capsObject **aobject)
810{
811 int i, j, status, nIn, nOut, *ranks, *fInOut, eFlag, nField = 0;
812 int major, minor, index, len = 0;
813 char dirName[PATH_MAX4096], filename[PATH_MAX4096], temp[PATH_MAX4096];
814 char **fields = NULL((void*)0), *apath = NULL((void*)0);
815 void *instStore;
816 capsObject *pobject, *object, **tmp;
817 capsAnalysis *froma, *analy, *analysis = NULL((void*)0);
818 capsProblem *problem;
819 capsValue *value = NULL((void*)0), *src;
820 FILE *fp;
821
822 *aobject = NULL((void*)0);
823 froma = (capsAnalysis *) from->blind;
824 pobject = (capsObject *) from->parent;
825 problem = (capsProblem *) pobject->blind;
826
827 /* is the name unique? */
828 if (name != NULL((void*)0)) {
829 status = caps_isNameOK(name);
830 if (status != CAPS_SUCCESS0) return status;
831 apath = EG_strdup(name);
832 if (apath == NULL((void*)0)) return EGADS_MALLOC-4;
833 } else {
834 index = aim_Index(problem->aimFPTR, froma->loadName);
835 j = problem->aimFPTR.aim_nInst[index];
836 len = strlen(froma->loadName) + 8;
837 apath = (char *) EG_alloc(len*sizeof(char));
838 if (apath == NULL((void*)0)) return EGADS_MALLOC-4;
839 snprintf(apath, len, "%s%d", froma->loadName, j);
840 }
841 for (i = 0; i < problem->nAnalysis; i++) {
842 if (problem->analysis[i] == NULL((void*)0)) continue;
843 if (problem->analysis[i]->name == NULL((void*)0)) continue;
844 if (strcmp(apath, problem->analysis[i]->name) == 0) {
845 status = CAPS_BADNAME-317;
846 goto cleanup;
847 }
848 }
849#ifdef WIN32
850 snprintf(dirName, PATH_MAX4096, "%s\\%s", problem->root, apath);
851#else
852 snprintf(dirName, PATH_MAX4096, "%s/%s", problem->root, apath);
853#endif
854 status = caps_statFile(dirName);
855 if (status != EGADS_NOTFOUND-1) {
856 printf(" CAPS Error: %s already exists in the phase!\n", apath);
857 status = CAPS_DIRERR-333;
858 goto cleanup;
859 }
860
861 /* initialize the analysis structure */
862 analysis = (capsAnalysis *) EG_alloc(sizeof(capsAnalysis));
863 if (analysis == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
864
865 analysis->loadName = EG_strdup(froma->loadName);
866 analysis->fullPath = EG_strdup(dirName);
867 analysis->path = apath;
868 analysis->unitSys = EG_strdup(froma->unitSys);
869 analysis->major = CAPSMAJOR1;
870 analysis->minor = CAPSMINOR21;
871 analysis->instStore = NULL((void*)0);
872 analysis->autoexec = froma->autoexec;
873 analysis->eFlag = froma->eFlag;
874 analysis->intents = EG_strdup(froma->intents);
875 analysis->nField = 0;
876 analysis->fields = NULL((void*)0);
877 analysis->ranks = NULL((void*)0);
878 analysis->fInOut = NULL((void*)0);
879 analysis->nAnalysisIn = 0;
880 analysis->analysisIn = NULL((void*)0);
881 analysis->nAnalysisOut = 0;
882 analysis->analysisOut = NULL((void*)0);
883 analysis->nAnalysisDynO = 0;
884 analysis->analysisDynO = NULL((void*)0);
885 analysis->nBody = 0;
886 analysis->bodies = NULL((void*)0);
887 analysis->nTess = 0;
888 analysis->tess = NULL((void*)0);
889 analysis->pre.index = -1;
890 analysis->pre.pname = NULL((void*)0);
891 analysis->pre.pID = NULL((void*)0);
892 analysis->pre.user = NULL((void*)0);
893 analysis->pre.sNum = 0;
894 analysis->info.magicnumber = CAPSMAGIC1234321;
895 analysis->info.inPost = 0;
896 analysis->info.problem = problem;
897 analysis->info.analysis = analysis;
898 analysis->info.pIndex = 0;
899 analysis->info.irow = 0;
900 analysis->info.icol = 0;
901 analysis->info.errs.nError = 0;
902 analysis->info.errs.errors = NULL((void*)0);
903 analysis->info.wCntxt.aimWriterNum = 0;
904 for (i = 0; i < 6; i++) analysis->pre.datetime[i] = 0;
905
906 apath = NULL((void*)0);
907
908 /* get a new instance AIM */
909 eFlag = 0;
910 nField = 0;
911 fields = NULL((void*)0);
912 ranks = NULL((void*)0);
913 fInOut = NULL((void*)0);
914 major = CAPSMAJOR1;
915 minor = CAPSMINOR21;
916 instStore = NULL((void*)0);
917 status = aim_Initialize(&problem->aimFPTR, froma->loadName, &eFlag,
918 froma->unitSys, &analysis->info,
919 &major, &minor, &nIn, &nOut,
920 &nField, &fields, &ranks, &fInOut, &instStore);
921 if (status < CAPS_SUCCESS0) goto cleanup;
922 if (nIn <= 0) {
923 status = CAPS_BADINIT-338;
924 goto cleanup;
925 }
926
927 analysis->major = major;
928 analysis->minor = minor;
929 analysis->instStore = instStore;
930 analysis->eFlag = eFlag;
931 analysis->nField = nField;
932 analysis->fields = fields;
933 analysis->ranks = ranks;
934 analysis->fInOut = fInOut;
935 analysis->nAnalysisIn = nIn;
936 analysis->nAnalysisOut = nOut;
937 analysis->info.instance = status;
938 if ((analysis->autoexec == 1) && (eFlag == 0)) analysis->autoexec = 0;
939
940 instStore = NULL((void*)0);
941 fields = NULL((void*)0);
942 ranks = NULL((void*)0);
943 fInOut = NULL((void*)0);
944
945 /* allocate the objects for input */
946 if (nIn != 0) {
947 analysis->analysisIn = (capsObject **) EG_alloc(nIn*sizeof(capsObject *));
948 if (analysis->analysisIn == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
949
950 for (i = 0; i < nIn; i++) analysis->analysisIn[i] = NULL((void*)0);
951 value = (capsValue *) EG_alloc(nIn*sizeof(capsValue));
952 if (value == NULL((void*)0)) {
953 status = EGADS_MALLOC-4;
954 goto cleanup;
955 }
956
957 problem->sNum += 1;
958 for (i = 0; i < nIn; i++) {
959 value[i].length = value[i].nrow = value[i].ncol = 1;
960 value[i].type = Integer;
961 value[i].dim = value[i].pIndex = value[i].index = 0;
962 value[i].lfixed = value[i].sfixed = Fixed;
963 value[i].nullVal = NotAllowed;
964 value[i].units = NULL((void*)0);
965 value[i].meshWriter = NULL((void*)0);
966 value[i].link = NULL((void*)0);
967 value[i].vals.reals = NULL((void*)0);
968 value[i].limits.dlims[0] = value[i].limits.dlims[1] = 0.0;
969 value[i].linkMethod = Copy;
970 value[i].gInType = 0;
971 value[i].partial = NULL((void*)0);
972 value[i].nderiv = 0;
973 value[i].derivs = NULL((void*)0);
974
975 status = caps_makeObject(&object);
976 if (status != CAPS_SUCCESS0) {
977 EG_free(value);
978 goto cleanup;
979 }
980 if (i == 0) object->blind = value;
981 object->parent = NULL((void*)0);
982 object->name = EG_strdup(froma->analysisIn[i]->name);
983 if (object->name == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
984 object->type = VALUE;
985 object->subtype = ANALYSISIN;
986 object->last.sNum = problem->sNum;
987/*@-immediatetrans@*/
988 object->blind = &value[i];
989/*@+immediatetrans@*/
990 analysis->analysisIn[i] = object;
991 }
992
993 src = (capsValue *) froma->analysisIn[0]->blind;
994 if ((nIn != 0) && (src == NULL((void*)0))) { status = CAPS_NULLBLIND-321; goto cleanup; }
995 for (i = 0; i < nIn; i++) {
996 status = caps_dupValues(&src[i], &value[i]);
997 if (status != CAPS_SUCCESS0) goto cleanup;
998 }
999 }
1000
1001 /* allocate the objects for output */
1002 if (nOut != 0) {
1003 analysis->analysisOut = (capsObject **) EG_alloc(nOut*sizeof(capsObject *));
1004 if (analysis->analysisOut == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
1005 for (i = 0; i < nOut; i++) analysis->analysisOut[i] = NULL((void*)0);
1006
1007 value = (capsValue *) EG_alloc(nOut*sizeof(capsValue));
1008 if (value == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
1009
1010 problem->sNum += 1;
1011 for (i = 0; i < nOut; i++) {
1012 value[i].length = value[i].nrow = value[i].ncol = 1;
1013 value[i].type = Integer;
1014 value[i].dim = value[i].pIndex = value[i].index = 0;
1015 value[i].lfixed = value[i].sfixed = Fixed;
1016 value[i].nullVal = NotAllowed;
1017 value[i].units = NULL((void*)0);
1018 value[i].meshWriter = NULL((void*)0);
1019 value[i].link = NULL((void*)0);
1020 value[i].vals.reals = NULL((void*)0);
1021 value[i].limits.dlims[0] = value[i].limits.dlims[1] = 0.0;
1022 value[i].linkMethod = Copy;
1023 value[i].gInType = 0;
1024 value[i].partial = NULL((void*)0);
1025 value[i].nderiv = 0;
1026 value[i].derivs = NULL((void*)0);
1027
1028 status = caps_makeObject(&object);
1029 if (status != CAPS_SUCCESS0) {
1030 EG_free(value);
1031 status = EGADS_MALLOC-4;
1032 goto cleanup;
1033 }
1034 if (i == 0) object->blind = value;
1035 object->parent = NULL((void*)0);
1036 object->name = EG_strdup(froma->analysisOut[i]->name);
1037 if (object->name == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
1038 object->type = VALUE;
1039 object->subtype = ANALYSISOUT;
1040 object->last.sNum = problem->sNum;
1041/*@-immediatetrans@*/
1042 object->blind = &value[i];
1043/*@+immediatetrans@*/
1044 analysis->analysisOut[i] = object;
1045 }
1046
1047 src = (capsValue *) froma->analysisOut[0]->blind;
1048 if ((nOut != 0) && (src == NULL((void*)0))) { status = CAPS_NULLBLIND-321; goto cleanup; }
1049 for (i = 0; i < nOut; i++) {
1050 status = caps_dupValues(&src[i], &value[i]);
1051 if (status != CAPS_SUCCESS0) goto cleanup;
1052 }
1053 }
1054
1055 /* get a place in the problem to store the data away */
1056 if (problem->analysis == NULL((void*)0)) {
1057 problem->analysis = (capsObject **) EG_alloc(sizeof(capsObject *));
1058 if (problem->analysis == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
1059 } else {
1060 tmp = (capsObject **) EG_reall( problem->analysis,
1061 (problem->nAnalysis+1)*sizeof(capsObject *));
1062 if (tmp == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
1063 problem->analysis = tmp;
1064 }
1065
1066 /* make the directory */
1067 status = caps_mkDir(dirName);
1068 if (status != EGADS_SUCCESS0) {
1069 printf(" CAPS Error: Cannot make %s (caps_dupAnalysis)\n", dirName);
1070 status = CAPS_DIRERR-333;
1071 goto cleanup;
1072 }
1073
1074 /* get the analysis object */
1075 status = caps_makeObject(&object);
1076 if (status != CAPS_SUCCESS0) goto cleanup;
1077
1078 /* leave sNum 0 to flag we are unexecuted */
1079 object->parent = pobject;
1080 object->name = EG_strdup(analysis->path);
1081 if (object->name == NULL((void*)0)) { status = EGADS_MALLOC-4; goto cleanup; }
1082 object->type = ANALYSIS;
1083 object->blind = analysis;
1084/*@-nullderef@*/
1085/*@-kepttrans@*/
1086 for (i = 0; i < nIn; i++) analysis->analysisIn[i]->parent = object;
1087 for (i = 0; i < nOut; i++) analysis->analysisOut[i]->parent = object;
1088/*@+kepttrans@*/
1089/*@+nullderef@*/
1090
1091 *aobject = object;
1092 analysis = NULL((void*)0);
1093
1094 problem->analysis[problem->nAnalysis] = object;
1095 problem->nAnalysis += 1;
1096
1097 /* setup for restarts */
1098#ifdef WIN32
1099 snprintf(filename, PATH_MAX4096, "%s\\capsRestart\\analy.txt", problem->root);
1100 snprintf(temp, PATH_MAX4096, "%s\\capsRestart\\xxTempxx", problem->root);
1101#else
1102 snprintf(filename, PATH_MAX4096, "%s/capsRestart/analy.txt", problem->root);
1103 snprintf(temp, PATH_MAX4096, "%s/capsRestart/xxTempxx", problem->root);
1104#endif
1105 fp = fopen(temp, "w");
1106 if (fp == NULL((void*)0)) {
1107 printf(" CAPS Warning: Cannot open %s (caps_dupAnalysis)\n", filename);
1108 } else {
1109 fprintf(fp, "%d\n", problem->nAnalysis);
1110 if (problem->analysis != NULL((void*)0))
1111 for (i = 0; i < problem->nAnalysis; i++) {
1112 nIn = nOut = 0;
1113 analy = (capsAnalysis *) problem->analysis[i]->blind;
1114 if (analy != NULL((void*)0)) {
1115 nIn = analy->nAnalysisIn;
1116 nOut = analy->nAnalysisOut;
1117 }
1118 fprintf(fp, "%d %d %s\n", nIn, nOut, problem->analysis[i]->name);
1119 }
1120 fclose(fp);
1121 status = caps_rename(temp, filename);
1122 if (status != CAPS_SUCCESS0)
1123 printf(" CAPS Warning: Cannot rename %s!\n", filename);
1124 }
1125#ifdef WIN32
1126 snprintf(filename, PATH_MAX4096, "%s\\capsRestart\\AN-%s",
1127 problem->root, object->name);
1128#else
1129 snprintf(filename, PATH_MAX4096, "%s/capsRestart/AN-%s",
1130 problem->root, object->name);
1131#endif
1132 status = caps_mkDir(filename);
1133 if (status != CAPS_SUCCESS0) {
1134 printf(" CAPS Warning: Cant make dir %s (caps_dupAnalysis)\n", filename);
1135 status = CAPS_SUCCESS0;
1136 goto cleanup;
1137 } else {
1138 status = caps_dumpAnalysis(problem, object);
1139 if (status != CAPS_SUCCESS0) {
1140 printf(" CAPS Warning: caps_dumpAnalysis = %d (caps_dupAnalysis)\n",
1141 status);
1142 status = CAPS_SUCCESS0;
1143 goto cleanup;
1144 }
1145 }
1146
1147cleanup:
1148 EG_free(apath);
1149 if (fields != NULL((void*)0)) {
1150 for (i = 0; i < nField; i++) EG_free(fields[i]);
1151 EG_free(fields);
1152 }
1153
1154 if (status != CAPS_SUCCESS0)
1155 if (analysis != NULL((void*)0)) caps_freeAnalysis(0, analysis);
1156
1157 return status;
1158}
1159
1160
1161int
1162caps_dupAnalysis(capsObject *from, const char *name, capsObject **aobject)
1163{
1164 int stat, ret;
1165 CAPSLONGunsigned long sNum;
1166 capsObject *pobject;
1167 capsProblem *problem;
1168 capsJrnl args[1];
1169
1170 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
1171 *aobject = NULL((void*)0);
1172 if (from == NULL((void*)0)) return CAPS_NULLOBJ-309;
1173 if (from->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1174 if (from->type != ANALYSIS) return CAPS_BADTYPE-306;
1175 if (from->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1176 if (name == NULL((void*)0)) return CAPS_NULLNAME-308;
1177 if (from->parent == NULL((void*)0)) return CAPS_NULLOBJ-309;
1178 pobject = (capsObject *) from->parent;
1179 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1180 problem = (capsProblem *) pobject->blind;
1181 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
1182
1183 args[0].type = jObject;
1184 stat = caps_jrnlRead(CAPS_DUPANALYSIS45, problem, *aobject, 1, args, &sNum, &ret);
1185 if (stat == CAPS_JOURNALERR-343) return stat;
1186 if (stat == CAPS_JOURNAL-342) {
1187 *aobject = args[0].members.obj;
1188 return ret;
1189 }
1190
1191 sNum = problem->sNum;
1192 ret = caps_dupAnalysiX(from, name, aobject);
1193 args[0].members.obj = *aobject;
1194 caps_jrnlWrite(CAPS_DUPANALYSIS45, problem, *aobject, ret, 1, args, sNum, problem->sNum);
1195
1196 return ret;
1197}
1198
1199
1200int
1201caps_resetAnalysis(capsObject *aobject, int *nErr, capsErrs **errors)
1202{
1203 int status;
1204 capsObject *pobject;
1205 capsProblem *problem;
1206 capsAnalysis *analysis;
1207
1208 if (nErr == NULL((void*)0)) return CAPS_NULLVALUE-307;
1209 if (errors == NULL((void*)0)) return CAPS_NULLVALUE-307;
1210 *nErr = 0;
1211 *errors = NULL((void*)0);
1212 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
1213 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1214 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
1215 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1216 analysis = (capsAnalysis *) aobject->blind;
1217 status = caps_findProblem(aobject, CAPS_RESETANALYSIS52, &pobject);
1218 if (status != CAPS_SUCCESS0) return status;
1219 problem = (capsProblem *) pobject->blind;
1220 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
1221
1222 /* ignore if restarting */
1223 if (problem->stFlag == CAPS_JOURNALERR-343) return CAPS_JOURNALERR-343;
1224 if (problem->stFlag == 4) {
1225 status = caps_jrnlEnd(problem);
1226 if (status != CAPS_CLEAN-336) return CAPS_SUCCESS0;
1227 }
1228
1229 status = caps_rmDir(analysis->fullPath);
1230 if (status != EGADS_SUCCESS0) {
1231 caps_makeSimpleErr(pobject, CERROR,
1232 "Cannot remove directory (caps_resetAnalysis):",
1233 analysis->fullPath, NULL((void*)0), errors);
1234 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
1235 return status;
1236 }
1237 status = caps_mkDir(analysis->fullPath);
1238 if (status != EGADS_SUCCESS0) {
1239 caps_makeSimpleErr(pobject, CERROR,
1240 "Cannot make directory (caps_resetAnalysis):",
1241 analysis->fullPath, NULL((void*)0), errors);
1242 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
1243 return status;
1244 }
1245
1246 return CAPS_SUCCESS0;
1247}
1248
1249
1250int
1251caps_analysisInfX(capsObject *aobject, char **apath, char **unitSys, int *major,
1252 int *minor, char **intents, int *nField, char ***fnames,
1253 int **ranks, int **fInOut, int *execute, int *status)
1254{
1255 int i, stat, ret, gstatus;
1256 int majorX, minorX, nFieldX, execX, dirtyX;
1257 int *ranksX, *fInOutX;
1258 char *intentsX, *apathX, *unitSysX, **fnamesX;
1259 CAPSLONGunsigned long sn;
1260 capsAnalysis *analysis;
1261 capsObject *pobject, *source, *object, *last;
1262 capsValue *value;
1263 capsProblem *problem;
1264
1265 *nField = *status = *major = *minor = 0;
1266 *apath = NULL((void*)0);
1267 *unitSys = NULL((void*)0);
1268 *fnames = NULL((void*)0);
1269 *ranks = NULL((void*)0);
1270 *fInOut = NULL((void*)0);
1271 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
1272 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1273 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
1274 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1275 analysis = (capsAnalysis *) aobject->blind;
1276 if (aobject->parent == NULL((void*)0)) return CAPS_NULLOBJ-309;
1277 pobject = (capsObject *) aobject->parent;
1278 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1279 problem = (capsProblem *) pobject->blind;
1280
1281 *apath = analysis->fullPath;
1282 *unitSys = analysis->unitSys;
1283 *execute = analysis->eFlag;
1284 *major = analysis->major;
1285 *minor = analysis->minor;
1286 *intents = analysis->intents;
1287 *nField = analysis->nField;
1288 *fnames = analysis->fields;
1289 *ranks = analysis->ranks;
1290 *fInOut = analysis->fInOut;
1291 if ((analysis->autoexec == 1) && (analysis->eFlag == 1)) *execute = 2;
1292
1293 /* are we "geometry" clean? */
1294 gstatus = 0;
1295 if (pobject->subtype == PARAMETRIC) {
1296 /* check for dirty geometry inputs */
1297 for (i = 0; i < problem->nGeomIn; i++) {
1298 source = object = problem->geomIn[i];
1299 do {
1300 if (source->magicnumber != CAPSMAGIC1234321) {
1301 ret = CAPS_BADOBJECT-310;
1302 goto done;
1303 }
1304 if (source->type != VALUE) {
1305 ret = CAPS_BADTYPE-306;
1306 goto done;
1307 }
1308 if (source->blind == NULL((void*)0)) {
1309 ret = CAPS_NULLBLIND-321;
1310 goto done;
1311 }
1312 value = (capsValue *) source->blind;
1313 if (value->link == object) {
1314 ret = CAPS_CIRCULARLINK-319;
1315 goto done;
1316 }
1317 last = source;
1318 source = value->link;
1319 } while (value->link != NULL((void*)0));
1320 if (last->last.sNum > problem->geometry.sNum) {
1321 gstatus = 1;
1322 break;
1323 }
1324 }
1325 }
1326
1327 /* are we "analysis" clean? */
1328 if (analysis->pre.sNum == 0) {
1329 *status = 1;
1330 } else {
1331 /* check for dirty inputs */
1332 for (i = 0; i < analysis->nAnalysisIn; i++) {
1333 source = object = analysis->analysisIn[i];
1334 do {
1335 if (source->magicnumber != CAPSMAGIC1234321) {
1336 ret = CAPS_BADOBJECT-310;
1337 goto done;
1338 }
1339 if (source->type != VALUE) {
1340 ret = CAPS_BADTYPE-306;
1341 goto done;
1342 }
1343 if (source->blind == NULL((void*)0)) {
1344 ret = CAPS_NULLBLIND-321;
1345 goto done;
1346 }
1347 value = (capsValue *) source->blind;
1348 if (value->link == object) {
1349 ret = CAPS_CIRCULARLINK-319;
1350 goto done;
1351 }
1352 last = source;
1353 source = value->link;
1354 } while (value->link != NULL((void*)0));
1355 if (last->last.sNum > analysis->pre.sNum) {
1356 *status = 1;
1357 break;
1358 }
1359 /* if the value is linked, check the state of the linked parent */
1360 if (last != object) {
1361 stat = caps_analysisInfX(last->parent, &apathX, &unitSysX, &majorX, &minorX,
Value stored to 'stat' is never read
1362 &intentsX, &nFieldX, &fnamesX, &ranksX, &fInOutX,
1363 &execX, &dirtyX);
1364 if (dirtyX > 0) {
1365 *status = 1;
1366 break;
1367 }
1368 }
1369 }
1370 if (*status == 0) {
1371 stat = caps_snDataSets(aobject, 0, &sn);
1372 if (stat == CAPS_SUCCESS0)
1373 if (sn > analysis->pre.sNum) *status = 1;
1374 }
1375 }
1376 *status += gstatus*2;
1377
1378 /* is geometry new? */
1379 if (*status == 0)
1380 if (problem->geometry.sNum > analysis->pre.sNum) *status = 4;
1381
1382 /* is post required? */
1383 if (*status == 0)
1384 if (analysis->pre.sNum > aobject->last.sNum) {
1385 *status = 5;
1386 if (analysis->eFlag == 0) *status = 6;
1387 }
1388
1389 ret = CAPS_SUCCESS0;
1390
1391done:
1392 return ret;
1393}
1394
1395
1396int
1397caps_analysisInfo(capsObject *aobject, char **apath, char **unitSys, int *major,
1398 int *minor, char **intents, int *nField, char ***fnames,
1399 int **ranks, int **fInOut, int *execute, int *status)
1400{
1401 int stat, ret;
1402 CAPSLONGunsigned long sNum;
1403 capsAnalysis *analysis;
1404 capsObject *pobject;
1405 capsProblem *problem;
1406 capsJrnl args[1];
1407
1408 *nField = *status = *major = *minor = 0;
1409 *apath = NULL((void*)0);
1410 *unitSys = NULL((void*)0);
1411 *fnames = NULL((void*)0);
1412 *ranks = NULL((void*)0);
1413 *fInOut = NULL((void*)0);
1414 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
1415 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1416 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
1417 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1418 analysis = (capsAnalysis *) aobject->blind;
1419 if (aobject->parent == NULL((void*)0)) return CAPS_NULLOBJ-309;
1420 pobject = (capsObject *) aobject->parent;
1421 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1422 problem = (capsProblem *) pobject->blind;
1423
1424 *apath = analysis->fullPath;
1425 *unitSys = analysis->unitSys;
1426 *execute = analysis->eFlag;
1427 *major = analysis->major;
1428 *minor = analysis->minor;
1429 *intents = analysis->intents;
1430 *nField = analysis->nField;
1431 *fnames = analysis->fields;
1432 *ranks = analysis->ranks;
1433 *fInOut = analysis->fInOut;
1434 if ((analysis->autoexec == 1) && (analysis->eFlag == 1)) *execute = 2;
1435
1436 args[0].type = jInteger;
1437 if (problem->dbFlag == 0) {
1438 stat = caps_jrnlRead(CAPS_ANALYSISINFO47, problem, aobject, 1, args, &sNum, &ret);
1439 if (stat == CAPS_JOURNALERR-343) return stat;
1440 if (stat == CAPS_JOURNAL-342) {
1441 *status = args[0].members.integer;
1442 return ret;
1443 }
1444 }
1445
1446 sNum = problem->sNum;
1447 ret = caps_analysisInfX(aobject, apath, unitSys, major, minor, intents,
1448 nField, fnames, ranks, fInOut, execute, status);
1449 if (problem->dbFlag == 1) return ret;
1450 args[0].members.integer = *status;
1451 caps_jrnlWrite(CAPS_ANALYSISINFO47, problem, aobject, ret, 1, args, sNum, problem->sNum);
1452
1453 return ret;
1454}
1455
1456
1457int
1458caps_circularAutoExecs(capsObject *asrc, capsObject *aobject)
1459{
1460 int i, j, k, stat;
1461 int found;
1462 capsAnalysis *analysis;
1463 capsObject *object, *source, *last, *pobject, *aObj=NULL((void*)0);
1464 capsValue *value;
1465 capsBound *bound;
1466 capsVertexSet *vertexset, *vset_link;
1467 capsDataSet *dataset;
1468 capsProblem *problem;
1469
1470 if (asrc->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1471 if (asrc->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1472
1473 /* startup */
1474 if (asrc->type == VALUE) asrc = asrc->parent;
1475 else if (asrc->type == DATASET) {
1476
1477 if (asrc->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1478 dataset = (capsDataSet *) asrc->blind;
1479 if (dataset->ftype != FieldIn) return CAPS_BADTYPE-306;
1480
1481 source = dataset->link->parent;
1482 if (source == NULL((void*)0)) return CAPS_NULLOBJ-309;
1483 if (source->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1484 if (source->type != VERTEXSET) return CAPS_BADTYPE-306;
1485 if (source->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1486 vertexset = source->blind;
1487 if (vertexset->analysis == NULL((void*)0)) return CAPS_NULLOBJ-309;
1488 asrc = vertexset->analysis;
1489 }
1490 if (aobject == NULL((void*)0)) aObj = asrc;
1491 else aObj = aobject;
1492
1493 /* extract analysis from aobject */
1494 if (aObj->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1495 if (aObj->type != ANALYSIS) return CAPS_BADTYPE-306;
1496 if (aObj->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1497 analysis = (capsAnalysis *) aObj->blind;
1498 pobject = aObj->parent;
1499 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1500 problem = (capsProblem *) pobject->blind;
1501
1502 /* check if we cannot auto-execute */
1503 if ((analysis->autoexec != 1) || (analysis->eFlag != 1))
1504 return CAPS_SUCCESS0;
1505
1506 /* asrc came back on it self, circular link! */
1507 if (asrc == aobject) return CAPS_CIRCULARLINK-319;
1508
1509 /* we can auto execute, do we have any links?
1510 * first check for AnalysisIn links, then FieldIn links
1511 */
1512
1513 /* check AnalysisIn links */
1514 for (i = 0; i < analysis->nAnalysisIn; i++) {
1515 source = object = analysis->analysisIn[i];
1516 do {
1517 if (source->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1518 if (source->type != VALUE) return CAPS_BADTYPE-306;
1519 if (source->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1520 value = (capsValue *) source->blind;
1521 if (value->link == object) return CAPS_CIRCULARLINK-319;
1522 last = source;
1523 source = value->link;
1524 } while (value->link != NULL((void*)0));
1525 if (last != object) {
1526 source = last->parent;
1527 if (source->type == ANALYSIS) {
1528 stat = caps_circularAutoExecs(asrc, source);
1529 if (stat != CAPS_SUCCESS0) return stat;
1530 }
1531 }
1532 }
1533
1534 /* check FieldIn links */
1535 for (i = 0; i < problem->nBound; i++) {
1536
1537 bound = (capsBound*) problem->bounds[i]->blind;
1538 for (found = j = 0; j < bound->nVertexSet; j++) {
1539 vertexset = (capsVertexSet*) bound->vertexSet[j]->blind;
1540 if (vertexset->analysis == aObj) {
1541 found = 1;
1542 break;
1543 }
1544 }
1545 if (found == 0) continue;
1546
1547 for (j = 0; j < bound->nVertexSet; j++) {
1548 vertexset = (capsVertexSet*) bound->vertexSet[j]->blind;
1549 if (vertexset->analysis != aObj) continue;
1550
1551 for (k = 0; k < vertexset->nDataSets; k++) {
1552
1553 source = vertexset->dataSets[k];
1554 if (source->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1555 if (source->type != DATASET) return CAPS_BADTYPE-306;
1556 if (source->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1557 dataset = (capsDataSet *) source->blind;
1558 if (dataset->link == source) return CAPS_CIRCULARLINK-319;
1559
1560 if (dataset->ftype != FieldIn) continue;
1561 if (dataset->link == NULL((void*)0)) continue;
1562
1563 source = dataset->link->parent;
1564 if (source == NULL((void*)0)) return CAPS_NULLOBJ-309;
1565 if (source->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
1566 if (source->type != VERTEXSET) return CAPS_BADTYPE-306;
1567 if (source->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
1568 vset_link = source->blind;
1569 if (vset_link->analysis == NULL((void*)0)) return CAPS_NULLOBJ-309;
1570 stat = caps_circularAutoExecs(asrc, vset_link->analysis);
1571 if (stat != CAPS_SUCCESS0) return stat;
1572 }
1573 }
1574 }
1575
1576 return CAPS_SUCCESS0;
1577}
1578
1579
1580/* maps gIndices indexes to body global tessellation indexes */
1581static int
1582caps_makeTessGlobal(capsDiscr *discr)
1583{
1584 int i, k, iface, vert, local, global, bIndex, typ, len, stat;
1585 int state, nGlobal;
1586 ego body;
1587 capsBodyDiscr *discBody = NULL((void*)0);
1588
1589 if (discr->nPoints == 0) return CAPS_SUCCESS0;
1590 if (discr->nBodys == 0) return CAPS_SUCCESS0;
1591
1592 discr->bodys[0].globalOffset = 0;
1593
1594 stat = EGADS_MALLOC-4;
1595 discr->tessGlobal = (int *) EG_alloc(2*discr->nPoints*sizeof(int));
1596 if (discr->tessGlobal == NULL((void*)0)) goto cleanup;
1597
1598 for (bIndex = 1; bIndex <= discr->nBodys; bIndex++) {
1599 discBody = &discr->bodys[bIndex-1];
1600
1601 /* fill in tessGlobal */
1602 for (i = 0; i < discBody->nElems; i++) {
1603 typ = discBody->elems[i].tIndex;
1604 len = discr->types[typ-1].nref;
1605 for (k = 0; k < len; k++) {
1606 iface = discBody->elems[i].eIndex;
1607 vert = discBody->elems[i].gIndices[2*k ]-1;
1608 local = discBody->elems[i].gIndices[2*k+1];
1609 stat = EG_localToGlobal(discBody->tess, iface, local, &global);
1610 if (stat != EGADS_SUCCESS0) goto cleanup;
1611 discr->tessGlobal[2*vert ] = bIndex;
1612 discr->tessGlobal[2*vert+1] = global;
1613 }
1614 }
1615
1616 /* fill in globalOffset across bodies */
1617 if (bIndex < discr->nBodys) {
1618 stat = EG_statusTessBody(discBody->tess, &body, &state, &nGlobal);
1619 if (stat != EGADS_SUCCESS0) goto cleanup;
1620 discr->bodys[bIndex].globalOffset = discBody->globalOffset + nGlobal;
1621 }
1622 }
1623
1624 stat = CAPS_SUCCESS0;
1625
1626cleanup:
1627 return stat;
1628}
1629
1630
1631int
1632caps_checkDiscr(capsDiscr *discr, int l, char *line)
1633{
1634 int i, j, len, typ, stat, bIndex, nEdge, nFace, last, state;
1635 int nGlobal, npts, ntris;
1636 ego body;
1637 capsBodyDiscr *discBody;
1638 const int *ptype, *pindex, *tris, *tric;
1639 const double *xyz, *prms;
1640
1641 if (discr->types == NULL((void*)0)) {
1642 snprintf(line, l, "caps_checkDiscr: types is NULL!\n");
1643 return CAPS_NULLBLIND-321;
1644 }
1645
1646 /* do the element types */
1647 for (i = 0; i < discr->nTypes; i++) {
1648 if (discr->types[i].gst == NULL((void*)0)) {
1649 snprintf(line, l, "caps_checkDiscr: types[%d].gst = NULL!", i+1);
1650 return CAPS_NULLVALUE-307;
1651 }
1652 if ((discr->types[i].dst == NULL((void*)0)) && (discr->types[i].ndata != 0)) {
1653 snprintf(line, l, "caps_checkDiscr: types[%d].dst = NULL!", i+1);
1654 return CAPS_NULLVALUE-307;
1655 }
1656 if ((discr->types[i].matst == NULL((void*)0)) && (discr->types[i].nmat != 0)) {
1657 snprintf(line, l, "caps_checkDiscr: types[%d].matst = NULL!", i+1);
1658 return CAPS_NULLVALUE-307;
1659 }
1660 if (discr->dim == 2)
1661 if (discr->types[i].tris == NULL((void*)0)) {
1662 snprintf(line, l, "caps_checkDiscr: types[%d].tris = NULL!", i+1);
1663 return CAPS_NULLVALUE-307;
1664 }
1665 for (j = 0; j < 3*discr->types[i].ntri; j++)
1666 if ((discr->types[i].tris[j] < 1) ||
1667 (discr->types[i].tris[j] > discr->types[i].nref)) {
1668 snprintf(line, l,
1669 "caps_checkDiscr: types[%d].tris[%d] = %d out of range [1-%d] ",
1670 i+1, j+1, discr->types[i].tris[j], discr->types[i].nref);
1671 return CAPS_BADINDEX-304;
1672 }
1673 }
1674
1675 /* check vert element indices */
1676 if (discr->nVerts != 0) {
1677 if (discr->verts == NULL((void*)0)) {
1678 snprintf(line, l, "caps_checkDiscr: nVert = %d but verts = NULL!",
1679 discr->nVerts);
1680 return CAPS_NULLVALUE-307;
1681 }
1682 if (discr->celem == NULL((void*)0)) {
1683 snprintf(line, l, "caps_checkDiscr: nVert = %d but celem = NULL!",
1684 discr->nVerts);
1685 return CAPS_NULLVALUE-307;
1686 }
1687 for (i = 0; i < discr->nVerts; i++) {
1688 bIndex = discr->celem[2*i];
1689 if ((bIndex < 1) || (bIndex > discr->nBodys)) {
1690 snprintf(line, l,
1691 "caps_checkDiscr:celem[2*%d] = %d out of range [1-%d] ",
1692 i, discr->celem[i], discr->nBodys);
1693 return CAPS_BADINDEX-304;
1694 }
1695 discBody = &discr->bodys[discr->celem[2*i]-1];
1696
1697 if ((discr->celem[2*i] < 1) || (discr->celem[2*i+1] > discBody->nElems)) {
1698 snprintf(line, l,
1699 "caps_checkDiscr: celem[2*%d+1] = %d out of range [1-%d] ",
1700 i, discr->celem[i], discBody->nElems);
1701 return CAPS_BADINDEX-304;
1702 }
1703 }
1704 }
1705
1706 /* look at body discretizations */
1707 if (discr->bodys == NULL((void*)0)) {
1708 snprintf(line, l, "caps_checkDiscr: bodys is NULL!\n");
1709 return CAPS_NULLBLIND-321;
1710 }
1711
1712 for (bIndex = 1; bIndex <= discr->nBodys; bIndex++) {
1713 discBody = &discr->bodys[bIndex-1];
1714
1715 if (discBody->tess == NULL((void*)0)) {
1716 snprintf(line, l, "caps_checkDiscr: body %d etess is NULL!\n", bIndex);
1717 return CAPS_NULLBLIND-321;
1718 }
1719
1720 if (discBody->elems == NULL((void*)0)) {
1721 snprintf(line, l, "caps_checkDiscr: body %d elems is NULL!\n", bIndex);
1722 return CAPS_NULLBLIND-321;
1723 }
1724
1725 stat = EG_statusTessBody(discBody->tess, &body, &state, &nGlobal);
1726 if (stat < EGADS_SUCCESS0) {
1727 snprintf(line, l, "caps_checkDiscr: statusTessBody = %d for body %d!\n",
1728 stat, bIndex);
1729 return stat;
1730 }
1731 if (state == 0) {
1732 snprintf(line, l, "caps_checkDiscr: Tessellation is Open for body %d!\n",
1733 bIndex);
1734 return EGADS_TESSTATE-31;
1735 }
1736
1737 /* look at the data associated with each body */
1738 stat = EG_getBodyTopos(body, NULL((void*)0), FACE23, &nFace, NULL((void*)0));
1739 if (stat != EGADS_SUCCESS0) {
1740 snprintf(line, l, "caps_checkDiscr: getBodyTopos (Face) = %d for %d!\n",
1741 stat, bIndex);
1742 return stat;
1743 }
1744 stat = EG_getBodyTopos(body, NULL((void*)0), EDGE21, &nEdge, NULL((void*)0));
1745 if (stat != EGADS_SUCCESS0) {
1746 snprintf(line, l, "caps_checkDiscr: getBodyTopos (Edge) = %d for %d!\n",
1747 stat, bIndex);
1748 return stat;
1749 }
1750
1751 /* do the elements */
1752 last = 0;
1753 for (i = 1; i <= discBody->nElems; i++) {
1754 if ((discBody->elems[i-1].tIndex < 1) ||
1755 (discBody->elems[i-1].tIndex > discr->nTypes)) {
1756 snprintf(line, l,
1757 "caps_checkDiscr: elems[%d].tIndex = %d out of range [1-%d] ",
1758 i, discBody->elems[i].tIndex, discr->nTypes);
1759 return CAPS_BADINDEX-304;
1760 }
1761 if (discr->dim == 1) {
1762 if ((discBody->elems[i-1].eIndex < 1) ||
1763 (discBody->elems[i-1].eIndex > nEdge)) {
1764 snprintf(line, l,
1765 "caps_checkDiscr: elems[%d].eIndex = %d out of range [1-%d] ",
1766 i, discBody->elems[i-1].eIndex, nEdge);
1767 return CAPS_BADINDEX-304;
1768 }
1769 if (discBody->elems[i-1].eIndex != last) {
1770/*@-nullpass@*/
1771 stat = EG_getTessEdge(discBody->tess, discBody->elems[i-1].eIndex,
1772 &npts, &xyz, &prms);
1773/*@+nullpass@*/
1774 if (stat != EGADS_SUCCESS0) {
1775 snprintf(line, l, "caps_checkDiscr: getTessEdge %d = %d for %d!\n",
1776 discBody->elems[i-1].eIndex, stat, bIndex);
1777 return stat;
1778 }
1779 ntris = npts-1;
1780 last = discBody->elems[i-1].eIndex;
1781 }
1782 } else if (discr->dim == 2) {
1783 if ((discBody->elems[i-1].eIndex < 1) ||
1784 (discBody->elems[i-1].eIndex > nFace)) {
1785 snprintf(line, l,
1786 "caps_checkDiscr: elems[%d].eIndex = %d out of range [1-%d] ",
1787 i, discBody->elems[i-1].eIndex, nFace);
1788 return CAPS_BADINDEX-304;
1789 }
1790 if (discBody->elems[i-1].eIndex != last) {
1791/*@-nullpass@*/
1792 stat = EG_getTessFace(discBody->tess,
1793 discBody->elems[i-1].eIndex, &npts, &xyz, &prms,
1794 &ptype, &pindex, &ntris, &tris, &tric);
1795/*@+nullpass@*/
1796 if (stat != EGADS_SUCCESS0) {
1797 snprintf(line, l, "caps_checkDiscr: getTessFace %d = %d for %d!\n",
1798 discBody->elems[i-1].eIndex, stat, bIndex);
1799 return stat;
1800 }
1801 last = discBody->elems[i-1].eIndex;
1802 }
1803 }
1804 typ = discBody->elems[i-1].tIndex;
1805 len = discr->types[typ-1].nref;
1806 for (j = 0; j < len; j++) {
1807 if ((discBody->elems[i-1].gIndices[2*j] < 1) ||
1808 (discBody->elems[i-1].gIndices[2*j] > discr->nPoints)) {
1809 snprintf(line, l,
1810 "caps_checkDiscr: elems[%d].gIndices[%d]p = %d out of range [1-%d] ",
1811 i, j, discBody->elems[i-1].gIndices[2*j], discr->nPoints);
1812 return CAPS_BADINDEX-304;
1813 }
1814#ifndef __clang_analyzer__1
1815 if ((discBody->elems[i-1].gIndices[2*j+1] < 1) ||
1816 (discBody->elems[i-1].gIndices[2*j+1] > npts)) {
1817 snprintf(line, l,
1818 "caps_checkDiscr: elems[%d].gIndices[%d]t = %d out of range [1-%d] ",
1819 i, j+1, discBody->elems[i-1].gIndices[2*j+1], npts);
1820 return CAPS_BADINDEX-304;
1821 }
1822#endif
1823 }
1824 if (discr->verts != NULL((void*)0)) {
1825 len = discr->types[typ-1].ndata;
1826 if ((len != 0) && (discBody->elems[i-1].dIndices == NULL((void*)0))) {
1827 snprintf(line, l,
1828 "caps_checkDiscr: elems[%d].dIndices[%d] == NULL ",
1829 i, j+1);
1830 return CAPS_NULLVALUE-307;
1831 }
1832 for (j = 0; j < len; j++)
1833 if ((discBody->elems[i-1].dIndices[j] < 1) ||
1834 (discBody->elems[i-1].dIndices[j] > discr->nVerts)) {
1835 snprintf(line, l,
1836 "caps_checkDiscr: elems[%d].dIndices[%d] = %d out of range [1-%d] ",
1837 i, j, discBody->elems[i-1].dIndices[j], discr->nPoints);
1838 return CAPS_BADINDEX-304;
1839 }
1840 }
1841 len = discr->types[typ-1].ntri;
1842 if (len > 2) {
1843 if (discBody->elems[i-1].eTris.poly == NULL((void*)0)) {
1844 snprintf(line, l, "caps_checkDiscr: elems[%d].poly = NULL!", i);
1845 return CAPS_NULLVALUE-307;
1846 }
1847 for (j = 0; j < len; j++) {
1848#ifndef __clang_analyzer__1
1849 if ((discBody->elems[i-1].eTris.poly[j] < 1) ||
1850 (discBody->elems[i-1].eTris.poly[j] > ntris)) {
1851 snprintf(line, l,
1852 "caps_checkDiscr: elems[%d].eTris[%d] = %d out of range [1-%d] ",
1853 i, j+1, discBody->elems[i-1].eTris.poly[j], ntris);
1854 return CAPS_BADINDEX-304;
1855 }
1856#endif
1857 }
1858
1859 } else {
1860 for (j = 0; j < len; j++) {
1861#ifndef __clang_analyzer__1
1862 if ((discBody->elems[i-1].eTris.tq[j] < 1) ||
1863 (discBody->elems[i-1].eTris.tq[j] > ntris)) {
1864 snprintf(line, l,
1865 "caps_checkDiscr: elems[%d].eTris[%d] = %d out of range [1-%d] ",
1866 i, j+1, discBody->elems[i].eTris.tq[j], ntris);
1867 return CAPS_BADINDEX-304;
1868 }
1869#endif
1870 }
1871 }
1872 }
1873 }
1874
1875 /* create the global tessellation index and check */
1876 if (discr->tessGlobal == NULL((void*)0)) {
1877 stat = caps_makeTessGlobal(discr);
1878 if (stat < EGADS_SUCCESS0 || discr->tessGlobal == NULL((void*)0)) {
1879 snprintf(line, l, "caps_checkDiscr: caps_makeTessGlobal stat = %d!\n",
1880 stat);
1881 return stat;
1882 }
1883 }
1884
1885 /* look at body indices */
1886/*@-nullderef@*/
1887 for (i = 0; i < discr->nPoints; i++)
1888 if ((discr->tessGlobal[2*i] < 1) || (discr->tessGlobal[2*i] > discr->nBodys)) {
1889 snprintf(line, l, "caps_checkDiscr: body mapping %d = %d [1,%d]!\n",
1890 i+1, discr->tessGlobal[2*i], discr->nBodys);
1891 return CAPS_BADINDEX-304;
1892 }
1893/*@+nullderef@*/
1894
1895 for (bIndex = 1; bIndex <= discr->nBodys; bIndex++) {
1896 discBody = &discr->bodys[bIndex-1];
1897
1898 stat = EG_statusTessBody(discBody->tess, &body, &state, &nGlobal);
1899 if (stat < EGADS_SUCCESS0) {
1900 snprintf(line, l, "caps_checkDiscr: statusTessBody = %d for body %d!\n",
1901 stat, bIndex);
1902 return stat;
1903 }
1904 if (state == 0) {
1905 snprintf(line, l, "caps_checkDiscr: Tessellation is Open for body %d!\n",
1906 bIndex);
1907 return EGADS_TESSTATE-31;
1908 }
1909
1910 /* check point tessGlobal is withing the expected range for this body */
1911/*@-nullderef@*/
1912 for (i = 0; i < discr->nPoints; i++) {
1913 if (discr->tessGlobal[2*i] != bIndex) continue;
1914 if ((discr->tessGlobal[2*i+1] < 1) || (discr->tessGlobal[2*i+1] > nGlobal)) {
1915 snprintf(line, l, "caps_checkDiscr: tessGlobal[2*%d+1] = %d [1,%d] for %d!\n",
1916 i, discr->tessGlobal[2*i+1], nGlobal, bIndex);
1917 return CAPS_BADINDEX-304;
1918 }
1919 }
1920/*@+nullderef@*/
1921
1922 if (bIndex == 1) {
1923 if (discBody->globalOffset != 0) {
1924 snprintf(line, l, "caps_checkDiscr: body %d globalOffset != 0!\n",
1925 bIndex);
1926 return CAPS_BADINDEX-304;
1927 }
1928 }
1929 if (bIndex < discr->nBodys) {
1930 if (discr->bodys[bIndex].globalOffset != discBody->globalOffset + nGlobal) {
1931 snprintf(line, l, "caps_checkDiscr: body %d globalOffset != %d!\n",
1932 bIndex+1, discBody->globalOffset + nGlobal);
1933 return CAPS_BADINDEX-304;
1934 }
1935 }
1936 }
1937
1938 /* check data triangulation */
1939 if ((discr->nDtris != 0) && (discr->dtris != NULL((void*)0)) &&
1940 (discr->nVerts != 0))
1941 for (i = 0; i < discr->nDtris; i++)
1942 for (j = 0; j < 3; j++)
1943 if ((discr->dtris[3*i+j] < 1) ||
1944 (discr->dtris[3*i+j] > discr->nVerts)) {
1945 snprintf(line, l,
1946 "caps_checkDiscr: dtris[%d %d] = %d out of range [1-%d] ",
1947 i+1, j+1, discr->dtris[3*i+j], discr->nVerts);
1948 return CAPS_BADINDEX-304;
1949 }
1950
1951 return CAPS_SUCCESS0;
1952}
1953
1954
1955static void
1956caps_fillBuiltIn(capsObject *bobject, capsDiscr *discr, capsObject *dobject,
1957 CAPSLONGunsigned long sNum)
1958{
1959 int i, j, k, m, stat, npts, rank, bIndex, pt, pi, typ, len;
1960 int last, ntris, nptx, index, global;
1961 double *values, xyz[3], st[2];
1962 capsObject *pobject, *vobject;
1963 capsProblem *problem;
1964 capsBound *bound;
1965 aimInfo *aInfo;
1966 capsAnalysis *analysis;
1967 capsDataSet *dataset, *ds;
1968 capsVertexSet *vertexset;
1969 capsBodyDiscr *discBody;
1970 const int *ptype, *pindex, *tris, *tric;
1971 const double *xyzs, *prms;
1972
1973 aInfo = (aimInfo *) discr->aInfo;
1974 analysis = (capsAnalysis *) aInfo->analysis;
1975 bound = (capsBound *) bobject->blind;
1976 dataset = (capsDataSet *) dobject->blind;
1977 vobject = dobject->parent;
1978 vertexset = (capsVertexSet *) vobject->blind;
1979 pobject = bobject->parent;
1980 problem = (capsProblem *) pobject->blind;
1981 if ((strcmp(dobject->name, "xyzd") == 0) && (discr->verts == NULL((void*)0))) return;
1982 if ((strcmp(dobject->name, "paramd") == 0) && (discr->verts == NULL((void*)0))) return;
1983
1984 rank = dataset->rank;
1985 if (strcmp(dobject->name, "xyz") == 0) {
1986 npts = discr->nPoints;
1987 } else if (strcmp(dobject->name, "xyzd") == 0) {
1988 npts = discr->nVerts;
1989 } else if (strcmp(dobject->name, "param") == 0) {
1990 if (bound->state == MultipleError) return;
1991 npts = discr->nPoints;
1992 } else if (strcmp(dobject->name, "paramd") == 0) {
1993 if (bound->state == MultipleError) return;
1994 npts = discr->nVerts;
1995 } else {
1996 printf(" CAPS Internal: Unknown BuiltIn DataSet = %s\n", dobject->name);
1997 return;
1998 }
1999 if (npts == 0) return;
2000
2001 values = (double *) EG_alloc(npts*rank*sizeof(double));
2002 if (values == NULL((void*)0)) {
2003 printf(" CAPS Internal: Malloc on %d %d Dataset = %s\n", npts, rank,
2004 dobject->name);
2005 return;
2006 }
2007
2008 if (strcmp(dobject->name, "xyz") == 0) {
2009
2010 for (i = 0; i < npts; i++) {
2011 bIndex = discr->tessGlobal[2*i ];
2012 global = discr->tessGlobal[2*i+1];
2013 discBody = &discr->bodys[bIndex-1];
2014 stat = EG_getGlobal(discBody->tess, global, &pt, &pi, &values[3*i]);
2015 if (stat != EGADS_SUCCESS0)
2016 printf(" CAPS Internal: %d EG_getGlobal %d for %s = %d\n",
2017 bIndex, i+1, dobject->name, stat);
2018 }
2019 if (bound->lunits != NULL((void*)0)) {
2020 if (dataset->units != NULL((void*)0)) EG_free(dataset->units);
2021 dataset->units = EG_strdup(bound->lunits);
2022 }
2023
2024 } else if (strcmp(dobject->name, "xyzd") == 0) {
2025
2026 for (i = 0; i < npts; i++) {
2027 values[3*i ] = discr->verts[3*i ];
2028 values[3*i+1] = discr->verts[3*i+1];
2029 values[3*i+2] = discr->verts[3*i+2];
2030 }
2031 if (bound->lunits != NULL((void*)0)) {
2032 if (dataset->units != NULL((void*)0)) EG_free(dataset->units);
2033 dataset->units = EG_strdup(bound->lunits);
2034 }
2035
2036 } else if (strcmp(dobject->name, "param") == 0) {
2037
2038 if (bound->dim == 2) {
2039 for (i = 0; i < npts; i++) {
2040 values[2*i ] = 0.0;
2041 values[2*i+1] = 0.0;
2042 }
2043 if (bound->state != Multiple) {
2044 for (bIndex = 1; bIndex <= discr->nBodys; bIndex++) {
2045 discBody = &discr->bodys[bIndex-1];
2046 for (last = j = 0; j < discBody->nElems; j++) {
2047 if (discBody->elems[j].eIndex != last) {
2048 stat = EG_getTessFace(discBody->tess, discBody->elems[j].eIndex,
2049 &nptx, &xyzs, &prms,
2050 &ptype, &pindex, &ntris, &tris, &tric);
2051 if (stat != EGADS_SUCCESS0) {
2052 printf(" CAPS Internal: getTessFace %d = %d for %d\n",
2053 discBody->elems[j].eIndex, stat, bIndex);
2054 continue;
2055 }
2056 last = discBody->elems[j].eIndex;
2057 }
2058#ifndef __clang_analyzer__1
2059 typ = discBody->elems[j].tIndex;
2060 len = discr->types[typ-1].nref;
2061 for (k = 0; k < len; k++) {
2062 i = discBody->elems[j].gIndices[2*k ]-1;
2063 pt = discBody->elems[j].gIndices[2*k+1]-1;
2064 values[2*i ] = prms[2*pt ];
2065 values[2*i+1] = prms[2*pt+1];
2066 }
2067#endif
2068 }
2069 }
2070 } else {
2071 for (i = 0; i < npts; i++) {
2072 bIndex = discr->tessGlobal[2*i ];
2073 global = discr->tessGlobal[2*i+1];
2074 discBody = &discr->bodys[bIndex-1];
2075 stat = EG_getGlobal(discBody->tess, global, &pt, &pi, xyz);
2076 if (stat != EGADS_SUCCESS0) {
2077 printf(" CAPS Internal: %d EG_getGlobal %d for %s = %d\n",
2078 bIndex, i+1, dobject->name, stat);
2079 continue;
2080 }
2081 stat = caps_invInterpolate2D(bound->surface, xyz, &values[2*i]);
2082 if (stat != EGADS_SUCCESS0)
2083 printf(" CAPS Internal: caps_invInterpolate2D %d for %s = %d\n",
2084 i+1, dobject->name, stat);
2085 }
2086 }
2087
2088 } else {
2089
2090 if (bound->state == Single) {
2091 for (bIndex = 1; bIndex <= discr->nBodys; bIndex++) {
2092 discBody = &discr->bodys[bIndex-1];
2093 for (last = j = 0; j < discBody->nElems; j++) {
2094 if (discBody->elems[j].eIndex != last) {
2095 stat = EG_getTessEdge(discBody->tess, discBody->elems[j].eIndex,
2096 &nptx, &xyzs, &prms);
2097 if (stat != EGADS_SUCCESS0) {
2098 printf(" CAPS Internal: getTessEdge %d = %d for %d\n",
2099 discBody->elems[j].eIndex, stat, bIndex);
2100 continue;
2101 }
2102 last = discBody->elems[j].eIndex;
2103 }
2104#ifndef __clang_analyzer__1
2105 typ = discBody->elems[j].tIndex;
2106 len = discr->types[typ-1].nref;
2107 for (k = 0; k < len; k++) {
2108 i = discBody->elems[j].gIndices[2*k ]-1;
2109 pt = discBody->elems[j].gIndices[2*k+1]-1;
2110 values[i] = prms[pt];
2111 }
2112#endif
2113 }
2114 }
2115 } else {
2116 for (i = 0; i < npts; i++) {
2117 bIndex = discr->tessGlobal[2*i ];
2118 global = discr->tessGlobal[2*i+1];
2119 discBody = &discr->bodys[bIndex-1];
2120 stat = EG_getGlobal(discBody->tess, global, &pt, &pi, xyz);
2121 if (stat != EGADS_SUCCESS0) {
2122 printf(" CAPS Internal: %d EG_getGlobal %d for %s = %d\n",
2123 bIndex, i+1, dobject->name, stat);
2124 continue;
2125 }
2126 stat = caps_invInterpolate1D(bound->curve, xyz, &values[i]);
2127 if (stat != EGADS_SUCCESS0)
2128 printf(" CAPS Internal: caps_invInterpolate1D %d for %s = %d\n",
2129 i+1, dobject->name, stat);
2130 }
2131 }
2132 }
2133
2134 } else {
2135
2136 for (i = 0; i < npts; i++) values[i] = 0.0;
2137 index = aim_Index(problem->aimFPTR, analysis->loadName);
2138 if (index < 0)
2139 printf(" CAPS Internal: aim_Index %s = %d\n", dobject->name, index);
2140
2141 /* assume that we have the dataset "param" */
2142 ds = NULL((void*)0);
2143 if (vertexset->dataSets[2] == NULL((void*)0)) {
2144 printf(" CAPS Internal: params obj == NULL for %s\n", dobject->name);
2145 index = -1;
2146 } else {
2147 ds = (capsDataSet *) vertexset->dataSets[2]->blind;
2148 if (ds == NULL((void*)0)) {
2149 printf(" CAPS Internal: params ds == NULL for %s\n", dobject->name);
2150 index = -1;
2151 }
2152 }
2153
2154 if (bound->dim == 2) {
2155 for (i = 0; i < npts; i++) {
2156 values[2*i ] = 0.0;
2157 values[2*i+1] = 0.0;
2158 }
2159 if (bound->state == Single) {
2160 if (index >= 0) {
2161 for (i = 0; i < npts; i++) {
2162 bIndex = discr->celem[2*i ];
2163 k = discr->celem[2*i+1] - 1;
2164 discBody = &discr->bodys[bIndex-1];
2165 m = discBody->elems[k].tIndex - 1;
2166 len = discr->types[m].ndata;
2167 for (j = 0; j < len; j++)
2168 if (discBody->elems[k].dIndices[j] == i+1) {
2169 st[0] = discr->types[m].dst[2*j ];
2170 st[1] = discr->types[m].dst[2*j+1];
2171 break;
2172 }
2173 if ((j == len) || (ds == NULL((void*)0))) {
2174 printf(" CAPS Internal: data ref %d for %s not found!\n",
2175 i+1, dobject->name);
2176 continue;
2177 }
2178 stat = aim_InterpolIndex(problem->aimFPTR, index, discr, "paramd",
2179 discr->celem[2*i], discr->celem[2*i+1],
2180 st, 2, ds->data, &values[2*i]);
2181 if (stat != CAPS_SUCCESS0)
2182 printf(" CAPS Internal: aim_InterpolIndex %d for %s = %d\n",
2183 i+1, dobject->name, stat);
2184 }
2185 }
2186 } else {
2187 for (i = 0; i < npts; i++) {
2188 xyz[0] = discr->verts[3*i ];
2189 xyz[1] = discr->verts[3*i+1];
2190 xyz[2] = discr->verts[3*i+2];
2191 stat = caps_invInterpolate2D(bound->surface, xyz, &values[2*i]);
2192 if (stat != EGADS_SUCCESS0)
2193 printf(" CAPS Internal: caps_invInterpolate2D %d for %s = %d\n",
2194 i+1, dobject->name, stat);
2195 }
2196 }
2197
2198 } else {
2199 for (i = 0; i < npts; i++) values[i] = 0.0;
2200 if (bound->state == Single) {
2201 if (index >= 0) {
2202 for (i = 0; i < discr->nVerts; i++) {
2203 bIndex = discr->celem[2*i ];
2204 k = discr->celem[2*i+1] - 1;
2205 discBody = &discr->bodys[bIndex-1];
2206 m = discBody->elems[k].tIndex - 1;
2207 len = discr->types[m].ndata;
2208 for (j = 0; j < len; j++)
2209 if (discBody->elems[k].dIndices[j] == i+1) {
2210 st[0] = discr->types[m].dst[j];
2211 break;
2212 }
2213 if ((j == len) || (ds == NULL((void*)0))) {
2214 printf(" CAPS Internal: data ref %d for %s not found!\n",
2215 i+1, dobject->name);
2216 continue;
2217 }
2218 stat = aim_InterpolIndex(problem->aimFPTR, index, discr, "paramd",
2219 discr->celem[2*i], discr->celem[2*i+1],
2220 st, 1, ds->data, &values[i]);
2221 if (stat != CAPS_SUCCESS0)
2222 printf(" CAPS Internal: aim_InterpolIndex %d for %s = %d\n",
2223 i+1, dobject->name, stat);
2224 }
2225 }
2226 } else {
2227 for (i = 0; i < npts; i++) {
2228 xyz[0] = discr->verts[3*i ];
2229 xyz[1] = discr->verts[3*i+1];
2230 xyz[2] = discr->verts[3*i+2];
2231 stat = caps_invInterpolate1D(bound->curve, xyz, &values[i]);
2232 if (stat != EGADS_SUCCESS0)
2233 printf(" CAPS Internal: caps_invInterpolate1D %d for %s = %d\n",
2234 i+1, dobject->name, stat);
2235 }
2236 }
2237 }
2238
2239 }
2240
2241 dataset->data = values;
2242 dataset->npts = npts;
2243/*
2244 if (dobject->last.sNum != 0) {
2245 if (dataset->history == NULL) {
2246 dataset->nHist = 0;
2247 dataset->history = (capsOwn *) EG_alloc(sizeof(capsOwn));
2248 if (dataset->history == NULL) OK = 0;
2249 } else {
2250 tmp = (capsOwn *) EG_reall( dataset->history,
2251 (dataset->nHist+1)*sizeof(capsOwn));
2252 if (tmp == NULL) {
2253 OK = 0;
2254 } else {
2255 dataset->history = tmp;
2256 }
2257 }
2258 if ((OK == 1) && (dataset->history != NULL)) {
2259 dataset->history[dataset->nHist] = dobject->last;
2260 dataset->history[dataset->nHist].nLines = 0;
2261 dataset->history[dataset->nHist].lines = NULL;
2262 dataset->history[dataset->nHist].pname = EG_strdup(dobject->last.pname);
2263 dataset->history[dataset->nHist].pID = EG_strdup(dobject->last.pID);
2264 dataset->history[dataset->nHist].user = EG_strdup(dobject->last.user);
2265 dataset->nHist += 1;
2266 }
2267 }
2268*/
2269 caps_freeOwner(&dobject->last);
2270 dobject->last.sNum = sNum;
2271 caps_fillDateTime(dobject->last.datetime);
2272 stat = caps_writeDataSet(dobject);
2273 if (stat != CAPS_SUCCESS0)
2274 printf(" CAPS Warning: caps_writeDataSet = %d (caps_fillBuiltIn)\n", stat);
2275}
2276
2277
2278static void
2279caps_fillSensit(capsProblem *problem, capsDiscr *discr, capsDataSet *dataset)
2280{
2281 int i, j, k, n, bIndex, index, ibody, stat, state, nGlobal, outLevel;
2282 int ii, ni, oclass, mtype, nEdge, nFace, len, ntri, *bins, *senses;
2283 double limits[4], *vel;
2284 const int *ptype, *pindex, *tris, *tric;
2285 const double *dxyz, *xyzs, *uvs;
2286 ego topRef, prev, next, tess, oldtess, body, eobject, *objs;
2287 modl_T *MODL;
2288 capsBodyDiscr *discBody;
2289
2290 MODL = (modl_T *) problem->modl;
2291 for (bIndex = 1; bIndex <= discr->nBodys; bIndex++) {
2292 discBody = &discr->bodys[bIndex-1];
2293
2294 stat = EG_statusTessBody(discBody->tess, &body, &state, &nGlobal);
2295 if (stat != EGADS_SUCCESS0) {
2296 printf(" caps_fillSensit abort: EG_statusTessBody = %d for body %d!\n",
2297 stat, bIndex);
2298 return;
2299 }
2300
2301 stat = EG_getInfo(body, &oclass, &mtype, &topRef, &prev, &next);
2302 if (stat != EGADS_SUCCESS0) {
2303 printf(" caps_fillSensit abort: getInfo = %d for body %d!\n",
2304 stat, bIndex);
2305 return;
2306 }
2307 nEdge = nFace = 0;
2308 if (mtype == WIREBODY6) {
2309 stat = EG_getBodyTopos(body, NULL((void*)0), EDGE21, &nEdge, NULL((void*)0));
2310 if (stat != EGADS_SUCCESS0) {
2311 printf(" caps_fillSensit abort: getBodyTopos (Edge) = %d for %d!\n",
2312 stat, bIndex);
2313 return;
2314 }
2315 } else {
2316 stat = EG_getBodyTopos(body, NULL((void*)0), FACE23, &nFace, NULL((void*)0));
2317 if (stat != EGADS_SUCCESS0) {
2318 printf(" caps_fillSensit abort: getBodyTopos (Face) = %d for %d!\n",
2319 stat, bIndex);
2320 return;
2321 }
2322 }
2323 for (ibody = 1; ibody <= MODL->nbody; ibody++) {
2324 if (MODL->body[ibody].onstack != 1) continue;
2325 if (MODL->body[ibody].botype == OCSM_NULL_BODY404) continue;
2326 if (MODL->body[ibody].ebody == body) break;
2327 }
2328 if (ibody > MODL->nbody) {
2329 printf(" caps_fillSensit abort: Body Not Found in OpenCSM stack!\n");
2330 return;
2331 }
2332 oldtess = MODL->body[ibody].etess;
2333 tess = discBody->tess;
2334 if (tess == NULL((void*)0)) {
2335 printf(" caps_fillSensit abort: Body Tess %d Not Found!\n",
2336 bIndex);
2337 return;
2338 }
2339 MODL->body[ibody].etess = tess;
2340
2341 bins = (int *) EG_alloc((nEdge+nFace)*sizeof(int));
2342 if (bins == NULL((void*)0)) {
2343 printf(" caps_fillSensit abort: %d allocating = %d ints!\n",
2344 ibody, nEdge+nFace);
2345 MODL->body[ibody].etess = oldtess;
2346 return;
2347 }
2348
2349 for (ii = 0; ii < discBody->nElems; ii++) {
2350 j = discBody->elems[ii].eIndex - 1;
2351 bins[j]++;
2352 }
2353
2354 if (nFace == 0) {
2355
2356 for (index = 1; index <= nEdge; index++) {
2357 if (bins[index-1] == 0) continue;
2358 stat = EG_getTessEdge(tess, index, &len, &xyzs, &uvs);
2359 if (stat != SUCCESS0) {
2360 printf(" caps_fillSensit EG_getTessFace Edge = %d for %d!\n",
2361 stat, index);
2362 continue;
2363 }
2364 if (len == 0) continue;
2365 /* get the EGADS status of the Edge */
2366 stat = EG_objectBodyTopo(body, EDGE21, index, &eobject);
2367 if (stat != EGADS_SUCCESS0) {
2368 printf(" caps_fillSensit EG_objectBodyTopo Edge = %d for %d!\n",
2369 stat, index);
2370 continue;
2371 }
2372 stat = EG_getTopology(eobject, &prev, &oclass, &mtype, limits, &n,
2373 &objs, &senses);
2374 if (stat != EGADS_SUCCESS0) {
2375 printf(" caps_fillSensit EG_getTopology Edge = %d for %d!\n",
2376 stat, index);
2377 continue;
2378 }
2379 if (mtype == DEGENERATE5) {
2380 printf(" caps_fillSensit DEGENERATE Edge for %d!\n", index);
2381 continue;
2382 }
2383 vel = (double *) EG_alloc(3*len*sizeof(double));
2384 if (vel == NULL((void*)0)) {
2385 printf(" caps_fillSensit Edge malloc using %d doubles for %d!\n",
2386 len, index);
2387 continue;
2388 }
2389 if (dataset->ftype == TessSens) {
2390 outLevel = ocsmSetOutLevel(0);
2391 stat = ocsmGetTessVel(problem->modl, ibody, OCSM_EDGE601, index, &dxyz);
2392 ocsmSetOutLevel(outLevel);
2393 if (stat != SUCCESS0) {
2394 printf(" caps_fillSensit ocsmGetTessVel Edge = %d for %d!\n",
2395 stat, index);
2396 EG_free(vel);
2397 continue;
2398 }
2399 for (k = 0; k < 3*len; k++) vel[k] = dxyz[k];
2400 /* readjust the Nodes */
2401 ii = EG_indexBodyTopo(body, objs[0]);
2402 if (ii <= EGADS_SUCCESS0) {
2403 printf(" caps_fillSensit EG_indexBodyTopo Edge 0 = %d for %d!\n",
2404 ii, index);
2405 EG_free(vel);
2406 continue;
2407 }
2408 outLevel = ocsmSetOutLevel(0);
2409 stat = ocsmGetTessVel(problem->modl, ibody, OCSM_NODE600, ii, &dxyz);
2410 ocsmSetOutLevel(outLevel);
2411 if (stat != SUCCESS0) {
2412 printf(" caps_fillSensit ocsmGetTessVel Node 0 = %d for %d!\n",
2413 stat, index);
2414 EG_free(vel);
2415 continue;
2416 }
2417 vel[0] = dxyz[0];
2418 vel[1] = dxyz[1];
2419 vel[2] = dxyz[2];
2420 if (n > 1) {
2421 ii = EG_indexBodyTopo(body, objs[1]);
2422 if (ii <= EGADS_SUCCESS0) {
2423 printf(" caps_fillSensit EG_indexBodyTopo Edge 1 = %d for %d!\n",
2424 ii, index);
2425 EG_free(vel);
2426 continue;
2427 }
2428 outLevel = ocsmSetOutLevel(0);
2429 stat = ocsmGetTessVel(problem->modl, ibody, OCSM_NODE600, ii, &dxyz);
2430 ocsmSetOutLevel(outLevel);
2431 if (stat != SUCCESS0) {
2432 printf(" caps_fillSensit ocsmGetTessVel Node 1 = %d for %d!\n",
2433 stat, index);
2434 EG_free(vel);
2435 continue;
2436 }
2437 }
2438 vel[3*len-3] = dxyz[0];
2439 vel[3*len-2] = dxyz[1];
2440 vel[3*len-1] = dxyz[2];
2441 } else {
2442 outLevel = ocsmSetOutLevel(0);
2443 stat = ocsmGetVel(problem->modl, ibody, OCSM_EDGE601, index, len, NULL((void*)0),
2444 vel);
2445 ocsmSetOutLevel(outLevel);
2446 if (stat != SUCCESS0) {
2447 printf(" caps_fillSensit ocsmGetVel Edge = %d for %d!\n",
2448 stat, index);
2449 EG_free(vel);
2450 continue;
2451 }
2452 }
2453 for (ii = 0; ii < discBody->nElems; ii++) {
2454 if (discBody->elems[ii].eIndex != index) continue;
2455 ni = discr->types[discBody->elems[ii].tIndex-1].nref;
2456 for (k = 0; k < ni; k++) {
2457 i = discBody->elems[ii].gIndices[2*k ]-1;
2458 j = discBody->elems[ii].gIndices[2*k+1]-1;
2459 dataset->data[3*i ] = vel[3*j ];
2460 dataset->data[3*i+1] = vel[3*j+1];
2461 dataset->data[3*i+2] = vel[3*j+2];
2462 }
2463 }
2464 EG_free(vel);
2465 }
2466
2467 } else {
2468
2469 for (index = 1; index <= nFace; index++) {
2470 if (bins[index-1] == 0) continue;
2471 stat = EG_getTessFace(tess, index, &len, &xyzs, &uvs, &ptype,
2472 &pindex, &ntri, &tris, &tric);
2473 if (stat != SUCCESS0) {
2474 printf(" caps_fillSensit EG_getTessFace Face = %d for %d!\n",
2475 stat, index);
2476 continue;
2477 }
2478 if (len == 0) continue;
2479 vel = (double *) EG_alloc(3*len*sizeof(double));
2480 if (vel == NULL((void*)0)) {
2481 printf(" caps_fillSensit Face malloc using %d doubles for %d!\n",
2482 len, index);
2483 continue;
2484 }
2485 if (dataset->ftype == TessSens) {
2486 outLevel = ocsmSetOutLevel(0);
2487 stat = ocsmGetTessVel(problem->modl, ibody, OCSM_FACE602, index, &dxyz);
2488 ocsmSetOutLevel(outLevel);
2489 if (stat != SUCCESS0) {
2490 printf(" caps_fillSensit ocsmGetTessVel Face = %d for %d!\n",
2491 stat, index);
2492 EG_free(vel);
2493 continue;
2494 }
2495 for (k = 0; k < 3*len; k++) vel[k] = dxyz[k];
2496 /* readjust the non-interior velocities */
2497 for (state = ni = k = 0; k < len; k++)
2498 if (ptype[k] == 0) {
2499 outLevel = ocsmSetOutLevel(0);
2500 stat = ocsmGetTessVel(problem->modl, ibody, OCSM_NODE600, pindex[k],
2501 &dxyz);
2502 ocsmSetOutLevel(outLevel);
2503 if (stat != SUCCESS0) {
2504 printf(" caps_fillSensit ocsmGetTessVel Node = %d for %d - %d!\n",
2505 stat, pindex[k], index);
2506 state++;
2507 break;
2508 }
2509 ni = 0;
2510 vel[3*k ] = dxyz[0];
2511 vel[3*k+1] = dxyz[1];
2512 vel[3*k+2] = dxyz[2];
2513 } else if (ptype[k] > 0) {
2514 if (pindex[k] != ni) {
2515 outLevel = ocsmSetOutLevel(0);
2516 stat = ocsmGetTessVel(problem->modl, ibody, OCSM_EDGE601, pindex[k],
2517 &dxyz);
2518 ocsmSetOutLevel(outLevel);
2519 if (stat != SUCCESS0) {
2520 printf(" caps_fillSensit ocsmGetTessVel Edge = %d for %d - %d!\n",
2521 stat, pindex[k], index);
2522 state++;
2523 break;
2524 }
2525 ni = pindex[k];
2526 }
2527 vel[3*k ] = dxyz[3*ptype[k]-3];
2528 vel[3*k+1] = dxyz[3*ptype[k]-2];
2529 vel[3*k+2] = dxyz[3*ptype[k]-1];
2530 }
2531 if (state != 0) {
2532 EG_free(vel);
2533 continue;
2534 }
2535 } else {
2536 outLevel = ocsmSetOutLevel(0);
2537 stat = ocsmGetVel(problem->modl, ibody, OCSM_FACE602, index, len, NULL((void*)0),
2538 vel);
2539 ocsmSetOutLevel(outLevel);
2540 if (stat != SUCCESS0) {
2541 printf(" caps_fillSensit ocsmGetVel Face = %d for %d!\n",
2542 stat, index);
2543 EG_free(vel);
2544 continue;
2545 }
2546 }
2547 for (ii = 0; ii < discBody->nElems; ii++) {
2548 if (discBody->elems[ii].eIndex != index) continue;
2549 ni = discr->types[discBody->elems[ii].tIndex-1].nref;
2550 for (k = 0; k < ni; k++) {
2551 i = discBody->elems[ii].gIndices[2*k ]-1;
2552 j = discBody->elems[ii].gIndices[2*k+1]-1;
2553 dataset->data[3*i ] = vel[3*j ];
2554 dataset->data[3*i+1] = vel[3*j+1];
2555 dataset->data[3*i+2] = vel[3*j+2];
2556 }
2557 }
2558 EG_free(vel);
2559 }
2560
2561 }
2562 EG_free(bins);
2563
2564 MODL->body[ibody].etess = oldtess;
2565 }
2566
2567}
2568
2569
2570static void
2571caps_freeBodyObjs(int nBodies, /*@only@*/ bodyObjs *bodies)
2572{
2573 int i;
2574
2575 for (i = 0; i < nBodies; i++) {
2576 if (bodies[i].objs != NULL((void*)0)) EG_free(bodies[i].objs);
2577 if (bodies[i].indices != NULL((void*)0)) EG_free(bodies[i].indices);
2578 }
2579 EG_free(bodies);
2580}
2581
2582
2583static double
2584caps_triangleArea3D(const double *xyz0, const double *xyz1, const double *xyz2)
2585{
2586 double x1[3], x2[3], n[3];
2587
2588 x1[0] = xyz1[0] - xyz0[0];
2589 x2[0] = xyz2[0] - xyz0[0];
2590 x1[1] = xyz1[1] - xyz0[1];
2591 x2[1] = xyz2[1] - xyz0[1];
2592 x1[2] = xyz1[2] - xyz0[2];
2593 x2[2] = xyz2[2] - xyz0[2];
2594 CROSS(n, x1, x2)n[0] = (x1[1]*x2[2]) - (x1[2]*x2[1]); n[1] = (x1[2]*x2[0]) - (
x1[0]*x2[2]); n[2] = (x1[0]*x2[1]) - (x1[1]*x2[0])
;
2595 return 0.5*sqrt(DOT(n, n)(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]));
2596}
2597
2598
2599static int
2600caps_paramQuilt(capsBound *bound, int l, char *line)
2601{
2602 int i, j, k, m, n, stat, npts, ntris, own, nu, nv, per, eType;
2603 int ntrx, nptx, last, bIndex, pt, pi, *ppnts, *vtab, count, iVS;
2604 int i0, i1, i2, global;
2605 double coord[3], box[6], tol, rmserr, maxerr, dotmin, area, d;
2606 double *grid, *r, *xyzs;
2607 capsDiscr *quilt;
2608 capsAprx2D *surface;
2609 capsVertexSet *vertexset;
2610 capsBodyDiscr *discBody;
2611 prmXYZ *xyz;
2612 prmTri *tris;
2613 prmUVF *uvf;
2614 prmUV *uv;
2615 connect *etab;
2616 const int *ptype, *pindex, *trix, *tric;
2617 const double *xyzx, *prms;
2618
2619 for (npts = ntris = i = 0; i < bound->nVertexSet; i++) {
2620 if (bound->vertexSet[i] == NULL((void*)0)) continue;
2621 if (bound->vertexSet[i]->magicnumber != CAPSMAGIC1234321) continue;
2622 if (bound->vertexSet[i]->type != VERTEXSET) continue;
2623 if (bound->vertexSet[i]->blind == NULL((void*)0)) continue;
2624 vertexset = (capsVertexSet *) bound->vertexSet[i]->blind;
2625 if (vertexset->analysis == NULL((void*)0)) continue;
2626 if (vertexset->discr == NULL((void*)0)) continue;
2627 quilt = vertexset->discr;
2628
2629 for (bIndex = 1; bIndex <= quilt->nBodys; bIndex++) {
2630 discBody = &quilt->bodys[bIndex-1];
2631 for (j = 0; j < discBody->nElems; j++) {
2632 eType = discBody->elems[j].tIndex;
2633 if (quilt->types[eType-1].tris == NULL((void*)0)) {
2634 ntris++;
2635 } else {
2636 ntris += quilt->types[eType-1].ntri;
2637 }
2638 }
2639 }
2640 npts += quilt->nPoints;
2641 }
2642
2643 if ((ntris == 0) || (npts == 0)) {
2644 snprintf(line, l,
2645 "caps_paramQuilt Error: nPoints = %d nTris = %d", npts, ntris);
2646 return CAPS_NOTCONNECT-313;
2647 }
2648
2649 uv = (prmUV *) EG_alloc(npts*sizeof(prmUV));
2650 if (uv == NULL((void*)0)) {
2651 snprintf(line, l,
2652 "caps_paramQuilt Error: Malloc on = %d prmUV", npts);
2653 return EGADS_MALLOC-4;
2654 }
2655 uvf = (prmUVF *) EG_alloc(ntris*sizeof(prmUVF));
2656 if (uvf == NULL((void*)0)) {
2657 EG_free(uv);
2658 snprintf(line, l,
2659 "caps_paramQuilt Error: Malloc on = %d prmUVF", ntris);
2660 return EGADS_MALLOC-4;
2661 }
2662 xyz = (prmXYZ *) EG_alloc(npts*sizeof(prmXYZ));
2663 if (xyz == NULL((void*)0)) {
2664 EG_free(uvf);
2665 EG_free(uv);
2666 snprintf(line, l,
2667 "caps_paramQuilt Error: Malloc on = %d prmXYZ", npts);
2668 return EGADS_MALLOC-4;
2669 }
2670 xyzs = (double *) xyz;
2671 tris = (prmTri *) EG_alloc(ntris*sizeof(prmTri));
2672 if (tris == NULL((void*)0)) {
2673 EG_free(xyz);
2674 EG_free(uvf);
2675 EG_free(uv);
2676 snprintf(line, l,
2677 "caps_paramQuilt Error: Malloc on = %d ints", 3*ntris);
2678 return EGADS_MALLOC-4;
2679 }
2680
2681 /* find the best candidate VertexSet for fitting */
2682 iVS = -1;
2683 area = 0.0;
2684 for (i = 0; i < bound->nVertexSet; i++) {
2685 if (bound->vertexSet[i] == NULL((void*)0)) continue;
2686 if (bound->vertexSet[i]->magicnumber != CAPSMAGIC1234321) continue;
2687 if (bound->vertexSet[i]->type != VERTEXSET) continue;
2688 if (bound->vertexSet[i]->blind == NULL((void*)0)) continue;
2689 vertexset = (capsVertexSet *) bound->vertexSet[i]->blind;
2690 if (vertexset->analysis == NULL((void*)0)) continue;
2691 if (vertexset->discr == NULL((void*)0)) continue;
2692 quilt = vertexset->discr;
2693
2694 d = 0.0;
2695 ntris = 0;
2696 for (bIndex = 1; bIndex <= quilt->nBodys; bIndex++) {
2697 discBody = &quilt->bodys[bIndex-1];
2698 for (last = j = 0; j < discBody->nElems; j++) {
2699 eType = discBody->elems[j].tIndex;
2700 own = discBody->elems[j].eIndex;
2701 if (own != last) {
2702 stat = EG_getTessFace(discBody->tess,
2703 own, &nptx, &xyzx, &prms, &ptype, &pindex,
2704 &ntrx, &trix, &tric);
2705 if (stat != EGADS_SUCCESS0) {
2706 printf(" CAPS Internal: EG_getTessFace %d = %d for %d\n",
2707 own, stat, bIndex);
2708 continue;
2709 }
2710/* printf(" VS = %s\n Face %d: ntris = %d quilt eles = %d!\n",
2711 bound->vertexSet[i]->parent->name, own, nptx, quilt->nElems); */
2712 last = own;
2713 }
2714 if (quilt->types[eType-1].tris == NULL((void*)0)) {
2715#ifndef __clang_analyzer__1
2716 i0 = discBody->elems[j].gIndices[1] - 1;
2717 i1 = discBody->elems[j].gIndices[3] - 1;
2718 i2 = discBody->elems[j].gIndices[5] - 1;
2719 d += caps_triangleArea3D(&xyzx[3*i0], &xyzx[3*i1], &xyzx[3*i2]);
2720#endif
2721 ntris++;
2722 } else {
2723#ifndef __clang_analyzer__1
2724 for (k = 0; k < quilt->types[eType-1].ntri; k++, ntris++) {
2725 n = quilt->types[eType-1].tris [3*k ] - 1;
2726 i0 = discBody->elems[j].gIndices[2*n+1] - 1;
2727 n = quilt->types[eType-1].tris [3*k+1] - 1;
2728 i1 = discBody->elems[j].gIndices[2*n+1] - 1;
2729 n = quilt->types[eType-1].tris [3*k+2] - 1;
2730 i2 = discBody->elems[j].gIndices[2*n+1] - 1;
2731 d += caps_triangleArea3D(&xyzx[3*i0], &xyzx[3*i1], &xyzx[3*i2]);
2732 }
2733#endif
2734 }
2735 }
2736 }
2737#ifdef DEBUG
2738 printf(" VertexSet %d: area = %lf ntris = %d\n", i+1, d, ntris);
2739#endif
2740 if (d > area) {
2741 iVS = i;
2742 area = d;
2743 }
2744 }
2745 if (iVS == -1) {
2746 EG_free(tris);
2747 EG_free(xyz);
2748 EG_free(uvf);
2749 EG_free(uv);
2750 snprintf(line, l,
2751 "caps_paramQuilt Error: No VertexSet Selected!");
2752 return EGADS_NOTFOUND-1;
2753 }
2754#ifdef DEBUG
2755 printf(" selected VertexSet = %d\n", iVS+1);
2756#endif
2757
2758/*
2759 for (count = npts = ntris = i = 0; i < bound->nVertexSet; i++) { */
2760 count = npts = ntris = 0;
2761 for (i = iVS; i <= iVS; i++) {
2762 if (bound->vertexSet[i] == NULL((void*)0)) continue;
2763 if (bound->vertexSet[i]->magicnumber != CAPSMAGIC1234321) continue;
2764 if (bound->vertexSet[i]->type != VERTEXSET) continue;
2765 if (bound->vertexSet[i]->blind == NULL((void*)0)) continue;
2766 vertexset = (capsVertexSet *) bound->vertexSet[i]->blind;
2767 if (vertexset->analysis == NULL((void*)0)) continue;
2768 if (vertexset->discr == NULL((void*)0)) continue;
2769 quilt = vertexset->discr;
2770 prms = NULL((void*)0);
2771 for (bIndex = 1; bIndex <= quilt->nBodys; bIndex++) {
2772 discBody = &quilt->bodys[bIndex-1];
2773 for (last = j = 0; j < discBody->nElems; j++) {
2774 eType = discBody->elems[j].tIndex;
2775 own = discBody->elems[j].eIndex;
2776 if (own != last) {
2777 count++;
2778/* printf(" Analysis %d/%d Body %d/%d Face %d: count = %d, npts = %d\n",
2779 i+1, bound->nVertexSet, bIndex, analysis->nBody, own, count,
2780 npts); */
2781 stat = EG_getTessFace(discBody->tess,
2782 own, &nptx, &xyzx, &prms, &ptype, &pindex,
2783 &ntrx, &trix, &tric);
2784 if (stat != EGADS_SUCCESS0) {
2785 printf(" CAPS Internal: getTessFace %d = %d for %d\n",
2786 own, stat, bIndex);
2787 continue;
2788 }
2789 last = own;
2790 }
2791 if (prms == NULL((void*)0)) continue;
2792 if (quilt->types[eType-1].tris == NULL((void*)0)) {
2793 m = discBody->elems[j].gIndices[1] - 1;
2794 uvf[ntris].u0 = prms[2*m ];
2795 uvf[ntris].v0 = prms[2*m+1];
2796 tris[ntris].indices[0] = discBody->elems[j].gIndices[0] + npts;
2797 m = discBody->elems[j].gIndices[3] - 1;
2798 uvf[ntris].u1 = prms[2*m ];
2799 uvf[ntris].v1 = prms[2*m+1];
2800 tris[ntris].indices[1] = discBody->elems[j].gIndices[2] + npts;
2801 m = discBody->elems[j].gIndices[5] - 1;
2802 uvf[ntris].u2 = prms[2*m ];
2803 uvf[ntris].v2 = prms[2*m+1];
2804 tris[ntris].indices[2] = discBody->elems[j].gIndices[4] + npts;
2805 tris[ntris].own = count;
2806 ntris++;
2807 } else {
2808 for (k = 0; k < quilt->types[eType-1].ntri; k++, ntris++) {
2809 n = quilt->types[eType-1].tris [3*k ] - 1;
2810 m = discBody->elems[j].gIndices[2*n+1] - 1;
2811 uvf[ntris].u0 = prms[2*m ];
2812 uvf[ntris].v0 = prms[2*m+1];
2813 tris[ntris].indices[0] = discBody->elems[j].gIndices[2*n] + npts;
2814 n = quilt->types[eType-1].tris [3*k+1] - 1;
2815 m = discBody->elems[j].gIndices[2*n+1] - 1;
2816 uvf[ntris].u1 = prms[2*m ];
2817 uvf[ntris].v1 = prms[2*m+1];
2818 tris[ntris].indices[1] = discBody->elems[j].gIndices[2*n] + npts;
2819 n = quilt->types[eType-1].tris [3*k+2] - 1;
2820 m = discBody->elems[j].gIndices[2*n+1] - 1;
2821 uvf[ntris].u2 = prms[2*m ];
2822 uvf[ntris].v2 = prms[2*m+1];
2823 tris[ntris].indices[2] = discBody->elems[j].gIndices[2*n] + npts;
2824 tris[ntris].own = count;
2825 }
2826 }
2827 }
2828 }
2829 for (j = 0; j < quilt->nPoints; j++) {
2830 bIndex = quilt->tessGlobal[2*j ];
2831 global = quilt->tessGlobal[2*j+1];
2832 discBody = &quilt->bodys[bIndex-1];
2833 stat = EG_getGlobal(discBody->tess, global, &pt, &pi, coord);
2834 if (stat != EGADS_SUCCESS0) {
2835 printf(" CAPS Internal: %d EG_getGlobal %d = %d\n", bIndex, j+1, stat);
2836 } else {
2837 xyz[npts+j].x = coord[0];
2838 xyz[npts+j].y = coord[1];
2839 xyz[npts+j].z = coord[2];
2840 }
2841 }
2842 npts += quilt->nPoints;
2843 }
2844
2845 /* make the neighbors */
2846
2847 vtab = (int *) EG_alloc(npts*sizeof(int));
2848 if (vtab == NULL((void*)0)) {
2849 EG_free(tris);
2850 EG_free(xyz);
2851 EG_free(uvf);
2852 EG_free(uv);
2853 snprintf(line, l,
2854 "caps_paramQuilt Error: Malloc on table = %d ints", npts);
2855 return EGADS_MALLOC-4;
2856 }
2857 etab = (connect *) EG_alloc(ntris*3*sizeof(connect));
2858 if (etab == NULL((void*)0)) {
2859 EG_free(vtab);
2860 EG_free(tris);
2861 EG_free(xyz);
2862 EG_free(uvf);
2863 EG_free(uv);
2864 snprintf(line, l,
2865 "caps_paramQuilt Error: Malloc on side table = %d connect",
2866 3*ntris);
2867 return EGADS_MALLOC-4;
2868 }
2869 n = NOTFILLED-1;
2870 for (j = 0; j < npts; j++) vtab[j] = NOTFILLED-1;
2871 for (i = 0; i < ntris; i++) {
2872 tris[i].neigh[0] = tris[i].neigh[1] = tris[i].neigh[2] = i+1;
2873 EG_makeConnect( tris[i].indices[1], tris[i].indices[2],
2874 &tris[i].neigh[0], &n, vtab, etab, 0);
2875 EG_makeConnect( tris[i].indices[0], tris[i].indices[2],
2876 &tris[i].neigh[1], &n, vtab, etab, 0);
2877 EG_makeConnect( tris[i].indices[0], tris[i].indices[1],
2878 &tris[i].neigh[2], &n, vtab, etab, 0);
2879 }
2880 /* find any unconnected triangle sides */
2881 for (j = 0; j <= n; j++) {
2882 if (etab[j].tri == NULL((void*)0)) continue;
2883/* printf(" CAPS Info: Unconnected Side %d %d = %d\n",
2884 etab[j].node1+1, etab[j].node2+1, *etab[j].tri); */
2885 *etab[j].tri = 0;
2886 }
2887 EG_free(etab);
2888 EG_free(vtab);
2889
2890 /* get tolerance */
2891
2892 box[0] = box[3] = xyz[0].x;
2893 box[1] = box[4] = xyz[0].y;
2894 box[2] = box[5] = xyz[0].z;
2895 for (j = 1; j < npts; j++) {
2896 if (xyz[j].x < box[0]) box[0] = xyz[j].x;
2897 if (xyz[j].x > box[3]) box[3] = xyz[j].x;
2898 if (xyz[j].y < box[1]) box[1] = xyz[j].y;
2899 if (xyz[j].y > box[4]) box[4] = xyz[j].y;
2900 if (xyz[j].z < box[2]) box[2] = xyz[j].z;
2901 if (xyz[j].z > box[5]) box[5] = xyz[j].z;
2902 }
2903 n = 1;
2904 grid = NULL((void*)0);
2905 ppnts = NULL((void*)0);
2906 tol = 1.e-7*sqrt((box[3]-box[0])*(box[3]-box[0]) +
2907 (box[4]-box[1])*(box[4]-box[1]) +
2908 (box[5]-box[2])*(box[5]-box[2]));
2909
2910 /* reparameterize */
2911
2912 stat = prm_CreateUV(0, ntris, tris, uvf, npts, NULL((void*)0), NULL((void*)0), uv, xyz,
2913 &per, &ppnts);
2914#ifdef DEBUG
2915 printf(" caps_paramQuilt: prm_CreateUV = %d per = %d\n", stat, per);
2916#endif
2917 if (stat > 0) {
2918 n = 2;
2919 stat = prm_SmoothUV(3, per, ppnts, ntris, tris, npts, 3, uv, xyzs);
2920#ifdef DEBUG
2921 printf(" caps_paraQuilt: prm_SmoothUV = %d\n", stat);
2922#endif
2923 if (stat == CAPS_SUCCESS0) {
2924 n = 3;
2925 stat = prm_NormalizeUV(0.05, per, npts, uv);
2926#ifdef DEBUG
2927 printf(" caps_paraQuilt: prm_NormalizeUV = %d\n", stat);
2928#endif
2929 if (stat == CAPS_SUCCESS0) {
2930 n = 4;
2931 nu = 2*npts;
2932 nv = 0;
2933 stat = prm_BestGrid(npts, 3, uv, xyzs, ntris, tris, tol, per, ppnts,
2934 &nu, &nv, &grid, &rmserr, &maxerr, &dotmin);
2935 if (stat == PRM_TOLERANCEUNMET-405) {
2936 printf(" caps_paramQuilt: Tolerance not met: %lf (%lf)!\n",
2937 maxerr, tol);
2938 stat = CAPS_SUCCESS0;
2939 }
2940#ifdef DEBUG
2941 printf(" caps_paramQuilt: prm_BestGrid = %d %d %d %lf %lf (%lf)\n",
2942 stat, nu, nv, rmserr, maxerr, tol);
2943#endif
2944 }
2945 }
2946 }
2947 if (ppnts != NULL((void*)0)) EG_free(ppnts);
2948 EG_free(tris);
2949 EG_free(uvf);
2950 EG_free(xyz);
2951 EG_free(uv);
2952 if ((stat != CAPS_SUCCESS0) || (grid == NULL((void*)0))) {
2953 snprintf(line, l,
2954 "caps_paramQuilt: Create/Smooth/Normalize/BestGrid %d = %d!",
2955 n, stat);
2956 return stat;
2957 }
2958
2959 /* make the surface approximation */
2960
2961 surface = (capsAprx2D *) EG_alloc(sizeof(capsAprx2D));
2962 if (surface == NULL((void*)0)) {
2963 EG_free(grid);
2964 snprintf(line, l,
2965 "caps_paramQuilt Error: Malloc on Surface!");
2966 return EGADS_MALLOC-4;
2967 }
2968 surface->nrank = 3;
2969 surface->periodic = per;
2970 surface->nus = nu;
2971 surface->nvs = nv;
2972 surface->urange[0] = 0.0;
2973 surface->urange[1] = nu-1;
2974 surface->vrange[0] = 0.0;
2975 surface->vrange[1] = nv-1;
2976 surface->num = 0;
2977 surface->nvm = 0;
2978 surface->uvmap = NULL((void*)0);
2979 surface->interp = (double *) EG_alloc(3*4*nu*nv*sizeof(double));
2980 if (surface->interp == NULL((void*)0)) {
2981 EG_free(surface);
2982 EG_free(grid);
2983 snprintf(line, l,
2984 "caps_paramQuilt Error: Malloc on Approx nu = %d, nv = %d",
2985 nu, nv);
2986 return EGADS_MALLOC-4;
2987 }
2988 n = nu;
2989 if (nv > nu) n = nv;
2990 r = (double *) EG_alloc(6*n*sizeof(double));
2991 if (r == NULL((void*)0)) {
2992 caps_Aprx2DFree(surface);
2993 EG_free(grid);
2994 snprintf(line, l,
2995 "caps_paramQuilt Error: Malloc on temp, size = %d", n);
2996 return EGADS_MALLOC-4;
2997 }
2998 stat = caps_fillCoeff2D(3, nu, nv, grid, surface->interp, r);
2999 EG_free(r);
3000 EG_free(grid);
3001 if (stat == 1) {
3002 caps_Aprx2DFree(surface);
3003 snprintf(line, l,
3004 "caps_paramQuilt Error: Failure in producing interpolant!");
3005 return CAPS_PARAMBNDERR-312;
3006 }
3007 bound->surface = surface;
3008 bound->plimits[0] = bound->plimits[2] = 0.0;
3009 bound->plimits[1] = nu-1;
3010 bound->plimits[3] = nv-1;
3011
3012 return CAPS_SUCCESS0;
3013}
3014
3015
3016static int
3017caps_parameterize(capsProblem *problem, capsObject *bobject, int l, char *line)
3018{
3019 int i, j, k, stat, last, top, bIndex, state, nGlobal;
3020 char *units;
3021 double plims[4];
3022 ego entity, body;
3023 capsBound *bound;
3024 capsVertexSet *vertexset;
3025 capsDiscr *discr;
3026 capsBodyDiscr *discBody;
3027 bodyObjs *bodies;
3028
3029 bound = (capsBound *) bobject->blind;
3030 if ((bound->dim != 1) && (bound->dim != 2)) {
3031 snprintf(line, l, "caps_parameterize Error: Dimension = %d", bound->dim);
3032 return CAPS_BADINDEX-304;
3033 }
3034 bodies = (bodyObjs *) EG_alloc(problem->nBodies*sizeof(bodyObjs));
3035 if (bodies == NULL((void*)0)) {
3036 snprintf(line, l, "caps_parameterize Error: Allocating %d bodyObjs",
3037 problem->nBodies);
3038 return EGADS_MALLOC-4;
3039 }
3040 for (i = 0; i < problem->nBodies; i++) {
3041 bodies[i].n = 0;
3042 bodies[i].gIndex = 0;
3043 bodies[i].geom = NULL((void*)0);
3044 bodies[i].objs = NULL((void*)0);
3045 bodies[i].indices = NULL((void*)0);
3046 }
3047 for (i = 0; i < problem->nBodies; i++) {
3048 if (bound->dim == 1) {
3049 stat = EG_getBodyTopos(problem->bodies[i], NULL((void*)0), EDGE21, &bodies[i].n,
3050 &bodies[i].objs);
3051 if (stat != EGADS_SUCCESS0) {
3052 snprintf(line, l,
3053 "caps_parameterize Error: getBodyTopos EDGE for Body #%d",
3054 i+1);
3055 caps_freeBodyObjs(problem->nBodies, bodies);
3056 return stat;
3057 }
3058 } else {
3059 stat = EG_getBodyTopos(problem->bodies[i], NULL((void*)0), FACE23, &bodies[i].n,
3060 &bodies[i].objs);
3061 if (stat != EGADS_SUCCESS0) {
3062 snprintf(line, l,
3063 "caps_parameterize Error: getBodyTopos FACE for Body #%d",
3064 i+1);
3065 caps_freeBodyObjs(problem->nBodies, bodies);
3066 return stat;
3067 }
3068 }
3069 if (bodies[i].n != 0) {
3070 bodies[i].indices = (int *) EG_alloc(bodies[i].n*sizeof(int));
3071 if (bodies[i].indices == NULL((void*)0)) {
3072 snprintf(line, l, "caps_parameterize Error: malloc %d ints for Body #%d",
3073 bodies[i].n, i+1);
3074 caps_freeBodyObjs(problem->nBodies, bodies);
3075 return EGADS_MALLOC-4;
3076 }
3077 for (j = 0; j < bodies[i].n; j++) bodies[i].indices[j] = 0;
3078 }
3079 }
3080
3081 for (i = 0; i < bound->nVertexSet; i++) {
3082 if (bound->vertexSet[i] == NULL((void*)0)) continue;
3083 if (bound->vertexSet[i]->magicnumber != CAPSMAGIC1234321) continue;
3084 if (bound->vertexSet[i]->type != VERTEXSET) continue;
3085 if (bound->vertexSet[i]->blind == NULL((void*)0)) continue;
3086 vertexset = (capsVertexSet *) bound->vertexSet[i]->blind;
3087 if (vertexset->analysis == NULL((void*)0)) continue;
3088 if (vertexset->discr == NULL((void*)0)) continue;
3089 discr = vertexset->discr;
3090 if (discr->dim != bound->dim) {
3091 snprintf(line, l,
3092 "caps_parameterize Error: VertexSet %s Dimension = %d not %d",
3093 bound->vertexSet[i]->name, discr->dim, bound->dim);
3094 caps_freeBodyObjs(problem->nBodies, bodies);
3095 return CAPS_BADINDEX-304;
3096 }
3097 for (bIndex = 1; bIndex <= discr->nBodys; bIndex++) {
3098 discBody = &discr->bodys[bIndex-1];
3099
3100 stat = EG_statusTessBody(discBody->tess, &body, &state, &nGlobal);
3101 if (stat != EGADS_SUCCESS0) {
3102 printf(" caps_parameterize: EG_statusTessBody = %d for body %d!\n",
3103 stat, bIndex);
3104 caps_freeBodyObjs(problem->nBodies, bodies);
3105 return stat;
3106 }
3107
3108 for (k = 0; k < problem->nBodies; k++)
3109 if (problem->bodies[k] == body) {
3110 for (j = 0; j < discBody->nElems; j++) {
3111 bodies[k].indices[discBody->elems[j].eIndex-1]++;
3112 break;
3113 }
3114 }
3115 }
3116 }
3117
3118 /* get the parameterization */
3119 entity = NULL((void*)0);
3120 bound->plimits[0] = bound->plimits[1] = bound->plimits[2] =
3121 bound->plimits[3] = 0.0;
3122
3123 /* do we have only a single Geometry entity -- in body? */
3124 for (last = i = 0; i < problem->nBodies; i++) {
3125 for (j = 0; j < bodies[i].n; j++) {
3126 if (bodies[i].indices[j] != 0) {
3127 if (bodies[i].gIndex == 0) {
3128 bodies[i].gIndex = j+1;
3129 bodies[i].geom = bodies[i].objs[j];
3130 plims[0] = plims[1] = plims[2] = plims[3] = 0.0;
3131 stat = EG_getRange(bodies[i].geom, plims, &top);
3132 if (stat != EGADS_SUCCESS0) {
3133 snprintf(line, l,
3134 "caps_parameterize Error: getRange for Body #%d %d",
3135 i+1, bodies[i].gIndex);
3136 caps_freeBodyObjs(problem->nBodies, bodies);
3137 return stat;
3138 }
3139 if (last == 0) {
3140 bound->plimits[0] = plims[0];
3141 bound->plimits[1] = plims[1];
3142 bound->plimits[2] = plims[2];
3143 bound->plimits[3] = plims[3];
3144 entity = bodies[i].geom;
3145 last++;
3146 } else {
3147 if (plims[0] < bound->plimits[0]) bound->plimits[0] = plims[0];
3148 if (plims[1] > bound->plimits[1]) bound->plimits[1] = plims[1];
3149 if (plims[2] < bound->plimits[2]) bound->plimits[2] = plims[2];
3150 if (plims[3] > bound->plimits[3]) bound->plimits[3] = plims[3];
3151 }
3152 } else {
3153 stat = EG_isSame(bodies[i].geom, bodies[i].objs[j]);
3154 if (stat < 0) {
3155 snprintf(line, l,
3156 "caps_parameterize Error: isSame for Body #%d %d %d",
3157 i+1, bodies[i].gIndex, j+1);
3158 caps_freeBodyObjs(problem->nBodies, bodies);
3159 return stat;
3160 }
3161 if (stat != EGADS_SUCCESS0) {
3162 bodies[i].gIndex = -1;
3163 break;
3164 }
3165 plims[0] = plims[1] = plims[2] = plims[3] = 0.0;
3166 stat = EG_getRange(bodies[i].objs[j], plims, &top);
3167 if (stat != EGADS_SUCCESS0) {
3168 snprintf(line, l,
3169 "caps_parameterize Error: getRange for Body #%d %d",
3170 i+1, j+1);
3171 caps_freeBodyObjs(problem->nBodies, bodies);
3172 return stat;
3173 }
3174 if (plims[0] < bound->plimits[0]) bound->plimits[0] = plims[0];
3175 if (plims[1] > bound->plimits[1]) bound->plimits[1] = plims[1];
3176 if (plims[2] < bound->plimits[2]) bound->plimits[2] = plims[2];
3177 if (plims[3] > bound->plimits[3]) bound->plimits[3] = plims[3];
3178 }
3179 }
3180 }
3181 }
3182
3183 /* cross body */
3184 for (last = i = 0; i < problem->nBodies; i++) {
3185 if (bodies[i].gIndex == 0) continue;
3186 if (bodies[i].gIndex == -1) {
3187 last = -1;
3188 break;
3189 }
3190 if (last == 0) {
3191 last = i+1;
3192 } else {
3193 stat = EG_isSame(bodies[last-1].geom, bodies[i].geom);
3194 if (stat < 0) {
3195 snprintf(line, l,
3196 "caps_parameterize Error: isSame for Body #%d %d - #%d %d",
3197 last, bodies[last-1].gIndex, i+1, bodies[i].gIndex);
3198 caps_freeBodyObjs(problem->nBodies, bodies);
3199 return stat;
3200 }
3201 if (stat != EGADS_SUCCESS0) {
3202 last = -1;
3203 break;
3204 }
3205 }
3206 }
3207 if (last == 0) {
3208 bound->state = Empty;
3209 printf(" CAPS Info: No geometry for Bound -> %s!\n", bobject->name);
3210 caps_freeBodyObjs(problem->nBodies, bodies);
3211 return CAPS_SUCCESS0;
3212 }
3213
3214 /* single geometric entity */
3215 if (last != -1) {
3216 if (bound->lunits != NULL((void*)0)) EG_free(bound->lunits);
3217 bound->geom = entity;
3218 bound->iBody = last;
3219 bound->iEnt = bodies[last-1].gIndex;
3220 bound->state = Single;
3221 bound->lunits = EG_strdup(problem->lunits[last-1]);
3222 caps_freeBodyObjs(problem->nBodies, bodies);
3223 return CAPS_SUCCESS0;
3224 }
3225
3226 /* need to reparameterize */
3227 units = NULL((void*)0);
3228 for (i = 0; i < problem->nBodies; i++) {
3229 if (bodies[i].gIndex == 0) continue;
3230 if (units == NULL((void*)0)) {
3231 units = problem->lunits[i];
3232 continue;
3233 }
3234 /* what do we do about units that don't match? */
3235 if (strcmp(problem->lunits[i], units) != 0) {
3236 printf(" CAPS Info: Units don't match for Bound -> %s -- %s %s\n",
3237 bobject->name, problem->lunits[i], units);
3238 }
3239 }
3240 if (bound->lunits != NULL((void*)0)) EG_free(bound->lunits);
3241 bound->geom = NULL((void*)0);
3242 bound->iBody = 0;
3243 bound->iEnt = 0;
3244 bound->state = Multiple;
3245 bound->lunits = EG_strdup(units);
3246 caps_freeBodyObjs(problem->nBodies, bodies);
3247
3248 if (bound->dim == 1) {
3249
3250 stat = CAPS_SUCCESS0;
3251
3252 } else {
3253 stat = caps_paramQuilt(bound, l, line);
3254 if (stat == CAPS_SUCCESS0)
3255 printf(" CAPS Info: Reparameterization Bound -> %s -- nu, nv = %d %d\n",
3256 bobject->name, bound->surface->nus, bound->surface->nvs);
3257 }
3258 if (stat != CAPS_SUCCESS0) bound->state = MultipleError;
3259
3260 return stat;
3261}
3262
3263
3264void
3265caps_geomOutSensit(capsProblem *problem, int ipmtr, int irow, int icol)
3266{
3267 int i, j, k, m, n, len_wrt, i_wrt;
3268 double *reals;
3269 capsValue *value;
3270
3271 for (i = 0; i < problem->nRegGIN; i++) {
3272 if (problem->geomIn[problem->regGIN[i].index-1] == NULL((void*)0)) continue;
3273 value = (capsValue *) problem->geomIn[problem->regGIN[i].index-1]->blind;
3274 if (value == NULL((void*)0)) continue;
3275 if (value->pIndex != ipmtr) continue;
3276 if (problem->regGIN[i].irow != irow && problem->regGIN[i].irow > 0) continue;
3277 if (problem->regGIN[i].icol != icol && problem->regGIN[i].icol > 0) continue;
3278
3279 if ((problem->regGIN[i].irow == 0) &&
3280 (problem->regGIN[i].icol == 0))
3281 i_wrt = value->ncol*(irow-1) + (icol-1);
3282 else
3283 i_wrt = 0;
3284
3285 for (j = 0; j < problem->nGeomOut; j++) {
3286 if (problem->geomOut[j] == NULL((void*)0)) continue;
3287 value = (capsValue *) problem->geomOut[j]->blind;
3288 if (value == NULL((void*)0)) continue;
3289 if (value->derivs == NULL((void*)0)) continue;
3290
3291 len_wrt = value->derivs[i].len_wrt;
3292 if (value->derivs[i].deriv == NULL((void*)0))
3293 value->derivs[i].deriv = (double *) EG_alloc(value->length*len_wrt*sizeof(double));
3294 if (value->derivs[i].deriv == NULL((void*)0)) continue;
3295
3296 reals = value->vals.reals;
3297 if (value->length == 1) reals = &value->vals.real;
3298 for (n = k = 0; k < value->nrow; k++)
3299 for (m = 0; m < value->ncol; m++, n++)
3300 ocsmGetValu(problem->modl, value->pIndex, k+1, m+1,
3301 &reals[n], &value->derivs[i].deriv[len_wrt*n + i_wrt]);
3302 }
3303 }
3304}
3305
3306
3307int
3308caps_transferLinks(capsAnalysis *analysis, int *nErr, capsErrs **errors)
3309{
3310 int i, status;
3311 char temp[PATH_MAX4096];
3312 enum capstMethod method;
3313 capsValue *value;
3314 capsObject *source, *object, *last;
3315
3316 /* fill in any values that have links */
3317 for (i = 0; i < analysis->nAnalysisIn; i++) {
3318 source = object = analysis->analysisIn[i];
3319 do {
3320 if (source->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
3321 if (source->type != VALUE) return CAPS_BADTYPE-306;
3322 if (source->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
3323 value = (capsValue *) source->blind;
3324 if (value->link == object) return CAPS_CIRCULARLINK-319;
3325 last = source;
3326 source = value->link;
3327 } while (value->link != NULL((void*)0));
3328 if (last != object) {
3329 value = (capsValue *) object->blind;
3330 source = value->link;
3331 method = value->linkMethod;
3332 status = caps_transferValueX(last, method, object, nErr, errors);
3333 value->link = source;
3334 value->linkMethod = method;
3335 if (status != CAPS_SUCCESS0) {
3336 snprintf(temp, PATH_MAX4096, "transferValues for %s from %s = %d",
3337 object->name, source->name, status);
3338 caps_makeSimpleErr(object, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
3339 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
3340 return status;
3341 }
3342 caps_freeOwner(&object->last);
3343 object->last = last->last;
3344 object->last.pname = EG_strdup(last->last.pname);
3345 object->last.pID = EG_strdup(last->last.pID);
3346 object->last.user = EG_strdup(last->last.user);
3347 }
3348 }
3349
3350 return CAPS_SUCCESS0;
3351}
3352
3353
3354static int
3355caps_refillBound(capsProblem *problem, capsObject *bobject,
3356 int *nErr, capsErrs **errors)
3357{
3358 int i, j, k, m, n, irow, icol, status, len, outLevel;
3359 int buildTo, builtTo, nbody, open;
3360 char name[129], error[129], *str, **names, **ntmp;
3361 capsValue *value;
3362 capsAnalysis *anal;
3363 capsObject *dobject;
3364 capsBound *bound;
3365 capsVertexSet *vertexset;
3366 capsDataSet *dataset;
3367 capsDiscr *discr;
3368 capsErrs *errs;
3369 modl_T *MODL;
3370
3371 /* invalidate/cleanup any geometry dependencies & remake the bound */
3372 bound = (capsBound *) bobject->blind;
3373 caps_Aprx1DFree(bound->curve); bound->curve = NULL((void*)0);
3374 caps_Aprx2DFree(bound->surface); bound->surface = NULL((void*)0);
3375
3376 for (j = 0; j < bound->nVertexSet; j++) {
3377 if (bound->vertexSet[j] == NULL((void*)0)) continue;
3378 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) continue;
3379 if (bound->vertexSet[j]->type != VERTEXSET) continue;
3380 if (bound->vertexSet[j]->blind == NULL((void*)0)) continue;
3381 vertexset = (capsVertexSet *) bound->vertexSet[j]->blind;
3382
3383 /* remove existing DataSets in the VertexSet */
3384 for (k = 0; k < vertexset->nDataSets; k++) {
3385 if (vertexset->dataSets[k] == NULL((void*)0)) continue;
3386 if (vertexset->dataSets[k]->magicnumber != CAPSMAGIC1234321) continue;
3387 if (vertexset->dataSets[k]->type != DATASET) continue;
3388 if (vertexset->dataSets[k]->blind == NULL((void*)0)) continue;
3389 dobject = vertexset->dataSets[k];
3390 dataset = (capsDataSet *) dobject->blind;
3391 if ((dataset->ftype == User) &&
3392 (strcmp(dobject->name, "xyz") == 0)) continue;
3393 if (dataset->data != NULL((void*)0)) EG_free(dataset->data);
3394 dataset->npts = 0;
3395 dataset->data = NULL((void*)0);
3396 }
3397
3398 if (vertexset->analysis != NULL((void*)0)) {
3399 if (vertexset->analysis->blind != NULL((void*)0)) {
3400 anal = (capsAnalysis *) vertexset->analysis->blind;
3401 aim_FreeDiscr(problem->aimFPTR, anal->loadName, vertexset->discr);
3402
3403 /* fill in any values that have links */
3404 status = caps_transferLinks(anal, nErr, errors);
3405 if (status != CAPS_SUCCESS0) return status;
3406
3407 status = aim_Discr(problem->aimFPTR, anal->loadName,
3408 bobject->name, vertexset->discr);
3409 if (status != CAPS_SUCCESS0) {
3410 aim_FreeDiscr(problem->aimFPTR, anal->loadName, vertexset->discr);
3411 snprintf(error, 129, "Bound = %s and Analysis = %s",
3412 bobject->name, anal->loadName);
3413 caps_makeSimpleErr(bound->vertexSet[j], CERROR,
3414 "caps_refillBound Error: aimDiscr fails!",
3415 error, NULL((void*)0), errors);
3416 if (*errors != NULL((void*)0)) {
3417 errs = *errors;
3418 *nErr = errs->nError;
3419 }
3420 return status;
3421 }
3422
3423 /* check the validity of the discretization just returned */
3424 status = caps_checkDiscr(vertexset->discr, 129, name);
3425 if (status != CAPS_SUCCESS0) {
3426 snprintf(error, 129, "Bound = %s and Analysis = %s",
3427 bobject->name, anal->loadName);
3428 caps_makeSimpleErr(bound->vertexSet[j], CERROR, name, error,
3429 NULL((void*)0), errors);
3430 if (*errors != NULL((void*)0)) {
3431 errs = *errors;
3432 *nErr = errs->nError;
3433 }
3434 aim_FreeDiscr(problem->aimFPTR, anal->loadName, vertexset->discr);
3435 return status;
3436 }
3437 caps_freeOwner(&bound->vertexSet[j]->last);
3438 bound->vertexSet[j]->last.sNum = problem->sNum;
3439 caps_fillDateTime(bound->vertexSet[j]->last.datetime);
3440 status = caps_writeVertexSet(bound->vertexSet[j]);
3441 if (status != CAPS_SUCCESS0)
3442 printf(" CAPS Warning: caps_writeVertexSet = %d (caps_refillBound)\n",
3443 status);
3444 }
3445 }
3446 }
3447 /* reparameterize the existing bounds (dim=1&2) for multiple entities */
3448 if (bound->dim != 3) {
3449 status = caps_parameterize(problem, bobject, 129, name);
3450 if (status != CAPS_SUCCESS0) {
3451 snprintf(error, 129, "Bound = %s", bobject->name);
3452 caps_makeSimpleErr(bobject, CERROR,
3453 "caps_refillBound: Bound Parameterization fails!",
3454 error, NULL((void*)0), errors);
3455 if (*errors != NULL((void*)0)) {
3456 errs = *errors;
3457 *nErr = errs->nError;
3458 }
3459 return status;
3460 }
3461 }
3462
3463 /* populate any built-in DataSet entries after the parameterization */
3464 for (j = 0; j < bound->nVertexSet; j++) {
3465 if (bound->vertexSet[j] == NULL((void*)0)) continue;
3466 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) continue;
3467 if (bound->vertexSet[j]->type != VERTEXSET) continue;
3468 if (bound->vertexSet[j]->blind == NULL((void*)0)) continue;
3469 vertexset = (capsVertexSet *) bound->vertexSet[j]->blind;
3470 for (k = 0; k < vertexset->nDataSets; k++) {
3471 if (vertexset->dataSets[k] == NULL((void*)0)) continue;
3472 if (vertexset->dataSets[k]->magicnumber != CAPSMAGIC1234321) continue;
3473 if (vertexset->dataSets[k]->type != DATASET) continue;
3474 if (vertexset->dataSets[k]->blind == NULL((void*)0)) continue;
3475 dataset = (capsDataSet *) vertexset->dataSets[k]->blind;
3476 if (dataset->ftype != BuiltIn) continue;
3477 caps_fillBuiltIn(bobject, vertexset->discr, vertexset->dataSets[k],
3478 problem->sNum);
3479 }
3480 }
3481
3482 caps_freeOwner(&bobject->last);
3483 bobject->last.sNum = problem->sNum;
3484 caps_fillDateTime(bobject->last.datetime);
3485 status = caps_writeBound(bobject);
3486 if (status != CAPS_SUCCESS0)
3487 printf(" CAPS Warning: caps_writeBound = %d (caps_refillBound)\n", status);
3488
3489 /* populate any sensitivities in DataSets */
3490 names = NULL((void*)0);
3491 for (n = j = 0; j < bound->nVertexSet; j++) {
3492 if (bound->vertexSet[j] == NULL((void*)0)) continue;
3493 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) continue;
3494 if (bound->vertexSet[j]->type != VERTEXSET) continue;
3495 if (bound->vertexSet[j]->blind == NULL((void*)0)) continue;
3496 vertexset = (capsVertexSet *) bound->vertexSet[j]->blind;
3497 if (vertexset->analysis == NULL((void*)0)) continue;
3498 if (vertexset->discr == NULL((void*)0)) continue;
3499 discr = vertexset->discr;
3500 if (discr->nPoints == 0) continue;
3501 if (discr->dim == 3) continue;
3502 for (k = 0; k < vertexset->nDataSets; k++) {
3503 if (vertexset->dataSets[k] == NULL((void*)0)) continue;
3504 if (vertexset->dataSets[k]->magicnumber != CAPSMAGIC1234321) continue;
3505 if (vertexset->dataSets[k]->type != DATASET) continue;
3506 if (vertexset->dataSets[k]->blind == NULL((void*)0)) continue;
3507 dataset = (capsDataSet *) vertexset->dataSets[k]->blind;
3508 if ((dataset->ftype != GeomSens) &&
3509 (dataset->ftype != TessSens)) continue;
3510 if (vertexset->dataSets[k]->last.sNum >=
3511 problem->geometry.sNum) continue;
3512 if (names == NULL((void*)0)) {
3513 names = (char **) EG_alloc(sizeof(char *));
3514 if (names == NULL((void*)0)) continue;
3515 names[0] = vertexset->dataSets[k]->name;
3516 n++;
3517 } else {
3518 for (m = 0; m < n; m++)
3519 if (strcmp(names[m], vertexset->dataSets[k]->name) == 0) break;
3520 if (m == n) {
3521 ntmp = (char **) EG_reall(names, (n+1)*sizeof(char *));
3522 if (ntmp == NULL((void*)0)) continue;
3523 names = ntmp;
3524 names[n] = vertexset->dataSets[k]->name;
3525 n++;
3526 }
3527 }
3528 }
3529 }
3530 if (names != NULL((void*)0)) {
3531
3532 /* go through the list of sensitivity names */
3533 for (m = 0; m < n; m++) {
3534 irow = icol = 1;
3535 open = 0;
3536 str = EG_strdup(names[m]);
3537 if (str == NULL((void*)0)) continue;
3538 len = strlen(str);
3539 for (j = 1; j < len; j++)
3540 if (str[j] == '[') {
3541 open = j;
3542 break;
3543 }
3544 if (open != 0) {
3545 str[open] = 0;
3546 for (i = open+1; i < len; i++)
3547 if (str[i] == ',') str[i] = ' ';
3548 sscanf(&str[open+1], "%d%d\n", &irow, &icol);
3549 }
3550 open = -1;
3551 for (i = 0; i < problem->nGeomIn; i++)
3552 if (strcmp(str,problem->geomIn[i]->name) == 0) {
3553 value = (capsValue *) problem->geomIn[i]->blind;
3554 if (value == NULL((void*)0)) continue;
3555 open = value->pIndex;
3556 break;
3557 }
3558 EG_free(str);
3559 if (open == -1) continue;
3560
3561 /* clear all then set */
3562 status = ocsmSetDtime(problem->modl, 0);
3563 if (status != SUCCESS0) return status;
3564 status = ocsmSetVelD(problem->modl, 0, 0, 0, 0.0);
3565 if (status != SUCCESS0) return status;
3566 status = ocsmSetVelD(problem->modl, open, irow, icol, 1.0);
3567 if (status != SUCCESS0) return status;
3568 buildTo = 0;
3569 nbody = 0;
3570 outLevel = ocsmSetOutLevel(0);
3571 printf(" CAPS Info: Building sensitivity information for: %s[%d,%d]\n", problem->geomIn[i]->name, irow, icol);
3572 status = ocsmBuild(problem->modl, buildTo, &builtTo, &nbody, NULL((void*)0));
3573 ocsmSetOutLevel(outLevel);
3574 printf(" CAPS Info: parameter %d %d %d sensitivity status = %d\n",
3575 open, irow, icol, status);
3576 fflush(stdoutstdout);
3577 if (status != SUCCESS0) continue;
3578 caps_geomOutSensit(problem, open, irow, icol);
3579
3580 for (j = 0; j < bound->nVertexSet; j++) {
3581 if (bound->vertexSet[j] == NULL((void*)0)) continue;
3582 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) continue;
3583 if (bound->vertexSet[j]->type != VERTEXSET) continue;
3584 if (bound->vertexSet[j]->blind == NULL((void*)0)) continue;
3585 vertexset = (capsVertexSet *) bound->vertexSet[j]->blind;
3586 if (vertexset->analysis == NULL((void*)0)) continue;
3587 if (vertexset->discr == NULL((void*)0)) continue;
3588 discr = vertexset->discr;
3589 if (discr->nPoints == 0) continue;
3590 if (discr->dim == 3) continue;
3591 for (k = 0; k < vertexset->nDataSets; k++) {
3592 if (vertexset->dataSets[k] == NULL((void*)0)) continue;
3593 if (vertexset->dataSets[k]->magicnumber != CAPSMAGIC1234321) continue;
3594 if (vertexset->dataSets[k]->type != DATASET) continue;
3595 if (vertexset->dataSets[k]->blind == NULL((void*)0)) continue;
3596 dobject = vertexset->dataSets[k];
3597 dataset = (capsDataSet *) dobject->blind;
3598 if ((dataset->ftype != GeomSens) &&
3599 (dataset->ftype != TessSens)) continue;
3600 if (vertexset->dataSets[k]->last.sNum >=
3601 problem->geometry.sNum) continue;
3602 if (strcmp(names[m],dobject->name) != 0) continue;
3603 dataset->data = (double *)
3604 EG_alloc(3*discr->nPoints*sizeof(double));
3605 if (dataset->data == NULL((void*)0)) continue;
3606 caps_fillSensit(problem, discr, dataset);
3607 dataset->npts = discr->nPoints;
3608/*
3609 OK = 1;
3610 if (dobject->last.sNum != 0) {
3611 if (dataset->history == NULL) {
3612 dataset->nHist = 0;
3613 dataset->history = (capsOwn *) EG_alloc(sizeof(capsOwn));
3614 if (dataset->history == NULL) OK = 0;
3615 } else {
3616 tmp = (capsOwn *) EG_reall( dataset->history,
3617 (dataset->nHist+1)*sizeof(capsOwn));
3618 if (tmp == NULL) {
3619 OK = 0;
3620 } else {
3621 dataset->history = tmp;
3622 }
3623 }
3624 if ((OK == 1) && (dataset->history != NULL)) {
3625 dataset->history[dataset->nHist] = dobject->last;
3626 dataset->history[dataset->nHist].nLines = 0;
3627 dataset->history[dataset->nHist].lines = NULL;
3628 dataset->history[dataset->nHist].pname = EG_strdup(dobject->last.pname);
3629 dataset->history[dataset->nHist].pID = EG_strdup(dobject->last.pID);
3630 dataset->history[dataset->nHist].user = EG_strdup(dobject->last.user);
3631 dataset->nHist += 1;
3632 }
3633 }
3634*/
3635 caps_freeOwner(&dobject->last);
3636 vertexset->dataSets[k]->last.sNum = problem->sNum;
3637 caps_fillDateTime(dobject->last.datetime);
3638 status = caps_writeDataSet(dobject);
3639 if (status != CAPS_SUCCESS0)
3640 printf(" CAPS Warning: caps_writeDataSet = %d (caps_refillBound)\n",
3641 status);
3642 }
3643
3644 MODL = (modl_T *) problem->modl;
3645 if (MODL->dtime != 0)
3646 printf(" CAPS Info: Sensitivity finite difference used for: %s[%d,%d]\n", problem->geomIn[i]->name, irow, icol);
3647 }
3648 }
3649 EG_free(names);
3650 }
3651
3652 return CAPS_SUCCESS0;
3653}
3654
3655
3656static int
3657caps_toktokcmp(const char *str1, const char *str2)
3658{
3659 char copy1[1025], copy2[1025], *word1, *word2, *last1, *last2, sep[3] = " ;";
3660
3661 /* do a token/token compare against 2 strings */
3662 strncpy(copy1, str1, 1024);
3663 copy1[1024] = 0;
3664 word1 = strtok_r(copy1, sep, &last1);
3665 while (word1 != NULL((void*)0)) {
3666 strncpy(copy2, str2, 1024);
3667 copy2[1024] = 0;
3668 word2 = strtok_r(copy2, sep, &last2);
3669 while (word2 != NULL((void*)0)) {
3670 if (strcmp(word2, word1) == 0) return 0;
3671 word2 = strtok_r(NULL((void*)0), sep, &last2);
3672 }
3673 word1 = strtok_r(NULL((void*)0), sep, &last1);
3674 }
3675
3676 return 1;
3677}
3678
3679
3680int
3681caps_filter(capsProblem *problem, capsAnalysis *analysis)
3682{
3683 int i, nBody, alen, atype, status;
3684 ego *bodies;
3685 const int *aints;
3686 const double *areals;
3687 const char *astr;
3688
3689 bodies = (ego *) EG_alloc(problem->nBodies*sizeof(ego));
3690 if (bodies == NULL((void*)0)) return EGADS_MALLOC-4;
3691 for (i = 0; i < problem->nBodies; i++) bodies[i] = NULL((void*)0);
3692
3693 /* do any bodies have our "capsAIM" attribute? */
3694 for (nBody = i = 0; i < problem->nBodies; i++) {
3695 status = EG_attributeRet(problem->bodies[i], "capsAIM", &atype,
3696 &alen, &aints, &areals, &astr);
3697 if (status != EGADS_SUCCESS0) continue;
3698 if (atype != ATTRSTRING3) continue;
3699 if (caps_toktokcmp(analysis->loadName, astr) != 0) continue;
3700 if (analysis->intents != NULL((void*)0)) {
3701 status = EG_attributeRet(problem->bodies[i], "capsIntent", &atype,
3702 &alen, &aints, &areals, &astr);
3703 if (status != EGADS_SUCCESS0) continue;
3704 if (atype != ATTRSTRING3) continue;
3705 if (caps_toktokcmp(analysis->intents, astr) != 0) continue;
3706 }
3707 bodies[nBody] = problem->bodies[i];
3708 nBody++;
3709 }
3710
3711 if (nBody == 0)
3712 if (analysis->intents == NULL((void*)0)) {
3713 printf(" caps_filter Warning: No bodies with capsAIM = %s!\n",
3714 analysis->loadName);
3715 /* print all "capsAIM" attribute */
3716 for (i = 0; i < problem->nBodies; i++) {
3717 status = EG_attributeRet(problem->bodies[i], "capsAIM", &atype,
3718 &alen, &aints, &areals, &astr);
3719 if (status != EGADS_SUCCESS0) continue;
3720 if (atype == ATTRSTRING3)
3721 printf(" Body %d capsAIM = %s\n",i+1, astr);
3722 else
3723 printf(" Body %d capsAIM is not a string\n",i+1);
3724 }
3725 } else {
3726 printf(" caps_filter Warning: No bodies with capsAIM = %s and capsIntent = %s!\n",
3727 analysis->loadName, analysis->intents);
3728 /* print all "capsAIM" and "capsIntent" attribute */
3729 for (i = 0; i < problem->nBodies; i++) {
3730 status = EG_attributeRet(problem->bodies[i], "capsAIM", &atype,
3731 &alen, &aints, &areals, &astr);
3732 if (status == EGADS_SUCCESS0) {
3733 if (atype == ATTRSTRING3)
3734 printf(" Body %d capsAIM = %s\n",i+1, astr);
3735 else
3736 printf(" Body %d capsAIM is not a string\n",i+1);
3737 }
3738 status = EG_attributeRet(problem->bodies[i], "capsIntent", &atype,
3739 &alen, &aints, &areals, &astr);
3740 if (status == EGADS_SUCCESS0) {
3741 if (atype == ATTRSTRING3)
3742 printf(" Body %d capsIntent = %s\n",i+1, astr);
3743 else
3744 printf(" Body %d capsIntent is not a string\n",i+1);
3745 }
3746 }
3747 }
3748 analysis->bodies = bodies;
3749 analysis->nBody = nBody;
3750 return CAPS_SUCCESS0;
3751}
3752
3753
3754int
3755caps_getBodies(capsObject *aobject, int *nBody, ego **bodies,
3756 int *nErr, capsErrs **errors)
3757{
3758 int i, stat, ret, oclass, mtype, *senses;
3759 CAPSLONGunsigned long sNum;
3760 capsObject *pobject;
3761 capsProblem *problem;
3762 capsAnalysis *analysis;
3763 capsJrnl args[3];
3764 ego model, ref, *egos = NULL((void*)0);
3765
3766 *nErr = 0;
3767 *errors = NULL((void*)0);
3768 *nBody = 0;
3769 *bodies = NULL((void*)0);
3770 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
3771 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
3772 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
3773 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
3774 stat = caps_findProblem(aobject, CAPS_GETBODIES41, &pobject);
3775 if (stat != CAPS_SUCCESS0) return stat;
3776 problem = (capsProblem *) pobject->blind;
3777
3778 args[0].type = jEgos;
3779 args[1].type = jInteger;
3780 args[2].type = jErr;
3781 if (problem->dbFlag == 0) {
3782 stat = caps_jrnlRead(CAPS_GETBODIES41, problem, aobject, 3, args, &sNum, &ret);
3783 if (stat == CAPS_JOURNALERR-343) return stat;
3784 if (stat == CAPS_JOURNAL-342) {
3785 *nErr = args[1].members.integer;
3786 *errors = args[2].members.errs;
3787 if (args[0].members.model != NULL((void*)0)) {
3788 i = EG_getTopology(args[0].members.model, &ref, &oclass, &mtype, NULL((void*)0),
3789 nBody, bodies, &senses);
3790 if (i != EGADS_SUCCESS0)
3791 printf(" CAPS Warning: EG_getTopology = %d (caps_getBodies)\n", i);
3792 }
3793 return ret;
3794 }
3795 }
3796
3797 analysis = (capsAnalysis *) aobject->blind;
3798 sNum = problem->sNum;
3799 if ((analysis->bodies == NULL((void*)0)) && (problem->dbFlag == 0)) {
3800 /* make sure geometry is up-to-date */
3801 stat = caps_build(pobject, nErr, errors);
3802 if ((stat != CAPS_SUCCESS0) && (stat != CAPS_CLEAN-336)) goto cleanup;
3803 stat = caps_filter(problem, analysis);
3804 if (stat != CAPS_SUCCESS0) goto cleanup;
3805 }
3806 *nBody = analysis->nBody;
3807 *bodies = analysis->bodies;
3808 if (problem->dbFlag == 1) return CAPS_SUCCESS0;
3809
3810 if ((*nBody == 0) || (*bodies == NULL((void*)0))) {
3811 *nBody = 0;
3812 *bodies = NULL((void*)0);
3813 args[0].members.model = NULL((void*)0);
3814 } else if (*nBody == 1) {
3815 args[0].members.model = *bodies[0];
3816 } else {
3817 egos = (ego *) EG_alloc(*nBody*sizeof(ego));
3818 if (egos == NULL((void*)0)) {
3819 stat = EGADS_MALLOC-4;
3820 goto cleanup;
3821 }
3822 for (i = 0; i < *nBody; i++) {
3823 stat = EG_copyObject((*bodies)[i], NULL((void*)0), &egos[i]);
3824 if (stat != EGADS_SUCCESS0) goto cleanup;
3825 }
3826 stat = EG_makeTopology(problem->context, NULL((void*)0), MODEL26, 0, NULL((void*)0), *nBody,
3827 egos, NULL((void*)0), &model);
3828 if (stat != EGADS_SUCCESS0) {
3829 printf(" CAPS Error: EG_makeTopology %d = %d (caps_getBodies)!\n",
3830 *nBody, stat);
3831 goto cleanup;
3832 }
3833 args[0].members.model = model;
3834 }
3835 stat = CAPS_SUCCESS0;
3836
3837cleanup:
3838 args[1].members.integer = *nErr;
3839 args[2].members.errs = *errors;
3840 caps_jrnlWrite(CAPS_GETBODIES41, problem, aobject, stat, 3, args, sNum, problem->sNum);
3841
3842 if (egos != NULL((void*)0)) EG_free(egos);
3843
3844 return stat;
3845}
3846
3847
3848int
3849caps_getTessels(capsObject *aobject, int *nTessel, ego **tessels,
3850 int *nErr, capsErrs **errors)
3851{
3852 int i, j, n, npts, stat, ret, oclass, mtype, *senses;
3853 CAPSLONGunsigned long sNum;
3854 capsObject *pobject;
3855 capsProblem *problem;
3856 capsAnalysis *analysis;
3857 capsJrnl args[3];
3858 ego model, ref, *bodies, *egos = NULL((void*)0);
3859
3860 *nErr = 0;
3861 *errors = NULL((void*)0);
3862 *nTessel = 0;
3863 *tessels = NULL((void*)0);
3864 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
3865 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
3866 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
3867 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
3868 stat = caps_findProblem(aobject, CAPS_GETTESSELS53, &pobject);
3869 if (stat != CAPS_SUCCESS0) return stat;
3870 problem = (capsProblem *) pobject->blind;
3871
3872 args[0].type = jEgos;
3873 args[1].type = jInteger;
3874 args[2].type = jErr;
3875 if (problem->dbFlag == 0) {
3876 stat = caps_jrnlRead(CAPS_GETTESSELS53, problem, aobject, 3, args, &sNum, &ret);
3877 if (stat == CAPS_JOURNALERR-343) return stat;
3878 if (stat == CAPS_JOURNAL-342) {
3879 *nErr = args[1].members.integer;
3880 *errors = args[2].members.errs;
3881 if (args[0].members.model != NULL((void*)0)) {
3882 i = EG_getTopology(args[0].members.model, &ref, &oclass, &mtype, NULL((void*)0),
3883 &n, &bodies, &senses);
3884 if (i != EGADS_SUCCESS0)
3885 printf(" CAPS Warning: EG_getTopology = %d (caps_getTessels)\n", i);
3886 if (mtype > n) {
3887 *nTessel = mtype - n;
3888 *tessels = &bodies[n];
3889 }
3890 }
3891 return ret;
3892 }
3893 }
3894
3895 analysis = (capsAnalysis *) aobject->blind;
3896 sNum = problem->sNum;
3897 *nTessel = analysis->nTess;
3898 *tessels = analysis->tess;
3899 if (problem->dbFlag == 1) return CAPS_SUCCESS0;
3900
3901 if (analysis->nTess == 0) {
3902 args[0].members.model = NULL((void*)0);
3903 } else {
3904 /* find all of the referenced bodies */
3905 egos = (ego *) EG_alloc(3*analysis->nTess*sizeof(ego));
3906 if (egos == NULL((void*)0)) {
3907 stat = EGADS_MALLOC-4;
3908 goto cleanup;
3909 }
3910 bodies = &egos[2*analysis->nTess];
3911 for (n = i = 0; i < analysis->nTess; i++) {
3912 stat = EG_statusTessBody(analysis->tess[i], &ref, &j, &npts);
3913 if (stat != EGADS_SUCCESS0) {
3914 printf(" CAPS Error: EG_statusTessBody %d = %d (caps_getTessels)!\n",
3915 i, stat);
3916 goto cleanup;
3917 }
3918 for (j = 0; j < n; j++)
3919 if (bodies[j] == ref) break;
3920 if (j == n) {
3921 bodies[n] = ref;
3922 n++;
3923 }
3924 }
3925
3926 /* copy the body objects */
3927 for (i = 0; i < n; i++) {
3928 stat = EG_copyObject(bodies[i], NULL((void*)0), &egos[i]);
3929 if (stat != EGADS_SUCCESS0) {
3930 for (j = 0; j < i; j++) EG_deleteObject(egos[j]);
3931 goto cleanup;
3932 }
3933 }
3934 /* copy the tessellation objects*/
3935 for (i = 0; i < analysis->nTess; i++) {
3936 stat = EG_statusTessBody(analysis->tess[i], &ref, &j, &npts);
3937 if (stat != EGADS_SUCCESS0) {
3938 printf(" CAPS Error: EG_statusTessBody %d = %d (caps_getTessels)!\n",
3939 i, stat);
3940 for (j = 0; j < n+i; j++) EG_deleteObject(egos[j]);
3941 goto cleanup;
3942 }
3943 for (j = 0; j < n; j++)
3944 if (bodies[j] == ref) break;
3945 if (j == n) {
3946 stat = EGADS_NOTFOUND-1;
3947 printf(" CAPS Error: Cannot find Body %d (caps_getTessels)!\n", i);
3948 for (j = 0; j < n+i; j++) EG_deleteObject(egos[j]);
3949 goto cleanup;
3950 }
3951 stat = EG_copyObject(analysis->tess[i], egos[j], &egos[n+i]);
3952 if (stat != EGADS_SUCCESS0) {
3953 for (j = 0; j < n+i; j++) EG_deleteObject(egos[j]);
3954 goto cleanup;
3955 }
3956 }
3957 /* make the model */
3958 stat = EG_makeTopology(problem->context, NULL((void*)0), MODEL26, analysis->nTess+n,
3959 NULL((void*)0), n, egos, NULL((void*)0), &model);
3960 if (stat != EGADS_SUCCESS0) {
3961 printf(" CAPS Error: EG_makeTopology %d = %d (caps_getTessels)!\n",
3962 analysis->nTess+n, stat);
3963 for (j = 0; j < analysis->nTess+n; j++) EG_deleteObject(egos[j]);
3964 goto cleanup;
3965 }
3966 args[0].members.model = model;
3967 }
3968 stat = CAPS_SUCCESS0;
3969
3970cleanup:
3971 args[1].members.integer = *nErr;
3972 args[2].members.errs = *errors;
3973 caps_jrnlWrite(CAPS_GETTESSELS53, problem, aobject, stat, 3, args, sNum, problem->sNum);
3974
3975 if (egos != NULL((void*)0)) EG_free(egos);
3976
3977 return stat;
3978}
3979
3980
3981static int
3982caps_preAnalysiX(capsObject *aobject, int *nErr, capsErrs **errors)
3983{
3984 int i, j, k, npts, rank, stat, status, gstatus;
3985 double *data;
3986 char *units;
3987 int majorX, minorX, nFieldX, execX, dirtyX;
3988 int *ranksX, *fInOutX;
3989 char *intentsX, *apathX, *unitSysX, **fnamesX;
3990 CAPSLONGunsigned long sn;
3991 capsValue *valIn, *value;
3992 capsProblem *problem;
3993 capsAnalysis *analysis;
3994 capsBound *bound;
3995 capsVertexSet *vertexset;
3996 capsDataSet *dataset;
3997 capsObject *pobject, *source, *object, *last;
3998
3999 analysis = NULL((void*)0);
4000 valIn = NULL((void*)0);
4001 if (aobject->type == PROBLEM) {
4002 pobject = aobject;
4003 problem = (capsProblem *) pobject->blind;
4004 } else {
4005 analysis = (capsAnalysis *) aobject->blind;
4006 pobject = (capsObject *) aobject->parent;
4007 problem = (capsProblem *) pobject->blind;
4008 valIn = (capsValue *) analysis->analysisIn[0]->blind;
4009 }
4010
4011 /* make sure geometry is up-to-date */
4012 gstatus = caps_build(pobject, nErr, errors);
4013 if (analysis == NULL((void*)0)) {
4014 if (gstatus == CAPS_CLEAN-336) return CAPS_CLEAN-336;
4015 if (problem->nBodies == 0)
4016 printf(" caps_preAnalysis Warning: No bodies generated!\n");
4017 return CAPS_SUCCESS0;
4018 }
4019 if ((gstatus != CAPS_SUCCESS0) && (gstatus != CAPS_CLEAN-336)) return gstatus;
4020
4021 /* are we "analysis" clean? */
4022 status = 0;
4023 if (analysis != NULL((void*)0)) {
4024 if (analysis->pre.sNum == 0) {
4025 status = 1;
4026 } else {
4027 /* check for dirty analysis inputs */
4028 for (i = 0; i < analysis->nAnalysisIn; i++) {
4029 source = object = analysis->analysisIn[i];
4030 do {
4031 if (source->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4032 if (source->type != VALUE) return CAPS_BADTYPE-306;
4033 if (source->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4034 value = (capsValue *) source->blind;
4035 if (value->link == object) return CAPS_CIRCULARLINK-319;
4036 last = source;
4037 source = value->link;
4038 } while (value->link != NULL((void*)0));
4039 if (last->last.sNum > analysis->pre.sNum) {
4040 status = 1;
4041 break;
4042 }
4043 /* if the value is linked, check the state of the linked parent */
4044 if (last != object) {
4045 stat = caps_analysisInfX(last->parent, &apathX, &unitSysX, &majorX, &minorX,
4046 &intentsX, &nFieldX, &fnamesX, &ranksX, &fInOutX,
4047 &execX, &dirtyX);
4048 if (dirtyX > 0) {
4049 status = 1;
4050 break;
4051 }
4052 }
4053 }
4054 if (status == 0) {
4055 stat = caps_snDataSets(aobject, 1, &sn);
4056 if (stat == CAPS_SUCCESS0)
4057 if (sn > analysis->pre.sNum) status = 1;
4058 }
4059 }
4060 if ((status == 0) && (gstatus == CAPS_CLEAN-336) &&
4061 (problem->geometry.sNum < analysis->pre.sNum)) return CAPS_CLEAN-336;
4062
4063 /* fill in any values that have links */
4064 stat = caps_transferLinks(analysis, nErr, errors);
4065 if (stat != CAPS_SUCCESS0) return stat;
4066 }
4067
4068 if ((problem->nBodies <= 0) || (problem->bodies == NULL((void*)0))) {
4069 printf(" caps_preAnalysis Warning: No bodies to %s!\n", analysis->loadName);
4070 if (analysis->bodies != NULL((void*)0)) EG_free(analysis->bodies);
4071 analysis->bodies = NULL((void*)0);
4072 analysis->nBody = 0;
4073 } else if (analysis->bodies == NULL((void*)0)) {
4074 stat = caps_filter(problem, analysis);
4075 if (stat != CAPS_SUCCESS0) return stat;
4076 }
4077
4078 /* do we need to fill FieldIn datasets? */
4079 for (i = 0; i < problem->nBound; i++) {
4080 if (problem->bounds[i] == NULL((void*)0)) return CAPS_NULLOBJ-309;
4081 if (problem->bounds[i]->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4082 if (problem->bounds[i]->type != BOUND) return CAPS_BADTYPE-306;
4083 if (problem->bounds[i]->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4084 bound = (capsBound *) problem->bounds[i]->blind;
4085 for (j = 0; j < bound->nVertexSet; j++) {
4086 if (bound->vertexSet[j] == NULL((void*)0)) return CAPS_NULLOBJ-309;
4087 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4088 if (bound->vertexSet[j]->type != VERTEXSET) return CAPS_BADTYPE-306;
4089 if (bound->vertexSet[j]->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4090 vertexset = (capsVertexSet *) bound->vertexSet[j]->blind;
4091 if (vertexset->analysis != aobject) continue;
4092 for (k = 0; k < vertexset->nDataSets; k++) {
4093 if (vertexset->dataSets[k] == NULL((void*)0)) return CAPS_NULLOBJ-309;
4094 if (vertexset->dataSets[k]->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4095 if (vertexset->dataSets[k]->type != DATASET) return CAPS_BADTYPE-306;
4096 if (vertexset->dataSets[k]->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4097 dataset = (capsDataSet *) vertexset->dataSets[k]->blind;
4098 if (dataset->ftype != FieldIn) continue;
4099 stat = caps_getDataX(vertexset->dataSets[k], &npts, &rank, &data,
4100 &units, nErr, errors);
4101 if (stat != CAPS_SUCCESS0) return stat;
4102 }
4103 }
4104 }
4105
4106 /* do it! */
4107 stat = aim_PreAnalysis(problem->aimFPTR, analysis->loadName,
4108 analysis->instStore, &analysis->info, valIn);
4109 caps_getAIMerrs(analysis, nErr, errors);
4110 if (stat == CAPS_SUCCESS0) {
4111 caps_freeValueObjects(1, analysis->nAnalysisDynO, analysis->analysisDynO);
4112 analysis->analysisDynO = NULL((void*)0);
4113 analysis->nAnalysisDynO = 0;
4114 caps_freeOwner(&analysis->pre);
4115 problem->sNum += 1;
4116 analysis->pre.sNum = problem->sNum;
4117 caps_fillDateTime(analysis->pre.datetime);
4118 stat = caps_dumpAnalysis(problem, aobject);
4119 if (stat != CAPS_SUCCESS0)
4120 printf(" CAPS Error: caps_dumpAnalysis = %d (caps_preAnalysis)\n",
4121 stat);
4122 }
4123
4124 return stat;
4125}
4126
4127
4128static int
4129caps_preAnalysiZ(capsObject *aobject, int *nErr, capsErrs **errors)
4130{
4131 int stat, ret;
4132 CAPSLONGunsigned long sNum;
4133 capsProblem *problem;
4134 capsAnalysis *analysis;
4135 capsObject *pobject;
4136 capsJrnl args[2];
4137
4138 *nErr = 0;
4139 *errors = NULL((void*)0);
4140 analysis = NULL((void*)0);
4141 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4142 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4143 if (aobject->type == PROBLEM) {
4144 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4145 pobject = aobject;
4146 problem = (capsProblem *) pobject->blind;
4147 } else {
4148 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
4149 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4150 analysis = (capsAnalysis *) aobject->blind;
4151 if (aobject->parent == NULL((void*)0)) return CAPS_NULLOBJ-309;
4152 pobject = (capsObject *) aobject->parent;
4153 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4154 problem = (capsProblem *) pobject->blind;
4155 if (analysis->analysisIn[0]->blind == NULL((void*)0)) return CAPS_NULLVALUE-307;
4156 }
4157
4158 args[0].type = jInteger;
4159 args[1].type = jErr;
4160 stat = caps_jrnlRead(CAPS_PREANALYSIS48, problem, aobject, 2, args, &sNum, &ret);
4161 if (stat == CAPS_JOURNALERR-343) return stat;
4162 if (stat == CAPS_JOURNAL-342) {
4163 *nErr = args[0].members.integer;
4164 *errors = args[1].members.errs;
4165 return ret;
4166 }
4167
4168 ret = caps_preAnalysiX(aobject, nErr, errors);
4169 *nErr = 0;
4170 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4171
4172 args[0].members.integer = *nErr;
4173 args[1].members.errs = *errors;
4174 caps_jrnlWrite(CAPS_PREANALYSIS48, problem, aobject, ret, 2, args, sNum, problem->sNum);
4175
4176 return ret;
4177}
4178
4179
4180int
4181caps_preAnalysis(capsObject *aobject, int *nErr, capsErrs **errors)
4182{
4183 char temp[PATH_MAX4096];
4184 capsAnalysis *analysis;
4185 capsProblem *problem;
4186 capsObject *pobject;
4187
4188 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4189 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4190 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
4191 pobject = (capsObject *) aobject->parent;
4192 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4193 problem = (capsProblem *) pobject->blind;
4194 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
4195
4196 analysis = (capsAnalysis *) aobject->blind;
4197 if ((analysis->autoexec == 1) &&
4198 (analysis->eFlag == 1)) {
4199 snprintf(temp, PATH_MAX4096, "Cannot call preAnalysis with AIM that auto-executes!");
4200 caps_makeSimpleErr(aobject, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
4201 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4202 return CAPS_EXECERR-335;
4203 }
4204
4205 return caps_preAnalysiZ(aobject, nErr, errors);
4206}
4207
4208
4209static int
4210caps_boundDependent(capsProblem *problem, capsObject *aobject,
4211 capsObject *oobject)
4212{
4213 int i, j, jj, k, kk;
4214 capsBound *bound;
4215 capsVertexSet *vs, *vso;
4216 capsDataSet *ds, *dso;
4217
4218 for (i = 0; i < problem->nBound; i++) {
4219 if (problem->bounds[i] == NULL((void*)0)) continue;
4220 if (problem->bounds[i]->magicnumber != CAPSMAGIC1234321) continue;
4221 if (problem->bounds[i]->type != BOUND) continue;
4222 if (problem->bounds[i]->blind == NULL((void*)0)) continue;
4223 bound = (capsBound *) problem->bounds[i]->blind;
4224 for (j = 0; j < bound->nVertexSet; j++) {
4225 if (bound->vertexSet[j] == NULL((void*)0)) continue;
4226 if (bound->vertexSet[j]->magicnumber != CAPSMAGIC1234321) continue;
4227 if (bound->vertexSet[j]->type != VERTEXSET) continue;
4228 if (bound->vertexSet[j]->blind == NULL((void*)0)) continue;
4229 vs = (capsVertexSet *) bound->vertexSet[j]->blind;
4230 if (vs->analysis != aobject) continue;
4231 for (k = 0; k < vs->nDataSets; k++) {
4232 if (vs->dataSets[k] == NULL((void*)0)) continue;
4233 if (vs->dataSets[k]->magicnumber != CAPSMAGIC1234321) continue;
4234 if (vs->dataSets[k]->type != DATASET) continue;
4235 if (vs->dataSets[k]->blind == NULL((void*)0)) continue;
4236 ds = (capsDataSet *) vs->dataSets[k]->blind;
4237 if (ds->ftype != FieldIn) continue;
4238 for (jj = 0; jj < bound->nVertexSet; jj++) {
4239 if (j == jj) continue;
4240 if (bound->vertexSet[jj] == NULL((void*)0)) continue;
4241 if (bound->vertexSet[jj]->magicnumber != CAPSMAGIC1234321) continue;
4242 if (bound->vertexSet[jj]->type != VERTEXSET) continue;
4243 if (bound->vertexSet[jj]->blind == NULL((void*)0)) continue;
4244 vso = (capsVertexSet *) bound->vertexSet[jj]->blind;
4245 if (vso->analysis != oobject) continue;
4246 for (kk = 0; kk < vso->nDataSets; kk++) {
4247 if (vso->dataSets[kk] == NULL((void*)0)) continue;
4248 if (vso->dataSets[kk]->magicnumber != CAPSMAGIC1234321) continue;
4249 if (vso->dataSets[kk]->type != DATASET) continue;
4250 if (vso->dataSets[kk]->blind == NULL((void*)0)) continue;
4251 dso = (capsDataSet *) vso->dataSets[kk]->blind;
4252 if (dso->ftype != FieldOut) continue;
4253 if (strcmp(vs->dataSets[k]->name,vso->dataSets[kk]->name) == 0)
4254 return CAPS_SUCCESS0;
4255 }
4256 }
4257 }
4258 }
4259 }
4260
4261 return CAPS_NOTFOUND-303;
4262}
4263
4264
4265int
4266caps_postAnalysiX(capsObject *aobject, int *nErr, capsErrs **errors)
4267{
4268 int i, major, minor, nField, *ranks, *fInOut, status, exec, dirty;
4269 char *intents, *apath, *unitSys, **fnames;
4270 capsProblem *problem;
4271 capsAnalysis *analysis;
4272 capsValue *valIn = NULL((void*)0);
4273 capsObject *pobject;
4274
4275 analysis = (capsAnalysis *) aobject->blind;
4276 pobject = (capsObject *) aobject->parent;
4277 problem = (capsProblem *) pobject->blind;
4278
4279 /* check to see if we need to do post */
4280 status = caps_analysisInfX(aobject, &apath, &unitSys, &major, &minor, &intents,
4281 &nField, &fnames, &ranks, &fInOut, &exec, &dirty);
4282 if (status != CAPS_SUCCESS0) return status;
4283 if (dirty == 0) return CAPS_CLEAN-336;
4284 if (dirty < 5) return CAPS_DIRTY-327;
4285
4286 if (analysis->nAnalysisIn > 0)
4287 valIn = (capsValue *) analysis->analysisIn[0]->blind;
4288
4289 /* call post in the AIM */
4290 analysis->info.inPost = 1;
4291 status = aim_PostAnalysis(problem->aimFPTR, analysis->loadName,
4292 analysis->instStore, &analysis->info, 0, valIn);
4293 analysis->info.inPost = 0;
4294 caps_getAIMerrs(analysis, nErr, errors);
4295 if (status != CAPS_SUCCESS0) {
4296 caps_freeValueObjects(1, analysis->nAnalysisDynO, analysis->analysisDynO);
4297 analysis->analysisDynO = NULL((void*)0);
4298 analysis->nAnalysisDynO = 0;
4299 return status;
4300 }
4301
4302 /* set the time/date stamp */
4303 caps_freeOwner(&aobject->last);
4304 problem->sNum += 1;
4305 aobject->last.sNum = problem->sNum;
4306 caps_fillDateTime(aobject->last.datetime);
4307 for (i = 0; i < analysis->nAnalysisDynO; i++) {
4308 analysis->analysisDynO[i]->last.sNum = problem->sNum;
4309 caps_fillDateTime(analysis->analysisDynO[i]->last.datetime);
4310 }
4311 status = caps_dumpAnalysis(problem, aobject);
4312 if (status != CAPS_SUCCESS0)
4313 printf(" CAPS Error: caps_dumpAnalysis = %d (caps_postAnalysis)\n", status);
4314
4315 return status;
4316}
4317
4318
4319static int
4320caps_postAnalysiZ(capsObject *aobject, int *nErr, capsErrs **errors)
4321{
4322 int stat, ret;
4323 CAPSLONGunsigned long sNum;
4324 capsProblem *problem;
4325 capsObject *pobject;
4326 capsJrnl args[2];
4327
4328 *nErr = 0;
4329 *errors = NULL((void*)0);
4330 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4331 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4332 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
4333 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4334 if (aobject->parent == NULL((void*)0)) return CAPS_NULLOBJ-309;
4335 pobject = (capsObject *) aobject->parent;
4336 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4337 problem = (capsProblem *) pobject->blind;
4338
4339 args[0].type = jInteger;
4340 args[1].type = jErr;
4341 stat = caps_jrnlRead(CAPS_POSTANALYSIS51, problem, aobject, 2, args, &sNum, &ret);
4342 if (stat == CAPS_JOURNALERR-343) return stat;
4343 if (stat == CAPS_JOURNAL-342) {
4344 *nErr = args[0].members.integer;
4345 *errors = args[1].members.errs;
4346 return ret;
4347 }
4348
4349 sNum = problem->sNum;
4350 ret = caps_postAnalysiX(aobject, nErr, errors);
4351 args[0].members.integer = *nErr;
4352 args[1].members.errs = *errors;
4353 caps_jrnlWrite(CAPS_POSTANALYSIS51, problem, aobject, ret, 2, args, sNum, problem->sNum);
4354
4355 return ret;
4356}
4357
4358
4359int
4360caps_postAnalysis(capsObject *aobject, int *nErr, capsErrs **errors)
4361{
4362 char temp[PATH_MAX4096];
4363 capsAnalysis *analysis;
4364 capsProblem *problem;
4365 capsObject *pobject;
4366
4367 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4368 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4369 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
4370 pobject = (capsObject *) aobject->parent;
4371 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4372 problem = (capsProblem *) pobject->blind;
4373 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
4374
4375 analysis = (capsAnalysis *) aobject->blind;
4376 if ((analysis->autoexec == 1) &&
4377 (analysis->eFlag == 1)) {
4378 snprintf(temp, PATH_MAX4096, "Cannot call postAnalysis with AIM that auto-executes!");
4379 caps_makeSimpleErr(aobject, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
4380 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4381 return CAPS_EXECERR-335;
4382 }
4383
4384 return caps_postAnalysiZ(aobject, nErr, errors);
4385}
4386
4387
4388int
4389caps_buildBound(capsObject *bobject, int *nErr, capsErrs **errors)
4390{
4391 int i, j, ia, it, stat, found = 0, dirty = 0;
4392 char temp[PATH_MAX4096];
4393 capsObject *pobject;
4394 capsProblem *problem;
4395 capsBound *bound;
4396 capsAnalysis *analysis, *anal;
4397 capsVertexSet *vs;
4398 ego tess;
4399
4400 *nErr = 0;
4401 *errors = NULL((void*)0);
4402 if (bobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4403 if (bobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4404 if (bobject->type != BOUND) return CAPS_BADTYPE-306;
4405 if (bobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4406 bound = (capsBound *) bobject->blind;
4407 if (bound->state == Open) return CAPS_STATEERR-329;
4408 pobject = bobject->parent;
4409 if (pobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4410 if (pobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4411 if (pobject->type != PROBLEM) return CAPS_BADTYPE-306;
4412 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4413 problem = (capsProblem *) pobject->blind;
4414 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
4415
4416 if (bound->state == Open) {
4417 snprintf(temp, PATH_MAX4096, "Bound '%s' is Open (caps_buildBound)!",
4418 bobject->name);
4419 caps_makeSimpleErr(bobject, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
4420 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4421 return CAPS_DIRTY-327;
4422 }
4423
4424 stat = caps_build(pobject, nErr, errors);
4425 if ((stat != CAPS_CLEAN-336) && (stat != CAPS_SUCCESS0)) return stat;
4426
4427 if (bobject->last.sNum < problem->geometry.sNum) dirty = 1;
4428
4429 for (i = 0; i < bound->nVertexSet; i++) {
4430 if (bound->vertexSet[i] == NULL((void*)0)) continue;
4431 if (bound->vertexSet[i]->magicnumber != CAPSMAGIC1234321) continue;
4432 if (bound->vertexSet[i]->type != VERTEXSET) continue;
4433 if (bound->vertexSet[i]->blind == NULL((void*)0)) continue;
4434 vs = (capsVertexSet *) bound->vertexSet[i]->blind;
4435 analysis = (capsAnalysis *) vs->analysis->blind;
4436 if (analysis == NULL((void*)0)) continue;
4437 if (analysis->bodies == NULL((void*)0)) {
4438 stat = caps_filter(problem, analysis);
4439 if (stat != CAPS_SUCCESS0) {
4440 snprintf(temp, PATH_MAX4096, "caps_filter = %d (caps_buildBound)!", stat);
4441 caps_makeSimpleErr(bobject, CERROR, temp, NULL((void*)0), NULL((void*)0), errors);
4442 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4443 return stat;
4444 }
4445 dirty = 1;
4446 }
4447 if (vs->discr == NULL((void*)0)) {
4448 dirty = 1;
4449 continue;
4450 }
4451
4452 /* if the discr tessellation object is not found (or is EMPTY)
4453 then it has been replaced and the VertexSet needs to be updated */
4454 for (j = 0; j < vs->discr->nBodys; j++) {
4455 tess = vs->discr->bodys[j].tess;
4456 if (tess == NULL((void*)0) ) { dirty = 1; continue; }
4457 if (tess->oclass == EMPTY4) { dirty = 1; continue; }
4458 found = 0;
4459 for (ia = 0; ia < problem->nAnalysis && found == 0; ia++) {
4460 anal = (capsAnalysis *) problem->analysis[ia]->blind;
4461 for (it = 0; it < anal->nTess; it++) {
4462 if ( tess == anal->tess[it] ) {
4463 found = 1;
4464 break;
4465 }
4466 }
4467 }
4468 if (found == 0) dirty = 1;
4469 }
4470 }
4471
4472 if (dirty == 0) return CAPS_SUCCESS0;
4473
4474 stat = caps_refillBound(problem, bobject, nErr, errors);
4475 if (stat != CAPS_SUCCESS0) return stat;
4476 stat = caps_writeBound(bobject);
4477 if (stat != CAPS_SUCCESS0)
4478 printf(" CAPS Warning: caps_writeBound = %d (caps_buildBound)\n", stat);
4479
4480 problem->sNum += 1;
4481 stat = caps_writeProblem(pobject);
4482 if (stat != CAPS_SUCCESS0)
4483 printf(" CAPS Warning: caps_writeProblem = %d (caps_buildBound)\n",
4484 stat);
4485
4486 return stat;
4487}
4488
4489
4490static void
4491caps_orderAnalyses(int nAobj, /*@null@*/ capsObject **aobjs)
4492{
4493 int i, hit;
4494 capsObject *aobj;
4495
4496 if ((nAobj <= 1) || (aobjs == NULL((void*)0))) return;
4497
4498 do {
4499 for (hit = i = 0; i < nAobj-1; i++) {
4500 if (aobjs[i]->last.sNum > aobjs[i+1]->last.sNum) {
4501 aobj = aobjs[i];
4502 aobjs[i] = aobjs[i+1];
4503 aobjs[i+1] = aobj;
4504 hit++;
4505 }
4506 }
4507 } while (hit != 0);
4508
4509}
4510
4511
4512static int
4513caps_dirtyAnalysiX(capsObject *object, capsProblem *problem,
4514 int *nAobj, capsObject ***aobjs)
4515{
4516 int i, j, execute, major, minor, nField, *ranks, *fInOut;
4517 int stat, dirty;
4518 char *intents, *apath, *unitSys, **fnames;
4519 capsBound *bound;
4520 capsVertexSet *vertexset;
4521 capsAnalysis *analysis;
4522 capsObject *aobject, *source, *start, *last;
4523 capsValue *value;
4524
4525 *nAobj = 0;
4526 *aobjs = NULL((void*)0);
4527 if (object == NULL((void*)0)) return CAPS_NULLOBJ-309;
4528 if (object->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4529 if ((object->type != PROBLEM) && (object->type != ANALYSIS) &&
4530 (object->type != BOUND)) return CAPS_BADTYPE-306;
4531 if (object->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4532
4533 if (object->type == PROBLEM) {
4534 if (problem->nAnalysis == 0) return CAPS_SUCCESS0;
4535
4536 for (i = 0; i < problem->nAnalysis; i++) {
4537 stat = caps_analysisInfX(problem->analysis[i], &apath, &unitSys, &major,
4538 &minor, &intents, &nField, &fnames, &ranks,
4539 &fInOut, &execute, &dirty);
4540 if (stat != CAPS_SUCCESS0) {
4541 if (*aobjs != NULL((void*)0)) {
4542 EG_free(*aobjs);
4543 *nAobj = 0;
4544 *aobjs = NULL((void*)0);
4545 }
4546 return stat;
4547 }
4548 if (dirty == 0) continue;
4549 if (*aobjs == NULL((void*)0)) {
4550 *aobjs = (capsObject **)
4551 EG_alloc(problem->nAnalysis*sizeof(capsObject *));
4552 if (*aobjs == NULL((void*)0)) return EGADS_MALLOC-4;
4553 }
4554 (*aobjs)[*nAobj] = problem->analysis[i];
4555 *nAobj += 1;
4556 }
4557
4558 } else if (object->type == BOUND) {
4559
4560 /* for Bound Objects -- find dependent Analysis Objects */
4561 bound = (capsBound *) object->blind;
4562 for (i = 0; i < bound->nVertexSet; i++) {
4563 if (bound->vertexSet[i] == NULL((void*)0)) continue;
4564 if (bound->vertexSet[i]->magicnumber != CAPSMAGIC1234321) continue;
4565 if (bound->vertexSet[i]->type != VERTEXSET) continue;
4566 if (bound->vertexSet[i]->blind == NULL((void*)0)) continue;
4567 vertexset = (capsVertexSet *) bound->vertexSet[i]->blind;
4568 aobject = vertexset->analysis;
4569 if (aobject == NULL((void*)0)) continue;
4570 stat = caps_analysisInfX(aobject, &apath, &unitSys, &major, &minor,
4571 &intents, &nField, &fnames, &ranks, &fInOut,
4572 &execute, &dirty);
4573 if (stat != CAPS_SUCCESS0) {
4574 if (*aobjs != NULL((void*)0)) {
4575 EG_free(*aobjs);
4576 *nAobj = 0;
4577 *aobjs = NULL((void*)0);
4578 }
4579 return stat;
4580 }
4581 if (dirty == 0) continue;
4582 if (*aobjs == NULL((void*)0)) {
4583 *aobjs = (capsObject **)
4584 EG_alloc(problem->nAnalysis*sizeof(capsObject *));
4585 if (*aobjs == NULL((void*)0)) return EGADS_MALLOC-4;
4586 }
4587 for (j = 0; j < *nAobj; j++)
4588 if (aobject == (*aobjs)[j]) break;
4589 if (j != *nAobj) continue;
4590 (*aobjs)[*nAobj] = aobject;
4591 *nAobj += 1;
4592 }
4593
4594 } else {
4595
4596 /* for Analysis Objects -- find dependent Analysis Objects in Bounds */
4597 for (i = 0; i < problem->nAnalysis; i++) {
4598 if (problem->analysis[i] == object) continue;
4599 stat = caps_boundDependent(problem, object, problem->analysis[i]);
4600 if (stat != CAPS_SUCCESS0) continue;
4601 stat = caps_analysisInfX(problem->analysis[i], &apath, &unitSys, &major,
4602 &minor, &intents, &nField, &fnames, &ranks,
4603 &fInOut, &execute, &dirty);
4604 if (stat != CAPS_SUCCESS0) {
4605 if (*aobjs != NULL((void*)0)) {
4606 EG_free(*aobjs);
4607 *nAobj = 0;
4608 *aobjs = NULL((void*)0);
4609 }
4610 return stat;
4611 }
4612 if (dirty == 0) continue;
4613 if (*aobjs == NULL((void*)0)) {
4614 *aobjs = (capsObject **)
4615 EG_alloc(problem->nAnalysis*sizeof(capsObject *));
4616 if (*aobjs == NULL((void*)0)) return EGADS_MALLOC-4;
4617 }
4618 (*aobjs)[*nAobj] = problem->analysis[i];
4619 *nAobj += 1;
4620 }
4621 /* now find dependent Analysis Objects in Links */
4622 analysis = (capsAnalysis *) object->blind;
4623 for (i = 0; i < analysis->nAnalysisIn; i++) {
4624 source = start = analysis->analysisIn[i];
4625 do {
4626 if (source->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4627 if (source->type != VALUE) return CAPS_BADTYPE-306;
4628 if (source->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4629 value = (capsValue *) source->blind;
4630 if (value->link == start) return CAPS_CIRCULARLINK-319;
4631 last = source;
4632 source = value->link;
4633 } while (value->link != NULL((void*)0));
4634 /* reject GeomOuts and save the Analysis Objects for AnalyOuts */
4635 source = last->parent;
4636 if ((source->type != ANALYSIS) || (source == object)) continue;
4637 stat = caps_analysisInfX(source, &apath, &unitSys, &major, &minor,
4638 &intents, &nField, &fnames, &ranks, &fInOut,
4639 &execute, &dirty);
4640 if (stat != CAPS_SUCCESS0) {
4641 if (*aobjs != NULL((void*)0)) {
4642 EG_free(*aobjs);
4643 *nAobj = 0;
4644 *aobjs = NULL((void*)0);
4645 }
4646 return stat;
4647 }
4648 if (dirty == 0) continue;
4649 if (*aobjs != NULL((void*)0)) {
4650 for (j = 0; j < *nAobj; j++)
4651 if ((*aobjs)[j] == source) break;
4652 } else {
4653 j = 0;
4654 }
4655 if (j == *nAobj) {
4656 if (*aobjs == NULL((void*)0)) {
4657 *aobjs = (capsObject **)
4658 EG_alloc(problem->nAnalysis*sizeof(capsObject *));
4659 if (*aobjs == NULL((void*)0)) return EGADS_MALLOC-4;
4660 }
4661 (*aobjs)[*nAobj] = source;
4662 *nAobj += 1;
4663 }
4664 }
4665 }
4666
4667 caps_orderAnalyses(*nAobj, *aobjs);
4668
4669 return CAPS_SUCCESS0;
4670}
4671
4672
4673int
4674caps_dirtyAnalysis(capsObject *object, int *nAobj, capsObject ***aobjs)
4675{
4676 int i, ret, stat;
4677 CAPSLONGunsigned long sNum;
4678 capsProblem *problem;
4679 capsObject *pobject, **objs;
4680 capsJrnl args[1];
4681
4682 *nAobj = 0;
4683 *aobjs = NULL((void*)0);
4684 if (object == NULL((void*)0)) return CAPS_NULLOBJ-309;
4685 if (object->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4686 if ((object->type != PROBLEM) && (object->type != ANALYSIS) &&
4687 (object->type != BOUND)) return CAPS_BADTYPE-306;
4688 if (object->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4689 stat = caps_findProblem(object, CAPS_DIRTYANALYSIS46, &pobject);
4690 if (stat != CAPS_SUCCESS0) return stat;
4691 problem = (capsProblem *) pobject->blind;
4692
4693 args[0].type = jObjs;
4694 if (problem->dbFlag == 0) {
4695 stat = caps_jrnlRead(CAPS_DIRTYANALYSIS46, problem, object, 1, args, &sNum, &ret);
4696 if (stat == CAPS_JOURNALERR-343) return stat;
4697 if (stat == CAPS_JOURNAL-342) {
4698 *nAobj = args[0].num;
4699 if (*nAobj != 0) {
4700 objs = (capsObject **) EG_alloc(*nAobj*sizeof(capsObject *));
4701 if (objs == NULL((void*)0)) return EGADS_MALLOC-4;
4702 for (i = 0; i < *nAobj; i++) objs[i] = args[0].members.objs[i];
4703 *aobjs = objs;
4704 }
4705 return ret;
4706 }
4707 }
4708
4709 sNum = problem->sNum;
4710 ret = caps_dirtyAnalysiX(object, problem, nAobj, aobjs);
4711 if (problem->dbFlag == 1) return ret;
4712
4713 args[0].num = *nAobj;
4714 args[0].members.objs = *aobjs;
4715 caps_jrnlWrite(CAPS_DIRTYANALYSIS46, problem, object, ret, 1, args, sNum, problem->sNum);
4716
4717 return ret;
4718}
4719
4720
4721static int
4722caps_runAnalysis(capsObject *aobject, int *stat, int *nErr, capsErrs **errors)
4723{
4724 int status;
4725 capsObject *pobject;
4726 capsProblem *problem;
4727 capsAnalysis *analysis;
4728
4729 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4730 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4731 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
4732 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4733 analysis = (capsAnalysis *) aobject->blind;
4734 status = caps_findProblem(aobject, CAPS_RUNANALYSIS49, &pobject);
4735 if (status != CAPS_SUCCESS0) return status;
4736 problem = (capsProblem *) pobject->blind;
4737 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
4738
4739 /* ignore if restarting
4740 if (problem->stFlag == CAPS_JOURNALERR) return CAPS_JOURNALERR;
4741 if (problem->stFlag == 4) return CAPS_SUCCESS; */
4742
4743 /* call the AIM */
4744 status = aim_Execute(problem->aimFPTR, analysis->loadName,
4745 analysis->instStore, &analysis->info, stat);
4746 caps_getAIMerrs(analysis, nErr, errors);
4747 if (status != CAPS_SUCCESS0) return status;
4748
4749 return CAPS_SUCCESS0;
4750}
4751
4752
4753#ifdef ASYNCEXEC
4754int
4755caps_checkAnalysis(capsObject *aobject, int *phase, int *nErr, capsErrs **errors)
4756{
4757 int status;
4758 capsObject *pobject;
4759 capsProblem *problem;
4760 capsAnalysis *analysis;
4761
4762 if (nErr == NULL((void*)0)) return CAPS_NULLVALUE-307;
4763 if (errors == NULL((void*)0)) return CAPS_NULLVALUE-307;
4764 *phase = 0;
4765 *nErr = 0;
4766 *errors = NULL((void*)0);
4767 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4768 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4769 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
4770 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4771 analysis = (capsAnalysis *) aobject->blind;
4772 status = caps_findProblem(aobject, CAPS_CHECKANALYSIS50, &pobject);
4773 if (status != CAPS_SUCCESS0) return status;
4774 problem = (capsProblem *) pobject->blind;
4775
4776 /* ignore if restarting */
4777 if (problem->stFlag == CAPS_JOURNALERR-343) return CAPS_JOURNALERR-343;
4778 if (problem->stFlag == 4) {
4779 status = caps_jrnlEnd(problem);
4780 if (status != CAPS_CLEAN-336) return CAPS_SUCCESS0;
4781 }
4782
4783 /* call the AIM */
4784 status = aim_Check(problem->aimFPTR, analysis->loadName,
4785 analysis->instStore, &analysis->info, phase);
4786 caps_getAIMerrs(analysis, nErr, errors);
4787 if (status != CAPS_SUCCESS0) return status;
4788
4789 return CAPS_SUCCESS0;
4790}
4791#endif
4792
4793
4794int
4795caps_execute(capsObject *object, int *state, int *nErr, capsErrs **errors)
4796{
4797 int stat;
4798 capsErrs *errs = NULL((void*)0);
4799 capsAnalysis *analysis;
4800 capsObject *pobject;
4801 capsProblem *problem;
4802
4803 if (nErr == NULL((void*)0)) return CAPS_NULLVALUE-307;
4804 if (errors == NULL((void*)0)) return CAPS_NULLVALUE-307;
4805 *state = 0;
4806 *nErr = 0;
4807 *errors = NULL((void*)0);
4808 pobject = object;
4809 if (object == NULL((void*)0)) return CAPS_NULLOBJ-309;
4810 if (object->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4811 if ((object->type != PROBLEM) &&
4812 (object->type != ANALYSIS)) return CAPS_BADTYPE-306;
4813 if (object->type == ANALYSIS) {
4814 if (object->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4815 analysis = (capsAnalysis *) object->blind;
4816 if (analysis->eFlag != 1) return CAPS_EXECERR-335;
4817 pobject = (capsObject *) object->parent;
4818 }
4819 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4820 problem = (capsProblem *) pobject->blind;
4821 if (problem->dbFlag == 1) return CAPS_READONLYERR-315;
4822
4823 /* perform pre, exec, post -- use individual journaling */
4824 stat = caps_preAnalysiZ(object, nErr, errors);
4825 if (stat != CAPS_SUCCESS0) return stat;
4826 if (object->type == PROBLEM) return CAPS_SUCCESS0;
4827 if (*nErr != 0) {
4828 errs = *errors;
4829 *nErr = 0;
4830 *errors = NULL((void*)0);
4831 }
4832
4833 stat = caps_runAnalysis(object, state, nErr, errors);
4834 caps_concatErrs(errs, errors);
4835 if (stat != CAPS_SUCCESS0) {
4836 *nErr = 0;
4837 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4838 return stat;
4839 }
4840 if (*nErr != 0) {
4841 errs = *errors;
4842 *nErr = 0;
4843 *errors = NULL((void*)0);
4844 }
4845
4846 stat = caps_postAnalysiZ(object, nErr, errors);
4847 caps_concatErrs(errs, errors);
4848 *nErr = 0;
4849 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4850 return stat;
4851}
4852
4853
4854int
4855caps_execX(capsObject *aobject, int *nErr, capsErrs **errors)
4856{
4857 int i, stat, state;
4858 capsErrs *errs = NULL((void*)0);
4859 capsObject *pobject, **tmp;
4860 capsAnalysis *analysis;
4861 capsProblem *problem;
4862
4863 if (nErr == NULL((void*)0)) return CAPS_NULLVALUE-307;
4864 if (errors == NULL((void*)0)) return CAPS_NULLVALUE-307;
4865 if (*nErr != 0) errs = *errors;
4866
4867 if (aobject == NULL((void*)0)) return CAPS_NULLOBJ-309;
4868 if (aobject->magicnumber != CAPSMAGIC1234321) return CAPS_BADOBJECT-310;
4869 if (aobject->type != ANALYSIS) return CAPS_BADTYPE-306;
4870 if (aobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4871 analysis = (capsAnalysis *) aobject->blind;
4872 if (analysis->autoexec != 1) return CAPS_EXECERR-335;
4873 pobject = (capsObject *) aobject->parent;
4874 if (pobject->blind == NULL((void*)0)) return CAPS_NULLBLIND-321;
4875 problem = (capsProblem *) pobject->blind;
4876
4877 /* perform pre, exec, post -- no journaling! */
4878 stat = caps_preAnalysiX(aobject, nErr, errors);
4879 caps_concatErrs(errs, errors);
4880 if (stat != CAPS_SUCCESS0) {
4881 *nErr = 0;
4882 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4883 return stat;
4884 }
4885 if (*nErr != 0) {
4886 errs = *errors;
4887 *nErr = 0;
4888 *errors = NULL((void*)0);
4889 }
4890
4891 /* call the AIM to execute */
4892 stat = aim_Execute(problem->aimFPTR, analysis->loadName,
4893 analysis->instStore, &analysis->info, &state);
4894 caps_getAIMerrs(analysis, nErr, errors);
4895 caps_concatErrs(errs, errors);
4896 if (stat != CAPS_SUCCESS0) {
4897 *nErr = 0;
4898 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4899 return stat;
4900 }
4901 if (*nErr != 0) {
4902 errs = *errors;
4903 *nErr = 0;
4904 *errors = NULL((void*)0);
4905 }
4906
4907 stat = caps_postAnalysiX(aobject, nErr, errors);
4908 caps_concatErrs(errs, errors);
4909 if (stat != CAPS_SUCCESS0) {
4910 *nErr = 0;
4911 if (*errors != NULL((void*)0)) *nErr = (*errors)->nError;
4912 return stat;
4913 }
4914
4915 /* add this object to our list of executed AIMs */
4916 for (i = 0; i < problem->nExec; i++)
4917 if (problem->execs[i] == aobject) {
4918 printf(" CAPS Info: Analysis already in list %d (caps_execX)\n", i);
4919 return CAPS_SUCCESS0;
4920 }
4921 if ((problem->nExec == 0) || (problem->execs == NULL((void*)0))) {
4922 tmp = (capsObject **) EG_alloc(sizeof(capsObject *));
4923 problem->nExec = 0;
4924 } else {
4925 tmp = (capsObject **) EG_reall( problem->execs,
4926 (problem->nExec+1)*sizeof(capsObject *));
4927 }
4928 if (tmp == NULL((void*)0)) {
4929 printf(" CAPS Info: MALLOC on storing Analysis execution (caps_execX)\n");
4930 return CAPS_SUCCESS0;
4931 }
4932 problem->execs = tmp;
4933 problem->execs[problem->nExec] = aobject;
4934 problem->nExec++;
4935
4936 return CAPS_SUCCESS0;
4937}