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

ASSERT1_FIELDS_COMPATIBLE(field1, field2)#
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

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

Parameters:
  • name – The name of the function to define

  • func – The function to apply to each value

Functions

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

Check if Fields have compatible meta-data.

template<typename T>
inline 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>
inline 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>
inline 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 Function, typename = decltype(std::declval<Function&>()(std::declval<typename T::ind_type&>()))>
inline T filledFrom(const T &f, Function func, std::string region_string = "RGN_ALL")#

Return a field of some type derived from Field, with metadata copied from another field and a data array allocated and filled using a callable e.g. lambda function

e.g. Field3D result = filledFrom(field, [&](const auto& index) { return …; });

An optional third argument is the region string

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

Unary + operator. This doesn’t do anything.

template<typename T>
inline T toFieldAligned(const T &f, const std::string &region = "RGN_ALL")#

Convert f to field-aligned space in region (default: whole domain)

template<typename T>
inline T fromFieldAligned(const T &f, const std::string &region = "RGN_ALL")#

Convert f from field-aligned space in region (default: whole domain)

template<typename T, typename = bout::utils::EnableIfField<T>>
inline BoutReal min(const T &f, bool allpe = false, const std::string &rgn = "RGN_NOBNDRY")#

Minimum of f, excluding the boundary/guard cells by default (can be changed with rgn argument).

By default this is only on the local processor, but setting allpe true does a collective Allreduce over all processors.

Parameters:
  • f[in] Input field

  • allpe[in] Minimum over all processors?

  • rgn[in] The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline bool isUniform(const T &f, bool allpe = false, const std::string &region = "RGN_ALL")#

Returns true if all elements of f over region are equal. By default only checks the local processor, use allpe to check globally

Parameters:
  • f[in] The field to check

  • allpe[in] Check over all processors

  • region[in] The region to check for uniformity over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline BoutReal getUniform(const T &f, MAYBE_UNUSED(bool allpe) = false, const std::string &region = "RGN_ALL")#

Returns the value of the first element of f (in the region region if given). If checks are enabled, then throws an exception if f is not uniform over region. By default only checks the local processor, use allpe to check globally

Parameters:
  • f[in] The field to check

  • allpe[in] Check over all processors

  • region[in] The region to assume is uniform

template<typename T, typename = bout::utils::EnableIfField<T>>
inline BoutReal max(const T &f, bool allpe = false, const std::string &rgn = "RGN_NOBNDRY")#

Maximum of r, excluding the boundary/guard cells by default (can be changed with rgn argument).

By default this is only on the local processor, but setting allpe to true does a collective Allreduce over all processors.

Parameters:
  • f[in] Input field

  • allpe[in] Maximum over all processors?

  • rgn[in] The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline BoutReal mean(const T &f, bool allpe = false, const std::string &rgn = "RGN_NOBNDRY")#

Mean of f, excluding the boundary/guard cells by default (can be changed with rgn argument).

By default this is only on the local processor, but setting allpe to true does a collective Allreduce over all processors.

Parameters:
  • f[in] Input field

  • allpe[in] Mean over all processors?

  • rgn[in] The region to calculate the result over

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, BoutReal rhs, const std::string &rgn = "RGN_ALL")#
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>>
inline 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>>
inline 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>>
inline 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>>
inline 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>>
inline 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[in] Angle in radians

  • rgn[in] The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline 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[in] Angle in radians

  • rgn[in] The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline 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[in] Angle in radians

  • rgn[in] The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline 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[in] Angle in radians

  • rgn[in] The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline 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[in] Angle in radians

  • rgn[in] The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline 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[in] Angle in radians

  • rgn[in] The region to calculate the result over

template<typename T, typename = bout::utils::EnableIfField<T>>
inline 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>>
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>>
inline 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[in] Variable to apply floor to

  • f[in] The floor value

  • rgn[in] The region to calculate the result over

class Field : public FieldData#
#include <field.hxx>

Base class for scalar fields.

Subclassed by Field2D, Field3D, FieldPerp

Public Functions

Field() = default#
Field(const Field &other) = default#
Field(Field &&other) = default#
Field &operator=(const Field &other) = default#
Field &operator=(Field &&other) = default#
virtual ~Field() = default#
Field(Mesh *localmesh, CELL_LOC location_in, DirectionTypes directions_in)#
inline DirectionTypes getDirections() const#

Getters for DIRECTION types.

inline YDirectionType getDirectionY() const#
inline ZDirectionType getDirectionZ() const#
inline virtual Field &setDirections(DirectionTypes directions_in)#

Setters for *DirectionType.

inline virtual Field &setDirectionY(YDirectionType y_type)#
inline virtual Field &setDirectionZ(ZDirectionType z_type)#
inline virtual bool bndryValid()#
virtual int getNx() const#

Return the number of nx points

virtual int getNy() const#

Return the number of ny points

virtual 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}#

Private Members

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

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

Friends

inline friend void swap(Field &first, Field &second) noexcept#
namespace bout

Provides access to the Hypre library, handling initialisation and finalisation.

Usage

#include <bout/hyprelib.hxx>

class MyClass { public:

private: HypreLib lib; };

This will then automatically initialise Hypre the first time an object is created, and finalise it when the last object is destroyed.

Copyright 2012 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/.

Information about the version of BOUT++

The build system will update this file on every commit, which may result in files that include it getting rebuilt. Therefore it should be included in as few places as possible

Information about the version of BOUT++

The build system will update this file at configure-time

SNB model

Functions

template<typename T>
inline 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>
inline 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.