1 #if !defined(NO_TABULAR_BACKENDS)
14 std::size_t i, std::size_t j) {
15 bool in_bounds = (i < table.
xvec.size() - 1 && j < table.
yvec.size() - 1);
17 throw ValueError(
"Cell to TTSEBackend::evaluate_single_phase_transport is not valid");
22 throw ValueError(
"Cell to TTSEBackend::evaluate_single_phase_transport must have four valid corners for now");
24 const std::vector<std::vector<double>>& f = table.
get(output);
26 double x1 = table.
xvec[i], x2 = table.
xvec[i + 1], y1 = table.
yvec[j], y2 = table.
yvec[j + 1];
27 double f11 = f[i][j], f12 = f[i][j + 1], f21 = f[i + 1][j], f22 = f[i + 1][j + 1];
29 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));
46 parameters output,
double x,
double y, std::size_t i, std::size_t j) {
47 connect_pointers(output, table);
50 double deltay = y - table.
yvec[j];
53 double a = 0.5 * (*d2zdx2)[i][j];
54 double b = (*dzdx)[i][j] + deltay * (*d2zdxdy)[i][j];
55 double c = (*z)[i][j] - x + deltay * (*dzdy)[i][j] + 0.5 * deltay * deltay * (*d2zdy2)[i][j];
57 double deltax1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
58 double deltax2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
61 double xspacing, xratio, val;
63 xspacing = table.
xvec[1] - table.
xvec[0];
64 if (std::abs(deltax1) < xspacing && !(std::abs(deltax2) < xspacing)) {
65 val = deltax1 + table.
xvec[i];
66 }
else if (std::abs(deltax2) < xspacing && !(std::abs(deltax1) < xspacing)) {
67 val = deltax2 + table.
xvec[i];
68 }
else if (std::abs(deltax1) < std::abs(deltax2) && std::abs(deltax1) < 10 * xspacing) {
69 val = deltax1 + table.
xvec[i];
71 throw ValueError(
format(
"Cannot find the x solution; xspacing: %g dx1: %g dx2: %g", xspacing, deltax1, deltax2));
74 xratio = table.
xvec[1] / table.
xvec[0];
75 double xj = table.
xvec[j];
76 double xratio1 = (xj + deltax1) / xj;
77 double xratio2 = (xj + deltax2) / xj;
78 if (xratio1 < xratio && xratio1 > 1 / xratio) {
79 val = deltax1 + table.
xvec[i];
80 }
else if (xratio2 < xratio && xratio2 > 1 / xratio) {
81 val = deltax2 + table.
xvec[i];
82 }
else if (xratio1 < xratio * 5 && xratio1 > 1 / xratio / 5) {
83 val = deltax1 + table.
xvec[i];
85 throw ValueError(
format(
"Cannot find the x solution; xj: %g xratio: %g xratio1: %g xratio2: %g a: %g b^2-4*a*c %g", xj, xratio, xratio1,
86 xratio2, a, b * b - 4 * a * c));
104 parameters output,
double y,
double x, std::size_t i, std::size_t j) {
105 connect_pointers(output, table);
108 double deltax = x - table.
xvec[i];
111 double a = 0.5 * (*d2zdy2)[i][j];
112 double b = (*dzdy)[i][j] + deltax * (*d2zdxdy)[i][j];
113 double c = (*z)[i][j] - y + deltax * (*dzdx)[i][j] + 0.5 * deltax * deltax * (*d2zdx2)[i][j];
115 double deltay1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a);
116 double deltay2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);
119 double yspacing, yratio, val;
121 yspacing = table.
yvec[1] - table.
yvec[0];
122 if (std::abs(deltay1) < yspacing && !(std::abs(deltay2) < yspacing)) {
123 val = deltay1 + table.
yvec[j];
124 }
else if (std::abs(deltay2) < yspacing && !(std::abs(deltay1) < yspacing)) {
125 val = deltay2 + table.
yvec[j];
126 }
else if (std::abs(deltay1) < std::abs(deltay2) && std::abs(deltay1) < 10 * yspacing) {
127 val = deltay1 + table.
yvec[j];
129 throw ValueError(
format(
"Cannot find the y solution; yspacing: %g dy1: %g dy2: %g", yspacing, deltay1, deltay2));
132 yratio = table.
yvec[1] / table.
yvec[0];
133 double yj = table.
yvec[j];
134 double yratio1 = (yj + deltay1) / yj;
135 double yratio2 = (yj + deltay2) / yj;
136 if (yratio1 < yratio && yratio1 > 1 / yratio) {
137 val = deltay1 + table.
yvec[j];
138 }
else if (yratio2 < yratio && yratio2 > 1 / yratio) {
139 val = deltay2 + table.
yvec[j];
140 }
else if (std::abs(yratio1 - 1) < std::abs(yratio2 - 1)) {
141 val = deltay1 + table.
yvec[j];
142 }
else if (std::abs(yratio2 - 1) < std::abs(yratio1 - 1)) {
143 val = deltay2 + table.
yvec[j];
145 throw ValueError(
format(
"Cannot find the y solution; yj: %g yratio: %g yratio1: %g yratio2: %g a: %g b: %g b^2-4ac: %g %d %d", yj, yratio,
146 yratio1, yratio2, a, b, b * b - 4 * a * c, i, j));
151 switch (table.
ykey) {
168 connect_pointers(output, table);
171 double deltax = x - table.
xvec[i];
172 double deltay = y - table.
yvec[j];
175 double val = (*z)[i][j] + deltax * (*dzdx)[i][j] + deltay * (*dzdy)[i][j] + 0.5 * deltax * deltax * (*d2zdx2)[i][j]
176 + 0.5 * deltay * deltay * (*d2zdy2)[i][j] + deltay * deltax * (*d2zdxdy)[i][j];
202 std::size_t i, std::size_t j, std::size_t Nx, std::size_t Ny) {
203 if (Nx == 1 && Ny == 0) {
204 if (output == table.
xkey) {
207 if (output == table.
ykey) {
210 }
else if (Ny == 1 && Nx == 0) {
211 if (output == table.
ykey) {
214 if (output == table.
xkey) {
219 connect_pointers(output, table);
222 double deltax = x - table.
xvec[i];
223 double deltay = y - table.
yvec[j];
226 if (Nx == 1 && Ny == 0) {
227 if (output == table.
xkey) {
230 if (output == table.
ykey) {
233 val = (*dzdx)[i][j] + deltax * (*d2zdx2)[i][j] + deltay * (*d2zdxdy)[i][j];
234 }
else if (Ny == 1 && Nx == 0) {
235 if (output == table.
ykey) {
238 if (output == table.
xkey) {
241 val = (*dzdy)[i][j] + deltay * (*d2zdy2)[i][j] + deltax * (*d2zdxdy)[i][j];