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.

Field2D toFieldAligned(const Field2D &f, const std::string &region = "RGN_ALL")
Field2D toFieldAligned(const Field2D &f, REGION region)
Field2D fromFieldAligned(const Field2D &f, const std::string &region = "RGN_ALL")
Field2D fromFieldAligned(const Field2D &f, REGION region)
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

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

Force guard cells of passed field var to NaN.

Field2D &ddt(Field2D &f)

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

Wrapper around member function f.timeDeriv()

template<>
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, public FieldData
#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::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: The mesh which defines the field size.

Field2D(const Field2D &f)

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

Field2D(Field2D &&f)

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

Constructor from Array and Mesh.

~Field2D()

Destructor

Field2D &allocate()

Ensure data is allocated.

bool isAllocated() const

Test if data is allocated.

Field2D *timeDeriv()

Return a pointer to the time-derivative field.

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

Field2D &setLocation(CELL_LOC location)
Field2D &setDirectionY(YDirectionType d)
bool hasParallelSlices() const

Check if this field has yup and ydown fields.

bool hasYupYdown() const
Field2D &yup(std::vector<Field2D>::size_type index = 0)
const Field2D &yup(std::vector<Field2D>::size_type index = 0) const
Field2D &ydown(std::vector<Field2D>::size_type index = 0)
const Field2D &ydown(std::vector<Field2D>::size_type index = 0) const
Field2D &ynext(int dir)
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=(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
Region<Ind2D>::RegionIndices::const_iterator begin() const
Region<Ind2D>::RegionIndices::const_iterator end() const
BoutReal &operator[](const Ind2D &d)
const BoutReal &operator[](const Ind2D &d) const
BoutReal &operator[](const Ind3D &d)
const BoutReal &operator[](const Ind3D &d) const
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.

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

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

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.

void accept(FieldVisitor &v)

Visitor pattern support.

bool isReal() const

Returns true if field consists of BoutReal values.

bool is3D() const

True if variable is 3D.

int byteSize() const

Number of bytes for a single point.

int BoutRealSize() const

Number of BoutReals (not implemented if not BoutReal)

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

Copy the boundary region.

Private Members

int nx = {-1}

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

int ny = {-1}
Array<BoutReal> data

Internal data array. Handles allocation/freeing of memory.

Field2D *deriv = {nullptr}

Time-derivative, can be nullptr.

Friends

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