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.H
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 #ifndef NEMOSYS_CGNSWRITER_H_
30 #define NEMOSYS_CGNSWRITER_H_
31 
32 // Nemosys headers
33 #include "nemosys_export.h"
34 
35 // third party
36 #ifdef _MSC_VER
37 #include <cwchar> // include before cgnslib.h to avoid errors related to _stat
38 #endif
39 #include <cgnslib.h>
40 
41 // others
42 #include <string>
43 #include <vector>
44 #include <map>
45 
46 // aliases
47 template <typename T>
48 using vect1d = std::vector<T>;
49 template <typename T>
50 using vect2d = std::vector<std::vector<T>>;
51 using keyValueList = std::map<int, std::string>;
52 
53 /* a class for writing CGNS files */
54 // TODO: This writer is heavily specific to Rocstar. This is not the original
55 // intent for this class and it should be generalized to base class and
56 // a derived one for Rocstar.
57 class NEMOSYS_EXPORT cgnsWriter {
58  public:
59  cgnsWriter(std::string fname, std::string baseName, int cellDim,
60  int physDim, int mode) :
61  myCgFileName(std::move(fname)), baseName(std::move(baseName)),
62  cellDim(cellDim), physDim(physDim), nBase(1), nZone(0),
63  nVrtx(0), nCell(0), nSection(0), gnSection(0),
64  coordRind(0), virtElmRind(0),
65  nSlnFld(0), nVrtxSln(0), nCellSln(0), nVrtxFld(0), nCellFld(0)
66  {
67  if (mode == 0) {
68  if (cg_open(myCgFileName.c_str(), CG_MODE_WRITE,
69  &indexFile))
70  cg_error_exit();
71  } else if (mode == 1) {
72  if (cg_open(myCgFileName.c_str(), CG_MODE_MODIFY,
73  &indexFile))
74  cg_error_exit();
75  }
76  int file_type;
77  cg_get_file_type(indexFile, &file_type);
78  };
79 
80  ~cgnsWriter() { cg_close(indexFile); };
81 
82  void deleteFile();
83  void setUnits(CGNS_ENUMT(MassUnits_t) mu, CGNS_ENUMT(LengthUnits_t) lu,
84  CGNS_ENUMT(TimeUnits_t) tu, CGNS_ENUMT(TemperatureUnits_t) tpu,
85  CGNS_ENUMT(AngleUnits_t) au);
86  void setBaseItrData(std::string bsitrname, int ntstp, double tval);
87  void setZoneItrData(std::string zitrname, std::string grdptr,
88  std::string slnptr);
89  void setIntData(std::string intname, int intval);
90  void setZone(std::string zName, CGNS_ENUMT(ZoneType_t) zt);
91  int getNSections();
92  void setTimestamp(std::string trimmed_base_t);
93  void setNVrtx(int nVt);
94  void setNCell(int nCl);
95  void setGlobalNCell(int gnCl);
96  void
97  setGridXYZ(vect1d<double> x, vect1d<double> y, vect1d<double> z);
98  void setCoordRind(int rind);
99  void setVirtElmRind(int rind);
100  void setPconnVec(const vect1d<int> &pConnVec);
101  void setPconnLimits(int pconnProcMin, int pconnProcMax);
102  void setPatchNo(int patchNo);
103  void setBcflag(int bcflag);
104  void setCnstrtype(int cnstr_type);
105  void setVolCellFacesNumber(int nVolCellFaces);
106  void setPconnGhostDescriptor(int ghostDescriptor);
107  void
108  setSection(std::string sName, CGNS_ENUMT(ElementType_t) st, vect1d<cgsize_t> elmConn);
109  void setGlobalSection(std::string sName, CGNS_ENUMT(ElementType_t) st,
110  vect1d<int> elmConn);
111  void setGlobalSection(std::string gsName, CGNS_ENUMT(ElementType_t) gst);
112  void resetSections();
113  void resetGlobalSections();
114  void setSolutionNode(std::string ndeName, CGNS_ENUMT(GridLocation_t) slnLoc);
115  void writeSolutionNode(std::string ndeName, CGNS_ENUMT(GridLocation_t) slnLoc,
116  int emptyFlag, int virtFlag);
117  void
118  writeSolutionField(std::string fname, std::string ndeName, CGNS_ENUMT(DataType_t) dt,
119  void *data);
120  void writeGridToFile();
121  void writeZoneToFile();
122  void writeWinToFile();
123  void setFluidUnitsMap();
124  void setFluidDimMap();
125  void setFluidMagMap();
126  void setiFluidUnitsMap();
127  void setiFluidDimMap();
128  void setiFluidMagMap();
129  void setBurnUnitsMap();
130  void setBurnDimMap();
131  void setBurnMagMap();
132  void setTypeFlag(int typeFlag);
133  void writeVolCellFacesNumber();
134 
135  private:
136  // general CGNS manager
137  std::string myCgFileName;
138  CGNS_ENUMT(ZoneType_t) zoneType;
139  CGNS_ENUMT(ElementType_t) sectionType, gsectionType;
140  int rmin[3], rmax[3];
141  cgsize_t cgCoreSize[9];
142  std::string baseName, zoneName, sectionName, gsectionName;
143  int indexFile, indexBase;
144  int indexZone, indexCoord;
146  int cellDim, physDim;
147  std::string trimmed_base_t;
148  int nBase;
149  int nZone;
150  int nVrtx;
151  int nCell;
152  int gnCell;
153  int nSection;
159  int typeFlag;
161  int pConnMin;
162  int pConnMax;
164  int patchNo;
165  int bcflag;
167  int intVal;
169  // units
170  CGNS_ENUMT(MassUnits_t) massU;
171  CGNS_ENUMT(LengthUnits_t) lengthU;
172  CGNS_ENUMT(TimeUnits_t) timeU;
173  CGNS_ENUMT(TemperatureUnits_t) tempU;
174  CGNS_ENUMT(AngleUnits_t) angleU;
175  // time-dependent data
176  std::string baseItrName, zoneItrName;
177  std::string intName;
178  std::string gridCrdPntr, flowSlnPntr;
179  int nTStep;
180  double timeLabel;
181  // mesh data
182  vect1d<double> xCrd, yCrd, zCrd;
193  // solution data
194  int nSlnFld;
195  int nVrtxSln;
196  int nCellSln;
197  int nVrtxFld;
198  int nCellFld;
199  std::map<std::string, int> slnNameNFld; // number of filed in the given solution name
200  vect1d<int> solutionIdx; // solution node indices
201  std::map<std::string, CGNS_ENUMT(GridLocation_t)> solutionNameLocMap;
202  // maps sol node to index (eg. NodeData0.0=1,ElemData0.0=2)
203  std::map<std::string, int> solutionNameSolIdxMap;
204  std::map<int, std::pair<int, keyValueList> > solutionMap; // (#sln, <slnIdx, [fldIdx, fldName]>)
207  // Rocstar variable units lookup dictionary
208  std::map<std::string, std::string> fluidUnitsMap;
209  std::map<std::string, std::vector<float>> fluidDimMap;
210  std::map<std::string, int> fluidMagMap;
211  std::map<std::string, std::string> ifluidUnitsMap;
212  std::map<std::string, std::vector<float>> ifluidDimMap;
213  std::map<std::string, int> ifluidMagMap;
214  std::map<std::string, std::string> burnUnitsMap;
215  std::map<std::string, std::vector<float>> burnDimMap;
216  std::map<std::string, int> burnMagMap;
217 };
218 
219 #endif // NEMOSYS_CGNSWRITER_H_
vect1d< std::string > zoneNames
Definition: cgnsWriter.H:183
int nVrtxSln
Definition: cgnsWriter.H:195
vect1d< CGNS_ENUMT(ElementType_t)> gsectionTypes
Definition: cgnsWriter.H:188
vect1d< std::string > gsectionNames
Definition: cgnsWriter.H:186
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).
std::vector< std::vector< T > > vect2d
Definition: cgnsWriter.H:50
int nVrtxFld
Definition: cgnsWriter.H:197
std::string intName
Definition: cgnsWriter.H:177
std::string gridCrdPntr
Definition: cgnsWriter.H:178
int nCellSln
Definition: cgnsWriter.H:196
int virtElmRind
Definition: cgnsWriter.H:157
std::map< std::string, int > ifluidMagMap
Definition: cgnsWriter.H:213
vect1d< int > elmConn
Definition: cgnsWriter.H:163
int nVrtxElem
Definition: cgnsWriter.H:155
std::map< int, std::pair< int, keyValueList > > solutionMap
Definition: cgnsWriter.H:204
STL namespace.
double timeLabel
Definition: cgnsWriter.H:180
vect1d< std::string > solutionName
Definition: cgnsWriter.H:205
vect1d< int > gnCells
Definition: cgnsWriter.H:192
vect1d< int > pConnVec
Definition: cgnsWriter.H:160
std::string trimmed_base_t
Definition: cgnsWriter.H:147
std::map< std::string, std::vector< float > > burnDimMap
Definition: cgnsWriter.H:215
std::map< std::string, std::string > burnUnitsMap
Definition: cgnsWriter.H:214
std::map< std::string, std::vector< float > > ifluidDimMap
Definition: cgnsWriter.H:212
std::map< std::string, std::vector< float > > fluidDimMap
Definition: cgnsWriter.H:209
std::map< std::string, std::string > fluidUnitsMap
Definition: cgnsWriter.H:208
int indexSection
Definition: cgnsWriter.H:145
vect1d< CGNS_ENUMT(ElementType_t)> sectionTypes
Definition: cgnsWriter.H:187
vect1d< double > zCrd
Definition: cgnsWriter.H:182
std::map< std::string, int > burnMagMap
Definition: cgnsWriter.H:216
vect1d< CGNS_ENUMT(GridLocation_t)> solutionGridLocation
Definition: cgnsWriter.H:206
cgnsWriter(std::string fname, std::string baseName, int cellDim, int physDim, int mode)
Definition: cgnsWriter.H:59
int nCellFld
Definition: cgnsWriter.H:198
std::map< std::string, int > fluidMagMap
Definition: cgnsWriter.H:210
std::string trimmed_base_t
int typeFlag
Definition: cgnsWriter.H:159
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
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
CGNS_ENUMT(MassUnits_t)
Definition: cgnsAnalyzer.C:457
int indexZone
Definition: cgnsWriter.H:144
vect2d< cgsize_t > elmConns
Definition: cgnsWriter.H:189
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
vect2d< int > gelmConns
Definition: cgnsWriter.H:190
vect1d< std::string > sectionNames
Definition: cgnsWriter.H:185
std::string zoneItrName
Definition: cgnsWriter.H:176
std::map< int, int > pconnProcMin
int cnstr_type
Definition: cgnsWriter.H:166
std::string myCgFileName
Definition: cgnsWriter.H:137
std::map< int, std::string > keyValueList
Definition: cgnsAnalyzer.H:61
int pConnGhostDescriptor
Definition: cgnsWriter.H:158
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
std::map< int, int > pconnProcMax