11 #include <Eigen/Dense>
25 template <
typename IsActive>
26 static std::pair<std::vector<MeshLib::Node*>, std::vector<MeshLib::Node*>>
31 auto*
const bulk_node_ids =
32 sub_mesh.
getProperties().template getPropertyVector<std::size_t>(
34 if (bulk_node_ids ==
nullptr)
37 "Bulk node ids map is not available in the deactivate subdomain "
41 std::vector<MeshLib::Node*> inner_nodes;
46 std::vector<MeshLib::Node*> outer_nodes;
50 back_inserter(inner_nodes), back_inserter(outer_nodes),
53 auto const bulk_node = mesh.
getNode((*bulk_node_ids)[n->
getID()]);
54 const auto& connected_elements =
57 return std::all_of(begin(connected_elements),
58 end(connected_elements), is_active);
61 return {std::move(inner_nodes), std::move(outer_nodes)};
68 auto is_active = [material_id, material_ids = *
materialIDs(mesh)](
70 {
return material_id == material_ids[e->getID()]; };
73 std::vector<MeshLib::Element*> deactivated_elements;
74 std::copy_if(begin(elements), end(elements),
75 back_inserter(deactivated_elements),
76 [&](
auto const e) {
return is_active(e); });
80 "deactivate_subdomain_" + std::to_string(material_id),
83 auto [inner_nodes, outer_nodes] =
85 return std::make_unique<DeactivatedSubdomainMesh>(
86 std::move(sub_mesh), std::move(inner_nodes), std::move(outer_nodes));
90 std::optional<BaseLib::ConfigTree>
const& time_interval_config,
91 std::optional<std::string>
const& curve_name,
93 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
97 if (time_interval_config && curve_name)
100 "In the deactivate subdomain either a time interval or a curve "
101 "must be given, not both.");
105 if (time_interval_config)
107 DBUG(
"Constructing time interval");
108 auto const start_time =
110 time_interval_config->getConfigParameter<
double>(
"start");
112 auto const end_time =
114 time_interval_config->getConfigParameter<
double>(
"end");
118 return {{start_time, end_time},
119 {std::numeric_limits<double>::max(),
120 std::numeric_limits<double>::max()},
127 DBUG(
"Using curve '{:s}'", *curve_name);
131 "Could not find curve.");
137 "In the deactivate subdomain neither a time interval nor a curve are "
138 "given. One of them must be specified.");
145 DBUG(
"Constructing line segment");
149 if (start.size() != 3)
152 "For construction of a line segment the start point must be a 3D "
153 "point. Got a vector of size {}.",
164 "For construction of a line segment the end point must be a 3D "
165 "point. Got a vector of size {}.",
168 return {Eigen::Vector3d{start[0], start[1], start[2]},
169 Eigen::Vector3d{end[0], end[1], end[2]}};
174 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
175 std::map<std::string,
176 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
179 auto const& time_interval_config =
183 auto const& curve_name =
189 auto const line_segment_config =
193 if (time_interval_config && line_segment_config)
196 "When using time interval for subdomain deactivation a line "
197 "segment must not be specified.");
200 if (curve_name && !line_segment_config)
203 "When using curve for subdomain deactivation a line segment must "
210 std::pair line_segment{Eigen::Vector3d{0, 0, 0}, Eigen::Vector3d{1, 1, 1}};
218 auto boundary_value_parameter_name =
221 if (boundary_value_parameter_name)
223 DBUG(
"Using parameter {:s}", *boundary_value_parameter_name);
224 boundary_value_parameter = &ParameterLib::findParameter<double>(
225 *boundary_value_parameter_name, parameters, 1, &mesh);
228 auto deactivated_subdomain_material_ids =
232 if (deactivated_subdomain_material_ids.empty())
235 "The material IDs of the deactivated subdomains are not given. The "
236 "program terminates now.");
239 std::sort(deactivated_subdomain_material_ids.begin(),
240 deactivated_subdomain_material_ids.end());
242 auto const*
const material_ids =
materialIDs(mesh);
243 if (material_ids ==
nullptr)
246 "The mesh doesn't contain materialIDs for subdomain deactivation. "
247 "The program terminates now.");
250 std::vector<std::unique_ptr<DeactivatedSubdomainMesh>>
251 deactivated_subdomain_meshes;
252 deactivated_subdomain_meshes.reserve(
253 deactivated_subdomain_material_ids.size());
255 std::transform(begin(deactivated_subdomain_material_ids),
256 end(deactivated_subdomain_material_ids),
257 back_inserter(deactivated_subdomain_meshes),
258 [&](std::size_t
const id)
261 return std::make_unique<DeactivatedSubdomain const>(
262 std::move(time_interval),
264 std::move(deactivated_subdomain_material_ids),
265 std::move(deactivated_subdomain_meshes),
266 boundary_value_parameter);
269 std::vector<std::unique_ptr<DeactivatedSubdomain const>>
273 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
274 std::map<std::string,
275 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
278 std::vector<std::unique_ptr<DeactivatedSubdomain const>>
279 deactivated_subdomains;
281 if (
auto subdomains_config =
285 INFO(
"There are subdomains being deactivated.");
287 auto const deactivated_subdomain_configs =
289 subdomains_config->getConfigSubtreeList(
"deactivated_subdomain");
290 std::transform(begin(deactivated_subdomain_configs),
291 end(deactivated_subdomain_configs),
292 back_inserter(deactivated_subdomains),
293 [&](
auto const& config) {
295 config, mesh, parameters, curves);
298 return deactivated_subdomains;
Definition of Duplicate functions.
Definition of the Element class.
void INFO(char const *fmt, Args const &... args)
void DBUG(char const *fmt, Args const &... args)
Definition of the Mesh class.
Definition of the Node class.
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
std::optional< T > getConfigParameterOptional(std::string const ¶m) const
T getConfigParameter(std::string const ¶m) const
std::size_t getID() const
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Properties & getProperties()
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
PropertyVector< int > const * materialIDs(Mesh const &mesh)
std::unique_ptr< MeshLib::Mesh > createMeshFromElementSelection(std::string mesh_name, std::vector< MeshLib::Element * > const &elements)
std::vector< Element * > cloneElements(std::vector< Element * > const &elements)
Clones a vector of elements using the Element::clone() function.
std::vector< std::unique_ptr< DeactivatedSubdomain const > > createDeactivatedSubdomains(BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const ¶meters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
static std::pair< Eigen::Vector3d, Eigen::Vector3d > parseLineSegment(BaseLib::ConfigTree const &config)
Returns a line segment represented by its begin and end points.
static MathLib::PiecewiseLinearInterpolation parseTimeIntervalOrCurve(std::optional< BaseLib::ConfigTree > const &time_interval_config, std::optional< std::string > const &curve_name, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
static std::pair< std::vector< MeshLib::Node * >, std::vector< MeshLib::Node * > > extractInnerAndOuterNodes(MeshLib::Mesh const &mesh, MeshLib::Mesh const &sub_mesh, IsActive is_active)
std::unique_ptr< DeactivatedSubdomain const > createDeactivatedSubdomain(BaseLib::ConfigTree const &config, MeshLib::Mesh const &mesh, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const ¶meters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation >> const &curves)
static std::unique_ptr< DeactivatedSubdomainMesh > createDeactivatedSubdomainMesh(MeshLib::Mesh const &mesh, int const material_id)