From 5ad524d24c5d4b5270e48c4d372f8ac9534a5fc7 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Fri, 26 Mar 2021 15:24:53 +0100 Subject: [PATCH] [PL/DS] Extract also the outer nodes. --- ProcessLib/CreateDeactivatedSubdomain.cpp | 47 +++++++++++++---------- ProcessLib/DeactivatedSubdomain.cpp | 6 ++- ProcessLib/DeactivatedSubdomain.h | 4 +- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/ProcessLib/CreateDeactivatedSubdomain.cpp b/ProcessLib/CreateDeactivatedSubdomain.cpp index 42b062bde36..362a6fa41fe 100644 --- a/ProcessLib/CreateDeactivatedSubdomain.cpp +++ b/ProcessLib/CreateDeactivatedSubdomain.cpp @@ -21,10 +21,10 @@ namespace ProcessLib { template <typename IsActive> -static std::vector<MeshLib::Node*> extractInnerNodes( - MeshLib::Mesh const& mesh, - MeshLib::Mesh const& sub_mesh, - IsActive is_active) +static std::pair<std::vector<MeshLib::Node*>, std::vector<MeshLib::Node*>> +extractInnerAndOuterNodes(MeshLib::Mesh const& mesh, + MeshLib::Mesh const& sub_mesh, + IsActive is_active) { auto* const bulk_node_ids = sub_mesh.getProperties().template getPropertyVector<std::size_t>( @@ -38,21 +38,25 @@ static std::vector<MeshLib::Node*> extractInnerNodes( std::vector<MeshLib::Node*> inner_nodes; // Reserve for more than needed, but not much, because almost all nodes will - // be found and copied. + // be the inner nodes. inner_nodes.reserve(sub_mesh.getNumberOfNodes()); - std::copy_if(begin(sub_mesh.getNodes()), end(sub_mesh.getNodes()), - back_inserter(inner_nodes), [&](MeshLib::Node* const n) { - auto const bulk_node = - mesh.getNode((*bulk_node_ids)[n->getID()]); - const auto& connected_elements = bulk_node->getElements(); - - // Check whether this node is connected to an active - // element. - return std::all_of(begin(connected_elements), - end(connected_elements), is_active); - }); - - return inner_nodes; + + std::vector<MeshLib::Node*> outer_nodes; + + std::partition_copy( + begin(sub_mesh.getNodes()), end(sub_mesh.getNodes()), + back_inserter(inner_nodes), back_inserter(outer_nodes), + [&](MeshLib::Node* const n) { + auto const bulk_node = mesh.getNode((*bulk_node_ids)[n->getID()]); + const auto& connected_elements = bulk_node->getElements(); + + // Check whether this node is connected only to an active + // elements. Then it is an inner node, and outer otherwise. + return std::all_of(begin(connected_elements), + end(connected_elements), is_active); + }); + + return {std::move(inner_nodes), std::move(outer_nodes)}; } static std::unique_ptr<DeactivatedSubdomainMesh> createDeactivatedSubdomainMesh( @@ -75,9 +79,10 @@ static std::unique_ptr<DeactivatedSubdomainMesh> createDeactivatedSubdomainMesh( "deactivate_subdomain_" + std::to_string(material_id), MeshLib::cloneElements(deactivated_elements)); - auto inner_nodes = extractInnerNodes(mesh, *sub_mesh, is_active); - return std::make_unique<DeactivatedSubdomainMesh>(std::move(sub_mesh), - std::move(inner_nodes)); + auto [inner_nodes, outer_nodes] = + extractInnerAndOuterNodes(mesh, *sub_mesh, is_active); + return std::make_unique<DeactivatedSubdomainMesh>( + std::move(sub_mesh), std::move(inner_nodes), std::move(outer_nodes)); } static MathLib::PiecewiseLinearInterpolation parseTimeIntervalOrCurve( diff --git a/ProcessLib/DeactivatedSubdomain.cpp b/ProcessLib/DeactivatedSubdomain.cpp index 5422fa37813..85a8438a3f1 100644 --- a/ProcessLib/DeactivatedSubdomain.cpp +++ b/ProcessLib/DeactivatedSubdomain.cpp @@ -24,9 +24,11 @@ const std::string DeactivatedSubdomain::zero_parameter_name = DeactivatedSubdomainMesh::DeactivatedSubdomainMesh( std::unique_ptr<MeshLib::Mesh> deactivated_subdomain_mesh_, - std::vector<MeshLib::Node*>&& inner_nodes_) + std::vector<MeshLib::Node*>&& inner_nodes_, + std::vector<MeshLib::Node*>&& outer_nodes_) : mesh(std::move(deactivated_subdomain_mesh_)), - inner_nodes(std::move(inner_nodes_)) + inner_nodes(std::move(inner_nodes_)), + outer_nodes(std::move(outer_nodes_)) { } diff --git a/ProcessLib/DeactivatedSubdomain.h b/ProcessLib/DeactivatedSubdomain.h index 282b3ace0a3..e7075ef8970 100644 --- a/ProcessLib/DeactivatedSubdomain.h +++ b/ProcessLib/DeactivatedSubdomain.h @@ -32,10 +32,12 @@ struct DeactivatedSubdomainMesh { DeactivatedSubdomainMesh( std::unique_ptr<MeshLib::Mesh> deactivated_subdomain_mesh_, - std::vector<MeshLib::Node*>&& inner_nodes_); + std::vector<MeshLib::Node*>&& inner_nodes_, + std::vector<MeshLib::Node*>&& outer_nodes_); std::unique_ptr<MeshLib::Mesh> const mesh; std::vector<MeshLib::Node*> const inner_nodes; + std::vector<MeshLib::Node*> const outer_nodes; }; /// Time depend subdomain deactivation. -- GitLab