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