OGS
MeshUtils.cpp
Go to the documentation of this file.
1 
10 #include "MeshUtils.h"
11 
12 #include <set>
13 
14 #include "BaseLib/Algorithm.h"
16 #include "MeshLib/Mesh.h"
18 #include "MeshLib/Node.h"
19 
20 namespace
21 {
22 std::vector<MeshLib::Element*> extractOneDimensionalElements(
23  std::vector<MeshLib::Element*> const& elements)
24 {
25  std::vector<MeshLib::Element*> one_dimensional_elements;
26 
27  copy_if(begin(elements), end(elements),
28  back_inserter(one_dimensional_elements),
29  [](MeshLib::Element* e) { return e->getDimension() == 1; });
30 
31  return one_dimensional_elements;
32 }
33 
34 std::vector<int> getUniqueMaterialIds(
35  std::vector<int> const& material_ids,
36  std::vector<MeshLib::Element*> const& elements)
37 {
38  std::set<int> unique_material_ids;
39  std::transform(begin(elements), end(elements),
40  inserter(unique_material_ids, end(unique_material_ids)),
41  [&material_ids](MeshLib::Element const* const e)
42  { return material_ids[e->getID()]; });
43  return {begin(unique_material_ids), end(unique_material_ids)};
44 }
45 } // namespace
46 
47 namespace ProcessLib
48 {
49 namespace HeatTransportBHE
50 {
52 {
53  std::vector<MeshLib::Element*> const all_bhe_elements =
55 
56  // finally counting two types of elements
57  // They are (i) soil, and (ii) BHE type of elements
58  DBUG("-> found total {:d} soil elements and {:d} BHE elements",
59  mesh.getNumberOfElements() - all_bhe_elements.size(),
60  all_bhe_elements.size());
61 
62  // get BHE material IDs
63  auto const* const opt_material_ids = MeshLib::materialIDs(mesh);
64  if (opt_material_ids == nullptr)
65  {
66  OGS_FATAL("Not able to get material IDs! ");
67  }
68  auto const& material_ids = *opt_material_ids;
69 
70  auto const& bhe_material_ids =
71  getUniqueMaterialIds(material_ids, all_bhe_elements);
72  DBUG("-> found {:d} BHE material groups", bhe_material_ids.size());
73 
74  // create a vector of BHE elements for each group
75  std::vector<std::vector<MeshLib::Element*>> bhe_elements;
76  bhe_elements.resize(bhe_material_ids.size());
77  for (unsigned bhe_id = 0; bhe_id < bhe_material_ids.size(); bhe_id++)
78  {
79  const auto bhe_mat_id = bhe_material_ids[bhe_id];
80  std::vector<MeshLib::Element*>& vec_elements = bhe_elements[bhe_id];
81  copy_if(begin(all_bhe_elements), end(all_bhe_elements),
82  back_inserter(vec_elements),
83  [&](MeshLib::Element* e)
84  { return material_ids[e->getID()] == bhe_mat_id; });
85  DBUG("-> found {:d} elements on the BHE_{:d}", vec_elements.size(),
86  bhe_id);
87  }
88 
89  // get a vector of BHE nodes
90  std::vector<std::vector<MeshLib::Node*>> bhe_nodes;
91  bhe_nodes.resize(bhe_material_ids.size());
92  for (unsigned bhe_id = 0; bhe_id < bhe_material_ids.size(); bhe_id++)
93  {
94  std::vector<MeshLib::Node*>& vec_nodes = bhe_nodes[bhe_id];
95  for (MeshLib::Element* e : bhe_elements[bhe_id])
96  {
97  for (unsigned i = 0; i < e->getNumberOfNodes(); i++)
98  {
99  vec_nodes.push_back(const_cast<MeshLib::Node*>(e->getNode(i)));
100  }
101  }
102  BaseLib::makeVectorUnique(vec_nodes,
103  [](MeshLib::Node* node1, MeshLib::Node* node2)
104  { return node1->getID() < node2->getID(); });
105  DBUG("-> found {:d} nodes on the BHE_{:d}", vec_nodes.size(), bhe_id);
106  }
107 
108  return {bhe_material_ids, bhe_elements, bhe_nodes};
109 }
110 } // end of namespace HeatTransportBHE
111 } // namespace ProcessLib
Definition of the Element class.
#define OGS_FATAL(...)
Definition: Error.h:26
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
Definition of the Mesh class.
Definition of the Node class.
std::size_t getID() const
Definition: Point3dWithID.h:62
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:82
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:98
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:86
void makeVectorUnique(std::vector< T > &v)
Definition: Algorithm.h:209
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:258
BHEMeshData getBHEDataInMesh(MeshLib::Mesh const &mesh)
Definition: MeshUtils.cpp:51
std::vector< int > getUniqueMaterialIds(std::vector< int > const &material_ids, std::vector< MeshLib::Element * > const &elements)
Definition: MeshUtils.cpp:34
std::vector< MeshLib::Element * > extractOneDimensionalElements(std::vector< MeshLib::Element * > const &elements)
Definition: MeshUtils.cpp:22