12#include <range/v3/algorithm/all_of.hpp>
13#include <range/v3/algorithm/copy_if.hpp>
14#include <range/v3/algorithm/partition_copy.hpp>
15#include <range/v3/range/conversion.hpp>
30template <
typename IsActive>
31static std::pair<std::vector<std::size_t>, std::vector<std::size_t>>
37 if (bulk_node_ids ==
nullptr)
40 "Bulk node ids map is not available in the deactivate subdomain "
44 std::vector<std::size_t> inner_nodes;
49 std::vector<std::size_t> outer_nodes;
51 ranges::partition_copy(
53 back_inserter(inner_nodes),
54 back_inserter(outer_nodes),
55 [&](std::size_t
const n)
57 auto const bulk_node = mesh.
getNode((*bulk_node_ids)[n]);
58 const auto& connected_elements =
66 return {std::move(inner_nodes), std::move(outer_nodes)};
71 std::vector<std::size_t>
const& outer_nodes)
73 auto const& bulk_node_ids =
74 *sub_mesh.
getProperties().template getPropertyVector<std::size_t>(
78 auto to_bulk_node_id =
79 ranges::views::transform([&bulk_node_ids](std::size_t
const node_id)
80 {
return bulk_node_ids[node_id]; });
81 auto connected_elements = ranges::views::transform(
82 [&mesh](std::size_t
const node_id)
88 return outer_nodes | to_bulk_node_id | connected_elements |
89 ranges::to<std::vector>;
94 std::unordered_set<int>
const& deactivated_subdomain_material_ids)
99 [&deactivated_subdomain_material_ids,
100 &material_ids = *materialIDs(mesh)](std::size_t element_id)
102 return deactivated_subdomain_material_ids.contains(
103 material_ids[element_id]);
107 std::vector<MeshLib::Element*> deactivated_elements;
108 ranges::copy_if(elements, back_inserter(deactivated_elements), is_active,
109 [](
auto const e) {
return e->getID(); });
112 ranges::to<std::unordered_set>;
114 static int mesh_number = 0;
117 "deactivate_subdomain_" + std::to_string(mesh_number++),
120 auto [inner_nodes, outer_nodes] =
123 auto outer_nodes_elements =
126 return {std::move(*sub_mesh), std::move(bulk_element_ids),
127 std::move(inner_nodes), std::move(outer_nodes),
128 std::move(outer_nodes_elements)};
132 std::optional<BaseLib::ConfigTree>
const& time_interval_config,
133 std::optional<std::string>
const& curve_name,
134 std::map<std::string,
135 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
139 if (time_interval_config && curve_name)
142 "In the deactivate subdomain either a time interval or a curve "
143 "must be given, not both.");
147 if (time_interval_config)
149 DBUG(
"Constructing time interval");
150 auto const start_time =
152 time_interval_config->getConfigParameter<
double>(
"start");
154 auto const end_time =
156 time_interval_config->getConfigParameter<
double>(
"end");
160 return {{start_time, end_time},
161 {std::numeric_limits<double>::max(),
162 std::numeric_limits<double>::max()},
169 DBUG(
"Using curve '{:s}'", *curve_name);
173 "Could not find curve.");
179 "In the deactivate subdomain neither a time interval nor a curve are "
180 "given. One of them must be specified.");
187 DBUG(
"Constructing line segment");
191 if (start.size() != 3)
194 "For construction of a line segment the start point must be a 3D "
195 "point. Got a vector of size {}.",
206 "For construction of a line segment the end point must be a 3D "
207 "point. Got a vector of size {}.",
210 return {Eigen::Vector3d{start[0], start[1], start[2]},
211 Eigen::Vector3d{end[0], end[1], end[2]}};
216 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
217 std::map<std::string,
218 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
221 auto const& time_interval_config =
225 auto const& curve_name =
231 auto const line_segment_config =
235 if (time_interval_config && line_segment_config)
238 "When using time interval for subdomain deactivation a line "
239 "segment must not be specified.");
242 if (curve_name && !line_segment_config)
245 "When using curve for subdomain deactivation a line segment must "
252 std::optional<std::pair<Eigen::Vector3d, Eigen::Vector3d>> line_segment;
259 auto boundary_value_parameter_name =
262 if (boundary_value_parameter_name)
264 DBUG(
"Using parameter {:s}", *boundary_value_parameter_name);
266 *boundary_value_parameter_name, parameters, 1, &mesh);
269 auto deactivated_subdomain_material_ids =
272 ranges::to<std::unordered_set>();
274 if (deactivated_subdomain_material_ids.empty())
277 "The material IDs of the deactivated subdomains are not given. The "
278 "program terminates now.");
281 if (materialIDs(mesh) ==
nullptr)
284 "The mesh doesn't contain materialIDs for subdomain deactivation. "
285 "The program terminates now.");
289 mesh, deactivated_subdomain_material_ids);
291 return {std::move(time_interval), line_segment,
292 std::move(deactivated_subdomain_mesh), boundary_value_parameter};
298 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>
const& parameters,
299 std::map<std::string,
300 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
303 std::vector<DeactivatedSubdomain> deactivated_subdomains;
305 if (
auto subdomains_config =
309 INFO(
"There are subdomains being deactivated.");
311 auto const deactivated_subdomain_configs =
313 subdomains_config->getConfigSubtreeList(
"deactivated_subdomain");
314 std::transform(std::begin(deactivated_subdomain_configs),
315 std::end(deactivated_subdomain_configs),
316 std::back_inserter(deactivated_subdomains),
317 [&](
auto const& config) {
319 config, mesh, parameters, curves);
322 return deactivated_subdomains;
Definition of Duplicate functions.
Definition of the Element class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... 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::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 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)