File field.hxx

field base class definition for differencing methods

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 http://www.gnu.org/licenses/.

Defines

FIELD_FUNC(name, func)

This macro takes a function func, which is assumed to operate on a single BoutReal and return a single BoutReal, and wraps it up into a function of a Field called name.

If CHECK >= 1, checks if the

Field is allocated
Parameters
  • name: The name of the function to define
  • func: The function to apply to each value

Loops over the entire domain, applies function, and uses checkData() to, if CHECK >= 3, check result for non-finite numbers

Functions

bool areFieldsCompatible(const Field &field1, const Field &field2)

Check if Fields have compatible meta-data.

template<typename T>
T emptyFrom(const T &f)

Return an empty shell field of some type derived from Field, with metadata copied and a data array that is allocated but not initialised.

template<typename T>
T zeroFrom(const T &f)

Return a field of some type derived from Field, with metadata copied from another field and a data array allocated and initialised to zero.

template<typename T>
T filledFrom(const T &f, BoutReal fill_value)

Return a field of some type derived from Field, with metadata copied from another field and a data array allocated and filled with the given value.

template<typename T, typename = bout::utils::EnableIfField<T>>
T operator+(const T &f)

Unary + operator. This doesn’t do anything.

template<typename T>
T toFieldAligned(const T &f, const std::string &region = "RGN_ALL")
template<typename T>
T toFieldAligned(const T &f, REGION region)
template<typename T>
T fromFieldAligned(const T &f, const std::string &region = "RGN_ALL")
template<typename T>
T fromFieldAligned(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
BoutReal min(const T &f, bool allpe = false, const std::string &rgn = "RGN_NOBNDRY")
template<typename T, typename = bout::utils::EnableIfField<T>>
BoutReal min(const T &f, bool allpe, REGION rgn)
template<typename T, typename = bout::utils::EnableIfField<T>>
BoutReal max(const T &f, bool allpe = false, const std::string &rgn = "RGN_NOBNDRY")
template<typename T, typename = bout::utils::EnableIfField<T>>
BoutReal max(const T &f, bool allpe, REGION rgn)
template<typename T, typename = bout::utils::EnableIfField<T>>
BoutReal mean(const T &f, bool allpe = false, const std::string &rgn = "RGN_NOBNDRY")
template<typename T, typename = bout::utils::EnableIfField<T>>
BoutReal mean(const T &f, bool allpe, REGION rgn)
template<typename T, typename = bout::utils::EnableIfField<T>>
T pow(const T &lhs, const T &rhs, const std::string &rgn = "RGN_ALL")

Exponent: pow(lhs, lhs) is lhs raised to the power of rhs

This loops over the entire domain, including guard/boundary cells by default (can be changed using the rgn argument) If CHECK >= 3 then the result will be checked for non-finite numbers

template<typename T, typename = bout::utils::EnableIfField<T>>
T pow(const T &lhs, const T &rhs, REGION rgn)
template<typename T, typename = bout::utils::EnableIfField<T>>
T pow(const T &lhs, BoutReal rhs, const std::string &rgn = "RGN_ALL")
template<typename T, typename = bout::utils::EnableIfField<T>>
T pow(const T &lhs, BoutReal rhs, REGION rgn)
template<typename T, typename = bout::utils::EnableIfField<T>>
T pow(BoutReal lhs, const T &rhs, const std::string &rgn = "RGN_ALL")
template<typename T, typename = bout::utils::EnableIfField<T>>
T pow(BoutReal lhs, const T &rhs, REGION rgn)
template<typename T, typename = bout::utils::EnableIfField<T>>
T sqrt(const T &f, const std::string &rgn = "RGN_ALL")

Square root of f over region rgn

This loops over the entire domain, including guard/boundary cells by default (can be changed using the rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers

template<typename T, typename = bout::utils::EnableIfField<T>>
T sqrt(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T abs(const T &f, const std::string &rgn = "RGN_ALL")

Absolute value (modulus, |f|) of f over region rgn

This loops over the entire domain, including guard/boundary cells by default (can be changed using the rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers

template<typename T, typename = bout::utils::EnableIfField<T>>
T abs(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T exp(const T &f, const std::string &rgn = "RGN_ALL")

Exponential: \(\exp(f)\) is e to the power of f, over region rgn

This loops over the entire domain, including guard/boundary cells by default (can be changed using the rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers

template<typename T, typename = bout::utils::EnableIfField<T>>
T exp(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T log(const T &f, const std::string &rgn = "RGN_ALL")

Natural logarithm of f over region rgn, inverse of exponential

\(\ln(\exp(f)) = f\)

This loops over the entire domain, including guard/boundary cells by default (can be changed using the rgn argument) If CHECK >= 3 then the result will be checked for non-finite numbers

template<typename T, typename = bout::utils::EnableIfField<T>>
T log(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T sin(const T &f, const std::string &rgn = "RGN_ALL")

Sine trigonometric function.

This loops over the entire domain, including guard/boundary cells by default (can be changed using the

rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers
Parameters
  • f: Angle in radians
  • rgn: The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
T sin(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T cos(const T &f, const std::string &rgn = "RGN_ALL")

Cosine trigonometric function.

This loops over the entire domain, including guard/boundary cells by default (can be changed using the

rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers
Parameters
  • f: Angle in radians
  • rgn: The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
T cos(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T tan(const T &f, const std::string &rgn = "RGN_ALL")

Tangent trigonometric function.

This loops over the entire domain, including guard/boundary cells by default (can be changed using the

rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers
Parameters
  • f: Angle in radians
  • rgn: The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
T tan(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T sinh(const T &f, const std::string &rgn = "RGN_ALL")

Hyperbolic sine trigonometric function.

This loops over the entire domain, including guard/boundary cells by default (can be changed using the

rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers
Parameters
  • f: Angle in radians
  • rgn: The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
T sinh(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T cosh(const T &f, const std::string &rgn = "RGN_ALL")

Hyperbolic cosine trigonometric function.

This loops over the entire domain, including guard/boundary cells by default (can be changed using the

rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers
Parameters
  • f: Angle in radians
  • rgn: The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
T cosh(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
T tanh(const T &f, const std::string &rgn = "RGN_ALL")

Hyperbolic tangent trigonometric function.

This loops over the entire domain, including guard/boundary cells by default (can be changed using the

rgn argument). If CHECK >= 3 then the result will be checked for non-finite numbers
Parameters
  • f: Angle in radians
  • rgn: The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
T tanh(const T &f, REGION region)
template<typename T, typename = bout::utils::EnableIfField<T>>
bool finite(const T &f, const std::string &rgn = "RGN_ALL")

Check if all values of a field var are finite. Loops over all points including the boundaries by default (can be changed using the rgn argument

template<typename T, typename = bout::utils::EnableIfField<T>>
bool finite(const T &f, REGION rgn)
template<typename T, typename = bout::utils::EnableIfField<T>>
T copy(const T &f)

Makes a copy of a field f, ensuring that the underlying data is not shared.

template<typename T, typename = bout::utils::EnableIfField<T>>
T floor(const T &var, BoutReal f, const std::string &rgn = "RGN_ALL")

Apply a floor value f to a field var. Any value lower than the floor is set to the floor.

Parameters
  • var: Variable to apply floor to
  • f: The floor value
  • rgn: The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
T floor(const T &var, BoutReal f, REGION rgn)
class Field
#include <field.hxx>

Base class for fields.

Defines the virtual function SetStencil, used by differencing methods

Subclassed by Field2D, Field3D, FieldPerp

Public Functions

Field()
Field(const Field &other)
Field(Field &&other)
Field &operator=(const Field &other)
Field &operator=(Field &&other)
virtual ~Field()
Field(Mesh *localmesh, CELL_LOC location_in, DirectionTypes directions_in)
void setLocation(CELL_LOC new_location)

Set variable location for staggered grids to

Parameters
  • new_location: Throws BoutException if new_location is not CELL_CENTRE and staggered grids are turned off and checks are on. If checks are off, silently sets location to CELL_CENTRE instead.

CELL_LOC getLocation() const

Get variable location.

DirectionTypes getDirections() const

Getters for DIRECTION types.

YDirectionType getDirectionY() const
ZDirectionType getDirectionZ() const
void setDirectionY(YDirectionType y_type)

Setters for *DirectionType.

void setDirectionZ(ZDirectionType z_type)
virtual bool bndryValid()
Mesh *getMesh() const
Coordinates *getCoordinates() const

Returns a pointer to the coordinates object at this field’s location from the mesh this field is on.

Coordinates *getCoordinates(CELL_LOC loc) const

Returns a pointer to the coordinates object at the requested location from the mesh this field is on. If location is CELL_DEFAULT then return coordinates at field location

int getNx() const

Return the number of nx points

int getNy() const

Return the number of ny points

int getNz() const

Return the number of nz points

Public Members

std::string name
bool bndry_xin = {true}

Status of the 4 boundaries.

bool bndry_xout = {true}
bool bndry_yup = {true}
bool bndry_ydown = {true}

Protected Functions

void copyFieldMembers(const Field &f)

Copy the members from another Field.

Protected Attributes

Mesh *fieldmesh = {nullptr}
std::shared_ptr<Coordinates> fieldCoordinates = {nullptr}
CELL_LOC location = {CELL_CENTRE}

Location of the variable in the cell.

DirectionTypes directions = {YDirectionType::Standard, ZDirectionType::Standard}

Labels for the type of coordinate system this field is defined over.

Friends

void swap(Field &first, Field &second)
namespace bout

SNB model

Functions

template<typename T>
void checkFinite(const T &f, const std::string &name = "field", const std::string &rgn = "RGN_ALL")

Check if all values of a field var are finite. Loops over all points including the boundaries by default (can be changed using the rgn argument) If any element is not finite, throws an exception that includes the position of the first found.

Note that checkFinite runs the check irrespective of CHECK level. It is intended to be used during initialization, where we always want to check inputs, even for optimized builds.

template<typename T>
void checkPositive(const T &f, const std::string &name = "field", const std::string &rgn = "RGN_ALL")

Check if all values of a field var are positive. Loops over all points including the boundaries by default (can be changed using the rgn argument) If any element is not finite, throws an exception that includes the position of the first found.

Note that checkPositive runs the check irrespective of CHECK level. It is intended to be used during initialization, where we always want to check inputs, even for optimized builds.