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