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