OpenCAEPoro  v0.5.0
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.
 
OCP_BOOL IsEmpty () const
 judge if table is empty.
 
USI GetColNum () const
 return the column num of table.
 
OCP_INT GetRowZero (const USI &mycol) const
 
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)
 Careful: the memory outdata and slope have not be allocated before. More...
 
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 126 of file OCPTable.cpp.

127 {
128  if (val >= data[j][bId]) {
129  for (USI i = bId + 1; i < nRow; i++) {
130  if (val < data[j][i]) {
131  bId = i - 1;
132  OCP_DBL k = (data[destj][bId + 1] - data[destj][bId]) /
133  (data[j][bId + 1] - data[j][bId]);
134  return (data[destj][bId] + k * (val - data[j][bId]));
135  }
136  }
137  return data[destj].back();
138  } else {
139  for (OCP_INT i = bId - 1; i >= 0; i--) {
140  if (val >= data[j][i]) {
141  bId = i;
142  OCP_DBL k = (data[destj][bId + 1] - data[destj][bId]) /
143  (data[j][bId + 1] - data[j][bId]);
144  return (data[destj][bId] + k * (val - data[j][bId]));
145  }
146  }
147  return data[destj].front();
148  }
149 }
unsigned int USI
Generic unsigned integer.
Definition: OCPConst.hpp:23
double OCP_DBL
Double precision.
Definition: OCPConst.hpp:27
int OCP_INT
Long integer.
Definition: OCPConst.hpp:26

◆ 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 151 of file OCPTable.cpp.

152 {
153  // becareful when the memory outdata and slope have not be allocated before
154 
155  if (val >= data[j][bId]) {
156  for (USI i = bId + 1; i < nRow; i++) {
157  if (val < data[j][i]) {
158  bId = i - 1;
159  myK = (data[destj][bId + 1] - data[destj][bId]) /
160  (data[j][bId + 1] - data[j][bId]);
161  return (data[destj][bId] + myK * (val - data[j][bId]));
162  }
163  }
164  return data[destj].back();
165  } else {
166  for (OCP_INT i = bId - 1; i >= 0; i--) {
167  if (val >= data[j][i]) {
168  bId = i;
169  myK = (data[destj][bId + 1] - data[destj][bId]) /
170  (data[j][bId + 1] - data[j][bId]);
171  return (data[destj][bId] + myK * (val - data[j][bId]));
172  }
173  }
174  return data[destj].front();
175  }
176 }

◆ Eval_All()

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

Careful: the memory outdata and slope have not be allocated before.

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

Definition at line 47 of file OCPTable.cpp.

51 {
52  if (val >= data[j][bId]) {
53  for (USI i = bId + 1; i < nRow; i++) {
54  if (val < data[j][i]) {
55  bId = i - 1;
56  for (USI k = 0; k < nCol; k++) {
57  slope[k] = (data[k][bId + 1] - data[k][bId]) /
58  (data[j][bId + 1] - data[j][bId]);
59  outdata[k] = data[k][bId] + slope[k] * (val - data[j][bId]);
60  }
61  return bId;
62  }
63  }
64  for (USI k = 0; k < nCol; k++) {
65  slope[k] = 0;
66  outdata[k] = data[k].back();
67  }
68  } else {
69  for (OCP_INT i = bId - 1; i >= 0; i--) {
70  if (val >= data[j][i]) {
71  bId = i;
72  for (USI k = 0; k < nCol; k++) {
73  slope[k] = (data[k][bId + 1] - data[k][bId]) /
74  (data[j][bId + 1] - data[j][bId]);
75  outdata[k] = data[k][bId] + slope[k] * (val - data[j][bId]);
76  }
77  return bId;
78  }
79  }
80  for (USI k = 0; k < nCol; k++) {
81  slope[k] = 0;
82  outdata[k] = data[k].front();
83  }
84  }
85  return bId;
86 }

◆ 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 returning date begins from 1

Definition at line 88 of file OCPTable.cpp.

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

◆ 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 178 of file OCPTable.cpp.

179 {
180  // becareful when the memory outdata and slope have not be allocated before
181 
182  if (val > data[j][bId]) {
183  for (OCP_INT i = bId - 1; i >= 0; i--) {
184  if (val <= data[j][i]) {
185  bId = i;
186  OCP_DBL k = (data[destj][bId + 1] - data[destj][bId]) /
187  (data[j][bId + 1] - data[j][bId]);
188  return (data[destj][bId] + k * (val - data[j][bId]));
189  }
190  }
191  return data[destj].front();
192  } else {
193  for (USI i = bId + 1; i < nRow; i++) {
194  if (val >= data[j][i]) {
195  bId = i;
196  OCP_DBL k = (data[destj][bId] - data[destj][bId - 1]) /
197  (data[j][bId] - data[j][bId - 1]);
198  return (data[destj][bId - 1] + k * (val - data[j][bId - 1]));
199  }
200  }
201  return data[destj].back();
202  }
203 }

◆ GetRowZero()

OCP_INT OCPTable::GetRowZero ( const USI mycol) const

return the row index of the last zero of some colnum, which is sorted in increasing order.

Definition at line 35 of file OCPTable.cpp.

36 {
37  if (mycol > nCol) OCP_ABORT("wrong specified column!");
38  for (USI i = 0; i < nRow; i++) {
39  if (data[mycol][i] >= TINY) {
40  return i - 1;
41  }
42  }
43  return nRow - 1;
44 }
const OCP_DBL TINY
Small constant.
Definition: OCPConst.hpp:38
#define OCP_ABORT(msg)
Abort if critical error happens.
Definition: UtilError.hpp:47

References OCP_ABORT, and TINY.


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