File field2d.hxx

Definition of 2D scalar field class.

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

__FIELD2D_H__

Functions

Field2D operator+(const Field2D &lhs, const Field2D &rhs)
Field2D operator-(const Field2D &lhs, const Field2D &rhs)
Field2D operator*(const Field2D &lhs, const Field2D &rhs)
Field2D operator/(const Field2D &lhs, const Field2D &rhs)
Field3D operator+(const Field2D &lhs, const Field3D &rhs)
Field3D operator-(const Field2D &lhs, const Field3D &rhs)
Field3D operator*(const Field2D &lhs, const Field3D &rhs)
Field3D operator/(const Field2D &lhs, const Field3D &rhs)
Field2D operator+(const Field2D &lhs, BoutReal rhs)
Field2D operator-(const Field2D &lhs, BoutReal rhs)
Field2D operator*(const Field2D &lhs, BoutReal rhs)
Field2D operator/(const Field2D &lhs, BoutReal rhs)
Field2D operator+(BoutReal lhs, const Field2D &rhs)
Field2D operator-(BoutReal lhs, const Field2D &rhs)
Field2D operator*(BoutReal lhs, const Field2D &rhs)
Field2D operator/(BoutReal lhs, const Field2D &rhs)
Field2D operator-(const Field2D &f)

Unary minus. Returns the negative of given field, iterates over whole domain including guard/boundary cells.

void checkData(const Field2D &f, const std::string &region = "RGN_NOBNDRY")

Check if the data is valid.

Throw an exception if f is not allocated or if any elements are non-finite (for CHECK > 2). Loops over all points including the boundaries by default (can be changed using the rgn argument

inline void checkData(const Field2D &f, REGION region)
void invalidateGuards(Field2D &var)

Force guard cells of passed field var to NaN.

inline Field2D DC(const Field2D &f)

Average in the Z direction Field2D has no Z direction — return input

Parameters

f[in] Variable to average

inline Field2D &ddt(Field2D &f)

Returns a reference to the time-derivative of a field f

Wrapper around member function f.timeDeriv()

template<>
inline std::string toString(const Field2D &val)

toString template specialisation Defined in utils.hxx

bool operator==(const Field2D &a, const Field2D &b)

Test if two fields are the same, by calculating the minimum absolute difference between them

std::ostream &operator<<(std::ostream &out, const Field2D &value)
class Field2D : public Field
#include <field2d.hxx>

2D X-Y scalar fields

Handles data for axisymmetric quantities. Essentially the same as the Field3D class.

Public Types

using ind_type = Ind2D
using value_type = BoutReal

Data type.

Public Functions

Field2D(Mesh *localmesh = nullptr, CELL_LOC location_in = CELL_CENTRE, DirectionTypes directions_in = {YDirectionType::Standard, ZDirectionType::Average})

Constructor, taking an optional mesh pointer This mesh pointer is not used until the data is allocated, since Field2D objects can be globals, created before a mesh has been created.

By default the global Mesh pointer (mesh) is used.

Parameters

localmesh[in] The mesh which defines the field size.

Field2D(const Field2D &f)

Copy constructor. After this both fields will share the same underlying data.

inline Field2D(Field2D &&f) noexcept

Move constructor

Field2D(BoutReal val, Mesh *localmesh = nullptr)

Constructor. This creates a Field2D using the global Mesh pointer (mesh) allocates data, and assigns the value val to all points including boundary cells.

Field2D(Array<BoutReal> data, Mesh *localmesh, CELL_LOC location = CELL_CENTRE, DirectionTypes directions_in = {YDirectionType::Standard, ZDirectionType::Average})

Constructor from Array and Mesh.

~Field2D() override

Destructor

Field2D &allocate()

Ensure data is allocated.

inline bool isAllocated() const

Test if data is allocated.

Field2D *timeDeriv()

Return a pointer to the time-derivative field.

inline virtual int getNx() const override

Return the number of nx points

inline virtual int getNy() const override

Return the number of ny points

inline virtual int getNz() const override

Return the number of nz points

inline virtual Field2D &setLocation(CELL_LOC new_location) override

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.

inline virtual Field2D &setDirectionY(YDirectionType d) override
inline bool hasParallelSlices() const

Check if this field has yup and ydown fields.

inline bool hasYupYdown() const
inline Field2D &yup(std::vector<Field2D>::size_type index = 0)
inline const Field2D &yup(std::vector<Field2D>::size_type index = 0) const
inline Field2D &ydown(std::vector<Field2D>::size_type index = 0)
inline const Field2D &ydown(std::vector<Field2D>::size_type index = 0) const
inline Field2D &ynext(int dir)
inline const Field2D &ynext(int dir) const
Field2D &operator=(const Field2D &rhs)

Assignment from Field2D. After this both fields will share the same underlying data. To make a true copy, call .allocate() after assignment, or use the copy() function.

Field2D &operator=(Field2D &&rhs) noexcept
Field2D &operator=(BoutReal rhs)

Allocates data if not already allocated, then sets all cells to rhs

const Region<Ind2D> &getRegion(REGION region) const

Return a Region<Ind2D> reference to use to iterate over this field.

const Region<Ind2D> &getRegion(const std::string &region_name) const
inline Region<Ind2D>::RegionIndices::const_iterator begin() const
inline Region<Ind2D>::RegionIndices::const_iterator end() const
inline BoutReal &operator[](const Ind2D &d)
inline const BoutReal &operator[](const Ind2D &d) const
BoutReal &operator[](const Ind3D &d)
const BoutReal &operator[](const Ind3D &d) const
inline BoutReal &operator()(int jx, int jy)

Access to the underlying data array.

If CHECK <= 2 then no checks are performed

If CHECK > 2 then both jx and jy are bounds checked. This will significantly reduce performance.

inline const BoutReal &operator()(int jx, int jy) const
inline BoutReal &operator()(int jx, int jy, int jz)

DIrect access to underlying array. This version is for compatibility with Field3D objects

inline const BoutReal &operator()(int jx, int jy, int jz) const
Field2D &operator+=(const Field2D &rhs)

In-place addition. Copy-on-write used if data is shared.

Field2D &operator+=(BoutReal rhs)

In-place addition. Copy-on-write used if data is shared.

Field2D &operator-=(const Field2D &rhs)

In-place subtraction. Copy-on-write used if data is shared.

Field2D &operator-=(BoutReal rhs)

In-place subtraction. Copy-on-write used if data is shared.

Field2D &operator*=(const Field2D &rhs)

In-place multiplication. Copy-on-write used if data is shared.

Field2D &operator*=(BoutReal rhs)

In-place multiplication. Copy-on-write used if data is shared.

Field2D &operator/=(const Field2D &rhs)

In-place division. Copy-on-write used if data is shared.

Field2D &operator/=(BoutReal rhs)

In-place division. Copy-on-write used if data is shared.

inline virtual bool is3D() const override

True if variable is 3D.

inline virtual void doneComms() override
virtual void applyBoundary(bool init = false) override
void applyBoundary(BoutReal time)
void applyBoundary(const std::string &condition)
inline void applyBoundary(const char *condition)
void applyBoundary(const std::string &region, const std::string &condition)
virtual void applyTDerivBoundary() override
void setBoundaryTo(const Field2D &f2d)

Copy the boundary region.

Public Members

Array<BoutReal> data

Internal data array. Handles allocation/freeing of memory.

Private Members

int nx = {-1}

Array sizes (from fieldmesh). These are valid only if fieldmesh is not null.

int ny = {-1}
Field2D *deriv = {nullptr}

Time-derivative, can be nullptr.

Friends

friend class Vector2D
friend void swap(Field2D &first, Field2D &second) noexcept