KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
alm_frictionless_mortar_criteria.h
Go to the documentation of this file.
1 // KRATOS ______ __ __ _____ __ __ __
2 // / ____/___ ____ / /_____ ______/ /_/ ___// /________ _______/ /___ ___________ _/ /
3 // / / / __ \/ __ \/ __/ __ `/ ___/ __/\__ \/ __/ ___/ / / / ___/ __/ / / / ___/ __ `/ /
4 // / /___/ /_/ / / / / /_/ /_/ / /__/ /_ ___/ / /_/ / / /_/ / /__/ /_/ /_/ / / / /_/ / /
5 // \____/\____/_/ /_/\__/\__,_/\___/\__//____/\__/_/ \__,_/\___/\__/\__,_/_/ \__,_/_/ MECHANICS
6 //
7 // License: BSD License
8 // license: ContactStructuralMechanicsApplication/license.txt
9 //
10 // Main authors: Vicente Mataix Ferrandiz
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
24 
25 namespace Kratos
26 {
29 
32 
36 
40 
44 
48 
55 template<class TSparseSpace, class TDenseSpace>
57  : public BaseMortarConvergenceCriteria< TSparseSpace, TDenseSpace >
58 {
59 public:
62 
65 
67  KRATOS_DEFINE_LOCAL_FLAG( PRINTING_OUTPUT );
68  KRATOS_DEFINE_LOCAL_FLAG( TABLE_IS_INITIALIZED );
69 
72 
75 
78 
81 
84 
87 
89  using TablePrinterPointerType = TableStreamUtility::Pointer;
90 
92  using IndexType = std::size_t;
93 
97 
100  const bool PrintingOutput = false,
101  const bool ComputeDynamicFactor = false,
102  const bool GiDIODebug = false
103  ) : BaseType(ComputeDynamicFactor, GiDIODebug)
104  {
105  // Set local flags
106  BaseType::mOptions.Set(ALMFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT, PrintingOutput);
107  BaseType::mOptions.Set(ALMFrictionlessMortarConvergenceCriteria::TABLE_IS_INITIALIZED, false);
108  }
109 
115  : BaseType()
116  {
117  // Validate and assign defaults
118  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
119  this->AssignSettings(ThisParameters);
120  }
121 
124  :BaseType(rOther)
125  {
126  }
127 
130 
134 
138 
143  typename ConvergenceCriteriaBaseType::Pointer Create(Parameters ThisParameters) const override
144  {
145  return Kratos::make_shared<ClassType>(ThisParameters);
146  }
147 
158  ModelPart& rModelPart,
159  DofsArrayType& rDofSet,
160  const TSystemMatrixType& rA,
161  const TSystemVectorType& rDx,
162  const TSystemVectorType& rb
163  ) override
164  {
165  BaseType::PreCriteria(rModelPart, rDofSet, rA, rDx, rb);
166 
167  return true;
168  }
169 
180  ModelPart& rModelPart,
181  DofsArrayType& rDofSet,
182  const TSystemMatrixType& rA,
183  const TSystemVectorType& rDx,
184  const TSystemVectorType& rb
185  ) override
186  {
187  // We call the base class
188  BaseType::PostCriteria(rModelPart, rDofSet, rA, rDx, rb);
189 
190  // Getting process info
191  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
192 
193  // Compute the active set
194  if (!r_process_info[ACTIVE_SET_COMPUTED]) {
195  const IndexType is_converged = ActiveSetUtilities::ComputeALMFrictionlessActiveSet(rModelPart);
196 
197  // We save to the process info if the active set has converged
198  r_process_info[ACTIVE_SET_CONVERGED] = is_converged == 0 ? true : false;
199  r_process_info[ACTIVE_SET_COMPUTED] = true;
200  }
201 
202  // Getting converged bools
203  const bool active_set_converged = r_process_info[ACTIVE_SET_CONVERGED];
204 
205  if (rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) {
206  if (r_process_info.Has(TABLE_UTILITY)) {
207  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
208  auto& r_table = p_table->GetTable();
209  if (active_set_converged) {
210  if (BaseType::mOptions.IsNot(ALMFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT))
211  r_table << BOLDFONT(FGRN(" Achieved"));
212  else
213  r_table << "Achieved";
214  } else {
215  if (BaseType::mOptions.IsNot(ALMFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT))
216  r_table << BOLDFONT(FRED(" Not achieved"));
217  else
218  r_table << "Not achieved";
219  }
220  } else {
221  if (active_set_converged) {
222  if (BaseType::mOptions.IsNot(ALMFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT))
223  KRATOS_INFO("ALMFrictionlessMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FGRN("achieved")) << std::endl;
224  } else {
225  if (BaseType::mOptions.IsNot(ALMFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT))
226  KRATOS_INFO("ALMFrictionlessMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FRED("not achieved")) << std::endl;
227  else
228  KRATOS_INFO("ALMFrictionlessMortarConvergenceCriteria") << "\tActive set convergence is not achieved" << std::endl;
229  }
230  }
231  }
232 
233  return active_set_converged;
234  }
235 
240  void Initialize(ModelPart& rModelPart) override
241  {
242  // Calling base criteria
243  BaseType::Initialize(rModelPart);
244 
245  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
246  if (r_process_info.Has(TABLE_UTILITY) && BaseType::mOptions.IsNot(ALMFrictionlessMortarConvergenceCriteria::TABLE_IS_INITIALIZED)) {
247  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
248  auto& r_table = p_table->GetTable();
249  r_table.AddColumn("ACTIVE SET CONV", 15);
250  BaseType::mOptions.Set(ALMFrictionlessMortarConvergenceCriteria::TABLE_IS_INITIALIZED, true);
251  }
252  }
253 
259  {
260  Parameters default_parameters = Parameters(R"(
261  {
262  "name" : "alm_frictionless_mortar_criteria",
263  "print_convergence_criterion" : false
264  })" );
265 
266  // Getting base class default parameters
267  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
268  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
269  return default_parameters;
270  }
271 
276  static std::string Name()
277  {
278  return "alm_frictionless_mortar_criteria";
279  }
280 
284 
288 
292 
294  std::string Info() const override
295  {
296  return "ALMFrictionlessMortarConvergenceCriteria";
297  }
298 
300  void PrintInfo(std::ostream& rOStream) const override
301  {
302  rOStream << Info();
303  }
304 
306  void PrintData(std::ostream& rOStream) const override
307  {
308  rOStream << Info();
309  }
310 
312 protected:
315 
319 
323 
327 
332  void AssignSettings(const Parameters ThisParameters) override
333  {
334  BaseType::AssignSettings(ThisParameters);
335 
336  // Set local flags
337  BaseType::mOptions.Set(ALMFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT, ThisParameters["print_convergence_criterion"].GetBool());
338  BaseType::mOptions.Set(ALMFrictionlessMortarConvergenceCriteria::TABLE_IS_INITIALIZED, false);
339  }
340 
342 }; // Class ALMFrictionlessMortarConvergenceCriteria
343 
346 
348 template<class TSparseSpace, class TDenseSpace>
349 const Kratos::Flags ALMFrictionlessMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::PRINTING_OUTPUT(Kratos::Flags::Create(3));
350 template<class TSparseSpace, class TDenseSpace>
351 const Kratos::Flags ALMFrictionlessMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::TABLE_IS_INITIALIZED(Kratos::Flags::Create(4));
352 
353 } // namespace Kratos
Custom convergence criteria for the mortar condition for frictionless case with components.
Definition: alm_frictionless_mortar_criteria.h:58
Custom convergence criteria for the mortar condition.
Definition: base_mortar_criteria.h:65
virtual int MyPID() const
Definition: communicator.cpp:91
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: convergence_criteria.h:466
bool Has(const Variable< TDataType > &rThisVariable) const
Checks if the data container has a value associated with a given variable.
Definition: data_value_container.h:382
Definition: flags.h:58
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
static Flags Create(IndexType ThisPosition, bool Value=true)
Definition: flags.h:138
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void RecursivelyAddMissingParameters(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing contain at least all parameters...
Definition: kratos_parameters.cpp:1457
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
#define FGRN(x)
Definition: color_utilities.h:27
#define FRED(x)
Definition: color_utilities.h:26
#define BOLDFONT(x)
Definition: color_utilities.h:34
KRATOS_CLASS_POINTER_DEFINITION(ALMFrictionlessMortarConvergenceCriteria)
Pointer definition of ALMFrictionlessMortarConvergenceCriteria.
ALMFrictionlessMortarConvergenceCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: alm_frictionless_mortar_criteria.h:114
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: base_mortar_criteria.h:299
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: base_mortar_criteria.h:85
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: alm_frictionless_mortar_criteria.h:332
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: alm_frictionless_mortar_criteria.h:86
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: alm_frictionless_mortar_criteria.h:83
std::string Info() const override
Turn back information as a string.
Definition: alm_frictionless_mortar_criteria.h:294
KRATOS_DEFINE_LOCAL_FLAG(PRINTING_OUTPUT)
Local Flags.
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: alm_frictionless_mortar_criteria.h:300
bool PreCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Criterias that need to be called before getting the solution.
Definition: alm_frictionless_mortar_criteria.h:157
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: alm_frictionless_mortar_criteria.h:258
TableStreamUtility::Pointer TablePrinterPointerType
The table stream definition TODO: Replace by logger.
Definition: alm_frictionless_mortar_criteria.h:89
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: base_mortar_criteria.h:88
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: alm_frictionless_mortar_criteria.h:240
ALMFrictionlessMortarConvergenceCriteria(const bool PrintingOutput=false, const bool ComputeDynamicFactor=false, const bool GiDIODebug=false)
Default constructors.
Definition: alm_frictionless_mortar_criteria.h:99
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: base_mortar_criteria.h:235
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: alm_frictionless_mortar_criteria.h:80
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: alm_frictionless_mortar_criteria.h:306
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: base_mortar_criteria.h:91
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: alm_frictionless_mortar_criteria.h:179
ALMFrictionlessMortarConvergenceCriteria(ALMFrictionlessMortarConvergenceCriteria const &rOther)
Copy constructor.
Definition: alm_frictionless_mortar_criteria.h:123
Flags mOptions
Definition: base_mortar_criteria.h:461
ConvergenceCriteriaBaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: alm_frictionless_mortar_criteria.h:143
~ALMFrictionlessMortarConvergenceCriteria() override=default
Destructor.
std::size_t IndexType
The index type definition.
Definition: alm_frictionless_mortar_criteria.h:92
bool PreCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Criterias that need to be called before getting the solution.
Definition: base_mortar_criteria.h:168
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: alm_frictionless_mortar_criteria.h:276
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: base_mortar_criteria.h:397
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: base_mortar_criteria.h:475
#define KRATOS_INFO(label)
Definition: logger.h:250
std::size_t ComputeALMFrictionlessActiveSet(ModelPart &rModelPart)
This function computes the active set for penalty frictionless cases.
Definition: active_set_utilities.cpp:175
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21