Skip to content

Commit

Permalink
Merge branch 'core/variable_utils/add_distribute_variable_method' of h…
Browse files Browse the repository at this point in the history
…ttps://github.com/KratosMultiphysics/Kratos into core/variable_utils/add_distribute_variable_method
  • Loading branch information
sunethwarna committed Jun 27, 2020
2 parents 83e69ee + 328369e commit 02bb746
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions kratos/utilities/variable_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,17 +511,17 @@ void VariableUtils::WeightedAccumulateVariableOnNodes(
SetNonHistoricalVariableToZero(rVariable, rModelPart.Nodes());

auto& r_entities = GetContainer<TContainerType>(rModelPart);
const int number_of_conditions = r_entities.size();
const int n_entities = r_entities.size();

const std::function<double(const Node<3>&)>& r_weight_method =
(IsInverseWeightProvided) ?
static_cast<std::function<double(const Node<3>&)>>([rWeightVariable](const Node<3>& rNode) -> double {return 1.0 / rNode.GetValue(rWeightVariable);}) :
static_cast<std::function<double(const Node<3>&)>>([rWeightVariable](const Node<3>& rNode) -> double {return rNode.GetValue(rWeightVariable);});

#pragma omp parallel for
for (int i_condition = 0; i_condition < number_of_conditions; ++i_condition)
for (int i_entity = 0; i_entity < n_entities; ++i_entity)
{
auto it_entity = r_entities.begin() + i_condition;
auto it_entity = r_entities.begin() + i_entity;
auto& r_geometry = it_entity->GetGeometry();

const auto& r_value = it_entity->GetValue(rVariable);
Expand All @@ -534,11 +534,10 @@ void VariableUtils::WeightedAccumulateVariableOnNodes(
<< r_node << " is not initialized in " << rModelPart.Name()
<< ". Please initialize it first.";

const auto& r_current_value = r_node.GetValue(rVariable);
const double weight = r_weight_method(r_node);

r_node.SetLock();
r_node.SetValue(rVariable, r_current_value + r_value * weight);
r_node.GetValue(rVariable) += r_value * weight;
r_node.UnSetLock();
}
}
Expand Down

0 comments on commit 02bb746

Please sign in to comment.