1#if !defined(NO_TABULAR_BACKENDS)
11 const std::vector<std::vector<CellCoeffs>>& coeffs,
double x,
double y,
12 std::size_t& i, std::size_t& j) {
23 throw ValueError(
format(
"Cell is invalid and has no good neighbors for x = %g, y= %g", x, y));
32 const double otherval, std::size_t& i, std::size_t& j) {
43 throw ValueError(
format(
"Cell is invalid and has no good neighbors for x = %g, y = %g", value1, otherval));
57 std::size_t i, std::size_t j) {
59 std::vector<std::vector<double>>* f =
nullptr;
68 throw ValueError(
format(
"invalid output variable to BicubicBackend::evaluate_single_phase_transport"));
70 double x1 = table.
xvec[i], x2 = table.
xvec[i + 1], y1 = table.
yvec[j], y2 = table.
yvec[j + 1];
71 double f11 = (*f)[i][j], f12 = (*f)[i][j + 1], f21 = (*f)[i + 1][j], f22 = (*f)[i + 1][j + 1];
73 1 / ((x2 - x1) * (y2 - y1)) * (f11 * (x2 - x) * (y2 - y) + f21 * (x - x1) * (y2 - y) + f12 * (x2 - x) * (y - y1) + f22 * (x - x1) * (y - y1));
84 throw ValueError(
"Invalid output variable in evaluate_single_phase_transport");
90 const parameters output,
const double x,
const double y,
const std::size_t i,
91 const std::size_t j) {
102 throw ValueError(
format(
"evaluate_single_phase called on cell (%zu, %zu) with no bicubic coefficients (x=%g, y=%g)", i, j, x, y));
106 const std::vector<double>& alpha = cell.
get(output);
109 double xhat = (x - table.
xvec[i]) / (table.
xvec[i + 1] - table.
xvec[i]);
110 double yhat = (y - table.
yvec[j]) / (table.
yvec[j + 1] - table.
yvec[j]);
114 double B0 = ((((0) + alpha[3 * 4 + 0]) * yhat + alpha[2 * 4 + 0]) * yhat + alpha[1 * 4 + 0]) * yhat + alpha[0 * 4 + 0];
116 double B1 = ((((0) + alpha[3 * 4 + 1]) * yhat + alpha[2 * 4 + 1]) * yhat + alpha[1 * 4 + 1]) * yhat + alpha[0 * 4 + 1];
118 double B2 = ((((0) + alpha[3 * 4 + 2]) * yhat + alpha[2 * 4 + 2]) * yhat + alpha[1 * 4 + 2]) * yhat + alpha[0 * 4 + 2];
120 double B3 = ((((0) + alpha[3 * 4 + 3]) * yhat + alpha[2 * 4 + 3]) * yhat + alpha[1 * 4 + 3]) * yhat + alpha[0 * 4 + 3];
122 double val = ((((0) + B3) * xhat + B2) * xhat + B1) * xhat + B0;
142 throw ValueError(
"Invalid output variable in evaluate_single_phase");
148 parameters output,
double x,
double y, std::size_t i, std::size_t j, std::size_t Nx,
155 const std::vector<double>& alpha = cell.
get(output);
158 double xhat = (x - table.
xvec[i]) / (table.
xvec[i + 1] - table.
xvec[i]);
159 double yhat = (y - table.
yvec[j]) / (table.
yvec[j + 1] - table.
yvec[j]);
160 double dxhatdx = 1 / (table.
xvec[i + 1] - table.
xvec[i]);
161 double dyhatdy = 1 / (table.
yvec[j + 1] - table.
yvec[j]);
165 if (Nx == 1 && Ny == 0) {
166 if (output == table.
xkey) {
169 if (output == table.
ykey) {
172 for (std::size_t l = 1; l < 4; ++l) {
173 for (std::size_t m = 0; m < 4; ++m) {
174 val += alpha[m * 4 + l] * l * pow(xhat,
static_cast<int>(l - 1)) * pow(yhat,
static_cast<int>(m));
178 return val * dxhatdx;
179 }
else if (Ny == 1 && Nx == 0) {
180 if (output == table.
ykey) {
183 if (output == table.
xkey) {
186 for (std::size_t l = 0; l < 4; ++l) {
187 for (std::size_t m = 1; m < 4; ++m) {
188 val += alpha[m * 4 + l] * pow(xhat,
static_cast<int>(l)) * m * pow(yhat,
static_cast<int>(m - 1));
192 return val * dyhatdy;
200 parameters other_key,
double other,
double y, std::size_t i, std::size_t j) {
205 const std::vector<double>& alpha = cell.
get(other_key);
208 double yhat = (y - table.
yvec[j]) / (table.
yvec[j + 1] - table.
yvec[j]);
210 double y_0 = 1, y_1 = yhat, y_2 = yhat * yhat, y_3 = yhat * yhat * yhat;
212 double a = alpha[3 + 0 * 4] * y_0 + alpha[3 + 1 * 4] * y_1 + alpha[3 + 2 * 4] * y_2 + alpha[3 + 3 * 4] * y_3;
213 double b = alpha[2 + 0 * 4] * y_0 + alpha[2 + 1 * 4] * y_1 + alpha[2 + 2 * 4] * y_2 + alpha[2 + 3 * 4] * y_3;
214 double c = alpha[1 + 0 * 4] * y_0 + alpha[1 + 1 * 4] * y_1 + alpha[1 + 2 * 4] * y_2 + alpha[1 + 3 * 4] * y_3;
215 double d = alpha[0 + 0 * 4] * y_0 + alpha[0 + 1 * 4] * y_1 + alpha[0 + 2 * 4] * y_2 + alpha[0 + 3 * 4] * y_3 - other;
217 double xhat0 = NAN, xhat1 = NAN, xhat2 = NAN, val = NAN, xhat = _HUGE;
222 xhat = std::abs(xhat0) < std::abs(xhat1) ? xhat0 : xhat1;
224 if (std::abs(xhat0) < std::abs(xhat1) && std::abs(xhat0) < std::abs(xhat2)) {
228 else if (std::abs(xhat1) < std::abs(xhat2)) {
234 throw ValueError(
"Could not find a solution in invert_single_phase_x");
239 val = xhat * (table.
xvec[i + 1] - table.
xvec[i]) + table.
xvec[i];
242 switch (table.
xkey) {
250 throw ValueError(
"Invalid output variable in invert_single_phase_x");
256 parameters other_key,
double other,
double x, std::size_t i, std::size_t j) {
261 const std::vector<double>& alpha = cell.
get(other_key);
264 double xhat = (x - table.
xvec[i]) / (table.
xvec[i + 1] - table.
xvec[i]);
266 double x_0 = 1, x_1 = xhat, x_2 = xhat * xhat, x_3 = xhat * xhat * xhat;
268 double a = alpha[0 + 3 * 4] * x_0 + alpha[1 + 3 * 4] * x_1 + alpha[2 + 3 * 4] * x_2 + alpha[3 + 3 * 4] * x_3;
269 double b = alpha[0 + 2 * 4] * x_0 + alpha[1 + 2 * 4] * x_1 + alpha[2 + 2 * 4] * x_2 + alpha[3 + 2 * 4] * x_3;
270 double c = alpha[0 + 1 * 4] * x_0 + alpha[1 + 1 * 4] * x_1 + alpha[2 + 1 * 4] * x_2 + alpha[3 + 1 * 4] * x_3;
271 double d = alpha[0 + 0 * 4] * x_0 + alpha[1 + 0 * 4] * x_1 + alpha[2 + 0 * 4] * x_2 + alpha[3 + 0 * 4] * x_3 - other;
273 double yhat0 = NAN, yhat1 = NAN, yhat2 = NAN, val = NAN, yhat = _HUGE;
278 yhat = std::abs(yhat0) < std::abs(yhat1) ? yhat0 : yhat1;
280 if (std::abs(yhat0) < std::abs(yhat1) && std::abs(yhat0) < std::abs(yhat2)) {
284 else if (std::abs(yhat1) < std::abs(yhat2)) {
290 throw ValueError(
"Could not find a solution in invert_single_phase_x");
295 val = yhat * (table.
yvec[j + 1] - table.
yvec[j]) + table.
yvec[j];
298 switch (table.
ykey) {
303 throw ValueError(
"Invalid output variable in invert_single_phase_x");