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_components_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(ALMFrictionlessComponentsMortarConvergenceCriteria::PRINTING_OUTPUT, PrintingOutput);
107  BaseType::mOptions.Set(ALMFrictionlessComponentsMortarConvergenceCriteria::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]) {
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(ALMFrictionlessComponentsMortarConvergenceCriteria::PRINTING_OUTPUT))
211  r_table << BOLDFONT(FGRN(" Achieved"));
212  else
213  r_table << "Achieved";
214  } else {
215  if (BaseType::mOptions.IsNot(ALMFrictionlessComponentsMortarConvergenceCriteria::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(ALMFrictionlessComponentsMortarConvergenceCriteria::PRINTING_OUTPUT))
223  KRATOS_INFO("ALMFrictionlessComponentsMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FGRN("achieved")) << std::endl;
224  else
225  KRATOS_INFO("ALMFrictionlessComponentsMortarConvergenceCriteria") << "\tActive set convergence is achieved" << std::endl;
226  } else {
227  if (BaseType::mOptions.IsNot(ALMFrictionlessComponentsMortarConvergenceCriteria::PRINTING_OUTPUT))
228  KRATOS_INFO("ALMFrictionlessComponentsMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FRED("not achieved")) << std::endl;
229  else
230  KRATOS_INFO("ALMFrictionlessComponentsMortarConvergenceCriteria") << "\tActive set convergence is not achieved" << std::endl;
231  }
232  }
233  }
234 
235  return active_set_converged;
236  }
237 
242  void Initialize(ModelPart& rModelPart) override
243  {
244  // Calling base criteria
245  BaseType::Initialize(rModelPart);
246 
247  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
248  if (r_process_info.Has(TABLE_UTILITY) && BaseType::mOptions.IsNot(ALMFrictionlessComponentsMortarConvergenceCriteria::TABLE_IS_INITIALIZED)) {
249  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
250  auto& r_table = p_table->GetTable();
251  r_table.AddColumn("ACTIVE SET CONV", 15);
252  BaseType::mOptions.Set(ALMFrictionlessComponentsMortarConvergenceCriteria::TABLE_IS_INITIALIZED, true);
253  }
254  }
255 
261  {
262  Parameters default_parameters = Parameters(R"(
263  {
264  "name" : "alm_frictionless_components_mortar_criteria",
265  "print_convergence_criterion" : false
266  })" );
267 
268  // Getting base class default parameters
269  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
270  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
271  return default_parameters;
272  }
273 
278  static std::string Name()
279  {
280  return "alm_frictionless_components_mortar_criteria";
281  }
282 
286 
290 
294 
296  std::string Info() const override
297  {
298  return "ALMFrictionlessComponentsMortarConvergenceCriteria";
299  }
300 
302  void PrintInfo(std::ostream& rOStream) const override
303  {
304  rOStream << Info();
305  }
306 
308  void PrintData(std::ostream& rOStream) const override
309  {
310  rOStream << Info();
311  }
312 
314 protected:
317 
321 
325 
329 
334  void AssignSettings(const Parameters ThisParameters) override
335  {
336  BaseType::AssignSettings(ThisParameters);
337 
338  // Set local flags
339  BaseType::mOptions.Set(ALMFrictionlessComponentsMortarConvergenceCriteria::PRINTING_OUTPUT, ThisParameters["print_convergence_criterion"].GetBool());
340  BaseType::mOptions.Set(ALMFrictionlessComponentsMortarConvergenceCriteria::TABLE_IS_INITIALIZED, false);
341  }
342 
344 }; // Class ALMFrictionlessComponentsMortarConvergenceCriteria
345 
348 
350 template<class TSparseSpace, class TDenseSpace>
351 const Kratos::Flags ALMFrictionlessComponentsMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::PRINTING_OUTPUT(Kratos::Flags::Create(3));
352 template<class TSparseSpace, class TDenseSpace>
353 const Kratos::Flags ALMFrictionlessComponentsMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::TABLE_IS_INITIALIZED(Kratos::Flags::Create(4));
354 
355 } // namespace Kratos
Custom convergence criteria for the mortar condition for frictionless case with components.
Definition: alm_frictionless_components_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
ConvergenceCriteriaBaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: alm_frictionless_components_mortar_criteria.h:143
ALMFrictionlessComponentsMortarConvergenceCriteria(const bool PrintingOutput=false, const bool ComputeDynamicFactor=false, const bool GiDIODebug=false)
Default constructors.
Definition: alm_frictionless_components_mortar_criteria.h:99
~ALMFrictionlessComponentsMortarConvergenceCriteria() override=default
Destructor.
std::size_t IndexType
The index type definition.
Definition: alm_frictionless_components_mortar_criteria.h:92
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
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: alm_frictionless_components_mortar_criteria.h:278
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_components_mortar_criteria.h:157
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: alm_frictionless_components_mortar_criteria.h:86
KRATOS_CLASS_POINTER_DEFINITION(ALMFrictionlessComponentsMortarConvergenceCriteria)
Pointer definition of ALMFrictionlessComponentsMortarConvergenceCriteria.
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: alm_frictionless_components_mortar_criteria.h:83
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: alm_frictionless_components_mortar_criteria.h:334
ALMFrictionlessComponentsMortarConvergenceCriteria(ALMFrictionlessComponentsMortarConvergenceCriteria const &rOther)
Copy constructor.
Definition: alm_frictionless_components_mortar_criteria.h:123
TableStreamUtility::Pointer TablePrinterPointerType
The table stream definition TODO: Replace by logger.
Definition: alm_frictionless_components_mortar_criteria.h:89
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: alm_frictionless_components_mortar_criteria.h:260
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: alm_frictionless_components_mortar_criteria.h:242
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: alm_frictionless_components_mortar_criteria.h:308
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: base_mortar_criteria.h:88
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: alm_frictionless_components_mortar_criteria.h:80
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::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: base_mortar_criteria.h:91
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: alm_frictionless_components_mortar_criteria.h:302
std::string Info() const override
Turn back information as a string.
Definition: alm_frictionless_components_mortar_criteria.h:296
Flags mOptions
Definition: base_mortar_criteria.h:461
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: alm_frictionless_components_mortar_criteria.h:179
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
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
ALMFrictionlessComponentsMortarConvergenceCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: alm_frictionless_components_mortar_criteria.h:114
#define KRATOS_INFO(label)
Definition: logger.h:250
std::size_t ComputeALMFrictionlessComponentsActiveSet(ModelPart &rModelPart)
This function computes the active set for penalty frictionless cases.
Definition: active_set_utilities.cpp:217
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21