NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
cgnsWriter.C
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 /* Implementation of CGNSWriter class */
30 #include "IO/cgnsWriter.H"
31 
32 #include <iostream>
33 #include <cstring>
34 #include <sstream>
35 #include <algorithm>
36 
37 // delete file
39 {
40  std::remove(myCgFileName.c_str());
41 }
42 
43 void cgnsWriter::setUnits(CGNS_ENUMT(MassUnits_t) mu, CGNS_ENUMT(LengthUnits_t) lu,
44  CGNS_ENUMT(TimeUnits_t) tu, CGNS_ENUMT(TemperatureUnits_t) tpu, CGNS_ENUMT(AngleUnits_t) au)
45 {
46  massU = mu;
47  lengthU = lu;
48  timeU = tu;
49  tempU = tpu;
50  angleU = au;
51 }
52 
53 // Note: It is unclear whether or not Rocstar actually uses the coordinates or dimensional quantities.
54 // We store them in the pre-defined maps below. The units defined below are copied directly from what is
55 // seen in Rocstar output files. However, there are some inconsistencies in units of the same quantities
56 // across files. Ideally, we could transfer this information upon remeshing. For now, we use the maps.
57 
58 // Map defining fluid units
60 {
61  // fluid
62  fluidUnitsMap.insert(std::pair<std::string,std::string>("CoordinateX", "m"));
63  fluidUnitsMap.insert(std::pair<std::string,std::string>("CoordinateY", "m"));
64  fluidUnitsMap.insert(std::pair<std::string,std::string>("CoordinateZ", "m"));
65  fluidUnitsMap.insert(std::pair<std::string,std::string>("dispX", "none"));
66  fluidUnitsMap.insert(std::pair<std::string,std::string>("dispY", "none"));
67  fluidUnitsMap.insert(std::pair<std::string,std::string>("dispZ", "none"));
68  fluidUnitsMap.insert(std::pair<std::string,std::string>("gs", "m/s"));
69  fluidUnitsMap.insert(std::pair<std::string,std::string>("rhof", "kg/(m^3)"));
70  fluidUnitsMap.insert(std::pair<std::string,std::string>("rhovfX", "kg/(m^2 s)"));
71  fluidUnitsMap.insert(std::pair<std::string,std::string>("rhovfY", "kg/(m^2 s)"));
72  fluidUnitsMap.insert(std::pair<std::string,std::string>("rhovfZ", "kg/(m^2 s)"));
73  fluidUnitsMap.insert(std::pair<std::string,std::string>("rhoEf", "(J/(m^3))"));
74  fluidUnitsMap.insert(std::pair<std::string,std::string>("pf", "N/(m^2)"));
75  fluidUnitsMap.insert(std::pair<std::string,std::string>("Tf", "K"));
76  fluidUnitsMap.insert(std::pair<std::string,std::string>("af", "m/s"));
77 }
78 
79 // Map defining fluid dimensions
81 {
82  // fluid
83  std::vector<float> dim1 = {0, 1, 0, 0, 0};
84  std::vector<float> dim2 = {0, 0, 0, 0, 0};
85  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateX", dim1));
86  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateY", dim1));
87  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateZ", dim1));
88  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("gs", dim2));
89  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhof", dim2));
90  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhovfX", dim2));
91  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhovfY", dim2));
92  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhovfZ", dim2));
93  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhoEf", dim2));
94  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("pf", dim2));
95  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("Tf", dim2));
96  fluidDimMap.insert(std::pair<std::string,std::vector<float>>("af", dim2));
97 }
98 
99 // Map storing a boolean that determines whether or not the "Magnitude" quantity is
100 // output to CGNS files. Currently not used. Rocstar outputs the magnitudes of some
101 // x-coordinate quantities, as seen below. This is not required functionality for Rocstar
102 // to run, however.
104 {
105  // fluid
106  fluidMagMap.insert(std::pair<std::string,int>("CoordinateX", 0));
107  fluidMagMap.insert(std::pair<std::string,int>("CoordinateY", 0));
108  fluidMagMap.insert(std::pair<std::string,int>("CoordinateZ", 0));
109  fluidMagMap.insert(std::pair<std::string,int>("dispX", 1));
110  fluidMagMap.insert(std::pair<std::string,int>("dispY", 0));
111  fluidMagMap.insert(std::pair<std::string,int>("dispZ", 0));
112  fluidMagMap.insert(std::pair<std::string,int>("gs", 0));
113  fluidMagMap.insert(std::pair<std::string,int>("rhof", 0));
114  fluidMagMap.insert(std::pair<std::string,int>("rhovfX", 1));
115  fluidMagMap.insert(std::pair<std::string,int>("rhovfY", 0));
116  fluidMagMap.insert(std::pair<std::string,int>("rhovfZ", 0));
117  fluidMagMap.insert(std::pair<std::string,int>("rhoEf", 0));
118  fluidMagMap.insert(std::pair<std::string,int>("pf", 0));
119  fluidMagMap.insert(std::pair<std::string,int>("Tf", 0));
120  fluidMagMap.insert(std::pair<std::string,int>("af", 0));
121 }
122 
123 // Map defining ifluid units
125 {
126  // ifluid_ni/ifluid_b/ifluid_nb
127  ifluidUnitsMap.insert(std::pair<std::string,std::string>("CoordinateX", "m"));
128  ifluidUnitsMap.insert(std::pair<std::string,std::string>("CoordinateY", "m"));
129  ifluidUnitsMap.insert(std::pair<std::string,std::string>("CoordinateZ", "m"));
130  ifluidUnitsMap.insert(std::pair<std::string,std::string>("du_alpX", "m"));
131  ifluidUnitsMap.insert(std::pair<std::string,std::string>("du_alpY", "m"));
132  ifluidUnitsMap.insert(std::pair<std::string,std::string>("du_alpZ", "m"));
133  ifluidUnitsMap.insert(std::pair<std::string,std::string>("vmX", "m/s"));
134  ifluidUnitsMap.insert(std::pair<std::string,std::string>("vmY", "m/s"));
135  ifluidUnitsMap.insert(std::pair<std::string,std::string>("vmZ", "m/s"));
136  ifluidUnitsMap.insert(std::pair<std::string,std::string>("mdot_alp", "kg/(m^2s)"));
137  ifluidUnitsMap.insert(std::pair<std::string,std::string>("rhofvf_alpX", "kg/(m^2s)"));
138  ifluidUnitsMap.insert(std::pair<std::string,std::string>("rhofvf_alpY", "kg/(m^2s)"));
139  ifluidUnitsMap.insert(std::pair<std::string,std::string>("rhofvf_alpZ", "kg/(m^2s)"));
140  ifluidUnitsMap.insert(std::pair<std::string,std::string>("Tflm_alp", "K"));
141  ifluidUnitsMap.insert(std::pair<std::string,std::string>("Tb_alp", "K"));
142  ifluidUnitsMap.insert(std::pair<std::string,std::string>("nf_alpX", "none"));
143  ifluidUnitsMap.insert(std::pair<std::string,std::string>("nf_alpY", "none"));
144  ifluidUnitsMap.insert(std::pair<std::string,std::string>("nf_alpZ", "none"));
145  ifluidUnitsMap.insert(std::pair<std::string,std::string>("pf", "Pa"));
146  ifluidUnitsMap.insert(std::pair<std::string,std::string>("tfX", "Pa"));
147  ifluidUnitsMap.insert(std::pair<std::string,std::string>("tfY", "Pa"));
148  ifluidUnitsMap.insert(std::pair<std::string,std::string>("tfZ", "Pa"));
149  ifluidUnitsMap.insert(std::pair<std::string,std::string>("qc", "kgK/(m^2s)"));
150  ifluidUnitsMap.insert(std::pair<std::string,std::string>("qr", "kgK/(m^2s)"));
151  ifluidUnitsMap.insert(std::pair<std::string,std::string>("rhof_alp", "kg/m^3"));
152  ifluidUnitsMap.insert(std::pair<std::string,std::string>("zoomFact", "none"));
153  ifluidUnitsMap.insert(std::pair<std::string,std::string>("gs", "m/s"));
154  ifluidUnitsMap.insert(std::pair<std::string,std::string>("mdot_old", "kg/(m^2 s)"));
155 }
156 
157 // Map defining ifluid dimensions
159 {
160  // ifluid_ni/ifluid_b/ifluid_nb
161  std::vector<float> dim1 = {0, 1, 0, 0, 0};
162  std::vector<float> dim2 = {0, 0, 0, 0, 0};
163  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateX", dim1));
164  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateY", dim1));
165  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateZ", dim1));
166  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("du_alpX", dim2));
167  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("du_alpY", dim2));
168  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("du_alpZ", dim2));
169  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("vmX", dim2));
170  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("vmY", dim2));
171  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("vmZ", dim2));
172  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("mdot_alp", dim2));
173  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhofvf_alpX", dim2));
174  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhofvf_alpY", dim2));
175  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhofvf_alpZ", dim2));
176  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("Tflm_alp", dim2));
177  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("Tb_alp", dim2));
178  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("pf", dim2));
179  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("tfX", dim2));
180  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("tfY", dim2));
181  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("tfZ", dim2));
182  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("qc", dim2));
183  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("qr", dim2));
184  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("rhof_alp", dim2));
185  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("zoomFact", dim2));
186  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("gs", dim2));
187  ifluidDimMap.insert(std::pair<std::string,std::vector<float>>("mdot_old", dim2));
188 }
189 
190 // Map storing magnitude quantities for ifluid files.
192 {
193  // ifluid_ni/ifluid_b/ifluid_nb
194  ifluidMagMap.insert(std::pair<std::string,int>("CoordinateX", 0));
195  ifluidMagMap.insert(std::pair<std::string,int>("CoordinateY", 0));
196  ifluidMagMap.insert(std::pair<std::string,int>("CoordinateZ", 0));
197  ifluidMagMap.insert(std::pair<std::string,int>("du_alpX", 1));
198  ifluidMagMap.insert(std::pair<std::string,int>("du_alpY", 0));
199  ifluidMagMap.insert(std::pair<std::string,int>("du_alpZ", 0));
200  ifluidMagMap.insert(std::pair<std::string,int>("vmX", 1));
201  ifluidMagMap.insert(std::pair<std::string,int>("vmY", 0));
202  ifluidMagMap.insert(std::pair<std::string,int>("vmZ", 0));
203  ifluidMagMap.insert(std::pair<std::string,int>("mdot_alp", 0));
204  ifluidMagMap.insert(std::pair<std::string,int>("rhofvf_alpX", 1));
205  ifluidMagMap.insert(std::pair<std::string,int>("rhofvf_alpY", 0));
206  ifluidMagMap.insert(std::pair<std::string,int>("rhofvf_alpZ", 0));
207  ifluidMagMap.insert(std::pair<std::string,int>("Tflm_alp", 0));
208  ifluidMagMap.insert(std::pair<std::string,int>("Tb_alp", 0));
209  ifluidMagMap.insert(std::pair<std::string,int>("nf_alpX", 1));
210  ifluidMagMap.insert(std::pair<std::string,int>("nf_alpY", 0));
211  ifluidMagMap.insert(std::pair<std::string,int>("nf_alpZ", 0));
212  ifluidMagMap.insert(std::pair<std::string,int>("pf", 0));
213  ifluidMagMap.insert(std::pair<std::string,int>("tfX", 1));
214  ifluidMagMap.insert(std::pair<std::string,int>("tfY", 0));
215  ifluidMagMap.insert(std::pair<std::string,int>("tfZ", 0));
216  ifluidMagMap.insert(std::pair<std::string,int>("qc", 0));
217  ifluidMagMap.insert(std::pair<std::string,int>("qr", 0));
218  ifluidMagMap.insert(std::pair<std::string,int>("rhof_alp", 0));
219  ifluidMagMap.insert(std::pair<std::string,int>("zoomFact", 0));
220  ifluidMagMap.insert(std::pair<std::string,int>("bflag", 0));
221  ifluidMagMap.insert(std::pair<std::string,int>("mdot_old", 0));
222 }
223 
224 // Map defining burn units
226 {
227  // burn, iburn_all
228  burnUnitsMap.insert(std::pair<std::string,std::string>("CoordinateX", "m"));
229  burnUnitsMap.insert(std::pair<std::string,std::string>("CoordinateY", "m"));
230  burnUnitsMap.insert(std::pair<std::string,std::string>("CoordinateZ", "m"));
231  burnUnitsMap.insert(std::pair<std::string,std::string>("pf", "Pa"));
232  burnUnitsMap.insert(std::pair<std::string,std::string>("centersX", "m"));
233  burnUnitsMap.insert(std::pair<std::string,std::string>("centersY", "m"));
234  burnUnitsMap.insert(std::pair<std::string,std::string>("centersZ", "m"));
235  burnUnitsMap.insert(std::pair<std::string,std::string>("rb", "m/s"));
236  burnUnitsMap.insert(std::pair<std::string,std::string>("Tflm", "K"));
237  burnUnitsMap.insert(std::pair<std::string,std::string>("rb_old", "m/s"));
238  burnUnitsMap.insert(std::pair<std::string,std::string>("pf_old", "Pa"));
239  burnUnitsMap.insert(std::pair<std::string,std::string>("pf_alp", "Pa"));
240  burnUnitsMap.insert(std::pair<std::string,std::string>("Tflm_old", "K"));
241 }
242 
243 // Map defining burn dimensions
245 {
246  // burn, iburn_all
247  std::vector<float> dim1 = {0, 1, 0, 0, 0};
248  std::vector<float> dim2 = {0, 0, 0, 0, 0};
249  burnDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateX", dim1));
250  burnDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateY", dim1));
251  burnDimMap.insert(std::pair<std::string,std::vector<float>>("CoordinateZ", dim1));
252  burnDimMap.insert(std::pair<std::string,std::vector<float>>("pf", dim2));
253  burnDimMap.insert(std::pair<std::string,std::vector<float>>("centersX", dim2));
254  burnDimMap.insert(std::pair<std::string,std::vector<float>>("centersY", dim2));
255  burnDimMap.insert(std::pair<std::string,std::vector<float>>("centersZ", dim2));
256  burnDimMap.insert(std::pair<std::string,std::vector<float>>("rb", dim2));
257  burnDimMap.insert(std::pair<std::string,std::vector<float>>("Tflm", dim2));
258  burnDimMap.insert(std::pair<std::string,std::vector<float>>("rb_old", dim2));
259  burnDimMap.insert(std::pair<std::string,std::vector<float>>("pf_old", dim2));
260  burnDimMap.insert(std::pair<std::string,std::vector<float>>("pf_alp", dim2));
261  burnDimMap.insert(std::pair<std::string,std::vector<float>>("Tflm_old", dim2));
262 }
263 
264 // Map storing magnitude quantities for burn files.
266 {
267  // burn, iburn_all
268  burnMagMap.insert(std::pair<std::string,int>("CoordinateX", 0));
269  burnMagMap.insert(std::pair<std::string,int>("CoordinateY", 0));
270  burnMagMap.insert(std::pair<std::string,int>("CoordinateZ", 0));
271  burnMagMap.insert(std::pair<std::string,int>("bflag", 0));
272  burnMagMap.insert(std::pair<std::string,int>("pf", 0));
273  burnMagMap.insert(std::pair<std::string,int>("centersX", 1));
274  burnMagMap.insert(std::pair<std::string,int>("centersY", 0));
275  burnMagMap.insert(std::pair<std::string,int>("centersZ", 0));
276  burnMagMap.insert(std::pair<std::string,int>("rb", 0));
277  burnMagMap.insert(std::pair<std::string,int>("Tflm", 0));
278  burnMagMap.insert(std::pair<std::string,int>("rb_old", 0));
279  burnMagMap.insert(std::pair<std::string,int>("pf_old", 0));
280  burnMagMap.insert(std::pair<std::string,int>("Tflm_old", 0));
281 }
282 
283 // Set type flag for CGNS writer
284 // 0 = volume (fluid)
285 // 1 = surface (ifluid)
286 // 2 = burn (iburn_all, burn)
287 void cgnsWriter::setTypeFlag(int _typeFlag)
288 {
289  typeFlag = _typeFlag;
290 }
291 
292 // Set base time iteration stamp string
293 void cgnsWriter::setBaseItrData(std::string bsitrname, int ntstp, double tval)
294 {
295  baseItrName = bsitrname;
296  nTStep = ntstp;
297  timeLabel = tval;
298 }
299 
300 // Set name and value for CGNS Integral writer
301 void cgnsWriter::setIntData(std::string intname, int intval)
302 {
303  intName = intname;
304  intVal = intval;
305 }
306 
307 // Set CGNS Zone Iterative information
308 void cgnsWriter::setZoneItrData(std::string zitrname, std::string grdptr, std::string slnptr)
309 {
310  zoneItrName = zitrname;
311  gridCrdPntr = grdptr;
312  flowSlnPntr = slnptr;
313 }
314 
315 // Set zones to write to file
316 void cgnsWriter::setZone(std::string zName, CGNS_ENUMT(ZoneType_t) zt)
317 {
318  nZone++;
319  zoneNames.push_back(zName);
320  zoneName = zName;
321  zoneTypes.push_back(zt);
322  zoneType = zt;
323 }
324 
325 // Get number of sections
327 {
328  return sectionNames.size();
329 }
330 
331 // Set local patch sections
332 void cgnsWriter::setSection(std::string sName, CGNS_ENUMT(ElementType_t) st, vect1d<cgsize_t> elmConn)
333 {
334  nSection++;
335  sectionNames.push_back(sName);
336  sectionName = sName;
337  sectionTypes.push_back(st);
338  sectionType = st;
339  elmConns.push_back(elmConn);
340 }
341 
342 // Set global partition sections
343 void cgnsWriter::setGlobalSection(std::string gsName, CGNS_ENUMT(ElementType_t) gst, vect1d<int> gelmConn)
344 {
345  gnSection++;
346  gsectionNames.push_back(gsName);
347  gsectionName = gsName;
348  gsectionTypes.push_back(gst);
349  gsectionType = gst;
350  gelmConns.push_back(gelmConn);
351 }
352 
353 // Set global partition sections.
354 // This overload is for "blank" data sections. For this version of the driver which only supports
355 // tetrahedral meshes, these blank sections include hexahedral and quadrilateral element sections.
356 void cgnsWriter::setGlobalSection(std::string gsName, CGNS_ENUMT(ElementType_t) gst)
357 {
358  gnSection++;
359  gsectionNames.push_back(gsName);
360  gsectionName = gsName;
361  gsectionTypes.push_back(gst);
362  gsectionType = gst;
363  std::vector<int> tmp = {0};
364  gelmConns.push_back(tmp);
365 }
366 
367 // Reset local patch sections
369 {
370  nSection = 0;
371  sectionNames.clear();
372  sectionName.clear();
373  sectionTypes.clear();
374  elmConns.clear();
375  nCells.clear();
376 }
377 
378 // Reset global partition sections
380 {
381  gnSection = 0;
382  gsectionNames.clear();
383  gsectionName.clear();
384  gsectionTypes.clear();
385  gelmConns.clear();
386  gnCells.clear();
387 }
388 
389 // Set timestamp to write to CGNS file
390 void cgnsWriter::setTimestamp(std::string _trimmed_base_t)
391 {
392  trimmed_base_t = _trimmed_base_t;
393 }
394 
395 // Set number of vertices to write to CGNS node data
396 void cgnsWriter::setNVrtx(int nVt)
397 {
398  nVrtx= nVt;
399 }
400 
401 // Set number of cells to write to CGNS element data
402 void cgnsWriter::setNCell(int nCl)
403 {
404  nCell= nCl;
405  nCells.push_back(nCl);
406 }
407 
408 // Set global number of cells
410 {
411  gnCell= gnCl;
412  gnCells.push_back(gnCl);
413 }
414 
415 // Set grid coordinates, stored separately in x,y,z for CGNS
417 {
418  xCrd.clear();
419  xCrd.insert(xCrd.begin(), x.begin(), x.end());
420  yCrd.clear();
421  yCrd.insert(yCrd.begin(), y.begin(), y.end());
422  zCrd.clear();
423  zCrd.insert(zCrd.begin(), z.begin(), z.end());
424 }
425 
426 // Set coordinate rind: virtual coordinates.
427 // The rule of thumb in CGNS files is: Total coordinates = number of vertexes + number of Rind
429 {
430  coordRind = rind;
431 }
432 
433 // Set rind of virtual elements
435 {
436  virtElmRind = rind;
437 }
438 
439 // Set number of ghost elements in Pane connectivity array
440 void cgnsWriter::setPconnGhostDescriptor(int ghostDescriptor)
441 {
442  pConnGhostDescriptor = ghostDescriptor;
443 }
444 
445 // Set entire Pane Connectivity vector
446 void cgnsWriter::setPconnVec(const vect1d<int>& _pConnVec)
447 {
448  pConnVec = _pConnVec;
449 }
450 
451 // Set limits, min and max, of Pane Connectivity vector, used in defining Pconn Range
452 void cgnsWriter::setPconnLimits(int _pconnProcMin, int _pconnProcMax)
453 {
454  pConnMax = _pconnProcMax;
455  pConnMin = _pconnProcMin;
456 }
457 
458 // Set patch number
459 void cgnsWriter::setPatchNo(int _patchNo)
460 {
461  patchNo = _patchNo;
462 }
463 
464 // Set number of faces in the interior of the volume mesh, not including the boundary
465 // faces on the exterior of the volume mesh
466 void cgnsWriter::setVolCellFacesNumber(int _nVolCellFaces)
467 {
468  nVolCellFaces = _nVolCellFaces;
469 }
470 
471 // Set boundary condition flag
472 void cgnsWriter::setBcflag(int _bcflag)
473 {
474  bcflag = _bcflag;
475 }
476 
477 // Set cnstr type
478 void cgnsWriter::setCnstrtype(int _cnstr_type)
479 {
480  cnstr_type = _cnstr_type;
481 }
482 
483 // Sets names and locations of solutions to write
484 void cgnsWriter::setSolutionNode(std::string ndeName, CGNS_ENUMT(GridLocation_t) slnLoc)
485 {
486  if (slnLoc == CGNS_ENUMV(Vertex))
487  nVrtxSln++;
488  else if (slnLoc == CGNS_ENUMV(CellCenter))
489  nCellSln++;
490  else
491  std::cerr << "Can not write to requested solution location.\n";
492  solutionNameLocMap[ndeName] = slnLoc;
493  slnNameNFld[ndeName] = 0;
494 }
495 
496 // write solution data node
497 void cgnsWriter::writeSolutionNode(std::string ndeName, CGNS_ENUMT(GridLocation_t) slnLoc, int emptyFlag, int virtFlag)
498 {
499  // emptyFlag
500  // 0 = write
501  // 1 = don't write; node is empty
502 
503  // virtFlag
504  // 0 = only write real
505  // 1 = write real and virtual
506 
507  if (slnLoc == CGNS_ENUMV(Vertex))
508  nVrtxSln++;
509  else if (slnLoc == CGNS_ENUMV(CellCenter))
510  nCellSln++;
511  else
512  {
513  std::cerr << "Can not write to requested solution location of type " << slnLoc <<".\n";
514  throw;
515  }
516  solutionNameLocMap[ndeName] = slnLoc;
517  slnNameNFld[ndeName] = 0;
518  int slnIdx;
519  if (cg_sol_write(indexFile, indexBase, indexZone,
520  ndeName.c_str(), slnLoc, &slnIdx)) cg_error_exit();
521  float* exponents;
522  std::string units;
523 
524  // volume (Rocflu fluid)
525  if (typeFlag == 0)
526  {
527  if (fluidDimMap.find(ndeName) != fluidDimMap.end())
528  {
529  exponents = &fluidDimMap[ndeName.c_str()][0];
530  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
531  }
532  if (fluidUnitsMap.find(ndeName) != fluidUnitsMap.end())
533  {
534  units = fluidUnitsMap[ndeName.c_str()];
535  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
536  }
537  }
538 
539  // surface (Rocflu ifluid)
540  else if (typeFlag == 1)
541  {
542  if (ifluidDimMap.find(ndeName) != ifluidDimMap.end())
543  {
544  exponents = &ifluidDimMap[ndeName.c_str()][0];
545  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
546  }
547  if (ifluidUnitsMap.find(ndeName) != ifluidUnitsMap.end())
548  {
549  units = ifluidUnitsMap[ndeName.c_str()];
550  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
551  }
552  }
553 
554  // burn (Rocburn iburn_all, burn)
555  else if (typeFlag == 2)
556  {
557  if (burnDimMap.find(ndeName) != burnDimMap.end())
558  {
559  exponents = &burnDimMap[ndeName.c_str()][0];
560  std::vector<float> test;
561  test = burnDimMap[ndeName.c_str()];
562  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
563  }
564  if (burnUnitsMap.find(ndeName) != burnUnitsMap.end())
565  {
566  units = burnUnitsMap[ndeName.c_str()];
567  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
568  }
569  }
570 
571  if (!emptyFlag)
572  {
573  solutionIdx.push_back(slnIdx);
574  solutionNameSolIdxMap[ndeName] = slnIdx;
575  cg_goto(indexFile, indexBase, "Zone_t", indexZone, "FlowSolution_t", slnIdx, "end");
576  cg_gridlocation_write(slnLoc);
577 
578  // Write virtual
579  if (virtFlag)
580  {
581  int rindArr[2];
582  rindArr[0] = 0;
583  if (coordRind && slnLoc == CGNS_ENUMV(Vertex))
584  {
585  rindArr[1] = coordRind;
586  }
587  if (virtElmRind && slnLoc == CGNS_ENUMV(CellCenter))
588  {
589  rindArr[1] = virtElmRind;
590  }
591  if (virtElmRind || coordRind)
592  {
593  if (cg_goto(indexFile, indexBase, "Zone_t",indexZone,"FlowSolution_t",slnIdx,"end")) cg_error_exit();
594  if (cg_rind_write(rindArr)) cg_error_exit();
595  }
596  }
597  }
598 }
599 
600 /* Writing a solution field to the CGNS file.
601  We assume the skeleton of the file is already written properly */
602 void cgnsWriter::writeSolutionField(std::string fname, std::string ndeName, CGNS_ENUMT(DataType_t) dt, void* data)
603 {
604  int slnIdx=-1;
605  auto is = solutionNameLocMap.begin();
606  while (is!=solutionNameLocMap.end())
607  {
608  slnIdx++;
609  if (!strcmp((is->first).c_str(), ndeName.c_str()))
610  {
611  break;
612  }
613  is++;
614  }
615 
616  // sanity check
617  if (is==solutionNameLocMap.end()){
618  std::cerr << ndeName
619  << " is not an existing solution node.\n";
620  return;
621  }
622 
623  // check vertex or cell based
624  if (is->second == CGNS_ENUMV(Vertex))
625  nVrtxFld++;
626  else
627  nCellFld++;
628 
629  // write solution to file
630  int fldIdx;
631  int currSlnIdx = solutionNameSolIdxMap[ndeName];
632  if (fname == "bflag")
633  {
634  if (cg_field_write(indexFile, indexBase, indexZone, currSlnIdx,
635  dt, fname.c_str(), data, &fldIdx)) cg_error_exit();
636  }
637  else
638  {
639  if (cg_field_write(indexFile, indexBase, indexZone, currSlnIdx,
640  dt, fname.c_str(), data, &fldIdx)) cg_error_exit();
641  }
642 
643  keyValueList fldIdxName;
644  fldIdxName[fldIdx] = fname;
645  std::pair<int, keyValueList> slnPair;
646  slnPair.first = slnIdx;
647  slnPair.second = fldIdxName;
648  solutionMap[++nSlnFld] = slnPair;
649 
650  // finding range of data
651  double* tmpData;
652  int* tmpIntData;
653  double min, max;
654  int intMin, intMax;
655  std::ostringstream os;
656  if (fname == "bflag")
657  {
658  tmpIntData = (int*) data;
659  intMin = tmpIntData[0];
660  intMax = tmpIntData[0];
661  for (int it=0; it<nVrtx; it++) {
662  if (intMin > tmpIntData[it])
663  {
664  intMin = (int) tmpIntData[it];
665  }
666  if (intMax < tmpIntData[it])
667  {
668  intMax = (int) tmpIntData[it];
669  }
670  }
671  os << intMin << ", " << intMax;
672  }
673  else
674  {
675  tmpData = (double*) data;
676  min = tmpData[0];
677  max = tmpData[0];
678  for (int it=0; it<nVrtx; it++)
679  {
680  min = std::min(tmpData[it], min);
681  max = std::max(tmpData[it], max);
682  }
683  os << min << ", " << max;
684  }
685  /*
686  int nItr = 0;
687  if (is->second == CGNS_ENUMV(Vertex))
688  {
689  nItr = nVrtx;
690  } else {
691  nItr = nCell;
692  }
693  */
694 
695  // writing range descriptor
696  std::string range = os.str();
697  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone,
698  "FlowSolution_t", currSlnIdx, "DataArray_t", fldIdx, "end")) cg_error_exit();
699  if (cg_descriptor_write("Range", range.c_str())) cg_error_exit();
700 
701  float* exponents;
702  std::string units;
703 
704  // write DimensionalExponents and units for cell data
705  if (is->second == CGNS_ENUMV(CellCenter))
706  {
707  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, "FlowSolution_t", currSlnIdx,
708  "DataArray_t", fldIdx, "end")) cg_error_exit();
709 
710  // surface (Rocflu fluid)
711  if (typeFlag == 0)
712  {
713  if (fluidUnitsMap.find(fname) != fluidUnitsMap.end())
714  {
715  units = fluidUnitsMap[fname];
716  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
717  }
718  if (fluidDimMap.find(fname) != fluidDimMap.end())
719  {
720  exponents = &fluidDimMap[fname][0];
721  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
722  }
723  }
724  // volume (Rocflu ifluid)
725  else if (typeFlag == 1)
726  {
727  if (ifluidUnitsMap.find(fname) != ifluidUnitsMap.end())
728  {
729  units = ifluidUnitsMap[fname];
730  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
731  }
732  if (ifluidDimMap.find(fname) != ifluidDimMap.end())
733  {
734  exponents = &ifluidDimMap[fname][0];
735  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
736  }
737  }
738  // burn (Rocburn iburn_all, burn)
739  else if (typeFlag == 2)
740  {
741  if (burnUnitsMap.find(fname) != burnUnitsMap.end())
742  {
743  units = burnUnitsMap[fname];
744  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
745  }
746  if (burnDimMap.find(fname) != burnDimMap.end())
747  {
748  exponents = &burnDimMap[fname][0];
749  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
750  }
751  }
752  }
753 
754  // For vertex data only
755  else if (is->second == CGNS_ENUMV(Vertex))
756  {
757  if (typeFlag == 1)
758  {
759  if (ifluidUnitsMap.find(fname) != ifluidUnitsMap.end())
760  {
761  units = ifluidUnitsMap[fname];
762  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
763  }
764  if (ifluidDimMap.find(fname) != ifluidDimMap.end())
765  {
766  exponents = &ifluidDimMap[fname][0];
767  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
768  }
769  }
770  }
771 }
772 
774 {
775  // dummy variables
776  std::ostringstream os;
777  // double min, max;
778  std::string str;
779 
780  // writing base data
781  char basename[33];
782  strcpy(basename, baseName.c_str());
783  if (cg_base_write(indexFile, basename, cellDim, physDim, &indexBase)) cg_error_exit();
784  if (cg_goto(indexFile, indexBase,"end")) cg_error_exit();
785  if (cg_units_write(massU, lengthU, timeU, tempU, angleU)) cg_error_exit();
786  if (cg_biter_write(indexFile, indexBase, baseItrName.c_str(), nTStep)) cg_error_exit();
787  if (cg_goto(indexFile, indexBase, baseItrName.c_str(), 0, "end")) cg_error_exit();
788  cgsize_t tmpDim = 1;
789  if (cg_array_write("TimeValues", CGNS_ENUMV(RealDouble), 1, (const cgsize_t*)
790  &tmpDim, &timeLabel)) cg_error_exit();
791 }
792 
794 {
795  intVal = 1;
796  char basename[33];
797  strcpy(basename, baseName.c_str());
798  cgsize_t tmpDim[1] = {1};
799 
800  // create Integral data for window
801  if (cg_goto(indexFile, indexBase, "end")) cg_error_exit();
802  if (cg_integral_write(intName.c_str())) cg_error_exit();
803  if (cg_goto(indexFile, indexBase, intName.c_str(), 0, "end")) cg_error_exit();
804  double zoomFact_arr[1] = {static_cast<double>(intVal)};
805  if (cg_array_write("zoomFact", CGNS_ENUMV(RealDouble), 1, tmpDim, zoomFact_arr)) cg_error_exit();
806  if (cg_goto(indexFile, indexBase, intName.c_str(), 0,"zoomFact",0,"end")) cg_error_exit();
807  std::ostringstream os;
808  std::string str;
809  os.str("");
810  os.clear();
811  os << std::to_string(intVal) << ", " << std::to_string(intVal);
812  str = os.str();
813  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
814  // float dimUnits[5] = {0, 0, 0, 0, 0};
815  if (cg_exponents_write(CGNS_ENUMV(RealSingle), &ifluidDimMap["zoomFact"][0])) cg_error_exit();
816  if (cg_descriptor_write("Units", ifluidUnitsMap["zoomFact"].c_str())) cg_error_exit();
817  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
818 }
819 
821 {
822  // create pane data node
823  std::string paneName("PaneData");
824  paneName += this->trimmed_base_t;
825 
826  // only for volume
827  cgsize_t tmpDim[1];
828  tmpDim[0] = nVolCellFaces;
829  //double gsArray[nVolCellFaces];
830  std::vector<double> gsArray;
831  gsArray.resize(nVolCellFaces, 0.);
832  memset(&gsArray[0], 0.0, nVolCellFaces*sizeof(double));
833  indexBase = 1;
834  if (cg_goto(indexFile, indexBase, "Zone_t", 1, paneName.c_str(),0,"end")) cg_error_exit();
835  if (cg_array_write("gs", CGNS_ENUMV(RealDouble), 1, tmpDim, &gsArray[0])) cg_error_exit();
836  if (cg_goto(indexFile, indexBase, "Zone_t", 1, paneName.c_str(),0,"gs",0,"end"))
837  cg_error_exit();
838  if (cg_descriptor_write("Range", "0, 0")) cg_error_exit();
839  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
840 
841  // dummy exponents
842  if (cg_exponents_write(CGNS_ENUMV(RealSingle), &fluidDimMap["gs"][0])) cg_error_exit();
843  if (cg_descriptor_write("Units", fluidUnitsMap["gs"].c_str())) cg_error_exit();
844 }
845 
847 {
848  // dummy variables
849  std::ostringstream os;
850  double min, max;
851  std::string str;
852 
853  // define zone name
854  char zonename[33];
855  strcpy(zonename, zoneName.c_str());
856  if (zoneType == CGNS_ENUMV(Unstructured)) {
857  cgCoreSize[0]=nVrtx;
858  cgCoreSize[1]=nCells[0];
859  cgCoreSize[2]=0;
860  } else {
861  std::cerr << "Format is not supported.\n";
862  cg_error_exit();
863  }
864 
865  // create zone
866  if (cg_zone_write(indexFile, indexBase, zonename,
867  cgCoreSize, CGNS_ENUMV(Unstructured), &indexZone)) cg_error_exit();
868 
869  // write zone iterative data
870  if (cg_ziter_write(indexFile, indexBase, indexZone, zoneItrName.c_str())) cg_error_exit();
871  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone,
872  zoneItrName.c_str(), 0, "end")) cg_error_exit();
873 
874  cgsize_t tmpDim2[2];
875  tmpDim2[0] = 32;
876  tmpDim2[1] = 1;
877  if (cg_array_write("GridCoordinatesPointers", CGNS_ENUMV(Character), 2, tmpDim2,
878  gridCrdPntr.c_str())) cg_error_exit();
879  if (cg_array_write("FlowSolutionsPointers", CGNS_ENUMV(Character), 2, tmpDim2,
880  flowSlnPntr.c_str())) cg_error_exit();
881 
882  // create grid coordinates node
883  int indexGrid = 1;
884  if (cg_grid_write(indexFile, indexBase, indexZone, "GridCoordinates", &indexGrid)) cg_error_exit();
885 
886  // write rind
887  if (coordRind)
888  {
889  int rindArr[2] = {0,coordRind};
890  if (cg_goto(indexFile, indexBase, "Zone_t",indexZone,"GridCoordinates",0,"end")) cg_error_exit();
891  if (cg_rind_write(rindArr)) cg_error_exit();
892  }
893 
894  // write coordinates + range, dimensional exponent, units
895  // float dimUnits[5] = {0, 1, 0, 0, 0};
896 
897  float* exponents;
898  std::string units;
899  std::vector<float> test;
900 
901  // x-coordinates
902  min = *std::min_element(xCrd.begin(), xCrd.begin()+nVrtx);
903  max = *std::max_element(xCrd.begin(), xCrd.begin()+nVrtx);
904  os.str("");
905  os.clear();
906  os << min << ", " << max;
907  str = os.str();
908 
909  // Get units and dimension information for volume, surface and burning fields
910  if (typeFlag == 0)
911  {
912  units = fluidUnitsMap["CoordinateX"];
913  exponents = &fluidDimMap["CoordinateX"][0];
914  test = fluidDimMap["CoordinateX"];
915  }
916  else if (typeFlag == 1)
917  {
918  units = ifluidUnitsMap["CoordinateX"];
919  exponents = &ifluidDimMap["CoordinateX"][0];
920  test = ifluidDimMap["CoordinateX"];
921  }
922  else if (typeFlag == 2)
923  {
924  units = burnUnitsMap["CoordinateX"];
925  exponents = &burnDimMap["CoordinateX"][0];
926  test = burnDimMap["CoordinateX"];
927  }
928  if (cg_coord_write(indexFile,indexBase,indexZone,CGNS_ENUMV(RealDouble),"CoordinateX",
929  &xCrd[0],&indexCoord)) cg_error_exit();
930  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, "GridCoordinates", 0,
931  "CoordinateX", 0, "end")) cg_error_exit();
932  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
933  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
934  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
935 
936  // y-coordinates
937  min = *std::min_element(yCrd.begin(), yCrd.begin()+nVrtx);
938  max = *std::max_element(yCrd.begin(), yCrd.begin()+nVrtx);
939  os.str("");
940  os.clear();
941  os << min << ", " << max;
942  str = os.str();
943 
944  // Get units and dimension information for volume, surface and burning fields
945  if (typeFlag == 0)
946  {
947  units = fluidUnitsMap["CoordinateY"];
948  exponents = &fluidDimMap["CoordinateY"][0];
949  }
950  else if (typeFlag == 1)
951  {
952  units = ifluidUnitsMap["CoordinateY"];
953  exponents = &ifluidDimMap["CoordinateY"][0];
954  }
955  else if (typeFlag == 2)
956  {
957  units = burnUnitsMap["CoordinateY"];
958  exponents = &burnDimMap["CoordinateY"][0];
959  }
960  if (cg_coord_write(indexFile,indexBase,indexZone,CGNS_ENUMV(RealDouble),"CoordinateY",
961  &yCrd[0],&indexCoord)) cg_error_exit();
962  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, "GridCoordinates", 0,
963  "CoordinateY", 0, "end")) cg_error_exit();
964  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
965  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
966  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
967 
968  // z-coordinates
969  min = *std::min_element(zCrd.begin(), zCrd.begin()+nVrtx);
970  max = *std::max_element(zCrd.begin(), zCrd.begin()+nVrtx);
971  os.str("");
972  os.clear();
973  os << min << ", " << max;
974  str = os.str();
975 
976  // Get units and dimension information for volume, surface and burning fields
977  if (typeFlag == 0)
978  {
979  units = fluidUnitsMap["CoordinateZ"];
980  exponents = &fluidDimMap["CoordinateZ"][0];
981  }
982  else if (typeFlag == 1)
983  {
984  units = ifluidUnitsMap["CoordinateZ"];
985  exponents = &ifluidDimMap["CoordinateZ"][0];
986  }
987  else if (typeFlag == 2)
988  {
989  units = burnUnitsMap["CoordinateZ"];
990  exponents = &burnDimMap["CoordinateZ"][0];
991  }
992  if (cg_coord_write(indexFile,indexBase,indexZone,CGNS_ENUMV(RealDouble),"CoordinateZ",
993  &zCrd[0],&indexCoord)) cg_error_exit();
994  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, "GridCoordinates", 0,
995  "CoordinateZ", 0, "end")) cg_error_exit();
996  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
997  if (cg_exponents_write(CGNS_ENUMV(RealSingle), exponents)) cg_error_exit();
998  if (cg_descriptor_write("Units", units.c_str())) cg_error_exit();
999 
1000  // create link to the grid coordinates
1001  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, "end")) cg_error_exit();
1002  os.str("");
1003  os.clear();
1004  os <<"/"<<baseName<<"/"<<zoneName<<"/GridCoordinates";
1005  str = os.str();
1006  if (cg_link_write(gridCrdPntr.c_str(), "", str.c_str())) cg_error_exit();
1007 
1008  // write Sections (real and virtual cells)
1009  int elm_start;
1010  int elm_end;
1011  // int nBdy;
1012  for (int iSec=0; iSec<nSection; iSec++)
1013  {
1014  elm_start = (iSec == 0 ? 1 : elm_start+nCells[iSec-1]);
1015  int elm_end = elm_start + nCells[iSec] - 1;
1016  int nBdy = 0;
1017  if (!sectionNames[iSec].compare("Empty:t3:virtual"))
1018  {
1019  cgsize_t tmp_arr[3] = {0, 0, 0};
1020  if (cg_section_write(indexFile, indexBase, indexZone, (sectionNames[iSec]).c_str(),
1021  sectionTypes[iSec], elm_start, elm_end, nBdy,
1022  &tmp_arr[0], &indexSection)) cg_error_exit();
1023  }
1024  else
1025  {
1026  if (elmConns[iSec].size() > 0)
1027  {
1028  if (cg_section_write(indexFile, indexBase, indexZone, (sectionNames[iSec]).c_str(),
1029  sectionTypes[iSec], elm_start, elm_end, nBdy,
1030  &elmConns[iSec][0], &indexSection)) cg_error_exit();
1031  }
1032  }
1033  // Write virtual elements
1034  if (virtElmRind)
1035  {
1036  int rindArr[2] = {0,virtElmRind};
1037 
1038  if (!sectionNames[iSec].compare(":T4:virtual"))
1039  {
1040  if (cg_goto(indexFile, indexBase, "Zone_t",indexZone,":T4:virtual",0,"end")) cg_error_exit();
1041  if (cg_rind_write(rindArr)) cg_error_exit();
1042  }
1043  else if (!sectionNames[iSec].compare(":T3:virtual"))
1044  {
1045  if (cg_goto(indexFile, indexBase, "Zone_t",indexZone,":T3:virtual",0,"end")) cg_error_exit();
1046  if (cg_rind_write(rindArr)) cg_error_exit();
1047  }
1048  else if (!sectionNames[iSec].compare(":t3:virtual"))
1049  {
1050  if (cg_goto(indexFile, indexBase, "Zone_t",indexZone,":t3:virtual",0,"end")) cg_error_exit();
1051  if (cg_rind_write(rindArr)) cg_error_exit();
1052  }
1053  }
1054  }
1055 
1056  // create pane data node
1057  std::string paneName("PaneData");
1058  paneName += this->trimmed_base_t;
1059  if (cg_goto(indexFile, indexBase, "Zone_t",indexZone,0,"end")) cg_error_exit();
1060  if (cg_integral_write(paneName.c_str())) cg_error_exit();
1061 
1062  // write pconn (and ridges)
1063  cgsize_t tmpDim[1];
1064  if (!pConnVec.empty())
1065  {
1066  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0,"end")) cg_error_exit();
1067  tmpDim[0] = {(cgsize_t) pConnVec.size()};
1068  if (cg_array_write("pconn",CGNS_ENUMV(Integer),1, tmpDim, &pConnVec[0])) cg_error_exit();
1069  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0, "pconn",0,"end"))
1070  cg_error_exit();
1071  min = pConnMin;
1072  max = pConnMax;
1073 
1074  os.str("");
1075  os.clear();
1076  os << min << ", " << max;
1077  str = os.str();
1078  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
1079  os.str("");
1080  os.clear();
1081  os << pConnGhostDescriptor;
1082  str = os.str();
1083  if (cg_descriptor_write("Ghost", str.c_str())) cg_error_exit();
1084  tmpDim[0] = 1;
1085  int ridge[1] = {0};
1086  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0,"end")) cg_error_exit();
1087  if (cg_array_write("ridges#1of2", CGNS_ENUMV(Integer),1,tmpDim,ridge)) cg_error_exit();
1088  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"ridges#1of2",0,"end"))
1089  cg_error_exit();
1090  if (cg_descriptor_write("Range", "EMPTY")) cg_error_exit();
1091  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
1092  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"end")) cg_error_exit();
1093  if (cg_array_write("ridges#2of2", CGNS_ENUMV(Integer),1,tmpDim,ridge)) cg_error_exit();
1094  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"ridges#2of2",0,"end"))
1095  cg_error_exit();
1096  if (cg_descriptor_write("Range", "EMPTY")) cg_error_exit();
1097  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
1098 
1099  // only for surface
1100  if (typeFlag == 1)
1101  {
1102  // bcflag
1103  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0,"end")) cg_error_exit();
1104  int bcflag_arr[1] = {bcflag};
1105  if (cg_array_write("bcflag", CGNS_ENUMV(Integer),1,tmpDim,bcflag_arr)) cg_error_exit();
1106  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"bcflag",0,"end"))
1107  cg_error_exit();
1108  os.str("");
1109  os.clear();
1110  os << std::to_string(bcflag) << ", " << std::to_string(bcflag);
1111  str = os.str();
1112  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
1113  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
1114 
1115  // patchNo
1116  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0,"end")) cg_error_exit();
1117  int patchNo_arr[1] = {patchNo};
1118  if (cg_array_write("patchNo", CGNS_ENUMV(Integer),1,tmpDim,patchNo_arr)) cg_error_exit();
1119  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"patchNo",0,"end"))
1120  cg_error_exit();
1121  os.str("");
1122  os.clear();
1123  os << std::to_string(patchNo) << ", " << std::to_string(patchNo);
1124  str = os.str();
1125  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
1126  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
1127 
1128  // cnstr_type
1129  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0,"end")) cg_error_exit();
1130  int cnstr_type_arr[1] = {cnstr_type};
1131  if (cg_array_write("cnstr_type", CGNS_ENUMV(Integer),1,tmpDim,cnstr_type_arr)) cg_error_exit();
1132  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"cnstr_type",0,"end"))
1133  cg_error_exit();
1134  os.str("");
1135  os.clear();
1136  os << std::to_string(cnstr_type) << ", " << std::to_string(cnstr_type);
1137  str = os.str();
1138  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
1139  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
1140  }
1141 
1142  }
1143  // only for burn
1144  else if (typeFlag == 2)
1145  {
1146  // write blank Pane Data
1147  tmpDim[0] = 1;
1148  // int pconn[1] = {0};
1149  int ridge[1] = {0};
1150 
1151  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0,"end")) cg_error_exit();
1152  if (cg_array_write("pconn", CGNS_ENUMV(Integer),1,tmpDim,ridge)) cg_error_exit();
1153  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0, "pconn",0,"end"))
1154  cg_error_exit();
1155  if (cg_descriptor_write("Range", "EMPTY")) cg_error_exit();
1156  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
1157 
1158  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0,"end")) cg_error_exit();
1159  if (cg_array_write("ridges#1of2", CGNS_ENUMV(Integer),1,tmpDim,ridge)) cg_error_exit();
1160  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"ridges#1of2",0,"end"))
1161  cg_error_exit();
1162  if (cg_descriptor_write("Range", "EMPTY")) cg_error_exit();
1163  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
1164 
1165  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"end")) cg_error_exit();
1166  if (cg_array_write("ridges#2of2", CGNS_ENUMV(Integer),1,tmpDim,ridge)) cg_error_exit();
1167  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(),0,"ridges#2of2",0,"end"))
1168  cg_error_exit();
1169  if (cg_descriptor_write("Range", "EMPTY")) cg_error_exit();
1170  if (cg_descriptor_write("Ghost", "0")) cg_error_exit();
1171  }
1172 
1173  // Write global sections. Global here means indexing according to partition, instead of local to
1174  // patch (as above).
1175  // Note: There are a lot of conditional statements below because the output format of the global
1176  // surface sections is inconsistent. How much of this does Rocstar actually require?
1177  for (int igSec=0; igSec<gnSection; igSec++)
1178  {
1179  elm_start = 1;
1180  if (gnCells[igSec] == 0)
1181  {
1182  elm_end = elm_start;
1183  }
1184  else
1185  {
1186  elm_end = gnCells[igSec];
1187  }
1188  // nBdy = 0;
1189 
1190  if (gsectionNames[igSec] == "t3g:virtual#1of3" ||
1191  gsectionNames[igSec] == "t3g:virtual#2of3" ||
1192  gsectionNames[igSec] == "t3g:virtual#3of3")
1193  {
1194  min = gelmConns[igSec][0];
1195  max = gelmConns[igSec][0];
1196  os.str("");
1197  os.clear();
1198  if (min == 0 && max == 0)
1199  {
1200  os << "EMPTY";
1201  }
1202  else
1203  {
1204  os << min << ", " << max;
1205  }
1206  str = os.str();
1207  }
1208  else if (gsectionNames[igSec] == "q4g:real#1of4" ||
1209  gsectionNames[igSec] == "q4g:real#2of4" ||
1210  gsectionNames[igSec] == "q4g:real#3of4" ||
1211  gsectionNames[igSec] == "q4g:real#4of4" ||
1212  gsectionNames[igSec] == "q4g:virtual#1of4" ||
1213  gsectionNames[igSec] == "q4g:virtual#2of4" ||
1214  gsectionNames[igSec] == "q4g:virtual#3of4" ||
1215  gsectionNames[igSec] == "q4g:virtual#4of4")
1216  {
1217  os.str("");
1218  os.clear();
1219  os << "EMPTY";
1220  str = os.str();
1221  }
1222  else
1223  {
1224  min = *std::min_element(gelmConns[igSec].begin(),gelmConns[igSec].end());
1225  max = *std::max_element(gelmConns[igSec].begin(),gelmConns[igSec].end());
1226  os.str("");
1227  os.clear();
1228  os << min << ", " << max;
1229  str = os.str();
1230  }
1231 
1232  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0,"end")) cg_error_exit();
1233  tmpDim[0] = {(cgsize_t) gelmConns[igSec].size()};
1234  if (cg_array_write((gsectionNames[igSec]).c_str(),CGNS_ENUMV(Integer),1, tmpDim, &gelmConns[igSec][0])) cg_error_exit();
1235  if (cg_goto(indexFile, indexBase, "Zone_t", indexZone, paneName.c_str(), 0, (gsectionNames[igSec]).c_str(),0,"end"))
1236  cg_error_exit();
1237  if (cg_descriptor_write("Range", str.c_str())) cg_error_exit();
1238 
1239  if (gsectionNames[igSec] == "t3g:virtual#1of3" ||
1240  gsectionNames[igSec] == "t3g:virtual#2of3" ||
1241  gsectionNames[igSec] == "t3g:virtual#3of3")
1242  {
1243  os.str("");
1244  os.clear();
1245  if (gnCells[igSec] == 1 && (min == 0 && max == 0))
1246  {
1247  os << 0;
1248  }
1249  else
1250  {
1251  os << elm_end;
1252  }
1253  str = os.str();
1254  }
1255  else
1256  {
1257  os.str("");
1258  os.clear();
1259  os << 0;
1260  str = os.str();
1261  }
1262  if (cg_descriptor_write("Ghost", str.c_str() )) cg_error_exit();
1263  }
1264 }
vect1d< std::string > zoneNames
Definition: cgnsWriter.H:183
void setFluidDimMap()
Definition: cgnsWriter.C:80
int nVrtxSln
Definition: cgnsWriter.H:195
vect1d< CGNS_ENUMT(ElementType_t)> gsectionTypes
Definition: cgnsWriter.H:188
vect1d< std::string > gsectionNames
Definition: cgnsWriter.H:186
int getNSections()
Definition: cgnsWriter.C:326
void setCnstrtype(int cnstr_type)
Definition: cgnsWriter.C:478
void setPconnVec(const vect1d< int > &pConnVec)
Definition: cgnsWriter.C:446
data_type data
Edge/face with sorted point ids (a, b, c, ...) is located at some index i in data[b], with data[b][i].first == [a, c] (for edges, third point id treated as -1).
int nVrtxFld
Definition: cgnsWriter.H:197
std::string intName
Definition: cgnsWriter.H:177
std::string gridCrdPntr
Definition: cgnsWriter.H:178
void deleteFile()
Definition: cgnsWriter.C:38
int nCellSln
Definition: cgnsWriter.H:196
int virtElmRind
Definition: cgnsWriter.H:157
std::map< std::string, int > ifluidMagMap
Definition: cgnsWriter.H:213
void setiFluidMagMap()
Definition: cgnsWriter.C:191
vect1d< int > elmConn
Definition: cgnsWriter.H:163
void setSection(std::string sName, CGNS_ENUMT(ElementType_t) st, vect1d< cgsize_t > elmConn)
Definition: cgnsWriter.C:332
std::string baseItrName
Definition: cgnsWriter.H:176
std::map< int, std::pair< int, keyValueList > > solutionMap
Definition: cgnsWriter.H:204
double timeLabel
Definition: cgnsWriter.H:180
std::string flowSlnPntr
Definition: cgnsWriter.H:178
void writeSolutionField(std::string fname, std::string ndeName, CGNS_ENUMT(DataType_t) dt, void *data)
Definition: cgnsWriter.C:602
vect1d< int > gnCells
Definition: cgnsWriter.H:192
void writeVolCellFacesNumber()
Definition: cgnsWriter.C:820
vect1d< int > pConnVec
Definition: cgnsWriter.H:160
std::string trimmed_base_t
Definition: cgnsWriter.H:147
void writeGridToFile()
Definition: cgnsWriter.C:773
std::map< std::string, std::vector< float > > burnDimMap
Definition: cgnsWriter.H:215
std::map< std::string, std::string > burnUnitsMap
Definition: cgnsWriter.H:214
int indexCoord
Definition: cgnsWriter.H:144
std::map< std::string, std::vector< float > > ifluidDimMap
Definition: cgnsWriter.H:212
void setBurnUnitsMap()
Definition: cgnsWriter.C:225
std::map< std::string, std::vector< float > > fluidDimMap
Definition: cgnsWriter.H:209
std::map< std::string, std::string > fluidUnitsMap
Definition: cgnsWriter.H:208
void setNVrtx(int nVt)
Definition: cgnsWriter.C:396
int indexSection
Definition: cgnsWriter.H:145
vect1d< CGNS_ENUMT(ElementType_t)> sectionTypes
Definition: cgnsWriter.H:187
void setZoneItrData(std::string zitrname, std::string grdptr, std::string slnptr)
Definition: cgnsWriter.C:308
vect1d< double > zCrd
Definition: cgnsWriter.H:182
void setSolutionNode(std::string ndeName, CGNS_ENUMT(GridLocation_t) slnLoc)
Definition: cgnsWriter.C:484
std::string sectionName
Definition: cgnsWriter.H:142
std::map< std::string, int > burnMagMap
Definition: cgnsWriter.H:216
int nCellFld
Definition: cgnsWriter.H:198
vect1d< double > yCrd
Definition: cgnsWriter.H:182
std::map< std::string, int > fluidMagMap
Definition: cgnsWriter.H:210
void resetSections()
Definition: cgnsWriter.C:368
int typeFlag
Definition: cgnsWriter.H:159
vect1d< double > xCrd
Definition: cgnsWriter.H:182
void setCoordRind(int rind)
Definition: cgnsWriter.C:428
void setZone(std::string zName, CGNS_ENUMT(ZoneType_t) zt)
Definition: cgnsWriter.C:316
std::map< std::string, int > solutionNameSolIdxMap
Definition: cgnsWriter.H:203
std::map< std::string, std::string > ifluidUnitsMap
Definition: cgnsWriter.H:211
std::string zoneName
Definition: cgnsWriter.H:142
int nVolCellFaces
Definition: cgnsWriter.H:168
void setGridXYZ(vect1d< double > x, vect1d< double > y, vect1d< double > z)
Definition: cgnsWriter.C:416
int indexBase
Definition: cgnsWriter.H:143
void setPconnLimits(int pconnProcMin, int pconnProcMax)
Definition: cgnsWriter.C:452
void setBurnMagMap()
Definition: cgnsWriter.C:265
std::map< std::string, CGNS_ENUMT(GridLocation_t)> solutionNameLocMap
Definition: cgnsWriter.H:201
vect1d< int > nCells
Definition: cgnsWriter.H:191
int nSection
Definition: cgnsWriter.H:153
vect1d< int > solutionIdx
Definition: cgnsWriter.H:200
void setPatchNo(int patchNo)
Definition: cgnsWriter.C:459
void setTimestamp(std::string trimmed_base_t)
Definition: cgnsWriter.C:390
void setPconnGhostDescriptor(int ghostDescriptor)
Definition: cgnsWriter.C:440
int indexZone
Definition: cgnsWriter.H:144
void setTypeFlag(int typeFlag)
Definition: cgnsWriter.C:287
vect2d< cgsize_t > elmConns
Definition: cgnsWriter.H:189
void setVolCellFacesNumber(int nVolCellFaces)
Definition: cgnsWriter.C:466
void setVirtElmRind(int rind)
Definition: cgnsWriter.C:434
std::string gsectionName
Definition: cgnsWriter.H:142
void resetGlobalSections()
Definition: cgnsWriter.C:379
void setiFluidDimMap()
Definition: cgnsWriter.C:158
void setBaseItrData(std::string bsitrname, int ntstp, double tval)
Definition: cgnsWriter.C:293
void setFluidMagMap()
Definition: cgnsWriter.C:103
void setNCell(int nCl)
Definition: cgnsWriter.C:402
void setFluidUnitsMap()
Definition: cgnsWriter.C:59
std::map< std::string, int > slnNameNFld
Definition: cgnsWriter.H:199
int pConnMax
Definition: cgnsWriter.H:162
int pConnMin
Definition: cgnsWriter.H:161
int gnSection
Definition: cgnsWriter.H:154
void setBcflag(int bcflag)
Definition: cgnsWriter.C:472
void setiFluidUnitsMap()
Definition: cgnsWriter.C:124
void writeSolutionNode(std::string ndeName, CGNS_ENUMT(GridLocation_t) slnLoc, int emptyFlag, int virtFlag)
Definition: cgnsWriter.C:497
void setUnits(CGNS_ENUMT(MassUnits_t) mu, CGNS_ENUMT(LengthUnits_t) lu, CGNS_ENUMT(TimeUnits_t) tu, CGNS_ENUMT(TemperatureUnits_t) tpu, CGNS_ENUMT(AngleUnits_t) au)
Definition: cgnsWriter.C:43
vect2d< int > gelmConns
Definition: cgnsWriter.H:190
void setGlobalNCell(int gnCl)
Definition: cgnsWriter.C:409
vect1d< std::string > sectionNames
Definition: cgnsWriter.H:185
CGNS_ENUMT(ZoneType_t) zoneType
std::string zoneItrName
Definition: cgnsWriter.H:176
void writeWinToFile()
Definition: cgnsWriter.C:793
int cnstr_type
Definition: cgnsWriter.H:166
void setIntData(std::string intname, int intval)
Definition: cgnsWriter.C:301
void setBurnDimMap()
Definition: cgnsWriter.C:244
cgsize_t cgCoreSize[9]
Definition: cgnsWriter.H:141
std::map< int, std::string > keyValueList
Definition: cgnsAnalyzer.H:61
std::string myCgFileName
Definition: cgnsWriter.H:137
int pConnGhostDescriptor
Definition: cgnsWriter.H:158
void writeZoneToFile()
Definition: cgnsWriter.C:846
std::string baseName
Definition: cgnsWriter.H:142
void setGlobalSection(std::string sName, CGNS_ENUMT(ElementType_t) st, vect1d< int > elmConn)
Definition: cgnsWriter.C:343
std::vector< T > vect1d
Definition: cgnsWriter.H:48
int coordRind
Definition: cgnsWriter.H:156
vect1d< CGNS_ENUMT(ZoneType_t)> zoneTypes
Definition: cgnsWriter.H:184
int indexFile
Definition: cgnsWriter.H:143