File: | fun3d/fun3dUtils.c |
Warning: | line 137, column 9 Value stored to 'status' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | // This software has been cleared for public release on 05 Nov 2020, case number 88ABW-2020-3462. |
2 | |
3 | #include <string.h> |
4 | #include <stdio.h> |
5 | #include <errno(*__errno_location ()).h> |
6 | #include <ctype.h> |
7 | |
8 | #include "egads.h" // Bring in egads utilss |
9 | #include "capsTypes.h" // Bring in CAPS types |
10 | #include "aimUtil.h" // Bring in AIM utils |
11 | #include "aimMesh.h" // Bring in AIM meshing |
12 | |
13 | #include "miscUtils.h" // Bring in misc. utility functions |
14 | #include "meshUtils.h" // Bring in meshing utility functions |
15 | #include "cfdTypes.h" // Bring in cfd specific types |
16 | #include "cfdUtils.h" |
17 | #include "tecplotUtils.h" // Bring in tecplot utility functions |
18 | #include "fun3dUtils.h" // Bring in fun3d utility header |
19 | #include "fun3dInputs.h" |
20 | #include "ugridWriter.h" |
21 | |
22 | |
23 | #ifdef WIN32 |
24 | #define strcasecmp stricmp |
25 | #define strncasecmp _strnicmp |
26 | #endif |
27 | |
28 | |
29 | // Extract the FEPOINT Tecoplot data from a FUN3D Aero-Loads file (connectivity is ignored) - dataMatrix = [numVariable][numDataPoint] |
30 | int fun3d_readAeroLoad(void *aimInfo, char *filename, int *numVariable, char **variableName[], |
31 | int *numDataPoint, double ***dataMatrix) |
32 | { |
33 | |
34 | int status = CAPS_SUCCESS0; // Function return |
35 | int i, j; // Indexing |
36 | |
37 | size_t linecap = 0; |
38 | |
39 | char *line = NULL((void*)0); // Temporary line holder |
40 | char *tempStr = NULL((void*)0), *tempStr2 = NULL((void*)0); // Temporary strings |
41 | int stringLen = 0; // Length of string holder |
42 | |
43 | FILE *fp = NULL((void*)0); // File pointer |
44 | |
45 | // Open file |
46 | fp = aim_fopen(aimInfo, filename, "r"); |
47 | if (fp == NULL((void*)0)) { |
48 | AIM_ERROR(aimInfo, "Unable to open file: %s\n", filename){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 48, __func__ , "Unable to open file: %s\n", filename); }; |
49 | return CAPS_IOERR-332; |
50 | } |
51 | |
52 | printf("Reading FUN3D AeroLoad File - %s!!!!!!\n", filename); |
53 | |
54 | *numVariable = 0; |
55 | *numDataPoint = 0; |
56 | // Loop through file line by line until we have determined how many variables and data points there are |
57 | while (*numVariable == 0 || *numDataPoint == 0) { |
58 | |
59 | // Get line from file |
60 | status = getline(&line, &linecap, fp); |
61 | if ((status < 0) || (line == NULL((void*)0))) break; |
62 | |
63 | // Get variable list if available in file line |
64 | if (strncmp("variables=", line, strlen("variables=")) == 0) { |
65 | |
66 | // Pull out substring at first occurrence of " |
67 | tempStr = strstr(line, "\""); |
68 | |
69 | // Create a temperory string of the variables in a the folling format - ["a","ae"] |
70 | stringLen = strlen(tempStr)-1 + 2; |
71 | |
72 | tempStr2 = (char *) EG_alloc((stringLen +1)*sizeof(char *)); |
73 | if (tempStr2 == NULL((void*)0)) { |
74 | fclose(fp); |
75 | if (line != NULL((void*)0)) EG_free(line); |
76 | return EGADS_MALLOC-4; |
77 | } |
78 | |
79 | tempStr2[0] = '['; |
80 | strncpy(tempStr2+1, tempStr, strlen(tempStr)-1); |
81 | tempStr2[stringLen-1] = ']'; |
82 | tempStr2[stringLen] = '\0'; |
83 | |
84 | // Sort string into an array of strings |
85 | status = string_toStringDynamicArray(tempStr2, numVariable, variableName); |
86 | |
87 | if (tempStr2 != NULL((void*)0)) EG_free(tempStr2); |
88 | tempStr2 = NULL((void*)0); |
89 | |
90 | if (status != CAPS_SUCCESS0) goto cleanup; |
91 | |
92 | // Print out list of variables found in load file |
93 | printf("Variables found in file %s:\n",filename); |
94 | for (i = 0; i < *numVariable; i++) printf("Variable %d = %s\n", i, (*variableName)[i]); |
95 | } |
96 | |
97 | // Get the number of data points in file if available in file line |
98 | if (strncmp("zone t=", line, strlen("zone t=")) == 0) { |
99 | |
100 | // Pull out substring at first occurrence of i= |
101 | tempStr = strstr(line, "i="); |
102 | |
103 | // Retrieve the i= value |
104 | sscanf(&tempStr[2], "%d", numDataPoint); |
105 | |
106 | // Print out the number of data points found in load file |
107 | printf("Number of data points = %d, in file %s\n", *numDataPoint, filename); |
108 | } |
109 | |
110 | } |
111 | |
112 | if (*numVariable != 0 && *numDataPoint != 0) { |
113 | |
114 | // Allocate dataMatrix array |
115 | AIM_FREE(*dataMatrix){ EG_free(*dataMatrix); *dataMatrix = ((void*)0); }; |
116 | |
117 | AIM_ALLOC(*dataMatrix, (*numVariable), double *, aimInfo, status){ if (*dataMatrix != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 117, __func__, 1, "AIM_ALLOC: %s != NULL" , "*dataMatrix"); goto cleanup; } size_t memorysize = (*numVariable ); *dataMatrix = (double * *) EG_alloc(memorysize*sizeof(double *)); if (*dataMatrix == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 117, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "*dataMatrix", memorysize, "double *"); goto cleanup; } }; |
118 | for (i = 0; i < *numVariable; i++) (*dataMatrix)[i] = NULL((void*)0); |
119 | |
120 | for (i = 0; i < *numVariable; i++) { |
121 | AIM_ALLOC((*dataMatrix)[i], (*numDataPoint), double, aimInfo, status){ if ((*dataMatrix)[i] != ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 121, __func__, 1, "AIM_ALLOC: %s != NULL" , "(*dataMatrix)[i]"); goto cleanup; } size_t memorysize = (* numDataPoint); (*dataMatrix)[i] = (double *) EG_alloc(memorysize *sizeof(double)); if ((*dataMatrix)[i] == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c", 121, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "(*dataMatrix)[i]", memorysize , "double"); goto cleanup; } }; |
122 | } |
123 | |
124 | // Loop through the file and fill up the data matrix |
125 | for (j = 0; j < *numDataPoint; j++) { |
126 | for (i = 0; i < *numVariable; i++) { |
127 | fscanf(fp, "%lf", &(*dataMatrix)[i][j]); |
128 | } |
129 | } |
130 | |
131 | // Output the first row of the dataMatrix |
132 | //for (i = 0; i < *numVariable; i++) printf("Variable %d - %.6f\n", i, (*dataMatrix)[i][0]); |
133 | |
134 | } else { |
135 | |
136 | printf("No data values extracted from file - %s",filename); |
137 | status = CAPS_BADVALUE-311; |
Value stored to 'status' is never read | |
138 | } |
139 | |
140 | status = CAPS_SUCCESS0; |
141 | |
142 | cleanup: |
143 | if (fp != NULL((void*)0)) fclose(fp); |
144 | |
145 | if (status != CAPS_SUCCESS0) { |
146 | if (*dataMatrix != NULL((void*)0)) { |
147 | for (j = 0; j < *numVariable; j++) { |
148 | AIM_FREE((*dataMatrix)[j]){ EG_free((*dataMatrix)[j]); (*dataMatrix)[j] = ((void*)0); }; |
149 | } |
150 | AIM_FREE((*dataMatrix)){ EG_free((*dataMatrix)); (*dataMatrix) = ((void*)0); }; |
151 | } |
152 | } |
153 | |
154 | EG_free(line); |
155 | return status; |
156 | } |
157 | |
158 | |
159 | static int |
160 | fun3d_read2DBinaryUgrid(void *aimInfo, FILE *fp, meshStruct *surfaceMesh) |
161 | { |
162 | int status = CAPS_SUCCESS0; |
163 | |
164 | int numNode, numLine, numTriangle, numQuadrilateral; |
165 | int numTetrahedral, numPyramid, numPrism, numHexahedral; |
166 | int i, elementIndex, numPoint, bcID; |
167 | double *coords = NULL((void*)0); |
168 | |
169 | /* we get a binary UGRID file */ |
170 | status = fread(&numNode, sizeof(int), 1, fp); |
171 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 171, __func__, 0); goto cleanup; }; } |
172 | status = fread(&numTriangle, sizeof(int), 1, fp); |
173 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 173, __func__, 0); goto cleanup; }; } |
174 | status = fread(&numQuadrilateral, sizeof(int), 1, fp); |
175 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 175, __func__, 0); goto cleanup; }; } |
176 | status = fread(&numTetrahedral, sizeof(int), 1, fp); |
177 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 177, __func__, 0); goto cleanup; }; } |
178 | status = fread(&numPyramid, sizeof(int), 1, fp); |
179 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 179, __func__, 0); goto cleanup; }; } |
180 | status = fread(&numPrism, sizeof(int), 1, fp); |
181 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 181, __func__, 0); goto cleanup; }; } |
182 | status = fread(&numHexahedral, sizeof(int), 1, fp); |
183 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 183, __func__, 0); goto cleanup; }; } |
184 | |
185 | if ( numTetrahedral + |
186 | numPyramid + |
187 | numPrism + |
188 | numHexahedral > 0) { |
189 | AIM_ERROR(aimInfo, "Expecting a 2D ugrid file!!!"){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 189, __func__ , "Expecting a 2D ugrid file!!!"); }; |
190 | status = CAPS_IOERR-332; |
191 | goto cleanup; |
192 | } |
193 | |
194 | /* |
195 | printf("\n Header from UGRID file: %d %d %d %d %d %d %d\n", numNode, |
196 | numTriangle, numQuadrilateral, numTetrahedral, numPyramid, numPrism, |
197 | numHexahedral); |
198 | */ |
199 | |
200 | AIM_ALLOC(coords, 3*numNode, double, aimInfo, status){ if (coords != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 200, __func__, 1, "AIM_ALLOC: %s != NULL" , "coords"); goto cleanup; } size_t memorysize = 3*numNode; coords = (double *) EG_alloc(memorysize*sizeof(double)); if (coords == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c" , 200, __func__, 3, "AIM_ALLOC: %s size %zu type %s", "coords" , memorysize, "double"); goto cleanup; } }; |
201 | |
202 | /* read all of the vertices */ |
203 | status = fread(coords, sizeof(double), 3*numNode, fp); |
204 | if (status != 3*numNode) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 204, __func__, 0); goto cleanup; }; } |
205 | |
206 | surfaceMesh->analysisType = UnknownMeshAnalysis; |
207 | |
208 | // Set that this is a volume mesh |
209 | surfaceMesh->meshType = Surface2DMesh; |
210 | |
211 | // Numbers |
212 | surfaceMesh->numNode = numNode; |
213 | surfaceMesh->numElement = numTriangle + numQuadrilateral; |
214 | |
215 | surfaceMesh->meshQuickRef.useStartIndex = (int) true1; |
216 | |
217 | surfaceMesh->meshQuickRef.numTriangle = numTriangle; |
218 | surfaceMesh->meshQuickRef.numQuadrilateral = numQuadrilateral; |
219 | |
220 | // Nodes - allocate |
221 | AIM_ALLOC(surfaceMesh->node, surfaceMesh->numNode, meshNodeStruct, aimInfo, status){ if (surfaceMesh->node != ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 221, __func__, 1, "AIM_ALLOC: %s != NULL" , "surfaceMesh->node"); goto cleanup; } size_t memorysize = surfaceMesh->numNode; surfaceMesh->node = (meshNodeStruct *) EG_alloc(memorysize*sizeof(meshNodeStruct)); if (surfaceMesh ->node == ((void*)0)) { status = -4; aim_status(aimInfo, status , "fun3dUtils.c", 221, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "surfaceMesh->node", memorysize, "meshNodeStruct"); goto cleanup; } }; |
222 | |
223 | // Initialize |
224 | for (i = 0; i < surfaceMesh->numNode; i++) { |
225 | status = initiate_meshNodeStruct(&surfaceMesh->node[i], |
226 | surfaceMesh->analysisType); |
227 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 227, __func__, 0); goto cleanup; }; |
228 | } |
229 | |
230 | // Nodes - set |
231 | for (i = 0; i < surfaceMesh->numNode; i++) { |
232 | |
233 | // Copy node data |
234 | surfaceMesh->node[i].nodeID = i+1; |
235 | |
236 | surfaceMesh->node[i].xyz[0] = coords[3*i+0]; |
237 | surfaceMesh->node[i].xyz[1] = coords[3*i+1]; |
238 | surfaceMesh->node[i].xyz[2] = coords[3*i+2]; |
239 | } |
240 | AIM_FREE(coords){ EG_free(coords); coords = ((void*)0); }; |
241 | |
242 | // Elements - allocate |
243 | AIM_ALLOC(surfaceMesh->element, surfaceMesh->numElement, meshElementStruct, aimInfo, status){ if (surfaceMesh->element != ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 243, __func__, 1, "AIM_ALLOC: %s != NULL" , "surfaceMesh->element"); goto cleanup; } size_t memorysize = surfaceMesh->numElement; surfaceMesh->element = (meshElementStruct *) EG_alloc(memorysize*sizeof(meshElementStruct)); if (surfaceMesh ->element == ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 243, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "surfaceMesh->element", memorysize, "meshElementStruct") ; goto cleanup; } }; |
244 | |
245 | // Initialize |
246 | for (i = 0; i < surfaceMesh->numElement; i++ ) { |
247 | status = initiate_meshElementStruct(&surfaceMesh->element[i], |
248 | surfaceMesh->analysisType); |
249 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 249, __func__, 0); goto cleanup; }; |
250 | } |
251 | |
252 | // Start of element index |
253 | elementIndex = 0; |
254 | |
255 | // Elements -Set triangles |
256 | if (numTriangle > 0) |
257 | surfaceMesh->meshQuickRef.startIndexTriangle = elementIndex; |
258 | |
259 | numPoint = mesh_numMeshConnectivity(Triangle); |
260 | for (i = 0; i < numTriangle; i++) { |
261 | |
262 | surfaceMesh->element[elementIndex].elementType = Triangle; |
263 | surfaceMesh->element[elementIndex].elementID = elementIndex+1; |
264 | |
265 | status = mesh_allocMeshElementConnectivity(&surfaceMesh->element[elementIndex]); |
266 | if (status != CAPS_SUCCESS0) goto cleanup; |
267 | |
268 | // read the element connectivity |
269 | status = fread(surfaceMesh->element[elementIndex].connectivity, |
270 | sizeof(int), numPoint, fp); |
271 | if (status != numPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 271, __func__, 0); goto cleanup; }; } |
272 | |
273 | elementIndex += 1; |
274 | } |
275 | |
276 | // Elements -Set quadrilateral |
277 | if (numQuadrilateral > 0) |
278 | surfaceMesh->meshQuickRef.startIndexQuadrilateral = elementIndex; |
279 | |
280 | numPoint = mesh_numMeshConnectivity(Quadrilateral); |
281 | for (i = 0; i < numQuadrilateral; i++) { |
282 | |
283 | surfaceMesh->element[elementIndex].elementType = Quadrilateral; |
284 | surfaceMesh->element[elementIndex].elementID = elementIndex+1; |
285 | |
286 | status = mesh_allocMeshElementConnectivity(&surfaceMesh->element[elementIndex]); |
287 | if (status != CAPS_SUCCESS0) goto cleanup; |
288 | |
289 | // read the element connectivity |
290 | status = fread(surfaceMesh->element[elementIndex].connectivity, |
291 | sizeof(int), numPoint, fp); |
292 | if (status != numPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 292, __func__, 0); goto cleanup; }; } |
293 | |
294 | elementIndex += 1; |
295 | } |
296 | |
297 | // skip face ID section of the file |
298 | status = fseek(fp, (numTriangle + numQuadrilateral)*sizeof(int), SEEK_CUR1); |
299 | if (status != 0) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 299, __func__, 0); goto cleanup; }; } |
300 | |
301 | // Get the number of Line elements |
302 | status = fread(&numLine, sizeof(int), 1, fp); |
303 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 303, __func__, 0); goto cleanup; }; } |
304 | |
305 | // Elements - re-allocate with Line elements |
306 | surfaceMesh->meshQuickRef.numLine = numLine; |
307 | AIM_REALL(surfaceMesh->element, surfaceMesh->numElement+numLine, meshElementStruct, aimInfo, status){ size_t memorysize = surfaceMesh->numElement+numLine; surfaceMesh ->element = (meshElementStruct *) EG_reall(surfaceMesh-> element, memorysize*sizeof(meshElementStruct)); if (surfaceMesh ->element == ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 307, __func__, 3, "AIM_REALL: %s size %zu type %s" , "surfaceMesh->element", memorysize, "meshElementStruct") ; goto cleanup; } }; |
308 | |
309 | surfaceMesh->meshQuickRef.startIndexLine = elementIndex; |
310 | |
311 | // Initialize |
312 | for (i = surfaceMesh->numElement; i < surfaceMesh->numElement+numLine; i++ ) { |
313 | status = initiate_meshElementStruct(&surfaceMesh->element[i], |
314 | surfaceMesh->analysisType); |
315 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 315, __func__, 0); goto cleanup; }; |
316 | } |
317 | surfaceMesh->numElement += numLine; |
318 | |
319 | numPoint = mesh_numMeshConnectivity(Line); |
320 | for (i = 0; i < numLine; i++) { |
321 | |
322 | surfaceMesh->element[elementIndex].elementType = Line; |
323 | surfaceMesh->element[elementIndex].elementID = elementIndex+1; |
324 | |
325 | status = mesh_allocMeshElementConnectivity(&surfaceMesh->element[elementIndex]); |
326 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 326, __func__, 0); goto cleanup; }; |
327 | |
328 | // read the element connectivity |
329 | status = fread(surfaceMesh->element[elementIndex].connectivity, |
330 | sizeof(int), numPoint, fp); |
331 | if (status != numPoint) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 331, __func__, 0); goto cleanup; }; } |
332 | status = fread(&bcID, sizeof(int), 1, fp); |
333 | if (status != 1) { status = CAPS_IOERR-332; AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 333, __func__, 0); goto cleanup; }; } |
334 | |
335 | surfaceMesh->element[elementIndex].markerID = bcID; |
336 | |
337 | elementIndex += 1; |
338 | } |
339 | |
340 | status = CAPS_SUCCESS0; |
341 | |
342 | cleanup: |
343 | if (status != CAPS_SUCCESS0) |
344 | printf("Premature exit in getUGRID status = %d\n", status); |
345 | |
346 | EG_free(coords); coords = NULL((void*)0); |
347 | |
348 | return status; |
349 | } |
350 | |
351 | |
352 | // Create a 3D BC for FUN3D from a 2D mesh |
353 | int fun3d_2DBC(void *aimInfo, |
354 | cfdBoundaryConditionStruct *bcProps) |
355 | { |
356 | int status; // Function return status |
357 | |
358 | int i; // Indexing |
359 | |
360 | int faceBCIndex = -1, extrusionBCIndex = -1; |
361 | |
362 | // Find the faceBCIndex for the symmetry plane |
363 | for (i = 0; i < bcProps->numSurfaceProp-1; i++) { |
364 | if (bcProps->surfaceProp[i].surfaceType == Symmetry) { |
365 | faceBCIndex = bcProps->surfaceProp[i].bcID; |
366 | break; |
367 | } |
368 | } |
369 | |
370 | if (faceBCIndex == -1) { |
371 | // Add plane boundary condition |
372 | AIM_REALL(bcProps->surfaceProp, bcProps->numSurfaceProp+1, cfdSurfaceStruct, aimInfo, status){ size_t memorysize = bcProps->numSurfaceProp+1; bcProps-> surfaceProp = (cfdSurfaceStruct *) EG_reall(bcProps->surfaceProp , memorysize*sizeof(cfdSurfaceStruct)); if (bcProps->surfaceProp == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c" , 372, __func__, 3, "AIM_REALL: %s size %zu type %s", "bcProps->surfaceProp" , memorysize, "cfdSurfaceStruct"); goto cleanup; } }; |
373 | bcProps->numSurfaceProp += 1; |
374 | |
375 | status = initiate_cfdSurfaceStruct(&bcProps->surfaceProp[bcProps->numSurfaceProp-1]); |
376 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 376, __func__, 0); goto cleanup; }; |
377 | |
378 | bcProps->surfaceProp[bcProps->numSurfaceProp-1].surfaceType = Symmetry; |
379 | bcProps->surfaceProp[bcProps->numSurfaceProp-1].symmetryPlane = 1; |
380 | |
381 | // Find largest index value for bcID and set it plus 1 to the new surfaceProp |
382 | for (i = 0; i < bcProps->numSurfaceProp-1; i++) { |
383 | if (bcProps->surfaceProp[i].bcID >= faceBCIndex) { |
384 | faceBCIndex = bcProps->surfaceProp[i].bcID + 1; |
385 | } |
386 | } |
387 | bcProps->surfaceProp[bcProps->numSurfaceProp-1].bcID = faceBCIndex; |
388 | } |
389 | |
390 | |
391 | // Add extruded plane boundary condition |
392 | AIM_REALL(bcProps->surfaceProp, bcProps->numSurfaceProp+1, cfdSurfaceStruct, aimInfo, status){ size_t memorysize = bcProps->numSurfaceProp+1; bcProps-> surfaceProp = (cfdSurfaceStruct *) EG_reall(bcProps->surfaceProp , memorysize*sizeof(cfdSurfaceStruct)); if (bcProps->surfaceProp == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c" , 392, __func__, 3, "AIM_REALL: %s size %zu type %s", "bcProps->surfaceProp" , memorysize, "cfdSurfaceStruct"); goto cleanup; } }; |
393 | bcProps->numSurfaceProp += 1; |
394 | |
395 | status = initiate_cfdSurfaceStruct(&bcProps->surfaceProp[bcProps->numSurfaceProp-1]); |
396 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 396, __func__, 0); goto cleanup; }; |
397 | |
398 | bcProps->surfaceProp[bcProps->numSurfaceProp-1].surfaceType = Symmetry; |
399 | bcProps->surfaceProp[bcProps->numSurfaceProp-1].symmetryPlane = 2; |
400 | |
401 | // Find largest index value for bcID and set it plus 1 to the new surfaceProp |
402 | for (i = 0; i < bcProps->numSurfaceProp-1; i++) { |
403 | if (bcProps->surfaceProp[i].bcID >= extrusionBCIndex) { |
404 | extrusionBCIndex = bcProps->surfaceProp[i].bcID + 1; |
405 | } |
406 | } |
407 | bcProps->surfaceProp[bcProps->numSurfaceProp-1].bcID = extrusionBCIndex; |
408 | |
409 | status = CAPS_SUCCESS0; |
410 | |
411 | cleanup: |
412 | return status; |
413 | } |
414 | |
415 | |
416 | // Create a 3D mesh for FUN3D from a 2D mesh |
417 | int fun3d_2DMesh(void *aimInfo, |
418 | aimMeshRef *meshRef, |
419 | const char *projectName, |
420 | const mapAttrToIndexStruct *groupMap) |
421 | { |
422 | |
423 | int status; // Function return status |
424 | |
425 | int i; // Indexing |
426 | |
427 | int faceBCIndex = -1, extrusionBCIndex = -1; |
428 | |
429 | double extrusion = -1.0; // Extrusion length |
430 | |
431 | // Flip coordinates |
432 | int xMeshConstant = (int) true1, yMeshConstant = (int) true1, zMeshConstant= (int) true1; // 2D mesh checks |
433 | double tempCoord; |
434 | |
435 | meshStruct surfaceMesh; |
436 | meshStruct volumeMesh; |
437 | |
438 | char filename[PATH_MAX4096]; |
439 | // int elementIndex; |
440 | FILE *fp = NULL((void*)0); |
441 | |
442 | status = initiate_meshStruct(&surfaceMesh); |
443 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 443, __func__, 0); goto cleanup; }; |
444 | |
445 | status = initiate_meshStruct(&volumeMesh); |
446 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 446, __func__, 0); goto cleanup; }; |
447 | |
448 | snprintf(filename, PATH_MAX4096, "%s%s", meshRef->fileName, MESHEXTENSION".lb8.ugrid"); |
449 | |
450 | fp = fopen(filename, "rb"); |
451 | if (fp == NULL((void*)0)) { |
452 | AIM_ERROR(aimInfo, "Cannot open file: %s\n", filename){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 452, __func__ , "Cannot open file: %s\n", filename); }; |
453 | status = CAPS_IOERR-332; |
454 | goto cleanup; |
455 | } |
456 | |
457 | status = fun3d_read2DBinaryUgrid(aimInfo, fp, &surfaceMesh); |
458 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 458, __func__, 0); goto cleanup; }; |
459 | |
460 | // add boundary elements if they are missing |
461 | if (surfaceMesh.meshQuickRef.numLine == 0) { |
462 | status = mesh_addTess2Dbc(aimInfo, &surfaceMesh, groupMap); |
463 | if (status != CAPS_SUCCESS0) goto cleanup; |
464 | } |
465 | |
466 | // Set the symmetry index for all Tri/Quad |
467 | for (i = 0; i < surfaceMesh.numElement; i++) { |
468 | |
469 | if (surfaceMesh.element[i].elementType != Triangle && |
470 | surfaceMesh.element[i].elementType != Quadrilateral) { |
471 | continue; |
472 | } |
473 | |
474 | surfaceMesh.element[i].markerID = faceBCIndex; |
475 | } |
476 | |
477 | #ifdef I_DONT_THINK_WE_NEED_THIS |
478 | // Determine a suitable boundary index of the extruded plane |
479 | *extrusionBCIndex = faceBCIndex; |
480 | for (i = 0; i < surfaceMesh.meshQuickRef.numLine; i++) { |
481 | |
482 | if (surfaceMesh.meshQuickRef.startIndexLine >= 0) { |
483 | elementIndex = surfaceMesh.meshQuickRef.startIndexLine + i; |
484 | } else { |
485 | elementIndex = surfaceMesh.meshQuickRef.listIndexLine[i]; |
486 | } |
487 | |
488 | marker = surfaceMesh.element[elementIndex].markerID; |
489 | |
490 | if (marker > *extrusionBCIndex) { |
491 | *extrusionBCIndex = marker; |
492 | } |
493 | } |
494 | *extrusionBCIndex += 1; |
495 | #endif |
496 | |
497 | // Check to make sure the face is on the y = 0 plane |
498 | for (i = 0; i < surfaceMesh.numNode; i++) { |
499 | |
500 | if (surfaceMesh.node[i].xyz[1] != 0.0) { |
501 | printf("\nSurface mesh is not on y = 0.0 plane, FUN3D could fail during execution for this 2D mesh!!!\n"); |
502 | break; |
503 | } |
504 | } |
505 | |
506 | // Constant x? |
507 | for (i = 0; i < surfaceMesh.numNode; i++) { |
508 | if ((surfaceMesh.node[i].xyz[0] - surfaceMesh.node[0].xyz[0]) > 1E-7) { |
509 | xMeshConstant = (int) false0; |
510 | break; |
511 | } |
512 | } |
513 | |
514 | // Constant y? |
515 | for (i = 0; i < surfaceMesh.numNode; i++) { |
516 | if ((surfaceMesh.node[i].xyz[1] - surfaceMesh.node[0].xyz[1] ) > 1E-7) { |
517 | yMeshConstant = (int) false0; |
518 | break; |
519 | } |
520 | } |
521 | |
522 | // Constant z? |
523 | for (i = 0; i < surfaceMesh.numNode; i++) { |
524 | if ((surfaceMesh.node[i].xyz[2] - surfaceMesh.node[0].xyz[2]) > 1E-7) { |
525 | zMeshConstant = (int) false0; |
526 | break; |
527 | } |
528 | } |
529 | |
530 | if (yMeshConstant != (int) true1) { |
531 | printf("FUN3D expects 2D meshes be in the x-z plane... attempting to rotate mesh!\n"); |
532 | |
533 | if (xMeshConstant == (int) true1 && zMeshConstant == (int) false0) { |
534 | printf("Swapping y and x coordinates!\n"); |
535 | for (i = 0; i < surfaceMesh.numNode; i++) { |
536 | tempCoord = surfaceMesh.node[i].xyz[0]; |
537 | surfaceMesh.node[i].xyz[0] = surfaceMesh.node[i].xyz[1]; |
538 | surfaceMesh.node[i].xyz[1] = tempCoord; |
539 | } |
540 | |
541 | } else if(xMeshConstant == (int) false0 && zMeshConstant == (int) true1) { |
542 | |
543 | printf("Swapping y and z coordinates!\n"); |
544 | for (i = 0; i < surfaceMesh.numNode; i++) { |
545 | tempCoord = surfaceMesh.node[i].xyz[2]; |
546 | surfaceMesh.node[i].xyz[2] = surfaceMesh.node[i].xyz[1]; |
547 | surfaceMesh.node[i].xyz[1] = tempCoord; |
548 | } |
549 | |
550 | } else { |
551 | AIM_ERROR(aimInfo, "Unable to rotate mesh!\n"){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 551, __func__ , "Unable to rotate mesh!\n"); }; |
552 | status = CAPS_NOTFOUND-303; |
553 | goto cleanup; |
554 | } |
555 | } |
556 | |
557 | status = extrude_SurfaceMesh(extrusion, extrusionBCIndex, &surfaceMesh, &volumeMesh); |
558 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 558, __func__, 0); goto cleanup; }; |
559 | |
560 | strcpy(filename, projectName); |
561 | |
562 | // Write AFLR3 |
563 | /*@-nullpass@*/ |
564 | status = mesh_writeAFLR3(aimInfo, filename, |
565 | 0, // write binary file |
566 | &volumeMesh, |
567 | 1.0); |
568 | /*@+nullpass@*/ |
569 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 569, __func__, 0); goto cleanup; }; |
570 | |
571 | status = CAPS_SUCCESS0; |
572 | |
573 | cleanup: |
574 | if (status != CAPS_SUCCESS0) { |
575 | printf("Error: Premature exit in fun3d_2DMesh status = %d\n", status); |
576 | } |
577 | |
578 | /*@-dependenttrans@*/ |
579 | if (fp != NULL((void*)0)) fclose(fp); |
580 | /*@+dependenttrans@*/ |
581 | |
582 | // Destroy meshes |
583 | (void) destroy_meshStruct(&surfaceMesh); |
584 | (void) destroy_meshStruct(&volumeMesh); |
585 | |
586 | return status; |
587 | } |
588 | |
589 | |
590 | // Remove unused nodes from dataMatrix and update connectivity matrix |
591 | static int fun3d_removeUnused(void *aimInfo, int numVariable, int *numNode, int used[], |
592 | double ***data, /*@null@*/ int *numConnect, |
593 | /*@null@*/ int *dataConnectMatrix) |
594 | { |
595 | int i, j, k; //Indexing |
596 | int status; |
597 | |
598 | int *usedNode=NULL((void*)0); // Freeable |
599 | |
600 | double **dataMatrix; |
601 | |
602 | dataMatrix = *data; |
603 | |
604 | // Copy used node array |
605 | usedNode = (int *) EG_alloc(*numNode*sizeof(int)); |
606 | if (usedNode == NULL((void*)0)) { |
607 | status = EGADS_MALLOC-4; |
608 | goto cleanup; |
609 | } |
610 | for (i = 0; i < *numNode; i++) usedNode[i] = used[i]; |
611 | |
612 | // Remove unused nodes |
613 | j = 0; |
614 | for (i = 0; i< *numNode; i++ ) { |
615 | if (usedNode[i] == (int) false0 || usedNode[i] < 0) continue; |
616 | |
617 | usedNode[i] = j+1; // Set i-th node to essentially the node ID, 1-bias |
618 | |
619 | j +=1; |
620 | } |
621 | |
622 | j = 0; |
623 | for (i = 0; i< *numNode; i++ ) { |
624 | if (usedNode[i] == (int) false0 || usedNode[i] < 0) continue; |
625 | |
626 | for (k = 0; k < numVariable; k++) { |
627 | dataMatrix[k][j] = dataMatrix[k][i]; //Re-order dataMatrix - bubbling i'th index to j |
628 | } |
629 | |
630 | j += 1; |
631 | } |
632 | |
633 | *numNode = j; // New number of nodes |
634 | |
635 | // Redo connectivity |
636 | if (dataConnectMatrix != NULL((void*)0)) { |
637 | AIM_NOTNULL(numConnect, aimInfo, status){ if (numConnect == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 637, __func__, 1, "%s == NULL!", "numConnect" ); goto cleanup; } }; |
638 | j = 0; |
639 | for (i = 0; i < *numConnect; i++) { |
640 | |
641 | if (usedNode[dataConnectMatrix[4*i+ 0]-1] == (int) false0) continue; |
642 | if (usedNode[dataConnectMatrix[4*i+ 1]-1] == (int) false0) continue; |
643 | if (usedNode[dataConnectMatrix[4*i+ 2]-1] == (int) false0) continue; |
644 | if (usedNode[dataConnectMatrix[4*i+ 3]-1] == (int) false0) continue; |
645 | |
646 | for (k = 0; k < 4; k++) { |
647 | dataConnectMatrix[4*j+ k] = usedNode[dataConnectMatrix[4*i+ k]-1]; |
648 | } |
649 | |
650 | j += 1; |
651 | } |
652 | |
653 | *numConnect = j; // New number of elements |
654 | } |
655 | |
656 | status = CAPS_SUCCESS0; |
657 | |
658 | cleanup: |
659 | if (status != CAPS_SUCCESS0) |
660 | printf("Error: Premature exit in fun3d_removeUnused status = %d\n", |
661 | status); |
662 | |
663 | if (usedNode != NULL((void*)0)) EG_free(usedNode); |
664 | return status; |
665 | } |
666 | |
667 | |
668 | // Write FUN3D data transfer files |
669 | int fun3d_dataTransfer(void *aimInfo, |
670 | const char *projectName, |
671 | const mapAttrToIndexStruct *groupMap, |
672 | const cfdBoundaryConditionStruct bcProps, |
673 | aimMeshRef *meshRef, |
674 | /*@null@*/ cfdModalAeroelasticStruct *eigenVector) |
675 | { |
676 | |
677 | /*! \page dataTransferFUN3D FUN3D Data Transfer |
678 | * |
679 | * \section dataToFUN3D Data transfer to FUN3D (FieldIn) |
680 | * |
681 | * <ul> |
682 | * <li> <B>"Displacement"</B> </li> <br> |
683 | * Retrieves nodal displacements (as from a structural solver) |
684 | * and updates FUN3D's surface mesh; a new [project_name]_body1.dat file is written out which may |
685 | * be loaded into FUN3D to update the surface mesh/move the volume mesh using the FUN3D command line option |
686 | * -\-read_surface_from_file |
687 | * </ul> |
688 | * |
689 | * <ul> |
690 | * <li> <B>"EigenVector_#"</B> </li> <br> |
691 | * Retrieves modal eigen-vectors from a structural solver, where "#" should be replaced by the |
692 | * corresponding mode number for the eigen-vector (eg. EigenVector_3 would correspond to the third mode, |
693 | * while EigenVector_6 would be the sixth mode) . A [project_name]_body1_mode#.dat file is written |
694 | * out for each mode. |
695 | * </ul> |
696 | * |
697 | */ |
698 | |
699 | int status; // Function return status |
700 | int i, j, ibound, ibody, iface, iglobal, eigenIndex; // Indexing |
701 | |
702 | int stringLength = 0; |
703 | |
704 | char *filename = NULL((void*)0); |
705 | |
706 | // Discrete data transfer variables |
707 | capsDiscr *discr; |
708 | char **boundName = NULL((void*)0); |
709 | int numBoundName = 0; |
710 | enum capsdMethod dataTransferMethod; |
711 | int numDataTransferPoint; |
712 | int dataTransferRank; |
713 | double *dataTransferData; |
714 | char *units; |
715 | |
716 | int state, nGlobal, *globalOffset=NULL((void*)0), nFace; |
717 | ego body, *faces=NULL((void*)0); |
718 | |
719 | int alen, ntri, atype, itri, ielem; |
720 | const double *face_xyz, *face_uv, *reals; |
721 | const int *face_ptype, *face_pindex, *face_tris, *face_tric, *nquad=NULL((void*)0); |
722 | const char *string, *groupName = NULL((void*)0); |
723 | |
724 | // Variables used in global node mapping |
725 | int ptype, pindex; |
726 | double xyz[3]; |
727 | |
728 | // Data transfer Out variables |
729 | const char *dataOutName[] = {"x","y","z", "id", "dx", "dy", "dz"}; |
730 | const int dataOutFormat[] = {Double, Double, Double, Integer, Double, Double, Double}; |
731 | |
732 | double **dataOutMatrix = NULL((void*)0); |
733 | int *dataConnectMatrix = NULL((void*)0); |
734 | |
735 | int numOutVariable = 7; |
736 | int numOutDataPoint = 0; |
737 | int numOutDataConnect = 0; |
738 | |
739 | const char fileExtBody[] = "_body1"; |
740 | const char fileExt[] = ".dat"; |
741 | const char fileExtMode[] = "_mode"; |
742 | |
743 | int foundDisplacement = (int) false0, foundEigenVector = (int) false0; |
744 | |
745 | int marker; |
746 | |
747 | int numUsedNode = 0, numUsedConnectivity = 0, usedElems; |
748 | int *usedNode = NULL((void*)0); |
749 | |
750 | status = aim_getBounds(aimInfo, &numBoundName, &boundName); |
751 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 751, __func__, 0); goto cleanup; }; |
752 | |
753 | foundDisplacement = foundEigenVector = (int) false0; |
754 | for (ibound = 0; ibound < numBoundName; ibound++) { |
755 | AIM_NOTNULL(boundName, aimInfo, status){ if (boundName == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 755, __func__, 1, "%s == NULL!", "boundName" ); goto cleanup; } }; |
756 | |
757 | status = aim_getDiscr(aimInfo, boundName[ibound], &discr); |
758 | if (status != CAPS_SUCCESS0) continue; |
759 | |
760 | status = aim_getDataSet(discr, |
761 | "Displacement", |
762 | &dataTransferMethod, |
763 | &numDataTransferPoint, |
764 | &dataTransferRank, |
765 | &dataTransferData, |
766 | &units); |
767 | |
768 | if (status == CAPS_SUCCESS0) { // If we do have data ready is the rank correct |
769 | |
770 | foundDisplacement = (int) true1; |
771 | |
772 | if (dataTransferRank != 3) { |
773 | AIM_ERROR(aimInfo, "Displacement transfer data found however rank is %d not 3!!!!\n", dataTransferRank){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 773, __func__ , "Displacement transfer data found however rank is %d not 3!!!!\n" , dataTransferRank); }; |
774 | status = CAPS_BADRANK-301; |
775 | goto cleanup; |
776 | } |
777 | break; |
778 | } |
779 | |
780 | if (eigenVector != NULL((void*)0)) { |
781 | for (eigenIndex = 0; eigenIndex < eigenVector->numEigenValue; eigenIndex++) { |
782 | |
783 | status = aim_getDataSet(discr, |
784 | eigenVector->eigenValue[eigenIndex].name, |
785 | &dataTransferMethod, |
786 | &numDataTransferPoint, |
787 | &dataTransferRank, |
788 | &dataTransferData, |
789 | &units); |
790 | |
791 | if (status == CAPS_SUCCESS0) { // If we do have data ready is the rank correct |
792 | |
793 | foundEigenVector = (int) true1; |
794 | |
795 | if (dataTransferRank != 3) { |
796 | AIM_ERROR(aimInfo, "EigenVector transfer data found however rank is %d not 3!!!!\n", dataTransferRank){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 796, __func__ , "EigenVector transfer data found however rank is %d not 3!!!!\n" , dataTransferRank); }; |
797 | status = CAPS_BADRANK-301; |
798 | goto cleanup; |
799 | } |
800 | break; |
801 | } |
802 | } // Loop through EigenValues |
803 | |
804 | if (foundEigenVector == (int) true1) break; |
805 | |
806 | } // If eigen-vectors provided |
807 | } // Loop through transfer names |
808 | |
809 | if (foundDisplacement != (int) true1 && foundEigenVector != (int) true1) { |
810 | printf("Info: No recognized data transfer names found.\n"); |
811 | status = CAPS_NOTFOUND-303; |
812 | goto cleanup; |
813 | } |
814 | |
815 | // Ok looks like we have displacements/EigenVectors to get so lets continue |
816 | printf("Writing FUN3D data transfer files\n"); |
817 | |
818 | // Allocate data arrays that are going to be output |
819 | AIM_ALLOC(dataOutMatrix, numOutVariable, double*, aimInfo, status){ if (dataOutMatrix != ((void*)0)) { status = -4; aim_status( aimInfo, status, "fun3dUtils.c", 819, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutMatrix"); goto cleanup; } size_t memorysize = numOutVariable ; dataOutMatrix = (double* *) EG_alloc(memorysize*sizeof(double *)); if (dataOutMatrix == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 819, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutMatrix", memorysize, "double*"); goto cleanup; } }; |
820 | for (i = 0; i < numOutVariable; i++) dataOutMatrix[i] = NULL((void*)0); |
821 | |
822 | AIM_ALLOC(globalOffset, meshRef->nmap+1, int, aimInfo, status){ if (globalOffset != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 822, __func__, 1, "AIM_ALLOC: %s != NULL" , "globalOffset"); goto cleanup; } size_t memorysize = meshRef ->nmap+1; globalOffset = (int *) EG_alloc(memorysize*sizeof (int)); if (globalOffset == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 822, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "globalOffset", memorysize, "int"); goto cleanup; } }; |
823 | numOutDataPoint = 0; |
824 | ielem = 0; |
825 | globalOffset[0] = 0; |
826 | for (i = 0; i < meshRef->nmap; i++) { |
827 | if (meshRef->maps[i].tess == NULL((void*)0)) continue; |
828 | |
829 | status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &nGlobal); |
830 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 830, __func__, 0); goto cleanup; }; |
831 | |
832 | // re-allocate data arrays |
833 | for (j = 0; j < numOutVariable; j++) { |
834 | AIM_REALL(dataOutMatrix[j], numOutDataPoint + nGlobal, double, aimInfo, status){ size_t memorysize = numOutDataPoint + nGlobal; dataOutMatrix [j] = (double *) EG_reall(dataOutMatrix[j], memorysize*sizeof (double)); if (dataOutMatrix[j] == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c", 834, __func__, 3 , "AIM_REALL: %s size %zu type %s", "dataOutMatrix[j]", memorysize , "double"); goto cleanup; } }; |
835 | } |
836 | AIM_REALL(usedNode, numOutDataPoint + nGlobal, int, aimInfo, status){ size_t memorysize = numOutDataPoint + nGlobal; usedNode = ( int *) EG_reall(usedNode, memorysize*sizeof(int)); if (usedNode == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c" , 836, __func__, 3, "AIM_REALL: %s size %zu type %s", "usedNode" , memorysize, "int"); goto cleanup; } }; |
837 | for (j = globalOffset[0]; j < numOutDataPoint + nGlobal; j++) usedNode[j] = (int) false0; |
838 | |
839 | |
840 | for (iglobal = 0; iglobal < nGlobal; iglobal++) { |
841 | status = EG_getGlobal(meshRef->maps[i].tess, |
842 | iglobal+1, &ptype, &pindex, xyz); |
843 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 843, __func__, 0); goto cleanup; }; |
844 | |
845 | // First just set the Coordinates |
846 | dataOutMatrix[0][globalOffset[i]+iglobal] = xyz[0]; |
847 | dataOutMatrix[1][globalOffset[i]+iglobal] = xyz[1]; |
848 | dataOutMatrix[2][globalOffset[i]+iglobal] = xyz[2]; |
849 | |
850 | // Volume mesh node ID |
851 | dataOutMatrix[3][globalOffset[i]+iglobal] = meshRef->maps[i].map[iglobal]; |
852 | |
853 | // Delta displacements |
854 | dataOutMatrix[4][i] = 0; |
855 | dataOutMatrix[5][i] = 0; |
856 | dataOutMatrix[6][i] = 0; |
857 | } |
858 | |
859 | // check if the tessellation has a mixture of quad and tess |
860 | status = EG_attributeRet(meshRef->maps[i].tess, ".mixed", |
861 | &atype, &alen, &nquad, &reals, &string); |
862 | if (status != EGADS_SUCCESS0 && |
863 | status != EGADS_NOTFOUND-1) AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 863, __func__, 0); goto cleanup; }; |
864 | |
865 | status = EG_getBodyTopos(body, NULL((void*)0), FACE23, &nFace, &faces); |
866 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 866, __func__, 0); goto cleanup; }; |
867 | for (iface = 0; iface < nFace; iface++) { |
868 | // get the face tessellation |
869 | status = EG_getTessFace(meshRef->maps[i].tess, iface+1, &alen, &face_xyz, &face_uv, |
870 | &face_ptype, &face_pindex, &ntri, &face_tris, &face_tric); |
871 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 871, __func__, 0); goto cleanup; }; |
872 | AIM_NOTNULL(faces, aimInfo, status){ if (faces == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 872, __func__, 1, "%s == NULL!", "faces" ); goto cleanup; } }; |
873 | |
874 | status = retrieve_CAPSGroupAttr(faces[iface], &groupName); |
875 | if (status == EGADS_SUCCESS0) { |
876 | AIM_NOTNULL(groupName, aimInfo, status){ if (groupName == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 876, __func__, 1, "%s == NULL!", "groupName" ); goto cleanup; } }; |
877 | status = get_mapAttrToIndexIndex(groupMap, groupName, &marker); |
878 | if (status != CAPS_SUCCESS0) { |
879 | AIM_ERROR(aimInfo, "No capsGroup \"%s\" not found in attribute map", groupName){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 879, __func__ , "No capsGroup \"%s\" not found in attribute map", groupName ); }; |
880 | goto cleanup; |
881 | } |
882 | } else { |
883 | AIM_ERROR(aimInfo, "No capsGroup on face %d", iface+1){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 883, __func__ , "No capsGroup on face %d", iface+1); }; |
884 | print_AllAttr(aimInfo, faces[iface]); |
885 | goto cleanup; |
886 | } |
887 | |
888 | // To keep with the moving_bodying input we will assume used nodes are all inviscid and viscous surfaces instead |
889 | // usedNode[k] = (int) true; |
890 | usedElems = (int) false0; |
891 | for (j = 0; j < bcProps.numSurfaceProp; j++) { |
892 | if (marker != bcProps.surfaceProp[j].bcID) continue; |
893 | |
894 | if (bcProps.surfaceProp[j].surfaceType == Viscous || |
895 | bcProps.surfaceProp[j].surfaceType == Inviscid) { |
896 | usedElems = (int) true1; |
897 | } |
898 | break; |
899 | } |
900 | |
901 | if (nquad == NULL((void*)0)) { // all triangles |
902 | |
903 | // re-allocate data arrays |
904 | AIM_REALL(dataConnectMatrix, 4*(numOutDataConnect + ntri), int, aimInfo, status){ size_t memorysize = 4*(numOutDataConnect + ntri); dataConnectMatrix = (int *) EG_reall(dataConnectMatrix, memorysize*sizeof(int) ); if (dataConnectMatrix == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 904, __func__, 3, "AIM_REALL: %s size %zu type %s" , "dataConnectMatrix", memorysize, "int"); goto cleanup; } }; |
905 | |
906 | for (itri = 0; itri < ntri; itri++, ielem++) { |
907 | for (j = 0; j < 3; j++) { |
908 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &iglobal); |
909 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 909, __func__, 0); goto cleanup; }; |
910 | dataConnectMatrix[4*ielem+j] = globalOffset[i] + iglobal; |
911 | usedNode[globalOffset[i]+iglobal-1] = usedElems; |
912 | } |
913 | // repeat the last node for triangles |
914 | dataConnectMatrix[4*ielem+3] = dataConnectMatrix[4*ielem+2]; |
915 | } |
916 | |
917 | numOutDataConnect += ntri; |
918 | |
919 | } else { // mixture of tri and quad elements |
920 | |
921 | // re-allocate data arrays |
922 | AIM_REALL(dataConnectMatrix, 4*(numOutDataConnect + ntri-nquad[iface]), int, aimInfo, status){ size_t memorysize = 4*(numOutDataConnect + ntri-nquad[iface ]); dataConnectMatrix = (int *) EG_reall(dataConnectMatrix, memorysize *sizeof(int)); if (dataConnectMatrix == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c", 922, __func__ , 3, "AIM_REALL: %s size %zu type %s", "dataConnectMatrix", memorysize , "int"); goto cleanup; } }; |
923 | |
924 | // process triangles |
925 | for (itri = 0; itri < ntri-2*nquad[iface]; itri++, ielem++) { |
926 | for (j = 0; j < 3; j++) { |
927 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &iglobal); |
928 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 928, __func__, 0); goto cleanup; }; |
929 | dataConnectMatrix[4*ielem+j] = globalOffset[i] + iglobal; |
930 | usedNode[globalOffset[i]+iglobal-1] = usedElems; |
931 | } |
932 | // repeat the last node for triangle |
933 | dataConnectMatrix[4*ielem+3] = dataConnectMatrix[4*ielem+2]; |
934 | } |
935 | // process quads |
936 | for (; itri < ntri; itri++, ielem++) { |
937 | for (j = 0; j < 3; j++) { |
938 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &iglobal); |
939 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 939, __func__, 0); goto cleanup; }; |
940 | dataConnectMatrix[4*ielem+j] = globalOffset[i] + iglobal; |
941 | usedNode[globalOffset[i]+iglobal-1] = usedElems; |
942 | } |
943 | |
944 | // add the last node from the 2nd triangle to make the quad |
945 | itri++; |
946 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+2], &iglobal); |
947 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 947, __func__, 0); goto cleanup; }; |
948 | dataConnectMatrix[4*ielem+3] = globalOffset[i] + iglobal; |
949 | usedNode[globalOffset[i]+iglobal-1] = usedElems; |
950 | } |
951 | |
952 | numOutDataConnect += ntri-nquad[iface]; |
953 | } |
954 | |
955 | } |
956 | AIM_FREE(faces){ EG_free(faces); faces = ((void*)0); }; |
957 | |
958 | numOutDataPoint += nGlobal; |
959 | globalOffset[i+1] = globalOffset[i] + nGlobal; |
960 | } |
961 | |
962 | // Re-loop through transfers - if we are doing displacements |
963 | if (foundDisplacement == (int) true1) { |
964 | |
965 | for (ibound = 0; ibound < numBoundName; ibound++) { |
966 | AIM_NOTNULL(boundName, aimInfo, status){ if (boundName == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 966, __func__, 1, "%s == NULL!", "boundName" ); goto cleanup; } }; |
967 | |
968 | status = aim_getDiscr(aimInfo, boundName[ibound], &discr); |
969 | if (status != CAPS_SUCCESS0) continue; |
970 | |
971 | status = aim_getDataSet(discr, |
972 | "Displacement", |
973 | &dataTransferMethod, |
974 | &numDataTransferPoint, |
975 | &dataTransferRank, |
976 | &dataTransferData, |
977 | &units); |
978 | if (status != CAPS_SUCCESS0) continue; // If no elements in this object skip to next transfer name |
979 | |
980 | if (numDataTransferPoint != discr->nPoints && |
981 | numDataTransferPoint > 1) { |
982 | AIM_ERROR(aimInfo, "Developer error!! %d != %d", numDataTransferPoint, discr->nPoints){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 982, __func__ , "Developer error!! %d != %d", numDataTransferPoint, discr-> nPoints); }; |
983 | status = CAPS_MISMATCH-324; |
984 | goto cleanup; |
985 | } |
986 | |
987 | for (i = 0; i < discr->nPoints; i++) { |
988 | |
989 | ibody = discr->tessGlobal[2*i+0]; |
990 | iglobal = discr->tessGlobal[2*i+1]; |
991 | |
992 | status = EG_getGlobal(discr->bodys[ibody-1].tess, |
993 | iglobal, &ptype, &pindex, xyz); |
994 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 994, __func__, 0); goto cleanup; }; |
995 | |
996 | // Find the disc tessellation in the original list of tessellations |
997 | for (j = 0; j < meshRef->nmap; j++) { |
998 | if (discr->bodys[ibody-1].tess == meshRef->maps[j].tess) { |
999 | break; |
1000 | } |
1001 | } |
1002 | if (j == meshRef->nmap) { |
1003 | AIM_ERROR(aimInfo, "Could not find matching tessellation!"){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 1003, __func__ , "Could not find matching tessellation!"); }; |
1004 | status = CAPS_MISMATCH-324; |
1005 | goto cleanup; |
1006 | } |
1007 | |
1008 | if (numDataTransferPoint == 1) { |
1009 | // A single point means this is an initialization phase |
1010 | |
1011 | // Apply delta displacements |
1012 | dataOutMatrix[0][globalOffset[j]+iglobal-1] += dataTransferData[0]; |
1013 | dataOutMatrix[1][globalOffset[j]+iglobal-1] += dataTransferData[1]; |
1014 | dataOutMatrix[2][globalOffset[j]+iglobal-1] += dataTransferData[2]; |
1015 | |
1016 | // save delta displacements |
1017 | dataOutMatrix[4][globalOffset[j]+iglobal-1] = dataTransferData[0]; |
1018 | dataOutMatrix[5][globalOffset[j]+iglobal-1] = dataTransferData[1]; |
1019 | dataOutMatrix[6][globalOffset[j]+iglobal-1] = dataTransferData[2]; |
1020 | |
1021 | } else { |
1022 | // Apply delta displacements |
1023 | dataOutMatrix[0][globalOffset[j]+iglobal-1] += dataTransferData[3*i+0]; |
1024 | dataOutMatrix[1][globalOffset[j]+iglobal-1] += dataTransferData[3*i+1]; |
1025 | dataOutMatrix[2][globalOffset[j]+iglobal-1] += dataTransferData[3*i+2]; |
1026 | |
1027 | dataOutMatrix[4][globalOffset[j]+iglobal-1] = dataTransferData[3*i+0]; |
1028 | dataOutMatrix[5][globalOffset[j]+iglobal-1] = dataTransferData[3*i+1]; |
1029 | dataOutMatrix[6][globalOffset[j]+iglobal-1] = dataTransferData[3*i+2]; |
1030 | } |
1031 | } |
1032 | } // End numBoundName loop |
1033 | |
1034 | // Remove unused nodes |
1035 | numUsedNode = numOutDataPoint; |
1036 | numUsedConnectivity = numOutDataConnect; |
1037 | AIM_NOTNULL(usedNode, aimInfo, status){ if (usedNode == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 1037, __func__, 1, "%s == NULL!", "usedNode" ); goto cleanup; } }; |
1038 | status = fun3d_removeUnused(aimInfo, numOutVariable, &numUsedNode, usedNode, |
1039 | &dataOutMatrix, &numUsedConnectivity, |
1040 | dataConnectMatrix); |
1041 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1041, __func__, 0); goto cleanup; }; |
1042 | |
1043 | stringLength = strlen(projectName) + strlen(fileExtBody) + strlen(fileExt) + 1; |
1044 | AIM_ALLOC(filename, stringLength+1, char, aimInfo, status){ if (filename != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 1044, __func__, 1, "AIM_ALLOC: %s != NULL" , "filename"); goto cleanup; } size_t memorysize = stringLength +1; filename = (char *) EG_alloc(memorysize*sizeof(char)); if (filename == ((void*)0)) { status = -4; aim_status(aimInfo, status , "fun3dUtils.c", 1044, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "filename", memorysize, "char"); goto cleanup; } }; |
1045 | |
1046 | strcpy(filename, projectName); |
1047 | strcat(filename, fileExtBody); |
1048 | strcat(filename, fileExt); |
1049 | filename[stringLength] = '\0'; |
1050 | |
1051 | // Write out displacement in tecplot file |
1052 | /*@-nullpass@*/ |
1053 | status = tecplot_writeFEPOINT(aimInfo, filename, |
1054 | "FUN3D AeroLoads", |
1055 | NULL((void*)0), |
1056 | numOutVariable, |
1057 | (char **)dataOutName, |
1058 | numUsedNode, // numOutDataPoint, |
1059 | dataOutMatrix, |
1060 | dataOutFormat, |
1061 | numUsedConnectivity, //numOutDataConnect, // numConnectivity |
1062 | dataConnectMatrix, // connectivity matrix |
1063 | NULL((void*)0)); // Solution time |
1064 | /*@+nullpass@*/ |
1065 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1065, __func__, 0); goto cleanup; }; |
1066 | AIM_FREE(filename){ EG_free(filename); filename = ((void*)0); }; |
1067 | } // End if found displacements |
1068 | |
1069 | // Re-loop through transfers - if we are doing eigen-vectors |
1070 | if ((foundEigenVector == (int) true1) && (eigenVector != NULL((void*)0))) { |
1071 | |
1072 | for (eigenIndex = 0; eigenIndex < eigenVector->numEigenValue; eigenIndex++) { |
1073 | |
1074 | // Zero out the eigen-vectors each time we are writing out a new one |
1075 | for (i = 0; i < numOutDataPoint; i++ ) { |
1076 | |
1077 | // Delta eigen-vectors |
1078 | dataOutMatrix[4][i] = 0; |
1079 | dataOutMatrix[5][i] = 0; |
1080 | dataOutMatrix[6][i] = 0; |
1081 | } |
1082 | |
1083 | for (ibound = 0; ibound < numBoundName; ibound++) { |
1084 | AIM_NOTNULL(boundName, aimInfo, status){ if (boundName == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 1084, __func__, 1, "%s == NULL!", "boundName" ); goto cleanup; } }; |
1085 | |
1086 | status = aim_getDiscr(aimInfo, boundName[ibound], &discr); |
1087 | if (status != CAPS_SUCCESS0) continue; |
1088 | |
1089 | status = aim_getDataSet(discr, |
1090 | eigenVector->eigenValue[eigenIndex].name, |
1091 | &dataTransferMethod, |
1092 | &numDataTransferPoint, |
1093 | &dataTransferRank, |
1094 | &dataTransferData, |
1095 | &units); |
1096 | if (status != CAPS_SUCCESS0) continue; // If no elements in this object skip to next transfer name |
1097 | |
1098 | if (numDataTransferPoint != discr->nPoints && |
1099 | numDataTransferPoint > 1) { |
1100 | AIM_ERROR(aimInfo, "Developer error!! %d != %d", numDataTransferPoint, discr->nPoints){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 1100, __func__ , "Developer error!! %d != %d", numDataTransferPoint, discr-> nPoints); }; |
1101 | status = CAPS_MISMATCH-324; |
1102 | goto cleanup; |
1103 | } |
1104 | |
1105 | for (i = 0; i < discr->nPoints; i++) { |
1106 | |
1107 | ibody = discr->tessGlobal[2*i+0]; |
1108 | iglobal = discr->tessGlobal[2*i+1]; |
1109 | |
1110 | // Find the disc tessellation in the original list of tessellations |
1111 | for (j = 0; j < meshRef->nmap; j++) { |
1112 | if (discr->bodys[ibody-1].tess == meshRef->maps[j].tess) { |
1113 | break; |
1114 | } |
1115 | } |
1116 | if (j == meshRef->nmap) { |
1117 | AIM_ERROR(aimInfo, "Could not find matching tessellation!"){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 1117, __func__ , "Could not find matching tessellation!"); }; |
1118 | status = CAPS_MISMATCH-324; |
1119 | goto cleanup; |
1120 | } |
1121 | |
1122 | if (numDataTransferPoint == 1) { |
1123 | // A single point means this is an initialization phase |
1124 | |
1125 | // save Eigen-vector |
1126 | dataOutMatrix[4][globalOffset[j]+iglobal-1] = dataTransferData[0]; |
1127 | dataOutMatrix[5][globalOffset[j]+iglobal-1] = dataTransferData[1]; |
1128 | dataOutMatrix[6][globalOffset[j]+iglobal-1] = dataTransferData[2]; |
1129 | |
1130 | } else { |
1131 | // save Eigen-vector |
1132 | dataOutMatrix[4][globalOffset[j]+iglobal-1] = dataTransferData[3*i+0]; |
1133 | dataOutMatrix[5][globalOffset[j]+iglobal-1] = dataTransferData[3*i+1]; |
1134 | dataOutMatrix[6][globalOffset[j]+iglobal-1] = dataTransferData[3*i+2]; |
1135 | } |
1136 | } |
1137 | } // End dataTransferDiscreteObj loop |
1138 | |
1139 | // Remove unused nodes |
1140 | numUsedNode = numOutDataPoint; |
1141 | AIM_NOTNULL(usedNode, aimInfo, status){ if (usedNode == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 1141, __func__, 1, "%s == NULL!", "usedNode" ); goto cleanup; } }; |
1142 | |
1143 | if (eigenIndex == 0) { |
1144 | numUsedConnectivity = numOutDataConnect; |
1145 | status = fun3d_removeUnused(aimInfo, numOutVariable, &numUsedNode, |
1146 | usedNode, &dataOutMatrix, |
1147 | &numUsedConnectivity, dataConnectMatrix); |
1148 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1148, __func__, 0); goto cleanup; }; |
1149 | } else { |
1150 | status = fun3d_removeUnused(aimInfo, numOutVariable, &numUsedNode, |
1151 | usedNode, &dataOutMatrix, NULL((void*)0), NULL((void*)0)); |
1152 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1152, __func__, 0); goto cleanup; }; |
1153 | } |
1154 | |
1155 | stringLength = strlen(projectName) + |
1156 | strlen(fileExtBody) + |
1157 | strlen(fileExtMode) + |
1158 | strlen(fileExt) + 5; |
1159 | |
1160 | AIM_ALLOC(filename, stringLength+1, char, aimInfo, status){ if (filename != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 1160, __func__, 1, "AIM_ALLOC: %s != NULL" , "filename"); goto cleanup; } size_t memorysize = stringLength +1; filename = (char *) EG_alloc(memorysize*sizeof(char)); if (filename == ((void*)0)) { status = -4; aim_status(aimInfo, status , "fun3dUtils.c", 1160, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "filename", memorysize, "char"); goto cleanup; } }; |
1161 | |
1162 | snprintf(filename,stringLength+1, "%s%s%s%d%s", |
1163 | projectName, |
1164 | fileExtBody, |
1165 | fileExtMode, // Change modeNumber so it always starts at 1! |
1166 | eigenIndex+1, // eigenVector->eigenValue[eigenIndex].modeNumber, |
1167 | fileExt); |
1168 | |
1169 | // Write out eigen-vector in tecplot file |
1170 | /*@-nullpass@*/ |
1171 | status = tecplot_writeFEPOINT(aimInfo, |
1172 | filename, |
1173 | "FUN3D Modal", |
1174 | NULL((void*)0), |
1175 | numOutVariable, |
1176 | (char **)dataOutName, |
1177 | numUsedNode, //numOutDataPoint, |
1178 | dataOutMatrix, |
1179 | dataOutFormat, |
1180 | numUsedConnectivity, //numOutDataConnect, // numConnectivity |
1181 | dataConnectMatrix, // connectivity matrix |
1182 | NULL((void*)0)); // Solution time |
1183 | /*@+nullpass@*/ |
1184 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1184, __func__, 0); goto cleanup; }; |
1185 | AIM_FREE(filename){ EG_free(filename); filename = ((void*)0); }; |
1186 | |
1187 | } // End eigenvector names |
1188 | } // End if found eigenvectors |
1189 | |
1190 | status = CAPS_SUCCESS0; |
1191 | |
1192 | // Clean-up |
1193 | cleanup: |
1194 | |
1195 | if (status != CAPS_SUCCESS0 && |
1196 | status != CAPS_NOTFOUND-303) printf("Error: Premature exit in fun3d_dataTransfer status = %d\n", status); |
1197 | |
1198 | if (dataOutMatrix != NULL((void*)0)) { |
1199 | for (i = 0; i < numOutVariable; i++) { |
1200 | AIM_FREE(dataOutMatrix[i]){ EG_free(dataOutMatrix[i]); dataOutMatrix[i] = ((void*)0); }; |
1201 | } |
1202 | } |
1203 | |
1204 | AIM_FREE(faces){ EG_free(faces); faces = ((void*)0); }; |
1205 | AIM_FREE(dataOutMatrix){ EG_free(dataOutMatrix); dataOutMatrix = ((void*)0); }; |
1206 | AIM_FREE(dataConnectMatrix){ EG_free(dataConnectMatrix); dataConnectMatrix = ((void*)0); }; |
1207 | |
1208 | AIM_FREE(filename){ EG_free(filename); filename = ((void*)0); }; |
1209 | AIM_FREE(boundName){ EG_free(boundName); boundName = ((void*)0); }; |
1210 | AIM_FREE(usedNode){ EG_free(usedNode); usedNode = ((void*)0); }; |
1211 | |
1212 | return status; |
1213 | } |
1214 | |
1215 | |
1216 | // Write FUN3D fun3d.nml file |
1217 | int fun3d_writeNML(void *aimInfo, capsValue *aimInputs, cfdBoundaryConditionStruct bcProps) |
1218 | { |
1219 | |
1220 | int status; // Function return status |
1221 | |
1222 | int i; // Indexing |
1223 | |
1224 | FILE *fnml = NULL((void*)0); |
1225 | char filename[PATH_MAX4096]; |
1226 | char fileExt[] ="fun3d.nml"; |
1227 | |
1228 | printf("Writing fun3d.nml\n"); |
1229 | if (aimInputs[Design_Functional-1].nullVal == NotNull || |
1230 | aimInputs[Design_SensFile-1].vals.integer == (int)true1) { |
1231 | #ifdef WIN32 |
1232 | snprintf(filename, PATH_MAX4096, "Flow\\%s", fileExt); |
1233 | #else |
1234 | snprintf(filename, PATH_MAX4096, "Flow/%s", fileExt); |
1235 | #endif |
1236 | } else { |
1237 | strcpy(filename, fileExt); |
1238 | } |
1239 | |
1240 | fnml = aim_fopen(aimInfo, filename, "w"); |
1241 | if (fnml == NULL((void*)0)) { |
1242 | AIM_ERROR(aimInfo, "Unable to open file - %s\n", filename){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 1242, __func__ , "Unable to open file - %s\n", filename); }; |
1243 | status = CAPS_IOERR-332; |
1244 | goto cleanup; |
1245 | } |
1246 | |
1247 | // &project |
1248 | fprintf(fnml,"&project\n"); |
1249 | fprintf(fnml," project_rootname = \"%s\"\n", |
1250 | aimInputs[Proj_Name-1].vals.string); |
1251 | fprintf(fnml,"/\n\n"); |
1252 | |
1253 | // &raw_grid |
1254 | fprintf(fnml,"&raw_grid\n"); |
1255 | //fprintf(fnml," grid_format = \"%s\"\n", |
1256 | // aimInputs[Mesh_Format-1].vals.string); |
1257 | |
1258 | // if (aimInputs[Mesh_ASCII_Flag-1].vals.integer == (int) true) { |
1259 | // fprintf(fnml," data_format = \"ascii\"\n"); |
1260 | // } else fprintf(fnml," data_format = \"stream\"\n"); |
1261 | |
1262 | fprintf(fnml," grid_format = \"AFLR3\"\n"); |
1263 | fprintf(fnml," data_format = \"stream\"\n"); |
1264 | |
1265 | if (aimInputs[Two_Dimensional-1].vals.integer == (int) true1) { |
1266 | fprintf(fnml," twod_mode = .true.\n"); |
1267 | //fprintf(fnml," ignore_euler_number = .true.\n"); |
1268 | } |
1269 | |
1270 | fprintf(fnml,"/\n\n"); |
1271 | |
1272 | // &reference_physical_properties |
1273 | fprintf(fnml,"&reference_physical_properties\n"); |
1274 | |
1275 | if (aimInputs[Mach-1].nullVal != IsNull) { |
1276 | fprintf(fnml," mach_number = %f\n", aimInputs[Mach-1].vals.real); |
1277 | } |
1278 | |
1279 | if (aimInputs[Re-1].nullVal != IsNull) { |
1280 | fprintf(fnml," reynolds_number = %f\n", aimInputs[Re-1].vals.real); |
1281 | } |
1282 | |
1283 | if (aimInputs[Alpha-1].nullVal != IsNull) { |
1284 | fprintf(fnml," angle_of_attack = %f\n", aimInputs[Alpha-1].vals.real); |
1285 | } |
1286 | |
1287 | if (aimInputs[Beta-1].nullVal != IsNull) { |
1288 | fprintf(fnml," angle_of_yaw = %f\n", aimInputs[Beta-1].vals.real); |
1289 | } |
1290 | |
1291 | if (aimInputs[Reference_Temperature-1].nullVal != IsNull) { |
1292 | fprintf(fnml," temperature = %f\n", aimInputs[Reference_Temperature-1].vals.real); |
1293 | |
1294 | if (aimInputs[Reference_Temperature-1].units != NULL((void*)0)) { |
1295 | fprintf(fnml," temperature_units = \'%s\'\n", aimInputs[Reference_Temperature-1].units); |
1296 | } |
1297 | } |
1298 | |
1299 | fprintf(fnml,"/\n\n"); |
1300 | |
1301 | // &governing_equations |
1302 | fprintf(fnml,"&governing_equations\n"); |
1303 | |
1304 | if (aimInputs[Viscoux-1].nullVal != IsNull) { |
1305 | fprintf(fnml," viscous_terms = \"%s\"\n", aimInputs[Viscoux-1].vals.string); |
1306 | } |
1307 | |
1308 | if (aimInputs[Equation_Type-1].nullVal != IsNull) { |
1309 | fprintf(fnml," eqn_type = \"%s\"\n", aimInputs[Equation_Type-1].vals.string); |
1310 | } |
1311 | |
1312 | fprintf(fnml,"/\n\n"); |
1313 | |
1314 | // &nonlinear_solver_parameters |
1315 | fprintf(fnml,"&nonlinear_solver_parameters\n"); |
1316 | |
1317 | if (aimInputs[Time_Accuracy-1].nullVal != IsNull) { |
1318 | fprintf(fnml," time_accuracy = \"%s\"\n", |
1319 | aimInputs[Time_Accuracy-1].vals.string); |
1320 | } |
1321 | |
1322 | if (aimInputs[Time_Step-1].nullVal != IsNull) { |
1323 | fprintf(fnml," time_step_nondim = %f\n", aimInputs[Time_Step-1].vals.real); |
1324 | } |
1325 | |
1326 | if (aimInputs[Num_Subiter-1].nullVal != IsNull) { |
1327 | fprintf(fnml," subiterations = %d\n", |
1328 | aimInputs[Num_Subiter-1].vals.integer); |
1329 | } |
1330 | |
1331 | if (aimInputs[Temporal_Error-1].nullVal != IsNull) { |
1332 | |
1333 | fprintf(fnml," temporal_err_control = .true.\n"); |
1334 | fprintf(fnml," temporal_err_floor = %f\n", |
1335 | aimInputs[Temporal_Error-1].vals.real); |
1336 | |
1337 | } |
1338 | |
1339 | if (aimInputs[CFL_Schedule-1].nullVal != IsNull) { |
1340 | fprintf(fnml," schedule_cfl = %f %f\n", |
1341 | aimInputs[CFL_Schedule-1].vals.reals[0], |
1342 | aimInputs[CFL_Schedule-1].vals.reals[1]); |
1343 | } |
1344 | |
1345 | if (aimInputs[CFL_Schedule_Iter-1].nullVal != IsNull) { |
1346 | fprintf(fnml," schedule_iteration = %d %d\n", |
1347 | aimInputs[CFL_Schedule_Iter-1].vals.integers[0], |
1348 | aimInputs[CFL_Schedule_Iter-1].vals.integers[1]); |
1349 | } |
1350 | |
1351 | fprintf(fnml,"/\n\n"); |
1352 | |
1353 | // &code_run_control |
1354 | fprintf(fnml,"&code_run_control\n"); |
1355 | |
1356 | if (aimInputs[Num_Iter-1].nullVal != IsNull) { |
1357 | fprintf(fnml," steps = %d\n", aimInputs[Num_Iter-1].vals.integer); |
1358 | } |
1359 | |
1360 | if (aimInputs[Restart_Read-1].nullVal != IsNull) { |
1361 | fprintf(fnml," restart_read = '%s'\n", |
1362 | aimInputs[Restart_Read-1].vals.string); |
1363 | } |
1364 | |
1365 | |
1366 | fprintf(fnml,"/\n\n"); |
1367 | |
1368 | //&force_moment_integ_properties |
1369 | fprintf(fnml,"&force_moment_integ_properties\n"); |
1370 | |
1371 | if (aimInputs[Reference_Area-1].nullVal != IsNull) { |
1372 | fprintf(fnml," area_reference = %f\n", |
1373 | aimInputs[Reference_Area-1].vals.real); |
1374 | } |
1375 | |
1376 | if (aimInputs[Moment_Length-1].nullVal != IsNull) { |
1377 | fprintf(fnml," x_moment_length = %f\n", |
1378 | aimInputs[Moment_Length-1].vals.reals[0]); |
1379 | |
1380 | fprintf(fnml," y_moment_length = %f\n", |
1381 | aimInputs[Moment_Length-1].vals.reals[1]); |
1382 | } |
1383 | |
1384 | if (aimInputs[Moment_Center-1].nullVal != IsNull) { |
1385 | fprintf(fnml," x_moment_center = %f\n", |
1386 | aimInputs[Moment_Center-1].vals.reals[0]); |
1387 | |
1388 | fprintf(fnml," y_moment_center = %f\n", |
1389 | aimInputs[Moment_Center-1].vals.reals[1]); |
1390 | |
1391 | fprintf(fnml," z_moment_center = %f\n", |
1392 | aimInputs[Moment_Center-1].vals.reals[2]); |
1393 | } |
1394 | |
1395 | fprintf(fnml,"/\n\n"); |
1396 | |
1397 | //&boundary_conditions |
1398 | fprintf(fnml,"&boundary_conditions\n"); |
1399 | |
1400 | // Loop through boundary conditions |
1401 | for (i = 0; i < bcProps.numSurfaceProp ; i++) { |
1402 | |
1403 | // Temperature |
1404 | if (bcProps.surfaceProp[i].wallTemperatureFlag == (int) true1) { |
1405 | fprintf(fnml," wall_temperature(%d) = %f\n",bcProps.surfaceProp[i].bcID, |
1406 | bcProps.surfaceProp[i].wallTemperature); |
1407 | fprintf(fnml," wall_temp_flag(%d) = .true.\n",bcProps.surfaceProp[i].bcID); |
1408 | } |
1409 | |
1410 | // Total pressure and temperature |
1411 | if (bcProps.surfaceProp[i].surfaceType == SubsonicInflow) { |
1412 | |
1413 | fprintf(fnml, " total_pressure_ratio(%d) = %f\n", bcProps.surfaceProp[i].bcID, |
1414 | bcProps.surfaceProp[i].totalPressure); |
1415 | |
1416 | fprintf(fnml, " total_temperature_ratio(%d) = %f\n", bcProps.surfaceProp[i].bcID, |
1417 | bcProps.surfaceProp[i].totalTemperature); |
1418 | } |
1419 | |
1420 | // Static pressure |
1421 | if (bcProps.surfaceProp[i].surfaceType == BackPressure || |
1422 | bcProps.surfaceProp[i].surfaceType == SubsonicOutflow) { |
1423 | |
1424 | fprintf(fnml, " static_pressure_ratio(%d) = %f\n", bcProps.surfaceProp[i].bcID, |
1425 | bcProps.surfaceProp[i].staticPressure); |
1426 | } |
1427 | |
1428 | // Mach number |
1429 | if (bcProps.surfaceProp[i].surfaceType == MachOutflow || |
1430 | bcProps.surfaceProp[i].surfaceType == MassflowOut) { |
1431 | |
1432 | fprintf(fnml, " mach_bc(%d) = %f\n", bcProps.surfaceProp[i].bcID, |
1433 | bcProps.surfaceProp[i].machNumber); |
1434 | } |
1435 | |
1436 | // Massflow |
1437 | if (bcProps.surfaceProp[i].surfaceType == MassflowIn || |
1438 | bcProps.surfaceProp[i].surfaceType == MassflowOut) { |
1439 | |
1440 | fprintf(fnml, " massflow(%d) = %f\n", bcProps.surfaceProp[i].bcID, |
1441 | bcProps.surfaceProp[i].massflow); |
1442 | } |
1443 | |
1444 | // Fixed inflow and outflow |
1445 | /*if (bcProps.surfaceProp[i].surfaceType == FixedInflow || |
1446 | bcProps.surfaceProp[i].surfaceType == FixedOutflow) { |
1447 | |
1448 | fprintf(fnml, " qset(%d,1) = %f\n", bcProps.surfaceProp[i].bcID, |
1449 | bcProps.surfaceProp[i].staticDensity); |
1450 | |
1451 | fprintf(fnml, " qset(%d,2) = %f\n", bcProps.surfaceProp[i].bcID, |
1452 | bcProps.surfaceProp[i].uVelocity); |
1453 | |
1454 | fprintf(fnml, " qset(%d,3) = %f\n", bcProps.surfaceProp[i].bcID, |
1455 | bcProps.surfaceProp[i].vVelocity); |
1456 | |
1457 | fprintf(fnml, " qset(%d,4) = %f\n", bcProps.surfaceProp[i].bcID, |
1458 | bcProps.surfaceProp[i].wVelocity); |
1459 | |
1460 | fprintf(fnml, " qset(%d,5) = %f\n", bcProps.surfaceProp[i].bcID, |
1461 | bcProps.surfaceProp[i].staticDensity); |
1462 | }*/ |
1463 | } |
1464 | |
1465 | fprintf(fnml,"/\n\n"); |
1466 | |
1467 | // &noninertial_reference_frame |
1468 | fprintf(fnml,"&noninertial_reference_frame\n"); |
1469 | |
1470 | |
1471 | if (aimInputs[NonInertial_Rotation_Rate-1].nullVal != IsNull || |
1472 | aimInputs[NonInertial_Rotation_Center-1].nullVal != IsNull) { |
1473 | |
1474 | fprintf(fnml," noninertial = .true.\n"); |
1475 | } |
1476 | |
1477 | if (aimInputs[NonInertial_Rotation_Center-1].nullVal != IsNull) { |
1478 | fprintf(fnml," rotation_center_x = %f\n", |
1479 | aimInputs[NonInertial_Rotation_Center-1].vals.reals[0]); |
1480 | fprintf(fnml," rotation_center_y = %f\n", |
1481 | aimInputs[NonInertial_Rotation_Center-1].vals.reals[1]); |
1482 | fprintf(fnml," rotation_center_z = %f\n", |
1483 | aimInputs[NonInertial_Rotation_Center-1].vals.reals[2]); |
1484 | } |
1485 | |
1486 | if (aimInputs[NonInertial_Rotation_Rate-1].nullVal != IsNull) { |
1487 | fprintf(fnml," rotation_rate_x = %f\n", |
1488 | aimInputs[NonInertial_Rotation_Rate-1].vals.reals[0]); |
1489 | fprintf(fnml," rotation_rate_y = %f\n", |
1490 | aimInputs[NonInertial_Rotation_Rate-1].vals.reals[1]); |
1491 | fprintf(fnml," rotation_rate_z = %f\n", |
1492 | aimInputs[NonInertial_Rotation_Rate-1].vals.reals[2]); |
1493 | |
1494 | } |
1495 | |
1496 | fprintf(fnml,"/\n\n"); |
1497 | |
1498 | status = CAPS_SUCCESS0; |
1499 | |
1500 | cleanup: |
1501 | |
1502 | if (status != CAPS_SUCCESS0) |
1503 | printf("Error: Premature exit in fun3d_writeNML status = %d\n", status); |
1504 | |
1505 | if (fnml != NULL((void*)0)) fclose(fnml); |
1506 | |
1507 | return status; |
1508 | } |
1509 | |
1510 | |
1511 | // Write FUN3D movingbody.input file |
1512 | int fun3d_writeMovingBody(void *aimInfo, double fun3dVersion, cfdBoundaryConditionStruct bcProps, |
1513 | const char *motion_driver, |
1514 | const char *mesh_movement, |
1515 | cfdModalAeroelasticStruct *modalAeroelastic) |
1516 | { |
1517 | |
1518 | int status; // Function return status |
1519 | |
1520 | int i, eigenIndex; // Indexing |
1521 | int counter = 0; |
1522 | FILE *fp = NULL((void*)0); |
1523 | char *filename = NULL((void*)0); |
1524 | char fileExt[] ="moving_body.input"; |
1525 | |
1526 | int bodyIndex = 1; |
1527 | int stringLength; |
1528 | |
1529 | printf("Writing moving_body.input\n"); |
1530 | |
1531 | stringLength = strlen(fileExt) + 1; |
1532 | |
1533 | AIM_ALLOC(filename,stringLength +1, char, aimInfo, status){ if (filename != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 1533, __func__, 1, "AIM_ALLOC: %s != NULL" , "filename"); goto cleanup; } size_t memorysize = stringLength +1; filename = (char *) EG_alloc(memorysize*sizeof(char)); if (filename == ((void*)0)) { status = -4; aim_status(aimInfo, status , "fun3dUtils.c", 1533, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "filename", memorysize, "char"); goto cleanup; } }; |
1534 | |
1535 | strcpy(filename, fileExt); |
1536 | filename[stringLength] = '\0'; |
1537 | |
1538 | fp = aim_fopen(aimInfo, filename, "w"); |
1539 | if (fp == NULL((void*)0)) { |
1540 | AIM_ERROR(aimInfo, "Unable to open file - %s\n", filename){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 1540, __func__ , "Unable to open file - %s\n", filename); }; |
1541 | status = CAPS_IOERR-332; |
1542 | goto cleanup; |
1543 | } |
1544 | |
1545 | // &body_definitions |
1546 | fprintf(fp,"&body_definitions\n"); |
1547 | |
1548 | fprintf(fp," n_moving_bodies = %d\n", bodyIndex); |
1549 | |
1550 | counter = 0; |
1551 | for (i = 0; i < bcProps.numSurfaceProp; i++) { |
1552 | |
1553 | if (bcProps.surfaceProp[i].surfaceType == Viscous || |
1554 | bcProps.surfaceProp[i].surfaceType == Inviscid) { |
1555 | |
1556 | fprintf(fp," defining_bndry(%d,%d) = %d\n", counter+1, |
1557 | bodyIndex, |
1558 | bcProps.surfaceProp[i].bcID); |
1559 | |
1560 | counter += 1; |
1561 | } |
1562 | } |
1563 | |
1564 | fprintf(fp," n_defining_bndry(%d) = %d\n", bodyIndex, counter); |
1565 | |
1566 | fprintf(fp," motion_driver(%d) = ", bodyIndex); |
1567 | if (modalAeroelastic != NULL((void*)0)) { |
1568 | fprintf(fp,"\"aeroelastic\"\n"); |
1569 | } else { |
1570 | AIM_NOTNULL(motion_driver, aimInfo, status){ if (motion_driver == ((void*)0)) { status = -307; aim_status (aimInfo, status, "fun3dUtils.c", 1570, __func__, 1, "%s == NULL!" , "motion_driver"); goto cleanup; } }; |
1571 | fprintf(fp,"\"%s\"\n", motion_driver); |
1572 | } |
1573 | |
1574 | fprintf(fp," mesh_movement(%d) = ", bodyIndex); |
1575 | if (modalAeroelastic != NULL((void*)0)) { |
1576 | fprintf(fp,"\"deform\"\n"); |
1577 | } else { |
1578 | AIM_NOTNULL(mesh_movement, aimInfo, status){ if (mesh_movement == ((void*)0)) { status = -307; aim_status (aimInfo, status, "fun3dUtils.c", 1578, __func__, 1, "%s == NULL!" , "mesh_movement"); goto cleanup; } }; |
1579 | fprintf(fp,"\"%s\"\n", mesh_movement); |
1580 | } |
1581 | |
1582 | fprintf(fp,"/\n\n"); |
1583 | |
1584 | if (modalAeroelastic != NULL((void*)0)) { |
1585 | |
1586 | // &aeroelastic_modal_data |
1587 | fprintf(fp,"&aeroelastic_modal_data\n"); |
1588 | |
1589 | fprintf(fp," nmode(%d) = %d\n", bodyIndex, modalAeroelastic->numEigenValue); |
1590 | |
1591 | if (fun3dVersion < 13.1) { |
1592 | fprintf(fp," uinf(%d) = %f\n", bodyIndex, modalAeroelastic->freestreamVelocity); |
1593 | fprintf(fp," qinf(%d) = %f\n", bodyIndex, modalAeroelastic->freestreamDynamicPressure); |
1594 | fprintf(fp," grefl(%d) = %f\n", bodyIndex, modalAeroelastic->lengthScaling); |
1595 | } else { |
1596 | fprintf(fp," uinf = %f\n", modalAeroelastic->freestreamVelocity); |
1597 | fprintf(fp," qinf = %f\n", modalAeroelastic->freestreamDynamicPressure); |
1598 | fprintf(fp," grefl = %f\n",modalAeroelastic->lengthScaling); |
1599 | } |
1600 | |
1601 | fprintf(fp, "\n"); |
1602 | |
1603 | |
1604 | for (i = 0; i < modalAeroelastic->numEigenValue; i++) { |
1605 | |
1606 | eigenIndex = i + 1; // Change mode number so that it always starts at 1 |
1607 | // modalAeroelastic->eigenValue[i].modeNumber |
1608 | |
1609 | fprintf(fp, " ! Mode %d of %d (structural mode %d)\n", eigenIndex, |
1610 | modalAeroelastic->numEigenValue, |
1611 | modalAeroelastic->eigenValue[i].modeNumber); |
1612 | |
1613 | fprintf(fp," freq(%d,%d) = %f\n", eigenIndex, bodyIndex, modalAeroelastic->eigenValue[i].frequency); |
1614 | fprintf(fp," damp(%d,%d) = %f\n", eigenIndex, bodyIndex, modalAeroelastic->eigenValue[i].damping); |
1615 | |
1616 | fprintf(fp," gmass(%d,%d) = %f\n" , eigenIndex, bodyIndex, modalAeroelastic->eigenValue[i].generalMass); |
1617 | fprintf(fp," gdisp0(%d,%d) = %f\n" , eigenIndex, bodyIndex, modalAeroelastic->eigenValue[i].generalDisplacement); |
1618 | fprintf(fp," gvel0(%d,%d) = %f\n" , eigenIndex, bodyIndex, modalAeroelastic->eigenValue[i].generalVelocity); |
1619 | fprintf(fp," gforce0(%d,%d) = %f\n", eigenIndex, bodyIndex, modalAeroelastic->eigenValue[i].generalForce); |
1620 | |
1621 | fprintf(fp, "\n"); |
1622 | } |
1623 | fprintf(fp,"/\n\n"); |
1624 | } |
1625 | |
1626 | status = CAPS_SUCCESS0; |
1627 | |
1628 | cleanup: |
1629 | if (fp != NULL((void*)0)) fclose(fp); |
1630 | |
1631 | if (filename != NULL((void*)0)) EG_free(filename); |
1632 | |
1633 | return status; |
1634 | } |
1635 | |
1636 | |
1637 | // Write FUN3D parameterization/sensitivity file |
1638 | // Will not calculate shape sensitivities if there are no geometry design variable; will |
1639 | // simple check and dump out the body meshes in model.tec files |
1640 | int fun3d_writeParameterization(void *aimInfo, |
1641 | int numDesignVariable, |
1642 | cfdDesignVariableStruct designVariable[], |
1643 | aimMeshRef *meshRef) |
1644 | { |
1645 | |
1646 | int status; // Function return status |
1647 | |
1648 | int i, j, k, m, row, col; // Indexing |
1649 | |
1650 | int stringLength = 7; |
1651 | |
1652 | // Data transfer Out variables |
1653 | char **dataOutName= NULL((void*)0); |
1654 | |
1655 | double ***dataOutMatrix = NULL((void*)0); |
1656 | int *dataOutFormat = NULL((void*)0); |
1657 | int *dataConnectMatrix = NULL((void*)0); |
1658 | |
1659 | int numOutVariable = 4; // x, y, z, id, ... + 3* active GeomIn |
1660 | int numOutDataPoint = 0; |
1661 | int numOutDataConnect = 0; |
1662 | |
1663 | // Variables used in global node mapping |
1664 | int ptype, pindex; |
1665 | double xyz[3]; |
1666 | |
1667 | const char *geomInName; |
1668 | int numPoint; |
1669 | double *dxyz = NULL((void*)0); |
1670 | |
1671 | int index; |
1672 | int iface, iglobal; |
1673 | int state, nFace; |
1674 | ego body, *faces=NULL((void*)0); |
1675 | |
1676 | int alen, ntri, atype, itri, ielem; |
1677 | const double *face_xyz, *face_uv, *reals; |
1678 | const int *face_ptype, *face_pindex, *face_tris, *face_tric, *nquad=NULL((void*)0); |
1679 | const char *string; |
1680 | |
1681 | char message[100]; |
1682 | char *filePre = "model.tec."; |
1683 | char *fileExt = ".sd1"; |
1684 | char *filename = NULL((void*)0); |
1685 | char folder[] = "Rubberize"; |
1686 | char zoneTitle[100]; |
1687 | |
1688 | capsValue *geomInVal; |
1689 | int *geomSelect = NULL((void*)0); |
1690 | |
1691 | AIM_ALLOC(geomSelect, numDesignVariable, int, aimInfo, status){ if (geomSelect != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 1691, __func__, 1, "AIM_ALLOC: %s != NULL" , "geomSelect"); goto cleanup; } size_t memorysize = numDesignVariable ; geomSelect = (int *) EG_alloc(memorysize*sizeof(int)); if ( geomSelect == ((void*)0)) { status = -4; aim_status(aimInfo, status , "fun3dUtils.c", 1691, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "geomSelect", memorysize, "int"); goto cleanup; } }; |
1692 | |
1693 | // Determine number of geometry input variables |
1694 | |
1695 | for (i = 0; i < numDesignVariable; i++) { |
1696 | geomSelect[i] = (int) false0; |
1697 | |
1698 | printf("DesignVariable = %s\n", designVariable[i].name); |
1699 | |
1700 | index = aim_getIndex(aimInfo, designVariable[i].name, GEOMETRYIN); |
1701 | if (index == CAPS_NOTFOUND-303) continue; |
1702 | if (index < CAPS_SUCCESS0 ) { |
1703 | status = index; |
1704 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1704, __func__, 0); goto cleanup; }; |
1705 | } |
1706 | |
1707 | if(aim_getGeomInType(aimInfo, index) != 0) { |
1708 | AIM_ERROR(aimInfo, "GeometryIn value %s is a configuration parameter and not a valid design parameter - can't get sensitivity\n",{ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 1709, __func__ , "GeometryIn value %s is a configuration parameter and not a valid design parameter - can't get sensitivity\n" , designVariable[i].name); } |
1709 | designVariable[i].name){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 1709, __func__ , "GeometryIn value %s is a configuration parameter and not a valid design parameter - can't get sensitivity\n" , designVariable[i].name); }; |
1710 | status = CAPS_BADVALUE-311; |
1711 | goto cleanup; |
1712 | } |
1713 | |
1714 | |
1715 | status = aim_getValue(aimInfo, index, GEOMETRYIN, &geomInVal); |
1716 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1716, __func__, 0); goto cleanup; }; |
1717 | |
1718 | numOutVariable += 3*geomInVal->length; // xD1, yD1, zD1, ... |
1719 | |
1720 | // Don't compute sensitivities if not needed |
1721 | geomSelect[i] = (int) true1; |
1722 | } |
1723 | |
1724 | // No need to write Rubberize files without GeometryIn design variables |
1725 | if (numOutVariable == 4) { |
1726 | status = CAPS_SUCCESS0; |
1727 | goto cleanup; |
1728 | } |
1729 | |
1730 | if (numOutVariable > 99999999) { |
1731 | AIM_ERROR(aimInfo, "Array of design variable names will be over-run!"){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 1731, __func__ , "Array of design variable names will be over-run!"); }; |
1732 | status = CAPS_RANGEERR-326; |
1733 | goto cleanup; |
1734 | } |
1735 | |
1736 | // Allocate our names |
1737 | AIM_ALLOC(dataOutName, numOutVariable, char*, aimInfo, status){ if (dataOutName != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 1737, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutName"); goto cleanup; } size_t memorysize = numOutVariable ; dataOutName = (char* *) EG_alloc(memorysize*sizeof(char*)); if (dataOutName == ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 1737, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutName", memorysize, "char*"); goto cleanup; } }; |
1738 | for (i = 0; i < numOutVariable; i++) dataOutName[i] = NULL((void*)0); |
1739 | |
1740 | stringLength = 11; |
1741 | j = 1; |
1742 | k = 1; |
1743 | for (i = 0; i < numOutVariable; i++) { |
1744 | AIM_ALLOC(dataOutName[i], stringLength+1, char, aimInfo, status){ if (dataOutName[i] != ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 1744, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutName[i]"); goto cleanup; } size_t memorysize = stringLength +1; dataOutName[i] = (char *) EG_alloc(memorysize*sizeof(char )); if (dataOutName[i] == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 1744, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutName[i]", memorysize, "char"); goto cleanup; } }; |
1745 | |
1746 | // Set names |
1747 | if (i == 0) snprintf(dataOutName[i], stringLength+1, "%s", "x"); |
1748 | else if (i == 1) snprintf(dataOutName[i], stringLength+1, "%s", "y"); |
1749 | else if (i == 2) snprintf(dataOutName[i], stringLength+1, "%s", "z"); |
1750 | else if (i == 3) snprintf(dataOutName[i], stringLength+1, "%s", "id"); |
1751 | else { |
1752 | |
1753 | if (j == 1) snprintf(dataOutName[i], stringLength+1, "%s%d", "xD", k); |
1754 | else if (j == 2) snprintf(dataOutName[i], stringLength+1, "%s%d", "yD", k); |
1755 | else if (j == 3) { |
1756 | snprintf(dataOutName[i], stringLength+1, "%s%d", "zD", k); |
1757 | j = 0; |
1758 | k += 1; |
1759 | } |
1760 | j += 1; |
1761 | } |
1762 | } |
1763 | |
1764 | AIM_ALLOC(dataOutFormat, numOutVariable, int, aimInfo, status){ if (dataOutFormat != ((void*)0)) { status = -4; aim_status( aimInfo, status, "fun3dUtils.c", 1764, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutFormat"); goto cleanup; } size_t memorysize = numOutVariable ; dataOutFormat = (int *) EG_alloc(memorysize*sizeof(int)); if (dataOutFormat == ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 1764, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutFormat", memorysize, "int"); goto cleanup; } }; |
1765 | |
1766 | // Set data out formatting |
1767 | for (i = 0; i < numOutVariable; i++) { |
1768 | if (strcasecmp(dataOutName[i], "id") == 0) { |
1769 | dataOutFormat[i] = (int) Integer; |
1770 | } else { |
1771 | dataOutFormat[i] = (int) Double; |
1772 | } |
1773 | } |
1774 | |
1775 | // Allocate data arrays that are going to be output |
1776 | AIM_ALLOC(dataOutMatrix, meshRef->nmap, double**, aimInfo, status){ if (dataOutMatrix != ((void*)0)) { status = -4; aim_status( aimInfo, status, "fun3dUtils.c", 1776, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutMatrix"); goto cleanup; } size_t memorysize = meshRef ->nmap; dataOutMatrix = (double** *) EG_alloc(memorysize*sizeof (double**)); if (dataOutMatrix == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 1776, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutMatrix", memorysize, "double**"); goto cleanup; } }; |
1777 | for (i = 0; i < meshRef->nmap; i++) dataOutMatrix[i] = NULL((void*)0); |
1778 | |
1779 | for (i = 0; i < meshRef->nmap; i++) { |
1780 | AIM_ALLOC(dataOutMatrix[i], numOutVariable, double*, aimInfo, status){ if (dataOutMatrix[i] != ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 1780, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutMatrix[i]"); goto cleanup; } size_t memorysize = numOutVariable ; dataOutMatrix[i] = (double* *) EG_alloc(memorysize*sizeof(double *)); if (dataOutMatrix[i] == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 1780, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutMatrix[i]", memorysize, "double*"); goto cleanup; } }; |
1781 | for (j = 0; j < numOutVariable; j++) dataOutMatrix[i][j] = NULL((void*)0); |
1782 | } |
1783 | |
1784 | for (i = 0; i < meshRef->nmap; i++) { |
1785 | if (meshRef->maps[i].tess == NULL((void*)0)) continue; |
1786 | |
1787 | status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &numOutDataPoint); |
1788 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1788, __func__, 0); goto cleanup; }; |
1789 | |
1790 | // allocate data arrays |
1791 | for (j = 0; j < numOutVariable; j++) { |
1792 | AIM_ALLOC(dataOutMatrix[i][j], numOutDataPoint, double, aimInfo, status){ if (dataOutMatrix[i][j] != ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 1792, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutMatrix[i][j]"); goto cleanup; } size_t memorysize = numOutDataPoint; dataOutMatrix[i][j] = (double *) EG_alloc(memorysize *sizeof(double)); if (dataOutMatrix[i][j] == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c", 1792, __func__ , 3, "AIM_ALLOC: %s size %zu type %s", "dataOutMatrix[i][j]", memorysize, "double"); goto cleanup; } }; |
1793 | } |
1794 | |
1795 | for (iglobal = 0; iglobal < numOutDataPoint; iglobal++) { |
1796 | status = EG_getGlobal(meshRef->maps[i].tess, |
1797 | iglobal+1, &ptype, &pindex, xyz); |
1798 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1798, __func__, 0); goto cleanup; }; |
1799 | |
1800 | // First just set the Coordinates |
1801 | dataOutMatrix[i][0][iglobal] = xyz[0]; |
1802 | dataOutMatrix[i][1][iglobal] = xyz[1]; |
1803 | dataOutMatrix[i][2][iglobal] = xyz[2]; |
1804 | |
1805 | // Volume mesh node ID |
1806 | dataOutMatrix[i][3][iglobal] = meshRef->maps[i].map[iglobal]; |
1807 | } |
1808 | } |
1809 | |
1810 | // Loop over the geometry in values and compute sensitivities for all bodies |
1811 | m = 4; |
1812 | for (j = 0; j < numDesignVariable; j++) { |
1813 | |
1814 | if (geomSelect[j] == (int) false0) continue; |
1815 | |
1816 | geomInName = designVariable[j].name; |
1817 | index = aim_getIndex(aimInfo, geomInName, GEOMETRYIN); |
1818 | |
1819 | status = aim_getValue(aimInfo, index, GEOMETRYIN, &geomInVal); |
1820 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1820, __func__, 0); goto cleanup; }; |
1821 | |
1822 | for (row = 0; row < geomInVal->nrow; row++) { |
1823 | for (col = 0; col < geomInVal->ncol; col++) { |
1824 | |
1825 | for (i = 0; i < meshRef->nmap; i++) { |
1826 | if (meshRef->maps[i].tess == NULL((void*)0)) continue; |
1827 | status = aim_tessSensitivity(aimInfo, |
1828 | geomInName, |
1829 | row+1, col+1, // row, col |
1830 | meshRef->maps[i].tess, |
1831 | &numPoint, &dxyz); |
1832 | AIM_STATUS(aimInfo, status, "Sensitivity for: %s\n", geomInName)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1832, __func__, 2, "Sensitivity for: %s\n", geomInName); goto cleanup; }; |
1833 | AIM_NOTNULL(dxyz, aimInfo, status){ if (dxyz == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 1833, __func__, 1, "%s == NULL!", "dxyz" ); goto cleanup; } }; |
1834 | |
1835 | for (k = 0; k < numPoint; k++) { |
1836 | dataOutMatrix[i][m+0][k] = dxyz[3*k + 0]; // dx/dGeomIn |
1837 | dataOutMatrix[i][m+1][k] = dxyz[3*k + 1]; // dy/dGeomIn |
1838 | dataOutMatrix[i][m+2][k] = dxyz[3*k + 2]; // dz/dGeomIn |
1839 | } |
1840 | AIM_FREE(dxyz){ EG_free(dxyz); dxyz = ((void*)0); }; |
1841 | } |
1842 | m += 3; |
1843 | } |
1844 | } |
1845 | } |
1846 | |
1847 | // Write sensitivity files for each body tessellation |
1848 | |
1849 | for (i = 0; i < meshRef->nmap; i++) { |
1850 | if (meshRef->maps[i].tess == NULL((void*)0)) continue; |
1851 | status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &numOutDataPoint); |
1852 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1852, __func__, 0); goto cleanup; }; |
1853 | |
1854 | // check if the tessellation has a mixture of quad and tess |
1855 | status = EG_attributeRet(meshRef->maps[i].tess, ".mixed", |
1856 | &atype, &alen, &nquad, &reals, &string); |
1857 | if (status != EGADS_SUCCESS0 && |
1858 | status != EGADS_NOTFOUND-1) AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1858, __func__, 0); goto cleanup; }; |
1859 | |
1860 | status = EG_getBodyTopos(body, NULL((void*)0), FACE23, &nFace, &faces); |
1861 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1861, __func__, 0); goto cleanup; }; |
1862 | |
1863 | ielem = 0; |
1864 | numOutDataConnect = 0; |
1865 | for (iface = 0; iface < nFace; iface++) { |
1866 | // get the face tessellation |
1867 | status = EG_getTessFace(meshRef->maps[i].tess, iface+1, &alen, &face_xyz, &face_uv, |
1868 | &face_ptype, &face_pindex, &ntri, &face_tris, &face_tric); |
1869 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1869, __func__, 0); goto cleanup; }; |
1870 | |
1871 | if (nquad == NULL((void*)0)) { // all triangles |
1872 | |
1873 | // re-allocate data arrays |
1874 | AIM_REALL(dataConnectMatrix, 4*(numOutDataConnect + ntri), int, aimInfo, status){ size_t memorysize = 4*(numOutDataConnect + ntri); dataConnectMatrix = (int *) EG_reall(dataConnectMatrix, memorysize*sizeof(int) ); if (dataConnectMatrix == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 1874, __func__, 3, "AIM_REALL: %s size %zu type %s" , "dataConnectMatrix", memorysize, "int"); goto cleanup; } }; |
1875 | |
1876 | for (itri = 0; itri < ntri; itri++, ielem++) { |
1877 | for (j = 0; j < 3; j++) { |
1878 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &iglobal); |
1879 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1879, __func__, 0); goto cleanup; }; |
1880 | dataConnectMatrix[4*ielem+j] = iglobal; |
1881 | } |
1882 | // repeat the last node for triangles |
1883 | dataConnectMatrix[4*ielem+3] = dataConnectMatrix[4*ielem+2]; |
1884 | } |
1885 | |
1886 | numOutDataConnect += ntri; |
1887 | |
1888 | } else { // mixture of tri and quad elements |
1889 | |
1890 | // re-allocate data arrays |
1891 | AIM_REALL(dataConnectMatrix, 4*(numOutDataConnect + ntri-nquad[iface]), int, aimInfo, status){ size_t memorysize = 4*(numOutDataConnect + ntri-nquad[iface ]); dataConnectMatrix = (int *) EG_reall(dataConnectMatrix, memorysize *sizeof(int)); if (dataConnectMatrix == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c", 1891, __func__ , 3, "AIM_REALL: %s size %zu type %s", "dataConnectMatrix", memorysize , "int"); goto cleanup; } }; |
1892 | |
1893 | // process triangles |
1894 | for (itri = 0; itri < ntri-2*nquad[iface]; itri++, ielem++) { |
1895 | for (j = 0; j < 3; j++) { |
1896 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &iglobal); |
1897 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1897, __func__, 0); goto cleanup; }; |
1898 | dataConnectMatrix[4*ielem+j] = iglobal; |
1899 | } |
1900 | // repeat the last node for triangle |
1901 | dataConnectMatrix[4*ielem+3] = dataConnectMatrix[4*ielem+2]; |
1902 | } |
1903 | // process quads |
1904 | for (; itri < ntri; itri++, ielem++) { |
1905 | for (j = 0; j < 3; j++) { |
1906 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &iglobal); |
1907 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1907, __func__, 0); goto cleanup; }; |
1908 | dataConnectMatrix[4*ielem+j] = iglobal; |
1909 | } |
1910 | |
1911 | // add the last node from the 2nd triangle to make the quad |
1912 | itri++; |
1913 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+2], &iglobal); |
1914 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1914, __func__, 0); goto cleanup; }; |
1915 | dataConnectMatrix[4*ielem+3] = iglobal; |
1916 | } |
1917 | |
1918 | numOutDataConnect += ntri-nquad[iface]; |
1919 | } |
1920 | |
1921 | } |
1922 | AIM_FREE(faces){ EG_free(faces); faces = ((void*)0); }; |
1923 | |
1924 | snprintf(message,100,"%s %d,", "sensitivity file for body", i+1); |
1925 | |
1926 | stringLength = strlen(folder) + 1 + strlen(filePre) + 7 + strlen(fileExt) + 1 ; |
1927 | |
1928 | AIM_REALL(filename, stringLength, char, aimInfo, status){ size_t memorysize = stringLength; filename = (char *) EG_reall (filename, memorysize*sizeof(char)); if (filename == ((void*) 0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c" , 1928, __func__, 3, "AIM_REALL: %s size %zu type %s", "filename" , memorysize, "char"); goto cleanup; } }; |
1929 | |
1930 | #ifdef WIN32 |
1931 | snprintf(filename, stringLength, "%s\\%s%d%s", folder, filePre, i+1, fileExt); |
1932 | #else |
1933 | snprintf(filename, stringLength, "%s/%s%d%s", folder, filePre, i+1, fileExt); |
1934 | #endif |
1935 | |
1936 | snprintf(zoneTitle, 100, "%s_%d", "Body", i+1); |
1937 | /*@-nullpass@*/ |
1938 | status = tecplot_writeFEPOINT(aimInfo, |
1939 | filename, |
1940 | message, |
1941 | zoneTitle, |
1942 | numOutVariable, |
1943 | dataOutName, |
1944 | numOutDataPoint, |
1945 | dataOutMatrix[i], |
1946 | dataOutFormat, |
1947 | numOutDataConnect, |
1948 | dataConnectMatrix, |
1949 | NULL((void*)0)); |
1950 | /*@+nullpass@*/ |
1951 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 1951, __func__, 0); goto cleanup; }; |
1952 | } |
1953 | |
1954 | status = CAPS_SUCCESS0; |
1955 | |
1956 | cleanup: |
1957 | (void) string_freeArray(numOutVariable, &dataOutName); |
1958 | #ifdef S_SPLINT_S |
1959 | EG_free(dataOutName); |
1960 | #endif |
1961 | |
1962 | if (dataOutMatrix != NULL((void*)0)) { |
1963 | for (i = 0; i < meshRef->nmap; i++) { |
1964 | if (dataOutMatrix[i] != NULL((void*)0)) { |
1965 | for (j = 0; j < numOutVariable; j++) { |
1966 | AIM_FREE(dataOutMatrix[i][j]){ EG_free(dataOutMatrix[i][j]); dataOutMatrix[i][j] = ((void* )0); }; |
1967 | } |
1968 | } |
1969 | AIM_FREE(dataOutMatrix[i]){ EG_free(dataOutMatrix[i]); dataOutMatrix[i] = ((void*)0); }; |
1970 | } |
1971 | } |
1972 | |
1973 | AIM_FREE(dataOutMatrix){ EG_free(dataOutMatrix); dataOutMatrix = ((void*)0); }; |
1974 | AIM_FREE(dataOutFormat){ EG_free(dataOutFormat); dataOutFormat = ((void*)0); }; |
1975 | AIM_FREE(dataConnectMatrix){ EG_free(dataConnectMatrix); dataConnectMatrix = ((void*)0); }; |
1976 | AIM_FREE(faces){ EG_free(faces); faces = ((void*)0); }; |
1977 | |
1978 | AIM_FREE(dxyz){ EG_free(dxyz); dxyz = ((void*)0); }; |
1979 | AIM_FREE(filename){ EG_free(filename); filename = ((void*)0); }; |
1980 | AIM_FREE(geomSelect){ EG_free(geomSelect); geomSelect = ((void*)0); }; |
1981 | |
1982 | return status; |
1983 | } |
1984 | |
1985 | |
1986 | // Write FUN3D surface file |
1987 | // Will dump out the body meshes in 'filename'_body#.dat files. |
1988 | // If combine == True all surfaces will be added to a single file; if |
1989 | // combine == False each surface representing a geometric body will be |
1990 | // written to an individual file. |
1991 | int fun3d_writeSurface(void *aimInfo, |
1992 | aimMeshRef *meshRef, |
1993 | char *filename, |
1994 | int combine) |
1995 | { |
1996 | |
1997 | int status; // Function return status |
1998 | |
1999 | int i, j, k, nodeOffset=0, connectOffset=0; // Indexing |
2000 | |
2001 | int stringLength = 7; |
2002 | |
2003 | // Data transfer Out variables |
2004 | char **dataOutName= NULL((void*)0); |
2005 | |
2006 | double **dataOutMatrix = NULL((void*)0); |
2007 | int *dataOutFormat = NULL((void*)0); |
2008 | int *dataConnectMatrix = NULL((void*)0); |
2009 | |
2010 | int numOutVariable = 4; // x, y, z, id |
2011 | int numOutDataPoint = 0, numNode = 0; |
2012 | int numOutDataConnect = 0; |
2013 | |
2014 | // Variables used in global node mapping |
2015 | int ptype, pindex; |
2016 | double xyz[3]; |
2017 | |
2018 | double *dxyz = NULL((void*)0); |
2019 | |
2020 | int iface; |
2021 | int state, nFace; |
2022 | ego body, *faces=NULL((void*)0); |
2023 | |
2024 | int alen, ntri, atype, itri, ielem; |
2025 | const double *face_xyz, *face_uv, *reals; |
2026 | const int *face_ptype, *face_pindex, *face_tris, *face_tric, *nquad=NULL((void*)0); |
2027 | const char *string; |
2028 | |
2029 | char message[100]; |
2030 | char *fileExt = ".dat"; |
2031 | char *fileBody = "_body"; |
2032 | char *fname = NULL((void*)0); |
2033 | char zoneTitle[100]; |
2034 | |
2035 | // Allocate our names |
2036 | AIM_ALLOC(dataOutName, numOutVariable, char*, aimInfo, status){ if (dataOutName != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 2036, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutName"); goto cleanup; } size_t memorysize = numOutVariable ; dataOutName = (char* *) EG_alloc(memorysize*sizeof(char*)); if (dataOutName == ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 2036, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutName", memorysize, "char*"); goto cleanup; } }; |
2037 | for (i = 0; i < numOutVariable; i++) dataOutName[i] = NULL((void*)0); |
2038 | |
2039 | stringLength = 11; |
2040 | |
2041 | for (i = 0; i < numOutVariable; i++) { |
2042 | |
2043 | AIM_ALLOC(dataOutName[i], stringLength+1, char, aimInfo, status){ if (dataOutName[i] != ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 2043, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutName[i]"); goto cleanup; } size_t memorysize = stringLength +1; dataOutName[i] = (char *) EG_alloc(memorysize*sizeof(char )); if (dataOutName[i] == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 2043, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutName[i]", memorysize, "char"); goto cleanup; } }; |
2044 | |
2045 | // Set names |
2046 | if (i == 0) snprintf(dataOutName[i], stringLength+1, "%s", "x"); |
2047 | else if (i == 1) snprintf(dataOutName[i], stringLength+1, "%s", "y"); |
2048 | else if (i == 2) snprintf(dataOutName[i], stringLength+1, "%s", "z"); |
2049 | else snprintf(dataOutName[i], stringLength+1, "%s", "id"); |
2050 | } |
2051 | |
2052 | // Allocate our variable type |
2053 | AIM_ALLOC(dataOutFormat, numOutVariable, int, aimInfo, status){ if (dataOutFormat != ((void*)0)) { status = -4; aim_status( aimInfo, status, "fun3dUtils.c", 2053, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutFormat"); goto cleanup; } size_t memorysize = numOutVariable ; dataOutFormat = (int *) EG_alloc(memorysize*sizeof(int)); if (dataOutFormat == ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 2053, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutFormat", memorysize, "int"); goto cleanup; } }; |
2054 | |
2055 | // Set data out formatting |
2056 | for (i = 0; i < numOutVariable; i++) { |
2057 | if (strcasecmp(dataOutName[i], "id") == 0) { |
2058 | dataOutFormat[i] = (int) Integer; |
2059 | } else { |
2060 | dataOutFormat[i] = (int) Double; |
2061 | } |
2062 | } |
2063 | |
2064 | // Allocate data arrays that are going to be output |
2065 | AIM_ALLOC(dataOutMatrix, numOutVariable, double*, aimInfo, status){ if (dataOutMatrix != ((void*)0)) { status = -4; aim_status( aimInfo, status, "fun3dUtils.c", 2065, __func__, 1, "AIM_ALLOC: %s != NULL" , "dataOutMatrix"); goto cleanup; } size_t memorysize = numOutVariable ; dataOutMatrix = (double* *) EG_alloc(memorysize*sizeof(double *)); if (dataOutMatrix == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 2065, __func__, 3, "AIM_ALLOC: %s size %zu type %s" , "dataOutMatrix", memorysize, "double*"); goto cleanup; } }; |
2066 | for (i = 0; i < numOutVariable; i++) dataOutMatrix[i] = NULL((void*)0); |
2067 | |
2068 | // Loop through bodies |
2069 | for (i = 0; i < meshRef->nmap; i++) { |
2070 | if (meshRef->maps[i].tess != NULL((void*)0)) { |
2071 | |
2072 | // |
2073 | // Get node locations and global index |
2074 | // |
2075 | |
2076 | status = EG_statusTessBody(meshRef->maps[i].tess, &body, &state, &numNode); |
2077 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2077, __func__, 0); goto cleanup; }; |
2078 | |
2079 | if (combine == (int) true1) numOutDataPoint += numNode; |
2080 | else numOutDataPoint = numNode; |
2081 | |
2082 | // Allocate data arrays |
2083 | for (j = 0; j < numOutVariable; j++) { |
2084 | AIM_REALL(dataOutMatrix[j], numOutDataPoint, double, aimInfo, status){ size_t memorysize = numOutDataPoint; dataOutMatrix[j] = (double *) EG_reall(dataOutMatrix[j], memorysize*sizeof(double)); if (dataOutMatrix[j] == ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 2084, __func__, 3, "AIM_REALL: %s size %zu type %s" , "dataOutMatrix[j]", memorysize, "double"); goto cleanup; } }; |
2085 | } |
2086 | |
2087 | for (j = 0; j < numNode; j++) { |
2088 | status = EG_getGlobal(meshRef->maps[i].tess, j+1, &ptype, &pindex, xyz); |
2089 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2089, __func__, 0); goto cleanup; }; |
2090 | |
2091 | // First just set the Coordinates |
2092 | dataOutMatrix[0][j+nodeOffset] = xyz[0]; |
2093 | dataOutMatrix[1][j+nodeOffset] = xyz[1]; |
2094 | dataOutMatrix[2][j+nodeOffset] = xyz[2]; |
2095 | |
2096 | // Volume mesh node ID |
2097 | dataOutMatrix[3][j+nodeOffset] = meshRef->maps[i].map[j]; |
2098 | } |
2099 | |
2100 | // |
2101 | // Get connectivity |
2102 | // |
2103 | |
2104 | // check if the tessellation has a mixture of quad and tess |
2105 | status = EG_attributeRet(meshRef->maps[i].tess, ".mixed", &atype, &alen, &nquad, &reals, &string); |
2106 | if (status != EGADS_SUCCESS0 && |
2107 | status != EGADS_NOTFOUND-1) AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2107, __func__, 0); goto cleanup; }; |
2108 | |
2109 | status = EG_getBodyTopos(body, NULL((void*)0), FACE23, &nFace, &faces); |
2110 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2110, __func__, 0); goto cleanup; }; |
2111 | |
2112 | ielem = 0; |
2113 | |
2114 | for (iface = 0; iface < nFace; iface++) { |
2115 | // get the face tessellation |
2116 | status = EG_getTessFace(meshRef->maps[i].tess, iface+1, &alen, &face_xyz, &face_uv, |
2117 | &face_ptype, &face_pindex, &ntri, &face_tris, &face_tric); |
2118 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2118, __func__, 0); goto cleanup; }; |
2119 | |
2120 | if (nquad == NULL((void*)0)) { // all triangles |
2121 | |
2122 | // re-allocate data arrays |
2123 | AIM_REALL(dataConnectMatrix, 4*(numOutDataConnect + ntri), int, aimInfo, status){ size_t memorysize = 4*(numOutDataConnect + ntri); dataConnectMatrix = (int *) EG_reall(dataConnectMatrix, memorysize*sizeof(int) ); if (dataConnectMatrix == ((void*)0)) { status = -4; aim_status (aimInfo, status, "fun3dUtils.c", 2123, __func__, 3, "AIM_REALL: %s size %zu type %s" , "dataConnectMatrix", memorysize, "int"); goto cleanup; } }; |
2124 | |
2125 | for (itri = 0; itri < ntri; itri++, ielem++) { |
2126 | for (j = 0; j < 3; j++) { |
2127 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &k); |
2128 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2128, __func__, 0); goto cleanup; }; |
2129 | |
2130 | dataConnectMatrix[4*(ielem+connectOffset)+j] = k+nodeOffset; |
2131 | } |
2132 | // repeat the last node for triangles |
2133 | dataConnectMatrix[4*(ielem+connectOffset)+3] = dataConnectMatrix[4*(ielem+connectOffset)+2]; |
2134 | } |
2135 | |
2136 | numOutDataConnect += ntri; |
2137 | |
2138 | } else { // mixture of tri and quad elements |
2139 | |
2140 | // re-allocate data arrays |
2141 | AIM_REALL(dataConnectMatrix, 4*(numOutDataConnect + ntri-nquad[iface]), int, aimInfo, status){ size_t memorysize = 4*(numOutDataConnect + ntri-nquad[iface ]); dataConnectMatrix = (int *) EG_reall(dataConnectMatrix, memorysize *sizeof(int)); if (dataConnectMatrix == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c", 2141, __func__ , 3, "AIM_REALL: %s size %zu type %s", "dataConnectMatrix", memorysize , "int"); goto cleanup; } }; |
2142 | |
2143 | // process triangles |
2144 | for (itri = 0; itri < ntri-2*nquad[iface]; itri++, ielem++) { |
2145 | for (j = 0; j < 3; j++) { |
2146 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &k); |
2147 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2147, __func__, 0); goto cleanup; }; |
2148 | |
2149 | dataConnectMatrix[4*(ielem+connectOffset)+j] = k+nodeOffset; |
2150 | } |
2151 | // repeat the last node for triangle |
2152 | dataConnectMatrix[4*(ielem+connectOffset)+3] = dataConnectMatrix[4*(ielem+connectOffset)+2]; |
2153 | } |
2154 | // process quads |
2155 | for (; itri < ntri; itri++, ielem++) { |
2156 | for (j = 0; j < 3; j++) { |
2157 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+j], &k); |
2158 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2158, __func__, 0); goto cleanup; }; |
2159 | |
2160 | dataConnectMatrix[4*(ielem+connectOffset)+j] = k+nodeOffset; |
2161 | } |
2162 | |
2163 | // add the last node from the 2nd triangle to make the quad |
2164 | itri++; |
2165 | status = EG_localToGlobal(meshRef->maps[i].tess, iface+1, face_tris[3*itri+2], &k); |
2166 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2166, __func__, 0); goto cleanup; }; |
2167 | |
2168 | dataConnectMatrix[4*(ielem+connectOffset)+3] = k+nodeOffset; |
2169 | } |
2170 | |
2171 | numOutDataConnect += ntri-nquad[iface]; |
2172 | } |
2173 | } |
2174 | |
2175 | AIM_FREE(faces){ EG_free(faces); faces = ((void*)0); }; |
2176 | |
2177 | |
2178 | // Write file |
2179 | if (combine == (int) true1) { |
2180 | |
2181 | nodeOffset = numOutDataPoint; |
2182 | connectOffset = numOutDataConnect; |
2183 | |
2184 | /// Need to keep writing - otherwise may never write if the last ->tess is null |
2185 | //if (i < meshRef->nmap - 1) continue; // Do NOT write a mesh until the last body |
2186 | |
2187 | snprintf(message,100,"surface file for %d (of %d) in body 1", 1, meshRef->nmap); |
2188 | |
2189 | stringLength = strlen(filename) + strlen("fileBody") + 7 + strlen(fileExt) + 1 ; |
2190 | |
2191 | AIM_REALL(fname, stringLength, char, aimInfo, status){ size_t memorysize = stringLength; fname = (char *) EG_reall (fname, memorysize*sizeof(char)); if (fname == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c", 2191, __func__ , 3, "AIM_REALL: %s size %zu type %s", "fname", memorysize, "char" ); goto cleanup; } }; |
2192 | |
2193 | snprintf(fname, stringLength, "%s%s%d%s", filename, fileBody, 1, fileExt); |
2194 | |
2195 | snprintf(zoneTitle,100, "%s_%d", "Body", 1); |
2196 | |
2197 | } else { |
2198 | |
2199 | nodeOffset = 0; |
2200 | connectOffset = 0; |
2201 | |
2202 | snprintf(message,100,"surface file for body %d (of %d)", i+1, meshRef->nmap); |
2203 | |
2204 | stringLength = strlen(filename) + strlen("fileBody") + 7 + strlen(fileExt) + 1 ; |
2205 | |
2206 | AIM_REALL(fname, stringLength, char, aimInfo, status){ size_t memorysize = stringLength; fname = (char *) EG_reall (fname, memorysize*sizeof(char)); if (fname == ((void*)0)) { status = -4; aim_status(aimInfo, status, "fun3dUtils.c", 2206, __func__ , 3, "AIM_REALL: %s size %zu type %s", "fname", memorysize, "char" ); goto cleanup; } }; |
2207 | |
2208 | snprintf(fname, stringLength, "%s%s%d%s", filename, fileBody, i+1, fileExt); |
2209 | |
2210 | snprintf(zoneTitle,100, "%s_%d", "Body", i+1); |
2211 | |
2212 | } |
2213 | |
2214 | /*@-nullpass@*/ |
2215 | status = tecplot_writeFEPOINT(aimInfo, |
2216 | fname, |
2217 | message, |
2218 | zoneTitle, |
2219 | numOutVariable, |
2220 | dataOutName, |
2221 | numOutDataPoint, |
2222 | dataOutMatrix, |
2223 | dataOutFormat, |
2224 | numOutDataConnect, |
2225 | dataConnectMatrix, |
2226 | NULL((void*)0)); |
2227 | /*@+nullpass@*/ |
2228 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2228, __func__, 0); goto cleanup; }; |
2229 | |
2230 | if (combine == (int) false0) numOutDataConnect = 0; // Reset counter |
2231 | } |
2232 | } |
2233 | |
2234 | status = CAPS_SUCCESS0; |
2235 | |
2236 | cleanup: |
2237 | |
2238 | (void) string_freeArray(numOutVariable, &dataOutName); |
2239 | #ifdef S_SPLINT_S |
2240 | EG_free(dataOutName); |
2241 | #endif |
2242 | |
2243 | if (dataOutMatrix != NULL((void*)0)) { |
2244 | for (i = 0; i < numOutVariable; i++) { |
2245 | AIM_FREE(dataOutMatrix[i]){ EG_free(dataOutMatrix[i]); dataOutMatrix[i] = ((void*)0); }; |
2246 | } |
2247 | } |
2248 | |
2249 | AIM_FREE(dataOutMatrix){ EG_free(dataOutMatrix); dataOutMatrix = ((void*)0); }; |
2250 | AIM_FREE(dataOutFormat){ EG_free(dataOutFormat); dataOutFormat = ((void*)0); }; |
2251 | AIM_FREE(dataConnectMatrix){ EG_free(dataConnectMatrix); dataConnectMatrix = ((void*)0); }; |
2252 | AIM_FREE(faces){ EG_free(faces); faces = ((void*)0); }; |
2253 | |
2254 | AIM_FREE(dxyz){ EG_free(dxyz); dxyz = ((void*)0); }; |
2255 | AIM_FREE(fname){ EG_free(fname); fname = ((void*)0); }; |
2256 | |
2257 | return status; |
2258 | } |
2259 | |
2260 | |
2261 | static int _writeFunctinoalComponent(void *aimInfo, FILE *fp, cfdDesignFunctionalCompStruct *comp) |
2262 | { |
2263 | int status = CAPS_SUCCESS0; |
2264 | |
2265 | const char *names[] = {"cl", "cd", // Lift, drag coefficients |
2266 | "clp", "cdp", // Lift, drag coefficients: pressure contributions |
2267 | "clv", "cdv", // Lift, drag coefficients: shear contributions |
2268 | "cmx", "cmy", "cmz", // x/y/z-axis moment coefficients |
2269 | "cmxp", "cmyp", "cmzp", // x/y/z-axis moment coefficients: pressure contributions |
2270 | "cmxv", "cmyv", "cmzv", // x/y/z-axis moment coefficients: shear contributions |
2271 | "cx", "cy", "cz", // x/y/z-axis force coefficients |
2272 | "cxp", "cyp", "czp", // x/y/z-axis force coefficients: pressure contributions |
2273 | "cxv", "cyv", "czv", // x/y/z-axis force coefficients: shear contributions |
2274 | "powerx", "powery", "powerz", // x/y/z-axis power coefficients |
2275 | "clcd", // Lift-to-drag ratio |
2276 | "fom" , // Rotorcraft figure of merit |
2277 | "propeff", // Rotorcraft propulsive efficiency |
2278 | "rtr" , // thrust Rotorcraft thrust function |
2279 | "pstag" , // RMS of stagnation pressure in cutting plane disk |
2280 | "distort", // Engine inflow distortion |
2281 | "boom" , // targ Near-field p/p∞ pressure target |
2282 | "sboom" , // Coupled sBOOM ground-based noise metrics |
2283 | "ae" , // Supersonic equivalent area target distribution |
2284 | "press" , // box RMS of pressure in user-defined box, also pointwise dp/dt, dρ/dt |
2285 | "cpstar" , // Target pressure distributions |
2286 | "sgen" // Entropy generation |
2287 | }; |
2288 | |
2289 | int i, found = (int)false0; |
2290 | char *function=NULL((void*)0), *c=NULL((void*)0); |
2291 | |
2292 | for (i = 0; i < sizeof(names)/sizeof(char*); i++) |
2293 | if ( strcasecmp(names[i], comp->name) == 0 ) { |
2294 | found = (int)true1; |
2295 | break; |
2296 | } |
2297 | |
2298 | if (found == (int) false0) { |
2299 | AIM_ERROR(aimInfo, "Unknown function: '%s'", comp->name){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 2299, __func__ , "Unknown function: '%s'", comp->name); }; |
2300 | AIM_ADDLINE(aimInfo, "Available functions:"){ aim_addLine(aimInfo, "Available functions:"); }; |
2301 | for (i = 0; i < sizeof(names)/sizeof(char*); i++) |
2302 | AIM_ADDLINE(aimInfo, "'%s'", names[i]){ aim_addLine(aimInfo, "'%s'", names[i]); }; |
2303 | status = CAPS_BADVALUE-311; |
2304 | goto cleanup; |
2305 | } |
2306 | |
2307 | // make the name lower case |
2308 | AIM_STRDUP(function, comp->name, aimInfo, status){ if (function != ((void*)0)) { status = -4; aim_status(aimInfo , status, "fun3dUtils.c", 2308, __func__, 1, "AIM_STRDUP: %s != NULL!" , "function"); goto cleanup; } function = EG_strdup(comp-> name); if (function == ((void*)0)) { status = -4; aim_status( aimInfo, status, "fun3dUtils.c", 2308, __func__, 2, "AIM_STRDUP: %s %s" , "function", comp->name); goto cleanup; } }; |
2309 | for (c = function; *c != '\0'; ++c) *c = tolower(*c)(__extension__ ({ int __res; if (sizeof (*c) > 1) { if (__builtin_constant_p (*c)) { int __c = (*c); __res = __c < -128 || __c > 255 ? __c : (*__ctype_tolower_loc ())[__c]; } else __res = tolower (*c); } else __res = (*__ctype_tolower_loc ())[(int) (*c)]; __res ; })); |
2310 | |
2311 | // fprintf(fp, "Components of function 1: boundary id (0=all)/name/value/weight/target/power\n"); |
2312 | fprintf(fp, " %d %s %f %f %f %f\n", comp->bcID, |
2313 | function, |
2314 | 0.0, |
2315 | comp->weight, |
2316 | comp->target, |
2317 | comp->power); |
2318 | |
2319 | status = CAPS_SUCCESS0; |
2320 | |
2321 | cleanup: |
2322 | AIM_FREE(function){ EG_free(function); function = ((void*)0); }; |
2323 | return status; |
2324 | } |
2325 | |
2326 | |
2327 | // Write FUN3D rubber.data file |
2328 | // Will not write shape entries unless explicitly told to check if they are need |
2329 | int fun3d_writeRubber(void *aimInfo, |
2330 | cfdDesignStruct design, |
2331 | int checkGeomShape, |
2332 | double fun3dVersion, |
2333 | aimMeshRef *meshRef) |
2334 | { |
2335 | int status; // Function return status |
2336 | |
2337 | int i, j, k, m; // Indexing |
2338 | |
2339 | int numBody = 0, numShapeVar = 0; |
2340 | |
2341 | char file[] = "rubber.data"; |
2342 | FILE *fp = NULL((void*)0); |
2343 | |
2344 | printf("Writing %s \n", file); |
2345 | if (meshRef == NULL((void*)0)) return CAPS_NULLVALUE-307; |
2346 | |
2347 | // Open file |
2348 | fp = aim_fopen(aimInfo, file, "w"); |
2349 | if (fp == NULL((void*)0)) { |
2350 | AIM_ERROR(aimInfo, "Unable to open file: %s\n", file){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 2350, __func__ , "Unable to open file: %s\n", file); }; |
2351 | status = CAPS_IOERR-332; |
2352 | goto cleanup; |
2353 | } |
2354 | |
2355 | numBody = meshRef->nmap; |
2356 | |
2357 | if (checkGeomShape == (int) true1) { |
2358 | // Determine number of geometry input variables |
2359 | for (i = 0; i < design.numDesignVariable; i++) { |
2360 | |
2361 | if (design.designVariable[i].type != DesignVariableGeometry) continue; |
2362 | |
2363 | numShapeVar += design.designVariable[i].var->length; // xD1, yD1, zD1, ... |
2364 | } |
2365 | } |
2366 | |
2367 | // Don't write out body information if there are no geometry design variables |
2368 | if (numShapeVar == 0) numBody = 0; |
2369 | |
2370 | |
2371 | fprintf(fp, "################################################################################\n"); |
2372 | fprintf(fp, "########################### Design Variable Information ########################\n"); |
2373 | fprintf(fp, "################################################################################\n"); |
2374 | fprintf(fp, "Global design variables (Mach number, AOA, Yaw, Noninertial rates)\n"); |
2375 | fprintf(fp, "Var Active Value Lower Bound Upper Bound\n"); |
2376 | |
2377 | for (i = 0; i < design.numDesignVariable; i++) { |
2378 | |
2379 | if (strcasecmp(design.designVariable[i].name, "Mach") != 0) continue; |
2380 | |
2381 | if (design.designVariable[i].var->length < 1) { |
2382 | status = CAPS_RANGEERR-326; |
2383 | goto cleanup; |
2384 | } |
2385 | |
2386 | fprintf(fp, "Mach 1 %.15E %.15E %.15E\n", design.designVariable[i].value[0], |
2387 | design.designVariable[i].lowerBound[0], |
2388 | design.designVariable[i].upperBound[0]); |
2389 | break; |
2390 | } |
2391 | |
2392 | if (i >= design.numDesignVariable) fprintf(fp, "Mach 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2393 | |
2394 | for (i = 0; i < design.numDesignVariable; i++) { |
2395 | |
2396 | if (strcasecmp(design.designVariable[i].name, "Alpha") != 0) continue; |
2397 | |
2398 | if (design.designVariable[i].var->length < 1) { |
2399 | status = CAPS_RANGEERR-326; |
2400 | goto cleanup; |
2401 | } |
2402 | |
2403 | fprintf(fp, "AOA 1 %.15E %.15E %.15E\n", design.designVariable[i].value[0], |
2404 | design.designVariable[i].lowerBound[0], |
2405 | design.designVariable[i].upperBound[0]); |
2406 | break; |
2407 | } |
2408 | |
2409 | if (i >= design.numDesignVariable) fprintf(fp, "AOA 0 0.000000000000000E+00 0.000000000000000E+00 0.00000000000000E+00\n"); |
2410 | |
2411 | |
2412 | if (fun3dVersion > 12.4) { |
2413 | // FUN3D version 13.1 - version 12.4 doesn't have these available |
2414 | |
2415 | for (i = 0; i < design.numDesignVariable; i++) { |
2416 | |
2417 | if (strcasecmp(design.designVariable[i].name, "Beta") != 0) continue; |
2418 | |
2419 | if (design.designVariable[i].var->length < 1) { |
2420 | status = CAPS_RANGEERR-326; |
2421 | goto cleanup; |
2422 | } |
2423 | |
2424 | fprintf(fp, "Yaw 1 %.15E %.15E %.15E\n", design.designVariable[i].value[0], |
2425 | design.designVariable[i].lowerBound[0], |
2426 | design.designVariable[i].upperBound[0]); |
2427 | break; |
2428 | } |
2429 | |
2430 | if (i >= design.numDesignVariable) fprintf(fp, "Yaw 0 0.000000000000000E+00 0.000000000000000E+00 0.00000000000000E+00\n"); |
2431 | |
2432 | for (i = 0; i < design.numDesignVariable; i++) { |
2433 | |
2434 | if (strcasecmp(design.designVariable[i].name, "NonInertial_Rotation_Rate") != 0) continue; |
2435 | |
2436 | if (design.designVariable[i].var->length < 3) { |
2437 | status = CAPS_RANGEERR-326; |
2438 | goto cleanup; |
2439 | } |
2440 | |
2441 | fprintf(fp, "xrate 1 %.15E %.15E %.15E\n", design.designVariable[i].value[0], |
2442 | design.designVariable[i].lowerBound[0], |
2443 | design.designVariable[i].upperBound[0]); |
2444 | break; |
2445 | } |
2446 | |
2447 | if (i >= design.numDesignVariable) fprintf(fp, "xrate 0 0.000000000000000E+00 0.000000000000000E+00 0.00000000000000E+00\n"); |
2448 | |
2449 | for (i = 0; i < design.numDesignVariable; i++) { |
2450 | |
2451 | if (strcasecmp(design.designVariable[i].name, "NonInertial_Rotation_Rate") != 0) continue; |
2452 | |
2453 | if (design.designVariable[i].var->length < 3) { |
2454 | status = CAPS_RANGEERR-326; |
2455 | goto cleanup; |
2456 | } |
2457 | |
2458 | fprintf(fp, "yrate 1 %.15E %.15E %.15E\n", design.designVariable[i].value[1], |
2459 | design.designVariable[i].lowerBound[1], |
2460 | design.designVariable[i].upperBound[1]); |
2461 | break; |
2462 | } |
2463 | |
2464 | if (i >= design.numDesignVariable) fprintf(fp, "yrate 0 0.000000000000000E+00 0.000000000000000E+00 0.00000000000000E+00\n"); |
2465 | |
2466 | for (i = 0; i < design.numDesignVariable; i++) { |
2467 | |
2468 | if (strcasecmp(design.designVariable[i].name, "NonInertial_Rotation_Rate") != 0) continue; |
2469 | |
2470 | if (design.designVariable[i].var->length < 3) { |
2471 | status = CAPS_RANGEERR-326; |
2472 | goto cleanup; |
2473 | } |
2474 | |
2475 | fprintf(fp, "zrate 1 %.15E %.15E %.15E\n", design.designVariable[i].value[2], |
2476 | design.designVariable[i].lowerBound[2], |
2477 | design.designVariable[i].upperBound[2]); |
2478 | break; |
2479 | } |
2480 | |
2481 | if (i >= design.numDesignVariable) fprintf(fp, "zrate 0 0.000000000000000E+00 0.000000000000000E+00 0.00000000000000E+00\n"); |
2482 | } |
2483 | |
2484 | fprintf(fp, "Number of bodies\n"); |
2485 | fprintf(fp, "%d\n", numBody); |
2486 | for (i = 0; i < numBody; i++) { |
2487 | fprintf(fp, "Rigid motion design variables for 'Body %d'\n", i+1); |
2488 | fprintf(fp, "Var Active Value Lower Bound Upper Bound\n"); |
2489 | fprintf(fp, "RotRate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2490 | fprintf(fp, "RotFreq 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2491 | fprintf(fp, "RotAmpl 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2492 | fprintf(fp, "RotOrgx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2493 | fprintf(fp, "RotOrgy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2494 | fprintf(fp, "RotOrgz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2495 | fprintf(fp, "RotVecx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2496 | fprintf(fp, "RotVecy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2497 | fprintf(fp, "RotVecz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2498 | fprintf(fp, "TrnRate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2499 | fprintf(fp, "TrnFreq 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2500 | fprintf(fp, "TrnAmpl 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2501 | fprintf(fp, "TrnVecx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2502 | fprintf(fp, "TrnVecy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2503 | fprintf(fp, "TrnVecz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00\n"); |
2504 | if (fun3dVersion > 12.4) { |
2505 | // FUN3D version 13.1 - version 12.4 doesn't have option 5 |
2506 | fprintf(fp, "Parameterization Scheme (Massoud=1 Bandaids=2 Sculptor=4 User-Defined=5)\n"); |
2507 | fprintf(fp, "5\n"); |
2508 | } else { |
2509 | |
2510 | fprintf(fp, "Parameterization Scheme (Massoud=1 Bandaids=2 Sculptor=4)\n"); |
2511 | fprintf(fp, "1\n"); |
2512 | } |
2513 | |
2514 | fprintf(fp, "Number of shape variables for 'Body %d'\n", i+1); |
2515 | fprintf(fp, "%d\n", numShapeVar); |
2516 | fprintf(fp, "Index Active Value Lower Bound Upper Bound\n"); |
2517 | |
2518 | m = 1; |
2519 | for (j = 0; j < design.numDesignVariable; j++) { |
2520 | |
2521 | if (design.designVariable[j].type != DesignVariableGeometry) continue; |
2522 | |
2523 | for (k = 0; k < design.designVariable[j].var->length; k++ ) { |
2524 | |
2525 | fprintf(fp, "%d 1 %.15E %.15E %.15E\n", m, design.designVariable[j].value[k], |
2526 | design.designVariable[j].lowerBound[k], |
2527 | design.designVariable[j].upperBound[k]); |
2528 | |
2529 | m += 1; |
2530 | } |
2531 | } |
2532 | } |
2533 | |
2534 | fprintf(fp, "################################################################################\n"); |
2535 | fprintf(fp, "############################### Function Information ###########################\n"); |
2536 | fprintf(fp, "################################################################################\n"); |
2537 | fprintf(fp, "Number of composite functions for design problem statement\n"); |
2538 | fprintf(fp, "%d\n", design.numDesignFunctional); |
2539 | |
2540 | for (i = 0; i < design.numDesignFunctional; i++) { |
2541 | fprintf(fp, "################################################################################\n"); |
2542 | fprintf(fp, "Cost function (1) or constraint (2)\n"); |
2543 | fprintf(fp, "1\n"); |
2544 | fprintf(fp, "If constraint, lower and upper bounds\n"); |
2545 | fprintf(fp, "0.0 0.0\n"); |
2546 | fprintf(fp, "Number of components for function %d\n", i+1); |
2547 | fprintf(fp, "%d\n", design.designFunctional[i].numComponent); |
2548 | fprintf(fp, "Physical timestep interval where function is defined\n"); |
2549 | fprintf(fp, "1 1\n"); |
2550 | fprintf(fp, "Composite function weight, target, and power\n"); |
2551 | fprintf(fp, "1.0 0.0 1.0\n"); |
2552 | fprintf(fp, "Components of function %d: boundary id (0=all)/name/value/weight/target/power\n", i+1); |
2553 | |
2554 | for (j = 0; j < design.designFunctional[i].numComponent; j++) { |
2555 | //fprintf(fp, "0 clcd 0.000000000000000 1.000 10.00000 2.000\n"); |
2556 | status = _writeFunctinoalComponent(aimInfo, fp, &design.designFunctional[i].component[j]); |
2557 | if (status != CAPS_SUCCESS0) goto cleanup; |
2558 | } |
2559 | |
2560 | fprintf(fp, "Current value of function %d\n", i+1); |
2561 | fprintf(fp, "0.000000000000000\n"); |
2562 | fprintf(fp, "Current derivatives of function wrt global design variables\n"); |
2563 | fprintf(fp, "0.000000000000000\n"); |
2564 | fprintf(fp, "0.000000000000000\n"); |
2565 | |
2566 | if (fun3dVersion > 12.4) { |
2567 | // FUN3D version 13.1 - version 12.4 doesn't have these available |
2568 | fprintf(fp, "0.000000000000000\n"); // Yaw |
2569 | fprintf(fp, "0.000000000000000\n"); // xrate |
2570 | fprintf(fp, "0.000000000000000\n"); // yrate |
2571 | fprintf(fp, "0.000000000000000\n"); // zrate |
2572 | } |
2573 | |
2574 | for (j = 0; j < numBody; j++) { |
2575 | fprintf(fp, "Current derivatives of function wrt rigid motion design variables of body %d\n", j+1); |
2576 | fprintf(fp, "0.000000000000000\n"); |
2577 | fprintf(fp, "0.000000000000000\n"); |
2578 | fprintf(fp, "0.000000000000000\n"); |
2579 | fprintf(fp, "0.000000000000000\n"); |
2580 | fprintf(fp, "0.000000000000000\n"); |
2581 | fprintf(fp, "0.000000000000000\n"); |
2582 | fprintf(fp, "0.000000000000000\n"); |
2583 | fprintf(fp, "0.000000000000000\n"); |
2584 | fprintf(fp, "0.000000000000000\n"); |
2585 | fprintf(fp, "0.000000000000000\n"); |
2586 | fprintf(fp, "0.000000000000000\n"); |
2587 | fprintf(fp, "0.000000000000000\n"); |
2588 | fprintf(fp, "0.000000000000000\n"); |
2589 | fprintf(fp, "0.000000000000000\n"); |
2590 | fprintf(fp, "0.000000000000000\n"); |
2591 | fprintf(fp, "Current derivatives of function wrt shape design variables of body %d\n", j+1); |
2592 | |
2593 | for (k = 0; k < design.numDesignVariable; k++) { |
2594 | |
2595 | if (design.designVariable[k].type != DesignVariableGeometry) continue; |
2596 | |
2597 | for (m = 0; m < design.designVariable[k].var->length; m++ ) fprintf(fp, "0.000000000000000\n"); |
2598 | } |
2599 | } |
2600 | } |
2601 | |
2602 | status = CAPS_SUCCESS0; |
2603 | |
2604 | cleanup: |
2605 | if (status != CAPS_SUCCESS0) |
2606 | printf("Error: Premature exit in fun3d_writeRubber status = %d\n", |
2607 | status); |
2608 | |
2609 | if (fp != NULL((void*)0)) fclose(fp); |
2610 | |
2611 | return status; |
2612 | |
2613 | /* Version 13.1 - template |
2614 | ################################################################################ |
2615 | ########################### Design Variable Information ######################## |
2616 | ################################################################################ |
2617 | Global design variables (Mach number, AOA, Yaw, Noninertial rates) |
2618 | Var Active Value Lower Bound Upper Bound |
2619 | Mach 0 0.800000000000000E+00 0.000000000000000E+00 0.900000000000000E+00 |
2620 | AOA 1 1.000000000000000E+00 0.000000000000000E+00 5.000000000000000E+00 |
2621 | Yaw 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2622 | xrate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2623 | yrate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2624 | zrate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2625 | Number of bodies |
2626 | 2 |
2627 | Rigid motion design variables for 'wing' |
2628 | Var Active Value Lower Bound Upper Bound |
2629 | RotRate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2630 | RotFreq 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2631 | RotAmpl 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2632 | RotOrgx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2633 | RotOrgy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2634 | RotOrgz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2635 | RotVecx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2636 | RotVecy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2637 | RotVecz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2638 | TrnRate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2639 | TrnFreq 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2640 | TrnAmpl 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2641 | TrnVecx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2642 | TrnVecy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2643 | TrnVecz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2644 | Parameterization Scheme (Massoud=1 Bandaids=2 Sculptor=4 User-Defined=5) |
2645 | 1 |
2646 | Number of shape variables for 'wing' |
2647 | 3 |
2648 | Index Active Value Lower Bound Upper Bound |
2649 | 1 1 1.000000000000000E+00 0.000000000000000E+00 2.000000000000000E+00 |
2650 | 2 1 1.000000000000000E+00 0.000000000000000E+00 2.000000000000000E+00 |
2651 | 3 1 1.000000000000000E+00 0.000000000000000E+00 2.000000000000000E+00 |
2652 | Rigid motion design variables for 'tail' |
2653 | Var Active Value Lower Bound Upper Bound |
2654 | RotRate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2655 | RotFreq 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2656 | RotAmpl 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2657 | RotOrgx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2658 | RotOrgy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2659 | RotOrgz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2660 | RotVecx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2661 | RotVecy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2662 | RotVecz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2663 | TrnRate 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2664 | TrnFreq 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2665 | TrnAmpl 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2666 | TrnVecx 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2667 | TrnVecy 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2668 | TrnVecz 0 0.000000000000000E+00 0.000000000000000E+00 0.000000000000000E+00 |
2669 | Parameterization Scheme (Massoud=1 Bandaids=2 Sculptor=4 User-Defined=5) |
2670 | 2 |
2671 | Number of shape variables for 'tail' |
2672 | 2 |
2673 | Index Active Value Lower Bound Upper Bound |
2674 | 1 1 2.000000000000000E+00 -1.000000000000000E+00 5.000000000000000E+00 |
2675 | 2 1 2.000000000000000E+00 -1.000000000000000E+00 5.000000000000000E+00 |
2676 | ################################################################################ |
2677 | ############################### Function Information ########################### |
2678 | ################################################################################ |
2679 | Number of composite functions for design problem statement |
2680 | 2 |
2681 | ################################################################################ |
2682 | Cost function (1) or constraint (2) |
2683 | 1 |
2684 | If constraint, lower and upper bounds |
2685 | 0.0 0.0 |
2686 | Number of components for function 1 |
2687 | 1 |
2688 | Physical timestep interval where function is defined |
2689 | 1 1 |
2690 | Composite function weight, target, and power |
2691 | 1.0 0.0 1.0 |
2692 | Components of function 1: boundary id (0=all)/name/value/weight/target/power |
2693 | 0 cl 0.000000000000000 1.000 10.00000 2.000 |
2694 | Current value of function 1 |
2695 | 0.000000000000000 |
2696 | Current derivatives of function wrt global design variables |
2697 | 0.000000000000000 |
2698 | 0.000000000000000 |
2699 | 0.000000000000000 |
2700 | 0.000000000000000 |
2701 | 0.000000000000000 |
2702 | 0.000000000000000 |
2703 | Current derivatives of function wrt rigid motion design variables of body 1 |
2704 | 0.000000000000000 |
2705 | 0.000000000000000 |
2706 | 0.000000000000000 |
2707 | 0.000000000000000 |
2708 | 0.000000000000000 |
2709 | 0.000000000000000 |
2710 | 0.000000000000000 |
2711 | 0.000000000000000 |
2712 | 0.000000000000000 |
2713 | 0.000000000000000 |
2714 | 0.000000000000000 |
2715 | 0.000000000000000 |
2716 | 0.000000000000000 |
2717 | 0.000000000000000 |
2718 | 0.000000000000000 |
2719 | Current derivatives of function wrt shape design variables of body 1 |
2720 | 0.000000000000000 |
2721 | 0.000000000000000 |
2722 | 0.000000000000000 |
2723 | Current derivatives of function wrt rigid motion design variables of body 2 |
2724 | 0.000000000000000 |
2725 | 0.000000000000000 |
2726 | 0.000000000000000 |
2727 | 0.000000000000000 |
2728 | 0.000000000000000 |
2729 | 0.000000000000000 |
2730 | 0.000000000000000 |
2731 | 0.000000000000000 |
2732 | 0.000000000000000 |
2733 | 0.000000000000000 |
2734 | 0.000000000000000 |
2735 | 0.000000000000000 |
2736 | 0.000000000000000 |
2737 | 0.000000000000000 |
2738 | 0.000000000000000 |
2739 | Current derivatives of function wrt shape design variables of body 2 |
2740 | 0.000000000000000 |
2741 | 0.000000000000000 |
2742 | ################################################################################ |
2743 | Cost function (1) or constraint (2) |
2744 | 2 |
2745 | If constraint, lower and upper bounds |
2746 | -0.03 -0.01 |
2747 | Number of components for function 2 |
2748 | 1 |
2749 | Physical timestep interval where function is defined |
2750 | 1 1 |
2751 | Composite function weight, target, and power |
2752 | 1.0 0.0 1.0 |
2753 | Components of function 2: boundary id (0=all)/name/value/weight/target/power |
2754 | 0 cmy 0.000000000000000 1.000 0.00000 1.000 |
2755 | Current value of function 2 |
2756 | 0.000000000000000 |
2757 | Current derivatives of function wrt global design variables |
2758 | 0.000000000000000 |
2759 | 0.000000000000000 |
2760 | 0.000000000000000 |
2761 | 0.000000000000000 |
2762 | 0.000000000000000 |
2763 | 0.000000000000000 |
2764 | Current derivatives of function wrt rigid motion design variables of body 1 |
2765 | 0.000000000000000 |
2766 | 0.000000000000000 |
2767 | 0.000000000000000 |
2768 | 0.000000000000000 |
2769 | 0.000000000000000 |
2770 | 0.000000000000000 |
2771 | 0.000000000000000 |
2772 | 0.000000000000000 |
2773 | 0.000000000000000 |
2774 | 0.000000000000000 |
2775 | 0.000000000000000 |
2776 | 0.000000000000000 |
2777 | 0.000000000000000 |
2778 | 0.000000000000000 |
2779 | 0.000000000000000 |
2780 | Current derivatives of function wrt shape design variables of body 1 |
2781 | 0.000000000000000 |
2782 | 0.000000000000000 |
2783 | 0.000000000000000 |
2784 | Current derivatives of function wrt rigid motion design variables of body 2 |
2785 | 0.000000000000000 |
2786 | 0.000000000000000 |
2787 | 0.000000000000000 |
2788 | 0.000000000000000 |
2789 | 0.000000000000000 |
2790 | 0.000000000000000 |
2791 | 0.000000000000000 |
2792 | 0.000000000000000 |
2793 | 0.000000000000000 |
2794 | 0.000000000000000 |
2795 | 0.000000000000000 |
2796 | 0.000000000000000 |
2797 | 0.000000000000000 |
2798 | 0.000000000000000 |
2799 | 0.000000000000000 |
2800 | Current derivatives of function wrt shape design variables of body 2 |
2801 | 0.000000000000000 |
2802 | 0.000000000000000 |
2803 | */ |
2804 | } |
2805 | |
2806 | // Finds a line in rubber.data that matches header |
2807 | static int _findHeader(const char *header, char **line, size_t *nline, int *iline, FILE *fp) |
2808 | { |
2809 | int i; |
2810 | while (getline(line, nline, fp) != -1) { |
2811 | (*iline)++; |
2812 | if (nline == 0) continue; |
2813 | if ((*line)[0] == '#') continue; |
2814 | i = 0; |
2815 | while ((*line)[i] == ' ' && (*line)[i] != '\0') i++; |
2816 | if (strncasecmp(header, &(*line)[i], strlen(header)) == 0) |
2817 | break; |
2818 | } |
2819 | if (feof(fp)) return CAPS_IOERR-332; |
2820 | |
2821 | return CAPS_SUCCESS0; |
2822 | } |
2823 | |
2824 | |
2825 | // Read objective value and derivatives from FUN3D rubber.data file |
2826 | // Will not read shape entries unless explicitly told to check if they are needed |
2827 | int fun3d_readRubber(void *aimInfo, |
2828 | cfdDesignStruct design, |
2829 | int checkGeomShape, |
2830 | double fun3dVersion, |
2831 | aimMeshRef *meshRef) |
2832 | { |
2833 | int status; // Function return status |
2834 | |
2835 | int i, j, k, ibody; // Indexing |
2836 | |
2837 | int numShapeVar = 0; |
2838 | |
2839 | size_t nline; |
2840 | int iline=0; |
2841 | char *line=NULL((void*)0); |
2842 | char file[] = "rubber.data"; |
2843 | double dfun_dvar = 0; |
2844 | FILE *fp = NULL((void*)0); |
2845 | |
2846 | int numBody; |
2847 | |
2848 | // Get AIM bodies |
2849 | numBody = meshRef->nmap; |
2850 | |
2851 | printf("Reading %s \n", file); |
2852 | |
2853 | // Open file |
2854 | fp = aim_fopen(aimInfo, file, "r"); |
2855 | if (fp == NULL((void*)0)) { |
2856 | AIM_ERROR(aimInfo, "Unable to open file: %s\n", file){ aim_message(aimInfo, CERROR, 0 , "fun3dUtils.c", 2856, __func__ , "Unable to open file: %s\n", file); }; |
2857 | status = CAPS_IOERR-332; |
2858 | goto cleanup; |
2859 | } |
2860 | |
2861 | for (i = 0; i < design.numDesignFunctional; i++) { |
2862 | |
2863 | status = _findHeader("Current value of function", &line, &nline, &iline, fp); |
2864 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2864, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2865 | |
2866 | // Get the line with the objective value |
2867 | status = getline(&line, &nline, fp); iline++; |
2868 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2869 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2869, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2870 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 2870, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
2871 | |
2872 | status = sscanf(line, "%lf", &design.designFunctional[i].value); |
2873 | if (status != 1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2874 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2874, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2875 | |
2876 | // skip: Current derivatives of function wrt rigid motion design variables of |
2877 | status = getline(&line, &nline, fp); iline++; |
2878 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2879 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2879, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2880 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 2880, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
2881 | |
2882 | // read the dFun/dMach |
2883 | status = getline(&line, &nline, fp); iline++; |
2884 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2885 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2885, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2886 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 2886, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
2887 | |
2888 | for (j = 0; j < design.designFunctional[i].numDesignVariable; j++) { |
2889 | |
2890 | if (strcasecmp(design.designFunctional[i].dvar[j].name, "Mach") != 0) continue; |
2891 | |
2892 | status = sscanf(line, "%lf", &design.designFunctional[i].dvar[j].value[0]); |
2893 | if (status != 1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2894 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2894, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2895 | break; |
2896 | } |
2897 | |
2898 | // read the dFun/dAOA |
2899 | status = getline(&line, &nline, fp); iline++; |
2900 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2901 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2901, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2902 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 2902, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
2903 | |
2904 | for (j = 0; j < design.numDesignVariable; j++) { |
2905 | |
2906 | if (strcasecmp(design.designFunctional[i].dvar[j].name, "Alpha") != 0) continue; |
2907 | |
2908 | status = sscanf(line, "%lf", &design.designFunctional[i].dvar[j].value[0]); |
2909 | if (status != 1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2910 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2910, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2911 | break; |
2912 | } |
2913 | |
2914 | if (fun3dVersion > 12.4) { |
2915 | // FUN3D version 13.1 - version 12.4 doesn't have these available |
2916 | |
2917 | // read the dFun/dBeta |
2918 | status = getline(&line, &nline, fp); iline++; |
2919 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2920 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2920, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2921 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 2921, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
2922 | |
2923 | for (j = 0; j < design.designFunctional[i].numDesignVariable; j++) { |
2924 | |
2925 | if (strcasecmp(design.designFunctional[i].dvar[j].name, "Beta") != 0) continue; |
2926 | |
2927 | status = sscanf(line, "%lf", &design.designFunctional[i].dvar[j].value[0]); |
2928 | if (status != 1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2929 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2929, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2930 | break; |
2931 | } |
2932 | |
2933 | // read the dFun/dNonInertial_Rotation_Rate[0] |
2934 | status = getline(&line, &nline, fp); iline++; |
2935 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2936 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2936, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2937 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 2937, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
2938 | |
2939 | for (j = 0; j < design.designFunctional[i].numDesignVariable; j++) { |
2940 | |
2941 | if (strcasecmp(design.designFunctional[i].dvar[j].name, "NonInertial_Rotation_Rate") != 0) continue; |
2942 | |
2943 | status = sscanf(line, "%lf", &design.designFunctional[i].dvar[j].value[0]); |
2944 | if (status != 1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2945 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2945, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2946 | break; |
2947 | } |
2948 | |
2949 | // read the dFun/dNonInertial_Rotation_Rate[1] |
2950 | status = getline(&line, &nline, fp); iline++; |
2951 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2952 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2952, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2953 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 2953, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
2954 | |
2955 | for (j = 0; j < design.designFunctional[i].numDesignVariable; j++) { |
2956 | |
2957 | if (strcasecmp(design.designFunctional[i].dvar[j].name, "NonInertial_Rotation_Rate") != 0) continue; |
2958 | |
2959 | status = sscanf(line, "%lf", &design.designFunctional[i].dvar[j].value[1]); |
2960 | if (status != 1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2961 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2961, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2962 | break; |
2963 | } |
2964 | |
2965 | // read the dFun/dNonInertial_Rotation_Rate[2] |
2966 | status = getline(&line, &nline, fp); iline++; |
2967 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2968 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2968, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2969 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 2969, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
2970 | |
2971 | for (j = 0; j < design.designFunctional[i].numDesignVariable; j++) { |
2972 | |
2973 | if (strcasecmp(design.designFunctional[i].dvar[j].name, "NonInertial_Rotation_Rate") != 0) continue; |
2974 | |
2975 | status = sscanf(line, "%lf", &design.designFunctional[i].dvar[j].value[2]); |
2976 | if (status != 1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
2977 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 2977, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
2978 | break; |
2979 | } |
2980 | } |
2981 | |
2982 | |
2983 | numShapeVar = 0; // Need to re-zero every functional loop |
2984 | |
2985 | if (checkGeomShape == (int) true1) { |
2986 | // zero out previous derivatives |
2987 | for (j = 0; j < design.designFunctional[i].numDesignVariable; j++) { |
2988 | if (design.designFunctional[i].dvar[j].type != DesignVariableGeometry) continue; |
2989 | numShapeVar++; |
2990 | for (k = 0; k < design.designVariable[j].var->length; k++ ) { |
2991 | design.designFunctional[i].dvar[j].value[k] = 0; |
2992 | } |
2993 | } |
2994 | } |
2995 | |
2996 | // No body information if there are no Geometry derivatives |
2997 | if (numShapeVar == 0) numBody = 0; |
2998 | |
2999 | for (ibody = 0; ibody < numBody; ibody++) { |
3000 | |
3001 | // Rigid motion design variables |
3002 | status = _findHeader("Current derivatives of", &line, &nline, &iline, fp); |
3003 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 3003, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
3004 | |
3005 | // Skip reading rigid motion design variables for now |
3006 | |
3007 | // Read shape design variables |
3008 | status = _findHeader("Current derivatives of", &line, &nline, &iline, fp); |
3009 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 3009, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
3010 | |
3011 | for (j = 0; j < design.designFunctional[i].numDesignVariable; j++) { |
3012 | |
3013 | if (design.designFunctional[i].dvar[j].type != DesignVariableGeometry) continue; |
3014 | |
3015 | for (k = 0; k < design.designVariable[j].var->length; k++ ) { |
3016 | |
3017 | // read the dFun/dDesignVar[k] |
3018 | status = getline(&line, &nline, fp); iline++; |
3019 | if (status == -1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
3020 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 3020, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
3021 | AIM_NOTNULL(line, aimInfo, status){ if (line == ((void*)0)) { status = -307; aim_status(aimInfo , status, "fun3dUtils.c", 3021, __func__, 1, "%s == NULL!", "line" ); goto cleanup; } }; |
3022 | |
3023 | status = sscanf(line, "%lf", &dfun_dvar); |
3024 | if (status != 1) status = CAPS_IOERR-332; else status = CAPS_SUCCESS0; |
3025 | AIM_STATUS(aimInfo, status, "rubber.data line %d", iline)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 3025, __func__, 2, "rubber.data line %d", iline); goto cleanup ; }; |
3026 | |
3027 | // accumulate derivatives across bodies |
3028 | design.designFunctional[i].dvar[j].value[k] += dfun_dvar; |
3029 | } |
3030 | } |
3031 | } |
3032 | } |
3033 | |
3034 | status = CAPS_SUCCESS0; |
3035 | |
3036 | cleanup: |
3037 | |
3038 | if (line != NULL((void*)0)) free(line); // Must use free! |
3039 | if (fp != NULL((void*)0)) fclose(fp); |
3040 | |
3041 | return status; |
3042 | } |
3043 | |
3044 | // Make FUN3D directory structure/tree |
3045 | int fun3d_makeDirectory(void *aimInfo) |
3046 | { |
3047 | int status; // Function return status |
3048 | |
3049 | char filename[PATH_MAX4096]; |
3050 | |
3051 | char flow[] = "Flow"; |
3052 | char datafile[] = "datafiles"; |
3053 | char adjoint[] = "Adjoint"; |
3054 | char rubber[] = "Rubberize"; |
3055 | |
3056 | printf("Creating FUN3D directory tree\n"); |
3057 | |
3058 | // Flow |
3059 | status = aim_mkDir(aimInfo, flow); |
3060 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 3060, __func__, 0); goto cleanup; }; |
3061 | |
3062 | // Datafiles |
3063 | snprintf(filename, PATH_MAX4096, "%s/%s", flow, datafile); |
3064 | status = aim_mkDir(aimInfo, filename); |
3065 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 3065, __func__, 0); goto cleanup; }; |
3066 | |
3067 | // Adjoint |
3068 | status = aim_mkDir(aimInfo, adjoint); |
3069 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 3069, __func__, 0); goto cleanup; }; |
3070 | |
3071 | // Rubber |
3072 | status = aim_mkDir(aimInfo, rubber); |
3073 | AIM_STATUS(aimInfo, status)if (status != 0) { aim_status(aimInfo, status, "fun3dUtils.c" , 3073, __func__, 0); goto cleanup; }; |
3074 | |
3075 | status = CAPS_SUCCESS0; |
3076 | |
3077 | cleanup: |
3078 | return status; |
3079 | } |