-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlulesh-viz.cc
304 lines (252 loc) · 8.63 KB
/
lulesh-viz.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "lulesh.h"
#ifdef VIZ_MESH
#ifdef __cplusplus
extern "C" {
#endif
#include "silo.h"
#ifdef __cplusplus
}
#endif
// Function prototypes
static void
DumpDomainToVisit(DBfile *db, Domain& domain, int myRank);
static
void
DumpMultiblockObjects(DBfile *db, char basename[], int numRanks);
/**********************************************************************/
void DumpToVisit(Domain& domain, int numFiles, int myRank, int numRanks)
{
char subdirName[32];
char basename[32];
DBfile *db;
sprintf(basename, "lulesh_plot_c%d", domain.cycle());
sprintf(subdirName, "data_%d", myRank);
db = (DBfile*)DBCreate(basename, DB_CLOBBER, DB_LOCAL, NULL, DB_HDF5X);
if (db) {
DBMkDir(db, subdirName);
DBSetDir(db, subdirName);
DumpDomainToVisit(db, domain, myRank);
DumpMultiblockObjects(db, basename, numRanks);
DBClose(db);
}
else {
printf("Error writing out viz file - rank %d\n", myRank);
}
}
/**********************************************************************/
static void
DumpDomainToVisit(DBfile *db, Domain& domain, int myRank)
{
int ok = 0;
/* Create an option list that will give some hints to VisIt for
* printing out the cycle and time in the annotations */
DBoptlist *optlist;
/* Write out the mesh connectivity in fully unstructured format */
int shapetype[1] = {DB_ZONETYPE_HEX};
int shapesize[1] = {8};
int shapecnt[1] = {domain.numElem()};
int *conn = new int[domain.numElem()*8] ;
int ci = 0 ;
for (int ei=0; ei < domain.numElem(); ++ei) {
Index_t *elemToNode = domain.nodelist(ei) ;
for (int ni=0; ni < 8; ++ni) {
conn[ci++] = elemToNode[ni] ;
}
}
ok += DBPutZonelist2(db, "connectivity", domain.numElem(), 3,
conn, domain.numElem()*8,
0,0,0, /* Not carrying ghost zones */
shapetype, shapesize, shapecnt,
1, NULL);
delete [] conn ;
/* Write out the mesh coordinates associated with the mesh */
const char* coordnames[3] = {"X", "Y", "Z"};
float *coords[3] ;
coords[0] = new float[domain.numNode()] ;
coords[1] = new float[domain.numNode()] ;
coords[2] = new float[domain.numNode()] ;
for (int ni=0; ni < domain.numNode() ; ++ni) {
coords[0][ni] = float(domain.x(ni)) ;
coords[1][ni] = float(domain.y(ni)) ;
coords[2][ni] = float(domain.z(ni)) ;
}
optlist = DBMakeOptlist(2);
ok += DBAddOption(optlist, DBOPT_DTIME, &domain.time());
ok += DBAddOption(optlist, DBOPT_CYCLE, &domain.cycle());
ok += DBPutUcdmesh(db, "mesh", 3, (char**)&coordnames[0], (float**)coords,
domain.numNode(), domain.numElem(), "connectivity",
0, DB_FLOAT, optlist);
ok += DBFreeOptlist(optlist);
delete [] coords[2] ;
delete [] coords[1] ;
delete [] coords[0] ;
/* Write out the materials */
int *matnums = new int[domain.numReg()];
int dims[1] = {domain.numElem()}; // No mixed elements
for(int i=0 ; i<domain.numReg() ; ++i)
matnums[i] = i+1;
ok += DBPutMaterial(db, "regions", "mesh", domain.numReg(),
matnums, domain.regNumList(), dims, 1,
NULL, NULL, NULL, NULL, 0, DB_FLOAT, NULL);
delete [] matnums;
/* Write out pressure, energy, relvol, q */
float *e = new float[domain.numElem()] ;
for (int ei=0; ei < domain.numElem(); ++ei) {
e[ei] = float(domain.e(ei)) ;
}
ok += DBPutUcdvar1(db, "e", "mesh", e,
domain.numElem(), NULL, 0, DB_FLOAT, DB_ZONECENT,
NULL);
delete [] e ;
float *p = new float[domain.numElem()] ;
for (int ei=0; ei < domain.numElem(); ++ei) {
p[ei] = float(domain.p(ei)) ;
}
ok += DBPutUcdvar1(db, "p", "mesh", p,
domain.numElem(), NULL, 0, DB_FLOAT, DB_ZONECENT,
NULL);
delete [] p ;
float *v = new float[domain.numElem()] ;
for (int ei=0; ei < domain.numElem(); ++ei) {
v[ei] = float(domain.v(ei)) ;
}
ok += DBPutUcdvar1(db, "v", "mesh", v,
domain.numElem(), NULL, 0, DB_FLOAT, DB_ZONECENT,
NULL);
delete [] v ;
float *q = new float[domain.numElem()] ;
for (int ei=0; ei < domain.numElem(); ++ei) {
q[ei] = float(domain.q(ei)) ;
}
ok += DBPutUcdvar1(db, "q", "mesh", q,
domain.numElem(), NULL, 0, DB_FLOAT, DB_ZONECENT,
NULL);
delete [] q ;
/* Write out nodal speed, velocities */
float *zd = new float[domain.numNode()];
float *yd = new float[domain.numNode()];
float *xd = new float[domain.numNode()];
float *speed = new float[domain.numNode()];
for(int ni=0 ; ni < domain.numNode() ; ++ni) {
xd[ni] = float(domain.xd(ni));
yd[ni] = float(domain.yd(ni));
zd[ni] = float(domain.zd(ni));
speed[ni] = float(sqrt((xd[ni]*xd[ni])+(yd[ni]*yd[ni])+(zd[ni]*zd[ni])));
}
ok += DBPutUcdvar1(db, "speed", "mesh", speed,
domain.numNode(), NULL, 0, DB_FLOAT, DB_NODECENT,
NULL);
delete [] speed;
ok += DBPutUcdvar1(db, "xd", "mesh", xd,
domain.numNode(), NULL, 0, DB_FLOAT, DB_NODECENT,
NULL);
delete [] xd ;
ok += DBPutUcdvar1(db, "yd", "mesh", yd,
domain.numNode(), NULL, 0, DB_FLOAT, DB_NODECENT,
NULL);
delete [] yd ;
ok += DBPutUcdvar1(db, "zd", "mesh", zd,
domain.numNode(), NULL, 0, DB_FLOAT, DB_NODECENT,
NULL);
delete [] zd ;
if (ok != 0) {
printf("Error writing out viz file - rank %d\n", myRank);
}
}
/**********************************************************************/
void
DumpMultiblockObjects(DBfile *db, char basename[], int numRanks)
{
/* MULTIBLOCK objects to tie together multiple files */
char **multimeshObjs;
char **multimatObjs;
char ***multivarObjs;
int *blockTypes;
int *varTypes;
int ok = 0;
// Make sure this list matches what's written out above
char vars[][10] = {"p","e","v","q", "speed", "xd", "yd", "zd"};
int numvars = sizeof(vars)/sizeof(vars[0]);
// Reset to the root directory of the silo file
DBSetDir(db, "/");
// Allocate a bunch of space for building up the string names
multimeshObjs = new char*[numRanks];
multimatObjs = new char*[numRanks];
multivarObjs = new char**[numvars];
blockTypes = new int[numRanks];
varTypes = new int[numRanks];
for(int v=0 ; v<numvars ; ++v) {
multivarObjs[v] = new char*[numRanks];
}
for(int i=0 ; i<numRanks ; ++i) {
multimeshObjs[i] = new char[64];
multimatObjs[i] = new char[64];
for(int v=0 ; v<numvars ; ++v) {
multivarObjs[v][i] = new char[64];
}
blockTypes[i] = DB_UCDMESH;
varTypes[i] = DB_UCDVAR;
}
// Build up the multiobject names
for(int i=0 ; i<numRanks ; ++i) {
int iorank = 0;
//delete multivarObjs[i];
if (iorank == 0) {
snprintf(multimeshObjs[i], 64, "/data_%d/mesh", i);
snprintf(multimatObjs[i], 64, "/data_%d/regions",i);
for(int v=0 ; v<numvars ; ++v) {
snprintf(multivarObjs[v][i], 64, "/data_%d/%s", i, vars[v]);
}
}
else {
snprintf(multimeshObjs[i], 64, "%s.%03d:/data_%d/mesh",
basename, iorank, i);
snprintf(multimatObjs[i], 64, "%s.%03d:/data_%d/regions",
basename, iorank, i);
for(int v=0 ; v<numvars ; ++v) {
snprintf(multivarObjs[v][i], 64, "%s.%03d:/data_%d/%s",
basename, iorank, i, vars[v]);
}
}
}
// Now write out the objects
ok += DBPutMultimesh(db, "mesh", numRanks,
(char**)multimeshObjs, blockTypes, NULL);
ok += DBPutMultimat(db, "regions", numRanks,
(char**)multimatObjs, NULL);
for(int v=0 ; v<numvars ; ++v) {
ok += DBPutMultivar(db, vars[v], numRanks,
(char**)multivarObjs[v], varTypes, NULL);
}
for(int v=0; v < numvars; ++v) {
for(int i = 0; i < numRanks; i++) {
delete multivarObjs[v][i];
}
delete multivarObjs[v];
}
// Clean up
for(int i=0 ; i<numRanks ; i++) {
delete multimeshObjs[i];
delete multimatObjs[i];
}
delete [] multimeshObjs;
delete [] multimatObjs;
delete [] multivarObjs;
delete [] blockTypes;
delete [] varTypes;
if (ok != 0) {
printf("Error writing out multiXXX objs to viz file - rank 0\n");
}
}
#else
void DumpToVisit(Domain& domain, int numFiles, int myRank, int numRanks)
{
if (myRank == 0) {
printf("Must enable -DVIZ_MESH at compile time to call DumpDomain\n");
}
}
#endif