OpenCAEPoro  v0.5.0
A simulator for multicomponent porous media flow
Output4Vtk.hpp
Go to the documentation of this file.
1 
12 #ifndef __OUTPUT4VTK_HEADER__
13 #define __OUTPUT4VTK_HEADER__
14 
15 #include <fstream>
16 #include <string>
17 #include <vector>
18 
19 #include "Grid.hpp"
20 
21 using namespace std;
22 
23 // Basic datatype
24 typedef OCP_DBL VTK_DBL;
25 typedef OCP_SIN VTK_SIN;
26 typedef OCP_USI VTK_USI;
27 typedef OCP_ULL VTK_ULL;
28 
29 // Basic Keyword
30 const string VTK_HEADER = "# vtk DataFile Version 3.0";
31 const string VTK_ASCII = "ASCII";
32 const string VTK_DATASET = "DATASET";
33 const string VTK_UNSTRUCTURED_GRID = "UNSTRUCTURED_GRID";
34 const string VTK_POINTS = "POINTS";
35 const string VTK_CELLS = "CELLS";
36 const string VTK_CELL_TYPES = "CELL_TYPES";
37 const string VTK_CELL_DATA = "CELL_DATA";
38 const string VTK_POINT_DATA = "POINT_DATA";
39 const VTK_USI VTK_MAX_TITLE_LENGTH = 256;
40 const string VTK_LOOKUP_TABLE = "LOOKUP_TABLE";
41 const string VTK_DEFAULT = "default";
42 const string VTK_SCALARS = "SCALARS";
43 
44 // Basic Cell Type
45 const VTK_USI VTK_HEXAHEDRON = 12;
46 const VTK_USI VTK_POLY_LINE = 4;
47 
48 const string VTK_FLOAT = "float";
49 const string VTK_UNSIGNED_INT = "unsigned_int";
50 
52 {
53  friend class Out4VTK;
54 
55 public:
56  void Init(const string& myFile,
57  const string& shortInfo,
58  const string& myCodeWay,
59  const string& girdType,
60  const VTK_USI& nG,
61  const VTK_USI& nW);
62  void OutputPOINTS(const string& myFile,
63  const vector<OCPpolyhedron>& myHexGrid,
64  const vector<OCPpolyhedron>& myHexWell,
65  const string& dataType) const;
66  void OutputCELLS(const string& myFile,
67  const vector<OCPpolyhedron>& myHexGrid,
68  const vector<OCPpolyhedron>& myHexWell) const;
69  void OutputCELL_TYPES(const string& myFile,
70  const vector<OCPpolyhedron>& myHex,
71  const vector<OCPpolyhedron>& myHexWell) const;
72  template <typename T>
73  void OutputCELL_DATA_SCALARS(const string& myFile,
74  const string& dataName,
75  const string& dataType,
76  const T* gridVal,
77  const USI& gap,
78  const vector<GB_Pair>& gbPair,
79  const bool& useActive,
80  const T* wellVal) const;
81  void BeginCellData() const { cellData = true; };
82 
83 private:
84  mutable bool cellData{false};
85  VTK_USI numGrid;
86  VTK_USI numWell;
87  VTK_USI numCell;
88 };
89 
90 template <typename T>
91 void Output4Vtk::OutputCELL_DATA_SCALARS(const string& myFile,
92  const string& dataName,
93  const string& dataType,
94  const T* gridVal,
95  const USI& gap,
96  const vector<GB_Pair>& gbPair,
97  const bool& useActive,
98  const T* wellVal) const
99 {
100  ofstream myVtk;
101  myVtk.open(myFile, ios::app);
102  if (!myVtk.is_open()) {
103  OCP_ABORT("Can not open file: " + myFile);
104  }
105 
106  ios::sync_with_stdio(false);
107  myVtk.tie(0);
108 
109  if (cellData) {
110  myVtk << VTK_CELL_DATA << " " << numCell << "\n";
111  cellData = false;
112  }
113 
114  myVtk << VTK_SCALARS << " " << dataName << " " << dataType << " " << 1 << "\n";
115  myVtk << VTK_LOOKUP_TABLE << " " << VTK_DEFAULT << "\n";
116 
117  // Grid
118  if (useActive) {
119  for (VTK_USI n = 0; n < numGrid; n++) {
120  if (gbPair[n].IsAct()) {
121  myVtk << gridVal[gbPair[n].GetId() * gap] << "\n";
122  } else {
123  myVtk << 0 << "\n";
124  }
125  }
126  } else {
127  for (VTK_USI n = 0; n < numGrid; n++) {
128  myVtk << gridVal[n * gap] << "\n";
129  }
130  }
131 
132  // Well
133  for (USI w = 0; w < numWell; w++) {
134  myVtk << wellVal[w] << "\n";
135  }
136 
137  myVtk << "\n";
138  myVtk.close();
139 }
140 
141 #endif
142 
143 /*----------------------------------------------------------------------------*/
144 /* Brief Change History of This File */
145 /*----------------------------------------------------------------------------*/
146 /* Author Date Actions */
147 /*----------------------------------------------------------------------------*/
148 /* Shizhe Li Oct/19/2022 Create file */
149 /* Chensong Zhang Feb/05/2023 Update output in vtk files */
150 /*----------------------------------------------------------------------------*/
Grid class declaration.
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:27
float OCP_SIN
Single precision.
Definition: OCPConst.hpp:28
unsigned int OCP_USI
Long unsigned integer.
Definition: OCPConst.hpp:25
unsigned long long OCP_ULL
Long long unsigned integer.
Definition: OCPConst.hpp:24
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47