OGS 6.2.0-97-g4a610c866
DeactivatedSubdomain.cpp
Go to the documentation of this file.
1 
13 #include "DeactivatedSubdomain.h"
14 
15 #include <logog/include/logog.hpp>
16 
17 #include "BaseLib/ConfigTree.h"
18 #include "BaseLib/Error.h"
19 
21 #include "MeshLib/Mesh.h"
23 #include "MeshLib/Node.h"
24 
25 namespace ProcessLib
26 {
28  "zero_for_element_deactivation_approach";
29 
31  std::unique_ptr<MeshLib::Mesh> deactivated_subdomain_mesh_,
32  std::vector<MeshLib::Node*>&& inactive_nodes_)
33  : mesh(std::move(deactivated_subdomain_mesh_)),
34  inactive_nodes(std::move(inactive_nodes_))
35 {
36 }
37 
39  std::unique_ptr<BaseLib::TimeInterval> time_interval_,
40  std::vector<int>&& materialIDs_,
41  std::vector<std::unique_ptr<DeactivetedSubdomainMesh>>&&
42  deactivated_subdomain_meshes_)
43  : time_interval(std::move(time_interval_)),
44  materialIDs(std::move(materialIDs_)),
45  deactivated_subdomain_meshes(std::move(deactivated_subdomain_meshes_))
46 {
47 }
48 
49 bool DeactivatedSubdomain::includesTimeOf(double const t) const
50 {
51  return time_interval->contains(t);
52 }
53 
54 std::unique_ptr<DeactivatedSubdomain const> createDeactivatedSubdomain(
55  BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh)
56 {
58  config.peekConfigParameter<std::string>("time_interval");
60 
61  std::vector<int> deactivated_subdomain_material_ids;
62  deactivated_subdomain_material_ids =
64  config.getConfigParameter<std::vector<int>>("material_ids",
65  std::vector<int>{});
66 
67  if (deactivated_subdomain_material_ids.empty())
68  {
69  OGS_FATAL(
70  "The material IDs of the deactivated subdomains are not given. The "
71  "program terminates now.");
72  }
73 
74  std::sort(deactivated_subdomain_material_ids.begin(),
75  deactivated_subdomain_material_ids.end());
76 
77  auto const* const material_ids = MeshLib::materialIDs(mesh);
78  if (material_ids == nullptr)
79  {
80  OGS_FATAL(
81  "The mesh doesn't contain materialIDs for subdomain deactivation. "
82  "The program terminates now.");
83  }
84 
85  std::vector<std::unique_ptr<DeactivetedSubdomainMesh>>
87  deactivated_subdomain_meshes.reserve(
88  deactivated_subdomain_material_ids.size());
89 
90  for (auto const ids : deactivated_subdomain_material_ids)
91  {
92  std::vector<MeshLib::Element*> deactivated_elements;
93  std::vector<MeshLib::Node*> deactivated_nodes;
94 
95  // temporary vector to enhance node searching.
96  std::vector<bool> deactivation_flag_of_nodes(mesh.getNumberOfNodes(),
97  false);
98 
99  for (std::size_t i = 0; i < mesh.getNumberOfElements(); i++)
100  {
101  if (ids != (*material_ids)[i])
102  {
103  continue;
104  }
105 
106  auto* element = mesh.getElement(i);
107  deactivated_elements.push_back(
108  const_cast<MeshLib::Element*>(element));
109 
110  for (unsigned i = 0; i < element->getNumberOfNodes(); i++)
111  {
112  auto const* const node = element->getNode(i);
113  const auto& connected_elements = node->getElements();
114 
115  if (deactivation_flag_of_nodes[node->getID()])
116  {
117  continue;
118  }
119 
120  // Check whether this node is in an activated element.
121  if (std::find_if(
122  connected_elements.begin(),
123  connected_elements.end(),
124  [&](auto const* const connected_elem) -> bool {
125  return ids !=
126  (*material_ids)[connected_elem->getID()];
127  }) != connected_elements.end())
128  {
129  continue;
130  }
131 
132  deactivated_nodes.push_back(const_cast<MeshLib::Node*>(node));
133  deactivation_flag_of_nodes[node->getID()] = true;
134  }
135  }
136 
138  "deactivate_subdomain" + std::to_string(ids),
139  MeshLib::cloneElements(deactivated_elements));
140 
141  deactivated_subdomain_meshes.emplace_back(
142  std::make_unique<DeactivetedSubdomainMesh>(
143  std::move(bc_mesh), std::move(deactivated_nodes)));
144  }
145 
146  return std::make_unique<DeactivatedSubdomain const>(
147  std::move(time_interval),
148  std::move(deactivated_subdomain_material_ids),
149  std::move(deactivated_subdomain_meshes));
150 }
151 
152 std::vector<std::unique_ptr<DeactivatedSubdomain const>>
154  MeshLib::Mesh const& mesh)
155 {
156  std::vector<std::unique_ptr<DeactivatedSubdomain const>>
157  deactivated_subdomains;
158  // Deactivated subdomains
159  if (auto subdomains_config =
161  config.getConfigSubtreeOptional("deactivated_subdomains"))
162  {
163  INFO("There are subdomains being deactivated.");
164 
165  for (
166  auto subdomain_config :
168  subdomains_config->getConfigSubtreeList("deactivated_subdomain"))
169  {
170  deactivated_subdomains.emplace_back(
171  createDeactivatedSubdomain(subdomain_config, mesh));
172  }
173  }
174  return deactivated_subdomains;
175 }
176 
177 } // namespace ProcessLib
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:99
std::unique_ptr< BaseLib::TimeInterval const > const time_interval
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition: Mesh.h:87
const std::vector< Element * > & getElements() const
Get all elements the node is part of.
Definition: Node.h:67
Definition of the Node class.
std::vector< MeshLib::Element * > cloneElements(std::vector< MeshLib::Element *> const &elements)
Clones a vector of elements using the Element::clone() function.
std::vector< std::unique_ptr< DeactivetedSubdomainMesh > > const deactivated_subdomain_meshes
Definition of the Mesh class.
bool includesTimeOf(double const t) const
T getConfigParameter(std::string const &param) const
static const std::string zero_parameter_name
std::unique_ptr< MeshLib::Mesh > createMeshFromElementSelection(std::string mesh_name, std::vector< MeshLib::Element *> const &elements)
Definition: Mesh.cpp:413
std::unique_ptr< TimeInterval > createTimeInterval(BaseLib::ConfigTree const &config)
std::unique_ptr< DeactivatedSubdomain const > createDeactivatedSubdomain(BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
T peekConfigParameter(std::string const &param) const
Definition of Duplicate functions.
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:403
DeactivatedSubdomain(std::unique_ptr< BaseLib::TimeInterval > time_interval_, std::vector< int > &&materialIDs_, std::vector< std::unique_ptr< DeactivetedSubdomainMesh >> &&deactivated_subdomain_meshes_)
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:96
#define OGS_FATAL(fmt,...)
Definition: Error.h:63
boost::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:160
Definition of the Element class.
DeactivetedSubdomainMesh(std::unique_ptr< MeshLib::Mesh > deactivated_subdomain_mesh_, std::vector< MeshLib::Node *> &&inactive_nodes_)
std::vector< std::unique_ptr< DeactivatedSubdomain const > > createDeactivatedSubdomains(BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh)
const Node * getNode(unsigned i) const
Definition: Element.cpp:156