Skip to content

Commit

Permalink
encapsulate in function
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Diez committed Oct 18, 2023
1 parent 2eb1a61 commit 27d8058
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,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();
const KeyType var_key = r_current_variable.IsComponent() ? r_current_variable.GetSourceVariable().Key() : r_current_variable.Key();
auto key_find = r_local_key_map.find(var_key);
if (key_find == r_local_key_map.end()) {
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;
}
const int var_local_key = key_find->second;

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 @@ -491,16 +491,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();
const KeyType key = r_current_variable.IsComponent() ? r_current_variable.GetSourceVariable().Key() : r_current_variable.Key();
auto key_find = mLocalKeyMap.find(key);
if (key_find == mLocalKeyMap.end()) {
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;
}
const int var_local_key = key_find->second;

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 All @@ -518,6 +515,30 @@ 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 iDof the dof
* @param rVarLocalKey variable local key
* @return dof variable is found or not
*/
bool FindVarLocalKey(
DofsArrayType::const_iterator iDof,
int& rVarLocalKey) const
{
const auto &r_current_variable = iDof->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;
}

/**
* @brief This method generates the list of variables from Parameters
* @param ThisParameters Input parameters
Expand Down

0 comments on commit 27d8058

Please sign in to comment.