From 92578a0928c53e8456c71f2d664e3a9bad65af3e Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Wed, 2 Jun 2021 23:57:25 +0200
Subject: [PATCH] [PL] Rewrite update of deactivated subdomains.

The previous implementation was looking for one deactivated
subdomain, but there could be multiple subdomains inactive
at the same time. Now all deactivated subdomains are
searched for active/inactive elements.
---
 ProcessLib/ProcessVariable.cpp | 42 +++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp
index 745d04a82ad..b88cd1e9504 100644
--- a/ProcessLib/ProcessVariable.cpp
+++ b/ProcessLib/ProcessVariable.cpp
@@ -286,34 +286,38 @@ void ProcessVariable::updateDeactivatedSubdomains(double const time)
 {
     _ids_of_active_elements.clear();
 
-    auto found_a_set =
-        std::find_if(_deactivated_subdomains.begin(),
-                     _deactivated_subdomains.end(),
-                     [&](auto& _deactivated_subdomain) {
-                         return _deactivated_subdomain->includesTimeOf(time);
-                     });
-
-    if (found_a_set == _deactivated_subdomains.end())
-    {
-        return;
-    }
+    auto const* const material_ids = MeshLib::materialIDs(_mesh);
 
-    auto const& deactivated_materialIDs = (*found_a_set)->materialIDs;
+    auto is_active_in_subdomain = [&](std::size_t const i,
+                                      DeactivatedSubdomain const& ds) -> bool {
+        if (!ds.includesTimeOf(time))
+        {
+            return true;
+        }
 
-    auto const* const material_ids = MeshLib::materialIDs(_mesh);
-    auto const number_of_elements = _mesh.getNumberOfElements();
+        auto const& deactivated_materialIDs =
+            ds.materialIDs;
 
-    for (std::size_t i = 0; i < number_of_elements; i++)
-    {
         auto const& element_center = getCenterOfGravity(*_mesh.getElement(i));
         if (std::binary_search(deactivated_materialIDs.begin(),
                                deactivated_materialIDs.end(),
                                (*material_ids)[i]) &&
-            (*found_a_set)->isDeactivated(element_center, time))
+            ds.isDeactivated(element_center, time))
         {
-            continue;
+            return false;
+        }
+        return true;
+    };
+
+    auto const number_of_elements = _mesh.getNumberOfElements();
+    for (std::size_t i = 0; i < number_of_elements; i++)
+    {
+        if (std::all_of(
+                begin(_deactivated_subdomains), end(_deactivated_subdomains),
+                [&](auto const& ds) { return is_active_in_subdomain(i, *ds); }))
+        {
+            _ids_of_active_elements.push_back(_mesh.getElement(i)->getID());
         }
-        _ids_of_active_elements.push_back(_mesh.getElement(i)->getID());
     }
 }
 
-- 
GitLab