From 80ea6fbe70e528d16d19dd8262a22e8e94d8d4a1 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Sat, 2 Jun 2018 01:18:14 +0200
Subject: [PATCH] [PL] BC: Replace getIntersectionByNodes.

The creation of a mesh subset via intersection is
split into two functions; the first one handles the
nodes intersection (and the resulting memory is managed
by the current scope), and in the second step the
actual MeshSubset object is created, w/o any memory
management obligations.
---
 .../GenericNaturalBoundaryCondition-impl.h                 | 4 ++--
 .../BoundaryCondition/GenericNaturalBoundaryCondition.h    | 4 ++++
 .../NormalTractionBoundaryCondition-impl.h                 | 3 ++-
 .../BoundaryCondition/NormalTractionBoundaryCondition.h    | 4 ++++
 Tests/NumLib/LocalToGlobalIndexMap.cpp                     | 6 ++++--
 Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp       | 7 ++++++-
 6 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/ProcessLib/BoundaryCondition/GenericNaturalBoundaryCondition-impl.h b/ProcessLib/BoundaryCondition/GenericNaturalBoundaryCondition-impl.h
index a65f5a0de03..7f38b3d0659 100644
--- a/ProcessLib/BoundaryCondition/GenericNaturalBoundaryCondition-impl.h
+++ b/ProcessLib/BoundaryCondition/GenericNaturalBoundaryCondition-impl.h
@@ -55,8 +55,8 @@ GenericNaturalBoundaryCondition<BoundaryConditionData,
     auto const& mesh_subset =
         dof_table_bulk.getMeshSubset(variable_id, component_id);
 
-    MeshLib::MeshSubset bc_mesh_subset =
-        mesh_subset.getIntersectionByNodes(nodes);
+    _nodes_subset = nodesNodesIntersection(mesh_subset.getNodes(), nodes);
+    MeshLib::MeshSubset bc_mesh_subset(mesh_subset.getMesh(), &_nodes_subset);
 
     // Create local DOF table from intersected mesh subsets for the given
     // variable and component ids.
diff --git a/ProcessLib/BoundaryCondition/GenericNaturalBoundaryCondition.h b/ProcessLib/BoundaryCondition/GenericNaturalBoundaryCondition.h
index 4cc07be9aac..62e452d51f4 100644
--- a/ProcessLib/BoundaryCondition/GenericNaturalBoundaryCondition.h
+++ b/ProcessLib/BoundaryCondition/GenericNaturalBoundaryCondition.h
@@ -55,6 +55,10 @@ private:
     /// defined.
     std::vector<MeshLib::Element*> _elements;
 
+    /// Intersection of boundary nodes and bulk mesh subset for the
+    /// variable_id/component_id pair.
+    std::vector<MeshLib::Node*> _nodes_subset;
+
     /// Local dof table, a subset of the global one restricted to the
     /// participating #_elements of the boundary condition.
     std::unique_ptr<NumLib::LocalToGlobalIndexMap> _dof_table_boundary;
diff --git a/ProcessLib/BoundaryCondition/NormalTractionBoundaryCondition-impl.h b/ProcessLib/BoundaryCondition/NormalTractionBoundaryCondition-impl.h
index ce4475b2c8b..d4e85f390a0 100644
--- a/ProcessLib/BoundaryCondition/NormalTractionBoundaryCondition-impl.h
+++ b/ProcessLib/BoundaryCondition/NormalTractionBoundaryCondition-impl.h
@@ -43,7 +43,8 @@ NormalTractionBoundaryCondition<LocalAssemblerImplementation>::
     // variable.
     auto const& mesh_subset = dof_table_bulk.getMeshSubset(variable_id, 0);
 
-    auto bc_mesh_subset = mesh_subset.getIntersectionByNodes(nodes);
+    _nodes_subset = nodesNodesIntersection(mesh_subset.getNodes(), nodes);
+    MeshLib::MeshSubset bc_mesh_subset(mesh_subset.getMesh(), &_nodes_subset);
 
     // Create component ids vector for the current variable.
     auto const& number_of_components =
diff --git a/ProcessLib/BoundaryCondition/NormalTractionBoundaryCondition.h b/ProcessLib/BoundaryCondition/NormalTractionBoundaryCondition.h
index a9fed867a69..1f59b291be4 100644
--- a/ProcessLib/BoundaryCondition/NormalTractionBoundaryCondition.h
+++ b/ProcessLib/BoundaryCondition/NormalTractionBoundaryCondition.h
@@ -57,6 +57,10 @@ private:
     /// defined.
     std::vector<MeshLib::Element*> _elements;
 
+    /// Intersection of boundary nodes and bulk mesh subset for the
+    /// variable_id/component_id pair.
+    std::vector<MeshLib::Node*> _nodes_subset;
+
     std::unique_ptr<MeshLib::MeshSubset const> _mesh_subset_all_nodes;
 
     /// Local dof table, a subset of the global one restricted to the
diff --git a/Tests/NumLib/LocalToGlobalIndexMap.cpp b/Tests/NumLib/LocalToGlobalIndexMap.cpp
index 7decd74106d..c7b28fd212a 100644
--- a/Tests/NumLib/LocalToGlobalIndexMap.cpp
+++ b/Tests/NumLib/LocalToGlobalIndexMap.cpp
@@ -101,8 +101,10 @@ TEST_F(NumLibLocalToGlobalIndexMapTest, DISABLED_SubsetByComponent)
     // Find unique node ids of the selected elements for testing.
     std::vector<MeshLib::Node*> selected_nodes = MeshLib::getUniqueNodes(some_elements);
 
-    auto selected_component =
-        nodesSubset->getIntersectionByNodes(selected_nodes);
+    std::vector<MeshLib::Node*> nodes_intersection =
+        nodesNodesIntersection(nodesSubset->getNodes(), selected_nodes);
+    MeshLib::MeshSubset selected_component(nodesSubset->getMesh(),
+                                           &nodes_intersection);
 
     auto dof_map_subset = std::unique_ptr<NumLib::LocalToGlobalIndexMap>{
         dof_map->deriveBoundaryConstrainedMap(1,    // variable id
diff --git a/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp b/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp
index 329385f6b83..4aa7ad8ef15 100644
--- a/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp
+++ b/Tests/NumLib/LocalToGlobalIndexMapMultiComponent.cpp
@@ -69,8 +69,10 @@ public:
 
         std::vector<MeL::Node*> nodes = MeL::getUniqueNodes(boundary_elements);
 
+        nodes_subset =
+            nodesNodesIntersection(mesh_items_all_nodes->getNodes(), nodes);
         mesh_items_boundary = std::make_unique<MeshLib::MeshSubset>(
-            mesh_items_all_nodes->getIntersectionByNodes(nodes));
+            mesh_items_all_nodes->getMesh(), &nodes_subset);
     }
 
     ~NumLibLocalToGlobalIndexMapMultiDOFTest() override
@@ -150,6 +152,9 @@ public:
 
     std::unique_ptr<MeL::MeshSubset const> mesh_items_boundary;
     std::vector<MeL::Element*> boundary_elements;
+
+    /// Intersection of boundary nodes and bulk mesh subset.
+    std::vector<MeshLib::Node*> nodes_subset;
 };
 
 
-- 
GitLab