OGS 6.2.1-97-g73d1aeda3
GocadNode.h
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #include <bitset>
12 #include <vector>
13 
14 #include "BaseLib/Error.h"
15 
16 #include "MeshLib/Node.h"
17 
18 namespace FileIO
19 {
20 namespace Gocad
21 {
22 enum class FaceDirection : char
23 {
24  U,
25  V,
26  W
27 };
28 
29 class GocadNode : public MeshLib::Node
30 {
31 public:
32  GocadNode(double const* const coords, std::size_t id,
33  std::size_t layer_transition_idx)
34  : Node(coords, id), _layer_transition_idx(layer_transition_idx)
35  {
36  }
37 
38  GocadNode() = delete;
39  GocadNode(GocadNode const& src) = default;
40  GocadNode(GocadNode&& src) = default;
41  GocadNode& operator=(GocadNode&& rhs) = default;
42  GocadNode& operator=(GocadNode const& rhs) = default;
43  ~GocadNode() override = default;
44 
45  void setFaceSet(std::size_t face_set_number, std::size_t face_indicator)
46  {
47  _face_set_membership.set(face_set_number);
48  switch (face_indicator)
49  {
50  case 0:
51  _face_directions.emplace_back(face_set_number,
53  break;
54  case 1:
55  _face_directions.emplace_back(face_set_number,
57  break;
58  case 2:
59  _face_directions.emplace_back(face_set_number,
61  break;
62  default:
63  OGS_FATAL("GocadNode::setFaceSet(): unknown face indicator %d.",
64  face_indicator);
65  }
66  }
67 
74  bool isMemberOfFaceSet(std::size_t face_set_number) const
75  {
76  return _face_set_membership[face_set_number];
77  }
78 
79  bool isMemberOfAnyFaceSet() const { return _face_set_membership.any(); }
80 
81  void resetID(std::size_t id) { this->setID(id); }
82 
83  std::bitset<128> const& getFaceSetMembership() const
84  {
85  return _face_set_membership;
86  }
87 
88  FaceDirection getFaceDirection(std::size_t const face_set_number) const
89  {
90  auto const it = std::find_if(
91  _face_directions.begin(), _face_directions.end(),
92  [&](auto const fi) { return fi.first == face_set_number; });
93  if (it == _face_directions.end())
94  {
95  OGS_FATAL(
96  "GocadNode %d: Could not found face indicator for face set %d",
97  _id, face_set_number);
98  }
99  return it->second;
100  }
101 
102  std::size_t getLayerTransitionIndex() const
103  {
104  return _layer_transition_idx;
105  }
106 
107 protected:
108  friend class GocadSplitNode;
109  std::vector<std::pair<std::size_t, FaceDirection>> _face_directions;
110 
111 private:
112  std::bitset<128> _face_set_membership;
114 };
115 
116 bool operator<=(GocadNode const& n0, GocadNode const& n1);
117 
118 class GocadSplitNode final : public GocadNode
119 {
120 public:
121  GocadSplitNode(double const* const coords, std::size_t id,
122  std::array<std::size_t, 3> const& grid_coords,
123  std::bitset<8> const& affected_cells,
124  std::size_t layer_transition_idx)
125  : GocadNode(coords, id, layer_transition_idx),
126  _grid_coords(grid_coords),
127  _affected_cells(affected_cells)
128  {
129  }
130 
131  std::array<std::size_t, 3> const& getGridCoords() const
132  {
133  return _grid_coords;
134  }
135  std::bitset<8> const& getAffectedCells() const
136  {
137  return _affected_cells;
138  }
139  void transmitFaceDirections(GocadNode const& gocad_node)
140  {
141  _face_directions = gocad_node._face_directions;
142  }
143 
144 private:
145  std::array<std::size_t, 3> _grid_coords;
146  std::bitset<8> const _affected_cells;
147 };
148 
149 } // end namespace Gocad
150 } // end namespace FileIO
151 
void setFaceSet(std::size_t face_set_number, std::size_t face_indicator)
Definition: GocadNode.h:45
Definition of the Node class.
std::bitset< 8 > const _affected_cells
Definition: GocadNode.h:146
std::array< std::size_t, 3 > const & getGridCoords() const
Definition: GocadNode.h:131
GocadSplitNode(double const *const coords, std::size_t id, std::array< std::size_t, 3 > const &grid_coords, std::bitset< 8 > const &affected_cells, std::size_t layer_transition_idx)
Definition: GocadNode.h:121
std::size_t _layer_transition_idx
Definition: GocadNode.h:113
std::array< std::size_t, 3 > _grid_coords
Definition: GocadNode.h:145
void resetID(std::size_t id)
Definition: GocadNode.h:81
bool isMemberOfAnyFaceSet() const
Definition: GocadNode.h:79
std::bitset< 128 > const & getFaceSetMembership() const
Definition: GocadNode.h:83
bool operator<=(GocadNode const &n0, GocadNode const &n1)
Definition: GocadNode.cpp:15
bool isMemberOfFaceSet(std::size_t face_set_number) const
Definition: GocadNode.h:74
GocadNode(double const *const coords, std::size_t id, std::size_t layer_transition_idx)
Definition: GocadNode.h:32
FaceDirection getFaceDirection(std::size_t const face_set_number) const
Definition: GocadNode.h:88
void transmitFaceDirections(GocadNode const &gocad_node)
Definition: GocadNode.h:139
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
std::size_t getLayerTransitionIndex() const
Definition: GocadNode.h:102
std::bitset< 8 > const & getAffectedCells() const
Definition: GocadNode.h:135
std::vector< std::pair< std::size_t, FaceDirection > > _face_directions
Definition: GocadNode.h:109
std::bitset< 128 > _face_set_membership
Definition: GocadNode.h:112