OGS 6.1.0-1721-g6382411ad
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 
16 #include <tclap/CmdLine.h>
17 
20 
23 
24 #include "GeoLib/GEOObjects.h"
25 #include "GeoLib/Polygon.h"
26 
28 
29 #include "MeshLib/Mesh.h"
30 #include "MeshLib/Node.h"
32 
33 namespace MeshGeoToolsLib
34 {
35 template <typename PT>
37  GeoLib::Polygon const& polygon,
38  std::string const& property_name,
39  PT new_property_value,
40  int restrict_to_material_id)
41 {
42  auto* const pv = MeshLib::getOrCreateMeshProperty<PT>(
43  mesh, property_name, MeshLib::MeshItemType::Cell, 1);
44 
45  if (pv->getMeshItemType() != MeshLib::MeshItemType::Cell)
46  {
47  ERR("Values of the PropertyVector are not assigned to cells.");
48  return;
49  }
50 
51  auto is_node_outside =
52  [outside = markNodesOutSideOfPolygon(mesh.getNodes(), polygon)](
53  auto const* node_ptr) { return outside[node_ptr->getID()]; };
54 
55  auto const* material_ids =
56  mesh.getProperties().getPropertyVector<int>("MaterialIDs");
57 
58  if (restrict_to_material_id != -1 && !material_ids)
59  {
60  OGS_FATAL(
61  "Restriction of reseting a property in a polygonal region "
62  "requires that a MaterialIDs data array is available in the "
63  "mesh.");
64  }
65 
66  auto has_element_required_material_id = [&](int const element_id) {
67  return restrict_to_material_id == -1 ||
68  (*material_ids)[element_id] == restrict_to_material_id;
69  };
70 
71  for (std::size_t j(0); j < mesh.getElements().size(); ++j)
72  {
73  MeshLib::Element const* const elem(mesh.getElements()[j]);
74  if (std::all_of(elem->getNodes(),
75  elem->getNodes() + elem->getNumberOfNodes(),
76  is_node_outside))
77  {
78  continue;
79  }
80  if (has_element_required_material_id(elem->getID()))
81  {
82  (*pv)[j] = new_property_value;
83  }
84  }
85 }
86 
87 } // end namespace
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:71
Definition of the Element class.