OpenCAEPoro  v0.5.0
A simulator for multicomponent porous media flow
Output4Vtk.cpp
Go to the documentation of this file.
1 
12 #include "Output4Vtk.hpp"
13 
14 void Output4Vtk::Init(const string& myFile,
15  const string& shortInfo,
16  const string& myCodeWay,
17  const string& girdType,
18  const VTK_USI& nG,
19  const VTK_USI& nW)
20 {
21  ofstream myVtk(myFile);
22  if (!myVtk.is_open()) {
23  OCP_ABORT("Can not open file: " + myFile);
24  }
25 
26  ios::sync_with_stdio(false);
27  myVtk.tie(0);
28 
29  // Header
30  myVtk << VTK_HEADER << "\n";
31 
32  // Title
33  if (shortInfo.size() > VTK_MAX_TITLE_LENGTH) {
34  OCP_WARNING("Length of title is beyond the limit: 256");
35  myVtk << "Invalid short info, Too many characters\n";
36  } else {
37  myVtk << shortInfo << "\n";
38  }
39 
40  // Code
41  myVtk << myCodeWay << "\n";
42 
43  // Grid Type
44  myVtk << VTK_DATASET << " " << girdType << "\n";
45 
46  myVtk << "\n";
47  myVtk.close();
48 
49  // Init numGrid and numGrid
50  numGrid = nG;
51  numWell = nW;
52  numCell = numGrid + numWell;
53 }
54 
55 void Output4Vtk::OutputPOINTS(const string& myFile,
56  const vector<OCPpolyhedron>& myHexGrid,
57  const vector<OCPpolyhedron>& myHexWell,
58  const string& dataType) const
59 {
60  ofstream myVtk;
61  myVtk.open(myFile, ios::app);
62  if (!myVtk.is_open()) {
63  OCP_ABORT("Can not open file: " + myFile);
64  }
65 
66  ios::sync_with_stdio(false);
67  myVtk.tie(0);
68 
69  // Grid Points
70  VTK_USI numWellPoints = numGrid * 8;
71  for (auto& w : myHexWell) {
72  numWellPoints += w.numPoints;
73  }
74  myVtk << VTK_POINTS << " " << numWellPoints << " " << VTK_FLOAT << "\n";
75 
76  for (VTK_USI i = 0; i < numGrid; i++) {
77  for (USI j = 0; j < myHexGrid[i].numPoints; j++) {
78  myVtk << setw(6) << myHexGrid[i].Points[j].x << " " << setw(6)
79  << myHexGrid[i].Points[j].y << " " << setw(6)
80  << myHexGrid[i].Points[j].z << "\n";
81  }
82  }
83 
84  // Well Points
85  for (VTK_USI w = 0; w < numWell; w++) {
86  for (USI j = 0; j < myHexWell[w].numPoints; j++) {
87  myVtk << setw(6) << myHexWell[w].Points[j].x << " " << setw(6)
88  << myHexWell[w].Points[j].y << " " << setw(6)
89  << myHexWell[w].Points[j].z << "\n";
90  }
91  }
92 
93  myVtk << "\n";
94  myVtk.close();
95 }
96 
97 void Output4Vtk::OutputCELLS(const string& myFile,
98  const vector<OCPpolyhedron>& myHexGrid,
99  const vector<OCPpolyhedron>& myHexWell) const
100 {
101  ofstream myVtk;
102  myVtk.open(myFile, ios::app);
103  if (!myVtk.is_open()) {
104  OCP_ABORT("Can not open file: " + myFile);
105  }
106 
107  ios::sync_with_stdio(false);
108  myVtk.tie(0);
109 
110  USI numSize = numCell;
111  for (VTK_USI n = 0; n < numGrid; n++) {
112  numSize += myHexGrid[n].numPoints;
113  }
114  for (USI w = 0; w < numWell; w++) {
115  numSize += myHexWell[w].numPoints;
116  }
117 
118  myVtk << VTK_CELLS << " " << numCell << " " << numSize << "\n";
119 
120  // EASY output!
121  // Grid Cell
122  VTK_USI tmp = 0;
123  for (VTK_USI n = 0; n < numGrid; n++) {
124  myVtk << 8 << " ";
125  for (VTK_USI j = 0; j < 8; j++) {
126  myVtk << j + tmp << " ";
127  }
128  myVtk << "\n";
129  tmp += 8;
130  }
131 
132  // Well Cell
133  for (USI w = 0; w < numWell; w++) {
134  myVtk << myHexWell[w].numPoints << " ";
135  for (VTK_USI j = 0; j < myHexWell[w].numPoints; j++) {
136  myVtk << j + tmp << " ";
137  }
138  myVtk << "\n";
139  tmp += myHexWell[w].numPoints;
140  }
141 
142  myVtk << "\n";
143  myVtk.close();
144 }
145 
146 void Output4Vtk::OutputCELL_TYPES(const string& myFile,
147  const vector<OCPpolyhedron>& myHexGrid,
148  const vector<OCPpolyhedron>& myHexWell) const
149 {
150  ofstream myVtk;
151  myVtk.open(myFile, ios::app);
152  if (!myVtk.is_open()) {
153  OCP_ABORT("Can not open file: " + myFile);
154  }
155 
156  ios::sync_with_stdio(false);
157  myVtk.tie(0);
158 
159  myVtk << VTK_CELL_TYPES << " " << numCell << "\n";
160 
161  // EASY output!
162  // Grid Cell
163  for (VTK_USI n = 0; n < numGrid; n++) {
164  myVtk << VTK_HEXAHEDRON << "\n";
165  }
166 
167  // Well Cell
168  for (USI w = 0; w < numWell; w++) {
169  myVtk << VTK_POLY_LINE << "\n";
170  }
171 
172  myVtk << "\n";
173  myVtk.close();
174 }
175 
176 /*----------------------------------------------------------------------------*/
177 /* Brief Change History of This File */
178 /*----------------------------------------------------------------------------*/
179 /* Author Date Actions */
180 /*----------------------------------------------------------------------------*/
181 /* Shizhe Li Oct/19/2022 Create file */
182 /* Chensong Zhang Feb/05/2023 Update output in vtk files */
183 /*----------------------------------------------------------------------------*/
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
Output reservoir information in vtk format.
#define OCP_WARNING(msg)
Log warning messages.
Definition: UtilError.hpp:39
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47
void Init(const string &myFile, const string &shortInfo, const string &myCodeWay, const string &girdType, const VTK_USI &nG, const VTK_USI &nW)
create a new file and write basic information
Definition: Output4Vtk.cpp:14