OGS
ZeroMeshFieldDataByMaterialIDs.cpp
Go to the documentation of this file.
1
13
14#include <algorithm>
15#include <functional>
16
19#include "MeshLib/Mesh.h"
21
22namespace MeshToolsLib
23{
25 MeshLib::Mesh& mesh, std::vector<int> const& selected_material_ids)
26{
27 auto const materialIds = materialIDs(mesh);
28 if (!materialIds)
29 {
31 "Mesh contains no int-property vector named 'MaterialIDs' needed "
32 "by the 'zero_mesh_field_data_by_materialIDs'");
33 }
34
35 std::vector<std::size_t> element_ids_for_selected_materials;
36 for (std::size_t i = 0; i < materialIds->size(); ++i)
37 {
38 if (std::find(selected_material_ids.begin(),
39 selected_material_ids.end(),
40 (*materialIds)[i]) != selected_material_ids.end())
41 {
42 element_ids_for_selected_materials.push_back(i);
43 }
44 }
45
46 MeshLib::Properties& properties = mesh.getProperties();
47
48 std::vector<std::size_t> element_ip_data_offsets;
49
50 for (auto const& [name, property] : properties)
51 {
52 if (auto const item_type = property->getMeshItemType();
54 {
55 continue;
56 }
57
58 // For special field data such as OGS_VERSION,
59 // IntegrationPointMetaData,
60 // etc., which are not "real" integration points:
61 if (!property->getPropertyName().ends_with("_ip"))
62 {
63 continue;
64 }
65
66 if (properties.template hasPropertyVector<double>(
68 {
69 auto& pv = *properties.template getPropertyVector<double>(name);
70 const int n_components = pv.getNumberOfGlobalComponents();
71
72 if (element_ip_data_offsets.empty())
73 {
74 // The returned values has already been multiplied with
75 // pv.getNumberOfGlobalComponents()
76 element_ip_data_offsets =
78 mesh.getElements(), pv, properties);
79
80 // element_ip_data_offsets / pv.getNumberOfGlobalComponents()
81 std::transform(element_ip_data_offsets.begin(),
82 element_ip_data_offsets.end(),
83 element_ip_data_offsets.begin(),
84 [n = n_components](double const v)
85 { return v / n; });
86 }
87
88 for (auto const element_id : element_ids_for_selected_materials)
89 {
90 std::fill(
91 pv.begin() +
92 n_components * element_ip_data_offsets[element_id],
93 pv.begin() +
94 n_components * element_ip_data_offsets[element_id + 1],
95 0.0);
96 }
97 }
98 }
99}
100} // namespace MeshToolsLib
Definition of the Element class.
#define OGS_FATAL(...)
Definition Error.h:26
Definition of the Mesh class.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
Properties & getProperties()
Definition Mesh.h:134
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition Properties.h:36
std::vector< std::size_t > getIntegrationPointDataOffsetsOfMeshElements(std::vector< MeshLib::Element * > const &mesh_elements, MeshLib::PropertyVectorBase const &pv, MeshLib::Properties const &properties)
void zeroMeshFieldDataByMaterialIDs(MeshLib::Mesh &mesh, std::vector< int > const &selected_material_ids)