File griddata.hxx¶
-
class
GridDataSource
¶ - #include <griddata.hxx>
Interface class to serve grid data.
Provides a generic interface for sources of equilibrium data. Could be used to simplify interfacing between BOUT++ and other codes
Subclassed by GridFile, GridFromOptions
Public Types
-
enum
Direction
¶ Values:
-
X
-
Y
-
Z
-
Public Functions
-
GridDataSource
(const bool source_is_file = false)¶
-
virtual
~GridDataSource
()¶
-
virtual bool
hasVar
(const std::string &name) = 0¶ Test if source can supply a variable.
-
virtual bool
get
(Mesh *m, std::string &sval, const std::string &name, const std::string &def = "") = 0¶ Get a string.
-
virtual bool
get
(Mesh *m, BoutReal &rval, const std::string &name, BoutReal def = 0.0) = 0¶ Get a BoutReal number.
-
virtual bool
get
(Mesh *m, std::vector<int> &var, const std::string &name, int len, int offset = 0, Direction dir = GridDataSource::X) = 0¶
-
virtual bool
get
(Mesh *m, std::vector<BoutReal> &var, const std::string &name, int len, int offset = 0, Direction dir = GridDataSource::X) = 0¶
-
virtual bool
hasYBoundaryGuards
() = 0¶ Are y-boundary guard cells read from the source?
Public Members
-
const bool
is_file
¶ Is the data source a grid file?
-
enum
-
class
GridFile
: public GridDataSource¶ - #include <griddata.hxx>
Interface to grid data in a file.
This is a thin wrapper around a DataFormat object. Only needs to implement reading routines.
Public Functions
-
GridFile
()¶
-
GridFile
(std::unique_ptr<DataFormat> format, std::string gridfilename)¶ Creates a GridFile object
format Pointer to DataFormat. This will be deleted in destructor
-
~GridFile
()¶
-
bool
hasVar
(const std::string &name)¶ Tests whether a variable exists in the file
Currently this is done by getting the variable’s size, and testing for zero size.
-
bool
get
(Mesh *m, std::string &sval, const std::string &name, const std::string &def = "")¶ Get a string.
Read a string from file. If the string is not found, then string is set to “” and false is returned.
Inputs
m Pointer to mesh, not used name String containing name of variable
Outputs
sval Reference to string
Returns
Boolean. True on success.
-
bool
get
(Mesh *m, int &ival, const std::string &name, int def = 0)¶ Get an integer.
Read a single integer from file. If the integer is not found, then ival is set to zero and false is returned.
Inputs
m Pointer to mesh, not used name String containing name of variable
Outputs
ival Reference to integer
Returns
Boolean. True on success.
-
bool
get
(Mesh *m, BoutReal &rval, const std::string &name, BoutReal def = 0.0)¶ Get a BoutReal number.
-
bool
get
(Mesh *m, Field2D &var, const std::string &name, BoutReal def = 0.0)¶ Reads a 2D, 3D or FieldPerp field variable from a file
Successfully reads Field2D or FieldPerp if the variable in the file is 0-D or 2-D. Successfully reads Field3D if the variable in the file is 0-D, 2-D or 3-D.
-
bool
get
(Mesh *m, std::vector<int> &var, const std::string &name, int len, int offset = 0, GridDataSource::Direction dir = GridDataSource::X)¶
-
bool
get
(Mesh *m, std::vector<BoutReal> &var, const std::string &name, int len, int offset = 0, GridDataSource::Direction dir = GridDataSource::X)¶
-
bool
hasYBoundaryGuards
()¶ Are y-boundary guard cells read from the source?
Private Functions
-
bool
readgrid_3dvar_fft
(Mesh *m, const std::string &name, int yread, int ydest, int ysize, int xread, int xdest, int xsize, Field3D &var)¶ Reads in a portion of the X-Y domain.
-
bool
readgrid_3dvar_real
(const std::string &name, int yread, int ydest, int ysize, int xread, int xdest, int xsize, Field3D &var)¶ Reads a 3D variable directly from the file, without any processing
-
bool
readgrid_perpvar_fft
(Mesh *m, const std::string &name, int xread, int xdest, int xsize, FieldPerp &var)¶
-
bool
readgrid_perpvar_real
(const std::string &name, int xread, int xdest, int xsize, FieldPerp &var)¶ Reads a FieldPerp variable directly from the file, without any processing
-
void
readField
(Mesh *m, const std::string &name, int ys, int yd, int ny_to_read, int xs, int xd, int nx_to_read, const std::vector<int> &size, Field2D &var)¶
Private Members
-
std::unique_ptr<DataFormat>
file
¶
-
std::string
filename
¶
-
int
grid_yguards
= {0}¶
-
int
ny_inner
= {0}¶
-
-
class
GridFromOptions
: public GridDataSource¶ - #include <griddata.hxx>
Provides a way to create variables from options, which can be set in the input file or on the command line. This is done using FieldFactory to convert string expressions into fields.
Public Functions
-
GridFromOptions
(Options *opt = nullptr)¶ Constructor, passing optional Options object
- Parameters
opt
: Options section to use as input. By default the “mesh” section under root will be used.
-
bool
hasVar
(const std::string &name)¶ Checks if the options has a given variable
-
bool
get
(Mesh *mesh, std::string &sval, const std::string &name, const std::string &def = "")¶ Reads strings from options. Uses Options::get to handle expressions
- Return
- True if option is set, false if ival is default (0)
- Parameters
mesh
: Not usedname
: Name of variablesval
: Always given a value, defaults to 0
-
bool
get
(Mesh *mesh, int &ival, const std::string &name, int def = 0)¶ Reads integers from options. Uses Options::get to handle expressions
- Return
- True if option is set, false if ival is default (0)
- Parameters
mesh
: Not usedival
: The variable which will be setname
: Name of variabledef
: Default value to use if option not found
-
bool
get
(Mesh *mesh, BoutReal &rval, const std::string &name, BoutReal def = 0.0)¶ Reads BoutReal from options. Uses Options::get to handle expressions
- Return
- True if option is set, false if ival is default (0)
- Parameters
mesh
: Not usedname
: Name of variablerval
: Always given a value, defaults to 0
-
bool
get
(Mesh *mesh, Field2D &var, const std::string &name, BoutReal def = 0.0)¶ Get a Field2D object by finding the option with the given name, and passing the string to FieldFactory
- Parameters
mesh
: The Mesh object over which the field is definedvar
: The variable which will be setname
: The name in the options. Not case sensitivedef
: Default value to use if option not found
-
bool
get
(Mesh *mesh, Field3D &var, const std::string &name, BoutReal def = 0.0)¶ Get a Field3D object by finding the option with the given name, and passing the string to FieldFactory
- Parameters
mesh
: The Mesh object over which the field is definedvar
: The variable which will be setname
: The name in the options. Not case sensitivedef
: Default value to use if option not found
-
bool
get
(Mesh *mesh, FieldPerp &var, const std::string &name, BoutReal def = 0.0)¶ Get a FieldPerp object by finding the option with the given name, and passing the string to FieldFactory
- Parameters
mesh
: The Mesh object over which the field is definedvar
: The variable which will be setname
: The name in the options. Not case sensitivedef
: Default value to use if option not found
-
bool
get
(Mesh *mesh, std::vector<int> &var, const std::string &name, int len, int offset = 0, GridDataSource::Direction dir = GridDataSource::X)¶ Get an array of integers. Currently reads a single integer, and sets the whole array to the same value
- Parameters
mesh
: Mesh objectvar
: A vector which will be resized to length lenname
: The name of the optionlen
: The length of the vectoroffset
: Not currently useddir
: The direction (X,Y,Z) of the array
-
bool
get
(Mesh *mesh, std::vector<BoutReal> &var, const std::string &name, int len, int offset = 0, GridDataSource::Direction dir = GridDataSource::X)¶ Get an array of BoutReals. Uses FieldFactory to generate an expression, then evaluates it at indices depending on the direction (dir) and length (len)
- Parameters
mesh
: Mesh objectvar
: A vector which will be resized to length lenname
: The name of the optionlen
: The length of the vectoroffset
: The index where this vector starts i.e. var[0] is at x=offset if dir is X.dir
: The direction (X,Y,Z) of the array
-
bool
hasYBoundaryGuards
()¶ Are y-boundary guard cells read from the source?
-