OGS
FileIO::Gocad::IndexCalculator Class Referencefinal

Detailed Description

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

Definition at line 29 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 38 of file IndexCalculator.h.

39 : _x_dim(x_dim),
40 _y_dim(y_dim),
41 _z_dim(z_dim),
42 _n_nodes(x_dim * y_dim * z_dim),
43 _n_cells((_x_dim - 1) * (_y_dim - 1) * (_z_dim - 1))
44 {
45 }

◆ 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 59 of file IndexCalculator.h.

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

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

Referenced by FileIO::Gocad::GocadSGridReader::applySplitInformation(), FileIO::Gocad::GocadSGridReader::createElements(), FileIO::Gocad::GocadSGridReader::mapRegionFlagsToCellProperties(), and FileIO::Gocad::GocadSGridReader::parseFaceSet().

◆ getCoordsForID()

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

Definition at line 75 of file IndexCalculator.h.

76 {
77 std::array<std::size_t, 3> const coords{
78 (id % (_x_dim * _y_dim)) % _x_dim,
79 (id % (_x_dim * _y_dim)) / _x_dim, id / (_x_dim * _y_dim)};
80 return coords;
81 }
constexpr ranges::views::view_closure coords
Definition Mesh.h:232

References _x_dim, and _y_dim.

Referenced by FileIO::Gocad::GocadSGridReader::addFaceSetQuad(), FileIO::Gocad::GocadSGridReader::parseFaceSet(), and FileIO::Gocad::GocadSGridReader::readNodesBinary().

◆ operator()()

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

Definition at line 49 of file IndexCalculator.h.

50 {
51 const std::size_t idx(c[2] * _x_dim * _y_dim + c[1] * _x_dim + c[0]);
52 if (idx >= _n_nodes)
53 {
54 return std::numeric_limits<std::size_t>::max();
55 }
56 return idx;
57 }

References _n_nodes, _x_dim, and _y_dim.

Member Data Documentation

◆ _n_cells

◆ _n_nodes

◆ _x_dim

◆ _y_dim

◆ _z_dim


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