7#include <range/v3/algorithm/all_of.hpp>
8#include <range/v3/algorithm/copy_if.hpp>
9#include <range/v3/algorithm/partition_copy.hpp>
10#include <range/v3/range/conversion.hpp>
25template <
typename IsActive>
26static std::pair<std::vector<std::size_t>, std::vector<std::size_t>>
32 if (bulk_node_ids ==
nullptr)
35 "Bulk node ids map is not available in the deactivate subdomain "
39 std::vector<std::size_t> inner_nodes;
44 std::vector<std::size_t> outer_nodes;
46 ranges::partition_copy(
48 back_inserter(inner_nodes),
49 back_inserter(outer_nodes),
50 [&](std::size_t
const n)
52 auto const bulk_node = mesh.
getNode((*bulk_node_ids)[n]);
53 const auto& connected_elements =
61 return {std::move(inner_nodes), std::move(outer_nodes)};
66 std::vector<std::size_t>
const& outer_nodes)
68 auto const& bulk_node_ids =
69 *sub_mesh.
getProperties().template getPropertyVector<std::size_t>(
73 auto to_bulk_node_id =
74 ranges::views::transform([&bulk_node_ids](std::size_t
const node_id)
75 {
return bulk_node_ids[node_id]; });
76 auto connected_elements = ranges::views::transform(
77 [&mesh](std::size_t
const node_id)
83 return outer_nodes | to_bulk_node_id | connected_elements |
84 ranges::to<std::vector>;
89 std::unordered_set<int>
const& deactivated_subdomain_material_ids)
94 [&deactivated_subdomain_material_ids,
95 &material_ids = *materialIDs(mesh)](std::size_t element_id)
97 return deactivated_subdomain_material_ids.contains(
98 material_ids[element_id]);
102 std::vector<MeshLib::Element*> deactivated_elements;
103 ranges::copy_if(elements, back_inserter(deactivated_elements), is_active,
104 [](
auto const e) {
return e->getID(); });
107 ranges::to<std::unordered_set>;
109 static int mesh_number = 0;
112 "deactivate_subdomain_" + std::to_string(mesh_number++),
115 auto [inner_nodes, outer_nodes] =
118 auto outer_nodes_elements =
121 return {std::move(*sub_mesh), std::move(bulk_element_ids),
122 std::move(inner_nodes), std::move(outer_nodes),
123 std::move(outer_nodes_elements)};
127 std::optional<BaseLib::ConfigTree>
const& time_interval_config,
128 std::optional<std::string>
const& curve_name,
129 std::map<std::string,
130 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
134 if (time_interval_config && curve_name)
137 "In the deactivate subdomain either a time interval or a curve "
138 "must be given, not both.");
142 if (time_interval_config)
144 DBUG(
"Constructing time interval");
145 auto const start_time =
147 time_interval_config->getConfigParameter<
double>(
"start");
149 auto const end_time =
151 time_interval_config->getConfigParameter<
double>(
"end");
155 return {std::vector<double>({start_time, end_time}),
156 std::vector<double>({std::numeric_limits<double>::max(),
157 std::numeric_limits<double>::max()}),
164 DBUG(
"Using curve '{:s}'", *curve_name);
168 "Could not find curve.");
174 "In the deactivate subdomain neither a time interval nor a curve are "
175 "given. One of them must be specified.");
182 DBUG(
"Constructing line segment");
186 if (start.size() != 3)
189 "For construction of a line segment the start point must be a 3D "
190 "point. Got a vector of size {}.",
201 "For construction of a line segment the end point must be a 3D "
202 "point. Got a vector of size {}.",
205 return {Eigen::Vector3d{start[0], start[1], start[2]},
206 Eigen::Vector3d{end[0], end[1], end[2]}};
212 DBUG(
"Constructing a ball");
216 if (center.size() != 3)
219 "For construction of the center of a ball must be a 3D point. Got "
220 "a vector of size {}.",
228 return {Eigen::Vector3d{center[0], center[1], center[2]}, radius};
233 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
234 std::map<std::string,
235 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
238 auto const& time_interval_config =
242 auto const& curve_name =
248 auto const line_segment_config =
252 auto const ball_config =
256 if (line_segment_config && ball_config)
259 "line_segment and ball can not be defined "
263 if (time_interval_config && (line_segment_config || ball_config))
266 "When using time interval for subdomain deactivation a line "
267 "segment or a ball must not be specified.");
270 if (curve_name && !(line_segment_config || ball_config))
273 "When using curve for subdomain deactivation a line segment or a "
274 "ball must be specified.");
280 std::optional<std::pair<Eigen::Vector3d, Eigen::Vector3d>> line_segment;
281 if (line_segment_config)
286 std::optional<detail::Ball> ball;
293 auto boundary_value_parameter_name =
296 if (boundary_value_parameter_name)
298 DBUG(
"Using parameter {:s}", *boundary_value_parameter_name);
300 *boundary_value_parameter_name, parameters, 1, &mesh);
303 auto deactivated_subdomain_material_ids =
306 ranges::to<std::unordered_set>();
308 if (deactivated_subdomain_material_ids.empty())
311 "The material IDs of the deactivated subdomains are not given. The "
312 "program terminates now.");
315 if (materialIDs(mesh) ==
nullptr)
318 "The mesh doesn't contain materialIDs for subdomain deactivation. "
319 "The program terminates now.");
323 mesh, deactivated_subdomain_material_ids);
325 return {std::move(time_interval), line_segment, ball,
326 std::move(deactivated_subdomain_mesh), boundary_value_parameter};
332 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
333 std::map<std::string,
334 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
337 std::vector<DeactivatedSubdomain> deactivated_subdomains;
339 if (
auto subdomains_config =
343 INFO(
"There are subdomains being deactivated.");
345 auto const deactivated_subdomain_configs =
347 subdomains_config->getConfigSubtreeList(
"deactivated_subdomain");
348 std::transform(std::begin(deactivated_subdomain_configs),
349 std::end(deactivated_subdomain_configs),
350 std::back_inserter(deactivated_subdomains),
351 [&](
auto const& config) {
353 config, mesh, parameters, curves);
356 return deactivated_subdomains;
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
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::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.
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Properties & getProperties()
std::size_t getNumberOfNodes() const
Get the number of nodes.
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
OGS_NO_DANGLING Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
std::unique_ptr< MeshLib::Mesh > createMeshFromElementSelection(std::string mesh_name, std::vector< MeshLib::Element * > const &elements)
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
std::vector< Element * > cloneElements(std::vector< Element * > const &elements)
Clones a vector of elements using the Element::clone() function.
PropertyVector< std::size_t > const * bulkNodeIDs(Mesh const &mesh)
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const ¶meter_name, std::vector< std::unique_ptr< ParameterBase > > const ¶meters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
static DeactivatedSubdomainMesh createDeactivatedSubdomainMesh(MeshLib::Mesh const &mesh, std::unordered_set< int > const &deactivated_subdomain_material_ids)
static detail::Ball parseBall(BaseLib::ConfigTree const &config)
Returns a ball represented by its center and its radius.
static std::pair< std::vector< std::size_t >, std::vector< std::size_t > > extractInnerAndOuterNodes(MeshLib::Mesh const &mesh, MeshLib::Mesh const &sub_mesh, IsActive is_active)
DeactivatedSubdomain 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)
std::vector< DeactivatedSubdomain > 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 std::vector< std::vector< std::size_t > > extractElementsAlongOuterNodes(MeshLib::Mesh const &mesh, MeshLib::Mesh const &sub_mesh, std::vector< std::size_t > const &outer_nodes)
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)