OpenCAEPoro  0.2.0 Sep/22/2022
A simulator for multicomponent porous media flow
Public Member Functions | List of all members
OCPTable Class Reference

#include <OCPTable.hpp>

Public Member Functions

 OCPTable ()=default
 Default constructor.
 
 OCPTable (const USI &row, const USI &col)
 Construct a table of fixed size.
 
 OCPTable (const vector< vector< OCP_DBL >> &src)
 Construct from existing data.
 
void Setup (const vector< vector< OCP_DBL >> &src)
 Setup tables from existing data of table.
 
bool IsEmpty () const
 judge if table is empty.
 
USI GetColNum () const
 return the column num of table.
 
OCP_INT GetRowZero (const USI &mycol) const
 return the row index of the last zero of some colnum, which is sorted in increasing order.
 
void PushCol (const vector< OCP_DBL > &v)
 push v into the last column of table.
 
vector< OCP_DBL > & GetCol (const USI &j)
 return the jth column in table to modify or use.
 
void SetRowCol ()
 Setup row nums and col nums of tables, initialize the bId.
 
USI Eval_All (const USI &j, const OCP_DBL &val, vector< OCP_DBL > &outdata, vector< OCP_DBL > &slope)
 
USI Eval_All0 (const OCP_DBL &val, vector< OCP_DBL > &outdata)
 
OCP_DBL Eval (const USI &j, const OCP_DBL &val, const USI &destj)
 
OCP_DBL Eval (const USI &j, const OCP_DBL &val, const USI &destj, OCP_DBL &myK)
 
OCP_DBL Eval_Inv (const USI &j, const OCP_DBL &val, const USI &destj)
 
void Display () const
 Display the data of table on screen.
 

Detailed Description

OCPTable is a Table class, which used to deal with everything about table in OpenCAEPoro such as PVT table, saturation table.

Definition at line 26 of file OCPTable.hpp.

Member Function Documentation

◆ Eval() [1/2]

OCP_DBL OCPTable::Eval ( const USI j,
const OCP_DBL val,
const USI destj 
)

interpolate the specified monotonically increasing column in table to evaluate the target column.

Definition at line 135 of file OCPTable.cpp.

136 {
137  // becareful when the memory outdata and slope have not be allocated before
138 
139  if (val >= data[j][bId]) {
140  for (USI i = bId + 1; i < nRow; i++) {
141  if (val < data[j][i]) {
142  bId = i - 1;
143  OCP_DBL k = (data[destj][bId + 1] - data[destj][bId]) /
144  (data[j][bId + 1] - data[j][bId]);
145  return (data[destj][bId] + k * (val - data[j][bId]));
146  }
147  }
148  return data[destj].back();
149  } else {
150  for (OCP_INT i = bId - 1; i >= 0; i--) {
151  if (val >= data[j][i]) {
152  bId = i;
153  OCP_DBL k = (data[destj][bId + 1] - data[destj][bId]) /
154  (data[j][bId + 1] - data[j][bId]);
155  return (data[destj][bId] + k * (val - data[j][bId]));
156  }
157  }
158  return data[destj].front();
159  }
160 }
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:22
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:26
int OCP_INT
Long integer.
Definition: OCPConst.hpp:25

◆ Eval() [2/2]

OCP_DBL OCPTable::Eval ( const USI j,
const OCP_DBL val,
const USI destj,
OCP_DBL myK 
)

interpolate the specified monotonically increasing column in table to evaluate the target column, and return corresponding slope.

Definition at line 163 of file OCPTable.cpp.

164 {
165  // becareful when the memory outdata and slope have not be allocated before
166 
167  if (val >= data[j][bId]) {
168  for (USI i = bId + 1; i < nRow; i++) {
169  if (val < data[j][i]) {
170  bId = i - 1;
171  myK = (data[destj][bId + 1] - data[destj][bId]) /
172  (data[j][bId + 1] - data[j][bId]);
173  return (data[destj][bId] + myK * (val - data[j][bId]));
174  }
175  }
176  return data[destj].back();
177  }
178  else {
179  for (OCP_INT i = bId - 1; i >= 0; i--) {
180  if (val >= data[j][i]) {
181  bId = i;
182  myK = (data[destj][bId + 1] - data[destj][bId]) /
183  (data[j][bId + 1] - data[j][bId]);
184  return (data[destj][bId] + myK * (val - data[j][bId]));
185  }
186  }
187  return data[destj].front();
188  }
189 }

◆ Eval_All()

USI OCPTable::Eval_All ( const USI j,
const OCP_DBL val,
vector< OCP_DBL > &  outdata,
vector< OCP_DBL > &  slope 
)

interpolate the specified monotonically increasing column in table to evaluate all columns and return slope

Definition at line 53 of file OCPTable.cpp.

55 {
56  // becareful when the memory outdata and slope have not be allocated before
57 
58  if (val >= data[j][bId]) {
59  for (USI i = bId + 1; i < nRow; i++) {
60  if (val < data[j][i]) {
61  bId = i - 1;
62  for (USI k = 0; k < nCol; k++) {
63  slope[k] = (data[k][bId + 1] - data[k][bId]) /
64  (data[j][bId + 1] - data[j][bId]);
65  outdata[k] = data[k][bId] + slope[k] * (val - data[j][bId]);
66  }
67  return bId;
68  }
69  }
70  for (USI k = 0; k < nCol; k++) {
71  slope[k] = 0;
72  outdata[k] = data[k].back();
73  }
74  } else {
75  for (OCP_INT i = bId - 1; i >= 0; i--) {
76  if (val >= data[j][i]) {
77  bId = i;
78  for (USI k = 0; k < nCol; k++) {
79  slope[k] = (data[k][bId + 1] - data[k][bId]) /
80  (data[j][bId + 1] - data[j][bId]);
81  outdata[k] = data[k][bId] + slope[k] * (val - data[j][bId]);
82  }
83  return bId;
84  }
85  }
86  for (USI k = 0; k < nCol; k++) {
87  slope[k] = 0;
88  outdata[k] = data[k].front();
89  }
90  }
91  return bId;
92 }

◆ Eval_All0()

USI OCPTable::Eval_All0 ( const OCP_DBL val,
vector< OCP_DBL > &  outdata 
)

interpolate the specified monotonically increasing column in table to evaluate all columns, j = 0 here and index of returnning date begins from 1

Definition at line 95 of file OCPTable.cpp.

96 {
97  const USI j = 0;
98  OCP_DBL tmpk = 0;
99  if (val >= data[j][bId]) {
100  for (USI i = bId + 1; i < nRow; i++) {
101  if (val < data[j][i]) {
102  bId = i - 1;
103  for (USI k = 1; k < nCol; k++) {
104  tmpk = (data[k][bId + 1] - data[k][bId]) /
105  (data[j][bId + 1] - data[j][bId]);
106  outdata[k - 1] = data[k][bId] + tmpk * (val - data[j][bId]);
107  }
108  return bId;
109  }
110  }
111  for (USI k = 1; k < nCol; k++) {
112  outdata[k - 1] = data[k].back();
113  }
114  }
115  else {
116  for (OCP_INT i = bId - 1; i >= 0; i--) {
117  if (val >= data[j][i]) {
118  bId = i;
119  for (USI k = 1; k < nCol; k++) {
120  tmpk = (data[k][bId + 1] - data[k][bId]) /
121  (data[j][bId + 1] - data[j][bId]);
122  outdata[k - 1] = data[k][bId] + tmpk * (val - data[j][bId]);
123  }
124  return bId;
125  }
126  }
127  for (USI k = 1; k < nCol; k++) {
128  outdata[k - 1] = data[k].front();
129  }
130  }
131  return bId;
132 }

◆ Eval_Inv()

OCP_DBL OCPTable::Eval_Inv ( const USI j,
const OCP_DBL val,
const USI destj 
)

interpolate the specified monotonically decreasing column in table to evaluate the target column.

Definition at line 192 of file OCPTable.cpp.

193 {
194  // becareful when the memory outdata and slope have not be allocated before
195 
196  if (val > data[j][bId]) {
197  for (OCP_INT i = bId - 1; i >= 0; i--) {
198  if (val <= data[j][i]) {
199  bId = i;
200  OCP_DBL k = (data[destj][bId + 1] - data[destj][bId]) /
201  (data[j][bId + 1] - data[j][bId]);
202  return (data[destj][bId] + k * (val - data[j][bId]));
203  }
204  }
205  return data[destj].front();
206  } else {
207  for (USI i = bId + 1; i < nRow; i++) {
208  if (val >= data[j][i]) {
209  bId = i;
210  OCP_DBL k = (data[destj][bId] - data[destj][bId - 1]) /
211  (data[j][bId] - data[j][bId - 1]);
212  return (data[destj][bId - 1] + k * (val - data[j][bId - 1]));
213  }
214  }
215  return data[destj].back();
216  }
217 }

The documentation for this class was generated from the following files: