diff --git a/examples/blob2d-laplacexz/blob2d.cxx b/examples/blob2d-laplacexz/blob2d.cxx index 9622f48933..72f673f582 100644 --- a/examples/blob2d-laplacexz/blob2d.cxx +++ b/examples/blob2d-laplacexz/blob2d.cxx @@ -110,7 +110,7 @@ class Blob2D : public PhysicsModel { } int rhs(BoutReal UNUSED(t)) { - //Coordinates *coord = mesh->getCoordinates(); + // Coordinates *coord = mesh->getCoordinates(); // Run communications //////////////////////////////////////////////////////////////////////////// @@ -140,15 +140,15 @@ class Blob2D : public PhysicsModel { ///////////////////////////////////////////////////////////////////////////// ddt(n) = -bracket(phi, n, BRACKET_SIMPLE) // ExB term - + 2 * DDZ(n) * (rho_s / R_c); // Curvature term - ddt(n) += D_n*Delp2(n, CELL_DEFAULT, false); + + 2 * DDZ(n) * (rho_s / R_c); // Curvature term + ddt(n) += D_n * Delp2(n, CELL_DEFAULT, false); // if(coord->is3D()){ // ddt(n) += Div_Perp_Lap_FV(D_n, n); // Diffusion term // }else{ // ddt(n) += D_n*Delp2(n); // } - + if (compressible) { ddt(n) -= 2 * n * DDZ(phi) * (rho_s / R_c); // ExB Compression term } @@ -162,8 +162,9 @@ class Blob2D : public PhysicsModel { ///////////////////////////////////////////////////////////////////////////// ddt(omega) = -bracket(phi, omega, BRACKET_SIMPLE) // ExB term - + 2 * DDZ(n) * (rho_s / R_c) / n; // Curvature term - ddt(omega) += D_vort * Delp2(omega, CELL_DEFAULT, false)/n; // Viscous diffusion term + + 2 * DDZ(n) * (rho_s / R_c) / n; // Curvature term + ddt(omega) += + D_vort * Delp2(omega, CELL_DEFAULT, false) / n; // Viscous diffusion term // if(coord->is3D()){ // ddt(omega) += Div_Perp_Lap_FV(D_vort ,omega) / n ; // Viscous diffusion term diff --git a/examples/elm-pb/elm_pb.cxx b/examples/elm-pb/elm_pb.cxx index f8148d6a85..5549e881eb 100644 --- a/examples/elm-pb/elm_pb.cxx +++ b/examples/elm-pb/elm_pb.cxx @@ -26,10 +26,10 @@ class ELMpb : public PhysicsModel { // 2D inital profiles Field2D J0, P0; // Current and pressure Vector2D b0xcv; // Curvature term - Field2D beta; // Used for Vpar terms + Field2D beta; // Used for Vpar terms Coordinates::metric_field_type gradparB; Field2D phi0; // When diamagnetic terms used - Field2D Psixy, x; // 0th vorticity of equilibrium flow, + Field2D Psixy, x; // 0th vorticity of equilibrium flow, Coordinates::metric_field_type U0; // radial flux coordinate, normalized radial flux coordinate @@ -657,8 +657,9 @@ class ELMpb : public PhysicsModel { for (int jy = 0; jy < mesh->LocalNy; jy++) for (int jz = 0; jz < mesh->LocalNz; jz++) { - BoutReal angle = rmp_m * pol_angle(jx, jy) - + rmp_n * ((BoutReal)jz) * mesh->getCoordinates()->dz(jx,jy,jz); + BoutReal angle = + rmp_m * pol_angle(jx, jy) + + rmp_n * ((BoutReal)jz) * mesh->getCoordinates()->dz(jx, jy, jz); rmp_Psi0(jx, jy, jz) = (((BoutReal)(jx - 4)) / ((BoutReal)(mesh->LocalNx - 5))) * rmp_factor * cos(angle); diff --git a/examples/lapd-drift/lapd_drift.cxx b/examples/lapd-drift/lapd_drift.cxx index 3b7aa7950b..356ffefa6b 100644 --- a/examples/lapd-drift/lapd_drift.cxx +++ b/examples/lapd-drift/lapd_drift.cxx @@ -728,8 +728,8 @@ class LAPDdrift : public PhysicsModel { /****************SPECIAL DIFFERENTIAL OPERATORS******************/ - Coordinates::metric_field_type Perp_Grad_dot_Grad(const Field2D &p, const Field2D &f) { - + Coordinates::metric_field_type Perp_Grad_dot_Grad(const Field2D& p, const Field2D& f) { + return DDX(p)*DDX(f)*mesh->getCoordinates()->g11; } @@ -738,7 +738,7 @@ class LAPDdrift : public PhysicsModel { // ExB terms. These routines allow comparisons with BOUT-06 // if bout_exb=true is set in BOUT.inp ///////////////////////////////////////////////////////////////// - Coordinates::metric_field_type vE_Grad(const Field2D &f, const Field2D &p) { + Coordinates::metric_field_type vE_Grad(const Field2D& f, const Field2D& p) { Coordinates::metric_field_type result; if (bout_exb) { // Use a subset of terms for comparison to BOUT-06 @@ -767,25 +767,27 @@ class LAPDdrift : public PhysicsModel { int jzm = (jz - 1 + ncz) % ncz; // J++ = DDZ(p)*DDX(f) - DDX(p)*DDZ(f) - BoutReal Jpp = 0.25*( (p(jx,jy,jzp) - p(jx,jy,jzm))* - (f(jx+1,jy) - f(jx-1,jy)) - - (p(jx+1,jy,jz) - p(jx-1,jy,jz))* - (f(jx,jy) - f(jx,jy)) ) - / (coord->dx(jx,jy, jz) * coord->dz(jx,jy,jz)); - + BoutReal Jpp = + 0.25 + * ((p(jx, jy, jzp) - p(jx, jy, jzm)) * (f(jx + 1, jy) - f(jx - 1, jy)) + - (p(jx + 1, jy, jz) - p(jx - 1, jy, jz)) * (f(jx, jy) - f(jx, jy))) + / (coord->dx(jx, jy, jz) * coord->dz(jx, jy, jz)); + // J+x - BoutReal Jpx = 0.25*( f(jx+1,jy)*(p(jx+1,jy,jzp)-p(jx+1,jy,jzm)) - - f(jx-1,jy)*(p(jx-1,jy,jzp)-p(jx-1,jy,jzm)) - - f(jx,jy)*(p(jx+1,jy,jzp)-p(jx-1,jy,jzp)) + - f(jx,jy)*(p(jx+1,jy,jzm)-p(jx-1,jy,jzm))) - / (coord->dx(jx,jy, jz) * coord->dz(jx,jy,jz)); + BoutReal Jpx = 0.25 + * (f(jx + 1, jy) * (p(jx + 1, jy, jzp) - p(jx + 1, jy, jzm)) + - f(jx - 1, jy) * (p(jx - 1, jy, jzp) - p(jx - 1, jy, jzm)) + - f(jx, jy) * (p(jx + 1, jy, jzp) - p(jx - 1, jy, jzp)) + + f(jx, jy) * (p(jx + 1, jy, jzm) - p(jx - 1, jy, jzm))) + / (coord->dx(jx, jy, jz) * coord->dz(jx, jy, jz)); // Jx+ - BoutReal Jxp = 0.25*( f(jx+1,jy)*(p(jx,jy,jzp)-p(jx+1,jy,jz)) - - f(jx-1,jy)*(p(jx-1,jy,jz)-p(jx,jy,jzm)) - - f(jx-1,jy)*(p(jx,jy,jzp)-p(jx-1,jy,jz)) + - f(jx+1,jy)*(p(jx+1,jy,jz)-p(jx,jy,jzm))) - / (coord->dx(jx,jy, jz) * coord->dz(jx,jy,jz)); - + BoutReal Jxp = 0.25 + * (f(jx + 1, jy) * (p(jx, jy, jzp) - p(jx + 1, jy, jz)) + - f(jx - 1, jy) * (p(jx - 1, jy, jz) - p(jx, jy, jzm)) + - f(jx - 1, jy) * (p(jx, jy, jzp) - p(jx - 1, jy, jz)) + + f(jx + 1, jy) * (p(jx + 1, jy, jz) - p(jx, jy, jzm))) + / (coord->dx(jx, jy, jz) * coord->dz(jx, jy, jz)); + result(jx,jy,jz) = (Jpp + Jpx + Jxp) / 3.; } @@ -828,25 +830,29 @@ class LAPDdrift : public PhysicsModel { int jzm = (jz - 1 + ncz) % ncz; // J++ = DDZ(p)*DDX(f) - DDX(p)*DDZ(f) - BoutReal Jpp = 0.25*( (p(jx,jy,jzp) - p(jx,jy,jzm))* - (f(jx+1,jy,jz) - f(jx-1,jy,jz)) - - (p(jx+1,jy,jz) - p(jx-1,jy,jz))* - (f(jx,jy,jzp) - f(jx,jy,jzm)) ) - / (coord->dx(jx,jy, jz) * coord->dz(jx,jy,jz)); - + BoutReal Jpp = 0.25 + * ((p(jx, jy, jzp) - p(jx, jy, jzm)) + * (f(jx + 1, jy, jz) - f(jx - 1, jy, jz)) + - (p(jx + 1, jy, jz) - p(jx - 1, jy, jz)) + * (f(jx, jy, jzp) - f(jx, jy, jzm))) + / (coord->dx(jx, jy, jz) * coord->dz(jx, jy, jz)); + // J+x - BoutReal Jpx = 0.25*( f(jx+1,jy,jz)*(p(jx+1,jy,jzp)-p(jx+1,jy,jzm)) - - f(jx-1,jy,jz)*(p(jx-1,jy,jzp)-p(jx-1,jy,jzm)) - - f(jx,jy,jzp)*(p(jx+1,jy,jzp)-p(jx-1,jy,jzp)) + - f(jx,jy,jzm)*(p(jx+1,jy,jzm)-p(jx-1,jy,jzm))) - / (coord->dx(jx,jy, jz) * coord->dz(jx,jy,jz)); + BoutReal Jpx = + 0.25 + * (f(jx + 1, jy, jz) * (p(jx + 1, jy, jzp) - p(jx + 1, jy, jzm)) + - f(jx - 1, jy, jz) * (p(jx - 1, jy, jzp) - p(jx - 1, jy, jzm)) + - f(jx, jy, jzp) * (p(jx + 1, jy, jzp) - p(jx - 1, jy, jzp)) + + f(jx, jy, jzm) * (p(jx + 1, jy, jzm) - p(jx - 1, jy, jzm))) + / (coord->dx(jx, jy, jz) * coord->dz(jx, jy, jz)); // Jx+ - BoutReal Jxp = 0.25*( f(jx+1,jy,jzp)*(p(jx,jy,jzp)-p(jx+1,jy,jz)) - - f(jx-1,jy,jzm)*(p(jx-1,jy,jz)-p(jx,jy,jzm)) - - f(jx-1,jy,jzp)*(p(jx,jy,jzp)-p(jx-1,jy,jz)) + - f(jx+1,jy,jzm)*(p(jx+1,jy,jz)-p(jx,jy,jzm))) - / (coord->dx(jx,jy, jz) * coord->dz(jx,jy,jz)); - + BoutReal Jxp = 0.25 + * (f(jx + 1, jy, jzp) * (p(jx, jy, jzp) - p(jx + 1, jy, jz)) + - f(jx - 1, jy, jzm) * (p(jx - 1, jy, jz) - p(jx, jy, jzm)) + - f(jx - 1, jy, jzp) * (p(jx, jy, jzp) - p(jx - 1, jy, jz)) + + f(jx + 1, jy, jzm) * (p(jx + 1, jy, jz) - p(jx, jy, jzm))) + / (coord->dx(jx, jy, jz) * coord->dz(jx, jy, jz)); + result(jx,jy,jz) = (Jpp + Jpx + Jxp) / 3.; } diff --git a/examples/orszag-tang/mhd.cxx b/examples/orszag-tang/mhd.cxx index 0c185c781a..0687f3663d 100644 --- a/examples/orszag-tang/mhd.cxx +++ b/examples/orszag-tang/mhd.cxx @@ -48,7 +48,7 @@ class MHD : public PhysicsModel { Coordinates *coord = mesh->getCoordinates(); output.write("dx(0,0,0) = {:e}, dy(0,0,0) = {:e}, dz(0,0,0) = {:e}\n", - coord->dx(0, 0, 0), coord->dy(0, 0, 0), coord->dz(0, 0, 0)); + coord->dx(0, 0, 0), coord->dy(0, 0, 0), coord->dz(0, 0, 0)); SAVE_REPEAT(divB); diff --git a/include/bout/coordinates.hxx b/include/bout/coordinates.hxx index 99a824005d..13547e00cc 100644 --- a/include/bout/coordinates.hxx +++ b/include/bout/coordinates.hxx @@ -93,10 +93,8 @@ public: Field2D zlength() const { #ifdef COORDINATES_USE_3D - Field2D result(0.,localmesh); - BOUT_FOR_SERIAL(i, dz.getRegion("RGN_ALL")) { - result[i] += dz[i]; - } + Field2D result(0., localmesh); + BOUT_FOR_SERIAL(i, dz.getRegion("RGN_ALL")) { result[i] += dz[i]; } return result; #else return dz * nz; @@ -105,8 +103,8 @@ public: /// True if corrections for non-uniform mesh spacing should be included in operators bool non_uniform; - metric_field_type d1_dx, - d1_dy, d1_dz; ///< 2nd-order correction for non-uniform meshes d/di(1/dx) and d/di(1/dy) + metric_field_type d1_dx, d1_dy, + d1_dz; ///< 2nd-order correction for non-uniform meshes d/di(1/dx) and d/di(1/dy) metric_field_type J; ///< Coordinate system Jacobian, so volume of cell is J*dx*dy*dz @@ -172,59 +170,66 @@ public: #ifdef DERIV_FUNC_REGION_ENUM_TO_STRING #error This utility macro should not clash with another one #else -#define DERIV_FUNC_REGION_ENUM_TO_STRING(func, ResultType, T) \ - [[deprecated("Please use Coordinates::#func(const #T& f, " \ - "CELL_LOC outloc = CELL_DEFAULT, const std::string& method = \"DEFAULT\", " \ - "const std::string& region = \"RGN_ALL\") instead")]] \ - inline ResultType func(const T& f, CELL_LOC outloc, const std::string& method, \ - REGION region) { \ - return func(f, outloc, method, toString(region)); \ - } \ - [[deprecated("Please use Coordinates::#func(const #T& f, " \ - "CELL_LOC outloc = CELL_DEFAULT, const std::string& method = \"DEFAULT\", " \ - "const std::string& region = \"RGN_ALL\") instead")]] \ - inline ResultType func(const T& f, CELL_LOC outloc, DIFF_METHOD method, \ - REGION region = RGN_NOBNDRY) { \ - return func(f, outloc, toString(method), toString(region)); \ +#define DERIV_FUNC_REGION_ENUM_TO_STRING(func, ResultType, T) \ + [[deprecated( \ + "Please use Coordinates::#func(const #T& f, " \ + "CELL_LOC outloc = CELL_DEFAULT, const std::string& method = \"DEFAULT\", " \ + "const std::string& region = \"RGN_ALL\") instead")]] inline ResultType \ + func(const T& f, CELL_LOC outloc, const std::string& method, REGION region) { \ + return func(f, outloc, method, toString(region)); \ + } \ + [[deprecated( \ + "Please use Coordinates::#func(const #T& f, " \ + "CELL_LOC outloc = CELL_DEFAULT, const std::string& method = \"DEFAULT\", " \ + "const std::string& region = \"RGN_ALL\") instead")]] inline ResultType \ + func(const T& f, CELL_LOC outloc, DIFF_METHOD method, REGION region = RGN_NOBNDRY) { \ + return func(f, outloc, toString(method), toString(region)); \ } #endif #ifdef GRAD_FUNC_REGION_ENUM_TO_STRING #error This utility macro should not clash with another one #else -#define GRAD_FUNC_REGION_ENUM_TO_STRING(func, ResultType, T) \ - [[deprecated("Please use Coordinates::#func(const #T& f, " \ +#define GRAD_FUNC_REGION_ENUM_TO_STRING(func, ResultType, T) \ + [[deprecated( \ + "Please use Coordinates::#func(const #T& f, " \ "CELL_LOC outloc = CELL_DEFAULT, const std::string& method = \"DEFAULT\") " \ - "instead")]] \ - inline ResultType func(const T& f, CELL_LOC outloc, DIFF_METHOD method) { \ - return func(f, outloc, toString(method)); \ + "instead")]] inline ResultType \ + func(const T& f, CELL_LOC outloc, DIFF_METHOD method) { \ + return func(f, outloc, toString(method)); \ } #endif metric_field_type DDX(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(DDX, metric_field_type, Field2D); metric_field_type DDY(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(DDY, metric_field_type, Field2D); metric_field_type DDZ(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(DDZ, metric_field_type, Field2D); Field3D DDX(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); Field3D DDY(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); Field3D DDZ(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); /// Gradient along magnetic field b.Grad(f) metric_field_type Grad_par(const Field2D& var, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT"); + const std::string& method = "DEFAULT"); GRAD_FUNC_REGION_ENUM_TO_STRING(Grad_par, metric_field_type, Field2D); Field3D Grad_par(const Field3D& var, CELL_LOC outloc = CELL_DEFAULT, @@ -233,12 +238,13 @@ public: /// Advection along magnetic field V*b.Grad(f) metric_field_type Vpar_Grad_par(const Field2D& v, const Field2D& f, - CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT"); - [[deprecated("Please use Coordinates::Vpar_Grad_par(const Field2D& v, " + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT"); + [[deprecated( + "Please use Coordinates::Vpar_Grad_par(const Field2D& v, " "const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, " - "const std::string& method = \"DEFAULT\") instead")]] - inline metric_field_type Vpar_Grad_par(const Field2D& v, const Field2D& f, CELL_LOC outloc, - DIFF_METHOD method) { + "const std::string& method = \"DEFAULT\") instead")]] inline metric_field_type + Vpar_Grad_par(const Field2D& v, const Field2D& f, CELL_LOC outloc, DIFF_METHOD method) { return Vpar_Grad_par(v, f, outloc, toString(method)); } @@ -254,7 +260,7 @@ public: /// Divergence along magnetic field Div(b*f) = B.Grad(f/B) metric_field_type Div_par(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT"); + const std::string& method = "DEFAULT"); GRAD_FUNC_REGION_ENUM_TO_STRING(Div_par, metric_field_type, Field2D); Field3D Div_par(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, @@ -263,7 +269,7 @@ public: // Second derivative along magnetic field metric_field_type Grad2_par2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT"); + const std::string& method = "DEFAULT"); GRAD_FUNC_REGION_ENUM_TO_STRING(Grad2_par2, metric_field_type, Field2D); Field3D Grad2_par2(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, @@ -276,19 +282,20 @@ public: // Perpendicular Laplacian operator, using only X-Z derivatives // NOTE: This might be better bundled with the Laplacian inversion code // since it makes use of the same coefficients and FFT routines - metric_field_type Delp2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, bool useFFT = true); + metric_field_type Delp2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + bool useFFT = true); Field3D Delp2(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, bool useFFT = true); FieldPerp Delp2(const FieldPerp& f, CELL_LOC outloc = CELL_DEFAULT, bool useFFT = true); // Full parallel Laplacian operator on scalar field - // Laplace_par(f) = Div( b (b dot Grad(f)) ) - metric_field_type Laplace_par(const Field2D &f, CELL_LOC outloc=CELL_DEFAULT); + // Laplace_par(f) = Div( b (b dot Grad(f)) ) + metric_field_type Laplace_par(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT); Field3D Laplace_par(const Field3D &f, CELL_LOC outloc=CELL_DEFAULT); // Full Laplacian operator on scalar field metric_field_type Laplace(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& dfdy_boundary_conditions = "free_o3", - const std::string& dfdy_dy_region = ""); + const std::string& dfdy_boundary_conditions = "free_o3", + const std::string& dfdy_dy_region = ""); Field3D Laplace(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& dfdy_boundary_conditions = "free_o3", const std::string& dfdy_dy_region = ""); @@ -309,32 +316,36 @@ private: /// Used in the constructor to create the transform object. void setParallelTransform(Options* options); - inline Field3D maybeFromFieldAligned(const Field3D& f, const std::string& region = "RGN_ALL") { + inline Field3D maybeFromFieldAligned(const Field3D& f, + const std::string& region = "RGN_ALL") { ASSERT1(location == f.getLocation()); ASSERT1(localmesh == f.getMesh()); - if (f.getDirectionY() != YDirectionType::Standard){ - if (this->getParallelTransform().canToFromFieldAligned()){ - return this->getParallelTransform().fromFieldAligned(f, region); + if (f.getDirectionY() != YDirectionType::Standard) { + if (this->getParallelTransform().canToFromFieldAligned()) { + return this->getParallelTransform().fromFieldAligned(f, region); } else { - Field3D f_ = f; - f_.setDirectionY(YDirectionType::Standard); - return f_; + Field3D f_ = f; + f_.setDirectionY(YDirectionType::Standard); + return f_; } } return f; } - inline Field2D maybeFromFieldAligned(const Field2D& f, const std::string& UNUSED(region) = "RGN_ALL") { + inline Field2D maybeFromFieldAligned(const Field2D& f, + const std::string& UNUSED(region) = "RGN_ALL") { return f; } /// A wrapper for index:DDY derivative that is able to tranform /// fields before the constructor is finished. - Coordinates::metric_field_type indexDDY(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); + Coordinates::metric_field_type indexDDY(const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); Field3D indexDDY(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); - + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); }; /* diff --git a/include/bout/fv_ops.hxx b/include/bout/fv_ops.hxx index fdac4f95b6..5f54274226 100644 --- a/include/bout/fv_ops.hxx +++ b/include/bout/fv_ops.hxx @@ -249,18 +249,23 @@ namespace FV { for (int k = 0; k < mesh->LocalNz; k++) { #ifdef COORDINATES_USE_3D // For right cell boundaries - BoutReal common_factor = (coord->J(i, j, k) + coord->J(i, j + 1, k)) / - (sqrt(coord->g_22(i, j, k)) + sqrt(coord->g_22(i, j + 1, k))); - - BoutReal flux_factor_rc = common_factor / (coord->dy(i, j, k) * coord->J(i, j, k)); - BoutReal flux_factor_rp = common_factor / (coord->dy(i, j + 1, k) * coord->J(i, j + 1, k)); - - // For left cell boundaries - common_factor = (coord->J(i, j, k) + coord->J(i, j - 1, k)) / - (sqrt(coord->g_22(i, j, k)) + sqrt(coord->g_22(i, j - 1, k))); - - BoutReal flux_factor_lc = common_factor / (coord->dy(i, j, k) * coord->J(i, j, k)); - BoutReal flux_factor_lm = common_factor / (coord->dy(i, j - 1, k) * coord->J(i, j - 1, k)); + BoutReal common_factor = + (coord->J(i, j, k) + coord->J(i, j + 1, k)) + / (sqrt(coord->g_22(i, j, k)) + sqrt(coord->g_22(i, j + 1, k))); + + BoutReal flux_factor_rc = + common_factor / (coord->dy(i, j, k) * coord->J(i, j, k)); + BoutReal flux_factor_rp = + common_factor / (coord->dy(i, j + 1, k) * coord->J(i, j + 1, k)); + + // For left cell boundaries + common_factor = (coord->J(i, j, k) + coord->J(i, j - 1, k)) + / (sqrt(coord->g_22(i, j, k)) + sqrt(coord->g_22(i, j - 1, k))); + + BoutReal flux_factor_lc = + common_factor / (coord->dy(i, j, k) * coord->J(i, j, k)); + BoutReal flux_factor_lm = + common_factor / (coord->dy(i, j - 1, k) * coord->J(i, j - 1, k)); #endif //////////////////////////////////////////// diff --git a/include/bout/mesh.hxx b/include/bout/mesh.hxx index 25964db431..5caa984377 100644 --- a/include/bout/mesh.hxx +++ b/include/bout/mesh.hxx @@ -224,7 +224,8 @@ class Mesh { /// By default all fields revert to zero /// /// @param[in] var This will be set to the value read - /// @param[in] name The name of the vector. Individual fields are read based on this name by appending. See above + /// @param[in] name The name of the vector. Individual fields are read based on this + /// name by appending. See above /// @param[in] def The default value if not found (used for all the components) /// @param[in] communicate Should the field be communicated to fill guard cells? /// @@ -240,7 +241,8 @@ class Mesh { /// By default all fields revert to zero /// /// @param[in] var This will be set to the value read - /// @param[in] name The name of the vector. Individual fields are read based on this name by appending. See above + /// @param[in] name The name of the vector. Individual fields are read based on this + /// name by appending. See above /// @param[in] def The default value if not found (used for all the components) /// @param[in] communicate Should the field be communicated to fill guard cells? /// diff --git a/include/derivs.hxx b/include/derivs.hxx index 83a27798cb..b49d9353e7 100644 --- a/include/derivs.hxx +++ b/include/derivs.hxx @@ -39,21 +39,21 @@ #ifdef DERIV_FUNC_REGION_ENUM_TO_STRING #error This utility macro should not clash with another one #else -#define DERIV_FUNC_REGION_ENUM_TO_STRING(func, T, Tr) \ -[[deprecated("Please use #func(const #T& f, CELL_LOC outloc = CELL_DEFAULT, " \ - "const std::string& method = \"DEFAULT\", const std::string& region = \"RGN_ALL\") " \ - "instead")]] \ -inline Tr func(const T& f, CELL_LOC outloc, const std::string& method, \ - REGION region) { \ - return func(f, outloc, method, toString(region)); \ -} \ -[[deprecated("Please use #func(const #T& f, CELL_LOC outloc = CELL_DEFAULT, " \ - "const std::string& method = \"DEFAULT\", const std::string& region = \"RGN_ALL\") " \ - "instead")]] \ -inline Tr func(const T& f, CELL_LOC outloc, DIFF_METHOD method, \ - REGION region = RGN_NOBNDRY) { \ - return func(f, outloc, toString(method), toString(region)); \ -} +#define DERIV_FUNC_REGION_ENUM_TO_STRING(func, T, Tr) \ + [[deprecated("Please use #func(const #T& f, CELL_LOC outloc = CELL_DEFAULT, " \ + "const std::string& method = \"DEFAULT\", const std::string& region = " \ + "\"RGN_ALL\") " \ + "instead")]] inline Tr \ + func(const T& f, CELL_LOC outloc, const std::string& method, REGION region) { \ + return func(f, outloc, method, toString(region)); \ + } \ + [[deprecated("Please use #func(const #T& f, CELL_LOC outloc = CELL_DEFAULT, " \ + "const std::string& method = \"DEFAULT\", const std::string& region = " \ + "\"RGN_ALL\") " \ + "instead")]] inline Tr \ + func(const T& f, CELL_LOC outloc, DIFF_METHOD method, REGION region = RGN_NOBNDRY) { \ + return func(f, outloc, toString(method), toString(region)); \ + } #endif #ifdef VDERIV_FUNC_REGION_ENUM_TO_STRING @@ -139,8 +139,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(DDY, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type DDY(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type DDY(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(DDY, Field2D, Coordinates::metric_field_type) /// Calculate first partial derivative in Z @@ -171,8 +172,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(DDZ, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type DDZ(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type DDZ(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(DDZ, Field2D, Coordinates::metric_field_type) /// Calculate first partial derivative in Z @@ -237,8 +239,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(D2DX2, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type D2DX2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type D2DX2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(D2DX2, Field2D, Coordinates::metric_field_type) /// Calculate second partial derivative in Y @@ -269,8 +272,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(D2DY2, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type D2DY2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type D2DY2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(D2DY2, Field2D, Coordinates::metric_field_type) /// Calculate second partial derivative in Z @@ -301,8 +305,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(D2DZ2, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type D2DZ2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type D2DZ2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(D2DZ2, Field2D, Coordinates::metric_field_type) ////////// FOURTH DERIVATIVES ////////// @@ -335,8 +340,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(D4DX4, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type D4DX4(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type D4DX4(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(D4DX4, Field2D, Coordinates::metric_field_type) /// Calculate forth partial derivative in Y @@ -367,8 +373,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(D4DY4, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type D4DY4(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type D4DY4(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(D4DY4, Field2D, Coordinates::metric_field_type) /// Calculate forth partial derivative in Z @@ -399,8 +406,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(D4DZ4, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type D4DZ4(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type D4DZ4(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(D4DZ4, Field2D, Coordinates::metric_field_type) /// For terms of form v * grad(f) @@ -433,8 +441,10 @@ VDERIV_FUNC_REGION_ENUM_TO_STRING(VDDX, Field3D, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type VDDX(const Field2D& v, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type VDDX(const Field2D& v, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); VDERIV_FUNC_REGION_ENUM_TO_STRING(VDDX, Coordinates::metric_field_type, Field2D, Field2D) /// For terms of form v * grad(f) @@ -467,8 +477,10 @@ VDERIV_FUNC_REGION_ENUM_TO_STRING(VDDY, Field3D, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type VDDY(const Field2D& v, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type VDDY(const Field2D& v, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); VDERIV_FUNC_REGION_ENUM_TO_STRING(VDDY, Coordinates::metric_field_type, Field2D, Field2D) /// For terms of form v * grad(f) @@ -501,8 +513,10 @@ VDERIV_FUNC_REGION_ENUM_TO_STRING(VDDZ, Field3D, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type VDDZ(const Field2D& v, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type VDDZ(const Field2D& v, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); VDERIV_FUNC_REGION_ENUM_TO_STRING(VDDZ, Coordinates::metric_field_type, Field2D, Field2D) /// For terms of form v * grad(f) @@ -518,8 +532,10 @@ VDERIV_FUNC_REGION_ENUM_TO_STRING(VDDZ, Coordinates::metric_field_type, Field2D, /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type VDDZ(const Field3D& v, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type VDDZ(const Field3D& v, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); VDERIV_FUNC_REGION_ENUM_TO_STRING(VDDZ, Coordinates::metric_field_type, Field3D, Field2D) /// for terms of form div(v * f) @@ -552,8 +568,10 @@ VDERIV_FUNC_REGION_ENUM_TO_STRING(FDDX, Field3D, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type FDDX(const Field2D& v, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type FDDX(const Field2D& v, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); VDERIV_FUNC_REGION_ENUM_TO_STRING(FDDX, Coordinates::metric_field_type, Field2D, Field2D) /// for terms of form div(v * f) @@ -586,8 +604,10 @@ VDERIV_FUNC_REGION_ENUM_TO_STRING(FDDY, Field3D, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type FDDY(const Field2D& v, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type FDDY(const Field2D& v, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); VDERIV_FUNC_REGION_ENUM_TO_STRING(FDDY, Coordinates::metric_field_type, Field2D, Field2D) /// for terms of form div(v * f) @@ -620,8 +640,10 @@ VDERIV_FUNC_REGION_ENUM_TO_STRING(FDDZ, Field3D, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type FDDZ(const Field2D& v, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type FDDZ(const Field2D& v, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); VDERIV_FUNC_REGION_ENUM_TO_STRING(FDDZ, Coordinates::metric_field_type, Field2D, Field2D) /// Calculate mixed partial derivative in x and y @@ -685,28 +707,31 @@ D2DXDY(const Field3D& f, CELL_LOC outloc, DIFF_METHOD method, REGION region = RG /// (default) then the same as the region for the calculation as a /// whole. If dfdy_region < region in size then this will cause /// errors. -Coordinates::metric_field_type D2DXDY(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT", - const std::string& region = "RGN_NOBNDRY", - const std::string& dfdy_boundary_condition = "free_o3", - const std::string& dfdy_region = ""); +Coordinates::metric_field_type +D2DXDY(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", const std::string& region = "RGN_NOBNDRY", + const std::string& dfdy_boundary_condition = "free_o3", + const std::string& dfdy_region = ""); [[deprecated( "Please use D2DXDY(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, " "const std::string& method = \"DEFAULT\", const std::string& region = \"RGN_ALL\", " - "const std::string& dfdy_boundary_condition) instead")]] inline Coordinates::metric_field_type -D2DXDY(const Field2D& f, CELL_LOC outloc, const std::string& method, REGION region, - const std::string& dfdy_boundary_condition = "free_o3", - const std::string& dfdy_region = "") { + "const std::string& dfdy_boundary_condition) instead")]] inline Coordinates:: + metric_field_type + D2DXDY(const Field2D& f, CELL_LOC outloc, const std::string& method, REGION region, + const std::string& dfdy_boundary_condition = "free_o3", + const std::string& dfdy_region = "") { return D2DXDY(f, outloc, method, toString(region), dfdy_boundary_condition, dfdy_region); } [[deprecated( "Please use D2DXDY(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, " "const std::string& method = \"DEFAULT\", const std::string& region = \"RGN_ALL\", " - "const std::string& dfdy_boundary_condition) instead")]] inline Coordinates::metric_field_type -D2DXDY(const Field2D& f, CELL_LOC outloc, DIFF_METHOD method, REGION region = RGN_NOBNDRY, - const std::string& dfdy_boundary_condition = "free_o3", - const std::string& dfdy_region = "") { + "const std::string& dfdy_boundary_condition) instead")]] inline Coordinates:: + metric_field_type + D2DXDY(const Field2D& f, CELL_LOC outloc, DIFF_METHOD method, + REGION region = RGN_NOBNDRY, + const std::string& dfdy_boundary_condition = "free_o3", + const std::string& dfdy_region = "") { return D2DXDY(f, outloc, toString(method), toString(region), dfdy_boundary_condition, dfdy_region); }; @@ -739,8 +764,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(D2DXDZ, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type D2DXDZ(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type D2DXDZ(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(D2DXDZ, Field2D, Coordinates::metric_field_type) /// Calculate mixed partial derivative in y and z @@ -771,8 +797,9 @@ DERIV_FUNC_REGION_ENUM_TO_STRING(D2DYDZ, Field3D, Field3D) /// If not given, defaults to DIFF_DEFAULT /// @param[in] region What region is expected to be calculated /// If not given, defaults to RGN_NOBNDRY -Coordinates::metric_field_type D2DYDZ(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& - method = "DEFAULT", const std::string& region = "RGN_NOBNDRY"); +Coordinates::metric_field_type D2DYDZ(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT", + const std::string& region = "RGN_NOBNDRY"); DERIV_FUNC_REGION_ENUM_TO_STRING(D2DYDZ, Field2D, Coordinates::metric_field_type) #undef DERIV_FUNC_REGION_ENUM_TO_STRING diff --git a/include/difops.hxx b/include/difops.hxx index 3633db1d96..41daa122a2 100644 --- a/include/difops.hxx +++ b/include/difops.hxx @@ -111,28 +111,26 @@ Field3D Grad_parP(const Field3D& apar, const Field3D& f); Coordinates::metric_field_type Vpar_Grad_par(const Field2D& v, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT"); -DEPRECATED(Coordinates::metric_field_type Vpar_Grad_par( - const Field2D& v, const Field2D& f, const std::string& method, - CELL_LOC outloc = CELL_DEFAULT)); -inline Coordinates::metric_field_type -Vpar_Grad_par(const Field2D& v, const Field2D& f, CELL_LOC outloc, DIFF_METHOD method) { +DEPRECATED(Coordinates::metric_field_type Vpar_Grad_par(const Field2D& v, + const Field2D& f, + const std::string& method, + CELL_LOC outloc = CELL_DEFAULT)); +inline Coordinates::metric_field_type Vpar_Grad_par(const Field2D& v, const Field2D& f, + CELL_LOC outloc, DIFF_METHOD method) { return Vpar_Grad_par(v, f, outloc, toString(method)); } -DEPRECATED(inline Coordinates::metric_field_type Vpar_Grad_par(const Field2D& v, - const Field2D& f, - DIFF_METHOD method, - CELL_LOC outloc)) { +DEPRECATED(inline Coordinates::metric_field_type Vpar_Grad_par( + const Field2D& v, const Field2D& f, DIFF_METHOD method, CELL_LOC outloc)) { return Vpar_Grad_par(v, f, outloc, toString(method)); } -Field3D Vpar_Grad_par(const Field3D& v, const Field3D& f, - CELL_LOC outloc = CELL_DEFAULT, +Field3D Vpar_Grad_par(const Field3D& v, const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT"); DEPRECATED(Field3D Vpar_Grad_par(const Field3D& v, const Field3D& f, const std::string& method, CELL_LOC outloc = CELL_DEFAULT)); inline Field3D Vpar_Grad_par(const Field3D& v, const Field3D& f, CELL_LOC outloc, - DIFF_METHOD method) { + DIFF_METHOD method) { return Vpar_Grad_par(v, f, outloc, toString(method)); } DEPRECATED(inline Field3D Vpar_Grad_par(const Field3D& v, const Field3D& f, @@ -152,8 +150,7 @@ DEPRECATED(inline Field3D Vpar_Grad_par(const Field3D& v, const Field3D& f, * @param[in] method The numerical method to use * */ -Coordinates::metric_field_type Div_par(const Field2D& f, - CELL_LOC outloc = CELL_DEFAULT, +Coordinates::metric_field_type Div_par(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT"); DEPRECATED(Coordinates::metric_field_type Div_par(const Field2D& f, const std::string& method, @@ -188,8 +185,7 @@ Field3D Div_par(const Field3D& f, const Field3D& v); // Flux methods. Model divergence of flux: df/dt = Div(v * f) // TODO : Should we add Field2D versions? -Field3D Div_par_flux(const Field3D& v, const Field3D& f, - CELL_LOC outloc = CELL_DEFAULT, +Field3D Div_par_flux(const Field3D& v, const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT"); DEPRECATED(Field3D Div_par_flux(const Field3D& v, const Field3D& f, const std::string& method, @@ -233,67 +229,66 @@ inline Field3D Grad2_par2(const Field3D& f, CELL_LOC outloc, DIFF_METHOD method) * Parallel derivatives, converting between cell-centred and lower cell boundary * These are a simple way to do staggered differencing */ -[[deprecated( - "Grad_par_CtoL is deprecated. Staggering is now supported in Grad_par.")]] -inline Field3D Grad_par_CtoL(const Field3D &var) { +[[deprecated("Grad_par_CtoL is deprecated. Staggering is now supported in " + "Grad_par.")]] inline Field3D +Grad_par_CtoL(const Field3D& var) { ASSERT2(var.getLocation() == CELL_CENTRE); return Grad_par(var, CELL_YLOW); } -[[deprecated( - "Grad_par_CtoL is deprecated. Staggering is now supported in Grad_par.")]] -inline Coordinates::metric_field_type Grad_par_CtoL(const Field2D &var) { +[[deprecated("Grad_par_CtoL is deprecated. Staggering is now supported in " + "Grad_par.")]] inline Coordinates::metric_field_type +Grad_par_CtoL(const Field2D& var) { ASSERT2(var.getLocation() == CELL_CENTRE); return Grad_par(var, CELL_YLOW); } -[[deprecated( - "Vpar_Grad_par_LCtoC is deprecated. Staggering is now supported in Vpar_Grad_par.")]] -inline Field3D Vpar_Grad_par_LCtoC(const Field3D& v, const Field3D& f, - const std::string& region="RGN_NOBNDRY") { +[[deprecated("Vpar_Grad_par_LCtoC is deprecated. Staggering is now supported in " + "Vpar_Grad_par.")]] inline Field3D +Vpar_Grad_par_LCtoC(const Field3D& v, const Field3D& f, + const std::string& region = "RGN_NOBNDRY") { ASSERT2(v.getLocation() == CELL_YLOW); ASSERT2(f.getLocation() == CELL_CENTRE); return Vpar_Grad_par(v, f, CELL_CENTRE, region); } -[[deprecated( - "Vpar_Grad_par_LCtoC is deprecated. Staggering is now supported in Vpar_Grad_par.")]] -inline Field3D Vpar_Grad_par_LCtoC(const Field3D& v, const Field3D& f, - REGION region=RGN_NOBNDRY) { +[[deprecated("Vpar_Grad_par_LCtoC is deprecated. Staggering is now supported in " + "Vpar_Grad_par.")]] inline Field3D +Vpar_Grad_par_LCtoC(const Field3D& v, const Field3D& f, REGION region = RGN_NOBNDRY) { ASSERT2(v.getLocation() == CELL_YLOW); ASSERT2(f.getLocation() == CELL_CENTRE); return Vpar_Grad_par(v, f, CELL_CENTRE, toString(region)); } -[[deprecated( - "Grad_par_LtoC is deprecated. Staggering is now supported in Grad_par.")]] -inline Field3D Grad_par_LtoC(const Field3D &var) { +[[deprecated("Grad_par_LtoC is deprecated. Staggering is now supported in " + "Grad_par.")]] inline Field3D +Grad_par_LtoC(const Field3D& var) { ASSERT2(var.getLocation() == CELL_YLOW); return Grad_par(var, CELL_CENTRE); } -[[deprecated( - "Grad_par_LtoC is deprecated. Staggering is now supported in Grad_par.")]] -inline Coordinates::metric_field_type Grad_par_LtoC(const Field2D &var) { +[[deprecated("Grad_par_LtoC is deprecated. Staggering is now supported in " + "Grad_par.")]] inline Coordinates::metric_field_type +Grad_par_LtoC(const Field2D& var) { ASSERT2(var.getLocation() == CELL_YLOW); return Grad_par(var, CELL_CENTRE); } -[[deprecated( - "Div_par_LtoC is deprecated. Staggering is now supported in Grad_par.")]] -inline Field3D Div_par_LtoC(const Field3D &var) { +[[deprecated("Div_par_LtoC is deprecated. Staggering is now supported in " + "Grad_par.")]] inline Field3D +Div_par_LtoC(const Field3D& var) { ASSERT2(var.getLocation() == CELL_YLOW); return Div_par(var, CELL_CENTRE); } -[[deprecated( - "Div_par_LtoC is deprecated. Staggering is now supported in Grad_par.")]] -inline Coordinates::metric_field_type Div_par_LtoC(const Field2D &var) { +[[deprecated("Div_par_LtoC is deprecated. Staggering is now supported in " + "Grad_par.")]] inline Coordinates::metric_field_type +Div_par_LtoC(const Field2D& var) { ASSERT2(var.getLocation() == CELL_YLOW); return Div_par(var, CELL_CENTRE); } -[[deprecated( - "Div_par_CtoL is deprecated. Staggering is now supported in Grad_par.")]] -inline Field3D Div_par_CtoL(const Field3D &var) { +[[deprecated("Div_par_CtoL is deprecated. Staggering is now supported in " + "Grad_par.")]] inline Field3D +Div_par_CtoL(const Field3D& var) { ASSERT2(var.getLocation() == CELL_CENTRE); return Div_par(var, CELL_YLOW); } -[[deprecated( - "Div_par_CtoL is deprecated. Staggering is now supported in Grad_par.")]] -inline Coordinates::metric_field_type Div_par_CtoL(const Field2D &var) { +[[deprecated("Div_par_CtoL is deprecated. Staggering is now supported in " + "Grad_par.")]] inline Coordinates::metric_field_type +Div_par_CtoL(const Field2D& var) { ASSERT2(var.getLocation() == CELL_CENTRE); return Div_par(var, CELL_YLOW); } @@ -309,13 +304,16 @@ inline Coordinates::metric_field_type Div_par_CtoL(const Field2D &var) { * @param[in] f The field whose gradient drives a flux */ Coordinates::metric_field_type Div_par_K_Grad_par(BoutReal kY, const Field2D& f, - CELL_LOC outloc = CELL_DEFAULT); -Field3D Div_par_K_Grad_par(BoutReal kY, const Field3D &f, CELL_LOC outloc=CELL_DEFAULT); -Coordinates::metric_field_type -Div_par_K_Grad_par(const Field2D& kY, const Field2D& f, CELL_LOC outloc = CELL_DEFAULT); -Field3D Div_par_K_Grad_par(const Field2D &kY, const Field3D &f, CELL_LOC outloc=CELL_DEFAULT); -Field3D Div_par_K_Grad_par(const Field3D &kY, const Field2D &f, CELL_LOC outloc=CELL_DEFAULT); -Field3D Div_par_K_Grad_par(const Field3D &kY, const Field3D &f, CELL_LOC outloc=CELL_DEFAULT); + CELL_LOC outloc = CELL_DEFAULT); +Field3D Div_par_K_Grad_par(BoutReal kY, const Field3D& f, CELL_LOC outloc = CELL_DEFAULT); +Coordinates::metric_field_type Div_par_K_Grad_par(const Field2D& kY, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT); +Field3D Div_par_K_Grad_par(const Field2D& kY, const Field3D& f, + CELL_LOC outloc = CELL_DEFAULT); +Field3D Div_par_K_Grad_par(const Field3D& kY, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT); +Field3D Div_par_K_Grad_par(const Field3D& kY, const Field3D& f, + CELL_LOC outloc = CELL_DEFAULT); /*! * Perpendicular Laplacian operator @@ -326,19 +324,20 @@ Field3D Div_par_K_Grad_par(const Field3D &kY, const Field3D &f, CELL_LOC outloc= * * For the full perpendicular Laplacian, use Laplace_perp */ -Coordinates::metric_field_type Delp2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, bool useFFT = true); +Coordinates::metric_field_type Delp2(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + bool useFFT = true); Field3D Delp2(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, bool useFFT = true); -FieldPerp Delp2(const FieldPerp& f, CELL_LOC outloc = CELL_DEFAULT, - bool useFFT = true); +FieldPerp Delp2(const FieldPerp& f, CELL_LOC outloc = CELL_DEFAULT, bool useFFT = true); /*! * Perpendicular Laplacian, keeping y derivatives * * */ -Coordinates::metric_field_type Laplace_perp(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& dfdy_boundary_condition = "free_o3", - const std::string& dfdy_region = ""); +Coordinates::metric_field_type +Laplace_perp(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& dfdy_boundary_condition = "free_o3", + const std::string& dfdy_region = ""); Field3D Laplace_perp(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& dfdy_boundary_condition = "free_o3", const std::string& dfdy_region = ""); @@ -349,14 +348,15 @@ Field3D Laplace_perp(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, */ Coordinates::metric_field_type Laplace_par(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT); -Field3D Laplace_par(const Field3D &f, CELL_LOC outloc=CELL_DEFAULT); +Field3D Laplace_par(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT); /*! * Full Laplacian operator (par + perp) */ -Coordinates::metric_field_type Laplace(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, - const std::string& dfdy_boundary_condition = "free_o3", - const std::string& dfdy_region = ""); +Coordinates::metric_field_type +Laplace(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, + const std::string& dfdy_boundary_condition = "free_o3", + const std::string& dfdy_region = ""); Field3D Laplace(const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& dfdy_boundary_condition = "free_o3", const std::string& dfdy_region = ""); @@ -370,8 +370,8 @@ Field2D Laplace_perpXY(const Field2D& A, const Field2D& f); * Terms of form b0 x Grad(phi) dot Grad(A) * */ -Coordinates::metric_field_type -b0xGrad_dot_Grad(const Field2D& phi, const Field2D& A, CELL_LOC outloc = CELL_DEFAULT); +Coordinates::metric_field_type b0xGrad_dot_Grad(const Field2D& phi, const Field2D& A, + CELL_LOC outloc = CELL_DEFAULT); /*! * Terms of form @@ -384,16 +384,18 @@ b0xGrad_dot_Grad(const Field2D& phi, const Field2D& A, CELL_LOC outloc = CELL_DE * @param[in] A The field being advected * @param[in] outloc The cell location where the result is defined. By default the same as A. */ -Field3D b0xGrad_dot_Grad(const Field3D &phi, const Field2D &A, CELL_LOC outloc=CELL_DEFAULT); -Field3D b0xGrad_dot_Grad(const Field2D &phi, const Field3D &A, CELL_LOC outloc=CELL_DEFAULT); -Field3D b0xGrad_dot_Grad(const Field3D &phi, const Field3D &A, CELL_LOC outloc=CELL_DEFAULT); - +Field3D b0xGrad_dot_Grad(const Field3D& phi, const Field2D& A, + CELL_LOC outloc = CELL_DEFAULT); +Field3D b0xGrad_dot_Grad(const Field2D& phi, const Field3D& A, + CELL_LOC outloc = CELL_DEFAULT); +Field3D b0xGrad_dot_Grad(const Field3D& phi, const Field3D& A, + CELL_LOC outloc = CELL_DEFAULT); /*! * X-Z Finite Volume diffusion operator */ -Field3D Div_Perp_Lap_FV(const Field3D &a, const Field3D &f, CELL_LOC outloc = CELL_DEFAULT); - +Field3D Div_Perp_Lap_FV(const Field3D& a, const Field3D& f, + CELL_LOC outloc = CELL_DEFAULT); /*! * Poisson bracket methods @@ -431,14 +433,11 @@ Coordinates::metric_field_type bracket(const Field2D& f, const Field2D& g, BRACKET_METHOD method = BRACKET_STD, CELL_LOC outloc = CELL_DEFAULT, Solver* solver = nullptr); -Field3D bracket(const Field2D &f, const Field3D &g, - BRACKET_METHOD method = BRACKET_STD, CELL_LOC outloc = CELL_DEFAULT, - Solver *solver = nullptr); -Field3D bracket(const Field3D &f, const Field2D &g, - BRACKET_METHOD method = BRACKET_STD, CELL_LOC outloc = CELL_DEFAULT, - Solver *solver = nullptr); -Field3D bracket(const Field3D &f, const Field3D &g, - BRACKET_METHOD method = BRACKET_STD, CELL_LOC outloc = CELL_DEFAULT, - Solver *solver = nullptr); +Field3D bracket(const Field2D& f, const Field3D& g, BRACKET_METHOD method = BRACKET_STD, + CELL_LOC outloc = CELL_DEFAULT, Solver* solver = nullptr); +Field3D bracket(const Field3D& f, const Field2D& g, BRACKET_METHOD method = BRACKET_STD, + CELL_LOC outloc = CELL_DEFAULT, Solver* solver = nullptr); +Field3D bracket(const Field3D& f, const Field3D& g, BRACKET_METHOD method = BRACKET_STD, + CELL_LOC outloc = CELL_DEFAULT, Solver* solver = nullptr); #endif /* __DIFOPS_H__ */ diff --git a/include/field.hxx b/include/field.hxx index a88961b275..d5e929d258 100644 --- a/include/field.hxx +++ b/include/field.hxx @@ -297,7 +297,9 @@ inline void checkPositive(const T& f, const std::string& name="field", const std BOUT_FOR_SERIAL(i, f.getRegion(rgn)) { if (f[i] <= 0.) { - throw BoutException("{:s} ({:s} {:s}) is {:e} (not positive) at {:s}", name, toString(f.getLocation()), toString(f.getDirections()), f[i], toString(i)); + throw BoutException("{:s} ({:s} {:s}) is {:e} (not positive) at {:s}", name, + toString(f.getLocation()), toString(f.getDirections()), f[i], + toString(i)); } } } @@ -359,40 +361,41 @@ inline BoutReal min(const T& f, bool allpe, REGION rgn) { return min(f, allpe, toString(rgn)); } - -template> -inline bool isConst(const T& f, bool allpe = false, const std::string& region = "RGN_ALL") { +template > +inline bool isConst(const T& f, bool allpe = false, + const std::string& region = "RGN_ALL") { bool result = true; auto element = f[*f.getRegion(region).begin()]; - BOUT_FOR_SERIAL(i, f.getRegion(region)){ - if (f[i] != element){ - result=false; + BOUT_FOR_SERIAL(i, f.getRegion(region)) { + if (f[i] != element) { + result = false; break; } } - if(allpe) { + if (allpe) { bool localresult = result; MPI_Allreduce(&localresult, &result, 1, MPI_C_BOOL, MPI_LOR, BoutComm::get()); } return result; } -template> -inline BoutReal getConst(const T& f, bool allpe = false, const std::string& region = "RGN_ALL") { +template > +inline BoutReal getConst(const T& f, bool allpe = false, + const std::string& region = "RGN_ALL") { bool is_const = true; auto element = f[*f.getRegion(region).begin()]; #if CHECK > 1 - BOUT_FOR_SERIAL(i, f.getRegion(region)){ - if (f[i] != element){ + BOUT_FOR_SERIAL(i, f.getRegion(region)) { + if (f[i] != element) { is_const = false; break; } } - if(allpe) { + if (allpe) { bool local_is_const = is_const; MPI_Allreduce(&local_is_const, &is_const, 1, MPI_C_BOOL, MPI_LOR, BoutComm::get()); } - if (! is_const) { + if (!is_const) { throw BoutException("Requested getConst but Field is not const"); } #endif diff --git a/include/field2d.hxx b/include/field2d.hxx index 6e5702117b..29d330b971 100644 --- a/include/field2d.hxx +++ b/include/field2d.hxx @@ -380,9 +380,7 @@ inline void invalidateGuards(Field2D &UNUSED(var)) {} /// Average in the Z direction /// Field2D has no Z direction -- return input /// @param[in] f Variable to average -inline Field2D DC(const Field2D &f) { - return f; -} +inline Field2D DC(const Field2D& f) { return f; } /// Returns a reference to the time-derivative of a field \p f /// diff --git a/include/field3d.hxx b/include/field3d.hxx index 7bc218bef1..03177569ac 100644 --- a/include/field3d.hxx +++ b/include/field3d.hxx @@ -473,7 +473,6 @@ class Field3D : public Field, public FieldData { friend class Vector3D; friend class Vector2D; - Field3D& calcParallelSlices(); diff --git a/include/vecops.hxx b/include/vecops.hxx index 451175a0c8..deae65ed03 100644 --- a/include/vecops.hxx +++ b/include/vecops.hxx @@ -34,9 +34,9 @@ class Field3D; class Vector2D; class Vector3D; -#include "bout/deprecated.hxx" #include "bout_types.hxx" #include "bout/coordinates.hxx" +#include "bout/deprecated.hxx" // Those are needed because we implement functions here. // They can be dropped if we remove the deprecated wrappers. #include "field2d.hxx" @@ -87,13 +87,15 @@ const Vector2D Grad_perp(const Field2D& f, CELL_LOC outloc = CELL_DEFAULT, /// @param[in] outloc The cell location where the result is desired /// @param[in] method The method to use. The default is set in the options. /// -const Coordinates::metric_field_type Div(const Vector2D &v, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT"); -const Field3D Div(const Vector3D &v, CELL_LOC outloc = CELL_DEFAULT, - const std::string& method = "DEFAULT"); +const Coordinates::metric_field_type Div(const Vector2D& v, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT"); +const Field3D Div(const Vector3D& v, CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT"); -const Coordinates::metric_field_type Div(const Vector2D &v, const Field2D &f, - CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT"); +const Coordinates::metric_field_type Div(const Vector2D& v, const Field2D& f, + CELL_LOC outloc = CELL_DEFAULT, + const std::string& method = "DEFAULT"); const Field3D Div(const Vector3D& v, const Field3D& f, CELL_LOC outloc = CELL_DEFAULT, const std::string& method = "DEFAULT"); @@ -132,7 +134,7 @@ const Vector3D Curl(const Vector3D &v); /// /// The vector and the field must be at the same location, which /// cannot be CELL_VSHIFT -const Coordinates::metric_field_type V_dot_Grad(const Vector2D &v, const Field2D &f); +const Coordinates::metric_field_type V_dot_Grad(const Vector2D& v, const Field2D& f); const Field3D V_dot_Grad(const Vector2D &v, const Field3D &f); const Field3D V_dot_Grad(const Vector3D &v, const Field2D &f); const Field3D V_dot_Grad(const Vector3D &v, const Field3D &f); diff --git a/include/vector2d.hxx b/include/vector2d.hxx index e15254132d..f886f2121d 100644 --- a/include/vector2d.hxx +++ b/include/vector2d.hxx @@ -128,7 +128,8 @@ public: const Vector2D operator/(const Field2D &rhs) const; ///< Divides all components by \p rhs const Vector3D operator/(const Field3D &rhs) const; ///< Divides all components by \p rhs - const Coordinates::metric_field_type operator*(const Vector2D &rhs) const; ///< Dot product + const Coordinates::metric_field_type + operator*(const Vector2D& rhs) const; ///< Dot product const Field3D operator*(const Vector3D &rhs) const; ///< Dot product /*! @@ -180,10 +181,13 @@ const Vector3D cross(const Vector2D & lhs, const Vector3D &rhs); * * |v| = sqrt( v dot v ) */ -const Coordinates::metric_field_type abs(const Vector2D& v, const std::string& region = "RGN_ALL"); -[[deprecated("Please use Vector2D abs(const Vector2D& f, " - "const std::string& region = \"RGN_ALL\") instead")]] -inline const Coordinates::metric_field_type abs(const Vector2D &v, REGION region) { +const Coordinates::metric_field_type abs(const Vector2D& v, + const std::string& region = "RGN_ALL"); +[[deprecated( + "Please use Vector2D abs(const Vector2D& f, " + "const std::string& region = \"RGN_ALL\") instead")]] inline const Coordinates:: + metric_field_type + abs(const Vector2D& v, REGION region) { return abs(v, toString(region)); } diff --git a/src/field/field.cxx b/src/field/field.cxx index bae415532b..8eb499d702 100644 --- a/src/field/field.cxx +++ b/src/field/field.cxx @@ -25,13 +25,13 @@ //#include +#include +#include +#include #include -#include #include -#include +#include #include -#include -#include Field::Field(Mesh *localmesh, CELL_LOC location_in, DirectionTypes directions_in) diff --git a/src/field/field3d.cxx b/src/field/field3d.cxx index 98005e4b82..a9af3ed37e 100644 --- a/src/field/field3d.cxx +++ b/src/field/field3d.cxx @@ -209,7 +209,7 @@ bool Field3D::requiresTwistShift(bool twist_shift_enabled) { // We need to communicate in the coordinates constructure in that // case a Field3D, but coordinates isn't valid yet. As such we // disable twist-shift in that case. - if (getCoordinates() == nullptr){ + if (getCoordinates() == nullptr) { return false; } return getCoordinates()->getParallelTransform().requiresTwistShift(twist_shift_enabled, @@ -868,4 +868,3 @@ std::ostream& operator<<(std::ostream &out, const Field3D &value) { out << toString(value); return out; } - diff --git a/src/field/field_factory.cxx b/src/field/field_factory.cxx index d62cbcae23..77a2cb119a 100644 --- a/src/field/field_factory.cxx +++ b/src/field/field_factory.cxx @@ -222,11 +222,11 @@ Field3D FieldFactory::create3D(FieldGeneratorPtr gen, Mesh* localmesh, CELL_LOC output_warn.write("Skipping parallel transformation - coordinates not set!\n"); } else { if (coords->getParallelTransform().canToFromFieldAligned()) { - // Transform from field aligned coordinates, to be compatible with - // older BOUT++ inputs. This is not a particularly "nice" solution. - result = fromFieldAligned(result, "RGN_ALL"); + // Transform from field aligned coordinates, to be compatible with + // older BOUT++ inputs. This is not a particularly "nice" solution. + result = fromFieldAligned(result, "RGN_ALL"); } else { - result.setDirectionY(YDirectionType::Standard); + result.setDirectionY(YDirectionType::Standard); } } } @@ -273,9 +273,9 @@ FieldPerp FieldFactory::createPerp(FieldGeneratorPtr gen, Mesh* localmesh, CELL_ output_warn.write("Skipping parallel transformation - coordinates not set!\n"); } else { if (coords->getParallelTransform().canToFromFieldAligned()) { - // Transform from field aligned coordinates, to be compatible with - // older BOUT++ inputs. This is not a particularly "nice" solution. - result = fromFieldAligned(result, "RGN_ALL"); + // Transform from field aligned coordinates, to be compatible with + // older BOUT++ inputs. This is not a particularly "nice" solution. + result = fromFieldAligned(result, "RGN_ALL"); } } } diff --git a/src/field/fieldgenerators.cxx b/src/field/fieldgenerators.cxx index c30e4273f8..7a884bb053 100644 --- a/src/field/fieldgenerators.cxx +++ b/src/field/fieldgenerators.cxx @@ -89,13 +89,11 @@ BoutReal FieldBallooning::generate(const Context& ctx) { for (int i = 1; i <= ball_n; i++) { // y - i * 2pi - value += arg->generate(Context(ctx).set( - "y", ctx.y() - i * TWOPI, - "z", ctx.z() + i * ts * TWOPI / zlength)); + value += arg->generate(Context(ctx).set("y", ctx.y() - i * TWOPI, "z", + ctx.z() + i * ts * TWOPI / zlength)); - value += arg->generate(Context(ctx).set( - "y", ctx.y() + i * TWOPI, - "z", ctx.z() - i * ts * TWOPI / zlength)); + value += arg->generate(Context(ctx).set("y", ctx.y() + i * TWOPI, "z", + ctx.z() - i * ts * TWOPI / zlength)); } return value; } diff --git a/src/field/vecops.cxx b/src/field/vecops.cxx index 5a9ef01165..27856eb840 100644 --- a/src/field/vecops.cxx +++ b/src/field/vecops.cxx @@ -143,7 +143,8 @@ const Vector2D Grad_perp(const Field2D &f, CELL_LOC outloc, const std::string& m * Divergence operators **************************************************************************/ -const Coordinates::metric_field_type Div(const Vector2D &v, CELL_LOC outloc, const std::string& method) { +const Coordinates::metric_field_type Div(const Vector2D& v, CELL_LOC outloc, + const std::string& method) { TRACE("Div( Vector2D )"); SCOREP0(); if (outloc == CELL_DEFAULT) { @@ -159,8 +160,8 @@ const Coordinates::metric_field_type Div(const Vector2D &v, CELL_LOC outloc, con // get contravariant components of v Vector2D vcn = v; vcn.toContravariant(); - - Coordinates::metric_field_type result = DDX(metric->J*vcn.x, outloc, method); + + Coordinates::metric_field_type result = DDX(metric->J * vcn.x, outloc, method); result += DDY(metric->J*vcn.y, outloc, method); result += DDZ(metric->J*vcn.z, outloc, method); result /= metric->J; @@ -187,7 +188,7 @@ const Field3D Div(const Vector3D& v, CELL_LOC outloc, const std::string& method) vcn.toContravariant(); Field3D vcnJy = vcn.y.getCoordinates()->J * vcn.y; - if(!vcn.y.hasParallelSlices()){ + if (!vcn.y.hasParallelSlices()) { localmesh->communicate(vcnJy); } Field3D result = DDY(vcnJy, outloc, method); @@ -203,8 +204,8 @@ const Field3D Div(const Vector3D& v, CELL_LOC outloc, const std::string& method) * Divergence operators for flux methods **************************************************************************/ -const Coordinates::metric_field_type Div(const Vector2D &v, const Field2D &f, CELL_LOC outloc, - const std::string& method) { +const Coordinates::metric_field_type Div(const Vector2D& v, const Field2D& f, + CELL_LOC outloc, const std::string& method) { TRACE("Div( Vector2D, Field2D )"); SCOREP0(); if (outloc == CELL_DEFAULT) { @@ -221,7 +222,8 @@ const Coordinates::metric_field_type Div(const Vector2D &v, const Field2D &f, CE Vector2D vcn = v; vcn.toContravariant(); - Coordinates::metric_field_type result = FDDX(vcn.x.getCoordinates()->J * vcn.x, f, outloc, method); + Coordinates::metric_field_type result = + FDDX(vcn.x.getCoordinates()->J * vcn.x, f, outloc, method); result += FDDY(vcn.y.getCoordinates()->J * vcn.y, f, outloc, method); result += FDDZ(vcn.z.getCoordinates()->J * vcn.z, f, outloc, method); result /= metric->J; @@ -317,7 +319,7 @@ const Vector3D Curl(const Vector3D &v) { /************************************************************************** * Upwinding operators **************************************************************************/ -const Coordinates::metric_field_type V_dot_Grad(const Vector2D &v, const Field2D &f) { +const Coordinates::metric_field_type V_dot_Grad(const Vector2D& v, const Field2D& f) { TRACE("V_dot_Grad( Vector2D , Field2D )"); SCOREP0(); diff --git a/src/field/vector2d.cxx b/src/field/vector2d.cxx index 8dd5e0f5d2..96568e75f3 100644 --- a/src/field/vector2d.cxx +++ b/src/field/vector2d.cxx @@ -85,7 +85,7 @@ void Vector2D::toCovariant() { const auto y_at_z = interp_to(y, z.getLocation()); // multiply by g_{ij} - BOUT_FOR(i, x.getRegion("RGN_ALL")){ + BOUT_FOR(i, x.getRegion("RGN_ALL")) { x[i] = metric_x->g_11[i]*x[i] + metric_x->g_12[i]*y_at_x[i] + metric_x->g_13[i]*z_at_x[i]; y[i] = metric_y->g_22[i]*y[i] + metric_y->g_12[i]*x_at_y[i] + metric_y->g_23[i]*z_at_y[i]; z[i] = metric_z->g_33[i]*z[i] + metric_z->g_13[i]*x_at_z[i] + metric_z->g_23[i]*y_at_z[i]; @@ -96,7 +96,7 @@ void Vector2D::toCovariant() { // Need to use temporary arrays to store result Coordinates::metric_field_type gx{emptyFrom(x)}, gy{emptyFrom(y)}, gz{emptyFrom(z)}; - BOUT_FOR(i, x.getRegion("RGN_ALL")){ + BOUT_FOR(i, x.getRegion("RGN_ALL")) { gx[i] = metric->g_11[i]*x[i] + metric->g_12[i]*y[i] + metric->g_13[i]*z[i]; gy[i] = metric->g_22[i]*y[i] + metric->g_12[i]*x[i] + metric->g_23[i]*z[i]; gz[i] = metric->g_33[i]*z[i] + metric->g_13[i]*x[i] + metric->g_23[i]*y[i]; @@ -136,7 +136,7 @@ void Vector2D::toContravariant() { const auto y_at_z = interp_to(y, z.getLocation()); // multiply by g_{ij} - BOUT_FOR(i, x.getRegion("RGN_ALL")){ + BOUT_FOR(i, x.getRegion("RGN_ALL")) { x[i] = metric_x->g11[i]*x[i] + metric_x->g12[i]*y_at_x[i] + metric_x->g13[i]*z_at_x[i]; y[i] = metric_y->g22[i]*y[i] + metric_y->g12[i]*x_at_y[i] + metric_y->g23[i]*z_at_y[i]; z[i] = metric_z->g33[i]*z[i] + metric_z->g13[i]*x_at_z[i] + metric_z->g23[i]*y_at_z[i]; @@ -148,7 +148,7 @@ void Vector2D::toContravariant() { // Need to use temporary arrays to store result Coordinates::metric_field_type gx{emptyFrom(x)}, gy{emptyFrom(y)}, gz{emptyFrom(z)}; - BOUT_FOR(i, x.getRegion("RGN_ALL")){ + BOUT_FOR(i, x.getRegion("RGN_ALL")) { gx[i] = metric->g11[i]*x[i] + metric->g12[i]*y[i] + metric->g13[i]*z[i]; gy[i] = metric->g22[i]*y[i] + metric->g12[i]*x[i] + metric->g23[i]*z[i]; gz[i] = metric->g33[i]*z[i] + metric->g13[i]*x[i] + metric->g23[i]*y[i]; @@ -371,7 +371,7 @@ const Vector3D Vector2D::operator/(const Field3D &rhs) const { ////////////////// DOT PRODUCT /////////////////// -const Coordinates::metric_field_type Vector2D::operator*(const Vector2D &rhs) const { +const Coordinates::metric_field_type Vector2D::operator*(const Vector2D& rhs) const { ASSERT2(location == rhs.getLocation()); Mesh *localmesh = x.getMesh(); @@ -474,8 +474,7 @@ const Vector3D operator*(const Field3D &lhs, const Vector2D &rhs) { ***************************************************************/ // Return the magnitude of a vector -const Coordinates::metric_field_type -abs(const Vector2D &v, const std::string& region) { +const Coordinates::metric_field_type abs(const Vector2D& v, const std::string& region) { return sqrt(v*v, region); } diff --git a/src/fileio/datafile.cxx b/src/fileio/datafile.cxx index d79de67626..27127cbcd8 100644 --- a/src/fileio/datafile.cxx +++ b/src/fileio/datafile.cxx @@ -1030,9 +1030,9 @@ bool Datafile::read() { } // 2D vectors -#ifdef COORDINATES_USE_3D - for(const auto& var : v2d_arr) { - if(var.covar) { +#ifdef COORDINATES_USE_3D + for (const auto& var : v2d_arr) { + if (var.covar) { // Reading covariant vector read_f3d(var.name + "_x", &(var.ptr->x), var.save_repeat); read_f3d(var.name + "_y", &(var.ptr->y), var.save_repeat); @@ -1054,7 +1054,7 @@ bool Datafile::read() { read_f2d(var.name + "y", &(var.ptr->y), var.save_repeat); read_f2d(var.name + "z", &(var.ptr->z), var.save_repeat); } -#endif +#endif var.ptr->covariant = var.covar; } @@ -1188,24 +1188,24 @@ bool Datafile::write() { } // 2D vectors -#ifdef COORDINATES_USE_3D - for(const auto& var : v2d_arr) { - if(var.covar) { +#ifdef COORDINATES_USE_3D + for (const auto& var : v2d_arr) { + if (var.covar) { // Writing covariant vector - Vector2D v = *(var.ptr); + Vector2D v = *(var.ptr); v.toCovariant(); - - write_f3d(var.name+"_x", &(v.x), var.save_repeat); - write_f3d(var.name+"_y", &(v.y), var.save_repeat); - write_f3d(var.name+"_z", &(v.z), var.save_repeat); + + write_f3d(var.name + "_x", &(v.x), var.save_repeat); + write_f3d(var.name + "_y", &(v.y), var.save_repeat); + write_f3d(var.name + "_z", &(v.z), var.save_repeat); } else { // Writing contravariant vector - Vector2D v = *(var.ptr); + Vector2D v = *(var.ptr); v.toContravariant(); - - write_f3d(var.name+"x", &(v.x), var.save_repeat); - write_f3d(var.name+"y", &(v.y), var.save_repeat); - write_f3d(var.name+"z", &(v.z), var.save_repeat); + + write_f3d(var.name + "x", &(v.x), var.save_repeat); + write_f3d(var.name + "y", &(v.y), var.save_repeat); + write_f3d(var.name + "z", &(v.z), var.save_repeat); } } #else @@ -1227,7 +1227,7 @@ bool Datafile::write() { write_f2d(name+"z", &(v.z), var.save_repeat); } #endif - + // 3D vectors for(const auto& var : v3d_arr) { Vector3D v = *(var.ptr); diff --git a/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx b/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx index 255b47e307..7f633dbadc 100644 --- a/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx +++ b/src/invert/laplace/impls/multigrid/multigrid_laplace.cxx @@ -579,17 +579,19 @@ BOUT_OMP(for collapse(2)) BoutReal dz = coords->dz(i2, yindex); BoutReal ddx_C = (C2(i2+1, yindex, k2) - C2(i2-1, yindex, k2))/2./coords->dx(i2, yindex)/C1(i2, yindex, k2); - BoutReal ddz_C = (C2(i2, yindex, k2p) - C2(i2, yindex, k2m)) /2./dz/C1(i2, yindex, k2); - + BoutReal ddz_C = + (C2(i2, yindex, k2p) - C2(i2, yindex, k2m)) / 2. / dz / C1(i2, yindex, k2); + BoutReal ddx = D(i2, yindex, k2)*coords->g11(i2, yindex)/coords->dx(i2, yindex)/coords->dx(i2, yindex); // coefficient of 2nd derivative stencil (x-direction) - - BoutReal ddz = D(i2, yindex, k2)*coords->g33(i2, yindex)/SQ(dz); - // coefficient of 2nd derivative stencil (z-direction) - - BoutReal dxdz = D(i2, yindex, k2)*2.*coords->g13(i2, yindex)/coords->dx(i2, yindex)/dz; - // coefficient of mixed derivative stencil (could assume zero, at least initially, - // if easier; then check this is true in constructor) + + BoutReal ddz = D(i2, yindex, k2) * coords->g33(i2, yindex) / SQ(dz); + // coefficient of 2nd derivative stencil (z-direction) + + BoutReal dxdz = + D(i2, yindex, k2) * 2. * coords->g13(i2, yindex) / coords->dx(i2, yindex) / dz; + // coefficient of mixed derivative stencil (could assume zero, at least initially, + // if easier; then check this is true in constructor) BoutReal dxd = (D(i2, yindex, k2)*coords->G1(i2, yindex) + coords->g11(i2, yindex)*ddx_C @@ -599,12 +601,15 @@ BOUT_OMP(for collapse(2)) // add correction for non-uniform dx dxd += D(i2, yindex, k2)*coords->d1_dx(i2, yindex); } - - BoutReal dzd = (D(i2, yindex, k2)*coords->G3(i2, yindex) - + coords->g33(i2, yindex)*ddz_C - + coords->g13(i2, yindex)*ddx_C // (could assume zero, at least initially, if easier; then check this is true in constructor) - )/dz; // coefficient of 1st derivative stencil (z-direction) - + + BoutReal dzd = + (D(i2, yindex, k2) * coords->G3(i2, yindex) + coords->g33(i2, yindex) * ddz_C + + coords->g13(i2, yindex) + * ddx_C // (could assume zero, at least initially, if easier; then check + // this is true in constructor) + ) + / dz; // coefficient of 1st derivative stencil (z-direction) + int ic = i*(llz+2)+k; mat[ic*9] = dxdz/4.; mat[ic*9+1] = ddx - dxd/2.; diff --git a/src/invert/laplace/impls/petsc/petsc_laplace.cxx b/src/invert/laplace/impls/petsc/petsc_laplace.cxx index 8d2d62799f..6c2b1462a2 100644 --- a/src/invert/laplace/impls/petsc/petsc_laplace.cxx +++ b/src/invert/laplace/impls/petsc/petsc_laplace.cxx @@ -401,23 +401,43 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0) { // Set values corresponding to nodes adjacent in x if( fourth_order ) { // Fourth Order Accuracy on Boundary - Element(i,x,z, 0, 0, -25.0 / (12.0*coords->dx(x,y,z)) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, 1, 0, 4.0 / coords->dx(x,y,z) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, 2, 0, -3.0 / coords->dx(x,y,z) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, 3, 0, 4.0 / (3.0*coords->dx(x,y,z)) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, 4, 0, -1.0 / (4.0*coords->dx(x,y,z)) / sqrt(coords->g_11(x,y,z)), MatA ); + Element(i, x, z, 0, 0, + -25.0 / (12.0 * coords->dx(x, y, z)) + / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, 1, 0, + 4.0 / coords->dx(x, y, z) / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, 2, 0, + -3.0 / coords->dx(x, y, z) / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, 3, 0, + 4.0 / (3.0 * coords->dx(x, y, z)) + / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, 4, 0, + -1.0 / (4.0 * coords->dx(x, y, z)) + / sqrt(coords->g_11(x, y, z)), + MatA); } else { // Second Order Accuracy on Boundary // Element(i,x,z, 0, 0, -3.0 / (2.0*coords->dx(x,y)), MatA ); // Element(i,x,z, 1, 0, 2.0 / coords->dx(x,y), MatA ); // Element(i,x,z, 2, 0, -1.0 / (2.0*coords->dx(x,y)), MatA ); - // Element(i,x,z, 3, 0, 0.0, MatA ); // Reset these elements to 0 in case 4th order flag was used previously: not allowed now + // Element(i,x,z, 3, 0, 0.0, MatA ); // Reset these elements to 0 + // in case 4th order flag was used previously: not allowed now // Element(i,x,z, 4, 0, 0.0, MatA ); // Second Order Accuracy on Boundary, set half-way between grid points - Element(i,x,z, 0, 0, -1.0 / coords->dx(x,y,z) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, 1, 0, 1.0 / coords->dx(x,y,z) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, 2, 0, 0.0, MatA ); - // Element(i,x,z, 3, 0, 0.0, MatA ); // Reset these elements to 0 in case 4th order flag was used previously: not allowed now + Element(i, x, z, 0, 0, + -1.0 / coords->dx(x, y, z) / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, 1, 0, + 1.0 / coords->dx(x, y, z) / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, 2, 0, 0.0, MatA); + // Element(i,x,z, 3, 0, 0.0, MatA ); // Reset + // these elements to 0 in case 4th order flag was + // used previously: not allowed now // Element(i,x,z, 4, 0, 0.0, MatA ); } } else { @@ -472,12 +492,12 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0) { // Set the matrix coefficients Coeffs( x, y, z, A1, A2, A3, A4, A5 ); - BoutReal dx = coords->dx(x,y,z); - BoutReal dx2 = SQ(dx); - BoutReal dz = coords->dz(x,y,z); - BoutReal dz2 = SQ(dz); + BoutReal dx = coords->dx(x, y, z); + BoutReal dx2 = SQ(dx); + BoutReal dz = coords->dz(x, y, z); + BoutReal dz2 = SQ(dz); BoutReal dxdz = dx * dz; - + ASSERT3(finite(A1)); ASSERT3(finite(A2)); ASSERT3(finite(A3)); @@ -650,11 +670,24 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0) { // Set values corresponding to nodes adjacent in x if( fourth_order ) { // Fourth Order Accuracy on Boundary - Element(i,x,z, 0, 0, 25.0 / (12.0*coords->dx(x,y,z)) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, -1, 0, -4.0 / coords->dx(x,y,z) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, -2, 0, 3.0 / coords->dx(x,y,z) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, -3, 0, -4.0 / (3.0*coords->dx(x,y,z)) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, -4, 0, 1.0 / (4.0*coords->dx(x,y,z)) / sqrt(coords->g_11(x,y,z)), MatA ); + Element(i, x, z, 0, 0, + 25.0 / (12.0 * coords->dx(x, y, z)) + / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, -1, 0, + -4.0 / coords->dx(x, y, z) / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, -2, 0, + 3.0 / coords->dx(x, y, z) / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, -3, 0, + -4.0 / (3.0 * coords->dx(x, y, z)) + / sqrt(coords->g_11(x, y, z)), + MatA); + Element(i, x, z, -4, 0, + 1.0 / (4.0 * coords->dx(x, y, z)) + / sqrt(coords->g_11(x, y, z)), + MatA); } else { // // Second Order Accuracy on Boundary @@ -664,9 +697,9 @@ FieldPerp LaplacePetsc::solve(const FieldPerp& b, const FieldPerp& x0) { // // Element(i,x,z, -3, 0, 0.0, MatA ); // Reset these elements to 0 in case 4th order flag was used previously: not allowed now // // Element(i,x,z, -4, 0, 0.0, MatA ); // Second Order Accuracy on Boundary, set half-way between grid points - Element(i,x,z, 0, 0, 1.0 / coords->dx(x,y,z) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, -1, 0, -1.0 / coords->dx(x,y,z) / sqrt(coords->g_11(x,y,z)), MatA ); - Element(i,x,z, -2, 0, 0.0, MatA ); +Element(i, x, z, 0, 0, 1.0 / coords->dx(x, y, z) / sqrt(coords->g_11(x, y, z)), MatA); +Element(i, x, z, -1, 0, -1.0 / coords->dx(x, y, z) / sqrt(coords->g_11(x, y, z)), MatA); +Element(i, x, z, -2, 0, 0.0, MatA); // Element(i,x,z, -3, 0, 0.0, MatA ); // Reset these elements to 0 in case 4th order flag was used previously: not allowed now // Element(i,x,z, -4, 0, 0.0, MatA ); } @@ -938,16 +971,16 @@ void LaplacePetsc::Element(int i, int x, int z, */ void LaplacePetsc::Coeffs( int x, int y, int z, BoutReal &coef1, BoutReal &coef2, BoutReal &coef3, BoutReal &coef4, BoutReal &coef5 ) { - coef1 = coords->g11(x,y,z); // X 2nd derivative coefficient - coef2 = coords->g33(x,y,z); // Z 2nd derivative coefficient - coef3 = 2.*coords->g13(x,y,z); // X-Z mixed derivative coefficient + coef1 = coords->g11(x, y, z); // X 2nd derivative coefficient + coef2 = coords->g33(x, y, z); // Z 2nd derivative coefficient + coef3 = 2. * coords->g13(x, y, z); // X-Z mixed derivative coefficient coef4 = 0.0; coef5 = 0.0; // If global flag all_terms are set (true by default) if (all_terms) { - coef4 = coords->G1(x,y,z); // X 1st derivative - coef5 = coords->G3(x,y,z); // Z 1st derivative + coef4 = coords->G1(x, y, z); // X 1st derivative + coef5 = coords->G3(x, y, z); // Z 1st derivative ASSERT3(finite(coef4)); ASSERT3(finite(coef5)); @@ -956,13 +989,17 @@ void LaplacePetsc::Coeffs( int x, int y, int z, BoutReal &coef1, BoutReal &coef2 if(nonuniform) { // non-uniform mesh correction if((x != 0) && (x != (localmesh->LocalNx-1))) { - coef4 -= 0.5 * ( ( coords->dx(x+1,y,z) - coords->dx(x-1,y,z) ) / SQ(coords->dx(x,y,z)) ) * coef1; // BOUT-06 term + coef4 -= 0.5 + * ((coords->dx(x + 1, y, z) - coords->dx(x - 1, y, z)) + / SQ(coords->dx(x, y, z))) + * coef1; // BOUT-06 term } } if(localmesh->IncIntShear) { // d2dz2 term - coef2 += coords->g11(x,y,z) * coords->IntShiftTorsion(x,y,z) * coords->IntShiftTorsion(x,y,z); + coef2 += coords->g11(x, y, z) * coords->IntShiftTorsion(x, y, z) + * coords->IntShiftTorsion(x, y, z); // Mixed derivative coef3 = 0.0; // This cancels out } @@ -992,19 +1029,25 @@ void LaplacePetsc::Coeffs( int x, int y, int z, BoutReal &coef1, BoutReal &coef2 int zmm = z-2; // z minus 1 minus 1 if (zmm<0) zmm += meshz; // Fourth order discretization of C in x - ddx_C = (-C2(x+2,y,z) + 8.*C2(x+1,y,z) - 8.*C2(x-1,y,z) + C2(x-2,y,z)) / (12.*coords->dx(x,y,z)*(C1(x,y,z))); + ddx_C = (-C2(x + 2, y, z) + 8. * C2(x + 1, y, z) - 8. * C2(x - 1, y, z) + + C2(x - 2, y, z)) + / (12. * coords->dx(x, y, z) * (C1(x, y, z))); // Fourth order discretization of C in z - ddz_C = (-C2(x,y,zpp) + 8.*C2(x,y,zp) - 8.*C2(x,y,zm) + C2(x,y,zmm)) / (12.*coords->dz(x,y,z)*(C1(x,y,z))); + ddz_C = + (-C2(x, y, zpp) + 8. * C2(x, y, zp) - 8. * C2(x, y, zm) + C2(x, y, zmm)) + / (12. * coords->dz(x, y, z) * (C1(x, y, z))); } else { // Second order discretization of C in x - ddx_C = (C2(x+1,y,z) - C2(x-1,y,z)) / (2.*coords->dx(x,y,z)*(C1(x,y,z))); + ddx_C = (C2(x + 1, y, z) - C2(x - 1, y, z)) + / (2. * coords->dx(x, y, z) * (C1(x, y, z))); // Second order discretization of C in z - ddz_C = (C2(x,y,zp) - C2(x,y,zm)) / (2.*coords->dz(x,y,z)*(C1(x,y,z))); + ddz_C = (C2(x, y, zp) - C2(x, y, zm)) + / (2. * coords->dz(x, y, z) * (C1(x, y, z))); } - coef4 += coords->g11(x,y,z) * ddx_C + coords->g13(x,y,z) * ddz_C; - coef5 += coords->g13(x,y,z) * ddx_C + coords->g33(x,y,z) * ddz_C; + coef4 += coords->g11(x, y, z) * ddx_C + coords->g13(x, y, z) * ddz_C; + coef5 += coords->g13(x, y, z) * ddx_C + coords->g33(x, y, z) * ddz_C; } } diff --git a/src/invert/laplace/impls/petsc3damg/petsc3damg.cxx b/src/invert/laplace/impls/petsc3damg/petsc3damg.cxx index 6b94d5ff83..3e7e69ef6e 100644 --- a/src/invert/laplace/impls/petsc3damg/petsc3damg.cxx +++ b/src/invert/laplace/impls/petsc3damg/petsc3damg.cxx @@ -271,8 +271,8 @@ void LaplacePetsc3dAmg::updateMatrix3D() { const Field3D dc_dx = issetC ? DDX(C2) : Field3D(); const Field3D dc_dy = issetC ? DDY(C2) : Field3D(); const Field3D dc_dz = issetC ? DDZ(C2) : Field3D(); - const auto dJ_dy = DDY(coords->J/coords->g_22); - + const auto dJ_dy = DDY(coords->J / coords->g_22); + // Set up the matrix for the internal points on the grid. // Boundary conditions were set in the constructor. BOUT_FOR_SERIAL(l, indexer->getRegionNobndry()) { @@ -383,7 +383,7 @@ void LaplacePetsc3dAmg::updateMatrix3D() { C_d2f_dxdy /= 4*coords->dx[l]; // NOTE: This value is not completed here. It needs to // be divide by dx(i +/- 1, j, k) when using to set a // matrix element - C_d2f_dydz /= 4*coords->dy[l]*coords->dz[l]; + C_d2f_dydz /= 4 * coords->dy[l] * coords->dz[l]; // The values stored in the y-boundary are already interpolated // up/down, so we don't want the matrix to do any such diff --git a/src/invert/laplace/impls/serial_band/serial_band.cxx b/src/invert/laplace/impls/serial_band/serial_band.cxx index 19b92dffba..daa51c15f2 100644 --- a/src/invert/laplace/impls/serial_band/serial_band.cxx +++ b/src/invert/laplace/impls/serial_band/serial_band.cxx @@ -123,9 +123,8 @@ FieldPerp LaplaceSerialBand::solve(const FieldPerp& b, const FieldPerp& x0) { for(int iz=0;iz<=maxmode;iz++) { // solve differential equation in x - - BoutReal coef1=0.0, coef2=0.0, coef3=0.0, coef4=0.0, - coef5=0.0, coef6=0.0; + + BoutReal coef1 = 0.0, coef2 = 0.0, coef3 = 0.0, coef4 = 0.0, coef5 = 0.0, coef6 = 0.0; ///////// PERFORM INVERSION ///////// // shift freqs according to FFT convention @@ -200,7 +199,7 @@ FieldPerp LaplaceSerialBand::solve(const FieldPerp& b, const FieldPerp& x0) { int ix = 1; - auto kwave = kwave_(ix,jy); + auto kwave = kwave_(ix, jy); coef1=coords->g11(ix,jy)/(SQ(coords->dx(ix,jy))); coef2=coords->g33(ix,jy); coef3= kwave * coords->g13(ix,jy)/(2. * coords->dx(ix,jy)); @@ -322,7 +321,7 @@ FieldPerp LaplaceSerialBand::solve(const FieldPerp& b, const FieldPerp& x0) { int ix = 1; - auto kwave = kwave_(ix,jy); + auto kwave = kwave_(ix, jy); coef1=coords->g11(ix,jy)/(12.* SQ(coords->dx(ix,jy))); coef2=coords->g33(ix,jy); @@ -369,7 +368,7 @@ FieldPerp LaplaceSerialBand::solve(const FieldPerp& b, const FieldPerp& x0) { coef2=coords->g33(ix,jy); - auto kwave = kwave_(ix,jy); + auto kwave = kwave_(ix, jy); coef3= kwave * coords->g13(ix,jy)/(2. * coords->dx(ix,jy)); coef4 = Acoef(ix,jy); diff --git a/src/invert/laplace/impls/shoot/shoot_laplace.cxx b/src/invert/laplace/impls/shoot/shoot_laplace.cxx index f59429f105..ae61eb7710 100644 --- a/src/invert/laplace/impls/shoot/shoot_laplace.cxx +++ b/src/invert/laplace/impls/shoot/shoot_laplace.cxx @@ -134,8 +134,8 @@ FieldPerp LaplaceShoot::solve(const FieldPerp& rhs) { rfft(rhs[ix], localmesh->LocalNz, std::begin(rhsk)); for(int kz=0; kzgetLocation() == loc); ASSERT1(d == nullptr || d->getLocation() == loc); - BoutReal kwave=jz*2.0*PI/coords->zlength()(jx,jy); // wave number is 1/[rad] + BoutReal kwave = jz * 2.0 * PI / coords->zlength()(jx, jy); // wave number is 1/[rad] tridagCoefs(jx, jy, kwave, a, b, c, diff --git a/src/invert/laplacexy/laplacexy.cxx b/src/invert/laplacexy/laplacexy.cxx index a52da73b19..56b3289ef8 100644 --- a/src/invert/laplacexy/laplacexy.cxx +++ b/src/invert/laplacexy/laplacexy.cxx @@ -900,7 +900,7 @@ void LaplaceXY::setMatrixElementsFiniteVolume(const Field2D &A, const Field2D &B const Field2D g_22_DC = DC(coords->g_22); const Field2D g_23_DC = DC(coords->g_23); const Field2D g23_DC = DC(coords->g23); - + for(int x=localmesh->xstart; x <= localmesh->xend; x++) { for(int y=localmesh->ystart;y<=localmesh->yend;y++) { // stencil entries @@ -909,22 +909,22 @@ void LaplaceXY::setMatrixElementsFiniteVolume(const Field2D &A, const Field2D &B // XX component // Metrics on x+1/2 boundary - BoutReal J = 0.5*(J_DC(x,y) + J_DC(x+1,y)); - BoutReal g11 = 0.5*(g11_DC(x,y) + g11_DC(x+1,y)); - BoutReal dx = 0.5*(dx_DC(x,y) + dx_DC(x+1,y)); + BoutReal J = 0.5 * (J_DC(x, y) + J_DC(x + 1, y)); + BoutReal g11 = 0.5 * (g11_DC(x, y) + g11_DC(x + 1, y)); + BoutReal dx = 0.5 * (dx_DC(x, y) + dx_DC(x + 1, y)); BoutReal Acoef = 0.5*(A(x,y) + A(x+1,y)); - BoutReal val = Acoef * J * g11 / (J_DC(x,y) * dx * dx_DC(x,y)); + BoutReal val = Acoef * J * g11 / (J_DC(x, y) * dx * dx_DC(x, y)); xp = val; c = -val; // Metrics on x-1/2 boundary - J = 0.5*(J_DC(x,y) + J_DC(x-1,y)); - g11 = 0.5*(g11_DC(x,y) + g11_DC(x-1,y)); - dx = 0.5*(dx_DC(x,y) + dx_DC(x-1,y)); + J = 0.5 * (J_DC(x, y) + J_DC(x - 1, y)); + g11 = 0.5 * (g11_DC(x, y) + g11_DC(x - 1, y)); + dx = 0.5 * (dx_DC(x, y) + dx_DC(x - 1, y)); Acoef = 0.5*(A(x,y) + A(x-1,y)); - val = Acoef * J * g11 / (J_DC(x,y) * dx * dx_DC(x,y)); + val = Acoef * J * g11 / (J_DC(x, y) * dx * dx_DC(x, y)); xm = val; c -= val; @@ -938,26 +938,26 @@ void LaplaceXY::setMatrixElementsFiniteVolume(const Field2D &A, const Field2D &B if( include_y_derivs ) { // YY component // Metrics at y+1/2 - J = 0.5*(J_DC(x,y) + J_DC(x,y+1)); - BoutReal g_22 = 0.5*(g_22_DC(x,y) + g_22_DC(x,y+1)); - BoutReal g23 = 0.5*(g23_DC(x,y) + g23_DC(x,y+1)); - BoutReal g_23 = 0.5*(g_23_DC(x,y) + g_23_DC(x,y+1)); - BoutReal dy = 0.5*(dy_DC(x,y) + dy_DC(x,y+1)); + J = 0.5 * (J_DC(x, y) + J_DC(x, y + 1)); + BoutReal g_22 = 0.5 * (g_22_DC(x, y) + g_22_DC(x, y + 1)); + BoutReal g23 = 0.5 * (g23_DC(x, y) + g23_DC(x, y + 1)); + BoutReal g_23 = 0.5 * (g_23_DC(x, y) + g_23_DC(x, y + 1)); + BoutReal dy = 0.5 * (dy_DC(x, y) + dy_DC(x, y + 1)); Acoef = 0.5*(A(x,y+1) + A(x,y)); - val = -Acoef * J * g23 * g_23 / (g_22 * J_DC(x,y) * dy * dy_DC(x,y)); + val = -Acoef * J * g23 * g_23 / (g_22 * J_DC(x, y) * dy * dy_DC(x, y)); yp = val; c -= val; // Metrics at y-1/2 - J = 0.5*(J_DC(x,y) + J_DC(x,y-1)); - g_22 = 0.5*(g_22_DC(x,y) + g_22_DC(x,y-1)); - g23 = 0.5*(g23_DC(x,y) + g23_DC(x,y-1)); - g_23 = 0.5*(g_23_DC(x,y) + g_23_DC(x,y-1)); - dy = 0.5*(dy_DC(x,y) + dy_DC(x,y-1)); + J = 0.5 * (J_DC(x, y) + J_DC(x, y - 1)); + g_22 = 0.5 * (g_22_DC(x, y) + g_22_DC(x, y - 1)); + g23 = 0.5 * (g23_DC(x, y) + g23_DC(x, y - 1)); + g_23 = 0.5 * (g_23_DC(x, y) + g_23_DC(x, y - 1)); + dy = 0.5 * (dy_DC(x, y) + dy_DC(x, y - 1)); Acoef = 0.5*(A(x,y-1) + A(x,y)); - val = -Acoef * J * g23 * g_23 / (g_22 * J_DC(x,y) * dy * dy_DC(x,y)); + val = -Acoef * J * g23 * g_23 / (g_22 * J_DC(x, y) * dy * dy_DC(x, y)); ym = val; c -= val; } @@ -1014,33 +1014,33 @@ void LaplaceXY::setMatrixElementsFiniteDifference(const Field2D &A, const Field2 const Field2D d1_dy_2D = DC(coords->d1_dy); const Field2D dx_2D = DC(coords->dx); const Field2D dy_2D = DC(coords->dy); - - const Field2D coef_dfdy = G2_2D - DC(DDY(J_2D/g_22_2D)/J_2D); + + const Field2D coef_dfdy = G2_2D - DC(DDY(J_2D / g_22_2D) / J_2D); for(int x = localmesh->xstart; x <= localmesh->xend; x++) { for(int y = localmesh->ystart; y <= localmesh->yend; y++) { // stencil entries PetscScalar c, xm, xp, ym, yp, xpyp, xpym, xmyp, xmym; - BoutReal dx = dx_2D(x,y); + BoutReal dx = dx_2D(x, y); // A*G1*dfdx - BoutReal val = A(x, y)*G1_2D(x, y)/(2.*dx); + BoutReal val = A(x, y) * G1_2D(x, y) / (2. * dx); xp = val; xm = -val; // A*g11*d2fdx2 - val = A(x, y)*g11_2D(x, y)/SQ(dx); + val = A(x, y) * g11_2D(x, y) / SQ(dx); xp += val; c = -2.*val; xm += val; // Non-uniform grid correction - val = A(x, y)*g11_2D(x, y)*d1_dx_2D(x, y)/(2.*dx); + val = A(x, y) * g11_2D(x, y) * d1_dx_2D(x, y) / (2. * dx); xp += val; xm -= val; // g11*dAdx*dfdx - val = g11_2D(x, y)*(A(x+1, y) - A(x-1, y))/(4.*SQ(dx)); + val = g11_2D(x, y) * (A(x + 1, y) - A(x - 1, y)) / (4. * SQ(dx)); xp += val; xm -= val; @@ -1053,7 +1053,7 @@ void LaplaceXY::setMatrixElementsFiniteDifference(const Field2D &A, const Field2 ccoef(y - localmesh->ystart, x - xstart) = xp; if(include_y_derivs) { - BoutReal dy = dy_2D(x,y); + BoutReal dy = dy_2D(x, y); BoutReal dAdx = (A(x+1, y) - A(x-1, y))/(2.*dx); BoutReal dAdy = (A(x, y+1) - A(x, y-1))/(2.*dy); @@ -1063,33 +1063,32 @@ void LaplaceXY::setMatrixElementsFiniteDifference(const Field2D &A, const Field2 ym = -val; // A*(g22-1/g_22)*d2fdy2 - val = A(x, y)*(g22_2D(x, y) - 1./g_22_2D(x,y))/SQ(dy); + val = A(x, y) * (g22_2D(x, y) - 1. / g_22_2D(x, y)) / SQ(dy); yp += val; c -= 2.*val; ym += val; // Non-uniform mesh correction - val = A(x, y)*(g22_2D(x, y) - 1./g_22_2D(x,y)) - *d1_dy_2D(x, y)/(2.*dy); + val = A(x, y) * (g22_2D(x, y) - 1. / g_22_2D(x, y)) * d1_dy_2D(x, y) / (2. * dy); yp += val; ym -= val; // 2*A*g12*d2dfdxdy - val = A(x, y)*g12_2D(x, y)/(2.*dx*dy); + val = A(x, y) * g12_2D(x, y) / (2. * dx * dy); xpyp = val; xpym = -val; xmyp = -val; xmym = val; // g22*dAdy*dfdy - val = (g22_2D(x, y) - 1./g_22_2D(x,y))*dAdy/(2.*dy); + val = (g22_2D(x, y) - 1. / g_22_2D(x, y)) * dAdy / (2. * dy); yp += val; ym -= val; // g12*(dAdx*dfdy + dAdy*dfdx) - val = g12_2D(x, y)*dAdx/(2.*dy); + val = g12_2D(x, y) * dAdx / (2. * dy); yp += val; ym -= val; - val = g12_2D(x, y)*dAdy/(2.*dx); + val = g12_2D(x, y) * dAdy / (2. * dx); xp += val; xm -= val; } diff --git a/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx b/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx index bfe67f7dc7..4e0a166f5e 100644 --- a/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx +++ b/src/invert/laplacexz/impls/petsc/laplacexz-petsc.cxx @@ -392,26 +392,28 @@ void LaplaceXZpetsc::setCoefs(const Field3D &Ain, const Field3D &Bin) { // XX component { // Metrics on x+1/2 boundary - const BoutReal J = 0.5*(coords->J(x,y,z) + coords->J(x+1,y,z)); - const BoutReal g11 = 0.5*(coords->g11(x,y,z) + coords->g11(x+1,y,z)); - const BoutReal dx = 0.5*(coords->dx(x,y,z) + coords->dx(x+1,y,z)); - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x+1,y,z)); + const BoutReal J = 0.5 * (coords->J(x, y, z) + coords->J(x + 1, y, z)); + const BoutReal g11 = 0.5 * (coords->g11(x, y, z) + coords->g11(x + 1, y, z)); + const BoutReal dx = 0.5 * (coords->dx(x, y, z) + coords->dx(x + 1, y, z)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x + 1, y, z)); - const BoutReal val = Acoef * J * g11 / (coords->J(x,y,z) * dx * coords->dx(x,y,z)); + const BoutReal val = + Acoef * J * g11 / (coords->J(x, y, z) * dx * coords->dx(x, y, z)); xp = val; - c = -val; + c = -val; } { // Metrics on x-1/2 boundary - const BoutReal J = 0.5*(coords->J(x,y,z) + coords->J(x-1,y,z)); - const BoutReal g11 = 0.5*(coords->g11(x,y,z) + coords->g11(x-1,y,z)); - const BoutReal dx = 0.5*(coords->dx(x,y,z) + coords->dx(x-1,y,z)); - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x-1,y,z)); + const BoutReal J = 0.5 * (coords->J(x, y, z) + coords->J(x - 1, y, z)); + const BoutReal g11 = 0.5 * (coords->g11(x, y, z) + coords->g11(x - 1, y, z)); + const BoutReal dx = 0.5 * (coords->dx(x, y, z) + coords->dx(x - 1, y, z)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x - 1, y, z)); - const BoutReal val = Acoef * J * g11 / (coords->J(x,y,z) * dx * coords->dx(x,y,z)); + const BoutReal val = + Acoef * J * g11 / (coords->J(x, y, z) * dx * coords->dx(x, y, z)); xm = val; - c -= val; + c -= val; } // ZZ component @@ -420,26 +422,26 @@ void LaplaceXZpetsc::setCoefs(const Field3D &Ain, const Field3D &Bin) { const int zplus = (z + 1) % (localmesh->LocalNz); { - const BoutReal J = 0.5*(coords->J(x,y,z) + coords->J(x,y,zplus)); - const BoutReal g33 = 0.5*(coords->g33(x,y,z) + coords->g33(x,y,zplus)); - const BoutReal dz = 0.5 * (coords->dz(x,y,z)+ coords->dz(x,y,zplus)); + const BoutReal J = 0.5 * (coords->J(x, y, z) + coords->J(x, y, zplus)); + const BoutReal g33 = 0.5 * (coords->g33(x, y, z) + coords->g33(x, y, zplus)); + const BoutReal dz = 0.5 * (coords->dz(x, y, z) + coords->dz(x, y, zplus)); // Metrics on z+1/2 boundary - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x,y,zplus)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x, y, zplus)); - const BoutReal val = Acoef * J * g33 / (coords->J(x,y,z) * dz * dz); + const BoutReal val = Acoef * J * g33 / (coords->J(x, y, z) * dz * dz); zp = val; - c -= val; + c -= val; } { // Metrics on z-1/2 boundary - const BoutReal J = 0.5*(coords->J(x,y,z) + coords->J(x,y,zminus)); - const BoutReal g33 = 0.5*(coords->g33(x,y,z) + coords->g33(x,y,zminus)); - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x,y,zminus)); - const BoutReal dz = 0.5 * (coords->dz(x,y,z)+ coords->dz(x,y,zminus)); + const BoutReal J = 0.5 * (coords->J(x, y, z) + coords->J(x, y, zminus)); + const BoutReal g33 = 0.5 * (coords->g33(x, y, z) + coords->g33(x, y, zminus)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x, y, zminus)); + const BoutReal dz = 0.5 * (coords->dz(x, y, z) + coords->dz(x, y, zminus)); - const BoutReal val = Acoef * J * g33 / (coords->J(x,y,z) * dz * dz); + const BoutReal val = Acoef * J * g33 / (coords->J(x, y, z) * dz * dz); zm = val; - c -= val; + c -= val; } // XZ components @@ -447,13 +449,14 @@ void LaplaceXZpetsc::setCoefs(const Field3D &Ain, const Field3D &Bin) { { // x+1/2, z+1/2 // TODOL Should they have a z dependency? - const BoutReal J = 0.5*(coords->J(x,y,z) + coords->J(x+1,y,z)); - const BoutReal g13 = 0.5*(coords->g13(x,y,z) + coords->g13(x+1,y,z)); - const BoutReal fourdz = 2 * (coords->dz(x,y,z)+ coords->dz(x+1,y,zplus)); + const BoutReal J = 0.5 * (coords->J(x, y, z) + coords->J(x + 1, y, z)); + const BoutReal g13 = 0.5 * (coords->g13(x, y, z) + coords->g13(x + 1, y, z)); + const BoutReal fourdz = 2 * (coords->dz(x, y, z) + coords->dz(x + 1, y, zplus)); { - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x,y,zplus)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x, y, zplus)); - const BoutReal val = Acoef * J * g13 / (coords->J(x,y,z) * fourdz * coords->dx(x,y,z)); + const BoutReal val = + Acoef * J * g13 / (coords->J(x, y, z) * fourdz * coords->dx(x, y, z)); xpzp = val; c -= val; } @@ -461,30 +464,33 @@ void LaplaceXZpetsc::setCoefs(const Field3D &Ain, const Field3D &Bin) { // x+1/2, z-1/2 // J = 0.5*(coords->J(x,y,z) + coords->J(x+1,y,z)); // g13 = 0.5*(coords->gxz(x,y,z) + coords->gxz(x+1,y,z)); - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x,y,zminus)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x, y, zminus)); - const BoutReal val = - Acoef * J * g13 / (coords->J(x,y,z) * fourdz * coords->dx(x,y,z)); + const BoutReal val = + -Acoef * J * g13 / (coords->J(x, y, z) * fourdz * coords->dx(x, y, z)); xpzm = val; c -= val; } } { // x-1/2, z+1/2 - const BoutReal J = 0.5*(coords->J(x,y,z) + coords->J(x-1,y,z)); - const BoutReal g13 = 0.5*(coords->g13(x,y,z) + coords->g13(x-1,y,z)); - const BoutReal fourdz = 2 * (coords->dz(x,y,z)+ coords->dz(x-1,y,z)); + const BoutReal J = 0.5 * (coords->J(x, y, z) + coords->J(x - 1, y, z)); + const BoutReal g13 = 0.5 * (coords->g13(x, y, z) + coords->g13(x - 1, y, z)); + const BoutReal fourdz = 2 * (coords->dz(x, y, z) + coords->dz(x - 1, y, z)); { - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x,y,zplus)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x, y, zplus)); - const BoutReal val = - Acoef * J * g13 / (coords->J(x,y,z) * fourdz * coords->dx(x,y,z)); + const BoutReal val = + -Acoef * J * g13 / (coords->J(x, y, z) * fourdz * coords->dx(x, y, z)); xmzp = val; c -= val; } { // x-1/2, z-1/2 - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x,y,zminus)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x, y, zminus)); - const BoutReal val = Acoef * J * g13 / (coords->J(x,y,z) * fourdz * coords->dx(x,y,z)); + const BoutReal val = + Acoef * J * g13 / (coords->J(x, y, z) * fourdz * coords->dx(x, y, z)); xmzm = val; c -= val; } @@ -493,53 +499,52 @@ void LaplaceXZpetsc::setCoefs(const Field3D &Ain, const Field3D &Bin) { { // ZX components // z+1/2, x+1/2 - const BoutReal J = 0.5*(coords->J(x,y,z) + coords->J(x,y,zplus)); - const BoutReal g13 = 0.5*(coords->g13(x,y,z) + coords->g13(x,y,zplus)); - const BoutReal dz = 0.5 * (coords->dz(x,y,z)+ coords->dz(x,y,zplus)); + const BoutReal J = 0.5 * (coords->J(x, y, z) + coords->J(x, y, zplus)); + const BoutReal g13 = 0.5 * (coords->g13(x, y, z) + coords->g13(x, y, zplus)); + const BoutReal dz = 0.5 * (coords->dz(x, y, z) + coords->dz(x, y, zplus)); { - const BoutReal dx = 2.0*(coords->dx(x,y,z) + coords->dx(x+1,y,z)); - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x+1,y,z)); + const BoutReal dx = 2.0 * (coords->dx(x, y, z) + coords->dx(x + 1, y, z)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x + 1, y, z)); - const BoutReal val = Acoef * J * g13 / (coords->J(x,y,z) * dx * dz); + const BoutReal val = Acoef * J * g13 / (coords->J(x, y, z) * dx * dz); zpxp = val; c -= val; } { - //z+1/2, x-1/2 - const BoutReal dx = 2.0*(coords->dx(x,y,z) + coords->dx(x-1,y,z)); - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x-1,y,z)); + // z+1/2, x-1/2 + const BoutReal dx = 2.0 * (coords->dx(x, y, z) + coords->dx(x - 1, y, z)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x - 1, y, z)); - const BoutReal val = - Acoef * J * g13 / (coords->J(x,y,z) * dx * dz); + const BoutReal val = -Acoef * J * g13 / (coords->J(x, y, z) * dx * dz); zpxm = val; c -= val; } } { // z-1/2, x+1/2 - const BoutReal J = 0.5*(coords->J(x,y,z) + coords->J(x,y,zminus)); - const BoutReal g13 = 0.5*(coords->g13(x,y,z) + coords->g13(x,y,zminus)); - const BoutReal dz = 0.5 * (coords->dz(x,y,z)+ coords->dz(x,y,zminus)); + const BoutReal J = 0.5 * (coords->J(x, y, z) + coords->J(x, y, zminus)); + const BoutReal g13 = 0.5 * (coords->g13(x, y, z) + coords->g13(x, y, zminus)); + const BoutReal dz = 0.5 * (coords->dz(x, y, z) + coords->dz(x, y, zminus)); { - const BoutReal dx = 2.0*(coords->dx(x,y,z) + coords->dx(x+1,y,z)); - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x+1,y,z)); + const BoutReal dx = 2.0 * (coords->dx(x, y, z) + coords->dx(x + 1, y, z)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x + 1, y, z)); - const BoutReal val = - Acoef * J * g13 / (coords->J(x,y,z) * dx * dz); + const BoutReal val = -Acoef * J * g13 / (coords->J(x, y, z) * dx * dz); zmxp = val; c -= val; } { // z-1/2, x-1/2 - const BoutReal dx = 2.0*(coords->dx(x,y,z) + coords->dx(x-1,y,z)); - const BoutReal Acoef = 0.5*(A(x,y,z) + A(x-1,y,z)); + const BoutReal dx = 2.0 * (coords->dx(x, y, z) + coords->dx(x - 1, y, z)); + const BoutReal Acoef = 0.5 * (A(x, y, z) + A(x - 1, y, z)); - const BoutReal val = Acoef * J * g13 / (coords->J(x,y,z) * dx * dz); + const BoutReal val = Acoef * J * g13 / (coords->J(x, y, z) * dx * dz); zmxm = val; c -= val; } } - ///////////// OLDER CODE ///////////////// // Note that because metrics are constant in Z many terms cancel @@ -562,7 +567,6 @@ void LaplaceXZpetsc::setCoefs(const Field3D &Ain, const Field3D &Bin) { // c -= val; ////////////////////////////////////////// - // B term c += B(x,y,z); @@ -570,45 +574,45 @@ void LaplaceXZpetsc::setCoefs(const Field3D &Ain, const Field3D &Bin) { // Now have a 5-point stencil for the Laplacian // Set the centre (diagonal) - MatSetValues(it.MatA,1,&row,1,&row,&c,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &row, &c, INSERT_VALUES); // X + 1 int col = row + (localmesh->LocalNz); - MatSetValues(it.MatA,1,&row,1,&col,&xp,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &col, &xp, INSERT_VALUES); // X - 1 col = row - (localmesh->LocalNz); - MatSetValues(it.MatA,1,&row,1,&col,&xm,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &col, &xm, INSERT_VALUES); // Z + 1 col = row + 1; if(z == localmesh->LocalNz-1) { col -= localmesh->LocalNz; // Wrap around } - MatSetValues(it.MatA,1,&row,1,&col,&zp,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &col, &zp, INSERT_VALUES); int xzcol = col + (localmesh->LocalNz); // X+1 - MatSetValues(it.MatA,1,&row,1,&xzcol,&xpzp,INSERT_VALUES); - MatSetValues(it.MatA,1,&row,1,&xzcol,&zpxp,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &xzcol, &xpzp, INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &xzcol, &zpxp, INSERT_VALUES); xzcol = col - (localmesh->LocalNz); // X-1 - MatSetValues(it.MatA,1,&row,1,&xzcol,&xmzp,INSERT_VALUES); - MatSetValues(it.MatA,1,&row,1,&xzcol,&zpxm,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &xzcol, &xmzp, INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &xzcol, &zpxm, INSERT_VALUES); // Z - 1 col = row - 1; if(z == 0) { col += localmesh->LocalNz; // Wrap around } - MatSetValues(it.MatA,1,&row,1,&col,&zm,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &col, &zm, INSERT_VALUES); xzcol = col + (localmesh->LocalNz); // X+1 - MatSetValues(it.MatA,1,&row,1,&xzcol,&xpzm,INSERT_VALUES); - MatSetValues(it.MatA,1,&row,1,&xzcol,&zmxp,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &xzcol, &xpzm, INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &xzcol, &zmxp, INSERT_VALUES); xzcol = col - (localmesh->LocalNz); // X-1 - MatSetValues(it.MatA,1,&row,1,&xzcol,&xmzm,INSERT_VALUES); - MatSetValues(it.MatA,1,&row,1,&xzcol,&zmxm,INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &xzcol, &xmzm, INSERT_VALUES); + MatSetValues(it.MatA, 1, &row, 1, &xzcol, &zmxm, INSERT_VALUES); row++; } diff --git a/src/invert/parderiv/impls/cyclic/cyclic.cxx b/src/invert/parderiv/impls/cyclic/cyclic.cxx index 6d90d5ed84..5f14122757 100644 --- a/src/invert/parderiv/impls/cyclic/cyclic.cxx +++ b/src/invert/parderiv/impls/cyclic/cyclic.cxx @@ -127,7 +127,7 @@ const Field3D InvertParCR::solve(const Field3D &f) { // Set up tridiagonal system for(int k=0; kLocalNy - 2 * localmesh->ystart; y++) { BoutReal acoef = A(x, y + localmesh->ystart); // Constant @@ -138,7 +138,8 @@ const Field3D InvertParCR::solve(const Field3D &f) { BoutReal ecoef = E(x, y + localmesh->ystart); // ddy bcoef /= SQ(coord->dy(x, y + localmesh->ystart)); - ccoef /= coord->dy(x, y + localmesh->ystart) * coord->dz(x, y + localmesh->ystart); + ccoef /= + coord->dy(x, y + localmesh->ystart) * coord->dz(x, y + localmesh->ystart); dcoef /= SQ(coord->dz(x, y + localmesh->ystart)); ecoef /= coord->dy(x, y + localmesh->ystart); @@ -159,14 +160,14 @@ const Field3D InvertParCR::solve(const Field3D &f) { bout::globals::mpi->MPI_Comm_size(surf.communicator(), &np); if(rank == 0) { for(int k=0; kLocalNy - 2 * localmesh->ystart - 1) *= phase; } @@ -217,5 +218,3 @@ const Field3D InvertParCR::solve(const Field3D &f) { return Field3D{}; #endif }; - - diff --git a/src/mesh/boundary_standard.cxx b/src/mesh/boundary_standard.cxx index ad96c68a82..86fd031f6f 100644 --- a/src/mesh/boundary_standard.cxx +++ b/src/mesh/boundary_standard.cxx @@ -1619,311 +1619,116 @@ void BoundaryNeumann_NonOrthogonal::apply(Field3D& f) { #ifdef COORDINATES_USE_3D for (int z = 0; z < mesh->LocalNz; z++) { #else - int z=0; + int z = 0; #endif - // Interpolate (linearly) metrics to halfway between last cell and boundary cell - BoutReal g11shift = - 0.5 - * (metric->g11(bndry->x, bndry->y, z) + metric->g11(bndry->x - bndry->bx, bndry->y, z)); - BoutReal g12shift = - 0.5 - * (metric->g12(bndry->x, bndry->y, z) + metric->g12(bndry->x - bndry->bx, bndry->y, z)); - BoutReal g13shift = - 0.5 - * (metric->g13(bndry->x, bndry->y, z) + metric->g13(bndry->x - bndry->bx, bndry->y, z)); - // Have to use derivatives at last gridpoint instead of derivatives on boundary layer - // because derivative values don't exist in boundary region - // NOTE: should be fixed to interpolate to boundary line + // Interpolate (linearly) metrics to halfway between last cell and boundary cell + BoutReal g11shift = 0.5 + * (metric->g11(bndry->x, bndry->y, z) + + metric->g11(bndry->x - bndry->bx, bndry->y, z)); + BoutReal g12shift = 0.5 + * (metric->g12(bndry->x, bndry->y, z) + + metric->g12(bndry->x - bndry->bx, bndry->y, z)); + BoutReal g13shift = 0.5 + * (metric->g13(bndry->x, bndry->y, z) + + metric->g13(bndry->x - bndry->bx, bndry->y, z)); + // Have to use derivatives at last gridpoint instead of derivatives on boundary + // layer + // because derivative values don't exist in boundary region + // NOTE: should be fixed to interpolate to boundary line #ifndef COORDINATES_USE_3D - for (int z = 0; z < mesh->LocalNz; z++) { + for (int z = 0; z < mesh->LocalNz; z++) { #endif - BoutReal xshift = g12shift * dfdy(bndry->x - bndry->bx, bndry->y, z) - + g13shift * dfdz(bndry->x - bndry->bx, bndry->y, z); - if (bndry->bx != 0 && bndry->by == 0) { - // x boundaries only - BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, z); - f(bndry->x, bndry->y, z) = - f(bndry->x - bndry->bx, bndry->y, z) + delta / g11shift * (val - xshift); - if (bndry->width == 2) { - f(bndry->x + bndry->bx, bndry->y, z) = - f(bndry->x - 2 * bndry->bx, bndry->y, z) - + 3.0 * delta / g11shift * (val - xshift); - } - } else if (bndry->by != 0 && bndry->bx == 0) { - // y boundaries only - // no need to shift this b/c we want parallel nuemann not theta - BoutReal delta = bndry->by * metric->dy(bndry->x, bndry->y, z); - f(bndry->x, bndry->y, z) = f(bndry->x, bndry->y - bndry->by, z) + delta * val; - if (bndry->width == 2) { - f(bndry->x, bndry->y + bndry->by, z) = - f(bndry->x, bndry->y - 2 * bndry->by, z) + 3.0 * delta * val; - } - } else { - // set corners to zero - f(bndry->x, bndry->y, z) = 0.0; - if (bndry->width == 2) { - f(bndry->x + bndry->bx, bndry->y + bndry->by, z) = 0.0; - } - } - } - } -} - -/////////////////////////////////////////////////////////////// - -BoundaryOp* BoundaryNeumann::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 1); - std::shared_ptr newgen = nullptr; - if (!args.empty()) { - // First argument should be an expression - newgen = FieldFactory::get()->parse(args.front()); - } - return new BoundaryNeumann(region, newgen); -} - -void BoundaryNeumann::apply(Field2D& f) { BoundaryNeumann::apply(f, 0.); } - -void BoundaryNeumann::apply(Field2D& f, BoutReal t) { - // Set (at 2nd order / 3rd order) the value at the mid-point between - // the guard cell and the grid cell to be val - // N.B. First guard cells (closest to the grid) is 2nd order, while - // 2nd is 3rd order - -#ifndef COORDINATES_USE_3D - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Coordinates* metric = f.getCoordinates(); - - bndry->first(); - - // Decide which generator to use - std::shared_ptr fg = gen; - if (!fg) - fg = f.getBndryGenerator(bndry->location); - - BoutReal val = 0.0; - - // Check for staggered grids - - CELL_LOC loc = f.getLocation(); - if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { - // Staggered. Need to apply slightly differently - // Use one-sided differencing. Cell is now on - // the boundary, so use one-sided differencing - - if (loc == CELL_XLOW) { - // Field is shifted in X - - if (bndry->bx > 0) { - // Outer x boundary - - for (; !bndry->isDone(); bndry->next1d()) { - - if (fg) { - val = fg->generate(Context(bndry, loc, t, mesh)) * metric->dx(bndry->x, bndry->y); - } - - f(bndry->x, bndry->y) = (4. * f(bndry->x - bndry->bx, bndry->y) - - f(bndry->x - 2 * bndry->bx, bndry->y) + 2. * val) - / 3.; - // Need to set second guard cell, as may be used for interpolation or upwinding - // derivatives - for (int i = 1; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - // Use third order extrapolation because boundary point is set to third order, - // and these points may be used be used by 2nd order upwinding type schemes, - // which require 3rd order - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); - } - } - } - if (bndry->bx < 0) { - // Inner x boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - - if (fg) { - val = fg->generate(Context(bndry, loc, t, mesh)) * metric->dx(bndry->x, bndry->y); - } - - f(bndry->x - bndry->bx, bndry->y) = - (4. * f(bndry->x - 2 * bndry->bx, bndry->y) - - f(bndry->x - 3 * bndry->bx, bndry->y) - 2. * val) - / 3.; - - // Need to set second guard cell, as may be used for interpolation or upwinding - // derivatives - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - // Use third order extrapolation because boundary point is set to third order, - // and these points may be used be used by 2nd order upwinding type schemes, - // which require 3rd order - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); - } - } - } - if (bndry->by != 0) { - // y boundaries - - for (bndry->first(); !bndry->isDone(); bndry->next1d()) { - BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) - + bndry->by * metric->dy(bndry->x, bndry->y); - - if (fg) { - val = fg->generate(Context(bndry, loc, t, mesh)); - } - - f(bndry->x, bndry->y) = - f(bndry->x - bndry->bx, bndry->y - bndry->by) + delta * val; + BoutReal xshift = g12shift * dfdy(bndry->x - bndry->bx, bndry->y, z) + + g13shift * dfdz(bndry->x - bndry->bx, bndry->y, z); + if (bndry->bx != 0 && bndry->by == 0) { + // x boundaries only + BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, z); + f(bndry->x, bndry->y, z) = + f(bndry->x - bndry->bx, bndry->y, z) + delta / g11shift * (val - xshift); if (bndry->width == 2) { - f(bndry->x + bndry->bx, bndry->y + bndry->by) = - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) + 3.0 * delta * val; - } - } - } - } else if (loc == CELL_YLOW) { - // Y boundary, and field is shifted in Y - - if (bndry->by > 0) { - // Outer y boundary - - for (; !bndry->isDone(); bndry->next1d()) { - if (fg) { - val = fg->generate(Context(bndry, loc, t, mesh)) * metric->dy(bndry->x, bndry->y); - } - f(bndry->x, bndry->y) = (4. * f(bndry->x, bndry->y - bndry->by) - - f(bndry->x, bndry->y - 2 * bndry->by) + 2. * val) - / 3.; - - // Need to set second guard cell, as may be used for interpolation or upwinding - // derivatives - for (int i = 1; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - // Use third order extrapolation because boundary point is set to third order, - // and these points may be used be used by 2nd order upwinding type schemes, - // which require 3rd order - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); - } - } - } - if (bndry->by < 0) { - // Inner y boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - - if (fg) { - val = fg->generate(Context(bndry, loc, t, mesh)) * metric->dy(bndry->x, bndry->y - bndry->by); - } - f(bndry->x, bndry->y - bndry->by) = - (4. * f(bndry->x, bndry->y - 2 * bndry->by) - - f(bndry->x, bndry->y - 3 * bndry->by) - 2. * val) - / 3.; - - // Need to set second guard cell, as may be used for interpolation or upwinding - // derivatives - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - // Use third order extrapolation because boundary point is set to third order, - // and these points may be used be used by 2nd order upwinding type schemes, - // which require 3rd order - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); - } - } - } - if (bndry->bx != 0) { - // x boundaries - for (bndry->first(); !bndry->isDone(); bndry->next1d()) { - BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) - + bndry->by * metric->dy(bndry->x, bndry->y); - - if (fg) { - val = fg->generate(Context(bndry, loc, t, mesh)); + f(bndry->x + bndry->bx, bndry->y, z) = + f(bndry->x - 2 * bndry->bx, bndry->y, z) + + 3.0 * delta / g11shift * (val - xshift); + } + } else if (bndry->by != 0 && bndry->bx == 0) { + // y boundaries only + // no need to shift this b/c we want parallel nuemann not theta + BoutReal delta = bndry->by * metric->dy(bndry->x, bndry->y, z); + f(bndry->x, bndry->y, z) = f(bndry->x, bndry->y - bndry->by, z) + delta * val; + if (bndry->width == 2) { + f(bndry->x, bndry->y + bndry->by, z) = + f(bndry->x, bndry->y - 2 * bndry->by, z) + 3.0 * delta * val; } - - f(bndry->x, bndry->y) = - f(bndry->x - bndry->bx, bndry->y - bndry->by) + delta * val; + } else { + // set corners to zero + f(bndry->x, bndry->y, z) = 0.0; if (bndry->width == 2) { - f(bndry->x + bndry->bx, bndry->y + bndry->by) = - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) + 3.0 * delta * val; + f(bndry->x + bndry->bx, bndry->y + bndry->by, z) = 0.0; } } } } - } else { - // Non-staggered, standard case - - for (bndry->first(); !bndry->isDone(); bndry->next1d()) { - BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) - + bndry->by * metric->dy(bndry->x, bndry->y); + } - if (fg) { - val = fg->generate(Context(bndry, loc, t, mesh)); - } + /////////////////////////////////////////////////////////////// - f(bndry->x, bndry->y) = f(bndry->x - bndry->bx, bndry->y - bndry->by) + delta * val; - if (bndry->width == 2) { - f(bndry->x + bndry->bx, bndry->y + bndry->by) = - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) + 3.0 * delta * val; - } + BoundaryOp* BoundaryNeumann::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 1); + std::shared_ptr newgen = nullptr; + if (!args.empty()) { + // First argument should be an expression + newgen = FieldFactory::get()->parse(args.front()); } + return new BoundaryNeumann(region, newgen); } -#else - throw BoutException( - "Applying boundary to Field2D not compatible with 3D metrics in all cases."); -#endif -} -void BoundaryNeumann::apply(Field3D& f) { BoundaryNeumann::apply(f, 0.); } + void BoundaryNeumann::apply(Field2D & f) { BoundaryNeumann::apply(f, 0.); } -void BoundaryNeumann::apply(Field3D& f, BoutReal t) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Coordinates* metric = f.getCoordinates(); + void BoundaryNeumann::apply(Field2D & f, BoutReal t) { + // Set (at 2nd order / 3rd order) the value at the mid-point between + // the guard cell and the grid cell to be val + // N.B. First guard cells (closest to the grid) is 2nd order, while + // 2nd is 3rd order - bndry->first(); +#ifndef COORDINATES_USE_3D + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Coordinates* metric = f.getCoordinates(); - // Decide which generator to use - std::shared_ptr fg = gen; - if (!fg) - fg = f.getBndryGenerator(bndry->location); + bndry->first(); - BoutReal val = 0.0; + // Decide which generator to use + std::shared_ptr fg = gen; + if (!fg) + fg = f.getBndryGenerator(bndry->location); - // Check for staggered grids + BoutReal val = 0.0; - CELL_LOC loc = f.getLocation(); - if (mesh->StaggerGrids && loc != CELL_CENTRE) { - // Staggered. Need to apply slightly differently - // Use one-sided differencing. Cell is now on - // the boundary, so use one-sided differencing + // Check for staggered grids - if (loc == CELL_XLOW) { - // Field is shifted in X + CELL_LOC loc = f.getLocation(); + if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { + // Staggered. Need to apply slightly differently + // Use one-sided differencing. Cell is now on + // the boundary, so use one-sided differencing + + if (loc == CELL_XLOW) { + // Field is shifted in X + + if (bndry->bx > 0) { + // Outer x boundary + + for (; !bndry->isDone(); bndry->next1d()) { - if (bndry->bx > 0) { - // Outer x boundary - for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { if (fg) { - val = fg->generate(Context(bndry, zk, loc, t, mesh)) * metric->dx(bndry->x, bndry->y, zk); + val = fg->generate(Context(bndry, loc, t, mesh)) + * metric->dx(bndry->x, bndry->y); } - f(bndry->x, bndry->y, zk) = - (4. * f(bndry->x - bndry->bx, bndry->y, zk) - - f(bndry->x - 2 * bndry->bx, bndry->y, zk) + 2. * val) - / 3.; - + f(bndry->x, bndry->y) = (4. * f(bndry->x - bndry->bx, bndry->y) + - f(bndry->x - 2 * bndry->bx, bndry->y) + 2. * val) + / 3.; // Need to set second guard cell, as may be used for interpolation or // upwinding derivatives for (int i = 1; i < bndry->width; i++) { @@ -1932,24 +1737,24 @@ void BoundaryNeumann::apply(Field3D& f, BoutReal t) { // Use third order extrapolation because boundary point is set to third // order, and these points may be used be used by 2nd order upwinding type // schemes, which require 3rd order - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } - } - if (bndry->bx < 0) { - // Inner x boundary - for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->bx < 0) { + // Inner x boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { + if (fg) { - val = fg->generate(Context(bndry, zk, loc, t, mesh)) * metric->dx(bndry->x - bndry->bx, bndry->y, zk); + val = fg->generate(Context(bndry, loc, t, mesh)) + * metric->dx(bndry->x, bndry->y); } - f(bndry->x - bndry->bx, bndry->y, zk) = - (4. * f(bndry->x - 2 * bndry->bx, bndry->y, zk) - - f(bndry->x - 3 * bndry->bx, bndry->y, zk) - 2. * val) + f(bndry->x - bndry->bx, bndry->y) = + (4. * f(bndry->x - 2 * bndry->bx, bndry->y) + - f(bndry->x - 3 * bndry->bx, bndry->y) - 2. * val) / 3.; // Need to set second guard cell, as may be used for interpolation or @@ -1960,51 +1765,46 @@ void BoundaryNeumann::apply(Field3D& f, BoutReal t) { // Use third order extrapolation because boundary point is set to third // order, and these points may be used be used by 2nd order upwinding type // schemes, which require 3rd order - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } - } - if (bndry->by != 0) { - for (; !bndry->isDone(); bndry->next1d()) { -#ifndef COORDINATES_USE_3D - BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) - + bndry->by * metric->dy(bndry->x, bndry->y); -#endif - for (int zk = 0; zk < mesh->LocalNz; zk++) { -#ifdef COORDINATES_USE_3D - BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, zk) - + bndry->by * metric->dy(bndry->x, bndry->y, zk); -#endif + if (bndry->by != 0) { + // y boundaries + + for (bndry->first(); !bndry->isDone(); bndry->next1d()) { + BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) + + bndry->by * metric->dy(bndry->x, bndry->y); + if (fg) { - val = fg->generate(Context(bndry, zk, loc, t, mesh)); + val = fg->generate(Context(bndry, loc, t, mesh)); } - f(bndry->x, bndry->y, zk) = - f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + delta * val; + + f(bndry->x, bndry->y) = + f(bndry->x - bndry->bx, bndry->y - bndry->by) + delta * val; if (bndry->width == 2) { - f(bndry->x + bndry->bx, bndry->y + bndry->by, zk) = - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zk) + f(bndry->x + bndry->bx, bndry->y + bndry->by) = + f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) + 3.0 * delta * val; } } } - } - } else if (loc == CELL_YLOW) { - // Field is shifted in Y + } else if (loc == CELL_YLOW) { + // Y boundary, and field is shifted in Y - if (bndry->by > 0) { - // Outer y boundary - for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->by > 0) { + // Outer y boundary + + for (; !bndry->isDone(); bndry->next1d()) { if (fg) { - val = fg->generate(Context(bndry, zk, loc, t, mesh)) * metric->dy(bndry->x, bndry->y, zk); + val = fg->generate(Context(bndry, loc, t, mesh)) + * metric->dy(bndry->x, bndry->y); } - f(bndry->x, bndry->y, zk) = - (4. * f(bndry->x, bndry->y - bndry->by, zk) - - f(bndry->x, bndry->y - 2 * bndry->by, zk) + 2. * val) - / 3.; + f(bndry->x, bndry->y) = (4. * f(bndry->x, bndry->y - bndry->by) + - f(bndry->x, bndry->y - 2 * bndry->by) + 2. * val) + / 3.; // Need to set second guard cell, as may be used for interpolation or // upwinding derivatives @@ -2014,24 +1814,23 @@ void BoundaryNeumann::apply(Field3D& f, BoutReal t) { // Use third order extrapolation because boundary point is set to third // order, and these points may be used be used by 2nd order upwinding type // schemes, which require 3rd order - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } - } - if (bndry->by < 0) { - // Inner y boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->by < 0) { + // Inner y boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { + if (fg) { - val = fg->generate(Context(bndry, zk, loc, t, mesh)) * metric->dy(bndry->x, bndry->y - bndry->by, zk); + val = fg->generate(Context(bndry, loc, t, mesh)) + * metric->dy(bndry->x, bndry->y - bndry->by); } - - f(bndry->x, bndry->y - bndry->by, zk) = - (4. * f(bndry->x, bndry->y - 2 * bndry->by, zk) - - f(bndry->x, bndry->y - 3 * bndry->by, zk) - 2. * val) + f(bndry->x, bndry->y - bndry->by) = + (4. * f(bndry->x, bndry->y - 2 * bndry->by) + - f(bndry->x, bndry->y - 3 * bndry->by) - 2. * val) / 3.; // Need to set second guard cell, as may be used for interpolation or @@ -2042,28 +1841,271 @@ void BoundaryNeumann::apply(Field3D& f, BoutReal t) { // Use third order extrapolation because boundary point is set to third // order, and these points may be used be used by 2nd order upwinding type // schemes, which require 3rd order - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); + } + } + } + if (bndry->bx != 0) { + // x boundaries + for (bndry->first(); !bndry->isDone(); bndry->next1d()) { + BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) + + bndry->by * metric->dy(bndry->x, bndry->y); + + if (fg) { + val = fg->generate(Context(bndry, loc, t, mesh)); + } + + f(bndry->x, bndry->y) = + f(bndry->x - bndry->bx, bndry->y - bndry->by) + delta * val; + if (bndry->width == 2) { + f(bndry->x + bndry->bx, bndry->y + bndry->by) = + f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) + + 3.0 * delta * val; } } } } - if (bndry->bx != 0) { - // x boundaries. - for (; !bndry->isDone(); bndry->next1d()) { + } else { + // Non-staggered, standard case + + for (bndry->first(); !bndry->isDone(); bndry->next1d()) { + BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) + + bndry->by * metric->dy(bndry->x, bndry->y); + + if (fg) { + val = fg->generate(Context(bndry, loc, t, mesh)); + } + + f(bndry->x, bndry->y) = + f(bndry->x - bndry->bx, bndry->y - bndry->by) + delta * val; + if (bndry->width == 2) { + f(bndry->x + bndry->bx, bndry->y + bndry->by) = + f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) + 3.0 * delta * val; + } + } + } +#else + throw BoutException( + "Applying boundary to Field2D not compatible with 3D metrics in all cases."); +#endif + } + + void BoundaryNeumann::apply(Field3D & f) { BoundaryNeumann::apply(f, 0.); } + + void BoundaryNeumann::apply(Field3D & f, BoutReal t) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Coordinates* metric = f.getCoordinates(); + + bndry->first(); + + // Decide which generator to use + std::shared_ptr fg = gen; + if (!fg) + fg = f.getBndryGenerator(bndry->location); + + BoutReal val = 0.0; + + // Check for staggered grids + + CELL_LOC loc = f.getLocation(); + if (mesh->StaggerGrids && loc != CELL_CENTRE) { + // Staggered. Need to apply slightly differently + // Use one-sided differencing. Cell is now on + // the boundary, so use one-sided differencing + + if (loc == CELL_XLOW) { + // Field is shifted in X + + if (bndry->bx > 0) { + // Outer x boundary + for (; !bndry->isDone(); bndry->next1d()) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (fg) { + val = fg->generate(Context(bndry, zk, loc, t, mesh)) + * metric->dx(bndry->x, bndry->y, zk); + } + + f(bndry->x, bndry->y, zk) = + (4. * f(bndry->x - bndry->bx, bndry->y, zk) + - f(bndry->x - 2 * bndry->bx, bndry->y, zk) + 2. * val) + / 3.; + + // Need to set second guard cell, as may be used for interpolation or + // upwinding derivatives + for (int i = 1; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + // Use third order extrapolation because boundary point is set to third + // order, and these points may be used be used by 2nd order upwinding type + // schemes, which require 3rd order + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + if (bndry->bx < 0) { + // Inner x boundary + for (; !bndry->isDone(); bndry->next1d()) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (fg) { + val = fg->generate(Context(bndry, zk, loc, t, mesh)) + * metric->dx(bndry->x - bndry->bx, bndry->y, zk); + } + + f(bndry->x - bndry->bx, bndry->y, zk) = + (4. * f(bndry->x - 2 * bndry->bx, bndry->y, zk) + - f(bndry->x - 3 * bndry->bx, bndry->y, zk) - 2. * val) + / 3.; + + // Need to set second guard cell, as may be used for interpolation or + // upwinding derivatives + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + // Use third order extrapolation because boundary point is set to third + // order, and these points may be used be used by 2nd order upwinding type + // schemes, which require 3rd order + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + if (bndry->by != 0) { + for (; !bndry->isDone(); bndry->next1d()) { #ifndef COORDINATES_USE_3D - int zk=0; - BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, zk) - + bndry->by * metric->dy(bndry->x, bndry->y, zk); + BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) + + bndry->by * metric->dy(bndry->x, bndry->y); #endif - for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { #ifdef COORDINATES_USE_3D - BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, zk) - + bndry->by * metric->dy(bndry->x, bndry->y, zk); + BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, zk) + + bndry->by * metric->dy(bndry->x, bndry->y, zk); +#endif + if (fg) { + val = fg->generate(Context(bndry, zk, loc, t, mesh)); + } + f(bndry->x, bndry->y, zk) = + f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + delta * val; + if (bndry->width == 2) { + f(bndry->x + bndry->bx, bndry->y + bndry->by, zk) = + f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zk) + + 3.0 * delta * val; + } + } + } + } + } else if (loc == CELL_YLOW) { + // Field is shifted in Y + + if (bndry->by > 0) { + // Outer y boundary + for (; !bndry->isDone(); bndry->next1d()) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (fg) { + val = fg->generate(Context(bndry, zk, loc, t, mesh)) + * metric->dy(bndry->x, bndry->y, zk); + } + f(bndry->x, bndry->y, zk) = + (4. * f(bndry->x, bndry->y - bndry->by, zk) + - f(bndry->x, bndry->y - 2 * bndry->by, zk) + 2. * val) + / 3.; + + // Need to set second guard cell, as may be used for interpolation or + // upwinding derivatives + for (int i = 1; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + // Use third order extrapolation because boundary point is set to third + // order, and these points may be used be used by 2nd order upwinding type + // schemes, which require 3rd order + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + if (bndry->by < 0) { + // Inner y boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (fg) { + val = fg->generate(Context(bndry, zk, loc, t, mesh)) + * metric->dy(bndry->x, bndry->y - bndry->by, zk); + } + + f(bndry->x, bndry->y - bndry->by, zk) = + (4. * f(bndry->x, bndry->y - 2 * bndry->by, zk) + - f(bndry->x, bndry->y - 3 * bndry->by, zk) - 2. * val) + / 3.; + + // Need to set second guard cell, as may be used for interpolation or + // upwinding derivatives + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + // Use third order extrapolation because boundary point is set to third + // order, and these points may be used be used by 2nd order upwinding type + // schemes, which require 3rd order + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + if (bndry->bx != 0) { + // x boundaries. + for (; !bndry->isDone(); bndry->next1d()) { +#ifndef COORDINATES_USE_3D + int zk = 0; + BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, zk) + + bndry->by * metric->dy(bndry->x, bndry->y, zk); +#endif + for (int zk = 0; zk < mesh->LocalNz; zk++) { +#ifdef COORDINATES_USE_3D + BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y, zk) + + bndry->by * metric->dy(bndry->x, bndry->y, zk); #endif + if (fg) { + val = fg->generate(Context(bndry, zk, loc, t, mesh)); + } + f(bndry->x, bndry->y, zk) = + f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + delta * val; + if (bndry->width == 2) { + f(bndry->x + bndry->bx, bndry->y + bndry->by, zk) = + f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zk) + + 3.0 * delta * val; + } + } + } + } + } else if (loc == CELL_ZLOW) { + // 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 + + BoutReal ynorm = 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(Context(bndry, zk, loc, t, mesh)); + val = fg->generate(xnorm, TWOPI * ynorm, + TWOPI * (zk - 0.5) / (mesh->LocalNz), t); } f(bndry->x, bndry->y, zk) = f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + delta * val; @@ -2074,1568 +2116,1571 @@ void BoundaryNeumann::apply(Field3D& f, BoutReal t) { } } } - } - } else if (loc == CELL_ZLOW) { - // 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 - - BoutReal ynorm = 0.5*( mesh->GlobalY(bndry->y) // In the guard cell - + mesh->GlobalY(bndry->y - bndry->by) ); // the grid cell - - - for(int zk=0;zkLocalNz;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); - } - f(bndry->x,bndry->y, zk) = f(bndry->x-bndry->bx, bndry->y-bndry->by, zk) + delta*val; - if (bndry->width == 2){ - f(bndry->x + bndry->bx, bndry->y + bndry->by, zk) = f(bndry->x - 2*bndry->bx, bndry->y - 2*bndry->by, zk) + 3.0*delta*val; - } - } + } else { + throw BoutException("Unrecognized location"); } } else { - throw BoutException("Unrecognized location"); - } - } else { - for (; !bndry->isDone(); bndry->next1d()) { + for (; !bndry->isDone(); bndry->next1d()) { #ifdef COORDINATES_USE_3D - 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); + 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); #else BoutReal delta = bndry->bx * metric->dx(bndry->x, bndry->y) - + bndry->by * metric->dy(bndry->x, bndry->y); + + bndry->by * metric->dy(bndry->x, bndry->y); for (int zk = 0; zk < mesh->LocalNz; zk++) { #endif - if (fg) { - val = fg->generate(Context(bndry, zk, loc, t, mesh)); - } - f(bndry->x, bndry->y, zk) = - f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + delta * val; - if (bndry->width == 2) { - f(bndry->x + bndry->bx, bndry->y + bndry->by, zk) = - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zk) - + 3.0 * delta * val; + if (fg) { + val = fg->generate(Context(bndry, zk, loc, t, mesh)); + } + f(bndry->x, bndry->y, zk) = + f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + delta * val; + if (bndry->width == 2) { + f(bndry->x + bndry->bx, bndry->y + bndry->by, zk) = + f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zk) + + 3.0 * delta * val; + } } } } } -} -void BoundaryNeumann::apply_ddt(Field2D& f) { - Field2D* dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero -} + void BoundaryNeumann::apply_ddt(Field2D & f) { + Field2D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero + } -void BoundaryNeumann::apply_ddt(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Field3D* dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0; z < mesh->LocalNz; z++) - (*dt)(bndry->x, bndry->y, z) = 0.; // Set time derivative to zero -} + void BoundaryNeumann::apply_ddt(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Field3D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) + (*dt)(bndry->x, bndry->y, z) = 0.; // Set time derivative to zero + } -/////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryNeumann_O4::clone(BoundaryRegion* region, - const std::list& args) { - std::shared_ptr newgen = nullptr; - if (!args.empty()) { - // First argument should be an expression - newgen = FieldFactory::get()->parse(args.front()); + BoundaryOp* BoundaryNeumann_O4::clone(BoundaryRegion * region, + const std::list& args) { + std::shared_ptr newgen = nullptr; + if (!args.empty()) { + // First argument should be an expression + newgen = FieldFactory::get()->parse(args.front()); + } + return new BoundaryNeumann_O4(region, newgen); } - return new BoundaryNeumann_O4(region, newgen); -} -void BoundaryNeumann_O4::apply(Field2D& f) { BoundaryNeumann_O4::apply(f, 0.); } + void BoundaryNeumann_O4::apply(Field2D & f) { BoundaryNeumann_O4::apply(f, 0.); } -void BoundaryNeumann_O4::apply(Field2D& f, BoutReal t) { + void BoundaryNeumann_O4::apply(Field2D & f, BoutReal t) { #ifndef COORDINATES_USE_3D - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); - // Set (at 4th order) the value at the mid-point between the guard cell and the grid - // cell to be val N.B. Only first guard cells (closest to the grid) should ever be used - bndry->first(); + // Set (at 4th order) the value at the mid-point between the guard cell and the grid + // cell to be val N.B. Only first guard cells (closest to the grid) should ever be + // used + bndry->first(); - // Decide which generator to use - std::shared_ptr fg = gen; - if (!fg) - fg = f.getBndryGenerator(bndry->location); + // Decide which generator to use + std::shared_ptr fg = gen; + if (!fg) + fg = f.getBndryGenerator(bndry->location); - BoutReal val = 0.0; + BoutReal val = 0.0; - // Check for staggered grids - CELL_LOC loc = f.getLocation(); - if (mesh->StaggerGrids && loc != CELL_CENTRE) { - throw BoutException("neumann_o4 not implemented with staggered grid yet"); - } else { - // Non-staggered, standard case + // Check for staggered grids + CELL_LOC loc = f.getLocation(); + if (mesh->StaggerGrids && loc != CELL_CENTRE) { + throw BoutException("neumann_o4 not implemented with staggered grid yet"); + } else { + // Non-staggered, standard case - Coordinates* coords = f.getCoordinates(); + Coordinates* coords = f.getCoordinates(); - for (bndry->first(); !bndry->isDone(); bndry->next1d()) { - BoutReal delta = bndry->bx * coords->dx(bndry->x, bndry->y) - + bndry->by * coords->dy(bndry->x, bndry->y); + for (bndry->first(); !bndry->isDone(); bndry->next1d()) { + BoutReal delta = bndry->bx * coords->dx(bndry->x, bndry->y) + + bndry->by * coords->dy(bndry->x, bndry->y); - if (fg) { - val = fg->generate(Context(bndry, loc, t, mesh)); - } + if (fg) { + val = fg->generate(Context(bndry, loc, t, mesh)); + } - f(bndry->x, bndry->y) = - 12. * delta * val / 11. - + (+17. * f(bndry->x - bndry->bx, bndry->y - bndry->by) - + 9. * f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) - - 5. * f(bndry->x - 3 * bndry->bx, bndry->y - 3 * bndry->by) - + f(bndry->x - 4 * bndry->bx, bndry->y - 4 * bndry->by)) - / 22.; + f(bndry->x, bndry->y) = + 12. * delta * val / 11. + + (+17. * f(bndry->x - bndry->bx, bndry->y - bndry->by) + + 9. * f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) + - 5. * f(bndry->x - 3 * bndry->bx, bndry->y - 3 * bndry->by) + + f(bndry->x - 4 * bndry->bx, bndry->y - 4 * bndry->by)) + / 22.; - if (bndry->width == 2) { - throw BoutException("neumann_o4 with a boundary width of 2 not implemented yet"); + if (bndry->width == 2) { + throw BoutException( + "neumann_o4 with a boundary width of 2 not implemented yet"); + } } } - } #else throw BoutException( "Applying boundary to Field2D not compatible with 3D metrics in all cases."); #endif -} + } -void BoundaryNeumann_O4::apply(Field3D& f) { BoundaryNeumann_O4::apply(f, 0.); } + void BoundaryNeumann_O4::apply(Field3D & f) { BoundaryNeumann_O4::apply(f, 0.); } -void BoundaryNeumann_O4::apply(Field3D& f, BoutReal t) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - bndry->first(); + void BoundaryNeumann_O4::apply(Field3D & f, BoutReal t) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + bndry->first(); - // Decide which generator to use - std::shared_ptr fg = gen; - if (!fg) - fg = f.getBndryGenerator(bndry->location); + // Decide which generator to use + std::shared_ptr fg = gen; + if (!fg) + fg = f.getBndryGenerator(bndry->location); - BoutReal val = 0.0; + BoutReal val = 0.0; - // Check for staggered grids - CELL_LOC loc = f.getLocation(); - if (mesh->StaggerGrids && loc != CELL_CENTRE) { - throw BoutException("neumann_o4 not implemented with staggered grid yet"); - } else { - Coordinates* coords = f.getCoordinates(); - for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { - BoutReal delta = bndry->bx * coords->dx(bndry->x, bndry->y, zk) - + bndry->by * coords->dy(bndry->x, bndry->y, zk); - if (fg) { - val = fg->generate(Context(bndry, zk, loc, t, mesh)); - } + // Check for staggered grids + CELL_LOC loc = f.getLocation(); + if (mesh->StaggerGrids && loc != CELL_CENTRE) { + throw BoutException("neumann_o4 not implemented with staggered grid yet"); + } else { + Coordinates* coords = f.getCoordinates(); + for (; !bndry->isDone(); bndry->next1d()) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { + BoutReal delta = bndry->bx * coords->dx(bndry->x, bndry->y, zk) + + bndry->by * coords->dy(bndry->x, bndry->y, zk); + if (fg) { + val = fg->generate(Context(bndry, zk, loc, t, mesh)); + } - f(bndry->x, bndry->y, zk) = - 12. * delta * val / 11. - + (+17. * f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) - + 9. * f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zk) - - 5. * f(bndry->x - 3 * bndry->bx, bndry->y - 3 * bndry->by, zk) - + f(bndry->x - 4 * bndry->bx, bndry->y - 4 * bndry->by, zk)) - / 22.; + f(bndry->x, bndry->y, zk) = + 12. * delta * val / 11. + + (+17. * f(bndry->x - bndry->bx, bndry->y - bndry->by, zk) + + 9. * f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zk) + - 5. * f(bndry->x - 3 * bndry->bx, bndry->y - 3 * bndry->by, zk) + + f(bndry->x - 4 * bndry->bx, bndry->y - 4 * bndry->by, zk)) + / 22.; - if (bndry->width == 2) { - throw BoutException( - "neumann_o4 with a boundary width of 2 not implemented yet"); + if (bndry->width == 2) { + throw BoutException( + "neumann_o4 with a boundary width of 2 not implemented yet"); + } } } } } -} -void BoundaryNeumann_O4::apply_ddt(Field2D& f) { - Field2D* dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero -} + void BoundaryNeumann_O4::apply_ddt(Field2D & f) { + Field2D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero + } -void BoundaryNeumann_O4::apply_ddt(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Field3D *dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0; z < mesh->LocalNz; z++) - (*dt)(bndry->x, bndry->y, z) = 0.; // Set time derivative to zero -} + void BoundaryNeumann_O4::apply_ddt(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Field3D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) + (*dt)(bndry->x, bndry->y, z) = 0.; // Set time derivative to zero + } -/////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryNeumann_4thOrder::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 4); - if (!args.empty()) { - // First argument should be a value - val = stringToReal(args.front()); - return new BoundaryNeumann_4thOrder(region, val); + BoundaryOp* BoundaryNeumann_4thOrder::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 4); + if (!args.empty()) { + // First argument should be a value + val = stringToReal(args.front()); + return new BoundaryNeumann_4thOrder(region, val); + } + return new BoundaryNeumann_4thOrder(region); } - return new BoundaryNeumann_4thOrder(region); -} -void BoundaryNeumann_4thOrder::apply(Field2D& f) { + void BoundaryNeumann_4thOrder::apply(Field2D & f) { #ifndef COORDINATES_USE_3D - Coordinates* metric = f.getCoordinates(); - // Set (at 4th order) the gradient at the mid-point between the guard cell and the grid - // cell to be val This sets the value of the co-ordinate derivative, i.e. DDX/DDY not - // Grad_par/Grad_perp.x - for (bndry->first(); !bndry->isDone(); bndry->next1d()) { - BoutReal delta = -(bndry->bx * metric->dx(bndry->x, bndry->y) - + bndry->by * metric->dy(bndry->x, bndry->y)); - f(bndry->x, bndry->y) = - 12. * delta / 11. * val - + 17. / 22. * f(bndry->x - bndry->bx, bndry->y - bndry->by) - + 9. / 22. * f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) - - 5. / 22. * f(bndry->x - 3 * bndry->bx, bndry->y - 3 * bndry->by) - + 1. / 22. * f(bndry->x - 4 * bndry->bx, bndry->y - 4 * bndry->by); - f(bndry->x + bndry->bx, bndry->y + bndry->by) = - -24. * delta * val + 27. * f(bndry->x, bndry->y) - - 27. * f(bndry->x - bndry->bx, bndry->y - bndry->by) - + f(bndry->x - 2 * bndry->bx, - bndry->y - - 2 * bndry->by); // The f(bndry->x-4*bndry->bx,bndry->y-4*bndry->by) term - // vanishes, so that this sets to zero the 4th order - // central difference first derivative at the point half - // way between the guard cell and the grid cell - } + Coordinates* metric = f.getCoordinates(); + // Set (at 4th order) the gradient at the mid-point between the guard cell and the + // grid cell to be val This sets the value of the co-ordinate derivative, i.e. DDX/DDY + // not Grad_par/Grad_perp.x + for (bndry->first(); !bndry->isDone(); bndry->next1d()) { + BoutReal delta = -(bndry->bx * metric->dx(bndry->x, bndry->y) + + bndry->by * metric->dy(bndry->x, bndry->y)); + f(bndry->x, bndry->y) = + 12. * delta / 11. * val + + 17. / 22. * f(bndry->x - bndry->bx, bndry->y - bndry->by) + + 9. / 22. * f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by) + - 5. / 22. * f(bndry->x - 3 * bndry->bx, bndry->y - 3 * bndry->by) + + 1. / 22. * f(bndry->x - 4 * bndry->bx, bndry->y - 4 * bndry->by); + f(bndry->x + bndry->bx, bndry->y + bndry->by) = + -24. * delta * val + 27. * f(bndry->x, bndry->y) + - 27. * f(bndry->x - bndry->bx, bndry->y - bndry->by) + + f(bndry->x - 2 * bndry->bx, + bndry->y + - 2 * bndry->by); // The f(bndry->x-4*bndry->bx,bndry->y-4*bndry->by) + // term vanishes, so that this sets to zero the 4th + // order central difference first derivative at the + // point half way between the guard cell and the grid + // cell + } #else - throw BoutException("void BoundaryNeumann_4thOrder::apply(Field2D& f) not implemented with 3D metrics"); + throw BoutException( + "void BoundaryNeumann_4thOrder::apply(Field2D& f) not implemented with 3D metrics"); #endif -} - -void BoundaryNeumann_4thOrder::apply(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Coordinates *metric = f.getCoordinates(); - // Set (at 4th order) the gradient at the mid-point between the guard cell and the grid cell to be val - // This sets the value of the co-ordinate derivative, i.e. DDX/DDY not Grad_par/Grad_perp.x - for (bndry->first(); !bndry->isDone(); bndry->next1d()) - for (int z = 0;z < mesh->LocalNz; z++) { - BoutReal delta = -(bndry->bx*metric->dx(bndry->x,bndry->y, z)+bndry->by*metric->dy(bndry->x,bndry->y, z)); - f(bndry->x,bndry->y,z) = 12.*delta/11.*val + 17./22.*f(bndry->x-bndry->bx,bndry->y-bndry->by,z) + 9./22.*f(bndry->x-2*bndry->bx,bndry->y-2*bndry->by,z) - 5./22.*f(bndry->x-3*bndry->bx,bndry->y-3*bndry->by,z) + 1./22.*f(bndry->x-4*bndry->bx,bndry->y-4*bndry->by,z); - f(bndry->x+bndry->bx,bndry->y+bndry->by,z) = -24.*delta*val + 27.*f(bndry->x,bndry->y,z) - 27.*f(bndry->x-bndry->bx,bndry->y-bndry->by,z) + f(bndry->x-2*bndry->bx,bndry->y-2*bndry->by,z); // The f(bndry->x-4*bndry->bx,bndry->y-4*bndry->by,z) term vanishes, so that this sets to zero the 4th order central difference first derivative at the point half way between the guard cell and the grid cell - } -} + } -void BoundaryNeumann_4thOrder::apply_ddt(Field2D& f) { - Field2D* dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero -} + void BoundaryNeumann_4thOrder::apply(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Coordinates* metric = f.getCoordinates(); + // Set (at 4th order) the gradient at the mid-point between the guard cell and the + // grid cell to be val This sets the value of the co-ordinate derivative, i.e. DDX/DDY + // not Grad_par/Grad_perp.x + for (bndry->first(); !bndry->isDone(); bndry->next1d()) + for (int z = 0; z < mesh->LocalNz; z++) { + BoutReal delta = -(bndry->bx * metric->dx(bndry->x, bndry->y, z) + + bndry->by * metric->dy(bndry->x, bndry->y, z)); + f(bndry->x, bndry->y, z) = + 12. * delta / 11. * val + + 17. / 22. * f(bndry->x - bndry->bx, bndry->y - bndry->by, z) + + 9. / 22. * f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, z) + - 5. / 22. * f(bndry->x - 3 * bndry->bx, bndry->y - 3 * bndry->by, z) + + 1. / 22. * f(bndry->x - 4 * bndry->bx, bndry->y - 4 * bndry->by, z); + f(bndry->x + bndry->bx, bndry->y + bndry->by, z) = + -24. * delta * val + 27. * f(bndry->x, bndry->y, z) + - 27. * f(bndry->x - bndry->bx, bndry->y - bndry->by, z) + + f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, + z); // The f(bndry->x-4*bndry->bx,bndry->y-4*bndry->by,z) term vanishes, + // so that this sets to zero the 4th order central difference first + // derivative at the point half way between the guard cell and the + // grid cell + } + } + + void BoundaryNeumann_4thOrder::apply_ddt(Field2D & f) { + Field2D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero + } -void BoundaryNeumann_4thOrder::apply_ddt(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Field3D *dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0;z < mesh->LocalNz; z++) - (*dt)(bndry->x,bndry->y,z) = 0.; // Set time derivative to zero -} + void BoundaryNeumann_4thOrder::apply_ddt(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Field3D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) + (*dt)(bndry->x, bndry->y, z) = 0.; // Set time derivative to zero + } -/////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryNeumannPar::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 1); - if (!args.empty()) { - output << "WARNING: Ignoring arguments to BoundaryNeumann2\n"; + BoundaryOp* BoundaryNeumannPar::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 1); + if (!args.empty()) { + output << "WARNING: Ignoring arguments to BoundaryNeumann2\n"; + } + return new BoundaryNeumannPar(region); } - return new BoundaryNeumannPar(region); -} -void BoundaryNeumannPar::apply(Field2D& f) { + void BoundaryNeumannPar::apply(Field2D & f) { #ifndef COORDINATES_USE_3D - Coordinates* metric = f.getCoordinates(); - // Loop over all elements and set equal to the next point in - for (bndry->first(); !bndry->isDone(); bndry->next()) - f(bndry->x, bndry->y) = - f(bndry->x - bndry->bx, bndry->y - bndry->by) - * sqrt(metric->g_22(bndry->x, bndry->y) - / metric->g_22(bndry->x - bndry->bx, bndry->y - bndry->by)); + Coordinates* metric = f.getCoordinates(); + // Loop over all elements and set equal to the next point in + for (bndry->first(); !bndry->isDone(); bndry->next()) + f(bndry->x, bndry->y) = + f(bndry->x - bndry->bx, bndry->y - bndry->by) + * sqrt(metric->g_22(bndry->x, bndry->y) + / metric->g_22(bndry->x - bndry->bx, bndry->y - bndry->by)); #else throw BoutException( - "Applying boundary to Field2D not compatible with 3D metrics in all cases."); + "Applying boundary to Field2D not compatible with 3D metrics in all cases."); #endif -} - -void BoundaryNeumannPar::apply(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Coordinates *metric = f.getCoordinates(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0;z < mesh->LocalNz; z++) - f(bndry->x,bndry->y,z) = f(bndry->x - bndry->bx,bndry->y - bndry->by,z)*sqrt(metric->g_22(bndry->x, bndry->y, z)/metric->g_22(bndry->x - bndry->bx, bndry->y - bndry->by,z)); -} + } -/////////////////////////////////////////////////////////////// + void BoundaryNeumannPar::apply(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Coordinates* metric = f.getCoordinates(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) + f(bndry->x, bndry->y, z) = + f(bndry->x - bndry->bx, bndry->y - bndry->by, z) + * sqrt(metric->g_22(bndry->x, bndry->y, z) + / metric->g_22(bndry->x - bndry->bx, bndry->y - bndry->by, z)); + } -BoundaryOp* BoundaryRobin::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 1); - BoutReal a = 0.5, b = 1.0, g = 0.; + /////////////////////////////////////////////////////////////// - auto it = args.begin(); + BoundaryOp* BoundaryRobin::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 1); + BoutReal a = 0.5, b = 1.0, g = 0.; - if (it != args.end()) { - // First argument is 'a' - a = stringToReal(*it); - it++; + auto it = args.begin(); if (it != args.end()) { - // Second is 'b' - b = stringToReal(*it); + // First argument is 'a' + a = stringToReal(*it); it++; if (it != args.end()) { - // Third is 'g' - g = stringToReal(*it); + // Second is 'b' + b = stringToReal(*it); it++; + if (it != args.end()) { - output - << "WARNING: BoundaryRobin takes maximum of 3 arguments. Ignoring extras\n"; + // Third is 'g' + g = stringToReal(*it); + it++; + if (it != args.end()) { + output << "WARNING: BoundaryRobin takes maximum of 3 arguments. Ignoring " + "extras\n"; + } } } } + + return new BoundaryRobin(region, a, b, g); } - return new BoundaryRobin(region, a, b, g); -} + void BoundaryRobin::apply(Field2D & f) { + if (fabs(bval) < 1.e-12) { + // No derivative term so just constant value + for (bndry->first(); !bndry->isDone(); bndry->next()) + f(bndry->x, bndry->y) = gval / aval; + } else { + BoutReal sign = 1.; + if ((bndry->bx < 0) || (bndry->by < 0)) + sign = -1.; + for (bndry->first(); !bndry->isDone(); bndry->next()) + f(bndry->x, bndry->y) = + f(bndry->x - bndry->bx, bndry->y - bndry->by) + + sign * (gval - aval * f(bndry->x - bndry->bx, bndry->y - bndry->by)) / bval; + } + } -void BoundaryRobin::apply(Field2D& f) { - if (fabs(bval) < 1.e-12) { - // No derivative term so just constant value - for (bndry->first(); !bndry->isDone(); bndry->next()) - f(bndry->x, bndry->y) = gval / aval; - } else { - BoutReal sign = 1.; - if ((bndry->bx < 0) || (bndry->by < 0)) - sign = -1.; - for (bndry->first(); !bndry->isDone(); bndry->next()) - f(bndry->x, bndry->y) = - f(bndry->x - bndry->bx, bndry->y - bndry->by) - + sign * (gval - aval * f(bndry->x - bndry->bx, bndry->y - bndry->by)) / bval; + void BoundaryRobin::apply(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + if (fabs(bval) < 1.e-12) { + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) + f(bndry->x, bndry->y, z) = gval / aval; + } else { + BoutReal sign = 1.; + if ((bndry->bx < 0) || (bndry->by < 0)) + sign = -1.; + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) + f(bndry->x, bndry->y, z) = + f(bndry->x - bndry->bx, bndry->y - bndry->by, z) + + sign * (gval - aval * f(bndry->x - bndry->bx, bndry->y - bndry->by, z)) + / bval; + } } -} -void BoundaryRobin::apply(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - if (fabs(bval) < 1.e-12) { + /////////////////////////////////////////////////////////////// + + void BoundaryConstGradient::apply(Field2D & f) { + // Loop over all elements and set equal to the next point in for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0;z < mesh->LocalNz; z++) - f(bndry->x, bndry->y, z) = gval / aval; - } else { - BoutReal sign = 1.; - if ((bndry->bx < 0) || (bndry->by < 0)) - sign = -1.; + f(bndry->x, bndry->y) = 2. * f(bndry->x - bndry->bx, bndry->y - bndry->by) + - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by); + } + + void BoundaryConstGradient::apply(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); for (bndry->first(); !bndry->isDone(); bndry->next()) for (int z = 0; z < mesh->LocalNz; z++) f(bndry->x, bndry->y, z) = - f(bndry->x - bndry->bx, bndry->y - bndry->by, z) - + sign * (gval - aval * f(bndry->x - bndry->bx, bndry->y - bndry->by, z)) - / bval; + 2. * f(bndry->x - bndry->bx, bndry->y - bndry->by, z) + - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, z); } -} - -/////////////////////////////////////////////////////////////// - -void BoundaryConstGradient::apply(Field2D& f) { - // Loop over all elements and set equal to the next point in - for (bndry->first(); !bndry->isDone(); bndry->next()) - f(bndry->x, bndry->y) = 2. * f(bndry->x - bndry->bx, bndry->y - bndry->by) - - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by); -} - -void BoundaryConstGradient::apply(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0;z < mesh->LocalNz; z++) - f(bndry->x, bndry->y, z) = 2.*f(bndry->x - bndry->bx, bndry->y - bndry->by, z) - f(bndry->x - 2*bndry->bx,bndry->y - 2*bndry->by,z); -} -/////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryConstGradient::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 2); - if (!args.empty()) { - output << "WARNING: Ignoring arguments to BoundaryConstGradient\n"; + BoundaryOp* BoundaryConstGradient::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 2); + if (!args.empty()) { + output << "WARNING: Ignoring arguments to BoundaryConstGradient\n"; + } + return new BoundaryConstGradient(region); } - return new BoundaryConstGradient(region); -} -/////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryZeroLaplace::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 2); - if (!args.empty()) { - output << "WARNING: Ignoring arguments to BoundaryZeroLaplace\n"; + BoundaryOp* BoundaryZeroLaplace::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 2); + if (!args.empty()) { + output << "WARNING: Ignoring arguments to BoundaryZeroLaplace\n"; + } + return new BoundaryZeroLaplace(region); } - return new BoundaryZeroLaplace(region); -} -void BoundaryZeroLaplace::apply(Field2D& f) { + void BoundaryZeroLaplace::apply(Field2D & f) { #ifndef COORDINATES_USE_3D - Coordinates* metric = f.getCoordinates(); - if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { - // Can't apply this boundary condition to non-X boundaries - throw BoutException( - "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); - } - // Constant X derivative - int bx = bndry->bx; - // Loop over the Y dimension - for (bndry->first(); !bndry->isDone(); bndry->nextY()) { - int x = bndry->x; - int y = bndry->y; - BoutReal g = (f(x - bx, y) - f(x - 2 * bx, y)) / metric->dx(x - bx, y); - // Loop in X towards edge of domain - do { - f(x, y) = f(x - bx, y) + g * metric->dx(x, y); - bndry->nextX(); - x = bndry->x; - y = bndry->y; - } while (!bndry->isDone()); - } + Coordinates* metric = f.getCoordinates(); + if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { + // Can't apply this boundary condition to non-X boundaries + throw BoutException( + "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); + } + // Constant X derivative + int bx = bndry->bx; + // Loop over the Y dimension + for (bndry->first(); !bndry->isDone(); bndry->nextY()) { + int x = bndry->x; + int y = bndry->y; + BoutReal g = (f(x - bx, y) - f(x - 2 * bx, y)) / metric->dx(x - bx, y); + // Loop in X towards edge of domain + do { + f(x, y) = f(x - bx, y) + g * metric->dx(x, y); + bndry->nextX(); + x = bndry->x; + y = bndry->y; + } while (!bndry->isDone()); + } #else throw BoutException( "Applying boundary to Field2D not compatible with 3D metrics in all cases."); #endif -} - -void BoundaryZeroLaplace::apply(Field3D& f) { -#ifndef COORDINATES_USE_3D - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - int ncz = mesh->LocalNz; - - Coordinates* metric = f.getCoordinates(); - - Array c0(ncz / 2 + 1); - Array c1(ncz / 2 + 1); - - if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { - // Can't apply this boundary condition to non-X boundaries - throw BoutException( - "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); } - int bx = bndry->bx; - // Loop over the Y dimension - for (bndry->first(); !bndry->isDone(); bndry->nextY()) { - // bndry->(x,y) is the first point in the boundary - // bndry->(x-bx,y) is the last "real" point in the domain - - int x = bndry->x; - int y = bndry->y; - - // Take FFT of last 2 points in domain - rfft(f(x - bx, y), mesh->LocalNz, c0.begin()); - rfft(f(x - 2 * bx, y), mesh->LocalNz, c1.begin()); - c1[0] = c0[0] - c1[0]; // Only need gradient + void BoundaryZeroLaplace::apply(Field3D & f) { +#ifndef COORDINATES_USE_3D + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + int ncz = mesh->LocalNz; - // Solve metric->g11*d2f/dx2 - metric->g33*kz^2f = 0 - // Assume metric->g11, metric->g33 constant -> exponential growth or decay + Coordinates* metric = f.getCoordinates(); - // Loop in X towards edge of domain - do { - // kz = 0 solution - c0[0] += c1[0]; // Straight line + Array c0(ncz / 2 + 1); + Array c1(ncz / 2 + 1); - // kz != 0 solution - BoutReal coef = - -1.0 * sqrt(metric->g33(x, y) / metric->g11(x, y)) * metric->dx(x, y); - for (int jz = 1; jz <= ncz / 2; jz++) { - BoutReal kwave = jz * 2.0 * PI / metric->zlength()(x,y); // wavenumber in [rad^-1] - c0[jz] *= exp(coef * kwave); // The decaying solution only - } - // Reverse FFT - irfft(c0.begin(), mesh->LocalNz, f(x, y)); + if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { + // Can't apply this boundary condition to non-X boundaries + throw BoutException( + "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); + } - bndry->nextX(); - x = bndry->x; - y = bndry->y; - } while (!bndry->isDone()); - } + int bx = bndry->bx; + // Loop over the Y dimension + for (bndry->first(); !bndry->isDone(); bndry->nextY()) { + // bndry->(x,y) is the first point in the boundary + // bndry->(x-bx,y) is the last "real" point in the domain + + int x = bndry->x; + int y = bndry->y; + + // Take FFT of last 2 points in domain + rfft(f(x - bx, y), mesh->LocalNz, c0.begin()); + rfft(f(x - 2 * bx, y), mesh->LocalNz, c1.begin()); + c1[0] = c0[0] - c1[0]; // Only need gradient + + // Solve metric->g11*d2f/dx2 - metric->g33*kz^2f = 0 + // Assume metric->g11, metric->g33 constant -> exponential growth or decay + + // Loop in X towards edge of domain + do { + // kz = 0 solution + c0[0] += c1[0]; // Straight line + + // kz != 0 solution + BoutReal coef = + -1.0 * sqrt(metric->g33(x, y) / metric->g11(x, y)) * metric->dx(x, y); + for (int jz = 1; jz <= ncz / 2; jz++) { + BoutReal kwave = + jz * 2.0 * PI / metric->zlength()(x, y); // wavenumber in [rad^-1] + c0[jz] *= exp(coef * kwave); // The decaying solution only + } + // Reverse FFT + irfft(c0.begin(), mesh->LocalNz, f(x, y)); + + bndry->nextX(); + x = bndry->x; + y = bndry->y; + } while (!bndry->isDone()); + } #else throw BoutException( "Applying boundary to Field3D not compatible with 3D metrics in ZeroLaplace case."); #endif -} + } -/////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryZeroLaplace2::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 3); - if (!args.empty()) { - output << "WARNING: Ignoring arguments to BoundaryZeroLaplace2\n"; + BoundaryOp* BoundaryZeroLaplace2::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 3); + if (!args.empty()) { + output << "WARNING: Ignoring arguments to BoundaryZeroLaplace2\n"; + } + return new BoundaryZeroLaplace2(region); } - return new BoundaryZeroLaplace2(region); -} -void BoundaryZeroLaplace2::apply(Field2D& f) { + void BoundaryZeroLaplace2::apply(Field2D & f) { #ifndef COORDINATES_USE_3D - if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { - // Can't apply this boundary condition to non-X boundaries - throw BoutException( - "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); - } - - Coordinates* metric = f.getCoordinates(); + if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { + // Can't apply this boundary condition to non-X boundaries + throw BoutException( + "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); + } - // Constant X derivative - int bx = bndry->bx; - // Loop over the Y dimension - for (bndry->first(); !bndry->isDone(); bndry->nextY()) { - int x = bndry->x; - int y = bndry->y; - BoutReal g = (f(x - bx, y) - f(x - 2 * bx, y)) / metric->dx(x - bx, y); - // Loop in X towards edge of domain - do { - f(x, y) = f(x - bx, y) + g * metric->dx(x, y); - bndry->nextX(); - x = bndry->x; - y = bndry->y; - } while (!bndry->isDone()); - } + Coordinates* metric = f.getCoordinates(); + + // Constant X derivative + int bx = bndry->bx; + // Loop over the Y dimension + for (bndry->first(); !bndry->isDone(); bndry->nextY()) { + int x = bndry->x; + int y = bndry->y; + BoutReal g = (f(x - bx, y) - f(x - 2 * bx, y)) / metric->dx(x - bx, y); + // Loop in X towards edge of domain + do { + f(x, y) = f(x - bx, y) + g * metric->dx(x, y); + bndry->nextX(); + x = bndry->x; + y = bndry->y; + } while (!bndry->isDone()); + } #else throw BoutException( "Applying boundary to Field2D not compatible with 3D metrics in all cases."); #endif -} - -void BoundaryZeroLaplace2::apply(Field3D& f) { -#ifndef COORDINATES_USE_3D - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - int ncz = mesh->LocalNz; - - ASSERT0(ncz % 2 == 0); // Allocation assumes even number - - // allocate memory - Array c0(ncz / 2 + 1), c1(ncz / 2 + 1), c2(ncz / 2 + 1); - - if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { - // Can't apply this boundary condition to non-X boundaries - throw BoutException( - "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); } - int bx = bndry->bx; - // Loop over the Y dimension - for (bndry->first(); !bndry->isDone(); bndry->nextY()) { - // bndry->(x,y) is the first point in the boundary - // bndry->(x-bx,y) is the last "real" point in the domain + void BoundaryZeroLaplace2::apply(Field3D & f) { +#ifndef COORDINATES_USE_3D + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + int ncz = mesh->LocalNz; - int x = bndry->x; - int y = bndry->y; + ASSERT0(ncz % 2 == 0); // Allocation assumes even number - // Take FFT of last 2 points in domain - rfft(f(x - bx, y), ncz, c1.begin()); - rfft(f(x - 2 * bx, y), ncz, c2.begin()); + // allocate memory + Array c0(ncz / 2 + 1), c1(ncz / 2 + 1), c2(ncz / 2 + 1); - // Loop in X towards edge of domain - do { - for (int jz = 0; jz <= ncz / 2; jz++) { - dcomplex la, lb, lc; - laplace_tridag_coefs(x - bx, y, jz, la, lb, lc); - if (bx > 0) { - // Outer boundary - swap(la, lc); - } - c0[jz] = -(lb * c1[jz] + lc * c2[jz]) / la; - } - // Reverse FFT - irfft(c0.begin(), ncz, f(x, y)); - // cycle c0 -> c1 -> c2 -> c0 - swap(c0, c2); - swap(c2, c1); + if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { + // Can't apply this boundary condition to non-X boundaries + throw BoutException( + "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); + } - bndry->nextX(); - x = bndry->x; - y = bndry->y; - } while (!bndry->isDone()); - } + int bx = bndry->bx; + // Loop over the Y dimension + for (bndry->first(); !bndry->isDone(); bndry->nextY()) { + // bndry->(x,y) is the first point in the boundary + // bndry->(x-bx,y) is the last "real" point in the domain + + int x = bndry->x; + int y = bndry->y; + + // Take FFT of last 2 points in domain + rfft(f(x - bx, y), ncz, c1.begin()); + rfft(f(x - 2 * bx, y), ncz, c2.begin()); + + // Loop in X towards edge of domain + do { + for (int jz = 0; jz <= ncz / 2; jz++) { + dcomplex la, lb, lc; + laplace_tridag_coefs(x - bx, y, jz, la, lb, lc); + if (bx > 0) { + // Outer boundary + swap(la, lc); + } + c0[jz] = -(lb * c1[jz] + lc * c2[jz]) / la; + } + // Reverse FFT + irfft(c0.begin(), ncz, f(x, y)); + // cycle c0 -> c1 -> c2 -> c0 + swap(c0, c2); + swap(c2, c1); + + bndry->nextX(); + x = bndry->x; + y = bndry->y; + } while (!bndry->isDone()); + } #else throw BoutException("Applying boundary to Field3D not compatible with 3D metrics in " "ZeroLaplace2 case."); #endif -} + } -/////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryConstLaplace::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 2); - if (!args.empty()) { - output << "WARNING: Ignoring arguments to BoundaryConstLaplace\n"; + BoundaryOp* BoundaryConstLaplace::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 2); + if (!args.empty()) { + output << "WARNING: Ignoring arguments to BoundaryConstLaplace\n"; + } + return new BoundaryConstLaplace(region); } - return new BoundaryConstLaplace(region); -} -void BoundaryConstLaplace::apply(Field2D& f) { - if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { - // Can't apply this boundary condition to non-X boundaries - throw BoutException( - "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); - } - - // Constant X second derivative - int bx = bndry->bx; - // Loop over the Y dimension - for (bndry->first(); !bndry->isDone(); bndry->nextY()) { - int x = bndry->x; - int y = bndry->y; - // Calculate the Laplacian on the last point - dcomplex la, lb, lc; - laplace_tridag_coefs(x - 2 * bx, y, 0, la, lb, lc); - dcomplex val = - la * f(x - bx - 1, y) + lb * f(x - 2 * bx, y) + lc * f(x - 2 * bx + 1, y); - // Loop in X towards edge of domain - do { - laplace_tridag_coefs(x - bx, y, 0, la, lb, lc); - if (bx < 0) { // Lower X - f(x, y) = ((val - lb * f(x - bx, y) + lc * f(x - 2 * bx, y)) / la).real(); - } else // Upper X - f(x, y) = ((val - lb * f(x - bx, y) + la * f(x - 2 * bx, y)) / lc).real(); - - bndry->nextX(); - x = bndry->x; - y = bndry->y; - } while (!bndry->isDone()); + void BoundaryConstLaplace::apply(Field2D & f) { + if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { + // Can't apply this boundary condition to non-X boundaries + throw BoutException( + "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); + } + + // Constant X second derivative + int bx = bndry->bx; + // Loop over the Y dimension + for (bndry->first(); !bndry->isDone(); bndry->nextY()) { + int x = bndry->x; + int y = bndry->y; + // Calculate the Laplacian on the last point + dcomplex la, lb, lc; + laplace_tridag_coefs(x - 2 * bx, y, 0, la, lb, lc); + dcomplex val = + la * f(x - bx - 1, y) + lb * f(x - 2 * bx, y) + lc * f(x - 2 * bx + 1, y); + // Loop in X towards edge of domain + do { + laplace_tridag_coefs(x - bx, y, 0, la, lb, lc); + if (bx < 0) { // Lower X + f(x, y) = ((val - lb * f(x - bx, y) + lc * f(x - 2 * bx, y)) / la).real(); + } else // Upper X + f(x, y) = ((val - lb * f(x - bx, y) + la * f(x - 2 * bx, y)) / lc).real(); + + bndry->nextX(); + x = bndry->x; + y = bndry->y; + } while (!bndry->isDone()); + } } -} -void BoundaryConstLaplace::apply(Field3D& f) { + void BoundaryConstLaplace::apply(Field3D & f) { #ifndef COORDINATES_USE_3D - if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { - // Can't apply this boundary condition to non-X boundaries - throw BoutException( - "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); - } + if ((bndry->location != BNDRY_XIN) && (bndry->location != BNDRY_XOUT)) { + // Can't apply this boundary condition to non-X boundaries + throw BoutException( + "ERROR: Can't apply Zero Laplace condition to non-X boundaries\n"); + } - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Coordinates *metric = f.getCoordinates(); - - int ncz = mesh->LocalNz; - - // Allocate memory - Array c0(ncz / 2 + 1), c1(ncz / 2 + 1), c2(ncz / 2 + 1); - - int bx = bndry->bx; - // Loop over the Y dimension - for (bndry->first(); !bndry->isDone(); bndry->nextY()) { - int x = bndry->x; - int y = bndry->y; - - // Take FFT of last 3 points in domain - rfft(f(x - bx, y), ncz, c0.begin()); - rfft(f(x - 2 * bx, y), ncz, c1.begin()); - rfft(f(x - 3 * bx, y), ncz, c2.begin()); - dcomplex k0lin = (c1[0] - c0[0]) / metric->dx(x - bx, y); // for kz=0 solution - - // Calculate Delp2 on point MXG+1 (and put into c1) - for (int jz = 0; jz <= ncz / 2; jz++) { - dcomplex la, lb, lc; - laplace_tridag_coefs(x - 2 * bx, y, jz, la, lb, lc); - if (bx < 0) { // Inner X - c1[jz] = la * c0[jz] + lb * c1[jz] + lc * c2[jz]; - } else { // Outer X - c1[jz] = la * c2[jz] + lb * c1[jz] + lc * c0[jz]; - } + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Coordinates* metric = f.getCoordinates(); + + int ncz = mesh->LocalNz; + + // Allocate memory + Array c0(ncz / 2 + 1), c1(ncz / 2 + 1), c2(ncz / 2 + 1); + + int bx = bndry->bx; + // Loop over the Y dimension + for (bndry->first(); !bndry->isDone(); bndry->nextY()) { + int x = bndry->x; + int y = bndry->y; + + // Take FFT of last 3 points in domain + rfft(f(x - bx, y), ncz, c0.begin()); + rfft(f(x - 2 * bx, y), ncz, c1.begin()); + rfft(f(x - 3 * bx, y), ncz, c2.begin()); + dcomplex k0lin = (c1[0] - c0[0]) / metric->dx(x - bx, y); // for kz=0 solution + + // Calculate Delp2 on point MXG+1 (and put into c1) + for (int jz = 0; jz <= ncz / 2; jz++) { + dcomplex la, lb, lc; + laplace_tridag_coefs(x - 2 * bx, y, jz, la, lb, lc); + if (bx < 0) { // Inner X + c1[jz] = la * c0[jz] + lb * c1[jz] + lc * c2[jz]; + } else { // Outer X + c1[jz] = la * c2[jz] + lb * c1[jz] + lc * c0[jz]; + } + } + // Solve metric->g11*d2f/dx2 - metric->g33*kz^2f = 0 + // Assume metric->g11, metric->g33 constant -> exponential growth or decay + BoutReal xpos = 0.0; + // Loop in X towards edge of domain + do { + // kz = 0 solution + xpos -= metric->dx(x, y); + c2[0] = c0[0] + k0lin * xpos + 0.5 * c1[0] * xpos * xpos / metric->g11(x - bx, y); + // kz != 0 solution + BoutReal coef = -1.0 * sqrt(metric->g33(x - bx, y) / metric->g11(x - bx, y)) + * metric->dx(x - bx, y); + for (int jz = 1; jz <= ncz / 2; jz++) { + BoutReal kwave = + jz * 2.0 * PI / getConst(metric->zlength()); // wavenumber in [rad^-1] + c0[jz] *= exp(coef * kwave); // The decaying solution only + // Add the particular solution + c2[jz] = c0[jz] - c1[jz] / (metric->g33(x - bx, y) * kwave * kwave); + } + // Reverse FFT + irfft(c2.begin(), ncz, f(x, y)); + + bndry->nextX(); + x = bndry->x; + y = bndry->y; + } while (!bndry->isDone()); } - // Solve metric->g11*d2f/dx2 - metric->g33*kz^2f = 0 - // Assume metric->g11, metric->g33 constant -> exponential growth or decay - BoutReal xpos = 0.0; - // Loop in X towards edge of domain - do { - // kz = 0 solution - xpos -= metric->dx(x, y); - c2[0] = c0[0] + k0lin * xpos + 0.5 * c1[0] * xpos * xpos / metric->g11(x - bx, y); - // kz != 0 solution - BoutReal coef = -1.0 * sqrt(metric->g33(x - bx, y) / metric->g11(x - bx, y)) - * metric->dx(x - bx, y); - for (int jz = 1; jz <= ncz / 2; jz++) { - BoutReal kwave = jz * 2.0 * PI / getConst(metric->zlength()); // wavenumber in [rad^-1] - c0[jz] *= exp(coef * kwave); // The decaying solution only - // Add the particular solution - c2[jz] = c0[jz] - c1[jz] / (metric->g33(x - bx, y) * kwave * kwave); - } - // Reverse FFT - irfft(c2.begin(), ncz, f(x, y)); - - bndry->nextX(); - x = bndry->x; - y = bndry->y; - } while (!bndry->isDone()); - } #else throw BoutException("Applying boundary to Field3D not compatible with 3D metrics in " "ConstLaplace case."); #endif -} + } -/////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryDivCurl::clone(BoundaryRegion* region, - const std::list& args) { - if (!args.empty()) { - output << "WARNING: Ignoring arguments to BoundaryDivCurl\n"; + BoundaryOp* BoundaryDivCurl::clone(BoundaryRegion * region, + const std::list& args) { + if (!args.empty()) { + output << "WARNING: Ignoring arguments to BoundaryDivCurl\n"; + } + return new BoundaryDivCurl(region); } - return new BoundaryDivCurl(region); -} -void BoundaryDivCurl::apply(Vector2D& UNUSED(f)) { - throw BoutException("ERROR: DivCurl boundary not yet implemented for 2D vectors\n"); -} + void BoundaryDivCurl::apply(Vector2D & UNUSED(f)) { + throw BoutException("ERROR: DivCurl boundary not yet implemented for 2D vectors\n"); + } -void BoundaryDivCurl::apply(Vector3D& var) { + void BoundaryDivCurl::apply(Vector3D & var) { #ifndef COORDINATES_USE_3D - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == var.x.getMesh()); + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == var.x.getMesh()); - int jx, jy, jz, jzp, jzm; - BoutReal tmp; + int jx, jy, jz, jzp, jzm; + BoutReal tmp; - Coordinates* metric = mesh->getCoordinates(var.getLocation()); + Coordinates* metric = mesh->getCoordinates(var.getLocation()); - int ncz = mesh->LocalNz; + int ncz = mesh->LocalNz; - if (bndry->location != BNDRY_XOUT) { - throw BoutException("ERROR: DivCurl boundary only works for outer X currently\n"); - } - var.toCovariant(); + if (bndry->location != BNDRY_XOUT) { + throw BoutException("ERROR: DivCurl boundary only works for outer X currently\n"); + } + var.toCovariant(); - if (mesh->xstart > 2) { - throw BoutException( - "Error: Div = Curl = 0 boundary condition doesn't work for MXG > 2. Sorry\n"); - } + if (mesh->xstart > 2) { + throw BoutException( + "Error: Div = Curl = 0 boundary condition doesn't work for MXG > 2. Sorry\n"); + } - jx = mesh->xend + 1; - for (jy = 1; jy < mesh->LocalNy - 1; jy++) { - for (jz = 0; jz < ncz; jz++) { - jzp = (jz + 1) % ncz; - jzm = (jz - 1 + ncz) % ncz; + jx = mesh->xend + 1; + for (jy = 1; jy < mesh->LocalNy - 1; jy++) { + for (jz = 0; jz < ncz; jz++) { + jzp = (jz + 1) % ncz; + jzm = (jz - 1 + ncz) % ncz; - // dB_y / dx = dB_x / dy + // dB_y / dx = dB_x / dy - // dB_x / dy - tmp = (var.x(jx - 1, jy + 1, jz) - var.x(jx - 1, jy - 1, jz)) - / (metric->dy(jx - 1, jy - 1) + metric->dy(jx - 1, jy)); + // dB_x / dy + tmp = (var.x(jx - 1, jy + 1, jz) - var.x(jx - 1, jy - 1, jz)) + / (metric->dy(jx - 1, jy - 1) + metric->dy(jx - 1, jy)); - var.y(jx, jy, jz) = - var.y(jx - 2, jy, jz) + (metric->dx(jx - 2, jy) + metric->dx(jx - 1, jy)) * tmp; - if (mesh->xstart == 2) - // 4th order to get last point - var.y(jx + 1, jy, jz) = var.y(jx - 3, jy, jz) + 4. * metric->dx(jx, jy) * tmp; + var.y(jx, jy, jz) = var.y(jx - 2, jy, jz) + + (metric->dx(jx - 2, jy) + metric->dx(jx - 1, jy)) * tmp; + if (mesh->xstart == 2) + // 4th order to get last point + var.y(jx + 1, jy, jz) = var.y(jx - 3, jy, jz) + 4. * metric->dx(jx, jy) * tmp; - // dB_z / dx = dB_x / dz + // dB_z / dx = dB_x / dz - tmp = (var.x(jx - 1, jy, jzp) - var.x(jx - 1, jy, jzm)) / (2. * metric->dz(jx - 1, jy)); + tmp = (var.x(jx - 1, jy, jzp) - var.x(jx - 1, jy, jzm)) + / (2. * metric->dz(jx - 1, jy)); - var.z(jx, jy, jz) = - var.z(jx - 2, jy, jz) + (metric->dx(jx - 2, jy) + metric->dx(jx - 1, jy)) * tmp; - if (mesh->xstart == 2) - var.z(jx + 1, jy, jz) = var.z(jx - 3, jy, jz) + 4. * metric->dx(jx, jy) * tmp; + var.z(jx, jy, jz) = var.z(jx - 2, jy, jz) + + (metric->dx(jx - 2, jy) + metric->dx(jx - 1, jy)) * tmp; + if (mesh->xstart == 2) + var.z(jx + 1, jy, jz) = var.z(jx - 3, jy, jz) + 4. * metric->dx(jx, jy) * tmp; - // d/dx( Jmetric->g11 B_x ) = - d/dx( Jmetric->g12 B_y + Jmetric->g13 B_z) - // - d/dy( JB^y ) - d/dz( JB^z ) + // d/dx( Jmetric->g11 B_x ) = - d/dx( Jmetric->g12 B_y + Jmetric->g13 B_z) + // - d/dy( JB^y ) - d/dz( JB^z ) - tmp = -(metric->J(jx, jy) * metric->g12(jx, jy) * var.y(jx, jy, jz) + tmp = + -(metric->J(jx, jy) * metric->g12(jx, jy) * var.y(jx, jy, jz) + metric->J(jx, jy) * metric->g13(jx, jy) * var.z(jx, jy, jz) - metric->J(jx - 2, jy) * metric->g12(jx - 2, jy) * var.y(jx - 2, jy, jz) + metric->J(jx - 2, jy) * metric->g13(jx - 2, jy) * var.z(jx - 2, jy, jz)) / (metric->dx(jx - 2, jy) + metric->dx(jx - 1, jy)); // First term (d/dx) using vals calculated above - tmp -= (metric->J(jx - 1, jy + 1) * metric->g12(jx - 1, jy + 1) - * var.x(jx - 1, jy + 1, jz) - - metric->J(jx - 1, jy - 1) * metric->g12(jx - 1, jy - 1) - * var.x(jx - 1, jy - 1, jz) - + metric->J(jx - 1, jy + 1) * metric->g22(jx - 1, jy + 1) - * var.y(jx - 1, jy + 1, jz) - - metric->J(jx - 1, jy - 1) * metric->g22(jx - 1, jy - 1) - * var.y(jx - 1, jy - 1, jz) - + metric->J(jx - 1, jy + 1) * metric->g23(jx - 1, jy + 1) - * var.z(jx - 1, jy + 1, jz) - - metric->J(jx - 1, jy - 1) * metric->g23(jx - 1, jy - 1) - * var.z(jx - 1, jy - 1, jz)) - / (metric->dy(jx - 1, jy - 1) + metric->dy(jx - 1, jy)); // second (d/dy) - tmp -= (metric->J(jx - 1, jy) * metric->g13(jx - 1, jy) - * (var.x(jx - 1, jy, jzp) - var.x(jx - 1, jy, jzm)) - + metric->J(jx - 1, jy) * metric->g23(jx - 1, jy) - * (var.y(jx - 1, jy, jzp) - var.y(jx - 1, jy, jzm)) - + metric->J(jx - 1, jy) * metric->g33(jx - 1, jy) - * (var.z(jx - 1, jy, jzp) - var.z(jx - 1, jy, jzm))) - / (2. * metric->dz(jx - 1, jy)); - - var.x(jx, jy, jz) = - (metric->J(jx - 2, jy) * metric->g11(jx - 2, jy) * var.x(jx - 2, jy, jz) - + (metric->dx(jx - 2, jy) + metric->dx(jx - 1, jy)) * tmp) - / metric->J(jx, jy) * metric->g11(jx, jy); - if (mesh->xstart == 2) - var.x(jx + 1, jy, jz) = - (metric->J(jx - 3, jy) * metric->g11(jx - 3, jy) * var.x(jx - 3, jy, jz) - + 4. * metric->dx(jx, jy) * tmp) - / metric->J(jx + 1, jy) * metric->g11(jx + 1, jy); + tmp -= (metric->J(jx - 1, jy + 1) * metric->g12(jx - 1, jy + 1) + * var.x(jx - 1, jy + 1, jz) + - metric->J(jx - 1, jy - 1) * metric->g12(jx - 1, jy - 1) + * var.x(jx - 1, jy - 1, jz) + + metric->J(jx - 1, jy + 1) * metric->g22(jx - 1, jy + 1) + * var.y(jx - 1, jy + 1, jz) + - metric->J(jx - 1, jy - 1) * metric->g22(jx - 1, jy - 1) + * var.y(jx - 1, jy - 1, jz) + + metric->J(jx - 1, jy + 1) * metric->g23(jx - 1, jy + 1) + * var.z(jx - 1, jy + 1, jz) + - metric->J(jx - 1, jy - 1) * metric->g23(jx - 1, jy - 1) + * var.z(jx - 1, jy - 1, jz)) + / (metric->dy(jx - 1, jy - 1) + metric->dy(jx - 1, jy)); // second (d/dy) + tmp -= (metric->J(jx - 1, jy) * metric->g13(jx - 1, jy) + * (var.x(jx - 1, jy, jzp) - var.x(jx - 1, jy, jzm)) + + metric->J(jx - 1, jy) * metric->g23(jx - 1, jy) + * (var.y(jx - 1, jy, jzp) - var.y(jx - 1, jy, jzm)) + + metric->J(jx - 1, jy) * metric->g33(jx - 1, jy) + * (var.z(jx - 1, jy, jzp) - var.z(jx - 1, jy, jzm))) + / (2. * metric->dz(jx - 1, jy)); + + var.x(jx, jy, jz) = + (metric->J(jx - 2, jy) * metric->g11(jx - 2, jy) * var.x(jx - 2, jy, jz) + + (metric->dx(jx - 2, jy) + metric->dx(jx - 1, jy)) * tmp) + / metric->J(jx, jy) * metric->g11(jx, jy); + if (mesh->xstart == 2) + var.x(jx + 1, jy, jz) = + (metric->J(jx - 3, jy) * metric->g11(jx - 3, jy) * var.x(jx - 3, jy, jz) + + 4. * metric->dx(jx, jy) * tmp) + / metric->J(jx + 1, jy) * metric->g11(jx + 1, jy); + } } - } #else throw BoutException( "Applying boundary to Vector3D not compatible with 3D metrics in DivCurl."); #endif -} - -/////////////////////////////////////////////////////////////// - -BoundaryOp* BoundaryFree::clone(BoundaryRegion* region, - const std::list& args) { - if (!args.empty()) { - // First argument should be a value - val = stringToReal(args.front()); - return new BoundaryFree(region, val); } - return new BoundaryFree(region); -} - -void BoundaryFree::apply(Field2D& UNUSED(f)) { - // Do nothing for free boundary -} - -void BoundaryFree::apply(Field3D& UNUSED(f)) { - // Do nothing for free boundary -} - -void BoundaryFree::apply_ddt(Field2D& UNUSED(f)) { - // Do nothing for free boundary -} -void BoundaryFree::apply_ddt(Field3D& UNUSED(f)) { - // Do nothing for free boundary -} -/////////////////////////////////////////////////////////////// -// New free boundary implementation. Uses last grid points to extrapolate into the guard -// cells. Written by L. Easy. -/////////////////////////////////////////////////////////////// - -// 2nd order extrapolation: + /////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryFree_O2::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 2); - if (!args.empty()) { - output << "WARNING: Ignoring arguments to BoundaryFree\n"; + BoundaryOp* BoundaryFree::clone(BoundaryRegion * region, + const std::list& args) { + if (!args.empty()) { + // First argument should be a value + val = stringToReal(args.front()); + return new BoundaryFree(region, val); + } + return new BoundaryFree(region); } - return new BoundaryFree_O2(region); -} - -void BoundaryFree_O2::apply(Field2D& f) { - // Set (at 2nd order) the value at the mid-point between the guard cell and the grid - // cell to be val N.B. Only first guard cells (closest to the grid) should ever be used - - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - bndry->first(); - // Check for staggered grids - - CELL_LOC loc = f.getLocation(); - if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { - // Staggered. Need to apply slightly differently - - if (loc == CELL_XLOW) { - // Field is shifted in X - - if (bndry->bx > 0) { - // Outer x boundary - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); - } - } - } - if (bndry->bx < 0) { - // Inner x boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = -1; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); - } - } - } - if (bndry->by != 0) { - // y boundaries - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); - } - } - } - } else if (loc == CELL_YLOW) { - // Field is shifted in Y + void BoundaryFree::apply(Field2D & UNUSED(f)) { + // Do nothing for free boundary + } - if (bndry->by > 0) { - // Upper y boundary + void BoundaryFree::apply(Field3D & UNUSED(f)) { + // Do nothing for free boundary + } - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); - } - } - } - if (bndry->by < 0) { - // Lower y boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = -1; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); - } - } - } - if (bndry->bx != 0) { - // x boundaries - for (; !bndry->isDone(); bndry->next1d()) { + void BoundaryFree::apply_ddt(Field2D & UNUSED(f)) { + // Do nothing for free boundary + } - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); - } - } - } - } - } else { - // Non-staggered, standard case + void BoundaryFree::apply_ddt(Field3D & UNUSED(f)) { + // Do nothing for free boundary + } + /////////////////////////////////////////////////////////////// + // New free boundary implementation. Uses last grid points to extrapolate into the + // guard cells. Written by L. Easy. + /////////////////////////////////////////////////////////////// - for (; !bndry->isDone(); bndry->next1d()) { + // 2nd order extrapolation: - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); - } + BoundaryOp* BoundaryFree_O2::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 2); + if (!args.empty()) { + output << "WARNING: Ignoring arguments to BoundaryFree\n"; } + return new BoundaryFree_O2(region); } -} - -void BoundaryFree_O2::apply(Field3D& f) { - // Extrapolate from the last evolved simulation cells into the guard cells at 3rd order. - - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - bndry->first(); - // Check for staggered grids + void BoundaryFree_O2::apply(Field2D & f) { + // Set (at 2nd order) the value at the mid-point between the guard cell and the grid + // cell to be val N.B. Only first guard cells (closest to the grid) should ever be + // used - CELL_LOC loc = f.getLocation(); - if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { - // Staggered. Need to apply slightly differently + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + bndry->first(); - if (loc == CELL_XLOW) { - // Field is shifted in X + // Check for staggered grids - if (bndry->bx > 0) { - // Outer x boundary + CELL_LOC loc = f.getLocation(); + if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { + // Staggered. Need to apply slightly differently - for (; !bndry->isDone(); bndry->next1d()) { + if (loc == CELL_XLOW) { + // Field is shifted in X - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->bx > 0) { + // Outer x boundary + for (; !bndry->isDone(); bndry->next1d()) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); } } } - } - if (bndry->bx < 0) { - // Inner x boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->bx < 0) { + // Inner x boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { for (int i = -1; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); } } } - } - if (bndry->by != 0) { - // y boundaries - - for (; !bndry->isDone(); bndry->next1d()) { - - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->by != 0) { + // y boundaries + for (; !bndry->isDone(); bndry->next1d()) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); } } } - } - } else if (loc == CELL_YLOW) { - // Field is shifted in Y + } else if (loc == CELL_YLOW) { + // Field is shifted in Y - if (bndry->by > 0) { - // Upper y boundary - for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->by > 0) { + // Upper y boundary + + for (; !bndry->isDone(); bndry->next1d()) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); } } } - } - if (bndry->by < 0) { - // Lower y boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->by < 0) { + // Lower y boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { for (int i = -1; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); } } } - } - if (bndry->bx != 0) { - // x boundaries - for (; !bndry->isDone(); bndry->next1d()) { + if (bndry->bx != 0) { + // x boundaries + for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); } } } } - } - } else { - // Standard (non-staggered) case - for (; !bndry->isDone(); bndry->next1d()) { + } else { + // Non-staggered, standard case + + for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) - - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + f(xi, yi) = 2 * f(xi - bndry->bx, yi - bndry->by) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by); } } } } -} - -void BoundaryFree_O2::apply_ddt(Field2D& f) { - Field2D* dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero -} -void BoundaryFree_O2::apply_ddt(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Field3D *dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0; z < mesh->LocalNz; z++) - (*dt)(bndry->x,bndry->y,z) = 0.; // Set time derivative to zero -} - -////////////////////////////////// -// Third order extrapolation: -////////////////////////////////// -BoundaryOp* BoundaryFree_O3::clone(BoundaryRegion* region, - const std::list& args) { - verifyNumPoints(region, 3); + void BoundaryFree_O2::apply(Field3D & f) { + // Extrapolate from the last evolved simulation cells into the guard cells at 3rd + // order. - if (!args.empty()) { - output << "WARNING: Ignoring arguments to BoundaryConstLaplace\n"; - } - return new BoundaryFree_O3(region); -} + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + bndry->first(); -void BoundaryFree_O3::apply(Field2D& f) { + // Check for staggered grids - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - bndry->first(); + CELL_LOC loc = f.getLocation(); + if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { + // Staggered. Need to apply slightly differently - // Check for staggered grids + if (loc == CELL_XLOW) { + // Field is shifted in X - CELL_LOC loc = f.getLocation(); - if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { - // Staggered. Need to apply slightly differently + if (bndry->bx > 0) { + // Outer x boundary - if (loc == CELL_XLOW) { - // Field is shifted in X + for (; !bndry->isDone(); bndry->next1d()) { - if (bndry->bx > 0) { - // Outer x boundary - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + } + } } - } - } - if (bndry->bx < 0) { - // Inner x boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = -1; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); + } + if (bndry->bx < 0) { + // Inner x boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = -1; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + } + } } } - } - if (bndry->by != 0) { - // y boundaries - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); + if (bndry->by != 0) { + // y boundaries + + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + } + } } } - } - } else if (loc == CELL_YLOW) { - // Field is shifted in Y + } else if (loc == CELL_YLOW) { + // Field is shifted in Y - if (bndry->by > 0) { - // Upper y boundary + if (bndry->by > 0) { + // Upper y boundary + for (; !bndry->isDone(); bndry->next1d()) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + } + } + } + } + if (bndry->by < 0) { + // Lower y boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = -1; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + } + } } } - } - if (bndry->by < 0) { - // Lower y boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - for (int i = -1; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); + if (bndry->bx != 0) { + // x boundaries + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); + } + } } } } - if (bndry->bx != 0) { - // x boundaries - for (; !bndry->isDone(); bndry->next1d()) { + } else { + // Standard (non-staggered) case + for (; !bndry->isDone(); bndry->next1d()) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); + f(xi, yi, zk) = 2 * f(xi - bndry->bx, yi - bndry->by, zk) + - f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk); } } } } - } else { - // Non-staggered, standard case + } - for (; !bndry->isDone(); bndry->next1d()) { + void BoundaryFree_O2::apply_ddt(Field2D & f) { + Field2D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero + } - for (int i = 0; i < bndry->width; i++) { - int xi = bndry->x + i * bndry->bx; - int yi = bndry->y + i * bndry->by; - f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); - } - } + void BoundaryFree_O2::apply_ddt(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Field3D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) + (*dt)(bndry->x, bndry->y, z) = 0.; // Set time derivative to zero } -} -void BoundaryFree_O3::apply(Field3D& f) { - // Extrapolate from the last evolved simulation cells into the guard cells at 3rd order. + ////////////////////////////////// + // Third order extrapolation: + ////////////////////////////////// + BoundaryOp* BoundaryFree_O3::clone(BoundaryRegion * region, + const std::list& args) { + verifyNumPoints(region, 3); - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - bndry->first(); + if (!args.empty()) { + output << "WARNING: Ignoring arguments to BoundaryConstLaplace\n"; + } + return new BoundaryFree_O3(region); + } - // Check for staggered grids + void BoundaryFree_O3::apply(Field2D & f) { - CELL_LOC loc = f.getLocation(); - if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { - // Staggered. Need to apply slightly differently + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + bndry->first(); - if (loc == CELL_XLOW) { - // Field is shifted in X + // Check for staggered grids - if (bndry->bx > 0) { - // Outer x boundary + CELL_LOC loc = f.getLocation(); + if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { + // Staggered. Need to apply slightly differently - for (; !bndry->isDone(); bndry->next1d()) { + if (loc == CELL_XLOW) { + // Field is shifted in X - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->bx > 0) { + // Outer x boundary + for (; !bndry->isDone(); bndry->next1d()) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } - } - if (bndry->bx < 0) { - // Inner x boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->bx < 0) { + // Inner x boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { for (int i = -1; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } - } - if (bndry->by != 0) { - // y boundaries - - for (; !bndry->isDone(); bndry->next1d()) { - - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->by != 0) { + // y boundaries + for (; !bndry->isDone(); bndry->next1d()) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } - } - } else if (loc == CELL_YLOW) { - // Field is shifted in Y + } else if (loc == CELL_YLOW) { + // Field is shifted in Y - if (bndry->by > 0) { - // Upper y boundary - for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->by > 0) { + // Upper y boundary + + for (; !bndry->isDone(); bndry->next1d()) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } - } - if (bndry->by < 0) { - // Lower y boundary. Set one point inwards - for (; !bndry->isDone(); bndry->next1d()) { - - for (int zk = 0; zk < mesh->LocalNz; zk++) { + if (bndry->by < 0) { + // Lower y boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { for (int i = -1; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } - } - if (bndry->bx != 0) { - // x boundaries - for (; !bndry->isDone(); bndry->next1d()) { + if (bndry->bx != 0) { + // x boundaries + for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } } - } - } else { - // Standard (non-staggered) case - for (; !bndry->isDone(); bndry->next1d()) { + } else { + // Non-staggered, standard case + + for (; !bndry->isDone(); bndry->next1d()) { - for (int zk = 0; zk < mesh->LocalNz; zk++) { for (int i = 0; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) - - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) - + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + f(xi, yi) = 3.0 * f(xi - bndry->bx, yi - bndry->by) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by); } } } } -} -void BoundaryFree_O3::apply_ddt(Field2D& f) { - Field2D* dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero -} + void BoundaryFree_O3::apply(Field3D & f) { + // Extrapolate from the last evolved simulation cells into the guard cells at 3rd + // order. -void BoundaryFree_O3::apply_ddt(Field3D& f) { - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); - Field3D *dt = f.timeDeriv(); - for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0; z < mesh->LocalNz; z++) - (*dt)(bndry->x,bndry->y,z) = 0.; // Set time derivative to zero -} + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + bndry->first(); -/////////////////////////////////////////////////////////////// + // Check for staggered grids -BoundaryOp* BoundaryRelax::cloneMod(BoundaryOp* operation, - const std::list& args) { - auto* result = new BoundaryRelax(operation, r); + CELL_LOC loc = f.getLocation(); + if (mesh->StaggerGrids and (loc == CELL_XLOW or loc == CELL_YLOW)) { + // Staggered. Need to apply slightly differently - if (!args.empty()) { - // First argument should be the rate - BoutReal val = stringToReal(args.front()); - val = fabs(val); // Should always be positive - result->r = val; + if (loc == CELL_XLOW) { + // Field is shifted in X + + if (bndry->bx > 0) { + // Outer x boundary + + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + if (bndry->bx < 0) { + // Inner x boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = -1; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + if (bndry->by != 0) { + // y boundaries + + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + } else if (loc == CELL_YLOW) { + // Field is shifted in Y + + if (bndry->by > 0) { + // Upper y boundary + for (; !bndry->isDone(); bndry->next1d()) { + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + if (bndry->by < 0) { + // Lower y boundary. Set one point inwards + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = -1; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + if (bndry->bx != 0) { + // x boundaries + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } + } + } else { + // Standard (non-staggered) case + for (; !bndry->isDone(); bndry->next1d()) { + + for (int zk = 0; zk < mesh->LocalNz; zk++) { + for (int i = 0; i < bndry->width; i++) { + int xi = bndry->x + i * bndry->bx; + int yi = bndry->y + i * bndry->by; + f(xi, yi, zk) = 3.0 * f(xi - bndry->bx, yi - bndry->by, zk) + - 3.0 * f(xi - 2 * bndry->bx, yi - 2 * bndry->by, zk) + + f(xi - 3 * bndry->bx, yi - 3 * bndry->by, zk); + } + } + } + } } - return result; -} + void BoundaryFree_O3::apply_ddt(Field2D & f) { + Field2D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + (*dt)(bndry->x, bndry->y) = 0.; // Set time derivative to zero + } -void BoundaryRelax::apply(Field2D& f, BoutReal t) { - // Just apply the original boundary condition to f - op->apply(f, t); -} + void BoundaryFree_O3::apply_ddt(Field3D & f) { + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); + Field3D* dt = f.timeDeriv(); + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) + (*dt)(bndry->x, bndry->y, z) = 0.; // Set time derivative to zero + } -void BoundaryRelax::apply(Field3D& f, BoutReal UNUSED(t)) { - // Just apply the original boundary condition to f - op->apply(f); -} + /////////////////////////////////////////////////////////////// -void BoundaryRelax::apply_ddt(Field2D& f) { - TRACE("BoundaryRelax::apply_ddt(Field2D)"); + BoundaryOp* BoundaryRelax::cloneMod(BoundaryOp * operation, + const std::list& args) { + auto* result = new BoundaryRelax(operation, r); - // Make a copy of f - Field2D g = f; - // Apply the boundary to g - op->apply(g); + if (!args.empty()) { + // First argument should be the rate + BoutReal val = stringToReal(args.front()); + val = fabs(val); // Should always be positive + result->r = val; + } - bndry->first(); + return result; + } - // Set time-derivatives - for (bndry->first(); !bndry->isDone(); bndry->next()) { - ddt(f)(bndry->x, bndry->y) = r * (g(bndry->x, bndry->y) - f(bndry->x, bndry->y)); + void BoundaryRelax::apply(Field2D & f, BoutReal t) { + // Just apply the original boundary condition to f + op->apply(f, t); } -} -void BoundaryRelax::apply_ddt(Field3D& f) { - TRACE("BoundaryRelax::apply_ddt(Field3D)"); + void BoundaryRelax::apply(Field3D & f, BoutReal UNUSED(t)) { + // Just apply the original boundary condition to f + op->apply(f); + } - Mesh* mesh = bndry->localmesh; - ASSERT1(mesh == f.getMesh()); + void BoundaryRelax::apply_ddt(Field2D & f) { + TRACE("BoundaryRelax::apply_ddt(Field2D)"); - // Make a copy of f - Field3D g = f; // NOTE: This is not very efficient... copying entire field - // Apply the boundary to g - op->apply(g); - // Set time-derivatives - for (bndry->first(); !bndry->isDone(); bndry->next()) - for (int z = 0; z < mesh->LocalNz; z++) { - ddt(f)(bndry->x, bndry->y, z) = - r * (g(bndry->x, bndry->y, z) - f(bndry->x, bndry->y, z)); + // Make a copy of f + Field2D g = f; + // Apply the boundary to g + op->apply(g); + + bndry->first(); + + // Set time-derivatives + for (bndry->first(); !bndry->isDone(); bndry->next()) { + ddt(f)(bndry->x, bndry->y) = r * (g(bndry->x, bndry->y) - f(bndry->x, bndry->y)); } -} + } -/////////////////////////////////////////////////////////////// + void BoundaryRelax::apply_ddt(Field3D & f) { + TRACE("BoundaryRelax::apply_ddt(Field3D)"); -BoundaryOp* BoundaryWidth::cloneMod(BoundaryOp* operation, - const std::list& args) { - auto* result = new BoundaryWidth(operation, width); + Mesh* mesh = bndry->localmesh; + ASSERT1(mesh == f.getMesh()); - if (args.empty()) { - output << "WARNING: BoundaryWidth expected 1 argument\n"; - } else { - // First argument should be the rate - int val = stringToInt(args.front()); - result->width = val; + // Make a copy of f + Field3D g = f; // NOTE: This is not very efficient... copying entire field + // Apply the boundary to g + op->apply(g); + // Set time-derivatives + for (bndry->first(); !bndry->isDone(); bndry->next()) + for (int z = 0; z < mesh->LocalNz; z++) { + ddt(f)(bndry->x, bndry->y, z) = + r * (g(bndry->x, bndry->y, z) - f(bndry->x, bndry->y, z)); + } } - return result; -} + /////////////////////////////////////////////////////////////// -void BoundaryWidth::apply(Field2D& f, BoutReal t) { - // Pointer to boundary region shared between all BoundaryOp, BoundaryModifiers - int oldwid = bndry->width; - bndry->width = width; - op->apply(f, t); - bndry->width = oldwid; -} + BoundaryOp* BoundaryWidth::cloneMod(BoundaryOp * operation, + const std::list& args) { + auto* result = new BoundaryWidth(operation, width); -void BoundaryWidth::apply(Field3D& f, BoutReal t) { - int oldwid = bndry->width; - bndry->width = width; - op->apply(f, t); - bndry->width = oldwid; -} + if (args.empty()) { + output << "WARNING: BoundaryWidth expected 1 argument\n"; + } else { + // First argument should be the rate + int val = stringToInt(args.front()); + result->width = val; + } -void BoundaryWidth::apply_ddt(Field2D& f) { - int oldwid = bndry->width; - bndry->width = width; - op->apply_ddt(f); - bndry->width = oldwid; -} + return result; + } -void BoundaryWidth::apply_ddt(Field3D& f) { - int oldwid = bndry->width; - bndry->width = width; - op->apply_ddt(f); - bndry->width = oldwid; -} + void BoundaryWidth::apply(Field2D & f, BoutReal t) { + // Pointer to boundary region shared between all BoundaryOp, BoundaryModifiers + int oldwid = bndry->width; + bndry->width = width; + op->apply(f, t); + bndry->width = oldwid; + } -/////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryToFieldAligned::cloneMod(BoundaryOp* operation, - const std::list& args) { - auto* result = new BoundaryToFieldAligned(operation); + void BoundaryWidth::apply(Field3D & f, BoutReal t) { + int oldwid = bndry->width; + bndry->width = width; + op->apply(f, t); + bndry->width = oldwid; + } - if (!args.empty()) { - output << "WARNING: BoundaryToFieldAligned expected no argument\n"; - // Shouldn't we throw ? + void BoundaryWidth::apply_ddt(Field2D & f) { + int oldwid = bndry->width; + bndry->width = width; + op->apply_ddt(f); + bndry->width = oldwid; } - return result; -} + void BoundaryWidth::apply_ddt(Field3D & f) { + int oldwid = bndry->width; + bndry->width = width; + op->apply_ddt(f); + bndry->width = oldwid; + } -void BoundaryToFieldAligned::apply(Field2D& f, BoutReal t) { op->apply(f, t); } + /////////////////////////////////////////////////////////////// + BoundaryOp* BoundaryToFieldAligned::cloneMod(BoundaryOp * operation, + const std::list& args) { + auto* result = new BoundaryToFieldAligned(operation); -void BoundaryToFieldAligned::apply(Field3D &f, BoutReal t) { - ASSERT1(bndry->localmesh == f.getMesh()); + if (!args.empty()) { + output << "WARNING: BoundaryToFieldAligned expected no argument\n"; + // Shouldn't we throw ? + } - // NOTE: This is not very efficient... updating entire field - f = fromFieldAligned(f); + return result; + } - // Apply the boundary to shifted field - op->apply(f, t); + void BoundaryToFieldAligned::apply(Field2D & f, BoutReal t) { op->apply(f, t); } - // Shift back - f = toFieldAligned(f); + void BoundaryToFieldAligned::apply(Field3D & f, BoutReal t) { + ASSERT1(bndry->localmesh == f.getMesh()); - // This is inefficient -- could instead use the shiftZ just in the bndry - // but this is not portable to other parallel transforms -- we could instead - // have a flag to define the region in which we want to apply to/fromFieldAligned -} + // NOTE: This is not very efficient... updating entire field + f = fromFieldAligned(f); -void BoundaryToFieldAligned::apply_ddt(Field2D &f) { - op->apply_ddt(f); -} + // Apply the boundary to shifted field + op->apply(f, t); -void BoundaryToFieldAligned::apply_ddt(Field3D &f) { - ASSERT1(bndry->localmesh == f.getMesh()); + // Shift back + f = toFieldAligned(f); - f = fromFieldAligned(f); - ddt(f) = fromFieldAligned(ddt(f)); - op->apply_ddt(f); - ddt(f) = toFieldAligned(ddt(f)); -} + // This is inefficient -- could instead use the shiftZ just in the bndry + // but this is not portable to other parallel transforms -- we could instead + // have a flag to define the region in which we want to apply to/fromFieldAligned + } -/////////////////////////////////////////////////////////////// -BoundaryOp* BoundaryFromFieldAligned::cloneMod(BoundaryOp* operation, - const std::list& args) { - auto* result = new BoundaryFromFieldAligned(operation); + void BoundaryToFieldAligned::apply_ddt(Field2D & f) { op->apply_ddt(f); } - if (!args.empty()) { - output << "WARNING: BoundaryFromFieldAligned expected no argument\n"; - // Shouldn't we throw ? + void BoundaryToFieldAligned::apply_ddt(Field3D & f) { + ASSERT1(bndry->localmesh == f.getMesh()); + + f = fromFieldAligned(f); + ddt(f) = fromFieldAligned(ddt(f)); + op->apply_ddt(f); + ddt(f) = toFieldAligned(ddt(f)); } - return result; -} + /////////////////////////////////////////////////////////////// + BoundaryOp* BoundaryFromFieldAligned::cloneMod(BoundaryOp * operation, + const std::list& args) { + auto* result = new BoundaryFromFieldAligned(operation); + + if (!args.empty()) { + output << "WARNING: BoundaryFromFieldAligned expected no argument\n"; + // Shouldn't we throw ? + } -void BoundaryFromFieldAligned::apply(Field2D& f, BoutReal t) { op->apply(f, t); } + return result; + } -void BoundaryFromFieldAligned::apply(Field3D &f, BoutReal t) { - ASSERT1(bndry->localmesh == f.getMesh()); + void BoundaryFromFieldAligned::apply(Field2D & f, BoutReal t) { op->apply(f, t); } - // NOTE: This is not very efficient... shifting entire field - f = toFieldAligned(f); + void BoundaryFromFieldAligned::apply(Field3D & f, BoutReal t) { + ASSERT1(bndry->localmesh == f.getMesh()); - // Apply the boundary to shifted field - op->apply(f, t); + // NOTE: This is not very efficient... shifting entire field + f = toFieldAligned(f); - // Shift back - f = fromFieldAligned(f); + // Apply the boundary to shifted field + op->apply(f, t); - // This is inefficient -- could instead use the shiftZ just in the bndry - // but this is not portable to other parallel transforms -- we could instead - // have a flag to define the region in which we want to apply to/fromFieldAligned -} + // Shift back + f = fromFieldAligned(f); -void BoundaryFromFieldAligned::apply_ddt(Field2D &f) { - op->apply_ddt(f); -} + // This is inefficient -- could instead use the shiftZ just in the bndry + // but this is not portable to other parallel transforms -- we could instead + // have a flag to define the region in which we want to apply to/fromFieldAligned + } -void BoundaryFromFieldAligned::apply_ddt(Field3D &f) { - ASSERT1(bndry->localmesh == f.getMesh()); + void BoundaryFromFieldAligned::apply_ddt(Field2D & f) { op->apply_ddt(f); } - f = toFieldAligned(f); - ddt(f) = toFieldAligned(ddt(f)); - op->apply_ddt(f); - ddt(f) = fromFieldAligned(ddt(f)); -} + void BoundaryFromFieldAligned::apply_ddt(Field3D & f) { + ASSERT1(bndry->localmesh == f.getMesh()); + + f = toFieldAligned(f); + ddt(f) = toFieldAligned(ddt(f)); + op->apply_ddt(f); + ddt(f) = fromFieldAligned(ddt(f)); + } diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 3402338ba6..90ab83d1e0 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -27,9 +27,9 @@ namespace { /// Boundary guard cells are set by extrapolating from the grid, like /// 'free_o3' boundary conditions /// Corner guard cells are set to BoutNaN -Field2D interpolateAndExtrapolate(const Field2D& f, CELL_LOC location, - bool extrapolate_x, bool extrapolate_y, - bool no_extra_interpolate, ParallelTransform* UNUSED(pt) = nullptr) { +Field2D interpolateAndExtrapolate(const Field2D& f, CELL_LOC location, bool extrapolate_x, + bool extrapolate_y, bool no_extra_interpolate, + ParallelTransform* UNUSED(pt) = nullptr) { Mesh* localmesh = f.getMesh(); Field2D result = interp_to(f, location, "RGN_NOBNDRY"); @@ -148,39 +148,39 @@ Field2D interpolateAndExtrapolate(const Field2D& f, CELL_LOC location, return result; } - Field3D interpolateAndExtrapolate(const Field3D& f_, CELL_LOC location, - bool extrapolate_x, bool extrapolate_y, - bool no_extra_interpolate, ParallelTransform* pt_) { - - Mesh* localmesh = f_.getMesh(); - Field3D result; - Field3D f = f_; - ParallelTransform * pt_f; - if (f.getCoordinates() == nullptr) { - pt_f = pt_; +Field3D interpolateAndExtrapolate(const Field3D& f_, CELL_LOC location, + bool extrapolate_x, bool extrapolate_y, + bool no_extra_interpolate, ParallelTransform* pt_) { + + Mesh* localmesh = f_.getMesh(); + Field3D result; + Field3D f = f_; + ParallelTransform* pt_f; + if (f.getCoordinates() == nullptr) { + pt_f = pt_; + } else { + pt_f = &f.getCoordinates()->getParallelTransform(); + } + if (f.getDirectionY() != YDirectionType::Standard) { + if (pt_f->canToFromFieldAligned()) { + f = pt_f->fromFieldAligned(f); } else { - pt_f = & f.getCoordinates()->getParallelTransform(); - } - if (f.getDirectionY() != YDirectionType::Standard) { - if (pt_f->canToFromFieldAligned()) { - f = pt_f->fromFieldAligned(f); - } else { - f.setDirectionY(YDirectionType::Standard); - } + f.setDirectionY(YDirectionType::Standard); } - if (location == CELL_YLOW){ - auto f_aligned = pt_f->toFieldAligned(f, "RGN_NOX"); - result = interp_to(f_aligned, location, "RGN_NOBNDRY"); - ParallelTransform * pt_result; - if (result.getCoordinates() == nullptr){ - pt_result = pt_; - } else { - pt_result = & result.getCoordinates()->getParallelTransform(); - } - result = pt_result->fromFieldAligned(result, "RGN_NOBNDRY"); + } + if (location == CELL_YLOW) { + auto f_aligned = pt_f->toFieldAligned(f, "RGN_NOX"); + result = interp_to(f_aligned, location, "RGN_NOBNDRY"); + ParallelTransform* pt_result; + if (result.getCoordinates() == nullptr) { + pt_result = pt_; } else { - result = interp_to(f, location, "RGN_NOBNDRY"); + pt_result = &result.getCoordinates()->getParallelTransform(); } + result = pt_result->fromFieldAligned(result, "RGN_NOBNDRY"); + } else { + result = interp_to(f, location, "RGN_NOBNDRY"); + } // Ensure result's data is unique. Otherwise result might be a duplicate of // f (if no interpolation is needed, e.g. if interpolation is in the // z-direction); then f would be communicated. Since this function is used @@ -225,21 +225,19 @@ Field2D interpolateAndExtrapolate(const Field2D& f, CELL_LOC location, ASSERT1(bndry->bx == 0 or localmesh->xstart > 1); ASSERT1(bndry->by == 0 or localmesh->ystart > 1); // note that either bx or by is >0 here - for (int zi=0; zi < localmesh->LocalNz; ++zi){ + for (int zi = 0; zi < localmesh->LocalNz; ++zi) { result(bndry->x, bndry->y, zi) = - (9. * (f(bndry->x - bndry->bx, bndry->y - bndry->by, zi) + f(bndry->x, bndry->y, zi)) - - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zi) - - f(bndry->x + bndry->bx, bndry->y + bndry->by, zi)) - / 16.; + (9. + * (f(bndry->x - bndry->bx, bndry->y - bndry->by, zi) + + f(bndry->x, bndry->y, zi)) + - f(bndry->x - 2 * bndry->bx, bndry->y - 2 * bndry->by, zi) + - f(bndry->x + bndry->bx, bndry->y + bndry->by, zi)) + / 16.; } - } // set boundary guard cells if ((bndry->bx != 0 && localmesh->GlobalNx - 2 * bndry->width >= 3) - || (bndry->by != 0 - && localmesh->GlobalNy - 2 * bndry->width - >= 3)) - { + || (bndry->by != 0 && localmesh->GlobalNy - 2 * bndry->width >= 3)) { if (bndry->bx != 0 && localmesh->LocalNx == 1 && bndry->width == 1) { throw BoutException( "Not enough points in the x-direction on this " @@ -258,18 +256,19 @@ Field2D interpolateAndExtrapolate(const Field2D& f, CELL_LOC location, for (int i = extrap_start; i < bndry->width; i++) { int xi = bndry->x + i * bndry->bx; int yi = bndry->y + i * bndry->by; - for (int zi=0; zi < localmesh->LocalNz; ++zi){ - result(xi, yi, zi) = 3.0 * result(xi - bndry->bx, yi - bndry->by, zi) - - 3.0 * result(xi - 2 * bndry->bx, yi - 2 * bndry->by, zi) - + result(xi - 3 * bndry->bx, yi - 3 * bndry->by, zi); + for (int zi = 0; zi < localmesh->LocalNz; ++zi) { + result(xi, yi, zi) = + 3.0 * result(xi - bndry->bx, yi - bndry->by, zi) + - 3.0 * result(xi - 2 * bndry->bx, yi - 2 * bndry->by, zi) + + result(xi - 3 * bndry->bx, yi - 3 * bndry->by, zi); } } } else { // not enough grid points to extrapolate, set equal to last grid point for (int i = extrap_start; i < bndry->width; i++) { - for (int zi = 0; zi < localmesh->LocalNz; ++zi){ + for (int zi = 0; zi < localmesh->LocalNz; ++zi) { result(bndry->x + i * bndry->bx, bndry->y + i * bndry->by, zi) = - result(bndry->x - bndry->bx, bndry->y - bndry->by, zi); + result(bndry->x - bndry->bx, bndry->y - bndry->by, zi); } } } @@ -277,16 +276,14 @@ Field2D interpolateAndExtrapolate(const Field2D& f, CELL_LOC location, } } #if CHECK > 0 - if (not ( - // if include_corner_cells=true, then we extrapolate valid data into the - // corner cells if they are not already filled - localmesh->include_corner_cells - - // if we are not extrapolating at all, the corner cells should contain valid - // data - or (not extrapolate_x and not extrapolate_y) - ) - ) { + if (not( + // if include_corner_cells=true, then we extrapolate valid data into the + // corner cells if they are not already filled + localmesh->include_corner_cells + + // if we are not extrapolating at all, the corner cells should contain valid + // data + or (not extrapolate_x and not extrapolate_y))) { // Invalidate corner guard cells for (int i = 0; i < localmesh->xstart; i++) { for (int j = 0; j < localmesh->ystart; j++) { @@ -304,8 +301,6 @@ Field2D interpolateAndExtrapolate(const Field2D& f, CELL_LOC location, return result; } - - // If the CELL_CENTRE variable was read, the staggered version is required to // also exist for consistency void checkStaggeredGet(Mesh* mesh, const std::string& name, const std::string& suffix) { @@ -316,11 +311,11 @@ void checkStaggeredGet(Mesh* mesh, const std::string& name, const std::string& s } // convenience function for repeated code -int getAtLoc(Mesh* mesh, Coordinates::metric_field_type &var, const std::string& name, - const std::string& suffix, CELL_LOC location, BoutReal default_value = 0.) { +int getAtLoc(Mesh* mesh, Coordinates::metric_field_type& var, const std::string& name, + const std::string& suffix, CELL_LOC location, BoutReal default_value = 0.) { checkStaggeredGet(mesh, name, suffix); - int result = mesh->get(var, name+suffix, default_value, false); + int result = mesh->get(var, name + suffix, default_value, false); var.setLocation(location); return result; @@ -349,18 +344,17 @@ std::string getLocationSuffix(CELL_LOC location) { } } - template - void communicate(T & t, Ts&... ts) { - FieldGroup g(t,ts...); - // emulate full communicate - auto h = t.getMesh()->sendY(g); - t.getMesh()->wait(h); - h = t.getMesh()->sendX(g); - t.getMesh()->wait(h); - } - +template +void communicate(T& t, Ts&... ts) { + FieldGroup g(t, ts...); + // emulate full communicate + auto h = t.getMesh()->sendY(g); + t.getMesh()->wait(h); + h = t.getMesh()->sendX(g); + t.getMesh()->wait(h); +} -}// anonymous namespace +} // anonymous namespace Coordinates::Coordinates(Mesh* mesh, Field2D dx, Field2D dy, BoutReal dz, Field2D J, Field2D Bxy, Field2D g11, Field2D g22, Field2D g33, Field2D g12, @@ -383,14 +377,15 @@ Coordinates::Coordinates(Mesh* mesh, Field2D dx, Field2D dy, BoutReal dz, Field2 } Coordinates::Coordinates(Mesh* mesh, Options* options) - : dx(1., mesh), dy(1., mesh), dz(1., mesh), d1_dx(mesh), d1_dy(mesh), d1_dz(mesh), J(1., mesh), Bxy(1., mesh), + : dx(1., mesh), dy(1., mesh), dz(1., mesh), d1_dx(mesh), d1_dy(mesh), d1_dz(mesh), + J(1., mesh), Bxy(1., mesh), // Identity metric tensor - g11(1., mesh), g22(1., mesh), g33(1., mesh), g12(0, mesh), g13(0, mesh), g23(0, mesh), - g_11(1., mesh), g_22(1., mesh), g_33(1., mesh), g_12(0, mesh), g_13(0, mesh), - g_23(0, mesh), G1_11(mesh), G1_22(mesh), G1_33(mesh), G1_12(mesh), G1_13(mesh), - G1_23(mesh), G2_11(mesh), G2_22(mesh), G2_33(mesh), G2_12(mesh), G2_13(mesh), - G2_23(mesh), G3_11(mesh), G3_22(mesh), G3_33(mesh), G3_12(mesh), G3_13(mesh), - G3_23(mesh), G1(mesh), G2(mesh), G3(mesh), ShiftTorsion(mesh), + g11(1., mesh), g22(1., mesh), g33(1., mesh), g12(0, mesh), g13(0, mesh), + g23(0, mesh), g_11(1., mesh), g_22(1., mesh), g_33(1., mesh), g_12(0, mesh), + g_13(0, mesh), g_23(0, mesh), G1_11(mesh), G1_22(mesh), G1_33(mesh), G1_12(mesh), + G1_13(mesh), G1_23(mesh), G2_11(mesh), G2_22(mesh), G2_33(mesh), G2_12(mesh), + G2_13(mesh), G2_23(mesh), G3_11(mesh), G3_22(mesh), G3_33(mesh), G3_12(mesh), + G3_13(mesh), G3_23(mesh), G1(mesh), G2(mesh), G3(mesh), ShiftTorsion(mesh), IntShiftTorsion(mesh), localmesh(mesh), location(CELL_CENTRE) { if (options == nullptr) { @@ -434,17 +429,20 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) // required early for differentiation. setParallelTransform(options); - dz = interpolateAndExtrapolate(dz, location, extrapolate_x, extrapolate_y, false, transform.get()); - dx = interpolateAndExtrapolate(dx, location, extrapolate_x, extrapolate_y, false, transform.get()); + dz = interpolateAndExtrapolate(dz, location, extrapolate_x, extrapolate_y, false, + transform.get()); + dx = interpolateAndExtrapolate(dx, location, extrapolate_x, extrapolate_y, false, + transform.get()); if (mesh->periodicX) { communicate(dx); } - dy = interpolateAndExtrapolate(dy, location, extrapolate_x, extrapolate_y, false, transform.get()); + dy = interpolateAndExtrapolate(dy, location, extrapolate_x, extrapolate_y, false, + transform.get()); -#define GET(a,b) \ - mesh->get(a, #a, b, false); \ +#define GET(a, b) \ + mesh->get(a, #a, b, false); \ a = maybeFromFieldAligned(a); // Diagonal components of metric tensor g^{ij} (default to 1) @@ -457,12 +455,18 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) GET(g13, 0.0); GET(g23, 0.0); - g11 = interpolateAndExtrapolate(g11, location, extrapolate_x, extrapolate_y, false, transform.get()); - g22 = interpolateAndExtrapolate(g22, location, extrapolate_x, extrapolate_y, false, transform.get()); - g33 = interpolateAndExtrapolate(g33, location, extrapolate_x, extrapolate_y, false, transform.get()); - g12 = interpolateAndExtrapolate(g12, location, extrapolate_x, extrapolate_y, false, transform.get()); - g13 = interpolateAndExtrapolate(g13, location, extrapolate_x, extrapolate_y, false, transform.get()); - g23 = interpolateAndExtrapolate(g23, location, extrapolate_x, extrapolate_y, false, transform.get()); + g11 = interpolateAndExtrapolate(g11, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g22 = interpolateAndExtrapolate(g22, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g33 = interpolateAndExtrapolate(g33, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g12 = interpolateAndExtrapolate(g12, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g13 = interpolateAndExtrapolate(g13, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g23 = interpolateAndExtrapolate(g23, location, extrapolate_x, extrapolate_y, false, + transform.get()); // Check input metrics // Diagonal metric components should be finite @@ -517,12 +521,18 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) } // More robust to extrapolate derived quantities directly, rather than // deriving from extrapolated covariant metric components - g_11 = interpolateAndExtrapolate(g_11, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_22 = interpolateAndExtrapolate(g_22, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_33 = interpolateAndExtrapolate(g_33, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_12 = interpolateAndExtrapolate(g_12, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_13 = interpolateAndExtrapolate(g_13, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_23 = interpolateAndExtrapolate(g_23, location, extrapolate_x, extrapolate_y, false, transform.get()); + g_11 = interpolateAndExtrapolate(g_11, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_22 = interpolateAndExtrapolate(g_22, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_33 = interpolateAndExtrapolate(g_33, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_12 = interpolateAndExtrapolate(g_12, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_13 = interpolateAndExtrapolate(g_13, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_23 = interpolateAndExtrapolate(g_23, location, extrapolate_x, extrapolate_y, false, + transform.get()); // Check covariant metrics // Diagonal metric components should be finite @@ -549,7 +559,8 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) "\tWARNING: Jacobian 'J' not found. Calculating from metric tensor\n"); J = Jcalc; } else { - J = interpolateAndExtrapolate(J, location, extrapolate_x, extrapolate_y, false, transform.get()); + J = interpolateAndExtrapolate(J, location, extrapolate_x, extrapolate_y, false, + transform.get()); // Compare calculated and loaded values output_warn.write("\tMaximum difference in J is {:e}\n", max(abs(J - Jcalc))); @@ -575,7 +586,8 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) Bxy = Bcalc; } else { - Bxy = interpolateAndExtrapolate(Bxy, location, extrapolate_x, extrapolate_y, false, transform.get()); + Bxy = interpolateAndExtrapolate(Bxy, location, extrapolate_x, extrapolate_y, false, + transform.get()); output_warn.write("\tMaximum difference in Bxy is {:e}\n", max(abs(Bxy - Bcalc))); } @@ -594,7 +606,8 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) "\tWARNING: No Torsion specified for zShift. Derivatives may not be correct\n"); ShiftTorsion = 0.0; } - ShiftTorsion = interpolateAndExtrapolate(ShiftTorsion, location, extrapolate_x, extrapolate_y, false, transform.get()); + ShiftTorsion = interpolateAndExtrapolate(ShiftTorsion, location, extrapolate_x, + extrapolate_y, false, transform.get()); ////////////////////////////////////////////////////// @@ -602,7 +615,8 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) if (mesh->get(IntShiftTorsion, "IntShiftTorsion", 0.0, false)) { output_warn.write("\tWARNING: No Integrated torsion specified\n"); } - IntShiftTorsion = interpolateAndExtrapolate(IntShiftTorsion, location, extrapolate_x, extrapolate_y, false, transform.get()); + IntShiftTorsion = interpolateAndExtrapolate(IntShiftTorsion, location, extrapolate_x, + extrapolate_y, false, transform.get()); } else { // IntShiftTorsion will not be used, but set to zero to avoid uninitialized field IntShiftTorsion = 0.; @@ -612,25 +626,28 @@ Coordinates::Coordinates(Mesh* mesh, Options* options) // use anonymous namespace so this utility function is not available outside this file namespace { - /// Interpolate a Field2D to a new CELL_LOC with interp_to. - /// Communicates to set internal guard cells. - /// Boundary guard cells are set equal to the nearest grid point (equivalent to - /// 2nd order accurate Neumann boundary condition). - /// Corner guard cells are set to BoutNaN +/// Interpolate a Field2D to a new CELL_LOC with interp_to. +/// Communicates to set internal guard cells. +/// Boundary guard cells are set equal to the nearest grid point (equivalent to +/// 2nd order accurate Neumann boundary condition). +/// Corner guard cells are set to BoutNaN Coordinates::metric_field_type -interpolateAndNeumann(MAYBE_UNUSED(const Coordinates::metric_field_type& f), MAYBE_UNUSED(CELL_LOC location), MAYBE_UNUSED(ParallelTransform * pt)) { +interpolateAndNeumann(MAYBE_UNUSED(const Coordinates::metric_field_type& f), + MAYBE_UNUSED(CELL_LOC location), + MAYBE_UNUSED(ParallelTransform* pt)) { Mesh* localmesh = f.getMesh(); Coordinates::metric_field_type result; #ifdef COORDINATES_USE_3D - if (location == CELL_YLOW){ - auto f_aligned = f.getCoordinates() == nullptr ? - pt->toFieldAligned(f, "RGN_NOX") : toFieldAligned(f, "RGN_NOX"); + if (location == CELL_YLOW) { + auto f_aligned = f.getCoordinates() == nullptr ? pt->toFieldAligned(f, "RGN_NOX") + : toFieldAligned(f, "RGN_NOX"); result = interp_to(f_aligned, location, "RGN_NOBNDRY"); - result = result.getCoordinates() == nullptr ? - pt->fromFieldAligned(result, "RGN_NOBNDRY") : fromFieldAligned(result, "RGN_NOBNDRY"); + result = result.getCoordinates() == nullptr + ? pt->fromFieldAligned(result, "RGN_NOBNDRY") + : fromFieldAligned(result, "RGN_NOBNDRY"); } else #endif - { + { result = interp_to(f, location, "RGN_NOBNDRY"); } communicate(result); @@ -644,10 +661,10 @@ interpolateAndNeumann(MAYBE_UNUSED(const Coordinates::metric_field_type& f), MAY if (bndry->bx != 0) { // If bx!=0 we are on an x-boundary, inner if bx>0 and outer if bx<0 for (bndry->first(); !bndry->isDone(); bndry->next1d()) { - for (int i = 0; i < localmesh->xstart; i++){ - for (int z=0;zxstart; i++) { + for (int z = 0; z < result.getNz(); ++z) { result(bndry->x + i * bndry->bx, bndry->y, z) = - result(bndry->x + (i - 1) * bndry->bx, bndry->y - bndry->by, z); + result(bndry->x + (i - 1) * bndry->bx, bndry->y - bndry->by, z); } } } @@ -656,9 +673,9 @@ interpolateAndNeumann(MAYBE_UNUSED(const Coordinates::metric_field_type& f), MAY // If by!=0 we are on a y-boundary, upper if by>0 and lower if by<0 for (bndry->first(); !bndry->isDone(); bndry->next1d()) { for (int i = 0; i < localmesh->ystart; i++) { - for (int z=0;zx, bndry->y + i * bndry->by, z) = - result(bndry->x - bndry->bx, bndry->y + (i - 1) * bndry->by, z); + result(bndry->x - bndry->bx, bndry->y + (i - 1) * bndry->by, z); } } } @@ -668,7 +685,7 @@ interpolateAndNeumann(MAYBE_UNUSED(const Coordinates::metric_field_type& f), MAY // Set corner guard cells for (int i = 0; i < localmesh->xstart; i++) { for (int j = 0; j < localmesh->ystart; j++) { - for (int z=0;zLocalNy - 1 - j, z) = BoutNaN; result(localmesh->LocalNx - 1 - i, j, z) = BoutNaN; @@ -679,18 +696,19 @@ interpolateAndNeumann(MAYBE_UNUSED(const Coordinates::metric_field_type& f), MAY return result; } -} +} // namespace -Coordinates::Coordinates(Mesh *mesh, Options* options, const CELL_LOC loc, - const Coordinates* coords_in, bool force_interpolate_from_centre) - : dx(1., mesh), dy(1., mesh), dz(1., mesh), d1_dx(mesh), d1_dy(mesh), d1_dz(mesh), J(1., mesh), Bxy(1., mesh), +Coordinates::Coordinates(Mesh* mesh, Options* options, const CELL_LOC loc, + const Coordinates* coords_in, bool force_interpolate_from_centre) + : dx(1., mesh), dy(1., mesh), dz(1., mesh), d1_dx(mesh), d1_dy(mesh), d1_dz(mesh), + J(1., mesh), Bxy(1., mesh), // Identity metric tensor - g11(1., mesh), g22(1., mesh), g33(1., mesh), g12(0, mesh), g13(0, mesh), g23(0, mesh), - g_11(1., mesh), g_22(1., mesh), g_33(1., mesh), g_12(0, mesh), g_13(0, mesh), - g_23(0, mesh), G1_11(mesh), G1_22(mesh), G1_33(mesh), G1_12(mesh), G1_13(mesh), - G1_23(mesh), G2_11(mesh), G2_22(mesh), G2_33(mesh), G2_12(mesh), G2_13(mesh), - G2_23(mesh), G3_11(mesh), G3_22(mesh), G3_33(mesh), G3_12(mesh), G3_13(mesh), - G3_23(mesh), G1(mesh), G2(mesh), G3(mesh), ShiftTorsion(mesh), + g11(1., mesh), g22(1., mesh), g33(1., mesh), g12(0, mesh), g13(0, mesh), + g23(0, mesh), g_11(1., mesh), g_22(1., mesh), g_33(1., mesh), g_12(0, mesh), + g_13(0, mesh), g_23(0, mesh), G1_11(mesh), G1_22(mesh), G1_33(mesh), G1_12(mesh), + G1_13(mesh), G1_23(mesh), G2_11(mesh), G2_22(mesh), G2_33(mesh), G2_12(mesh), + G2_13(mesh), G2_23(mesh), G3_11(mesh), G3_22(mesh), G3_33(mesh), G3_12(mesh), + G3_13(mesh), G3_23(mesh), G1(mesh), G2(mesh), G3(mesh), ShiftTorsion(mesh), IntShiftTorsion(mesh), localmesh(mesh), location(loc) { std::string suffix = getLocationSuffix(location); @@ -728,32 +746,41 @@ Coordinates::Coordinates(Mesh *mesh, Options* options, const CELL_LOC loc, } setParallelTransform(options); - dz = interpolateAndExtrapolate(dz, location, extrapolate_x, extrapolate_y, false, transform.get()); + dz = interpolateAndExtrapolate(dz, location, extrapolate_x, extrapolate_y, false, + transform.get()); getAtLoc(mesh, dx, "dx", suffix, location, 1.0); - dx = interpolateAndExtrapolate(dx, location, extrapolate_x, extrapolate_y, false, transform.get()); + dx = interpolateAndExtrapolate(dx, location, extrapolate_x, extrapolate_y, false, + transform.get()); if (mesh->periodicX) { communicate(dx); } getAtLoc(mesh, dy, "dy", suffix, location, 1.0); - dy = interpolateAndExtrapolate(dy, location, extrapolate_x, extrapolate_y, false, transform.get()); + dy = interpolateAndExtrapolate(dy, location, extrapolate_x, extrapolate_y, false, + transform.get()); // grid data source has staggered fields, so read instead of interpolating // Diagonal components of metric tensor g^{ij} (default to 1) getAtLoc(mesh, g11, "g11", suffix, location, 1.0); - g11 = interpolateAndExtrapolate(g11, location, extrapolate_x, extrapolate_y, false, transform.get()); + g11 = interpolateAndExtrapolate(g11, location, extrapolate_x, extrapolate_y, false, + transform.get()); getAtLoc(mesh, g22, "g22", suffix, location, 1.0); - g22 = interpolateAndExtrapolate(g22, location, extrapolate_x, extrapolate_y, false, transform.get()); + g22 = interpolateAndExtrapolate(g22, location, extrapolate_x, extrapolate_y, false, + transform.get()); getAtLoc(mesh, g33, "g33", suffix, location, 1.0); - g33 = interpolateAndExtrapolate(g33, location, extrapolate_x, extrapolate_y, false, transform.get()); + g33 = interpolateAndExtrapolate(g33, location, extrapolate_x, extrapolate_y, false, + transform.get()); getAtLoc(mesh, g12, "g12", suffix, location, 0.0); - g12 = interpolateAndExtrapolate(g12, location, extrapolate_x, extrapolate_y, false, transform.get()); + g12 = interpolateAndExtrapolate(g12, location, extrapolate_x, extrapolate_y, false, + transform.get()); getAtLoc(mesh, g13, "g13", suffix, location, 0.0); - g13 = interpolateAndExtrapolate(g13, location, extrapolate_x, extrapolate_y, false, transform.get()); + g13 = interpolateAndExtrapolate(g13, location, extrapolate_x, extrapolate_y, false, + transform.get()); getAtLoc(mesh, g23, "g23", suffix, location, 0.0); - g23 = interpolateAndExtrapolate(g23, location, extrapolate_x, extrapolate_y, false, transform.get()); + g23 = interpolateAndExtrapolate(g23, location, extrapolate_x, extrapolate_y, false, + transform.get()); // Check input metrics // Diagonal metric components should be finite @@ -807,12 +834,18 @@ Coordinates::Coordinates(Mesh *mesh, Options* options, const CELL_LOC loc, } // More robust to extrapolate derived quantities directly, rather than // deriving from extrapolated covariant metric components - g_11 = interpolateAndExtrapolate(g_11, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_22 = interpolateAndExtrapolate(g_22, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_33 = interpolateAndExtrapolate(g_33, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_12 = interpolateAndExtrapolate(g_12, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_13 = interpolateAndExtrapolate(g_13, location, extrapolate_x, extrapolate_y, false, transform.get()); - g_23 = interpolateAndExtrapolate(g_23, location, extrapolate_x, extrapolate_y, false, transform.get()); + g_11 = interpolateAndExtrapolate(g_11, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_22 = interpolateAndExtrapolate(g_22, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_33 = interpolateAndExtrapolate(g_33, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_12 = interpolateAndExtrapolate(g_12, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_13 = interpolateAndExtrapolate(g_13, location, extrapolate_x, extrapolate_y, false, + transform.get()); + g_23 = interpolateAndExtrapolate(g_23, location, extrapolate_x, extrapolate_y, false, + transform.get()); // Check covariant metrics // Diagonal metric components should be finite @@ -842,7 +875,8 @@ Coordinates::Coordinates(Mesh *mesh, Options* options, const CELL_LOC loc, suffix.c_str()); J = Jcalc; } else { - J = interpolateAndExtrapolate(J, location, extrapolate_x, extrapolate_y, false, transform.get()); + J = interpolateAndExtrapolate(J, location, extrapolate_x, extrapolate_y, false, + transform.get()); // Compare calculated and loaded values output_warn.write("\tMaximum difference in J is %e\n", max(abs(J - Jcalc))); @@ -865,7 +899,8 @@ Coordinates::Coordinates(Mesh *mesh, Options* options, const CELL_LOC loc, " from metric tensor\n", suffix.c_str()); Bxy = Bcalc; } else { - Bxy = interpolateAndExtrapolate(Bxy, location, extrapolate_x, extrapolate_y, false, transform.get()); + Bxy = interpolateAndExtrapolate(Bxy, location, extrapolate_x, extrapolate_y, false, + transform.get()); output_warn.write("\tMaximum difference in Bxy is %e\n", max(abs(Bxy - Bcalc))); } @@ -875,23 +910,26 @@ Coordinates::Coordinates(Mesh *mesh, Options* options, const CELL_LOC loc, bout::checkPositive(Bxy, "Bxy" + suffix, "RGN_NOCORNERS"); checkStaggeredGet(mesh, "ShiftTorsion", suffix); - if (mesh->get(ShiftTorsion, "ShiftTorsion"+suffix, 0.0, false)) { + if (mesh->get(ShiftTorsion, "ShiftTorsion" + suffix, 0.0, false)) { output_warn.write("\tWARNING: No Torsion specified for zShift. Derivatives may not be correct\n"); ShiftTorsion = 0.0; } ShiftTorsion.setLocation(location); - ShiftTorsion = interpolateAndExtrapolate(ShiftTorsion, location, extrapolate_x, extrapolate_y, false, transform.get()); + ShiftTorsion = interpolateAndExtrapolate(ShiftTorsion, location, extrapolate_x, + extrapolate_y, false, transform.get()); ////////////////////////////////////////////////////// if (mesh->IncIntShear) { checkStaggeredGet(mesh, "IntShiftTorsion", suffix); - if (mesh->get(IntShiftTorsion, "IntShiftTorsion"+suffix, 0.0, false)) { + if (mesh->get(IntShiftTorsion, "IntShiftTorsion" + suffix, 0.0, false)) { output_warn.write("\tWARNING: No Integrated torsion specified\n"); IntShiftTorsion = 0.0; } IntShiftTorsion.setLocation(location); - IntShiftTorsion = interpolateAndExtrapolate(IntShiftTorsion, location, extrapolate_x, extrapolate_y, false, transform.get()); + IntShiftTorsion = + interpolateAndExtrapolate(IntShiftTorsion, location, extrapolate_x, + extrapolate_y, false, transform.get()); } else { // IntShiftTorsion will not be used, but set to zero to avoid uninitialized field IntShiftTorsion = 0.; @@ -899,38 +937,55 @@ Coordinates::Coordinates(Mesh *mesh, Options* options, const CELL_LOC loc, } else { // Interpolate fields from coords_in - if (isConst(coords_in->dz)){ + if (isConst(coords_in->dz)) { dz = coords_in->dz; dz.setLocation(location); } else { - throw BoutException("We are asked to transform dz to get dz before we have a transform, which might require dz!\nPlease provide a dz for the staggered quantity!"); + throw BoutException( + "We are asked to transform dz to get dz before we have a transform, which " + "might require dz!\nPlease provide a dz for the staggered quantity!"); } setParallelTransform(options); - dx = interpolateAndExtrapolate(coords_in->dx, location, true, true, false, transform.get()); - dy = interpolateAndExtrapolate(coords_in->dy, location, true, true, false, transform.get()); + dx = interpolateAndExtrapolate(coords_in->dx, location, true, true, false, + transform.get()); + dy = interpolateAndExtrapolate(coords_in->dy, location, true, true, false, + transform.get()); // not really needed - we have used dz already ... - dz = interpolateAndExtrapolate(coords_in->dz, location, true, true, false, transform.get()); + dz = interpolateAndExtrapolate(coords_in->dz, location, true, true, false, + transform.get()); // Diagonal components of metric tensor g^{ij} - g11 = interpolateAndExtrapolate(coords_in->g11, location, true, true, false, transform.get()); - g22 = interpolateAndExtrapolate(coords_in->g22, location, true, true, false, transform.get()); - g33 = interpolateAndExtrapolate(coords_in->g33, location, true, true, false, transform.get()); + g11 = interpolateAndExtrapolate(coords_in->g11, location, true, true, false, + transform.get()); + g22 = interpolateAndExtrapolate(coords_in->g22, location, true, true, false, + transform.get()); + g33 = interpolateAndExtrapolate(coords_in->g33, location, true, true, false, + transform.get()); // Off-diagonal elements. - g12 = interpolateAndExtrapolate(coords_in->g12, location, true, true, false, transform.get()); - g13 = interpolateAndExtrapolate(coords_in->g13, location, true, true, false, transform.get()); - g23 = interpolateAndExtrapolate(coords_in->g23, location, true, true, false, transform.get()); + g12 = interpolateAndExtrapolate(coords_in->g12, location, true, true, false, + transform.get()); + g13 = interpolateAndExtrapolate(coords_in->g13, location, true, true, false, + transform.get()); + g23 = interpolateAndExtrapolate(coords_in->g23, location, true, true, false, + transform.get()); // 3x3 matrix inversion can exaggerate small interpolation errors, so it is // more robust to interpolate and extrapolate derived quantities directly, // rather than deriving from interpolated/extrapolated covariant metric // components - g_11 = interpolateAndExtrapolate(coords_in->g_11, location, true, true, false, transform.get()); - g_22 = interpolateAndExtrapolate(coords_in->g_22, location, true, true, false, transform.get()); - g_33 = interpolateAndExtrapolate(coords_in->g_33, location, true, true, false, transform.get()); - g_12 = interpolateAndExtrapolate(coords_in->g_12, location, true, true, false, transform.get()); - g_13 = interpolateAndExtrapolate(coords_in->g_13, location, true, true, false, transform.get()); - g_23 = interpolateAndExtrapolate(coords_in->g_23, location, true, true, false, transform.get()); + g_11 = interpolateAndExtrapolate(coords_in->g_11, location, true, true, false, + transform.get()); + g_22 = interpolateAndExtrapolate(coords_in->g_22, location, true, true, false, + transform.get()); + g_33 = interpolateAndExtrapolate(coords_in->g_33, location, true, true, false, + transform.get()); + g_12 = interpolateAndExtrapolate(coords_in->g_12, location, true, true, false, + transform.get()); + g_13 = interpolateAndExtrapolate(coords_in->g_13, location, true, true, false, + transform.get()); + g_23 = interpolateAndExtrapolate(coords_in->g_23, location, true, true, false, + transform.get()); // Check input metrics // Diagonal metric components should be finite @@ -955,23 +1010,27 @@ Coordinates::Coordinates(Mesh *mesh, Options* options, const CELL_LOC loc, bout::checkFinite(g_13, "g_13", "RGN_NOCORNERS"); bout::checkFinite(g_23, "g_23", "RGN_NOCORNERS"); - J = interpolateAndExtrapolate(coords_in->J, location, true, true, false, transform.get()); - Bxy = interpolateAndExtrapolate(coords_in->Bxy, location, true, true, false, transform.get()); + J = interpolateAndExtrapolate(coords_in->J, location, true, true, false, + transform.get()); + Bxy = interpolateAndExtrapolate(coords_in->Bxy, location, true, true, false, + transform.get()); bout::checkFinite(J, "The Jacobian", "RGN_NOCORNERS"); bout::checkPositive(J, "The Jacobian", "RGN_NOCORNERS"); bout::checkFinite(Bxy, "Bxy", "RGN_NOCORNERS"); bout::checkPositive(Bxy, "Bxy", "RGN_NOCORNERS"); - ShiftTorsion = interpolateAndExtrapolate(coords_in->ShiftTorsion, location, true, true, false, transform.get()); + ShiftTorsion = interpolateAndExtrapolate(coords_in->ShiftTorsion, location, true, + true, false, transform.get()); if (mesh->IncIntShear) { - IntShiftTorsion = interpolateAndExtrapolate(coords_in->IntShiftTorsion, location, true, true, false, transform.get()); + IntShiftTorsion = interpolateAndExtrapolate(coords_in->IntShiftTorsion, location, + true, true, false, transform.get()); } } - - ShiftTorsion = interpolateAndNeumann(coords_in->ShiftTorsion, location, transform.get()); + ShiftTorsion = + interpolateAndNeumann(coords_in->ShiftTorsion, location, transform.get()); ////////////////////////////////////////////////////// /// Calculate Christoffel symbols. Needs communication @@ -1014,8 +1073,8 @@ void Coordinates::outputVars(Datafile& file) { int Coordinates::geometry(bool recalculate_staggered, bool force_interpolate_from_centre) { TRACE("Coordinates::geometry"); - communicate(dx, dy, dz, g11, g22, g33, g12, g13, g23, - g_11, g_22, g_33, g_12, g_13, g_23, J, Bxy); + communicate(dx, dy, dz, g11, g22, g33, g12, g13, g23, g_11, g_22, g_33, g_12, g_13, + g_23, J, Bxy); output_progress.write("Calculating differential geometry terms\n"); @@ -1055,7 +1114,6 @@ int Coordinates::geometry(bool recalculate_staggered, bout::checkFinite(g_13, "g_13", "RGN_NOCORNERS"); bout::checkFinite(g_23, "g_23", "RGN_NOCORNERS"); - // Calculate Christoffel symbol terms (18 independent values) // Note: This calculation is completely general: metric // tensor can be 2D or 3D. For 2D, all DDZ terms are zero @@ -1131,10 +1189,8 @@ int Coordinates::geometry(bool recalculate_staggered, // Communicate christoffel symbol terms output_progress.write("\tCommunicating connection terms\n"); - communicate(G1_11, G1_22, G1_33, G1_12, G1_13, G1_23, - G2_11, G2_22, G2_33, G2_12, G2_13, G2_23, - G3_11, G3_22, G3_33, G3_12, G3_13, G3_23, - G1, G2, G3); + communicate(G1_11, G1_22, G1_33, G1_12, G1_13, G1_23, G2_11, G2_22, G2_33, G2_12, G2_13, + G2_23, G3_11, G3_22, G3_33, G3_12, G3_13, G3_23, G1, G2, G3); // Set boundary guard cells of Christoffel symbol terms // Ideally, when location is staggered, we would set the upper/outer boundary point @@ -1176,7 +1232,8 @@ int Coordinates::geometry(bool recalculate_staggered, OPTION(Options::getRoot(), non_uniform, true); - Coordinates::metric_field_type d2x(localmesh), d2y(localmesh), d2z(localmesh); // d^2 x / d i^2 + Coordinates::metric_field_type d2x(localmesh), d2y(localmesh), + d2z(localmesh); // d^2 x / d i^2 // Read correction for non-uniform meshes std::string suffix = getLocationSuffix(location); @@ -1185,47 +1242,53 @@ int Coordinates::geometry(bool recalculate_staggered, bool extrapolate_x = not localmesh->sourceHasXBoundaryGuards(); bool extrapolate_y = not localmesh->sourceHasYBoundaryGuards(); - if (localmesh->get(d2x, "d2x"+suffix, 0.0, false)) { + if (localmesh->get(d2x, "d2x" + suffix, 0.0, false)) { output_warn.write( "\tWARNING: differencing quantity 'd2x' not found. Calculating from dx\n"); d1_dx = bout::derivatives::index::DDX(1. / dx); // d/di(1/dx) communicate(d1_dx); - d1_dx = interpolateAndExtrapolate(d1_dx, location, true, true, true, transform.get()); + d1_dx = + interpolateAndExtrapolate(d1_dx, location, true, true, true, transform.get()); } else { d2x.setLocation(location); // set boundary cells if necessary - d2x = interpolateAndExtrapolate(d2x, location, extrapolate_x, extrapolate_y, false, transform.get()); + d2x = interpolateAndExtrapolate(d2x, location, extrapolate_x, extrapolate_y, false, + transform.get()); d1_dx = -d2x / (dx * dx); } - if (localmesh->get(d2y, "d2y"+suffix, 0.0, false)) { + if (localmesh->get(d2y, "d2y" + suffix, 0.0, false)) { output_warn.write( "\tWARNING: differencing quantity 'd2y' not found. Calculating from dy\n"); d1_dy = indexDDY(1. / dy); // d/di(1/dy) communicate(d1_dy); - d1_dy = interpolateAndExtrapolate(d1_dy, location, true, true, true, transform.get()); + d1_dy = + interpolateAndExtrapolate(d1_dy, location, true, true, true, transform.get()); } else { d2y.setLocation(location); // set boundary cells if necessary - d2y = interpolateAndExtrapolate(d2y, location, extrapolate_x, extrapolate_y, false, transform.get()); + d2y = interpolateAndExtrapolate(d2y, location, extrapolate_x, extrapolate_y, false, + transform.get()); d1_dy = -d2y / (dy * dy); } #ifdef COORDINATES_USE_3D - if (localmesh->get(d2z, "d2z"+suffix, 0.0, false)) { + if (localmesh->get(d2z, "d2z" + suffix, 0.0, false)) { output_warn.write( "\tWARNING: differencing quantity 'd2z' not found. Calculating from dz\n"); d1_dz = bout::derivatives::index::DDZ(1. / dz); // d/di(1/dy) communicate(d1_dz); - d1_dz = interpolateAndExtrapolate(d1_dz, location, true, true, true, transform.get()); + d1_dz = + interpolateAndExtrapolate(d1_dz, location, true, true, true, transform.get()); } else { d2z.setLocation(location); // set boundary cells if necessary - d2z = interpolateAndExtrapolate(d2z, location, extrapolate_x, extrapolate_y, false, transform.get()); + d2z = interpolateAndExtrapolate(d2z, location, extrapolate_x, extrapolate_y, false, + transform.get()); d1_dz = -d2z / (dz * dz); } @@ -1239,7 +1302,8 @@ int Coordinates::geometry(bool recalculate_staggered, d1_dx = bout::derivatives::index::DDX(1. / dx); // d/di(1/dx) communicate(d1_dx); - d1_dx = interpolateAndExtrapolate(d1_dx, location, true, true, true, transform.get()); + d1_dx = + interpolateAndExtrapolate(d1_dx, location, true, true, true, transform.get()); } else { // Shift d2x to our location d2x = interpolateAndExtrapolate(d2x, location, true, true, false, transform.get()); @@ -1253,7 +1317,8 @@ int Coordinates::geometry(bool recalculate_staggered, d1_dy = indexDDY(1. / dy); // d/di(1/dy) communicate(d1_dy); - d1_dy = interpolateAndExtrapolate(d1_dy, location, true, true, true, transform.get()); + d1_dy = + interpolateAndExtrapolate(d1_dy, location, true, true, true, transform.get()); } else { // Shift d2y to our location d2y = interpolateAndExtrapolate(d2y, location, true, true, false, transform.get()); @@ -1268,7 +1333,8 @@ int Coordinates::geometry(bool recalculate_staggered, d1_dz = bout::derivatives::index::DDZ(1. / dz); // d/di(1/dy) communicate(d1_dz); - d1_dz = interpolateAndExtrapolate(d1_dz, location, true, true, true, transform.get()); + d1_dz = + interpolateAndExtrapolate(d1_dz, location, true, true, true, transform.get()); } else { // Shift d2z to our location d2z = interpolateAndExtrapolate(d2z, location, true, true, false, transform.get()); @@ -1421,24 +1487,25 @@ int Coordinates::jacobian() { J = 1. / sqrt(g); // More robust to extrapolate derived quantities directly, rather than // deriving from extrapolated covariant metric components - J = interpolateAndExtrapolate(J, location, extrapolate_x, extrapolate_y, false, transform.get()); + J = interpolateAndExtrapolate(J, location, extrapolate_x, extrapolate_y, false, + transform.get()); Bxy = sqrt(g_22) / J; - Bxy = interpolateAndExtrapolate(Bxy, location, extrapolate_x, extrapolate_y, false, transform.get()); + Bxy = interpolateAndExtrapolate(Bxy, location, extrapolate_x, extrapolate_y, false, + transform.get()); return 0; } namespace { // Utility function for fixing up guard cells of zShift - void fixZShiftGuards(Field2D& zShift) { +void fixZShiftGuards(Field2D& zShift) { auto localmesh = zShift.getMesh(); // extrapolate into boundary guard cells if necessary zShift = interpolateAndExtrapolate(zShift, zShift.getLocation(), - not localmesh->sourceHasXBoundaryGuards(), - not localmesh->sourceHasYBoundaryGuards(), - false); + not localmesh->sourceHasXBoundaryGuards(), + not localmesh->sourceHasYBoundaryGuards(), false); // make sure zShift has been communicated communicate(zShift); @@ -1486,9 +1553,9 @@ void Coordinates::setParallelTransform(Options* options) { if (localmesh->sourceHasVar("dx"+suffix)) { // Grid file has variables at this location, so should be able to read checkStaggeredGet(localmesh, "zShift", suffix); - if (localmesh->get(zShift, "zShift"+suffix, 0.0, false)) { + if (localmesh->get(zShift, "zShift" + suffix, 0.0, false)) { // No zShift variable. Try qinty in BOUT grid files - if (localmesh->get(zShift, "qinty"+suffix, 0.0, false)) { + if (localmesh->get(zShift, "qinty" + suffix, 0.0, false)) { // Failed to find either variable, cannot use ShiftedMetric throw BoutException("Could not read zShift"+suffix+" from grid file"); } @@ -1506,7 +1573,8 @@ void Coordinates::setParallelTransform(Options* options) { fixZShiftGuards(zShift_centre); - zShift = interpolateAndExtrapolate(zShift_centre, location, true, true, false, transform.get()); + zShift = interpolateAndExtrapolate(zShift_centre, location, true, true, false, + transform.get()); } fixZShiftGuards(zShift); @@ -1547,8 +1615,8 @@ Coordinates::metric_field_type Coordinates::DDX(const Field2D& f, CELL_LOC loc, ASSERT1(location == loc || loc == CELL_DEFAULT); return bout::derivatives::index::DDX(f, loc, method, region) / dx; } -Field3D Coordinates::DDX(const Field3D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { +Field3D Coordinates::DDX(const Field3D& f, CELL_LOC outloc, const std::string& method, + const std::string& region) { auto result = bout::derivatives::index::DDX(f, outloc, method, region); result /= dx; @@ -1568,9 +1636,9 @@ Coordinates::metric_field_type Coordinates::DDY(const Field2D& f, CELL_LOC loc, return bout::derivatives::index::DDY(f, loc, method, region) / dy; } -Field3D Coordinates::DDY(const Field3D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { - return indexDDY(f, outloc, method, region)/dy; +Field3D Coordinates::DDY(const Field3D& f, CELL_LOC outloc, const std::string& method, + const std::string& region) { + return indexDDY(f, outloc, method, region) / dy; }; Coordinates::metric_field_type Coordinates::DDZ(const Field2D& f, CELL_LOC loc, @@ -1583,17 +1651,17 @@ Coordinates::metric_field_type Coordinates::DDZ(const Field2D& f, CELL_LOC loc, } return zeroFrom(f).setLocation(loc); } -Field3D Coordinates::DDZ(const Field3D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { +Field3D Coordinates::DDZ(const Field3D& f, CELL_LOC outloc, const std::string& method, + const std::string& region) { return bout::derivatives::index::DDZ(f, outloc, method, region) / dz; }; ///////////////////////////////////////////////////////// // Parallel gradient -Coordinates::metric_field_type -Coordinates::Grad_par(const Field2D& var, MAYBE_UNUSED(CELL_LOC outloc), - const std::string& UNUSED(method)) { +Coordinates::metric_field_type Coordinates::Grad_par(const Field2D& var, + MAYBE_UNUSED(CELL_LOC outloc), + const std::string& UNUSED(method)) { TRACE("Coordinates::Grad_par( Field2D )"); ASSERT1(location == outloc || (outloc == CELL_DEFAULT && location == var.getLocation())); @@ -1630,8 +1698,8 @@ Field3D Coordinates::Vpar_Grad_par(const Field3D& v, const Field3D& f, CELL_LOC ///////////////////////////////////////////////////////// // Parallel divergence -Coordinates::metric_field_type -Coordinates::Div_par(const Field2D& f, CELL_LOC outloc, const std::string& method) { +Coordinates::metric_field_type Coordinates::Div_par(const Field2D& f, CELL_LOC outloc, + const std::string& method) { TRACE("Coordinates::Div_par( Field2D )"); ASSERT1(location == outloc || outloc == CELL_DEFAULT); @@ -1669,8 +1737,8 @@ Field3D Coordinates::Div_par(const Field3D& f, CELL_LOC outloc, // second parallel derivative (b dot Grad)(b dot Grad) // Note: For parallel Laplacian use Laplace_par -Coordinates::metric_field_type -Coordinates::Grad2_par2(const Field2D& f, CELL_LOC outloc, const std::string& method) { +Coordinates::metric_field_type Coordinates::Grad2_par2(const Field2D& f, CELL_LOC outloc, + const std::string& method) { TRACE("Coordinates::Grad2_par2( Field2D )"); ASSERT1(location == outloc || (outloc == CELL_DEFAULT && location == f.getLocation())); @@ -1711,8 +1779,8 @@ Field3D Coordinates::Grad2_par2(const Field3D& f, CELL_LOC outloc, #include // Delp2 uses same coefficients as inversion code -Coordinates::metric_field_type Coordinates::Delp2(const Field2D& f, - CELL_LOC outloc, bool UNUSED(useFFT)) { +Coordinates::metric_field_type Coordinates::Delp2(const Field2D& f, CELL_LOC outloc, + bool UNUSED(useFFT)) { TRACE("Coordinates::Delp2( Field2D )"); ASSERT1(location == outloc || outloc == CELL_DEFAULT); @@ -1777,7 +1845,7 @@ Field3D Coordinates::Delp2(const Field3D& f, CELL_LOC outloc, MAYBE_UNUSED(bool } } else #endif - { + { result = G1 * ::DDX(f, outloc) + G3 * ::DDZ(f, outloc) + g11 * ::D2DX2(f, outloc) + g33 * ::D2DZ2(f, outloc) + 2 * g13 * ::D2DXDZ(f, outloc); }; @@ -1862,18 +1930,18 @@ Field3D Coordinates::Laplace_par(const Field3D& f, CELL_LOC outloc) { // Full Laplacian operator on scalar field -Coordinates::metric_field_type Coordinates::Laplace(const Field2D& f, CELL_LOC outloc, - const std::string& dfdy_boundary_conditions, - const std::string& dfdy_dy_region) { +Coordinates::metric_field_type +Coordinates::Laplace(const Field2D& f, CELL_LOC outloc, + const std::string& dfdy_boundary_conditions, + const std::string& dfdy_dy_region) { TRACE("Coordinates::Laplace( Field2D )"); ASSERT1(location == outloc || outloc == CELL_DEFAULT); - auto result = - G1 * DDX(f, outloc) + G2 * DDY(f, outloc) + g11 * D2DX2(f, outloc) - + g22 * D2DY2(f, outloc) - + 2.0 * g12 - * D2DXDY(f, outloc, "DEFAULT", "RGN_NOBNDRY", - dfdy_boundary_conditions, dfdy_dy_region); + auto result = G1 * DDX(f, outloc) + G2 * DDY(f, outloc) + g11 * D2DX2(f, outloc) + + g22 * D2DY2(f, outloc) + + 2.0 * g12 + * D2DXDY(f, outloc, "DEFAULT", "RGN_NOBNDRY", + dfdy_boundary_conditions, dfdy_dy_region); return result; } @@ -1958,25 +2026,26 @@ Field2D Coordinates::Laplace_perpXY(const Field2D& A, const Field2D& f) { } Coordinates::metric_field_type Coordinates::indexDDY(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region){ + const std::string& method, + const std::string& region) { #ifdef COORDINATES_USE_3D - if (!f.hasParallelSlices()){ + if (!f.hasParallelSlices()) { const bool is_unaligned = (f.getDirectionY() == YDirectionType::Standard); const Field3D f_aligned = is_unaligned ? transform->toFieldAligned(f, "RGN_NOX") : f; Field3D result = bout::derivatives::index::DDY(f_aligned, outloc, method, region); - return (is_unaligned ? maybeFromFieldAligned(result, region) : result ); + return (is_unaligned ? maybeFromFieldAligned(result, region) : result); } #endif return bout::derivatives::index::DDY(f, outloc, method, region); } Field3D Coordinates::indexDDY(const Field3D& f, CELL_LOC outloc, - const std::string& method, const std::string& region){ + const std::string& method, const std::string& region) { #ifdef COORDINATES_USE_3D - if (!f.hasParallelSlices()){ + if (!f.hasParallelSlices()) { const bool is_unaligned = (f.getDirectionY() == YDirectionType::Standard); Field3D f_aligned; - if (transform->canToFromFieldAligned()){ + if (transform->canToFromFieldAligned()) { f_aligned = is_unaligned ? transform->toFieldAligned(f, "RGN_NOX") : f; } else { Field3D f_parallel = f; @@ -1984,7 +2053,7 @@ Field3D Coordinates::indexDDY(const Field3D& f, CELL_LOC outloc, return bout::derivatives::index::DDY(f_parallel, outloc, method, region); } Field3D result = bout::derivatives::index::DDY(f_aligned, outloc, method, region); - return (is_unaligned ? maybeFromFieldAligned(result, region) : result ); + return (is_unaligned ? maybeFromFieldAligned(result, region) : result); } #endif return bout::derivatives::index::DDY(f, outloc, method, region); diff --git a/src/mesh/data/gridfromfile.cxx b/src/mesh/data/gridfromfile.cxx index a8668c9ab1..78bb63d870 100644 --- a/src/mesh/data/gridfromfile.cxx +++ b/src/mesh/data/gridfromfile.cxx @@ -572,7 +572,7 @@ bool GridFile::readgrid_3dvar_fft(Mesh *m, const std::string &name, /// Expect the assertion to be true, in which case we probably don't /// need to pass m as can just use var.getMesh() BoutReal zlength = getConst(m->getCoordinates(var.getLocation())->zlength()); - + int zperiod = ROUND(TWOPI / zlength); /// Number of periods in 2pi // Print out which modes are going to be read in @@ -702,7 +702,7 @@ bool GridFile::readgrid_perpvar_fft(Mesh *m, const std::string &name, /// but don't do it yet as we don't assert that m == var.getMesh() /// Expect the assertion to be true, in which case we probably don't /// need to pass m as can just use var.getMesh() - BoutReal zlength =getConst(m->getCoordinates(var.getLocation())->zlength()); + BoutReal zlength = getConst(m->getCoordinates(var.getLocation())->zlength()); int zperiod = ROUND(TWOPI / zlength); /// Number of periods in 2pi diff --git a/src/mesh/difops.cxx b/src/mesh/difops.cxx index a895322a33..156b2ffdf3 100644 --- a/src/mesh/difops.cxx +++ b/src/mesh/difops.cxx @@ -1,27 +1,27 @@ /************************************************************************** -* Various differential operators defined on BOUT grid -* -************************************************************************** -* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu -* -* Contact: Ben Dudson, bd512@york.ac.uk -* -* This file is part of BOUT++. -* -* BOUT++ is free software: you can redistribute it and/or modify -* it under the terms of the GNU Lesser General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* BOUT++ is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public License -* along with BOUT++. If not, see . -* -**************************************************************************/ + * Various differential operators defined on BOUT grid + * + ************************************************************************** + * Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu + * + * Contact: Ben Dudson, bd512@york.ac.uk + * + * This file is part of BOUT++. + * + * BOUT++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * BOUT++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with BOUT++. If not, see . + * + **************************************************************************/ #include #include @@ -46,20 +46,20 @@ *******************************************************************************/ Coordinates::metric_field_type Grad_par(const Field2D& var, CELL_LOC outloc, - const std::string& method) { + const std::string& method) { return var.getCoordinates(outloc)->Grad_par(var, outloc, method); } -Coordinates::metric_field_type -Grad_par(const Field2D& var, const std::string& method, CELL_LOC outloc) { +Coordinates::metric_field_type Grad_par(const Field2D& var, const std::string& method, + CELL_LOC outloc) { return var.getCoordinates(outloc)->Grad_par(var, outloc, method); } -Field3D Grad_par(const Field3D &var, CELL_LOC outloc, const std::string &method) { +Field3D Grad_par(const Field3D& var, CELL_LOC outloc, const std::string& method) { return var.getCoordinates(outloc)->Grad_par(var, outloc, method); } -Field3D Grad_par(const Field3D &var, const std::string &method, CELL_LOC outloc) { +Field3D Grad_par(const Field3D& var, const std::string& method, CELL_LOC outloc) { return var.getCoordinates(outloc)->Grad_par(var, outloc, method); } @@ -74,7 +74,7 @@ Field3D Grad_par(const Field3D &var, const std::string &method, CELL_LOC outloc) * grid-points at the corners. *******************************************************************************/ -Field3D Grad_parP(const Field3D &apar, const Field3D &f) { +Field3D Grad_parP(const Field3D& apar, const Field3D& f) { ASSERT1_FIELDS_COMPATIBLE(apar, f); ASSERT1(f.hasParallelSlices()); @@ -92,21 +92,27 @@ Field3D Grad_parP(const Field3D &apar, const Field3D &f) { for(int x=1;x<=mesh->LocalNx-2;x++) for(int y=1;y<=mesh->LocalNy-2;y++) for(int z=0;zdy(x, y+1, z) + metric->dy(x, y, z) + 0.5*metric->dy(x, y-1, z)); + gys(x, y, z) = (f.yup()(x, y + 1, z) - f.ydown()(x, y - 1, z)) + / (0.5 * metric->dy(x, y + 1, z) + metric->dy(x, y, z) + + 0.5 * metric->dy(x, y - 1, z)); } for(int x=1;x<=mesh->LocalNx-2;x++) { for(int y=mesh->ystart;y<=mesh->yend;y++) { for(int z=0;zg_22(x, y, z)); + BoutReal by = 1. / sqrt(metric->g_22(x, y, z)); // Z indices zm and zp int zm = (z - 1 + ncz) % ncz; int zp = (z + 1) % ncz; // bx = -DDZ(apar) - BoutReal bx = (apar(x, y, zm) - apar(x, y, zp))/(0.5*metric->dz(x, y, zm) + metric->dz(x, y, z) + 0.5*metric->dz(x, y, zp)); + BoutReal bx = (apar(x, y, zm) - apar(x, y, zp)) + / (0.5 * metric->dz(x, y, zm) + metric->dz(x, y, z) + + 0.5 * metric->dz(x, y, zp)); // bz = DDX(f) - BoutReal bz = (apar(x+1, y, z) - apar(x-1, y, z))/(0.5*metric->dx(x-1, y, z) + metric->dx(x, y, z) + 0.5*metric->dx(x+1, y, z)); + BoutReal bz = (apar(x + 1, y, z) - apar(x - 1, y, z)) + / (0.5 * metric->dx(x - 1, y, z) + metric->dx(x, y, z) + + 0.5 * metric->dx(x + 1, y, z)); // Now calculate (bx*d/dx + by*d/dy + bz*d/dz) f @@ -118,40 +124,56 @@ Field3D Grad_parP(const Field3D &apar, const Field3D &f) { BoutReal fp, fm; // X differencing - fp = f(x+1, y, z) - + (0.25*dl/metric->dz(x, y, z)) * bz * (f(x+1, y, zm) - f(x+1, y, zp)) - - 0.5*dl * by * gys(x+1, y, z); + fp = + f(x + 1, y, z) + + (0.25 * dl / metric->dz(x, y, z)) * bz * (f(x + 1, y, zm) - f(x + 1, y, zp)) + - 0.5 * dl * by * gys(x + 1, y, z); - fm = f(x-1, y, z) - + (0.25*dl/metric->dz(x, y, z)) * bz * (f(x-1, y, zm) - f(x-1, y, zp)) - - 0.5*dl * by * gys(x-1, y, z); + fm = + f(x - 1, y, z) + + (0.25 * dl / metric->dz(x, y, z)) * bz * (f(x - 1, y, zm) - f(x - 1, y, zp)) + - 0.5 * dl * by * gys(x - 1, y, z); - result(x, y, z) = bx * (fp - fm) / (0.5*metric->dx(x-1, y, z) + metric->dx(x, y, z) + 0.5*metric->dx(x+1, y, z)); + result(x, y, z) = bx * (fp - fm) + / (0.5 * metric->dx(x - 1, y, z) + metric->dx(x, y, z) + + 0.5 * metric->dx(x + 1, y, z)); // Z differencing - fp = f(x, y, zp) - + (0.25*dl/metric->dx(x, y, z)) * bx * (f(x-1, y, zp) - f(x+1, y, zp)) - - 0.5*dl * by * gys(x, y, zp); + fp = + f(x, y, zp) + + (0.25 * dl / metric->dx(x, y, z)) * bx * (f(x - 1, y, zp) - f(x + 1, y, zp)) + - 0.5 * dl * by * gys(x, y, zp); - fm = f(x, y, zm) - + (0.25*dl/metric->dx(x, y, z)) * bx * (f(x-1,y,zm) - f(x+1, y, zm)) - - 0.5*dl * by * gys(x, y, zm); + fm = + f(x, y, zm) + + (0.25 * dl / metric->dx(x, y, z)) * bx * (f(x - 1, y, zm) - f(x + 1, y, zm)) + - 0.5 * dl * by * gys(x, y, zm); - result(x, y, z) += bz * (fp - fm) / (0.5*metric->dz(x, y, zm) + metric->dz(x, y, z) + 0.5*metric->dz(x, y, zp)); + result(x, y, z) += bz * (fp - fm) + / (0.5 * metric->dz(x, y, zm) + metric->dz(x, y, z) + + 0.5 * metric->dz(x, y, zp)); // Y differencing - fp = f.yup()(x,y+1,z) - - 0.5*dl * bx * (f.yup()(x+1, y+1, z) - f.yup()(x-1, y+1, z))/(0.5*metric->dx(x-1, y, z) + metric->dx(x, y, z) + 0.5*metric->dx(x+1, y, z)) + fp = f.yup()(x, y + 1, z) + - 0.5 * dl * bx * (f.yup()(x + 1, y + 1, z) - f.yup()(x - 1, y + 1, z)) + / (0.5 * metric->dx(x - 1, y, z) + metric->dx(x, y, z) + + 0.5 * metric->dx(x + 1, y, z)) - + (0.25*dl/metric->dz(x,y,z)) * bz * (f.yup()(x,y+1,zm) - f.yup()(x,y+1,zp)); + + (0.25 * dl / metric->dz(x, y, z)) * bz + * (f.yup()(x, y + 1, zm) - f.yup()(x, y + 1, zp)); - fm = f.ydown()(x,y-1,z) - - 0.5*dl * bx * (f.ydown()(x+1, y-1, z) - f.ydown()(x-1, y-1, z))/(0.5*metric->dx(x-1, y, z) + metric->dx(x, y, z) + 0.5*metric->dx(x+1, y, z)) - + (0.25*dl/metric->dz(x,y,z)) * bz * (f.ydown()(x,y-1,zm) - f.ydown()(x,y-1,zp)); + fm = f.ydown()(x, y - 1, z) + - 0.5 * dl * bx * (f.ydown()(x + 1, y - 1, z) - f.ydown()(x - 1, y - 1, z)) + / (0.5 * metric->dx(x - 1, y, z) + metric->dx(x, y, z) + + 0.5 * metric->dx(x + 1, y, z)) + + (0.25 * dl / metric->dz(x, y, z)) * bz + * (f.ydown()(x, y - 1, zm) - f.ydown()(x, y - 1, zp)); - result(x,y,z) += by * (fp - fm) / (0.5*metric->dy(x,y-1, z) + metric->dy(x,y,z) + 0.5*metric->dy(x,y+1,z)); + result(x, y, z) += by * (fp - fm) + / (0.5 * metric->dy(x, y - 1, z) + metric->dy(x, y, z) + + 0.5 * metric->dy(x, y + 1, z)); } } } @@ -167,22 +189,22 @@ Field3D Grad_parP(const Field3D &apar, const Field3D &f) { *******************************************************************************/ Coordinates::metric_field_type Vpar_Grad_par(const Field2D& v, const Field2D& f, - CELL_LOC outloc, - const std::string& method) { + CELL_LOC outloc, const std::string& method) { return f.getCoordinates(outloc)->Vpar_Grad_par(v, f, outloc, method); } Coordinates::metric_field_type Vpar_Grad_par(const Field2D& v, const Field2D& f, - const std::string& method, - CELL_LOC outloc) { + const std::string& method, CELL_LOC outloc) { return f.getCoordinates(outloc)->Vpar_Grad_par(v, f, outloc, method); } -Field3D Vpar_Grad_par(const Field3D &v, const Field3D &f, CELL_LOC outloc, const std::string &method) { +Field3D Vpar_Grad_par(const Field3D& v, const Field3D& f, CELL_LOC outloc, + const std::string& method) { return f.getCoordinates(outloc)->Vpar_Grad_par(v, f, outloc, method); } -Field3D Vpar_Grad_par(const Field3D &v, const Field3D &f, const std::string &method, CELL_LOC outloc) { +Field3D Vpar_Grad_par(const Field3D& v, const Field3D& f, const std::string& method, + CELL_LOC outloc) { return f.getCoordinates(outloc)->Vpar_Grad_par(v, f, outloc, method); } @@ -191,7 +213,7 @@ Field3D Vpar_Grad_par(const Field3D &v, const Field3D &f, const std::string &met * parallel divergence operator B \partial_{||} (F/B) *******************************************************************************/ Coordinates::metric_field_type Div_par(const Field2D& f, CELL_LOC outloc, - const std::string& method) { + const std::string& method) { return f.getCoordinates(outloc)->Div_par(f, outloc, method); } @@ -200,11 +222,11 @@ Coordinates::metric_field_type Div_par(const Field2D& f, const std::string& meth return f.getCoordinates(outloc)->Div_par(f, outloc, method); } -Field3D Div_par(const Field3D &f, CELL_LOC outloc, const std::string &method) { +Field3D Div_par(const Field3D& f, CELL_LOC outloc, const std::string& method) { return f.getCoordinates(outloc)->Div_par(f, outloc, method); } -Field3D Div_par(const Field3D &f, const std::string &method, CELL_LOC outloc) { +Field3D Div_par(const Field3D& f, const std::string& method, CELL_LOC outloc) { return f.getCoordinates(outloc)->Div_par(f, outloc, method); } @@ -251,7 +273,8 @@ Field3D Div_par(const Field3D& f, const Field3D& v) { //////// Flux methods -Field3D Div_par_flux(const Field3D &v, const Field3D &f, CELL_LOC outloc, const std::string &method) { +Field3D Div_par_flux(const Field3D& v, const Field3D& f, CELL_LOC outloc, + const std::string& method) { Coordinates *metric = f.getCoordinates(outloc); auto Bxy_floc = f.getCoordinates()->Bxy; @@ -269,7 +292,8 @@ Field3D Div_par_flux(const Field3D &v, const Field3D &f, CELL_LOC outloc, const return metric->Bxy*FDDY(v, f_B, outloc, method)/sqrt(metric->g_22); } -Field3D Div_par_flux(const Field3D &v, const Field3D &f, const std::string &method, CELL_LOC outloc) { +Field3D Div_par_flux(const Field3D& v, const Field3D& f, const std::string& method, + CELL_LOC outloc) { return Div_par_flux(v,f, outloc, method); } @@ -283,11 +307,11 @@ Field3D Div_par_flux(const Field3D &v, const Field3D &f, const std::string &meth *******************************************************************************/ Coordinates::metric_field_type Grad2_par2(const Field2D& f, CELL_LOC outloc, - const std::string& method) { + const std::string& method) { return f.getCoordinates(outloc)->Grad2_par2(f, outloc, method); } -Field3D Grad2_par2(const Field3D &f, CELL_LOC outloc, const std::string &method) { +Field3D Grad2_par2(const Field3D& f, CELL_LOC outloc, const std::string& method) { return f.getCoordinates(outloc)->Grad2_par2(f, outloc, method); } @@ -297,28 +321,28 @@ Field3D Grad2_par2(const Field3D &f, CELL_LOC outloc, const std::string &method) *******************************************************************************/ Coordinates::metric_field_type Div_par_K_Grad_par(BoutReal kY, const Field2D& f, - CELL_LOC outloc) { + CELL_LOC outloc) { return kY*Grad2_par2(f, outloc); } -Field3D Div_par_K_Grad_par(BoutReal kY, const Field3D &f, CELL_LOC outloc) { +Field3D Div_par_K_Grad_par(BoutReal kY, const Field3D& f, CELL_LOC outloc) { return kY*Grad2_par2(f, outloc); } -Coordinates::metric_field_type -Div_par_K_Grad_par(const Field2D& kY, const Field2D& f, CELL_LOC outloc) { +Coordinates::metric_field_type Div_par_K_Grad_par(const Field2D& kY, const Field2D& f, + CELL_LOC outloc) { return interp_to(kY, outloc)*Grad2_par2(f, outloc) + Div_par(kY, outloc)*Grad_par(f, outloc); } -Field3D Div_par_K_Grad_par(const Field2D &kY, const Field3D &f, CELL_LOC outloc) { +Field3D Div_par_K_Grad_par(const Field2D& kY, const Field3D& f, CELL_LOC outloc) { return interp_to(kY, outloc)*Grad2_par2(f, outloc) + Div_par(kY, outloc)*Grad_par(f, outloc); } -Field3D Div_par_K_Grad_par(const Field3D &kY, const Field2D &f, CELL_LOC outloc) { +Field3D Div_par_K_Grad_par(const Field3D& kY, const Field2D& f, CELL_LOC outloc) { return interp_to(kY, outloc)*Grad2_par2(f, outloc) + Div_par(kY, outloc)*Grad_par(f, outloc); } -Field3D Div_par_K_Grad_par(const Field3D &kY, const Field3D &f, CELL_LOC outloc) { +Field3D Div_par_K_Grad_par(const Field3D& kY, const Field3D& f, CELL_LOC outloc) { return interp_to(kY, outloc)*Grad2_par2(f, outloc) + Div_par(kY, outloc)*Grad_par(f, outloc); } @@ -347,32 +371,32 @@ FieldPerp Delp2(const FieldPerp& f, CELL_LOC outloc, bool useFFT) { *******************************************************************************/ Coordinates::metric_field_type Laplace_perp(const Field2D& f, CELL_LOC outloc, - const std::string& dfdy_boundary_condition, - const std::string& dfdy_region) { + const std::string& dfdy_boundary_condition, + const std::string& dfdy_region) { return Laplace(f, outloc, dfdy_boundary_condition, dfdy_region) - Laplace_par(f, outloc); } Field3D Laplace_perp(const Field3D& f, CELL_LOC outloc, - const std::string& dfdy_boundary_condition, - const std::string& dfdy_region) { + const std::string& dfdy_boundary_condition, + const std::string& dfdy_region) { return Laplace(f, outloc, dfdy_boundary_condition, dfdy_region) - Laplace_par(f, outloc); } /******************************************************************************* -* LaplacePar -* Full parallel Laplacian operator on scalar field -* -* LaplacePar(f) = Div( b (b dot Grad(f)) ) -* -*******************************************************************************/ + * LaplacePar + * Full parallel Laplacian operator on scalar field + * + * LaplacePar(f) = Div( b (b dot Grad(f)) ) + * + *******************************************************************************/ Coordinates::metric_field_type Laplace_par(const Field2D& f, CELL_LOC outloc) { return f.getCoordinates(outloc)->Laplace_par(f, outloc); } -Field3D Laplace_par(const Field3D &f, CELL_LOC outloc) { +Field3D Laplace_par(const Field3D& f, CELL_LOC outloc) { return f.getCoordinates(outloc)->Laplace_par(f, outloc); } @@ -382,15 +406,15 @@ Field3D Laplace_par(const Field3D &f, CELL_LOC outloc) { *******************************************************************************/ Coordinates::metric_field_type Laplace(const Field2D& f, CELL_LOC outloc, - const std::string& dfdy_boundary_condition, - const std::string& dfdy_region) { + const std::string& dfdy_boundary_condition, + const std::string& dfdy_region) { return f.getCoordinates(outloc)->Laplace(f, outloc, dfdy_boundary_condition, dfdy_region); } Field3D Laplace(const Field3D& f, CELL_LOC outloc, - const std::string& dfdy_boundary_condition, - const std::string& dfdy_region) { + const std::string& dfdy_boundary_condition, + const std::string& dfdy_region) { return f.getCoordinates(outloc)->Laplace(f, outloc, dfdy_boundary_condition, dfdy_region); } @@ -410,8 +434,8 @@ Field2D Laplace_perpXY(const Field2D& A, const Field2D& f) { * Used for ExB terms and perturbed B field using A_|| *******************************************************************************/ -Coordinates::metric_field_type b0xGrad_dot_Grad(const Field2D& phi, - const Field2D& A, CELL_LOC outloc) { +Coordinates::metric_field_type b0xGrad_dot_Grad(const Field2D& phi, const Field2D& A, + CELL_LOC outloc) { TRACE("b0xGrad_dot_Grad( Field2D , Field2D )"); @@ -441,7 +465,7 @@ Coordinates::metric_field_type b0xGrad_dot_Grad(const Field2D& phi, return result; } -Field3D b0xGrad_dot_Grad(const Field2D &phi, const Field3D &A, CELL_LOC outloc) { +Field3D b0xGrad_dot_Grad(const Field2D& phi, const Field3D& A, CELL_LOC outloc) { TRACE("b0xGrad_dot_Grad( Field2D , Field3D )"); if (outloc == CELL_DEFAULT) outloc = A.getLocation(); @@ -481,7 +505,7 @@ Field3D b0xGrad_dot_Grad(const Field2D &phi, const Field3D &A, CELL_LOC outloc) return result; } -Field3D b0xGrad_dot_Grad(const Field3D &p, const Field2D &A, CELL_LOC outloc) { +Field3D b0xGrad_dot_Grad(const Field3D& p, const Field2D& A, CELL_LOC outloc) { TRACE("b0xGrad_dot_Grad( Field3D , Field2D )"); if (outloc == CELL_DEFAULT) outloc = A.getLocation(); @@ -514,7 +538,7 @@ Field3D b0xGrad_dot_Grad(const Field3D &p, const Field2D &A, CELL_LOC outloc) { return result; } -Field3D b0xGrad_dot_Grad(const Field3D &phi, const Field3D &A, CELL_LOC outloc) { +Field3D b0xGrad_dot_Grad(const Field3D& phi, const Field3D& A, CELL_LOC outloc) { TRACE("b0xGrad_dot_Grad( Field3D , Field3D )"); if (outloc == CELL_DEFAULT) outloc = A.getLocation(); @@ -553,8 +577,7 @@ Field3D b0xGrad_dot_Grad(const Field3D &phi, const Field3D &A, CELL_LOC outloc) return result; } - -Field3D Div_Perp_Lap_FV(const Field3D &a, const Field3D &f, CELL_LOC outloc) { +Field3D Div_Perp_Lap_FV(const Field3D& a, const Field3D& f, CELL_LOC outloc) { Field3D result = 0.0; @@ -572,62 +595,79 @@ Field3D Div_Perp_Lap_FV(const Field3D &a, const Field3D &f, CELL_LOC outloc) { // | nD | // o --- gD --- o // - Coordinates *coords = a.getCoordinates(outloc); - Mesh *mesh = f.getMesh(); + Coordinates* coords = a.getCoordinates(outloc); + Mesh* mesh = f.getMesh(); - for(int i=mesh->xstart;i<=mesh->xend;i++) - for(int j=mesh->ystart;j<=mesh->yend;j++) - for(int k=0;kLocalNz;k++) { + for (int i = mesh->xstart; i <= mesh->xend; i++) + for (int j = mesh->ystart; j <= mesh->yend; j++) + for (int k = 0; k < mesh->LocalNz; k++) { // wrap k-index around as Z is (currently) periodic. - int kp = (k+1) % (mesh->LocalNz); - int km = (k-1+mesh->LocalNz) % (mesh->LocalNz); + int kp = (k + 1) % (mesh->LocalNz); + int km = (k - 1 + mesh->LocalNz) % (mesh->LocalNz); // Calculate gradients on cell faces -- assumes constant grid spacing - BoutReal gR = (coords->g11(i,j,k) + coords->g11(i+1,j,k)) * (f(i+1,j,k) - f(i,j,k))/(coords->dx(i+1,j,k) + coords->dx(i,j,k)) - + 0.5*(coords->g13(i,j,k) + coords->g13(i+1,j,k))*(f(i+1,j,kp) - f(i+1,j,km) + f(i,j,kp) - f(i,j,km))/(4.*coords->dz(i,j,k)); - - BoutReal gL = (coords->g11(i-1,j,k) + coords->g11(i,j,k))*(f(i,j,k) - f(i-1,j,k))/(coords->dx(i-1,j,k) + coords->dx(i,j,k)) - + 0.5*(coords->g13(i-1,j,k) + coords->g13(i,j,k))*(f(i-1,j,kp) - f(i-1,j,km) + f(i,j,kp) - f(i,j,km))/(4*coords->dz(i,j,k)); - - BoutReal gD = coords->g13(i,j,k)*(f(i+1,j,km) - f(i-1,j,km) + f(i+1,j,k) - f(i-1,j,k))/(4.*coords->dx(i,j,k)) - + coords->g33(i,j,k)*(f(i,j,k) - f(i,j,km))/coords->dz(i,j,k); - - BoutReal gU = coords->g13(i,j,k)*(f(i+1,j,kp) - f(i-1,j,kp) + f(i+1,j,k) - f(i-1,j,k))/(4.*coords->dx(i,j,k)) - + coords->g33(i,j,k)*(f(i,j,kp) - f(i,j,k))/coords->dz(i,j,k); - + BoutReal gR = + (coords->g11(i, j, k) + coords->g11(i + 1, j, k)) + * (f(i + 1, j, k) - f(i, j, k)) + / (coords->dx(i + 1, j, k) + coords->dx(i, j, k)) + + 0.5 * (coords->g13(i, j, k) + coords->g13(i + 1, j, k)) + * (f(i + 1, j, kp) - f(i + 1, j, km) + f(i, j, kp) - f(i, j, km)) + / (4. * coords->dz(i, j, k)); + + BoutReal gL = + (coords->g11(i - 1, j, k) + coords->g11(i, j, k)) + * (f(i, j, k) - f(i - 1, j, k)) + / (coords->dx(i - 1, j, k) + coords->dx(i, j, k)) + + 0.5 * (coords->g13(i - 1, j, k) + coords->g13(i, j, k)) + * (f(i - 1, j, kp) - f(i - 1, j, km) + f(i, j, kp) - f(i, j, km)) + / (4 * coords->dz(i, j, k)); + + BoutReal gD = + coords->g13(i, j, k) + * (f(i + 1, j, km) - f(i - 1, j, km) + f(i + 1, j, k) - f(i - 1, j, k)) + / (4. * coords->dx(i, j, k)) + + coords->g33(i, j, k) * (f(i, j, k) - f(i, j, km)) / coords->dz(i, j, k); + + BoutReal gU = + coords->g13(i, j, k) + * (f(i + 1, j, kp) - f(i - 1, j, kp) + f(i + 1, j, k) - f(i - 1, j, k)) + / (4. * coords->dx(i, j, k)) + + coords->g33(i, j, k) * (f(i, j, kp) - f(i, j, k)) / coords->dz(i, j, k); // Flow right - BoutReal flux = gR * 0.25*(coords->J(i+1,j,k) + coords->J(i,j,k)) *(a(i+1,j,k) + a(i,j,k)); - result(i,j,k) += flux / (coords->dx(i,j,k)*coords->J(i,j,k)); + BoutReal flux = gR * 0.25 * (coords->J(i + 1, j, k) + coords->J(i, j, k)) + * (a(i + 1, j, k) + a(i, j, k)); + result(i, j, k) += flux / (coords->dx(i, j, k) * coords->J(i, j, k)); // Flow left - flux = gL * 0.25*(coords->J(i-1,j,k) + coords->J(i,j,k)) *(a(i-1,j,k) + a(i,j,k)); - result(i,j,k) -= flux / (coords->dx(i,j,k)*coords->J(i,j,k)); - + flux = gL * 0.25 * (coords->J(i - 1, j, k) + coords->J(i, j, k)) + * (a(i - 1, j, k) + a(i, j, k)); + result(i, j, k) -= flux / (coords->dx(i, j, k) * coords->J(i, j, k)); // Flow up - flux = gU * 0.25*(coords->J(i,j,k) + coords->J(i,j,kp)) *(a(i,j,k) + a(i,j,kp)); - result(i,j,k) += flux / (coords->dz(i,j,k) * coords->J(i,j,k)); + flux = gU * 0.25 * (coords->J(i, j, k) + coords->J(i, j, kp)) + * (a(i, j, k) + a(i, j, kp)); + result(i, j, k) += flux / (coords->dz(i, j, k) * coords->J(i, j, k)); // Flow down - flux = gD * 0.25*(coords->J(i,j,km) + coords->J(i,j,k)) *(a(i,j,km) + a(i,j,k)); - result(i,j,k) += flux / (coords->dz(i,j,k) * coords->J(i,j,k)); + flux = gD * 0.25 * (coords->J(i, j, km) + coords->J(i, j, k)) + * (a(i, j, km) + a(i, j, k)); + result(i, j, k) += flux / (coords->dz(i, j, k) * coords->J(i, j, k)); } return result; } - /******************************************************************************* * Poisson bracket * Terms of form b0 x Grad(f) dot Grad(g) / B = [f, g] *******************************************************************************/ Coordinates::metric_field_type bracket(const Field2D& f, const Field2D& g, - BRACKET_METHOD method, CELL_LOC outloc, - Solver* UNUSED(solver)) { + BRACKET_METHOD method, CELL_LOC outloc, + Solver* UNUSED(solver)) { TRACE("bracket(Field2D, Field2D)"); ASSERT1_FIELDS_COMPATIBLE(f, g); @@ -649,8 +689,8 @@ Coordinates::metric_field_type bracket(const Field2D& f, const Field2D& g, return result; } -Field3D bracket(const Field3D &f, const Field2D &g, BRACKET_METHOD method, - CELL_LOC outloc, Solver *solver) { +Field3D bracket(const Field3D& f, const Field2D& g, BRACKET_METHOD method, + CELL_LOC outloc, Solver* solver) { TRACE("bracket(Field3D, Field2D)"); ASSERT1_FIELDS_COMPATIBLE(f, g); @@ -685,7 +725,7 @@ Field3D bracket(const Field3D &f, const Field2D &g, BRACKET_METHOD method, BoutReal gp, gm; // Vx = DDZ(f) - BoutReal vx = (f(x,y,zp) - f(x,y,zm))/(2.*metric->dz(x,y,z)); + BoutReal vx = (f(x, y, zp) - f(x, y, zm)) / (2. * metric->dz(x, y, z)); // Set stability condition solver->setMaxTimestep(metric->dx(x, y, z) / (fabs(vx) + 1e-16)); @@ -789,36 +829,35 @@ Field3D bracket(const Field3D &f, const Field2D &g, BRACKET_METHOD method, BOUT_OMP(parallel for) for(int jx=mesh->xstart;jx<=mesh->xend;jx++){ for(int jy=mesh->ystart;jy<=mesh->yend;jy++){ - const BoutReal partialFactor = 1.0/(12 * metric->dz(jx,jy)); - const BoutReal spacingFactor = partialFactor / metric->dx(jx,jy); + const BoutReal partialFactor = 1.0 / (12 * metric->dz(jx, jy)); + const BoutReal spacingFactor = partialFactor / metric->dx(jx, jy); for (int jz = 0; jz < mesh->LocalNz; jz++) { const int jzp = jz+1 < ncz ? jz + 1 : 0; - //Above is alternative to const int jzp = (jz + 1) % ncz; - const int jzm = jz-1 >= 0 ? jz - 1 : ncz-1; - //Above is alternative to const int jzmTmp = (jz - 1 + ncz) % ncz; + // Above is alternative to const int jzp = (jz + 1) % ncz; + const int jzm = jz - 1 >= 0 ? jz - 1 : ncz - 1; + // Above is alternative to const int jzmTmp = (jz - 1 + ncz) % ncz; // J++ = DDZ(f)*DDX(g) - DDX(f)*DDZ(g) - BoutReal Jpp = ( (f(jx,jy,jzp) - f(jx,jy,jzm))* - (g(jx+1,jy) - g(jx-1,jy)) - - (f(jx+1,jy,jz) - f(jx-1,jy,jz))* - (g(jx,jy) - g(jx,jy)) ); + BoutReal Jpp = + ((f(jx, jy, jzp) - f(jx, jy, jzm)) * (g(jx + 1, jy) - g(jx - 1, jy)) + - (f(jx + 1, jy, jz) - f(jx - 1, jy, jz)) * (g(jx, jy) - g(jx, jy))); // J+x - BoutReal Jpx = ( g(jx+1,jy)*(f(jx+1,jy,jzp)-f(jx+1,jy,jzm)) - - g(jx-1,jy)*(f(jx-1,jy,jzp)-f(jx-1,jy,jzm)) - - g(jx,jy)*(f(jx+1,jy,jzp)-f(jx-1,jy,jzp)) + - g(jx,jy)*(f(jx+1,jy,jzm)-f(jx-1,jy,jzm))); + BoutReal Jpx = (g(jx + 1, jy) * (f(jx + 1, jy, jzp) - f(jx + 1, jy, jzm)) + - g(jx - 1, jy) * (f(jx - 1, jy, jzp) - f(jx - 1, jy, jzm)) + - g(jx, jy) * (f(jx + 1, jy, jzp) - f(jx - 1, jy, jzp)) + + g(jx, jy) * (f(jx + 1, jy, jzm) - f(jx - 1, jy, jzm))); // Jx+ - BoutReal Jxp = ( g(jx+1,jy)*(f(jx,jy,jzp)-f(jx+1,jy,jz)) - - g(jx-1,jy)*(f(jx-1,jy,jz)-f(jx,jy,jzm)) - - g(jx-1,jy)*(f(jx,jy,jzp)-f(jx-1,jy,jz)) + - g(jx+1,jy)*(f(jx+1,jy,jz)-f(jx,jy,jzm))); + BoutReal Jxp = (g(jx + 1, jy) * (f(jx, jy, jzp) - f(jx + 1, jy, jz)) + - g(jx - 1, jy) * (f(jx - 1, jy, jz) - f(jx, jy, jzm)) + - g(jx - 1, jy) * (f(jx, jy, jzp) - f(jx - 1, jy, jz)) + + g(jx + 1, jy) * (f(jx + 1, jy, jz) - f(jx, jy, jzm))); result(jx,jy,jz) = (Jpp + Jpx + Jxp) * spacingFactor; - } } } + } #else throw BoutException("BRACKET_ARAKAWA_OLD not valid with 3D metrics yet."); #endif @@ -837,8 +876,8 @@ Field3D bracket(const Field3D &f, const Field2D &g, BRACKET_METHOD method, return result; } -Field3D bracket(const Field2D &f, const Field3D &g, BRACKET_METHOD method, - CELL_LOC outloc, Solver *solver) { +Field3D bracket(const Field2D& f, const Field3D& g, BRACKET_METHOD method, + CELL_LOC outloc, Solver* solver) { TRACE("bracket(Field2D, Field3D)"); ASSERT1_FIELDS_COMPATIBLE(f, g); @@ -874,8 +913,8 @@ Field3D bracket(const Field2D &f, const Field3D &g, BRACKET_METHOD method, return result; } -Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, - CELL_LOC outloc, Solver *solver) { +Field3D bracket(const Field3D& f, const Field3D& g, BRACKET_METHOD method, + CELL_LOC outloc, Solver* solver) { TRACE("Field3D, Field3D"); ASSERT1_FIELDS_COMPATIBLE(f, g); @@ -921,13 +960,13 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, int zp = (z + 1) % ncz; // Vx = DDZ(f) - vx(x,z) = (f(x,y,zp) - f(x,y,zm))/(2.*metric->dz(x,y,z)); + vx(x, z) = (f(x, y, zp) - f(x, y, zm)) / (2. * metric->dz(x, y, z)); // Vz = -DDX(f) vz(x,z) = (f(x-1,y,z) - f(x+1,y,z))/(0.5*metric->dx(x-1,y) + metric->dx(x,y) + 0.5*metric->dx(x+1,y)); // Set stability condition solver->setMaxTimestep(fabs(metric->dx(x,y)) / (fabs(vx(x,z)) + 1e-16)); - solver->setMaxTimestep(metric->dz(x,y) / (fabs(vz(x,z)) + 1e-16)); + solver->setMaxTimestep(metric->dz(x, y) / (fabs(vz(x, z)) + 1e-16)); } } @@ -942,26 +981,26 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, // X differencing if (vx(x, z) > 0.0) { - gp = g(x, y, z) + - (0.5 * dt / metric->dz(x,y)) * ((vz(x, z) > 0) - ? vz(x, z) * (g(x, y, zm) - g(x, y, z)) - : vz(x, z) * (g(x, y, z) - g(x, y, zp))); + gp = g(x, y, z) + + (0.5 * dt / metric->dz(x, y)) + * ((vz(x, z) > 0) ? vz(x, z) * (g(x, y, zm) - g(x, y, z)) + : vz(x, z) * (g(x, y, z) - g(x, y, zp))); - gm = g(x - 1, y, z) + - (0.5 * dt / metric->dz(x,y)) * - ((vz(x, z) > 0) ? vz(x, z) * (g(x - 1, y, zm) - g(x - 1, y, z)) - : vz(x, z) * (g(x - 1, y, z) - g(x - 1, y, zp))); + gm = g(x - 1, y, z) + + (0.5 * dt / metric->dz(x, y)) + * ((vz(x, z) > 0) ? vz(x, z) * (g(x - 1, y, zm) - g(x - 1, y, z)) + : vz(x, z) * (g(x - 1, y, z) - g(x - 1, y, zp))); } else { - gp = g(x + 1, y, z) + - (0.5 * dt / metric->dz(x,y)) * - ((vz(x, z) > 0) ? vz(x, z) * (g(x + 1, y, zm) - g(x + 1, y, z)) - : vz[x][z] * (g(x + 1, y, z) - g(x + 1, y, zp))); - - gm = g(x, y, z) + - (0.5 * dt / metric->dz(x,y)) * ((vz(x, z) > 0) - ? vz(x, z) * (g(x, y, zm) - g(x, y, z)) - : vz(x, z) * (g(x, y, z) - g(x, y, zp))); + gp = g(x + 1, y, z) + + (0.5 * dt / metric->dz(x, y)) + * ((vz(x, z) > 0) ? vz(x, z) * (g(x + 1, y, zm) - g(x + 1, y, z)) + : vz[x][z] * (g(x + 1, y, z) - g(x + 1, y, zp))); + + gm = g(x, y, z) + + (0.5 * dt / metric->dz(x, y)) + * ((vz(x, z) > 0) ? vz(x, z) * (g(x, y, zm) - g(x, y, z)) + : vz(x, z) * (g(x, y, z) - g(x, y, zp))); } result(x, y, z) = vx(x, z) * (gp - gm) / metric->dx(x, y); @@ -989,7 +1028,7 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, : vx(x, z) * (g(x, y, z) - g(x + 1, y, z))); } - result(x, y, z) += vz(x, z) * (gp - gm) / metric->dz(x,y); + result(x, y, z) += vz(x, z) * (gp - gm) / metric->dz(x, y); } } #else @@ -1008,7 +1047,7 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, BOUT_FOR(j2D, result.getRegion2D("RGN_NOBNDRY")) { #ifndef COORDINATES_USE_3D - const BoutReal spacingFactor = 1.0/(12 * metric->dz[j2D] * metric->dx[j2D]); + const BoutReal spacingFactor = 1.0 / (12 * metric->dz[j2D] * metric->dx[j2D]); #endif const int jy = j2D.y(), jx = j2D.x(); const int xm = jx - 1, xp = jx + 1; @@ -1025,7 +1064,8 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, const int jzp = 1; const int jzm = ncz - 1; #ifdef COORDINATES_USE_3D - const BoutReal spacingFactor = 1.0 / (12 * metric->dz(jx, jy, jz) * metric->dx(jx, jy, jz)); + const BoutReal spacingFactor = + 1.0 / (12 * metric->dz(jx, jy, jz) * metric->dx(jx, jy, jz)); #endif // J++ = DDZ(f)*DDX(g) - DDX(f)*DDZ(g) @@ -1047,7 +1087,8 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, for (int jz = 1; jz < mesh->LocalNz - 1; jz++) { #ifdef COORDINATES_USE_3D - const BoutReal spacingFactor = 1.0 / (12 * metric->dz(jx, jy, jz) * metric->dx(jx, jy, jz)); + const BoutReal spacingFactor = + 1.0 / (12 * metric->dz(jx, jy, jz) * metric->dx(jx, jy, jz)); #endif const int jzp = jz + 1; const int jzm = jz - 1; @@ -1074,7 +1115,8 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, const int jzp = 0; const int jzm = ncz - 2; #ifdef COORDINATES_USE_3D - const BoutReal spacingFactor = 1.0 / (12 * metric->dz(jx, jy, jz) * metric->dx(jx, jy, jz)); + const BoutReal spacingFactor = + 1.0 / (12 * metric->dz(jx, jy, jz) * metric->dx(jx, jy, jz)); #endif // J++ = DDZ(f)*DDX(g) - DDX(f)*DDZ(g) @@ -1110,8 +1152,8 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, for(int jx=mesh->xstart;jx<=mesh->xend;jx++){ for(int jy=mesh->ystart;jy<=mesh->yend;jy++){ #ifndef COORDINATES_USE_3D - const BoutReal spacingFactor = 1.0 / (12 * metric->dz(jx,jy) - * metric->dx(jx, jy)); + const BoutReal spacingFactor = + 1.0 / (12 * metric->dz(jx, jy) * metric->dx(jx, jy)); #endif const BoutReal *Fxm = f_temp(jx-1, jy); const BoutReal *Fx = f_temp(jx, jy); @@ -1121,29 +1163,27 @@ Field3D bracket(const Field3D &f, const Field3D &g, BRACKET_METHOD method, const BoutReal *Gxp = g_temp(jx+1, jy); for (int jz = 0; jz < mesh->LocalNz; jz++) { #ifdef COORDINATES_USE_3D - const BoutReal spacingFactor = 1.0 / (12 * metric->dz(jx, jy, jz) - * metric->dx(jx, jy, jz)); + const BoutReal spacingFactor = + 1.0 / (12 * metric->dz(jx, jy, jz) * metric->dx(jx, jy, jz)); #endif const int jzp = jz+1 < ncz ? jz + 1 : 0; - //Above is alternative to const int jzp = (jz + 1) % ncz; - const int jzm = jz-1 >= 0 ? jz - 1 : ncz-1; - //Above is alternative to const int jzm = (jz - 1 + ncz) % ncz; + // Above is alternative to const int jzp = (jz + 1) % ncz; + const int jzm = jz - 1 >= 0 ? jz - 1 : ncz - 1; + // Above is alternative to const int jzm = (jz - 1 + ncz) % ncz; // J++ = DDZ(f)*DDX(g) - DDX(f)*DDZ(g) - BoutReal Jpp = ((Fx[jzp] - Fx[jzm])*(Gxp[jz] - Gxm[jz]) - - (Fxp[jz] - Fxm[jz])*(Gx[jzp] - Gx[jzm])); + BoutReal Jpp = ((Fx[jzp] - Fx[jzm]) * (Gxp[jz] - Gxm[jz]) + - (Fxp[jz] - Fxm[jz]) * (Gx[jzp] - Gx[jzm])); // J+x - BoutReal Jpx = ( Gxp[jz]*(Fxp[jzp]-Fxp[jzm]) - - Gxm[jz]*(Fxm[jzp]-Fxm[jzm]) - - Gx[jzp]*(Fxp[jzp]-Fxm[jzp]) + - Gx[jzm]*(Fxp[jzm]-Fxm[jzm])) ; + BoutReal Jpx = + (Gxp[jz] * (Fxp[jzp] - Fxp[jzm]) - Gxm[jz] * (Fxm[jzp] - Fxm[jzm]) + - Gx[jzp] * (Fxp[jzp] - Fxm[jzp]) + Gx[jzm] * (Fxp[jzm] - Fxm[jzm])); // Jx+ - BoutReal Jxp = ( Gxp[jzp]*(Fx[jzp]-Fxp[jz]) - - Gxm[jzm]*(Fxm[jz]-Fx[jzm]) - - Gxm[jzp]*(Fx[jzp]-Fxm[jz]) + - Gxp[jzm]*(Fxp[jz]-Fx[jzm])); + BoutReal Jxp = + (Gxp[jzp] * (Fx[jzp] - Fxp[jz]) - Gxm[jzm] * (Fxm[jz] - Fx[jzm]) + - Gxm[jzp] * (Fx[jzp] - Fxm[jz]) + Gxp[jzm] * (Fxp[jz] - Fx[jzm])); result(jx, jy, jz) = (Jpp + Jpx + Jxp) * spacingFactor; } diff --git a/src/mesh/fv_ops.cxx b/src/mesh/fv_ops.cxx index 4c56040b24..3d989ff6da 100644 --- a/src/mesh/fv_ops.cxx +++ b/src/mesh/fv_ops.cxx @@ -36,13 +36,16 @@ namespace FV { for(int j=mesh->ystart;j<=mesh->yend;j++) { for(int k=0;kLocalNz;k++) { // Calculate flux from i to i+1 - - BoutReal fout = 0.5*(a(i,j,k) + a(i+1,j,k)) * (coord->J(i,j,k)*coord->g11(i,j,k) + coord->J(i+1,j,k)*coord->g11(i+1,j,k)) * - (f(i+1,j,k) - f(i,j,k))/(coord->dx(i,j,k) + coord->dx(i+1,j,k)); - - result(i,j,k) += fout / (coord->dx(i,j,k)*coord->J(i,j,k)); - result(i+1,j,k) -= fout / (coord->dx(i+1,j,k)*coord->J(i+1,j,k)); - } + + BoutReal fout = 0.5 * (a(i, j, k) + a(i + 1, j, k)) + * (coord->J(i, j, k) * coord->g11(i, j, k) + + coord->J(i + 1, j, k) * coord->g11(i + 1, j, k)) + * (f(i + 1, j, k) - f(i, j, k)) + / (coord->dx(i, j, k) + coord->dx(i + 1, j, k)); + + result(i, j, k) += fout / (coord->dx(i, j, k) * coord->J(i, j, k)); + result(i + 1, j, k) -= fout / (coord->dx(i + 1, j, k) * coord->J(i + 1, j, k)); + } } @@ -87,39 +90,41 @@ namespace FV { int kp = (k + 1) % mesh->LocalNz; int km = (k - 1 + mesh->LocalNz) % mesh->LocalNz; - BoutReal coef = - 0.5 * (coord->g_23(i, j, k) / SQ(coord->J(i, j, k) * coord->Bxy(i, j, k)) + - coord->g_23(i, j + 1, k) / SQ(coord->J(i, j + 1, k) * coord->Bxy(i, j + 1, k))); - + BoutReal coef = + 0.5 + * (coord->g_23(i, j, k) / SQ(coord->J(i, j, k) * coord->Bxy(i, j, k)) + + coord->g_23(i, j + 1, k) + / SQ(coord->J(i, j + 1, k) * coord->Bxy(i, j + 1, k))); // Calculate Z derivative at y boundary - BoutReal dfdz = 0.25 * (fc(i, j, kp) - fc(i, j, km) + fup(i, j + 1, kp) - - fup(i, j + 1, km)) / - coord->dz(i, j, k);// is this at right location? + BoutReal dfdz = + 0.25 * (fc(i, j, kp) - fc(i, j, km) + fup(i, j + 1, kp) - fup(i, j + 1, km)) + / coord->dz(i, j, k); // is this at right location? // Y derivative - BoutReal dfdy = 2. * (fup(i, j + 1, k) - fc(i, j, k)) / - (coord->dy(i, j + 1, k) + coord->dy(i, j, k)); + BoutReal dfdy = 2. * (fup(i, j + 1, k) - fc(i, j, k)) + / (coord->dy(i, j + 1, k) + coord->dy(i, j, k)); - BoutReal fout = 0.25 * (ac(i, j, k) + aup(i, j + 1, k)) * - (coord->J(i, j, k) * coord->g23(i, j, k) + - coord->J(i, j + 1, k) * coord->g23(i, j + 1, k)) * - (dfdz - coef * dfdy); + BoutReal fout = 0.25 * (ac(i, j, k) + aup(i, j + 1, k)) + * (coord->J(i, j, k) * coord->g23(i, j, k) + + coord->J(i, j + 1, k) * coord->g23(i, j + 1, k)) + * (dfdz - coef * dfdy); yzresult(i, j, k) = fout / (coord->dy(i, j, k) * coord->J(i, j, k)); // Calculate flux between j and j-1 - dfdz = 0.25 * (fc(i, j, kp) - fc(i, j, km) + fdown(i, j - 1, kp) - - fdown(i, j - 1, km)) / - coord->dz(i,j,k);// is this at right location? + dfdz = + 0.25 + * (fc(i, j, kp) - fc(i, j, km) + fdown(i, j - 1, kp) - fdown(i, j - 1, km)) + / coord->dz(i, j, k); // is this at right location? - dfdy = 2. * (fc(i, j, k) - fdown(i, j - 1, k)) / - (coord->dy(i, j, k) + coord->dy(i, j - 1, k)); + dfdy = 2. * (fc(i, j, k) - fdown(i, j - 1, k)) + / (coord->dy(i, j, k) + coord->dy(i, j - 1, k)); - fout = 0.25 * (ac(i, j, k) + adown(i, j - 1, k)) * - (coord->J(i, j, k) * coord->g23(i, j, k) + - coord->J(i, j - 1, k) * coord->g23(i, j - 1, k)) * - (dfdz - coef * dfdy); + fout = 0.25 * (ac(i, j, k) + adown(i, j - 1, k)) + * (coord->J(i, j, k) * coord->g23(i, j, k) + + coord->J(i, j - 1, k) * coord->g23(i, j - 1, k)) + * (dfdz - coef * dfdy); yzresult(i, j, k) -= fout / (coord->dy(i, j, k) * coord->J(i, j, k)); } @@ -135,21 +140,22 @@ namespace FV { // Calculate flux between k and k+1 int kp = (k + 1) % mesh->LocalNz; - // Coefficient in front of df/dy term - BoutReal coef = coord->g_23(i, j, k) / (coord->dy(i, j + 1, k) + 2. * coord->dy(i, j, k) + - coord->dy(i, j - 1, k)) / - SQ(coord->J(i, j, k) * coord->Bxy(i, j, k)); - - BoutReal fout = 0.5 * (ac(i, j, k) + ac(i, j, kp)) * coord->g33(i, j, k) * - ( // df/dz - (fc(i, j, kp) - fc(i, j, k)) / coord->dz(i, j, k) - // - g_yz * df/dy / SQ(J*B) - - - coef * (fup(i, j + 1, k) + fup(i, j + 1, kp) - - fdown(i, j - 1, k) - fdown(i, j - 1, kp))); - - yzresult(i, j, k) += fout / coord->dz(i,j,k); - yzresult(i, j, kp) -= fout / coord->dz(i,j,kp); + // Coefficient in front of df/dy term + BoutReal coef = coord->g_23(i, j, k) + / (coord->dy(i, j + 1, k) + 2. * coord->dy(i, j, k) + + coord->dy(i, j - 1, k)) + / SQ(coord->J(i, j, k) * coord->Bxy(i, j, k)); + + BoutReal fout = 0.5 * (ac(i, j, k) + ac(i, j, kp)) * coord->g33(i, j, k) + * ( // df/dz + (fc(i, j, kp) - fc(i, j, k)) / coord->dz(i, j, k) + // - g_yz * df/dy / SQ(J*B) + - coef + * (fup(i, j + 1, k) + fup(i, j + 1, kp) + - fdown(i, j - 1, k) - fdown(i, j - 1, kp))); + + yzresult(i, j, k) += fout / coord->dz(i, j, k); + yzresult(i, j, kp) -= fout / coord->dz(i, j, kp); } } } @@ -314,9 +320,9 @@ namespace FV { for (int k = 0; k < mesh->LocalNz; k++) { // Right boundary common factors - const BoutReal common_factor = 0.25 - * (coord->dy(i, j, k) + coord->dy(i, j + 1, k)) - * (coord->J(i, j, j) + coord->J(i, j + 1, k)); + const BoutReal common_factor = + 0.25 * (coord->dy(i, j, k) + coord->dy(i, j + 1, k)) + * (coord->J(i, j, j) + coord->J(i, j + 1, k)); const BoutReal factor_rc = common_factor / (coord->J(i, j, k) * coord->dy(i, j, k)); @@ -325,14 +331,10 @@ namespace FV { // Not on domain boundary // 3rd derivative at right cell boundary - - const BoutReal d3fdx3 = ( - f(i,j+2,k) - - 3.*f(i,j+1,k) - + 3.*f(i,j, k) - - f(i,j-1,k) - ); - + + const BoutReal d3fdx3 = (f(i, j + 2, k) - 3. * f(i, j + 1, k) + + 3. * f(i, j, k) - f(i, j - 1, k)); + result(i,j, k) += d3fdx3 * factor_rc; result(i,j+1,k) -= d3fdx3 * factor_rp; } @@ -342,22 +344,22 @@ namespace FV { for(int k=0;kLocalNz;k++) { // Right boundary common factors - const BoutReal common_factor = 0.25 - * (coord->dy(i, j, k) + coord->dy(i, j + 1, k)) - * (coord->J(i, j, j) + coord->J(i, j + 1, k)); + const BoutReal common_factor = + 0.25 * (coord->dy(i, j, k) + coord->dy(i, j + 1, k)) + * (coord->J(i, j, j) + coord->J(i, j + 1, k)); const BoutReal factor_rc = common_factor / (coord->J(i, j, k) * coord->dy(i, j, k)); const BoutReal factor_rp = common_factor / (coord->J(i, j + 1, k) * coord->dy(i, j + 1, k)); - const BoutReal d3fdx3 = -((16. / 5) * 0.5 * - (f(i, j + 1, k) + f(i, j, k)) // Boundary value f_b - - 6. * f(i, j, k) // f_0 - + 4. * f(i, j - 1, k) // f_1 - - (6. / 5) * f(i, j - 2, k) // f_2 - ); - + const BoutReal d3fdx3 = + -((16. / 5) * 0.5 * (f(i, j + 1, k) + f(i, j, k)) // Boundary value f_b + - 6. * f(i, j, k) // f_0 + + 4. * f(i, j - 1, k) // f_1 + - (6. / 5) * f(i, j - 2, k) // f_2 + ); + result(i,j, k) += d3fdx3 * factor_rc; result(i,j+1,k) -= d3fdx3 * factor_rp; } @@ -372,9 +374,9 @@ namespace FV { if ( j != mesh->ystart || !has_lower_boundary ) { for(int k=0;kLocalNz;k++) { - const BoutReal common_factor = 0.25 - * (coord->dy(i, j, k) + coord->dy(i, j + 1, k)) - * (coord->J(i, j, k) + coord->J(i, j - 1, k)); + const BoutReal common_factor = + 0.25 * (coord->dy(i, j, k) + coord->dy(i, j + 1, k)) + * (coord->J(i, j, k) + coord->J(i, j - 1, k)); const BoutReal factor_lc = common_factor / (coord->J(i, j, k) * coord->dy(i, j, k)); @@ -382,20 +384,18 @@ namespace FV { common_factor / (coord->J(i, j - 1, k) * coord->dy(i, j - 1, k)); // Not on a domain boundary - const BoutReal d3fdx3 = (f(i, j + 1, k) - - 3. * f(i, j, k) - + 3. * f(i, j - 1, k) - - f(i, j - 2, k)); - + const BoutReal d3fdx3 = (f(i, j + 1, k) - 3. * f(i, j, k) + + 3. * f(i, j - 1, k) - f(i, j - 2, k)); + result(i, j , k) -= d3fdx3 * factor_lc; result(i, j - 1, k) += d3fdx3 * factor_lm; } } else { // On a domain (Y) boundary for(int k=0;kLocalNz;k++) { - const BoutReal common_factor = 0.25 - * (coord->dy(i, j, k) + coord->dy(i, j + 1, k)) - * (coord->J(i, j, k) + coord->J(i, j - 1, k)); + const BoutReal common_factor = + 0.25 * (coord->dy(i, j, k) + coord->dy(i, j + 1, k)) + * (coord->J(i, j, k) + coord->J(i, j - 1, k)); const BoutReal factor_lc = common_factor / (coord->J(i, j, k) * coord->dy(i, j, k)); @@ -406,7 +406,7 @@ namespace FV { + 6. * f(i, j, k) // f_0 - 4. * f(i, j + 1, k) // f_1 + (6. / 5) * f(i, j + 2, k) // f_2 - ); + ); result(i, j , k) -= d3fdx3 * factor_lc; result(i, j - 1, k) += d3fdx3 * factor_lm; diff --git a/src/mesh/mesh.cxx b/src/mesh/mesh.cxx index 6d8c6a06ef..a4c5a44936 100644 --- a/src/mesh/mesh.cxx +++ b/src/mesh/mesh.cxx @@ -536,14 +536,13 @@ void Mesh::createDefaultRegions(){ (getRegion3D("RGN_NOBNDRY") + getRegion3D("RGN_XGUARDS") + getRegion3D("RGN_YGUARDS") + getRegion3D("RGN_ZGUARDS")).unique()); - addRegion3D("RGN_UPPER_Y_THIN", - Region(xstart, xend, yend + 1, yend + 1, 0, LocalNz - 1, LocalNy, LocalNz, - maxregionblocksize)); - addRegion3D("RGN_LOWER_Y_THIN", - Region(xstart, xend, ystart + 1, ystart + 1, 0, LocalNz - 1, LocalNy, LocalNz, - maxregionblocksize)); - - + addRegion3D("RGN_UPPER_Y_THIN", + Region(xstart, xend, yend + 1, yend + 1, 0, LocalNz - 1, LocalNy, + LocalNz, maxregionblocksize)); + addRegion3D("RGN_LOWER_Y_THIN", + Region(xstart, xend, ystart + 1, ystart + 1, 0, LocalNz - 1, LocalNy, + LocalNz, maxregionblocksize)); + //2D regions addRegion2D("RGN_ALL", Region(0, LocalNx - 1, 0, LocalNy - 1, 0, 0, LocalNy, 1, maxregionblocksize)); @@ -572,12 +571,10 @@ void Mesh::createDefaultRegions(){ (getRegion2D("RGN_NOBNDRY") + getRegion2D("RGN_XGUARDS") + getRegion2D("RGN_YGUARDS") + getRegion2D("RGN_ZGUARDS")).unique()); - addRegion2D("RGN_UPPER_Y_THIN", - Region(xstart, xend, yend + 1, yend + 1, 0, -1, LocalNy, 1, - maxregionblocksize)); - addRegion2D("RGN_LOWER_Y_THIN", - Region(xstart, xend, ystart + 1, ystart + 1, 0, -1, LocalNy, 1, - maxregionblocksize)); + addRegion2D("RGN_UPPER_Y_THIN", Region(xstart, xend, yend + 1, yend + 1, 0, -1, + LocalNy, 1, maxregionblocksize)); + addRegion2D("RGN_LOWER_Y_THIN", Region(xstart, xend, ystart + 1, ystart + 1, 0, + -1, LocalNy, 1, maxregionblocksize)); // Perp regions addRegionPerp("RGN_ALL", Region(0, LocalNx - 1, 0, 0, 0, LocalNz - 1, 1, diff --git a/src/mesh/parallel/fci.cxx b/src/mesh/parallel/fci.cxx index fdd379e1e9..df73924988 100644 --- a/src/mesh/parallel/fci.cxx +++ b/src/mesh/parallel/fci.cxx @@ -210,7 +210,6 @@ FCIMap::FCIMap(Mesh& mesh, Options& options, int offset_, BoundaryRegionPar* bou if ((t_z < 0.0) || (t_z > 1.0)) throw BoutException("t_z={:e} out of range at ({:d},{:d},{:d})", t_z, x, y, z); - //---------------------------------------- // Boundary stuff // @@ -262,11 +261,14 @@ FCIMap::FCIMap(Mesh& mesh, Options& options, int offset_, BoundaryRegionPar* bou // Invert 2x2 matrix to get change in index BoutReal dx = (dZ_dz * dR - dR_dz * dZ) / det; BoutReal dz = (dR_dx * dZ - dZ_dx * dR) / det; - boundary->add_point(x, y, z, - x + dx, y + 0.5*offset, z + dz, // Intersection point in local index space - 0.5*coord.dy(x,y,z), //sqrt( SQ(dR) + SQ(dZ) ), // Distance to intersection - PI // Right-angle intersection - ); + boundary->add_point( + x, y, z, x + dx, y + 0.5 * offset, + z + dz, // Intersection point in local index space + 0.5 + * coord.dy(x, y, + z), // sqrt( SQ(dR) + SQ(dZ) ), // Distance to intersection + PI // Right-angle intersection + ); } } } diff --git a/src/sys/boutexception.cxx b/src/sys/boutexception.cxx index 1f25c32ea9..edede438c9 100644 --- a/src/sys/boutexception.cxx +++ b/src/sys/boutexception.cxx @@ -54,7 +54,8 @@ std::string BoutException::getBacktrace() const { if (dladdr(trace[i],&info)){ // Additionally, check whether this is the default offset for an executable if (info.dli_fbase != reinterpret_cast(0x400000)) - ptr=reinterpret_cast(reinterpret_cast(trace[i])-reinterpret_cast(info.dli_fbase)); + ptr = reinterpret_cast(reinterpret_cast(trace[i]) + - reinterpret_cast(info.dli_fbase)); } // Pipe stderr to /dev/null to avoid cluttering output diff --git a/src/sys/derivs.cxx b/src/sys/derivs.cxx index f17f1d853f..6b18615a80 100644 --- a/src/sys/derivs.cxx +++ b/src/sys/derivs.cxx @@ -58,7 +58,8 @@ ////////////// X DERIVATIVE ///////////////// -Field3D DDX(const Field3D &f, CELL_LOC outloc, const std::string &method, const std::string& region) { +Field3D DDX(const Field3D& f, CELL_LOC outloc, const std::string& method, + const std::string& region) { return f.getCoordinates(outloc)->DDX(f, outloc, method, region); } @@ -75,8 +76,8 @@ Field3D DDY(const Field3D &f, CELL_LOC outloc, const std::string &method, / f.getCoordinates(outloc)->dy; } -Coordinates::metric_field_type DDY(const Field2D &f, CELL_LOC outloc, const std::string &method, - const std::string& region) { +Coordinates::metric_field_type DDY(const Field2D& f, CELL_LOC outloc, + const std::string& method, const std::string& region) { return f.getCoordinates(outloc)->DDY(f, outloc, method, region); } @@ -88,8 +89,9 @@ Field3D DDZ(const Field3D &f, CELL_LOC outloc, const std::string &method, / f.getCoordinates(outloc)->dz; } -Coordinates::metric_field_type DDZ(const Field2D &f, CELL_LOC UNUSED(outloc), const std::string - &UNUSED(method), const std::string& UNUSED(region)) { +Coordinates::metric_field_type DDZ(const Field2D& f, CELL_LOC UNUSED(outloc), + const std::string& UNUSED(method), + const std::string& UNUSED(region)) { auto tmp = Field2D(0., f.getMesh()); tmp.setLocation(f.getLocation()); return tmp; @@ -166,7 +168,8 @@ Field3D D2DX2(const Field3D &f, CELL_LOC outloc, const std::string &method, } Coordinates::metric_field_type D2DX2(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { + const std::string& method, + const std::string& region) { Coordinates *coords = f.getCoordinates(outloc); auto result = @@ -203,7 +206,8 @@ Field3D D2DY2(const Field3D &f, CELL_LOC outloc, const std::string &method, } Coordinates::metric_field_type D2DY2(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { + const std::string& method, + const std::string& region) { Coordinates *coords = f.getCoordinates(outloc); auto result = @@ -226,7 +230,8 @@ Field3D D2DZ2(const Field3D &f, CELL_LOC outloc, const std::string &method, } Coordinates::metric_field_type D2DZ2(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { + const std::string& method, + const std::string& region) { return bout::derivatives::index::D2DZ2(f, outloc, method, region) / SQ(f.getCoordinates(outloc)->dz); } @@ -242,7 +247,8 @@ Field3D D4DX4(const Field3D &f, CELL_LOC outloc, const std::string &method, } Coordinates::metric_field_type D4DX4(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { + const std::string& method, + const std::string& region) { return bout::derivatives::index::D4DX4(f, outloc, method, region) / SQ(SQ(f.getCoordinates(outloc)->dx)); } @@ -254,7 +260,8 @@ Field3D D4DY4(const Field3D &f, CELL_LOC outloc, const std::string &method, } Coordinates::metric_field_type D4DY4(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { + const std::string& method, + const std::string& region) { return bout::derivatives::index::D4DY4(f, outloc, method, region) / SQ(SQ(f.getCoordinates(outloc)->dy)); } @@ -266,7 +273,8 @@ Field3D D4DZ4(const Field3D &f, CELL_LOC outloc, const std::string &method, } Coordinates::metric_field_type D4DZ4(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { + const std::string& method, + const std::string& region) { return bout::derivatives::index::D4DZ4(f, outloc, method, region) / SQ(SQ(f.getCoordinates(outloc)->dz)); } @@ -282,9 +290,11 @@ Coordinates::metric_field_type D4DZ4(const Field2D& f, CELL_LOC outloc, * * ** Communicates and applies boundary in X. */ -Coordinates::metric_field_type D2DXDY(const Field2D& f, CELL_LOC outloc, const std::string& method, - const std::string& region, const std::string& dfdy_boundary_condition, - const std::string& dfdy_region) { +Coordinates::metric_field_type D2DXDY(const Field2D& f, CELL_LOC outloc, + const std::string& method, + const std::string& region, + const std::string& dfdy_boundary_condition, + const std::string& dfdy_region) { std::string dy_region = dfdy_region.empty() ? region : dfdy_region; // If staggering in x, take y-derivative at f's location. @@ -326,7 +336,8 @@ Field3D D2DXDY(const Field3D& f, CELL_LOC outloc, const std::string& method, } Coordinates::metric_field_type D2DXDZ(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { + const std::string& method, + const std::string& region) { #ifdef COORDINATES_USE_3D Field3D tmp{f}; return D2DXDZ(tmp, outloc, method, region); @@ -350,7 +361,8 @@ Field3D D2DXDZ(const Field3D &f, CELL_LOC outloc, const std::string &method, } Coordinates::metric_field_type D2DYDZ(const Field2D& f, CELL_LOC outloc, - const std::string& method, const std::string& region) { + const std::string& method, + const std::string& region) { #ifdef COORDINATES_USE_3D Field3D tmp{f}; return D2DYDZ(tmp, outloc, method, region); @@ -380,8 +392,8 @@ Field3D D2DYDZ(const Field3D& f, CELL_LOC outloc, MAYBE_UNUSED(const std::string ////////////// X DERIVATIVE ///////////////// /// Special case where both arguments are 2D. -Coordinates::metric_field_type VDDX(const Field2D& v, const Field2D& f, - CELL_LOC outloc, const std::string& method, +Coordinates::metric_field_type VDDX(const Field2D& v, const Field2D& f, CELL_LOC outloc, + const std::string& method, const std::string& region) { return bout::derivatives::index::VDDX(v, f, outloc, method, region) / f.getCoordinates(outloc)->dx; @@ -397,9 +409,9 @@ Field3D VDDX(const Field3D &v, const Field3D &f, CELL_LOC outloc, const std::str ////////////// Y DERIVATIVE ///////////////// // special case where both are 2D -Coordinates::metric_field_type VDDY(const Field2D& v, const Field2D& f, - CELL_LOC outloc, const std::string& method, - const std::string& region) { +Coordinates::metric_field_type VDDY(const Field2D& v, const Field2D& f, CELL_LOC outloc, + const std::string& method, + const std::string& region) { return bout::derivatives::index::VDDY(v, f, outloc, method, region) / f.getCoordinates(outloc)->dy; } @@ -414,16 +426,16 @@ Field3D VDDY(const Field3D &v, const Field3D &f, CELL_LOC outloc, const std::str ////////////// Z DERIVATIVE ///////////////// // special case where both are 2D -Coordinates::metric_field_type VDDZ(const Field2D &v, const Field2D &f, - CELL_LOC outloc, const std::string &method, +Coordinates::metric_field_type VDDZ(const Field2D& v, const Field2D& f, CELL_LOC outloc, + const std::string& method, const std::string& region) { return bout::derivatives::index::VDDZ(v, f, outloc, method, region) / f.getCoordinates(outloc)->dz; } // Note that this is zero because no compression is included -Coordinates::metric_field_type VDDZ(const Field3D &v, const Field2D& f, - CELL_LOC outloc, const std::string& method, +Coordinates::metric_field_type VDDZ(const Field3D& v, const Field2D& f, CELL_LOC outloc, + const std::string& method, const std::string& region) { #ifdef COORDINATES_USE_3D Field3D tmp{f}; @@ -447,8 +459,8 @@ Field3D VDDZ(const Field3D &v, const Field3D &f, CELL_LOC outloc, const std::str /******************************************************************************* * Flux conserving schemes *******************************************************************************/ -Coordinates::metric_field_type FDDX(const Field2D& v, const Field2D& f, - CELL_LOC outloc, const std::string& method, +Coordinates::metric_field_type FDDX(const Field2D& v, const Field2D& f, CELL_LOC outloc, + const std::string& method, const std::string& region) { return bout::derivatives::index::FDDX(v, f, outloc, method, region) / f.getCoordinates(outloc)->dx; @@ -462,8 +474,8 @@ Field3D FDDX(const Field3D &v, const Field3D &f, CELL_LOC outloc, const std::str ///////////////////////////////////////////////////////////////////////// -Coordinates::metric_field_type FDDY(const Field2D& v, const Field2D& f, - CELL_LOC outloc, const std::string& method, +Coordinates::metric_field_type FDDY(const Field2D& v, const Field2D& f, CELL_LOC outloc, + const std::string& method, const std::string& region) { return bout::derivatives::index::FDDY(v, f, outloc, method, region) / f.getCoordinates(outloc)->dy; @@ -477,8 +489,8 @@ Field3D FDDY(const Field3D &v, const Field3D &f, CELL_LOC outloc, const std::str ///////////////////////////////////////////////////////////////////////// -Coordinates::metric_field_type FDDZ(const Field2D &v, const Field2D &f, - CELL_LOC outloc, const std::string &method, +Coordinates::metric_field_type FDDZ(const Field2D& v, const Field2D& f, CELL_LOC outloc, + const std::string& method, const std::string& region) { return bout::derivatives::index::FDDZ(v, f, outloc, method, region) / f.getCoordinates(outloc)->dz; diff --git a/tests/MMS/diffusion/diffusion.cxx b/tests/MMS/diffusion/diffusion.cxx index 2e8e1f0f3b..ec0aae75a4 100644 --- a/tests/MMS/diffusion/diffusion.cxx +++ b/tests/MMS/diffusion/diffusion.cxx @@ -77,7 +77,8 @@ int physics_init(bool UNUSED(restarting)) { for (int yj = mesh->ystart; yj < mesh->yend + 1; yj++){ for (int zk = 0; zk < mesh->LocalNz; zk++) { output.write("Initial condition at {:d},{:d},{:d}\n", xi, yj, zk); - N(xi, yj, zk) = MS(0.,mesh->GlobalX(xi)*Lx,mesh->GlobalY(yj)*Ly,coord->dz(xi, yj, zk)*zk); + N(xi, yj, zk) = MS(0., mesh->GlobalX(xi) * Lx, mesh->GlobalY(yj) * Ly, + coord->dz(xi, yj, zk) * zk); } } } @@ -141,7 +142,7 @@ void solution(Field3D &f, BoutReal t, BoutReal UNUSED(D)) { x = mesh->GlobalX(xi); y = mesh->GlobalY(yj);//GlobalY not fixed yet for (int zk = 0; zk < mesh->LocalNz; zk++) { - z = coord->dz(xi, yj, zk)*zk; + z = coord->dz(xi, yj, zk) * zk; output.write("Solution at {:d},{:d},{:d}\n", xi, yj, zk); f(xi, yj, zk) = MS(t,x,y,z); } diff --git a/tests/MMS/diffusion2/diffusion.cxx b/tests/MMS/diffusion2/diffusion.cxx index 8af7e1b9ef..3f228b3468 100644 --- a/tests/MMS/diffusion2/diffusion.cxx +++ b/tests/MMS/diffusion2/diffusion.cxx @@ -22,8 +22,9 @@ int physics_init(bool UNUSED(restarting)) { coords->dx = Lx/(mesh->GlobalNx - 2*mesh->xstart); coords->dy = Ly/(mesh->GlobalNy - 2*mesh->ystart); - - output.write("SIZES: {:d}, {:d}, {:e}\n", mesh->GlobalNy, (mesh->GlobalNy - 2*mesh->ystart), coords->dy(0,0,0)); + + output.write("SIZES: {:d}, {:d}, {:e}\n", mesh->GlobalNy, + (mesh->GlobalNy - 2 * mesh->ystart), coords->dy(0, 0, 0)); SAVE_ONCE2(Lx,Ly); diff --git a/tests/MMS/spatial/diffusion/diffusion.cxx b/tests/MMS/spatial/diffusion/diffusion.cxx index bb32827897..4c9568363e 100644 --- a/tests/MMS/spatial/diffusion/diffusion.cxx +++ b/tests/MMS/spatial/diffusion/diffusion.cxx @@ -23,8 +23,9 @@ int physics_init(bool UNUSED(restarting)) { coords->dx = Lx/(mesh->GlobalNx - 2*mesh->xstart); coords->dy = Ly/(mesh->GlobalNy - 2*mesh->ystart); - - output.write("SIZES: {:d}, {:d}, {:e}\n", mesh->GlobalNy, (mesh->GlobalNy - 2*mesh->ystart), coords->dy(0,0,0)); + + output.write("SIZES: {:d}, {:d}, {:e}\n", mesh->GlobalNy, + (mesh->GlobalNy - 2 * mesh->ystart), coords->dy(0, 0, 0)); SAVE_ONCE2(Lx,Ly); diff --git a/tests/MMS/wave-1d/wave.cxx b/tests/MMS/wave-1d/wave.cxx index b55710511d..6518dc56d6 100644 --- a/tests/MMS/wave-1d/wave.cxx +++ b/tests/MMS/wave-1d/wave.cxx @@ -77,8 +77,10 @@ class Wave1D : public PhysicsModel { for (int xi = mesh->xstart; xi < mesh->xend + 1; xi++) { for (int yj = mesh->ystart; yj < mesh->yend + 1; yj++){ for (int zk = 0; zk < mesh->LocalNz; zk++) { - f(xi, yj, zk) = MS_f(0.,mesh->GlobalX(xi),mesh->GlobalY(yj),coord->dz(xi,yj,zk)*zk); - g(xi, yj, zk) = MS_g(0.,0.5*(mesh->GlobalX(xi)+mesh->GlobalX(xi-1)),mesh->GlobalY(yj),coord->dz(xi,yj,zk)*zk); + f(xi, yj, zk) = MS_f(0., mesh->GlobalX(xi), mesh->GlobalY(yj), + coord->dz(xi, yj, zk) * zk); + g(xi, yj, zk) = MS_g(0., 0.5 * (mesh->GlobalX(xi) + mesh->GlobalX(xi - 1)), + mesh->GlobalY(yj), coord->dz(xi, yj, zk) * zk); output.write("{:d}: {:e}\n", xi, g(xi, yj, zk)); } @@ -88,8 +90,10 @@ class Wave1D : public PhysicsModel { for (int xi = mesh->xstart; xi < mesh->xend + 1; xi++) { for (int yj = mesh->ystart; yj < mesh->yend + 1; yj++) { for (int zk = 0; zk < mesh->LocalNz; zk++) { - f(xi, yj, zk) = MS_f(0., mesh->GlobalX(xi), mesh->GlobalY(yj), coord->dz(xi, yj, zk) * zk); - g(xi, yj, zk) = MS_g(0., mesh->GlobalX(xi), mesh->GlobalY(yj), coord->dz(xi, yj, zk) * zk); + f(xi, yj, zk) = MS_f(0., mesh->GlobalX(xi), mesh->GlobalY(yj), + coord->dz(xi, yj, zk) * zk); + g(xi, yj, zk) = MS_g(0., mesh->GlobalX(xi), mesh->GlobalY(yj), + coord->dz(xi, yj, zk) * zk); } } } @@ -172,7 +176,7 @@ const Field3D Wave1D::solution_f(BoutReal t) { BoutReal x = mesh->GlobalX(xi); BoutReal y = mesh->GlobalY(yj);//GlobalY not fixed yet for (int zk = 0; zk < mesh->LocalNz; zk++) { - BoutReal z = coord->dz(xi,yj,zk)*zk; + BoutReal z = coord->dz(xi, yj, zk) * zk; S(xi, yj, zk) = MS_f(t,x,y,z); } } @@ -230,7 +234,7 @@ const Field3D Wave1D::solution_g(BoutReal t) { } BoutReal y = mesh->GlobalY(yj);//GlobalY not fixed yet for (int zk = 0; zk < mesh->LocalNz; zk++) { - BoutReal z = coord->dz(xi,yj,zk)*zk; + BoutReal z = coord->dz(xi, yj, zk) * zk; S(xi, yj, zk) = MS_g(t,x,y,z); } } diff --git a/tests/integrated/test-laplacexy-short/test-laplacexy.cxx b/tests/integrated/test-laplacexy-short/test-laplacexy.cxx index 3bd6471ead..e289007b77 100644 --- a/tests/integrated/test-laplacexy-short/test-laplacexy.cxx +++ b/tests/integrated/test-laplacexy-short/test-laplacexy.cxx @@ -62,9 +62,10 @@ int main(int argc, char** argv) { Field2D rhs, rhs_check; if (include_y_derivs) { - rhs = a*DC(Laplace_perp(f)) + DC(Grad_perp(a)*Grad_perp(f)) + b*f; + rhs = a * DC(Laplace_perp(f)) + DC(Grad_perp(a) * Grad_perp(f)) + b * f; } else { - rhs = a*DC(Delp2(f, CELL_DEFAULT, false)) + DC(coords->g11*DDX(a)*DDX(f)) + b*f; + rhs = + a * DC(Delp2(f, CELL_DEFAULT, false)) + DC(coords->g11 * DDX(a) * DDX(f)) + b * f; } laplacexy.setCoefs(a, b); @@ -78,9 +79,10 @@ int main(int argc, char** argv) { mesh->communicate(sol); if (include_y_derivs) { - rhs_check = a*DC(Laplace_perp(sol)) + DC(Grad_perp(a)*Grad_perp(sol)) + b*sol; + rhs_check = a * DC(Laplace_perp(sol)) + DC(Grad_perp(a) * Grad_perp(sol)) + b * sol; } else { - rhs_check = a*DC(Delp2(sol, CELL_DEFAULT, false)) + DC(coords->g11*DDX(a)*DDX(sol)) + b*sol; + rhs_check = a * DC(Delp2(sol, CELL_DEFAULT, false)) + + DC(coords->g11 * DDX(a) * DDX(sol)) + b * sol; } dump.add(a, "a"); diff --git a/tests/integrated/test-laplacexz/test-laplacexz.cxx b/tests/integrated/test-laplacexz/test-laplacexz.cxx index 42c126d339..79e77eb741 100644 --- a/tests/integrated/test-laplacexz/test-laplacexz.cxx +++ b/tests/integrated/test-laplacexz/test-laplacexz.cxx @@ -11,8 +11,8 @@ #include #include -#include #include +#include int main(int argc, char** argv) { BoutInitialise(argc, argv); @@ -20,21 +20,21 @@ int main(int argc, char** argv) { auto inv = LaplaceXZ::create(mesh); auto coord = bout::globals::mesh->getCoordinates(); - coord->g13 = 1.8; //test off-diagonal components with nonzero value + coord->g13 = 1.8; // test off-diagonal components with nonzero value // create some input field - Field3D f = FieldFactory::get()->create3D("f", Options::getRoot(), mesh); + Field3D f = FieldFactory::get()->create3D("f", Options::getRoot(), mesh); // Calculate the Laplacian with non-zero g13 - Field3D g = coord->g11*D2DX2(f) + coord->g13*D2DXDZ(f) + coord->g33*D2DZ2(f); + Field3D g = coord->g11 * D2DX2(f) + coord->g13 * D2DXDZ(f) + coord->g33 * D2DZ2(f); + + inv->setCoefs(Field2D(1.0), Field2D(0.0)); + + Field3D f2 = inv->solve(g, 0.0); // Invert the Laplacian. - inv->setCoefs(Field2D(1.0),Field2D(0.0)); - - Field3D f2 = inv->solve(g,0.0); // Invert the Laplacian. - - SAVE_ONCE3(f,f2,g); + SAVE_ONCE3(f, f2, g); - coord->g13 = 0.0; //reset to 0.0 for original laplacexz test + coord->g13 = 0.0; // reset to 0.0 for original laplacexz test // Now the normal test. output.write("Setting coefficients\n"); diff --git a/tests/integrated/test-petsc_laplace_MAST-grid/test_petsc_laplace_MAST_grid.cxx b/tests/integrated/test-petsc_laplace_MAST-grid/test_petsc_laplace_MAST_grid.cxx index 5730bc63c3..3a1e7d365c 100644 --- a/tests/integrated/test-petsc_laplace_MAST-grid/test_petsc_laplace_MAST_grid.cxx +++ b/tests/integrated/test-petsc_laplace_MAST-grid/test_petsc_laplace_MAST_grid.cxx @@ -662,9 +662,9 @@ int main(int argc, char** argv) { dump.write(); dump.close(); - + output << "\nFinished running test.\n"; - + MPI_Barrier(BoutComm::get()); // Wait for all processors to write data } BoutFinalise(); diff --git a/tests/unit/mesh/data/test_gridfromoptions.cxx b/tests/unit/mesh/data/test_gridfromoptions.cxx index d483bbf162..2cf318c280 100644 --- a/tests/unit/mesh/data/test_gridfromoptions.cxx +++ b/tests/unit/mesh/data/test_gridfromoptions.cxx @@ -64,9 +64,9 @@ class GridFromOptionsTest : public ::testing::Test { &mesh_from_options); expected_metric = #ifdef COORDINATES_USE_3D - expected_3d; + expected_3d; #else - expected_2d; + expected_2d; #endif } @@ -373,11 +373,12 @@ TEST_F(GridFromOptionsTest, CoordinatesXlowInterp) { auto coords = mesh_from_options.getCoordinates(CELL_XLOW); - Coordinates::metric_field_type expected_xlow = makeField( - [](Coordinates::metric_field_type::ind_type& index) { - return index.x() - 0.5 + (TWOPI * index.y()) + (TWOPI * index.z() / nz) + 3; - }, - &mesh_from_options); + Coordinates::metric_field_type expected_xlow = + makeField( + [](Coordinates::metric_field_type::ind_type& index) { + return index.x() - 0.5 + (TWOPI * index.y()) + (TWOPI * index.z() / nz) + 3; + }, + &mesh_from_options); mesh_from_options.communicate(expected_xlow); diff --git a/tests/unit/mesh/parallel/test_shiftedmetric.cxx b/tests/unit/mesh/parallel/test_shiftedmetric.cxx index 6a2aa56eff..cdf8c6dd59 100644 --- a/tests/unit/mesh/parallel/test_shiftedmetric.cxx +++ b/tests/unit/mesh/parallel/test_shiftedmetric.cxx @@ -42,9 +42,8 @@ class ShiftedMetricTest : public ::testing::Test { Field2D{0.0}, Field2D{0.0}, Field2D{0.0}, Field2D{0.0}, false)); auto coords = mesh->getCoordinates(); - coords->setParallelTransform( - bout::utils::make_unique(*mesh, CELL_CENTRE, zShift, - coords->zlength()(0,0))); + coords->setParallelTransform(bout::utils::make_unique( + *mesh, CELL_CENTRE, zShift, coords->zlength()(0, 0))); Field3D input_temp{mesh}; diff --git a/tests/unit/solver/test_solver.cxx b/tests/unit/solver/test_solver.cxx index df133d528f..0e7d33a5a2 100644 --- a/tests/unit/solver/test_solver.cxx +++ b/tests/unit/solver/test_solver.cxx @@ -256,9 +256,9 @@ TEST_F(SolverTest, AddVector2D) { Vector2D vector1{}, vector2{}; EXPECT_NO_THROW(solver.add(vector1, "vector")); #ifndef COORDINATES_USE_3D - constexpr int n2d=3, n3d=0; + constexpr int n2d = 3, n3d = 0; #else - constexpr int n2d=0, n3d=3; + constexpr int n2d = 0, n3d = 3; #endif EXPECT_EQ(solver.n2Dvars(), n2d); EXPECT_EQ(solver.n3Dvars(), n3d); @@ -274,8 +274,8 @@ TEST_F(SolverTest, AddVector2D) { vector2.covariant = false; EXPECT_NO_THROW(solver.add(vector2, "another_vector")); - EXPECT_EQ(solver.n2Dvars(), n2d*2); - EXPECT_EQ(solver.n3Dvars(), n3d*2); + EXPECT_EQ(solver.n2Dvars(), n2d * 2); + EXPECT_EQ(solver.n3Dvars(), n3d * 2); EXPECT_TRUE(IsFieldEqual(vector2.x, 8.0)); EXPECT_TRUE(IsFieldEqual(vector2.y, 9.0)); EXPECT_TRUE(IsFieldEqual(vector2.z, 10.0)); @@ -387,9 +387,9 @@ TEST_F(SolverTest, ConstraintVector2D) { Vector2D vector1{}, vector2{}; EXPECT_NO_THROW(solver.constraint(vector1, vector1, "vector")); #ifndef COORDINATES_USE_3D - constexpr int n2d=3, n3d=0; + constexpr int n2d = 3, n3d = 0; #else - constexpr int n2d=0, n3d=3; + constexpr int n2d = 0, n3d = 3; #endif EXPECT_EQ(solver.n2Dvars(), n2d); EXPECT_EQ(solver.n3Dvars(), n3d); @@ -412,8 +412,8 @@ TEST_F(SolverTest, ConstraintVector2D) { vector2.covariant = false; EXPECT_NO_THROW(solver.constraint(vector2, vector2, "another_vector")); - EXPECT_EQ(solver.n2Dvars(), n2d*2); - EXPECT_EQ(solver.n3Dvars(), n3d*2); + EXPECT_EQ(solver.n2Dvars(), n2d * 2); + EXPECT_EQ(solver.n3Dvars(), n3d * 2); const auto expected_names = std::vector{"vector", "another_vector"}; EXPECT_EQ(solver.listVector2DNames(), expected_names);