OGS
FileIO::Gocad::IndexCalculator Class Referencefinal

Detailed Description

Class for calculating the index to given 3d position within the structured grid.

Definition at line 23 of file IndexCalculator.h.

#include <IndexCalculator.h>

Public Member Functions

 IndexCalculator (std::size_t x_dim, std::size_t y_dim, std::size_t z_dim)
 IndexCalculator ()=default
std::size_t operator() (std::array< std::size_t, 3 > const &c) const
std::size_t getCellIdx (std::size_t u, std::size_t v, std::size_t w) const
std::array< std::size_t, 3 > getCoordsForID (std::size_t id) const

Public Attributes

std::size_t _x_dim {0}
std::size_t _y_dim {0}
std::size_t _z_dim {0}
std::size_t _n_nodes {0}
std::size_t _n_cells {0}

Constructor & Destructor Documentation

◆ IndexCalculator() [1/2]

FileIO::Gocad::IndexCalculator::IndexCalculator ( std::size_t x_dim,
std::size_t y_dim,
std::size_t z_dim )
inline

Constructor initializes the dimensions.

Parameters
x_dim
y_dim
z_dim

Definition at line 32 of file IndexCalculator.h.

33 : _x_dim(x_dim),
34 _y_dim(y_dim),
35 _z_dim(z_dim),
36 _n_nodes(x_dim * y_dim * z_dim),
37 _n_cells((_x_dim - 1) * (_y_dim - 1) * (_z_dim - 1))
38 {
39 }

References _n_cells, _n_nodes, _x_dim, _y_dim, and _z_dim.

◆ IndexCalculator() [2/2]

FileIO::Gocad::IndexCalculator::IndexCalculator ( )
default

Member Function Documentation

◆ getCellIdx()

std::size_t FileIO::Gocad::IndexCalculator::getCellIdx ( std::size_t u,
std::size_t v,
std::size_t w ) const
inline

Definition at line 53 of file IndexCalculator.h.

54 {
55 // ensure (u,v,w) is a valid cell
56 if (u >= _x_dim - 1 || v >= _y_dim - 1 || w >= _z_dim - 1)
57 {
58 ERR("GocadSGridReader::IndexCalculator::getCellIdx(): At least "
59 "one grid coordinate to big.");
60 ERR("\t Given: ({:d}, {:d}, {:d}), max allowed cell grid coords: "
61 "({:d}, {:d}, {:d}).",
62 u, v, w, _x_dim - 1, _y_dim - 1, _z_dim - 1);
63 return std::numeric_limits<std::size_t>::max();
64 }
65
66 return (_x_dim - 1) * (_y_dim - 1) + v * (_x_dim - 1) + u;
67 }
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40

References _x_dim, _y_dim, _z_dim, and ERR().

◆ getCoordsForID()

std::array< std::size_t, 3 > FileIO::Gocad::IndexCalculator::getCoordsForID ( std::size_t id) const
inline

Definition at line 69 of file IndexCalculator.h.

70 {
71 std::array<std::size_t, 3> const coords{
72 (id % (_x_dim * _y_dim)) % _x_dim,
73 (id % (_x_dim * _y_dim)) / _x_dim, id / (_x_dim * _y_dim)};
74 return coords;
75 }
constexpr ranges::views::view_closure coords
Definition Mesh.h:223

References _x_dim, and _y_dim.

◆ operator()()

std::size_t FileIO::Gocad::IndexCalculator::operator() ( std::array< std::size_t, 3 > const & c) const
inline

Definition at line 43 of file IndexCalculator.h.

44 {
45 const std::size_t idx(c[2] * _x_dim * _y_dim + c[1] * _x_dim + c[0]);
46 if (idx >= _n_nodes)
47 {
48 return std::numeric_limits<std::size_t>::max();
49 }
50 return idx;
51 }

References _n_nodes, _x_dim, and _y_dim.

Member Data Documentation

◆ _n_cells

std::size_t FileIO::Gocad::IndexCalculator::_n_cells {0}

Definition at line 81 of file IndexCalculator.h.

81{0};

Referenced by IndexCalculator().

◆ _n_nodes

std::size_t FileIO::Gocad::IndexCalculator::_n_nodes {0}

Definition at line 80 of file IndexCalculator.h.

80{0};

Referenced by IndexCalculator(), and operator()().

◆ _x_dim

std::size_t FileIO::Gocad::IndexCalculator::_x_dim {0}

Definition at line 77 of file IndexCalculator.h.

77{0};

Referenced by IndexCalculator(), getCellIdx(), getCoordsForID(), and operator()().

◆ _y_dim

std::size_t FileIO::Gocad::IndexCalculator::_y_dim {0}

Definition at line 78 of file IndexCalculator.h.

78{0};

Referenced by IndexCalculator(), getCellIdx(), getCoordsForID(), and operator()().

◆ _z_dim

std::size_t FileIO::Gocad::IndexCalculator::_z_dim {0}

Definition at line 79 of file IndexCalculator.h.

79{0};

Referenced by IndexCalculator(), and getCellIdx().


The documentation for this class was generated from the following file: