Skip to content
Snippets Groups Projects
Commit 6e0c6f85 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[PL/DS] Rewrite using ranges. Early return.

Small optimization for first variable, no need to make a set_union
with empty _ids_of_active_elements.
parent 1daa9f68
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
#include "Process.h" #include "Process.h"
#include <range/v3/algorithm/any_of.hpp>
#include <range/v3/algorithm/set_algorithm.hpp>
#include <range/v3/view/drop.hpp>
#include <range/v3/view/transform.hpp>
#include "NumLib/DOF/ComputeSparsityPattern.h" #include "NumLib/DOF/ComputeSparsityPattern.h"
#include "NumLib/Extrapolation/LocalLinearLeastSquaresExtrapolator.h" #include "NumLib/Extrapolation/LocalLinearLeastSquaresExtrapolator.h"
#include "NumLib/ODESolver/ConvergenceCriterionPerComponent.h" #include "NumLib/ODESolver/ConvergenceCriterionPerComponent.h"
...@@ -202,25 +207,36 @@ void Process::updateDeactivatedSubdomains(double const time, ...@@ -202,25 +207,36 @@ void Process::updateDeactivatedSubdomains(double const time,
{ {
variable.get().updateDeactivatedSubdomains(time); variable.get().updateDeactivatedSubdomains(time);
} }
_ids_of_active_elements.clear(); _ids_of_active_elements.clear();
for (ProcessLib::ProcessVariable const& pv :
getProcessVariables(process_id)) auto active_elements_ids = ranges::views::transform(
[](auto const& variable)
{ return variable.get().getActiveElementIDs(); });
// Early return if there's any process variable with all elements active.
if (ranges::any_of(variables_per_process | active_elements_ids,
[](auto const& vector) { return vector.empty(); }))
{ {
auto const pv_active_element_ids = pv.getActiveElementIDs(); return;
// empty if no deactivated_subdomains exist in process variable }
// executeSelectedMemberDereferenced with empty active_element_ids
// will run executeMemberDereferenced (i.e. on all elements) // Some process variable has deactivated elements. Create union of active
if (pv_active_element_ids.empty()) // ids.
{
_ids_of_active_elements.clear(); _ids_of_active_elements = // there is at least one process variable.
return; variables_per_process[0].get().getActiveElementIDs();
}
std::vector<std::size_t> tempResult; for (auto const& pv_active_element_ids :
std::set_union( variables_per_process | ranges::views::drop(1) | active_elements_ids)
_ids_of_active_elements.begin(), _ids_of_active_elements.end(), {
pv_active_element_ids.begin(), pv_active_element_ids.end(), std::vector<std::size_t> new_active_elements;
std::back_inserter(tempResult)); new_active_elements.reserve(_ids_of_active_elements.size() +
_ids_of_active_elements = std::move(tempResult); pv_active_element_ids.size());
ranges::set_union(_ids_of_active_elements, pv_active_element_ids,
std::back_inserter(new_active_elements));
_ids_of_active_elements = std::move(new_active_elements);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment