OGS 6.2.2-330-gf48c72f61.dirty.20200225212913
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"
20 #include "MeshLib/Mesh.h"
22 #include "MeshLib/Node.h"
23 
24 namespace ProcessLib
25 {
27  "zero_for_element_deactivation_approach";
28 
30  std::unique_ptr<MeshLib::Mesh> deactivated_subdomain_mesh_,
31  std::vector<MeshLib::Node*>&& inactive_nodes_)
32  : mesh(std::move(deactivated_subdomain_mesh_)),
33  inactive_nodes(std::move(inactive_nodes_))
34 {
35 }
36 
38  std::unique_ptr<BaseLib::TimeInterval> time_interval_,
39  std::vector<int>&& materialIDs_,
40  std::vector<std::unique_ptr<DeactivetedSubdomainMesh>>&&
41  deactivated_subdomain_meshes_)
42  : time_interval(std::move(time_interval_)),
43  materialIDs(std::move(materialIDs_)),
44  deactivated_subdomain_meshes(std::move(deactivated_subdomain_meshes_))
45 {
46 }
47 
48 bool DeactivatedSubdomain::includesTimeOf(double const t) const
49 {
50  return time_interval->contains(t);
51 }
52 
53 std::unique_ptr<DeactivatedSubdomain const> createDeactivatedSubdomain(
54  BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh)
55 {
57  config.peekConfigParameter<std::string>("time_interval");
59 
60  std::vector<int> deactivated_subdomain_material_ids;
61  deactivated_subdomain_material_ids =
63  config.getConfigParameter<std::vector<int>>("material_ids",
64  std::vector<int>{});
65 
66  if (deactivated_subdomain_material_ids.empty())
67  {
68  OGS_FATAL(
69  "The material IDs of the deactivated subdomains are not given. The "
70  "program terminates now.");
71  }
72 
73  std::sort(deactivated_subdomain_material_ids.begin(),
74  deactivated_subdomain_material_ids.end());
75 
76  auto const* const material_ids = MeshLib::materialIDs(mesh);
77  if (material_ids == nullptr)
78  {
79  OGS_FATAL(
80  "The mesh doesn't contain materialIDs for subdomain deactivation. "
81  "The program terminates now.");
82  }
83 
84  std::vector<std::unique_ptr<DeactivetedSubdomainMesh>>
86  deactivated_subdomain_meshes.reserve(
87  deactivated_subdomain_material_ids.size());
88 
89  for (auto const ids : deactivated_subdomain_material_ids)
90  {
91  auto const& nodes = mesh.getNodes();
92  std::vector<std::size_t> deactivated_bulk_node_ids;
93  for (auto const& node : nodes)
94  {
95  const auto& connected_elements = node->getElements();
96 
97  // Check whether this node is in an activated element.
98  if (std::find_if(
99  connected_elements.begin(),
100  connected_elements.end(),
101  [&](auto const* const connected_elem) -> bool {
102  return ids != (*material_ids)[connected_elem->getID()];
103  }) != connected_elements.end())
104  {
105  continue;
106  }
107 
108  deactivated_bulk_node_ids.push_back(node->getID());
109  }
110 
111  auto const& elements = mesh.getElements();
112  std::vector<MeshLib::Element*> deactivated_elements;
113  for (auto const& element : elements)
114  {
115  if (ids != (*material_ids)[element->getID()])
116  {
117  continue;
118  }
119 
120  deactivated_elements.push_back(
121  const_cast<MeshLib::Element*>(element));
122  }
123 
125  "deactivate_subdomain" + std::to_string(ids),
126  MeshLib::cloneElements(deactivated_elements));
127 
128  auto const& new_mesh_properties = bc_mesh->getProperties();
129  if (!new_mesh_properties.template existsPropertyVector<std::size_t>(
130  "bulk_node_ids"))
131  {
132  OGS_FATAL(
133  "Bulk node ids map expected in the construction of the mesh "
134  "subset.");
135  }
136  auto const& bulk_node_ids_map =
137  *new_mesh_properties.template getPropertyVector<std::size_t>(
138  "bulk_node_ids", MeshLib::MeshItemType::Node, 1);
139 
140  std::vector<MeshLib::Node*> deactivated_nodes;
141  auto const& nodes_in_bc_mesh = bc_mesh->getNodes();
142  for (std::size_t i = 0; i < bulk_node_ids_map.size(); i++)
143  {
144  auto const found_iterator = std::find(
145  deactivated_bulk_node_ids.begin(),
146  deactivated_bulk_node_ids.end(), bulk_node_ids_map[i]);
147 
148  if (std::end(deactivated_bulk_node_ids) == found_iterator)
149  {
150  continue;
151  }
152  deactivated_nodes.push_back(
153  const_cast<MeshLib::Node*>(nodes_in_bc_mesh[i]));
154 
155  deactivated_bulk_node_ids.erase(found_iterator);
156  }
157 
158  deactivated_subdomain_meshes.emplace_back(
159  std::make_unique<DeactivetedSubdomainMesh>(
160  std::move(bc_mesh), std::move(deactivated_nodes)));
161  }
162 
163  return std::make_unique<DeactivatedSubdomain const>(
164  std::move(time_interval),
165  std::move(deactivated_subdomain_material_ids),
166  std::move(deactivated_subdomain_meshes));
167 }
168 
169 std::vector<std::unique_ptr<DeactivatedSubdomain const>>
171  MeshLib::Mesh const& mesh)
172 {
173  std::vector<std::unique_ptr<DeactivatedSubdomain const>>
174  deactivated_subdomains;
175  // Deactivated subdomains
176  if (auto subdomains_config =
178  config.getConfigSubtreeOptional("deactivated_subdomains"))
179  {
180  INFO("There are subdomains being deactivated.");
181 
182  for (
183  auto subdomain_config :
185  subdomains_config->getConfigSubtreeList("deactivated_subdomain"))
186  {
187  deactivated_subdomains.emplace_back(
188  createDeactivatedSubdomain(subdomain_config, mesh));
189  }
190  }
191  return deactivated_subdomains;
192 }
193 
194 } // namespace ProcessLib
std::unique_ptr< BaseLib::TimeInterval const > const time_interval
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
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:102
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:320
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:310
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:105
DeactivatedSubdomain(std::unique_ptr< BaseLib::TimeInterval > time_interval_, std::vector< int > &&materialIDs_, std::vector< std::unique_ptr< DeactivetedSubdomainMesh >> &&deactivated_subdomain_meshes_)
#define OGS_FATAL(fmt,...)
Definition: Error.h:64
boost::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
Definition: ConfigTree.cpp:161
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)