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.
penalty_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 = true,
102  const bool GiDIODebug = false
103  ) : BaseType(ComputeDynamicFactor, GiDIODebug)
104  {
105  // Set local flags
106  BaseType::mOptions.Set(PenaltyFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT, PrintingOutput);
107  BaseType::mOptions.Set(PenaltyFrictionlessMortarConvergenceCriteria::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  // Compute the active set
192 
193  // We save to the process info if the active set has converged
194  const bool active_set_converged = (is_converged == 0 ? true : false);
195 
196  // We get the process info
197  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
198  r_process_info[ACTIVE_SET_CONVERGED] = active_set_converged;
199 
200  if (rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) {
201  if (r_process_info.Has(TABLE_UTILITY)) {
202  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
203  auto& r_table = p_table->GetTable();
204  if (active_set_converged) {
205  if (BaseType::mOptions.IsNot(PenaltyFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT))
206  r_table << BOLDFONT(FGRN(" Achieved"));
207  else
208  r_table << "Achieved";
209  } else {
210  if (BaseType::mOptions.IsNot(PenaltyFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT))
211  r_table << BOLDFONT(FRED(" Not achieved"));
212  else
213  r_table << "Not achieved";
214  }
215  } else {
216  if (active_set_converged) {
217  if (BaseType::mOptions.IsNot(PenaltyFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT))
218  KRATOS_INFO("PenaltyFrictionlessMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FGRN("achieved")) << std::endl;
219  } else {
220  if (BaseType::mOptions.IsNot(PenaltyFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT))
221  KRATOS_INFO("PenaltyFrictionlessMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FRED("not achieved")) << std::endl;
222  else
223  KRATOS_INFO("PenaltyFrictionlessMortarConvergenceCriteria") << "\tActive set convergence is not achieved" << std::endl;
224  }
225  }
226  }
227 
228  return active_set_converged;
229  }
230 
235  void Initialize(ModelPart& rModelPart) override
236  {
238 
239  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
240  if (r_process_info.Has(TABLE_UTILITY) && BaseType::mOptions.IsNot(PenaltyFrictionlessMortarConvergenceCriteria::TABLE_IS_INITIALIZED)) {
241  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
242  auto& r_table = p_table->GetTable();
243  r_table.AddColumn("ACTIVE SET CONV", 15);
244  BaseType::mOptions.Set(PenaltyFrictionlessMortarConvergenceCriteria::TABLE_IS_INITIALIZED, true);
245  }
246  }
247 
253  {
254  Parameters default_parameters = Parameters(R"(
255  {
256  "name" : "penalty_frictionless_mortar_criteria",
257  "print_convergence_criterion" : false
258  })" );
259 
260  // Getting base class default parameters
261  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
262  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
263  return default_parameters;
264  }
265 
270  static std::string Name()
271  {
272  return "penalty_frictionless_mortar_criteria";
273  }
274 
278 
282 
286 
288  std::string Info() const override
289  {
290  return "PenaltyFrictionlessMortarConvergenceCriteria";
291  }
292 
294  void PrintInfo(std::ostream& rOStream) const override
295  {
296  rOStream << Info();
297  }
298 
300  void PrintData(std::ostream& rOStream) const override
301  {
302  rOStream << Info();
303  }
304 
306 protected:
309 
313 
317 
321 
326  void AssignSettings(const Parameters ThisParameters) override
327  {
328  BaseType::AssignSettings(ThisParameters);
329 
330  // Set local flags
331  BaseType::mOptions.Set(PenaltyFrictionlessMortarConvergenceCriteria::PRINTING_OUTPUT, ThisParameters["print_convergence_criterion"].GetBool());
332  BaseType::mOptions.Set(PenaltyFrictionlessMortarConvergenceCriteria::TABLE_IS_INITIALIZED, false);
333  }
334 
336 }; // Class PenaltyFrictionlessMortarConvergenceCriteria
337 
340 
342 template<class TSparseSpace, class TDenseSpace>
343 const Kratos::Flags PenaltyFrictionlessMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::PRINTING_OUTPUT(Kratos::Flags::Create(3));
344 template<class TSparseSpace, class TDenseSpace>
345 const Kratos::Flags PenaltyFrictionlessMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::TABLE_IS_INITIALIZED(Kratos::Flags::Create(4));
346 
347 } // namespace Kratos
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
int GetEchoLevel()
This returns the level of echo for the solving strategy.
Definition: convergence_criteria.h:209
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: convergence_criteria.h:466
bool mConvergenceCriteriaIsInitialized
This "flag" is set in order to know if it is necessary to actualize the RHS.
Definition: convergence_criteria.h:448
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
Custom convergence criteria for the mortar condition for frictionless case with components.
Definition: penalty_frictionless_mortar_criteria.h:58
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
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: penalty_frictionless_mortar_criteria.h:270
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: base_mortar_criteria.h:85
PenaltyFrictionlessMortarConvergenceCriteria(const bool PrintingOutput=false, const bool ComputeDynamicFactor=true, const bool GiDIODebug=false)
Default constructors.
Definition: penalty_frictionless_mortar_criteria.h:99
KRATOS_DEFINE_LOCAL_FLAG(PRINTING_OUTPUT)
Local Flags.
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: penalty_frictionless_mortar_criteria.h:80
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: penalty_frictionless_mortar_criteria.h:157
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: penalty_frictionless_mortar_criteria.h:179
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: penalty_frictionless_mortar_criteria.h:235
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: penalty_frictionless_mortar_criteria.h:300
PenaltyFrictionlessMortarConvergenceCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: penalty_frictionless_mortar_criteria.h:114
std::size_t IndexType
The index type definition.
Definition: penalty_frictionless_mortar_criteria.h:92
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: base_mortar_criteria.h:88
ConvergenceCriteriaBaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: penalty_frictionless_mortar_criteria.h:143
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::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: penalty_frictionless_mortar_criteria.h:83
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: penalty_frictionless_mortar_criteria.h:252
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: base_mortar_criteria.h:91
TableStreamUtility::Pointer TablePrinterPointerType
The table stream definition TODO: Replace by logger.
Definition: penalty_frictionless_mortar_criteria.h:89
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: penalty_frictionless_mortar_criteria.h:86
Flags mOptions
Definition: base_mortar_criteria.h:461
KRATOS_CLASS_POINTER_DEFINITION(PenaltyFrictionlessMortarConvergenceCriteria)
Pointer definition of PenaltyFrictionlessMortarConvergenceCriteria.
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
PenaltyFrictionlessMortarConvergenceCriteria(PenaltyFrictionlessMortarConvergenceCriteria const &rOther)
Copy constructor.
Definition: penalty_frictionless_mortar_criteria.h:123
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: penalty_frictionless_mortar_criteria.h:326
~PenaltyFrictionlessMortarConvergenceCriteria() override=default
Destructor.
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: base_mortar_criteria.h:475
std::string Info() const override
Turn back information as a string.
Definition: penalty_frictionless_mortar_criteria.h:288
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: penalty_frictionless_mortar_criteria.h:294
#define KRATOS_INFO(label)
Definition: logger.h:250
std::size_t ComputePenaltyFrictionlessActiveSet(ModelPart &rModelPart)
This function computes the active set for penalty frictionless cases.
Definition: active_set_utilities.cpp:28
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21