|
8 | 8 | #include <bout/mesh.hxx> |
9 | 9 | #include <bout/msg_stack.hxx> |
10 | 10 | #include <bout/output.hxx> |
| 11 | +#include <bout/sys/generator_context.hxx> |
11 | 12 | #include <bout/utils.hxx> |
12 | 13 |
|
13 | 14 | using bout::generator::Context; |
@@ -460,18 +461,18 @@ void BoundaryDirichlet::apply(Field3D& f, BoutReal t) { |
460 | 461 |
|
461 | 462 | for (; !bndry->isDone(); bndry->next1d()) { |
462 | 463 | // Calculate the X and Y normalised values half-way between the guard cell and grid cell |
463 | | - BoutReal xnorm = 0.5 |
464 | | - * (mesh->GlobalX(bndry->x) // In the guard cell |
465 | | - + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell |
| 464 | + const BoutReal xnorm = 0.5 |
| 465 | + * (mesh->GlobalX(bndry->x) // In the guard cell |
| 466 | + + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell |
466 | 467 |
|
467 | | - BoutReal ynorm = 0.5 |
468 | | - * (mesh->GlobalY(bndry->y) // In the guard cell |
469 | | - + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell |
| 468 | + const BoutReal ynorm = TWOPI * 0.5 |
| 469 | + * (mesh->GlobalY(bndry->y) // In the guard cell |
| 470 | + + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell |
470 | 471 |
|
471 | 472 | for (int zk = 0; zk < mesh->LocalNz; zk++) { |
472 | 473 | if (fg) { |
473 | | - val = fg->generate(xnorm, TWOPI * ynorm, TWOPI * (zk - 0.5) / (mesh->LocalNz), |
474 | | - t); |
| 474 | + val = fg->generate( |
| 475 | + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); |
475 | 476 | } |
476 | 477 | f(bndry->x, bndry->y, zk) = |
477 | 478 | 2 * val - f(bndry->x - bndry->bx, bndry->y - bndry->by, zk); |
@@ -508,14 +509,14 @@ void BoundaryDirichlet::apply(Field3D& f, BoutReal t) { |
508 | 509 | // can help with the stability of higher order methods. |
509 | 510 | for (int i = 1; i < bndry->width; i++) { |
510 | 511 | // Set any other guard cells using the values on the cells |
511 | | - int xi = bndry->x + i * bndry->bx; |
512 | | - int yi = bndry->y + i * bndry->by; |
513 | | - xnorm = mesh->GlobalX(xi); |
514 | | - ynorm = mesh->GlobalY(yi); |
| 512 | + const int xi = bndry->x + (i * bndry->bx); |
| 513 | + const int yi = bndry->y + (i * bndry->by); |
| 514 | + const auto xnorm = mesh->GlobalX(xi); |
| 515 | + const auto ynorm = mesh->GlobalY(yi) * TWOPI; |
515 | 516 | for (int zk = 0; zk < mesh->LocalNz; zk++) { |
516 | 517 | if (fg) { |
517 | | - val = fg->generate(xnorm, TWOPI * ynorm, |
518 | | - TWOPI * (zk - 0.5) / (mesh->LocalNz), t); |
| 518 | + val = fg->generate( |
| 519 | + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); |
519 | 520 | } |
520 | 521 | f(xi, yi, zk) = val; |
521 | 522 | } |
@@ -965,18 +966,18 @@ void BoundaryDirichlet_O3::apply(Field3D& f, BoutReal t) { |
965 | 966 |
|
966 | 967 | for (; !bndry->isDone(); bndry->next1d()) { |
967 | 968 | // Calculate the X and Y normalised values half-way between the guard cell and grid cell |
968 | | - BoutReal xnorm = 0.5 |
969 | | - * (mesh->GlobalX(bndry->x) // In the guard cell |
970 | | - + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell |
| 969 | + const BoutReal xnorm = 0.5 |
| 970 | + * (mesh->GlobalX(bndry->x) // In the guard cell |
| 971 | + + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell |
971 | 972 |
|
972 | | - BoutReal ynorm = 0.5 |
973 | | - * (mesh->GlobalY(bndry->y) // In the guard cell |
974 | | - + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell |
| 973 | + const BoutReal ynorm = TWOPI * 0.5 |
| 974 | + * (mesh->GlobalY(bndry->y) // In the guard cell |
| 975 | + + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell |
975 | 976 |
|
976 | 977 | for (int zk = 0; zk < mesh->LocalNz; zk++) { |
977 | 978 | if (fg) { |
978 | | - val = fg->generate(xnorm, TWOPI * ynorm, TWOPI * (zk - 0.5) / (mesh->LocalNz), |
979 | | - t); |
| 979 | + val = fg->generate( |
| 980 | + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); |
980 | 981 | } |
981 | 982 |
|
982 | 983 | f(bndry->x, bndry->y, zk) = |
@@ -1431,18 +1432,18 @@ void BoundaryDirichlet_O4::apply(Field3D& f, BoutReal t) { |
1431 | 1432 | // Shifted in Z |
1432 | 1433 | for (; !bndry->isDone(); bndry->next1d()) { |
1433 | 1434 | // Calculate the X and Y normalised values half-way between the guard cell and grid cell |
1434 | | - BoutReal xnorm = 0.5 |
1435 | | - * (mesh->GlobalX(bndry->x) // In the guard cell |
1436 | | - + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell |
| 1435 | + const BoutReal xnorm = 0.5 |
| 1436 | + * (mesh->GlobalX(bndry->x) // In the guard cell |
| 1437 | + + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell |
1437 | 1438 |
|
1438 | | - BoutReal ynorm = 0.5 |
1439 | | - * (mesh->GlobalY(bndry->y) // In the guard cell |
1440 | | - + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell |
| 1439 | + const BoutReal ynorm = TWOPI * 0.5 |
| 1440 | + * (mesh->GlobalY(bndry->y) // In the guard cell |
| 1441 | + + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell |
1441 | 1442 |
|
1442 | 1443 | for (int zk = 0; zk < mesh->LocalNz; zk++) { |
1443 | 1444 | if (fg) { |
1444 | | - val = fg->generate(xnorm, TWOPI * ynorm, TWOPI * (zk - 0.5) / (mesh->LocalNz), |
1445 | | - t); |
| 1445 | + val = fg->generate( |
| 1446 | + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); |
1446 | 1447 | } |
1447 | 1448 |
|
1448 | 1449 | f(bndry->x, bndry->y, zk) = |
@@ -2137,20 +2138,22 @@ void BoundaryNeumann_NonOrthogonal::apply(Field3D& f) { |
2137 | 2138 | for (; !bndry->isDone(); bndry->next1d()) { |
2138 | 2139 | // Calculate the X and Y normalised values half-way between the guard cell and |
2139 | 2140 | // grid cell |
2140 | | - BoutReal xnorm = 0.5 |
2141 | | - * (mesh->GlobalX(bndry->x) // In the guard cell |
2142 | | - + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell |
| 2141 | + const BoutReal xnorm = |
| 2142 | + 0.5 |
| 2143 | + * (mesh->GlobalX(bndry->x) // In the guard cell |
| 2144 | + + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell |
2143 | 2145 |
|
2144 | | - BoutReal ynorm = 0.5 |
2145 | | - * (mesh->GlobalY(bndry->y) // In the guard cell |
2146 | | - + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell |
| 2146 | + const BoutReal ynorm = |
| 2147 | + TWOPI * 0.5 |
| 2148 | + * (mesh->GlobalY(bndry->y) // In the guard cell |
| 2149 | + + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell |
2147 | 2150 |
|
2148 | 2151 | for (int zk = 0; zk < mesh->LocalNz; zk++) { |
2149 | 2152 | BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, zk) |
2150 | 2153 | + bndry->by * metric->dy(bndry->x, bndry->y, zk); |
2151 | 2154 | if (fg) { |
2152 | | - val = fg->generate(xnorm, TWOPI * ynorm, |
2153 | | - TWOPI * (zk - 0.5) / (mesh->LocalNz), t); |
| 2155 | + val = fg->generate( |
| 2156 | + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); |
2154 | 2157 | } |
2155 | 2158 | f(bndry->x, bndry->y, zk) = |
2156 | 2159 | f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + delta * val; |
|
0 commit comments