OGS 6.1.0-1699-ge946d4c5f
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  continue;
103 
104  auto* element = mesh.getElement(i);
105  deactivated_elements.push_back(
106  const_cast<MeshLib::Element*>(element));
107 
108  for (unsigned i = 0; i < element->getNumberOfNodes(); i++)
109  {
110  auto const* const node = element->getNode(i);
111  const auto& connected_elements = node->getElements();
112 
113  if (deactivation_flag_of_nodes[node->getID()])
114  continue;
115 
116  // Check whether this node is in an activated element.
117  if (std::find_if(
118  connected_elements.begin(),
119  connected_elements.end(),
120  [&](auto const* const connected_elem) -> bool {
121  return ids !=
122  (*material_ids)[connected_elem->getID()];
123  }) != connected_elements.end())
124  continue;
125 
126  deactivated_nodes.push_back(const_cast<MeshLib::Node*>(node));
127  deactivation_flag_of_nodes[node->getID()] = true;
128  }
129  }
130 
132  "deactivate_subdomain" + std::to_string(ids),
133  MeshLib::cloneElements(deactivated_elements));
134 
135  deactivated_subdomain_meshes.emplace_back(
136  std::make_unique<DeactivetedSubdomainMesh>(
137  std::move(bc_mesh), std::move(deactivated_nodes)));
138  }
139 
140  return std::make_unique<DeactivatedSubdomain const>(
141  std::move(time_interval),
142  std::move(deactivated_subdomain_material_ids),
143  std::move(deactivated_subdomain_meshes));
144 }
145 
146 std::vector<std::unique_ptr<DeactivatedSubdomain const>>
148  MeshLib::Mesh const& mesh)
149 {
150  std::vector<std::unique_ptr<DeactivatedSubdomain const>>
151  deactivated_subdomains;
152  // Deactivated subdomains
153  if (auto subdomains_config =
155  config.getConfigSubtreeOptional("deactivated_subdomains"))
156  {
157  INFO("There are subdomains being deactivated.");
158 
159  for (
160  auto subdomain_config :
162  subdomains_config->getConfigSubtreeList("deactivated_subdomain"))
163  {
164  deactivated_subdomains.emplace_back(
165  createDeactivatedSubdomain(subdomain_config, mesh));
166  }
167  }
168  return deactivated_subdomains;
169 }
170 
171 } // 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:65
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:352
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:342
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:71
boost::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:156
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:144