diff --git a/include/bout/sys/expressionparser.hxx b/include/bout/sys/expressionparser.hxx index 660ad20ab3..b312ce2fb1 100644 --- a/include/bout/sys/expressionparser.hxx +++ b/include/bout/sys/expressionparser.hxx @@ -64,12 +64,6 @@ public: return nullptr; } - [[deprecated("This will be removed in a future version. Implementations should " - "override the Context version of this function.")]] virtual double - generate(BoutReal x, BoutReal y, BoutReal z, BoutReal t) { - return generate(bout::generator::Context().set("x", x, "y", y, "z", z, "t", t)); - } - /// Generate a value at the given coordinates (x,y,z,t) /// This should be deterministic, always returning the same value given the same inputs /// @@ -78,7 +72,7 @@ public: /// them or an infinite recursion results. This is for backward /// compatibility for users and implementors. In a future version /// this function will be made pure virtual. - virtual double generate(const bout::generator::Context& ctx); + virtual double generate(const bout::generator::Context& ctx) = 0; /// Create a string representation of the generator, for debugging output virtual std::string str() const { return std::string("?"); } diff --git a/src/mesh/boundary_standard.cxx b/src/mesh/boundary_standard.cxx index c12901e53a..8f2c7df5ec 100644 --- a/src/mesh/boundary_standard.cxx +++ b/src/mesh/boundary_standard.cxx @@ -8,6 +8,7 @@ #include #include #include +#include #include using bout::generator::Context; @@ -460,18 +461,18 @@ void BoundaryDirichlet::apply(Field3D& f, BoutReal t) { for (; !bndry->isDone(); bndry->next1d()) { // Calculate the X and Y normalised values half-way between the guard cell and grid cell - BoutReal xnorm = 0.5 - * (mesh->GlobalX(bndry->x) // In the guard cell - + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell + const BoutReal xnorm = 0.5 + * (mesh->GlobalX(bndry->x) // In the guard cell + + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell - BoutReal ynorm = 0.5 - * (mesh->GlobalY(bndry->y) // In the guard cell - + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell + const BoutReal ynorm = TWOPI * 0.5 + * (mesh->GlobalY(bndry->y) // In the guard cell + + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell for (int zk = 0; zk < mesh->LocalNz; zk++) { if (fg) { - val = fg->generate(xnorm, TWOPI * ynorm, TWOPI * (zk - 0.5) / (mesh->LocalNz), - t); + val = fg->generate( + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); } f(bndry->x, bndry->y, zk) = 2 * val - f(bndry->x - bndry->bx, bndry->y - bndry->by, zk); @@ -508,14 +509,14 @@ void BoundaryDirichlet::apply(Field3D& f, BoutReal t) { // can help with the stability of higher order methods. for (int i = 1; i < bndry->width; i++) { // Set any other guard cells using the values on the cells - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - xnorm = mesh->GlobalX(xi); - ynorm = mesh->GlobalY(yi); + const int xi = bndry->x + (i * bndry->bx); + const int yi = bndry->y + (i * bndry->by); + const auto xnorm = mesh->GlobalX(xi); + const auto ynorm = mesh->GlobalY(yi) * TWOPI; for (int zk = 0; zk < mesh->LocalNz; zk++) { if (fg) { - val = fg->generate(xnorm, TWOPI * ynorm, - TWOPI * (zk - 0.5) / (mesh->LocalNz), t); + val = fg->generate( + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); } f(xi, yi, zk) = val; } @@ -965,18 +966,18 @@ void BoundaryDirichlet_O3::apply(Field3D& f, BoutReal t) { for (; !bndry->isDone(); bndry->next1d()) { // Calculate the X and Y normalised values half-way between the guard cell and grid cell - BoutReal xnorm = 0.5 - * (mesh->GlobalX(bndry->x) // In the guard cell - + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell + const BoutReal xnorm = 0.5 + * (mesh->GlobalX(bndry->x) // In the guard cell + + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell - BoutReal ynorm = 0.5 - * (mesh->GlobalY(bndry->y) // In the guard cell - + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell + const BoutReal ynorm = TWOPI * 0.5 + * (mesh->GlobalY(bndry->y) // In the guard cell + + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell for (int zk = 0; zk < mesh->LocalNz; zk++) { if (fg) { - val = fg->generate(xnorm, TWOPI * ynorm, TWOPI * (zk - 0.5) / (mesh->LocalNz), - t); + val = fg->generate( + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); } f(bndry->x, bndry->y, zk) = @@ -1431,18 +1432,18 @@ void BoundaryDirichlet_O4::apply(Field3D& f, BoutReal t) { // Shifted in Z for (; !bndry->isDone(); bndry->next1d()) { // Calculate the X and Y normalised values half-way between the guard cell and grid cell - BoutReal xnorm = 0.5 - * (mesh->GlobalX(bndry->x) // In the guard cell - + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell + const BoutReal xnorm = 0.5 + * (mesh->GlobalX(bndry->x) // In the guard cell + + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell - BoutReal ynorm = 0.5 - * (mesh->GlobalY(bndry->y) // In the guard cell - + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell + const BoutReal ynorm = TWOPI * 0.5 + * (mesh->GlobalY(bndry->y) // In the guard cell + + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell for (int zk = 0; zk < mesh->LocalNz; zk++) { if (fg) { - val = fg->generate(xnorm, TWOPI * ynorm, TWOPI * (zk - 0.5) / (mesh->LocalNz), - t); + val = fg->generate( + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); } f(bndry->x, bndry->y, zk) = @@ -2137,20 +2138,22 @@ void BoundaryNeumann_NonOrthogonal::apply(Field3D& f) { for (; !bndry->isDone(); bndry->next1d()) { // Calculate the X and Y normalised values half-way between the guard cell and // grid cell - BoutReal xnorm = 0.5 - * (mesh->GlobalX(bndry->x) // In the guard cell - + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell + const BoutReal xnorm = + 0.5 + * (mesh->GlobalX(bndry->x) // In the guard cell + + mesh->GlobalX(bndry->x - bndry->bx)); // the grid cell - BoutReal ynorm = 0.5 - * (mesh->GlobalY(bndry->y) // In the guard cell - + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell + const BoutReal ynorm = + TWOPI * 0.5 + * (mesh->GlobalY(bndry->y) // In the guard cell + + mesh->GlobalY(bndry->y - bndry->by)); // the grid cell for (int zk = 0; zk < mesh->LocalNz; zk++) { BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, zk) + bndry->by * metric->dy(bndry->x, bndry->y, zk); if (fg) { - val = fg->generate(xnorm, TWOPI * ynorm, - TWOPI * (zk - 0.5) / (mesh->LocalNz), t); + val = fg->generate( + Context(bndry, zk, loc, t, mesh).set("x", xnorm, "y", ynorm)); } f(bndry->x, bndry->y, zk) = f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + delta * val; diff --git a/src/sys/expressionparser.cxx b/src/sys/expressionparser.cxx index 8290a4cae0..804f371bbe 100644 --- a/src/sys/expressionparser.cxx +++ b/src/sys/expressionparser.cxx @@ -37,12 +37,6 @@ using namespace std::string_literals; using bout::generator::Context; -// Note: Here rather than in header to avoid many deprecated warnings -// Remove in future and make this function pure virtual -double FieldGenerator::generate(const Context& ctx) { - return generate(ctx.x(), ctx.y(), ctx.z(), ctx.t()); -} - ///////////////////////////////////////////// namespace { // These classes only visible in this file