OGS 6.2.0-97-g4a610c866
ResetMeshElementProperty.h
Go to the documentation of this file.
1 /*
2  * \copyright
3  * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org)
4  * Distributed under a Modified BSD License.
5  * See accompanying file LICENSE.txt or
6  * http://www.opengeosys.org/project/license
7  *
8  */
9 
10 #pragma once
11 
12 #include <algorithm>
13 #include <cstdlib>
14 #include <vector>
15 
18 
19 #include "GeoLib/GEOObjects.h"
20 #include "GeoLib/Polygon.h"
21 
23 
24 #include "MeshLib/Mesh.h"
25 #include "MeshLib/Node.h"
27 
28 namespace MeshGeoToolsLib
29 {
30 template <typename PT>
32  GeoLib::Polygon const& polygon,
33  std::string const& property_name,
34  PT new_property_value,
35  int restrict_to_material_id)
36 {
37  auto* const pv = MeshLib::getOrCreateMeshProperty<PT>(
38  mesh, property_name, MeshLib::MeshItemType::Cell, 1);
39 
40  if (pv->getMeshItemType() != MeshLib::MeshItemType::Cell)
41  {
42  ERR("Values of the PropertyVector are not assigned to cells.");
43  return;
44  }
45 
46  auto is_node_outside =
47  [outside = markNodesOutSideOfPolygon(mesh.getNodes(), polygon)](
48  auto const* node_ptr) { return outside[node_ptr->getID()]; };
49 
50  auto const* material_ids =
51  mesh.getProperties().getPropertyVector<int>("MaterialIDs");
52 
53  if (restrict_to_material_id != -1 && !material_ids)
54  {
55  OGS_FATAL(
56  "Restriction of reseting a property in a polygonal region "
57  "requires that a MaterialIDs data array is available in the "
58  "mesh.");
59  }
60 
61  auto has_element_required_material_id = [&](int const element_id) {
62  return restrict_to_material_id == -1 ||
63  (*material_ids)[element_id] == restrict_to_material_id;
64  };
65 
66  for (std::size_t j(0); j < mesh.getElements().size(); ++j)
67  {
68  MeshLib::Element const* const elem(mesh.getElements()[j]);
69  if (std::all_of(elem->getNodes(),
70  elem->getNodes() + elem->getNumberOfNodes(),
71  is_node_outside))
72  {
73  continue;
74  }
75  if (has_element_required_material_id(elem->getID()))
76  {
77  (*pv)[j] = new_property_value;
78  }
79  }
80 }
81 
82 } // namespace MeshGeoToolsLib
Implementation of heuristic search length strategy.
void resetMeshElementProperty(MeshLib::Mesh &mesh, GeoLib::Polygon const &polygon, std::string const &property_name, PT new_property_value, int restrict_to_material_id)
Definition of the Node class.
Definition of the Mesh class.
std::vector< bool > markNodesOutSideOfPolygon(std::vector< MeshLib::Node *> const &nodes, GeoLib::Polygon const &polygon)
Definition of readMeshFromFile function.
Definition of the Polygon class.
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
Definition of the Element class.