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