From 90a057aa6463f7d347cfecc34fcde0c51ae231ad Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Tue, 17 Oct 2023 13:11:45 +0200 Subject: [PATCH 01/12] using at when reading from map --- .../convergencecriterias/mixed_generic_criteria.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index e5957b2f3630..267f70cb1ce8 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -493,7 +493,8 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa 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()]; + const KeyType key = r_current_variable.IsComponent() ? r_current_variable.GetSourceVariable().Key() : r_current_variable.Key(); + const int var_local_key = mLocalKeyMap.at(key); var_solution_norm_reduction[var_local_key] += dof_value * dof_value; var_correction_norm_reduction[var_local_key] += dof_dx * dof_dx; From 89c2549c6f84a48116d1d69c16e114bfeca4ee00 Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Tue, 17 Oct 2023 13:50:06 +0200 Subject: [PATCH 02/12] pragma once --- .../convergencecriterias/mixed_generic_criteria.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index 267f70cb1ce8..722005a84f8e 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -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 @@ -564,5 +563,3 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa ///@} // Application group } - -#endif // KRATOS_MIXED_GENERIC_CRITERIA_H From 24162ac38b4a6b0c51b35ee1aa3c7cd700e6a546 Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Tue, 17 Oct 2023 14:32:30 +0200 Subject: [PATCH 03/12] throw more meaningful error --- .../convergencecriterias/mixed_generic_criteria.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index 722005a84f8e..e2733ff66183 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -493,7 +493,12 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa const auto &r_current_variable = it_dof->GetVariable(); const KeyType key = r_current_variable.IsComponent() ? r_current_variable.GetSourceVariable().Key() : r_current_variable.Key(); - const int var_local_key = mLocalKeyMap.at(key); + auto key_find = mLocalKeyMap.find(key); + if (key_find == mLocalKeyMap.end()) { + KRATOS_ERROR << "MixedGenericCriteria: The key " << key << " was not found in mLocalKeyMap." << + "Make sure the input variables in constructor and the dofset variables match.\n"; + } + 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; From 3180296c0653f916caba750214d2d7efb6c5f2b9 Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Tue, 17 Oct 2023 14:42:11 +0200 Subject: [PATCH 04/12] Update kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h Co-authored-by: Philipp Bucher --- .../convergencecriterias/mixed_generic_criteria.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index e2733ff66183..a80d5a479bf9 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -494,10 +494,7 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa 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()) { - KRATOS_ERROR << "MixedGenericCriteria: The key " << key << " was not found in mLocalKeyMap." << - "Make sure the input variables in constructor and the dofset variables match.\n"; - } + KRATOS_ERROR_IF(key_find == mLocalKeyMap.end()) << "MixedGenericCriteria: The key " << key << " was not found in mLocalKeyMap for variable " << r_current_variable.Name() << ". Make sure the input variables in constructor and the dofset variables match." << std::endl; const int var_local_key = key_find->second; var_solution_norm_reduction[var_local_key] += dof_value * dof_value; From 875474fdc9b0640eb894edec8926851e4244b04b Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Wed, 18 Oct 2023 09:23:54 +0200 Subject: [PATCH 05/12] skipping dofs instead of throwing error --- .../trilinos_mixed_generic_criteria.h | 12 +++++++++--- .../convergencecriterias/mixed_generic_criteria.h | 7 ++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h index 65f99f822a22..2143674cb101 100644 --- a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h +++ b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h @@ -158,7 +158,7 @@ class TrilinosMixedGenericCriteria : public MixedGenericCriteria< TSparseSpace, const TSystemVectorType& rDx, std::vector& rDofsCount, std::vector& rSolutionNormsVector, - std::vector& rIncreaseNormsVector) override + std::vector& rIncreaseNormsVector) const override { int n_dofs = rDofSet.size(); const auto& r_data_comm = rModelPart.GetCommunicator().GetDataCommunicator(); @@ -183,8 +183,14 @@ class TrilinosMixedGenericCriteria : public MixedGenericCriteria< TSparseSpace, 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]; + 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()) { + // 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; diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index e2733ff66183..729eb5bad919 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -461,7 +461,7 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa const TSystemVectorType& rDx, std::vector& rDofsCount, std::vector& rSolutionNormsVector, - std::vector& rIncreaseNormsVector) + std::vector& rIncreaseNormsVector) const { int n_dofs = rDofSet.size(); @@ -495,8 +495,9 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa 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()) { - KRATOS_ERROR << "MixedGenericCriteria: The key " << key << " was not found in mLocalKeyMap." << - "Make sure the input variables in constructor and the dofset variables match.\n"; + // 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; From 34571c1ea0ef83300e7be7769e2f42411a148d04 Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Wed, 18 Oct 2023 10:31:57 +0200 Subject: [PATCH 06/12] maintaining qualifiers --- .../convergencecriterias/trilinos_mixed_generic_criteria.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h index 2143674cb101..989d2f17bbc3 100644 --- a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h +++ b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h @@ -163,7 +163,7 @@ class TrilinosMixedGenericCriteria : public MixedGenericCriteria< TSparseSpace, 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(); + const auto& r_local_key_map = BaseType::GetLocalKeyMap(); // Do the local Dx vector import Epetra_Vector local_dx(mpDofImport->TargetMap()); From 27d80580a555411154ded95baf02b804d2093788 Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Wed, 18 Oct 2023 12:53:43 +0200 Subject: [PATCH 07/12] encapsulate in function --- .../trilinos_mixed_generic_criteria.h | 8 ++--- .../mixed_generic_criteria.h | 33 +++++++++++++++---- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h index 989d2f17bbc3..0c2bb6955bea 100644 --- a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h +++ b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h @@ -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; diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index 729eb5bad919..d6064814a08a 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -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]++; @@ -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 From da466f6370a2aa503b36f24a15acd8d0957e501a Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Wed, 18 Oct 2023 13:11:37 +0200 Subject: [PATCH 08/12] missing typename --- .../convergencecriterias/mixed_generic_criteria.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index d6064814a08a..06130bcbee9a 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -524,7 +524,7 @@ class MixedGenericCriteria : public ConvergenceCriteria< TSparseSpace, TDenseSpa * @return dof variable is found or not */ bool FindVarLocalKey( - DofsArrayType::const_iterator iDof, + typename DofsArrayType::const_iterator iDof, int& rVarLocalKey) const { const auto &r_current_variable = iDof->GetVariable(); From 1acb8616f794a1d3fab9d66e4234a005931a24a0 Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Wed, 18 Oct 2023 13:12:55 +0200 Subject: [PATCH 09/12] unused var --- .../convergencecriterias/trilinos_mixed_generic_criteria.h | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h index 0c2bb6955bea..23e4a8bc6d1c 100644 --- a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h +++ b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h @@ -163,7 +163,6 @@ class TrilinosMixedGenericCriteria : public MixedGenericCriteria< TSparseSpace, int n_dofs = rDofSet.size(); const auto& r_data_comm = rModelPart.GetCommunicator().GetDataCommunicator(); const int rank = r_data_comm.Rank(); - const auto& r_local_key_map = BaseType::GetLocalKeyMap(); // Do the local Dx vector import Epetra_Vector local_dx(mpDofImport->TargetMap()); From 1338fb0579e3b52fae587ed7d9d1891577213dcb Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Wed, 18 Oct 2023 13:50:52 +0200 Subject: [PATCH 10/12] attempt to fix issues in trilinos --- .../convergencecriterias/trilinos_mixed_generic_criteria.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h index 23e4a8bc6d1c..85cbbe2d597b 100644 --- a/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h +++ b/applications/TrilinosApplication/custom_strategies/convergencecriterias/trilinos_mixed_generic_criteria.h @@ -182,7 +182,7 @@ class TrilinosMixedGenericCriteria : public MixedGenericCriteria< TSparseSpace, dof_dx = local_dx[mpDofImport->TargetMap().LID(dof_id)]; int var_local_key; - bool key_found = FindVarLocalKey(it_dof,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 From d21eecba5337ed194ebf5efd3073b5ddc4a86c63 Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Wed, 18 Oct 2023 14:49:24 +0200 Subject: [PATCH 11/12] making function protected --- .../mixed_generic_criteria.h | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index 06130bcbee9a..c26296c5b8e1 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -404,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 iDof the dof + * @param rVarLocalKey variable local key + * @return dof variable is found or not + */ + bool FindVarLocalKey( + typename 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; + } + + ///@} ///@name Protected Access ///@{ @@ -515,30 +540,6 @@ 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( - typename 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 From 23b9c17bd36477e0b5dbb1d84f834d460f809aa0 Mon Sep 17 00:00:00 2001 From: Daniel Diez Date: Thu, 19 Oct 2023 09:42:10 +0200 Subject: [PATCH 12/12] formatting --- .../convergencecriterias/mixed_generic_criteria.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h index c26296c5b8e1..6f8cecbc63b0 100644 --- a/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h +++ b/kratos/solving_strategies/convergencecriterias/mixed_generic_criteria.h @@ -406,17 +406,17 @@ 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 + * a gifen DOF. If the variable does not exist in mLocalKeyMap * this function returns false - * @param iDof the dof + * @param itDof the DOF iterator * @param rVarLocalKey variable local key * @return dof variable is found or not */ bool FindVarLocalKey( - typename DofsArrayType::const_iterator iDof, + typename DofsArrayType::const_iterator itDof, int& rVarLocalKey) const { - const auto &r_current_variable = iDof->GetVariable(); + 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;