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.
displacement_lagrangemultiplier_frictional_contact_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
26 
27 namespace Kratos
28 {
31 
34 
38 
42 
46 
49 
59 template< class TSparseSpace,
60  class TDenseSpace >
62  : public ConvergenceCriteria< TSparseSpace, TDenseSpace >
63 {
64 public:
65 
68 
71 
73  KRATOS_DEFINE_LOCAL_FLAG( ENSURE_CONTACT );
74  KRATOS_DEFINE_LOCAL_FLAG( PRINTING_OUTPUT );
75  KRATOS_DEFINE_LOCAL_FLAG( TABLE_IS_INITIALIZED );
76  KRATOS_DEFINE_LOCAL_FLAG( ROTATION_DOF_IS_CONSIDERED );
78 
81 
84 
87 
90 
93 
95  using SparseSpaceType = TSparseSpace;
96 
98  using TablePrinterPointerType = TableStreamUtility::Pointer;
99 
101  using IndexType = std::size_t;
102 
104  static constexpr double Tolerance = std::numeric_limits<double>::epsilon();
105 
109 
114  : BaseType()
115  {
116  }
117 
123  : BaseType()
124  {
125  // Validate and assign defaults
126  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
127  this->AssignSettings(ThisParameters);
128  }
129 
144  const double DispRatioTolerance,
145  const double DispAbsTolerance,
146  const double RotRatioTolerance,
147  const double RotAbsTolerance,
148  const double LMNormalRatioTolerance,
149  const double LMNormalAbsTolerance,
150  const double LMTangentStickRatioTolerance,
151  const double LMTangentStickAbsTolerance,
152  const double LMTangentSlipRatioTolerance,
153  const double LMTangentSlipAbsTolerance,
154  const double NormalTangentRatio,
155  const bool EnsureContact = false,
156  const bool PureSlip = false,
157  const bool PrintingOutput = false
158  )
159  : BaseType()
160  {
161  // Set local flags
162  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::ENSURE_CONTACT, EnsureContact);
163  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::PRINTING_OUTPUT, PrintingOutput);
164  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::PURE_SLIP, PureSlip);
165  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::TABLE_IS_INITIALIZED, false);
166  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED, false);
167 
168  // The displacement solution
169  mDispRatioTolerance = DispRatioTolerance;
170  mDispAbsTolerance = DispAbsTolerance;
171 
172  // The rotation solution
173  mRotRatioTolerance = RotRatioTolerance;
174  mRotAbsTolerance = RotAbsTolerance;
175 
176  // The normal contact solution
177  mLMNormalRatioTolerance = LMNormalRatioTolerance;
178  mLMNormalAbsTolerance = LMNormalAbsTolerance;
179 
180  // The tangent contact solution
181  mLMTangentStickRatioTolerance = LMTangentStickRatioTolerance;
182  mLMTangentStickAbsTolerance = LMTangentStickAbsTolerance;
183  mLMTangentStickRatioTolerance = LMTangentSlipRatioTolerance;
184  mLMTangentStickAbsTolerance = LMTangentSlipAbsTolerance;
185 
186  // We get the ratio between the normal and tangent that will accepted as converged
187  mNormalTangentRatio = NormalTangentRatio;
188  }
189 
190  //* Copy constructor.
192  :BaseType(rOther)
193  ,mOptions(rOther.mOptions)
194  ,mDispRatioTolerance(rOther.mDispRatioTolerance)
195  ,mDispAbsTolerance(rOther.mDispAbsTolerance)
196  ,mRotRatioTolerance(rOther.mDispRatioTolerance)
197  ,mRotAbsTolerance(rOther.mDispAbsTolerance)
198  ,mLMNormalRatioTolerance(rOther.mLMNormalRatioTolerance)
199  ,mLMNormalAbsTolerance(rOther.mLMNormalAbsTolerance)
200  ,mLMTangentStickRatioTolerance(rOther.mLMTangentStickRatioTolerance)
201  ,mLMTangentStickAbsTolerance(rOther.mLMTangentStickAbsTolerance)
202  ,mLMTangentSlipRatioTolerance(rOther.mLMTangentSlipRatioTolerance)
203  ,mLMTangentSlipAbsTolerance(rOther.mLMTangentSlipAbsTolerance)
204  ,mNormalTangentRatio(rOther.mNormalTangentRatio)
205  {
206  }
207 
210 
214 
218 
223  typename BaseType::Pointer Create(Parameters ThisParameters) const override
224  {
225  return Kratos::make_shared<ClassType>(ThisParameters);
226  }
227 
238  ModelPart& rModelPart,
239  DofsArrayType& rDofSet,
240  const TSystemMatrixType& rA,
241  const TSystemVectorType& rDx,
242  const TSystemVectorType& rb
243  ) override
244  {
245  if (SparseSpaceType::Size(rDx) != 0) { //if we are solving for something
246 
247  // Getting process info
248  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
249 
250  // Initialize
251  double disp_solution_norm = 0.0, rot_solution_norm = 0.0, normal_lm_solution_norm = 0.0, tangent_lm_stick_solution_norm = 0.0, tangent_lm_slip_solution_norm = 0.0, disp_increase_norm = 0.0, rot_increase_norm = 0.0, normal_lm_increase_norm = 0.0, tangent_lm_stick_increase_norm = 0.0, tangent_lm_slip_increase_norm = 0.0;
252  IndexType disp_dof_num(0), rot_dof_num(0), lm_dof_num(0), lm_stick_dof_num(0), lm_slip_dof_num(0);
253 
254  // The nodes array
255  auto& r_nodes_array = rModelPart.Nodes();
256 
257  // Auxiliary values
258  struct AuxValues {
259  std::size_t dof_id = 0;
260  double dof_value = 0.0, dof_incr = 0.0;
261  };
262  const bool pure_slip = mOptions.Is(DisplacementLagrangeMultiplierFrictionalContactCriteria::PURE_SLIP);
263 
264  // The number of active dofs
265  const std::size_t number_active_dofs = rb.size();
266 
267  // Auxiliary displacement DoF check
268  const std::function<bool(const VariableData&)> check_without_rot =
269  [](const VariableData& rCurrVar) -> bool {return true;};
270  const std::function<bool(const VariableData&)> check_with_rot =
271  [](const VariableData& rCurrVar) -> bool {return ((rCurrVar == DISPLACEMENT_X) || (rCurrVar == DISPLACEMENT_Y) || (rCurrVar == DISPLACEMENT_Z));};
272  const auto* p_check_disp = (mOptions.Is(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED)) ? &check_with_rot : &check_without_rot;
273 
274  // Loop over Dofs
276  std::tie(disp_solution_norm, rot_solution_norm, normal_lm_solution_norm, tangent_lm_slip_solution_norm, tangent_lm_stick_solution_norm, disp_increase_norm, rot_increase_norm, normal_lm_increase_norm, tangent_lm_slip_increase_norm, tangent_lm_stick_increase_norm, disp_dof_num, rot_dof_num, lm_dof_num, lm_slip_dof_num, lm_stick_dof_num) = block_for_each<FifteenReduction>(rDofSet, AuxValues(), [this,p_check_disp,&number_active_dofs,&pure_slip, &r_nodes_array,&rDx](Dof<double>& rDof, AuxValues& aux_values) {
277  aux_values.dof_id = rDof.EquationId();
278 
279  // Check dof id is solved
280  if (aux_values.dof_id < number_active_dofs) {
281  if (mActiveDofs[aux_values.dof_id] == 1) {
282  aux_values.dof_value = rDof.GetSolutionStepValue(0);
283  aux_values.dof_incr = rDx[aux_values.dof_id];
284 
285  const auto& r_curr_var = rDof.GetVariable();
286  if (r_curr_var == VECTOR_LAGRANGE_MULTIPLIER_X || r_curr_var == VECTOR_LAGRANGE_MULTIPLIER_Y || r_curr_var == VECTOR_LAGRANGE_MULTIPLIER_Z) {
287  // The normal of the node (TODO: how to solve this without accesing all the time to the database?)
288  const auto it_node = r_nodes_array.find(rDof.Id());
289 
290  const double mu = it_node->GetValue(FRICTION_COEFFICIENT);
291  if (mu < std::numeric_limits<double>::epsilon()) {
292  return std::make_tuple(0.0,0.0,std::pow(aux_values.dof_value, 2),0.0,0.0,0.0,0.0,std::pow(aux_values.dof_incr, 2),0.0,0.0,0,0,1,0,0);
293  } else {
294  const double normal = it_node->FastGetSolutionStepValue(NORMAL)[r_curr_var.GetComponentIndex()];
295  const double normal_dof_value = aux_values.dof_value * normal;
296  const double normal_dof_incr = aux_values.dof_incr * normal;
297 
298  if (it_node->Is(SLIP) || pure_slip) {
299  return std::make_tuple(0.0,0.0,std::pow(normal_dof_value, 2),std::pow(aux_values.dof_value - normal_dof_value, 2),0.0,0.0,0.0,std::pow(normal_dof_incr, 2),std::pow(aux_values.dof_incr - normal_dof_incr, 2),0.0,0,0,1,1,0);
300  } else {
301  return std::make_tuple(0.0,0.0,std::pow(normal_dof_value, 2),0.0,std::pow(aux_values.dof_value - normal_dof_value, 2),0.0,0.0,std::pow(normal_dof_incr, 2),0.0,std::pow(aux_values.dof_incr - normal_dof_incr, 2),0,0,1,0,1);
302  }
303  }
304  } else if ((*p_check_disp)(r_curr_var)) {
305  return std::make_tuple(std::pow(aux_values.dof_value, 2),0.0,0.0,0.0,0.0,std::pow(aux_values.dof_incr, 2),0.0,0.0,0.0,0.0,1,0,0,0,0);
306  } else { // We will assume is rotation dof
307  KRATOS_DEBUG_ERROR_IF_NOT((r_curr_var == ROTATION_X) || (r_curr_var == ROTATION_Y) || (r_curr_var == ROTATION_Z)) << "Variable must be a ROTATION and it is: " << r_curr_var.Name() << std::endl;
308  return std::make_tuple(0.0,std::pow(aux_values.dof_value, 2),0.0,0.0,0.0,0.0,std::pow(aux_values.dof_incr, 2),0.0,0.0,0.0,0,1,0,0,0);
309  }
310  }
311  }
312  return std::make_tuple(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,0,0,0,0);
313  });
314 
315  if(disp_increase_norm < Tolerance) disp_increase_norm = 1.0;
316  if(rot_increase_norm < Tolerance) rot_increase_norm = 1.0;
317  if(normal_lm_increase_norm < Tolerance) normal_lm_increase_norm = 1.0;
318  if(tangent_lm_stick_increase_norm < Tolerance) tangent_lm_stick_increase_norm = 1.0;
319  if(tangent_lm_slip_increase_norm < Tolerance) tangent_lm_slip_increase_norm = 1.0;
320  if(disp_solution_norm < Tolerance) disp_solution_norm = 1.0;
321 
322  KRATOS_ERROR_IF(mOptions.Is(DisplacementLagrangeMultiplierFrictionalContactCriteria::ENSURE_CONTACT) && normal_lm_solution_norm < Tolerance) << "WARNING::CONTACT LOST::ARE YOU SURE YOU ARE SUPPOSED TO HAVE CONTACT?" << std::endl;
323 
324  const double disp_ratio = std::sqrt(disp_increase_norm/disp_solution_norm);
325  const double rot_ratio = std::sqrt(rot_increase_norm/rot_solution_norm);
326  const double normal_lm_ratio = normal_lm_solution_norm > Tolerance ? std::sqrt(normal_lm_increase_norm/normal_lm_solution_norm) : 0.0;
327  const double tangent_lm_stick_ratio = tangent_lm_stick_solution_norm > Tolerance ? std::sqrt(tangent_lm_stick_increase_norm/tangent_lm_stick_solution_norm) : 0.0;
328  const double tangent_lm_slip_ratio = tangent_lm_slip_solution_norm > Tolerance ? std::sqrt(tangent_lm_slip_increase_norm/tangent_lm_slip_solution_norm) : 0.0;
329 
330  const double disp_abs = std::sqrt(disp_increase_norm)/ static_cast<double>(disp_dof_num);
331  const double rot_abs = std::sqrt(rot_increase_norm)/ static_cast<double>(rot_dof_num);
332  const double normal_lm_abs = std::sqrt(normal_lm_increase_norm)/ static_cast<double>(lm_dof_num);
333  const double tangent_lm_stick_abs = lm_stick_dof_num > 0 ? std::sqrt(tangent_lm_stick_increase_norm)/ static_cast<double>(lm_stick_dof_num) : 0.0;
334  const double tangent_lm_slip_abs = lm_slip_dof_num > 0 ? std::sqrt(tangent_lm_slip_increase_norm)/ static_cast<double>(lm_slip_dof_num) : 0.0;
335 
336  const double normal_tangent_stick_ratio = tangent_lm_stick_abs/normal_lm_abs;
337  const double normal_tangent_slip_ratio = tangent_lm_slip_abs/normal_lm_abs;
338 
339  // We print the results // TODO: Replace for the new log
340  if (rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) {
341  if (r_process_info.Has(TABLE_UTILITY)) {
342  std::cout.precision(4);
343  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
344  auto& Table = p_table->GetTable();
345  if (mOptions.Is(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
346  Table << disp_ratio << mDispRatioTolerance << disp_abs << mDispAbsTolerance << rot_ratio << mRotRatioTolerance << rot_abs << mRotAbsTolerance << normal_lm_ratio << mLMNormalRatioTolerance << normal_lm_abs << mLMNormalAbsTolerance << tangent_lm_stick_ratio << mLMTangentStickRatioTolerance << tangent_lm_stick_abs << mLMTangentStickAbsTolerance << tangent_lm_slip_ratio << mLMTangentSlipRatioTolerance << tangent_lm_slip_abs << mLMTangentSlipAbsTolerance;
347  } else {
348  Table << disp_ratio << mDispRatioTolerance << disp_abs << mDispAbsTolerance << normal_lm_ratio << mLMNormalRatioTolerance << normal_lm_abs << mLMNormalAbsTolerance << tangent_lm_stick_ratio << mLMTangentStickRatioTolerance << tangent_lm_stick_abs << mLMTangentStickAbsTolerance << tangent_lm_slip_ratio << mLMTangentSlipRatioTolerance << tangent_lm_slip_abs << mLMTangentSlipAbsTolerance;
349  }
350  } else {
351  std::cout.precision(4);
352  if (mOptions.IsNot(DisplacementLagrangeMultiplierFrictionalContactCriteria::PRINTING_OUTPUT)) {
353  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << BOLDFONT("DoF ONVERGENCE CHECK") << "\tSTEP: " << r_process_info[STEP] << "\tNL ITERATION: " << r_process_info[NL_ITERATION_NUMBER] << std::endl;
354  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << BOLDFONT("\tDISPLACEMENT: RATIO = ") << disp_ratio << BOLDFONT(" EXP.RATIO = ") << mDispRatioTolerance << BOLDFONT(" ABS = ") << disp_abs << BOLDFONT(" EXP.ABS = ") << mDispAbsTolerance << std::endl;
355  if (mOptions.Is(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
356  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << BOLDFONT("\tROTATION: RATIO = ") << rot_ratio << BOLDFONT(" EXP.RATIO = ") << mRotRatioTolerance << BOLDFONT(" ABS = ") << rot_abs << BOLDFONT(" EXP.ABS = ") << mRotAbsTolerance << std::endl;
357  }
358  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << BOLDFONT(" NORMAL LAGRANGE MUL:\tRATIO = ") << normal_lm_ratio << BOLDFONT(" EXP.RATIO = ") << mLMNormalRatioTolerance << BOLDFONT(" ABS = ") << normal_lm_abs << BOLDFONT(" EXP.ABS = ") << mLMNormalAbsTolerance << std::endl;
359  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << BOLDFONT(" STICK LAGRANGE MUL:\tRATIO = ") << tangent_lm_stick_ratio << BOLDFONT(" EXP.RATIO = ") << mLMTangentStickRatioTolerance << BOLDFONT(" ABS = ") << tangent_lm_stick_abs << BOLDFONT(" EXP.ABS = ") << mLMTangentStickAbsTolerance << std::endl;
360  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << BOLDFONT(" SLIP LAGRANGE MUL:\tRATIO = ") << tangent_lm_slip_ratio << BOLDFONT(" EXP.RATIO = ") << mLMTangentSlipRatioTolerance << BOLDFONT(" ABS = ") << tangent_lm_slip_abs << BOLDFONT(" EXP.ABS = ") << mLMTangentSlipAbsTolerance << std::endl;
361  } else {
362  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << "DoF ONVERGENCE CHECK" << "\tSTEP: " << r_process_info[STEP] << "\tNL ITERATION: " << r_process_info[NL_ITERATION_NUMBER] << std::endl;
363  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << "\tDISPLACEMENT: RATIO = " << disp_ratio << " EXP.RATIO = " << mDispRatioTolerance << " ABS = " << disp_abs << " EXP.ABS = " << mDispAbsTolerance << std::endl;
364  if (mOptions.Is(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
365  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << "\tROTATION: RATIO = " << rot_ratio << " EXP.RATIO = " << mRotRatioTolerance << " ABS = " << rot_abs << " EXP.ABS = " << mRotAbsTolerance << std::endl;
366  }
367  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << " NORMAL LAGRANGE MUL:\tRATIO = " << normal_lm_ratio << " EXP.RATIO = " << mLMNormalRatioTolerance << " ABS = " << normal_lm_abs << " EXP.ABS = " << mLMNormalAbsTolerance << std::endl;
368  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << " STICK LAGRANGE MUL:\tRATIO = " << tangent_lm_stick_ratio << " EXP.RATIO = " << mLMTangentStickRatioTolerance << " ABS = " << tangent_lm_stick_abs << " EXP.ABS = " << mLMTangentStickAbsTolerance << std::endl;
369  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << " SLIP LAGRANGE MUL:\tRATIO = " << tangent_lm_slip_ratio << " EXP.RATIO = " << mLMTangentSlipRatioTolerance << " ABS = " << tangent_lm_slip_abs << " EXP.ABS = " << mLMTangentSlipAbsTolerance << std::endl;
370  }
371  }
372  }
373 
374  // We check if converged
375  const bool disp_converged = (disp_ratio <= mDispRatioTolerance || disp_abs <= mDispAbsTolerance);
376  const bool rot_converged = (mOptions.Is(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED)) ? (rot_ratio <= mRotRatioTolerance || rot_abs <= mRotAbsTolerance) : true;
377  const bool lm_converged = (mOptions.IsNot(DisplacementLagrangeMultiplierFrictionalContactCriteria::ENSURE_CONTACT) && normal_lm_solution_norm < Tolerance) ? true : (normal_lm_ratio <= mLMNormalRatioTolerance || normal_lm_abs <= mLMNormalAbsTolerance) && (tangent_lm_stick_ratio <= mLMTangentStickRatioTolerance || tangent_lm_stick_abs <= mLMTangentStickAbsTolerance || normal_tangent_stick_ratio <= mNormalTangentRatio) && (tangent_lm_slip_ratio <= mLMTangentSlipRatioTolerance || tangent_lm_slip_abs <= mLMTangentSlipAbsTolerance || normal_tangent_slip_ratio <= mNormalTangentRatio);
378 
379  if (disp_converged && rot_converged && lm_converged) {
380  if (rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) {
381  if (r_process_info.Has(TABLE_UTILITY)) {
382  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
383  auto& r_table = p_table->GetTable();
384  if (mOptions.IsNot(DisplacementLagrangeMultiplierFrictionalContactCriteria::PRINTING_OUTPUT))
385  r_table << BOLDFONT(FGRN(" Achieved"));
386  else
387  r_table << "Achieved";
388  } else {
389  if (mOptions.IsNot(DisplacementLagrangeMultiplierFrictionalContactCriteria::PRINTING_OUTPUT))
390  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << BOLDFONT("\tDoF") << " convergence is " << BOLDFONT(FGRN("achieved")) << std::endl;
391  else
392  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << "\tDoF convergence is achieved" << std::endl;
393  }
394  }
395  return true;
396  } else {
397  if (rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) {
398  if (r_process_info.Has(TABLE_UTILITY)) {
399  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
400  auto& r_table = p_table->GetTable();
401  if (mOptions.IsNot(DisplacementLagrangeMultiplierFrictionalContactCriteria::PRINTING_OUTPUT))
402  r_table << BOLDFONT(FRED(" Not achieved"));
403  else
404  r_table << "Not achieved";
405  } else {
406  if (mOptions.IsNot(DisplacementLagrangeMultiplierFrictionalContactCriteria::PRINTING_OUTPUT))
407  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << BOLDFONT("\tDoF") << " convergence is " << BOLDFONT(FRED(" not achieved")) << std::endl;
408  else
409  KRATOS_INFO("DisplacementLagrangeMultiplierFrictionalContactCriteria") << "\tDoF convergence is not achieved" << std::endl;
410  }
411  }
412  return false;
413  }
414  }
415  else // In this case all the displacements are imposed!
416  return true;
417  }
418 
423  void Initialize( ModelPart& rModelPart ) override
424  {
425  // Initialize
426  BaseType::mConvergenceCriteriaIsInitialized = true;
427 
428  // Check rotation dof
429  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED, ContactUtilities::CheckModelPartHasRotationDoF(rModelPart));
430 
431  // Initialize header
432  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
433  if (r_process_info.Has(TABLE_UTILITY) && mOptions.IsNot(DisplacementLagrangeMultiplierFrictionalContactCriteria::TABLE_IS_INITIALIZED)) {
434  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
435  auto& r_table = p_table->GetTable();
436  r_table.AddColumn("DP RATIO", 10);
437  r_table.AddColumn("EXP. RAT", 10);
438  r_table.AddColumn("ABS", 10);
439  r_table.AddColumn("EXP. ABS", 10);
440  if (mOptions.Is(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
441  r_table.AddColumn("RT RATIO", 10);
442  r_table.AddColumn("EXP. RAT", 10);
443  r_table.AddColumn("ABS", 10);
444  r_table.AddColumn("EXP. ABS", 10);
445  }
446  r_table.AddColumn("N.LM RATIO", 10);
447  r_table.AddColumn("EXP. RAT", 10);
448  r_table.AddColumn("ABS", 10);
449  r_table.AddColumn("EXP. ABS", 10);
450  if (mOptions.IsNot(DisplacementLagrangeMultiplierFrictionalContactCriteria::PURE_SLIP)) {
451  r_table.AddColumn("STI. RATIO", 10);
452  r_table.AddColumn("EXP. RAT", 10);
453  r_table.AddColumn("ABS", 10);
454  r_table.AddColumn("EXP. ABS", 10);
455  }
456  r_table.AddColumn("SLIP RATIO", 10);
457  r_table.AddColumn("EXP. RAT", 10);
458  r_table.AddColumn("ABS", 10);
459  r_table.AddColumn("EXP. ABS", 10);
460  r_table.AddColumn("CONVERGENCE", 15);
461  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::TABLE_IS_INITIALIZED, true);
462  }
463  }
464 
474  ModelPart& rModelPart,
475  DofsArrayType& rDofSet,
476  const TSystemMatrixType& rA,
477  const TSystemVectorType& rDx,
478  const TSystemVectorType& rb
479  ) override
480  {
481  // Filling mActiveDofs when MPC exist
482  ConstraintUtilities::ComputeActiveDofs(rModelPart, mActiveDofs, rDofSet);
483  }
484 
494  ModelPart& rModelPart,
495  DofsArrayType& rDofSet,
496  const TSystemMatrixType& rA,
497  const TSystemVectorType& rDx,
498  const TSystemVectorType& rb
499  ) override
500  {
501  // Calling base criteria
502  BaseType::FinalizeNonLinearIteration(rModelPart, rDofSet, rA, rDx, rb);
503 
504  // The current process info
505  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
506  r_process_info.SetValue(ACTIVE_SET_COMPUTED, false);
507  }
508 
514  {
515  Parameters default_parameters = Parameters(R"(
516  {
517  "name" : "displacement_lagrangemultiplier_frictional_contact_criteria",
518  "ensure_contact" : false,
519  "pure_slip" : false,
520  "print_convergence_criterion" : false,
521  "displacement_relative_tolerance" : 1.0e-4,
522  "displacement_absolute_tolerance" : 1.0e-9,
523  "rotation_relative_tolerance" : 1.0e-4,
524  "rotation_absolute_tolerance" : 1.0e-9,
525  "contact_displacement_relative_tolerance" : 1.0e-4,
526  "contact_displacement_absolute_tolerance" : 1.0e-9,
527  "frictional_stick_contact_displacement_relative_tolerance" : 1.0e-4,
528  "frictional_stick_contact_displacement_absolute_tolerance" : 1.0e-9,
529  "frictional_slip_contact_displacement_relative_tolerance" : 1.0e-4,
530  "frictional_slip_contact_displacement_absolute_tolerance" : 1.0e-9,
531  "ratio_normal_tangent_threshold" : 1.0e-4
532  })");
533 
534  // Getting base class default parameters
535  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
536  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
537  return default_parameters;
538  }
539 
544  static std::string Name()
545  {
546  return "displacement_lagrangemultiplier_frictional_contact_criteria";
547  }
548 
552 
556 
560 
562  std::string Info() const override
563  {
564  return "DisplacementLagrangeMultiplierFrictionalContactCriteria";
565  }
566 
568  void PrintInfo(std::ostream& rOStream) const override
569  {
570  rOStream << Info();
571  }
572 
574  void PrintData(std::ostream& rOStream) const override
575  {
576  rOStream << Info();
577  }
578 
582 
583 protected:
584 
587 
591 
595 
599 
604  void AssignSettings(const Parameters ThisParameters) override
605  {
606  BaseType::AssignSettings(ThisParameters);
607 
608  // The displacement solution
609  mDispRatioTolerance = ThisParameters["displacement_relative_tolerance"].GetDouble();
610  mDispAbsTolerance = ThisParameters["displacement_absolute_tolerance"].GetDouble();
611 
612  // The rotation solution
613  mRotRatioTolerance = ThisParameters["rotation_relative_tolerance"].GetDouble();
614  mRotAbsTolerance = ThisParameters["rotation_absolute_tolerance"].GetDouble();
615 
616  // The normal contact solution
617  mLMNormalRatioTolerance = ThisParameters["contact_displacement_relative_tolerance"].GetDouble();
618  mLMNormalAbsTolerance = ThisParameters["contact_displacement_absolute_tolerance"].GetDouble();
619 
620  // The tangent contact solution
621  mLMTangentStickRatioTolerance = ThisParameters["frictional_stick_contact_displacement_relative_tolerance"].GetDouble();
622  mLMTangentStickAbsTolerance = ThisParameters["frictional_stick_contact_displacement_absolute_tolerance"].GetDouble();
623  mLMTangentSlipRatioTolerance = ThisParameters["frictional_slip_contact_displacement_relative_tolerance"].GetDouble();
624  mLMTangentSlipAbsTolerance = ThisParameters["frictional_slip_contact_displacement_absolute_tolerance"].GetDouble();
625 
626  // We get the ratio between the normal and tangent that will accepted as converged
627  mNormalTangentRatio = ThisParameters["ratio_normal_tangent_threshold"].GetDouble();
628 
629  // Set local flags
630  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::ENSURE_CONTACT, ThisParameters["ensure_contact"].GetBool());
631  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::PRINTING_OUTPUT, ThisParameters["print_convergence_criterion"].GetBool());
632  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::TABLE_IS_INITIALIZED, false);
633  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::ROTATION_DOF_IS_CONSIDERED, false);
634  mOptions.Set(DisplacementLagrangeMultiplierFrictionalContactCriteria::PURE_SLIP, ThisParameters["pure_slip"].GetBool());
635  }
636 
638 private:
641 
645 
646  Flags mOptions;
647 
648  double mDispRatioTolerance;
649  double mDispAbsTolerance;
650 
651  double mRotRatioTolerance;
652  double mRotAbsTolerance;
653 
654  double mLMNormalRatioTolerance;
655  double mLMNormalAbsTolerance;
656 
657  double mLMTangentStickRatioTolerance;
658  double mLMTangentStickAbsTolerance;
659  double mLMTangentSlipRatioTolerance;
660  double mLMTangentSlipAbsTolerance;
661 
662  double mNormalTangentRatio;
663 
664  std::vector<int> mActiveDofs;
665 
667 }; // Kratos DisplacementLagrangeMultiplierFrictionalContactCriteria
668 
671 
673 template<class TSparseSpace, class TDenseSpace>
674 const Kratos::Flags DisplacementLagrangeMultiplierFrictionalContactCriteria<TSparseSpace, TDenseSpace>::ENSURE_CONTACT(Kratos::Flags::Create(0));
675 template<class TSparseSpace, class TDenseSpace>
676 const Kratos::Flags DisplacementLagrangeMultiplierFrictionalContactCriteria<TSparseSpace, TDenseSpace>::PRINTING_OUTPUT(Kratos::Flags::Create(1));
677 template<class TSparseSpace, class TDenseSpace>
678 const Kratos::Flags DisplacementLagrangeMultiplierFrictionalContactCriteria<TSparseSpace, TDenseSpace>::TABLE_IS_INITIALIZED(Kratos::Flags::Create(2));
679 template<class TSparseSpace, class TDenseSpace>
680 const Kratos::Flags DisplacementLagrangeMultiplierFrictionalContactCriteria<TSparseSpace, TDenseSpace>::ROTATION_DOF_IS_CONSIDERED(Kratos::Flags::Create(3));
681 template<class TSparseSpace, class TDenseSpace>
682 const Kratos::Flags DisplacementLagrangeMultiplierFrictionalContactCriteria<TSparseSpace, TDenseSpace>::PURE_SLIP(Kratos::Flags::Create(4));
683 }
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
virtual int MyPID() const
Definition: communicator.cpp:91
static bool CheckModelPartHasRotationDoF(ModelPart &rModelPart)
This method checks that the modelpart has a rotation DoF.
Definition: contact_utilities.cpp:147
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
TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: convergence_criteria.h:72
ModelPart::DofsArrayType DofsArrayType
DoF array type definition.
Definition: convergence_criteria.h:81
TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: convergence_criteria.h:74
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
void SetValue(const Variable< TDataType > &rThisVariable, TDataType const &rValue)
Sets the value for a given variable.
Definition: data_value_container.h:320
Convergence criteria for contact problems.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:63
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
EquationIdType EquationId() const
Definition: dof.h:324
Definition: flags.h:58
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool Is(Flags const &rOther) const
Definition: flags.h:274
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
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
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
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
utility function to do a sum reduction
Definition: reduction_utilities.h:68
This class represents the value of its variable depending to other variable.
Definition: piecewize_linear_table.h:63
static IndexType Size(VectorType const &rV)
return size of vector rV
Definition: ublas_space.h:190
This class is the base of variables and variable's components which contains their common data.
Definition: variable_data.h:49
#define FGRN(x)
Definition: color_utilities.h:27
#define FRED(x)
Definition: color_utilities.h:26
#define BOLDFONT(x)
Definition: color_utilities.h:34
DisplacementLagrangeMultiplierFrictionalContactCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:122
std::string Info() const override
Turn back information as a string.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:562
DisplacementLagrangeMultiplierFrictionalContactCriteria(DisplacementLagrangeMultiplierFrictionalContactCriteria const &rOther)
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:191
DisplacementLagrangeMultiplierFrictionalContactCriteria(const double DispRatioTolerance, const double DispAbsTolerance, const double RotRatioTolerance, const double RotAbsTolerance, const double LMNormalRatioTolerance, const double LMNormalAbsTolerance, const double LMTangentStickRatioTolerance, const double LMTangentStickAbsTolerance, const double LMTangentSlipRatioTolerance, const double LMTangentSlipAbsTolerance, const double NormalTangentRatio, const bool EnsureContact=false, const bool PureSlip=false, const bool PrintingOutput=false)
Default constructor.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:143
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:604
TSparseSpace SparseSpaceType
The sparse space used.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:95
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:86
BaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:223
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:92
static constexpr double Tolerance
The epsilon tolerance definition.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:104
TableStreamUtility::Pointer TablePrinterPointerType
The table stream definition TODO: Replace by logger.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:98
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:568
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function initializes the solution step.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:473
~DisplacementLagrangeMultiplierFrictionalContactCriteria() override=default
Destructor.
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:237
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:574
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:89
void FinalizeNonLinearIteration(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function finalizes the non-linear iteration.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:493
KRATOS_CLASS_POINTER_DEFINITION(DisplacementLagrangeMultiplierFrictionalContactCriteria)
Pointer definition of DisplacementLagrangeMultiplierFrictionalContactCriteria.
DisplacementLagrangeMultiplierFrictionalContactCriteria()
Default constructor.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:113
void Initialize(ModelPart &rModelPart) override
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:423
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:513
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:544
std::size_t IndexType
The index type definition.
Definition: displacement_lagrangemultiplier_frictional_contact_criteria.h:101
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO(label)
Definition: logger.h:250
void ComputeActiveDofs(ModelPart &rModelPart, std::vector< int > &rActiveDofs, const ModelPart::DofsArrayType &rDofSet)
This method computes the active dofs.
Definition: constraint_utilities.cpp:26
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
REACTION_CHECK_STIFFNESS_FACTOR INNER_LOOP_ITERATION DISTANCE_THRESHOLD ACTIVE_CHECK_FACTOR AUXILIAR_COORDINATES NORMAL_GAP WEIGHTED_GAP WEIGHTED_SCALAR_RESIDUAL bool
Definition: contact_structural_mechanics_application_variables.h:93
Definition: reduction_utilities.h:310