Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Mixed Generic Criterion - fixing error when dofs and input variables mismatch #11688

Merged
merged 15 commits into from
Oct 19, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,11 @@ class TrilinosMixedGenericCriteria : public MixedGenericCriteria< TSparseSpace,
const TSystemVectorType& rDx,
std::vector<int>& rDofsCount,
std::vector<TDataType>& rSolutionNormsVector,
std::vector<TDataType>& rIncreaseNormsVector) override
std::vector<TDataType>& rIncreaseNormsVector) const override
{
int n_dofs = rDofSet.size();
const auto& r_data_comm = rModelPart.GetCommunicator().GetDataCommunicator();
const int rank = r_data_comm.Rank();
auto& r_local_key_map = BaseType::GetLocalKeyMap();

// Do the local Dx vector import
Epetra_Vector local_dx(mpDofImport->TargetMap());
Expand All @@ -182,9 +181,13 @@ class TrilinosMixedGenericCriteria : public MixedGenericCriteria< TSparseSpace,
const TDataType& r_dof_value = it_dof->GetSolutionStepValue(0);
dof_dx = local_dx[mpDofImport->TargetMap().LID(dof_id)];

const auto &r_current_variable = it_dof->GetVariable();
KeyType var_key = r_current_variable.IsComponent() ? r_current_variable.GetSourceVariable().Key() : r_current_variable.Key();
int var_local_key = r_local_key_map[var_key];
int var_local_key;
bool key_found = BaseType::FindVarLocalKey(it_dof,var_local_key);
if (!key_found) {
// the dof does not belong to the list of variables
// we are checking for convergence, so we skip it
continue;
}

rSolutionNormsVector[var_local_key] += r_dof_value * r_dof_value;
rIncreaseNormsVector[var_local_key] += dof_dx * dof_dx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
// Main authors: Jordi Cotela, Riccardo Rossi, Carlos Roig and Ruben Zorrilla
//

#ifndef KRATOS_MIXED_GENERIC_CRITERIA_H
#define KRATOS_MIXED_GENERIC_CRITERIA_H
#pragma once

// System includes

Expand Down Expand Up @@ -405,6 +404,31 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa
}
}

/**
* @brief Finds the var local key in the mLocalKeyMap for
* a gifen DOF. If the variable does not exist in mLocalKeyMap
* this function returns false
* @param itDof the DOF iterator
* @param rVarLocalKey variable local key
* @return dof variable is found or not
*/
bool FindVarLocalKey(
typename DofsArrayType::const_iterator itDof,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about passing the variable? The dof is only used to access the variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I used the dof to minimize the duplicated code in the trilinos side, what is the advantage on passing the variable instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a philosophical question :)

I try to always pass the least amount of information possible

int& rVarLocalKey) const
{
const auto &r_current_variable = itDof->GetVariable();
const KeyType key = r_current_variable.IsComponent() ? r_current_variable.GetSourceVariable().Key() : r_current_variable.Key();
auto key_find = this->mLocalKeyMap.find(key);
bool found = true;
if (key_find == this->mLocalKeyMap.end()) {
found = false;
} else {
rVarLocalKey = key_find->second;;
}
return found;
}


///@}
///@name Protected Access
///@{
Expand Down Expand Up @@ -462,7 +486,7 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa
const TSystemVectorType& rDx,
std::vector<int>& rDofsCount,
std::vector<TDataType>& rSolutionNormsVector,
std::vector<TDataType>& rIncreaseNormsVector)
std::vector<TDataType>& rIncreaseNormsVector) const
{
int n_dofs = rDofSet.size();

Expand Down Expand Up @@ -492,9 +516,13 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa
dof_value = it_dof->GetSolutionStepValue(0);
dof_dx = TSparseSpace::GetValue(rDx, dof_id);

const auto &r_current_variable = it_dof->GetVariable();
int var_local_key = mLocalKeyMap[r_current_variable.IsComponent() ? r_current_variable.GetSourceVariable().Key() : r_current_variable.Key()];

int var_local_key;
bool key_found = FindVarLocalKey(it_dof,var_local_key);
if (!key_found) {
// the dof does not belong to the list of variables
// we are checking for convergence, so we skip it
continue;
}
var_solution_norm_reduction[var_local_key] += dof_value * dof_value;
var_correction_norm_reduction[var_local_key] += dof_dx * dof_dx;
dofs_counter_reduction[var_local_key]++;
Expand Down Expand Up @@ -563,5 +591,3 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa

///@} // Application group
}

#endif // KRATOS_MIXED_GENERIC_CRITERIA_H