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_frictional_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  static constexpr double Tolerance = std::numeric_limits<double>::epsilon();
93 
97 
100  const bool PureSlip = false,
101  const bool PrintingOutput = false,
102  const bool ComputeDynamicFactor = true,
103  const bool IODebug = false
104  ) : BaseType(ComputeDynamicFactor, IODebug, PureSlip)
105  {
106  // Set local flags
107  BaseType::mOptions.Set(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT, PrintingOutput);
108  BaseType::mOptions.Set(PenaltyFrictionalMortarConvergenceCriteria::TABLE_IS_INITIALIZED, false);
109  }
110 
116  : BaseType()
117  {
118  // Validate and assign defaults
119  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
120  this->AssignSettings(ThisParameters);
121  }
122 
125  :BaseType(rOther)
126  {
127  }
128 
131 
135 
139 
144  typename ConvergenceCriteriaBaseType::Pointer Create(Parameters ThisParameters) const override
145  {
146  return Kratos::make_shared<ClassType>(ThisParameters);
147  }
148 
159  ModelPart& rModelPart,
160  DofsArrayType& rDofSet,
161  const TSystemMatrixType& rA,
162  const TSystemVectorType& rDx,
163  const TSystemVectorType& rb
164  ) override
165  {
166  BaseType::PreCriteria(rModelPart, rDofSet, rA, rDx, rb);
167 
168  return true;
169  }
170 
181  ModelPart& rModelPart,
182  DofsArrayType& rDofSet,
183  const TSystemMatrixType& rA,
184  const TSystemVectorType& rDx,
185  const TSystemVectorType& rb
186  ) override
187  {
188  // We call the base class
189  BaseType::PostCriteria(rModelPart, rDofSet, rA, rDx, rb);
190 
191  // Compute the active set
192  const array_1d<std::size_t, 2> is_converged = ActiveSetUtilities::ComputePenaltyFrictionalActiveSet(rModelPart, BaseType::mOptions.Is(BaseType::PURE_SLIP), this->GetEchoLevel());
193 
194  // We save to the process info if the active set has converged
195  const bool active_set_converged = (is_converged[0] + is_converged[1]) == 0 ? true : false;
196 
197  // We get the process info
198  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
199  r_process_info[ACTIVE_SET_CONVERGED] = active_set_converged;
200 
201  if (rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) {
202  if (r_process_info.Has(TABLE_UTILITY)) {
203  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
204  auto& r_table = p_table->GetTable();
205  if (is_converged[0] == 0) {
206  if (BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
207  r_table << BOLDFONT(FGRN(" Achieved"));
208  else
209  r_table << "Achieved";
210  } else {
211  if (BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
212  r_table << BOLDFONT(FRED(" Not achieved"));
213  else
214  r_table << "Not achieved";
215  }
216  if (is_converged[1] == 0) {
217  if (BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
218  r_table << BOLDFONT(FGRN(" Achieved"));
219  else
220  r_table << "Achieved";
221  } else {
222  if (BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
223  r_table << BOLDFONT(FRED(" Not achieved"));
224  else
225  r_table << "Not achieved";
226  }
227  } else {
228  if (is_converged[0] == 0) {
229  if (BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
230  KRATOS_INFO("PenaltyFrictionalMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FGRN("achieved")) << std::endl;
231  else
232  KRATOS_INFO("PenaltyFrictionalMortarConvergenceCriteria") << "\tActive set convergence is achieved" << std::endl;
233  } else {
234  if (BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
235  KRATOS_INFO("PenaltyFrictionalMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FRED("not achieved")) << std::endl;
236  else
237  KRATOS_INFO("PenaltyFrictionalMortarConvergenceCriteria") << "\tActive set convergence is not achieved" << std::endl;
238  }
239 
240  if (is_converged[1] == 0) {
241  if (BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
242  KRATOS_INFO("PenaltyFrictionalMortarConvergenceCriteria") << BOLDFONT("\tSlip/stick set") << " convergence is " << BOLDFONT(FGRN("achieved")) << std::endl;
243  else
244  KRATOS_INFO("PenaltyFrictionalMortarConvergenceCriteria") << "\tSlip/stick set convergence is achieved" << std::endl;
245  } else {
246  if (BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
247  KRATOS_INFO("PenaltyFrictionalMortarConvergenceCriteria") << BOLDFONT("\tSlip/stick set") << " convergence is " << BOLDFONT(FRED("not achieved")) << std::endl;
248  else
249  KRATOS_INFO("PenaltyFrictionalMortarConvergenceCriteria") << "\tSlip/stick set convergence is not achieved" << std::endl;
250  }
251  }
252  }
253 
254  return active_set_converged;
255  }
256 
261  void Initialize(ModelPart& rModelPart) override
262  {
264 
265  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
266  if (r_process_info.Has(TABLE_UTILITY) && BaseType::mOptions.IsNot(PenaltyFrictionalMortarConvergenceCriteria::TABLE_IS_INITIALIZED)) {
267  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
268  auto& r_table = p_table->GetTable();
269  r_table.AddColumn("ACTIVE SET CONV", 15);
270  r_table.AddColumn("SLIP/STICK CONV", 15);
271  BaseType::mOptions.Set(PenaltyFrictionalMortarConvergenceCriteria::TABLE_IS_INITIALIZED, true);
272  }
273  }
274 
280  {
281  Parameters default_parameters = Parameters(R"(
282  {
283  "name" : "penalty_frictional_mortar_criteria",
284  "print_convergence_criterion" : false
285  })" );
286 
287  // Getting base class default parameters
288  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
289  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
290  return default_parameters;
291  }
292 
297  static std::string Name()
298  {
299  return "penalty_frictional_mortar_criteria";
300  }
301 
305 
309 
313 
315  std::string Info() const override
316  {
317  return "PenaltyFrictionalMortarConvergenceCriteria";
318  }
319 
321  void PrintInfo(std::ostream& rOStream) const override
322  {
323  rOStream << Info();
324  }
325 
327  void PrintData(std::ostream& rOStream) const override
328  {
329  rOStream << Info();
330  }
331 
333 protected:
336 
340 
344 
348 
353  void AssignSettings(const Parameters ThisParameters) override
354  {
355  BaseType::AssignSettings(ThisParameters);
356 
357  // Set local flags
358  BaseType::mOptions.Set(PenaltyFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT, ThisParameters["print_convergence_criterion"].GetBool());
359  BaseType::mOptions.Set(PenaltyFrictionalMortarConvergenceCriteria::TABLE_IS_INITIALIZED, false);
360  }
361 
366  void ResetWeightedGap(ModelPart& rModelPart) override
367  {
368  // Auxiliary zero array
369  const array_1d<double, 3> zero_array = ZeroVector(3);
370 
371  // We reset the weighted values
372  auto& r_nodes_array = rModelPart.GetSubModelPart("Contact").Nodes();
373  VariableUtils().SetVariable(WEIGHTED_GAP, 0.0, r_nodes_array);
374  VariableUtils().SetVariable(WEIGHTED_SLIP, zero_array, r_nodes_array);
375  }
376 
378 }; // Class PenaltyFrictionalMortarConvergenceCriteria
379 
382 
384 template<class TSparseSpace, class TDenseSpace>
385 const Kratos::Flags PenaltyFrictionalMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::PRINTING_OUTPUT(Kratos::Flags::Create(3));
386 template<class TSparseSpace, class TDenseSpace>
387 const Kratos::Flags PenaltyFrictionalMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::TABLE_IS_INITIALIZED(Kratos::Flags::Create(4));
388 
389 } // 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
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
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 frictional case.
Definition: penalty_frictional_mortar_criteria.h:58
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void SetVariable(const TVarType &rVariable, const TDataType &rValue, NodesContainerType &rNodes, const unsigned int Step=0)
Sets the nodal value of a scalar variable.
Definition: variable_utils.h:675
Short class definition.
Definition: array_1d.h:61
#define FGRN(x)
Definition: color_utilities.h:27
#define FRED(x)
Definition: color_utilities.h:26
#define BOLDFONT(x)
Definition: color_utilities.h:34
PenaltyFrictionalMortarConvergenceCriteria(PenaltyFrictionalMortarConvergenceCriteria const &rOther)
Copy constructor.
Definition: penalty_frictional_mortar_criteria.h:124
PenaltyFrictionalMortarConvergenceCriteria(const bool PureSlip=false, const bool PrintingOutput=false, const bool ComputeDynamicFactor=true, const bool IODebug=false)
Default constructors.
Definition: penalty_frictional_mortar_criteria.h:99
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: base_mortar_criteria.h:85
ConvergenceCriteriaBaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: penalty_frictional_mortar_criteria.h:144
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: penalty_frictional_mortar_criteria.h:297
PenaltyFrictionalMortarConvergenceCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: penalty_frictional_mortar_criteria.h:115
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: penalty_frictional_mortar_criteria.h:180
TableStreamUtility::Pointer TablePrinterPointerType
The table stream definition TODO: Replace by logger.
Definition: penalty_frictional_mortar_criteria.h:89
std::string Info() const override
Turn back information as a string.
Definition: penalty_frictional_mortar_criteria.h:315
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: penalty_frictional_mortar_criteria.h:353
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: penalty_frictional_mortar_criteria.h:261
void ResetWeightedGap(ModelPart &rModelPart) override
This method resets the weighted gap in the nodes of the problem.
Definition: penalty_frictional_mortar_criteria.h:366
static constexpr double Tolerance
The epsilon tolerance definition.
Definition: penalty_frictional_mortar_criteria.h:92
KRATOS_DEFINE_LOCAL_FLAG(PRINTING_OUTPUT)
Local Flags.
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: penalty_frictional_mortar_criteria.h:321
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: penalty_frictional_mortar_criteria.h:86
KRATOS_CLASS_POINTER_DEFINITION(PenaltyFrictionalMortarConvergenceCriteria)
Pointer definition of PenaltyFrictionalMortarConvergenceCriteria.
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: base_mortar_criteria.h:88
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: penalty_frictional_mortar_criteria.h:327
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
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: penalty_frictional_mortar_criteria.h:279
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: base_mortar_criteria.h:91
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: penalty_frictional_mortar_criteria.h:80
Flags mOptions
Definition: base_mortar_criteria.h:461
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
~PenaltyFrictionalMortarConvergenceCriteria() override=default
Destructor.
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_frictional_mortar_criteria.h:158
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: base_mortar_criteria.h:397
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: penalty_frictional_mortar_criteria.h:83
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
array_1d< std::size_t, 2 > ComputePenaltyFrictionalActiveSet(ModelPart &rModelPart, const bool PureSlip, const SizeType EchoLevel)
This function computes the active set for penalty frictional cases.
Definition: active_set_utilities.cpp:68
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561