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_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 = false,
103  const bool IODebug = false
104  ) : BaseType(ComputeDynamicFactor, IODebug, PureSlip)
105  {
106  // Set local flags
107  BaseType::mOptions.Set(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT, PrintingOutput);
108  BaseType::mOptions.Set(ALMFrictionalMortarConvergenceCriteria::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  // Getting process info
192  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
193 
194  // Compute the active set
195  if (!r_process_info[ACTIVE_SET_COMPUTED]) {
196  const array_1d<std::size_t, 2> is_converged = ActiveSetUtilities::ComputeALMFrictionalActiveSet(rModelPart, BaseType::mOptions.Is(BaseType::PURE_SLIP), this->GetEchoLevel());
197 
198  // We save to the process info if the active set has converged
199  r_process_info[ACTIVE_SET_CONVERGED] = is_converged[0] == 0 ? true : false;
200  r_process_info[SLIP_SET_CONVERGED] = is_converged[1] == 0 ? true : false;
201  r_process_info[ACTIVE_SET_COMPUTED] = true;
202  }
203 
204  // Getting converged bools
205  const bool active_set_converged = r_process_info[ACTIVE_SET_CONVERGED];
206  const bool slip_set_converged = r_process_info[SLIP_SET_CONVERGED];
207 
208  if (rModelPart.GetCommunicator().MyPID() == 0 && this->GetEchoLevel() > 0) {
209  if (r_process_info.Has(TABLE_UTILITY)) {
210  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
211  auto& r_table = p_table->GetTable();
212  if (active_set_converged) {
213  if (BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
214  r_table << BOLDFONT(FGRN(" Achieved"));
215  else
216  r_table << "Achieved";
217  } else {
218  if (BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
219  r_table << BOLDFONT(FRED(" Not achieved"));
220  else
221  r_table << "Not achieved";
222  }
223  if (BaseType::mOptions.IsNot(BaseType::PURE_SLIP)) {
224  if (slip_set_converged) {
225  if (BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
226  r_table << BOLDFONT(FGRN(" Achieved"));
227  else
228  r_table << "Achieved";
229  } else {
230  if (BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
231  r_table << BOLDFONT(FRED(" Not achieved"));
232  else
233  r_table << "Not achieved";
234  }
235  }
236  } else {
237  if (active_set_converged) {
238  if (BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
239  KRATOS_INFO("ALMFrictionalMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FGRN("achieved")) << std::endl;
240  else
241  KRATOS_INFO("ALMFrictionalMortarConvergenceCriteria") << "\tActive set convergence is achieved" << std::endl;
242  } else {
243  if (BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
244  KRATOS_INFO("ALMFrictionalMortarConvergenceCriteria") << BOLDFONT("\tActive set") << " convergence is " << BOLDFONT(FRED("not achieved")) << std::endl;
245  else
246  KRATOS_INFO("ALMFrictionalMortarConvergenceCriteria") << "\tActive set convergence is not achieved" << std::endl;
247  }
248 
249  if (BaseType::mOptions.IsNot(BaseType::PURE_SLIP)) {
250  if (slip_set_converged) {
251  if (BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
252  KRATOS_INFO("ALMFrictionalMortarConvergenceCriteria") << BOLDFONT("\tSlip/stick set") << " convergence is " << BOLDFONT(FGRN("achieved")) << std::endl;
253  else
254  KRATOS_INFO("ALMFrictionalMortarConvergenceCriteria") << "\tSlip/stick set convergence is achieved" << std::endl;
255  } else {
256  if (BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT))
257  KRATOS_INFO("ALMFrictionalMortarConvergenceCriteria") << BOLDFONT("\tSlip/stick set") << " convergence is " << BOLDFONT(FRED("not achieved")) << std::endl;
258  else
259  KRATOS_INFO("ALMFrictionalMortarConvergenceCriteria") << "\tSlip/stick set convergence is not achieved" << std::endl;
260  }
261  }
262  }
263  }
264 
265  return (active_set_converged && slip_set_converged);
266  }
267 
272  void Initialize(ModelPart& rModelPart) override
273  {
274  // Calling base criteria
275  BaseType::Initialize(rModelPart);
276 
277  ProcessInfo& r_process_info = rModelPart.GetProcessInfo();
278  if (r_process_info.Has(TABLE_UTILITY) && BaseType::mOptions.IsNot(ALMFrictionalMortarConvergenceCriteria::TABLE_IS_INITIALIZED)) {
279  TablePrinterPointerType p_table = r_process_info[TABLE_UTILITY];
280  auto& r_table = p_table->GetTable();
281  r_table.AddColumn("ACTIVE SET CONV", 15);
282  if (BaseType::mOptions.IsNot(BaseType::PURE_SLIP)) {
283  r_table.AddColumn("SLIP/STICK CONV", 15);
284  }
285  BaseType::mOptions.Set(ALMFrictionalMortarConvergenceCriteria::TABLE_IS_INITIALIZED, true);
286  }
287  }
288 
294  {
295  Parameters default_parameters = Parameters(R"(
296  {
297  "name" : "alm_frictional_mortar_criteria",
298  "print_convergence_criterion" : false
299  })" );
300 
301  // Getting base class default parameters
302  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
303  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
304  return default_parameters;
305  }
306 
311  static std::string Name()
312  {
313  return "alm_frictional_mortar_criteria";
314  }
315 
319 
323 
327 
329  std::string Info() const override
330  {
331  return "ALMFrictionalMortarConvergenceCriteria";
332  }
333 
335  void PrintInfo(std::ostream& rOStream) const override
336  {
337  rOStream << Info();
338  }
339 
341  void PrintData(std::ostream& rOStream) const override
342  {
343  rOStream << Info();
344  }
345 
347 protected:
350 
354 
358 
362 
367  void AssignSettings(const Parameters ThisParameters) override
368  {
369  BaseType::AssignSettings(ThisParameters);
370 
371  // Set local flags
372  BaseType::mOptions.Set(ALMFrictionalMortarConvergenceCriteria::PRINTING_OUTPUT, ThisParameters["print_convergence_criterion"].GetBool());
373  BaseType::mOptions.Set(ALMFrictionalMortarConvergenceCriteria::TABLE_IS_INITIALIZED, false);
374  }
375 
380  void ResetWeightedGap(ModelPart& rModelPart) override
381  {
382  // Auxiliary zero array
383  const array_1d<double, 3> zero_array = ZeroVector(3);
384 
385  // We reset the weighted values
386  auto& r_nodes_array = rModelPart.GetSubModelPart("Contact").Nodes();
387  VariableUtils().SetVariable(WEIGHTED_GAP, 0.0, r_nodes_array);
388  VariableUtils().SetVariable(WEIGHTED_SLIP, zero_array, r_nodes_array);
389  }
390 
392 }; // Class ALMFrictionalMortarConvergenceCriteria
393 
396 
398 template<class TSparseSpace, class TDenseSpace>
399 const Kratos::Flags ALMFrictionalMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::PRINTING_OUTPUT(Kratos::Flags::Create(3));
400 template<class TSparseSpace, class TDenseSpace>
401 const Kratos::Flags ALMFrictionalMortarConvergenceCriteria<TSparseSpace, TDenseSpace>::TABLE_IS_INITIALIZED(Kratos::Flags::Create(4));
402 
403 } // namespace Kratos
Custom convergence criteria for the mortar condition for frictional case.
Definition: alm_frictional_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
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 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
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
std::string Info() const override
Turn back information as a string.
Definition: alm_frictional_mortar_criteria.h:329
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
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: alm_frictional_mortar_criteria.h:293
ALMFrictionalMortarConvergenceCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: alm_frictional_mortar_criteria.h:115
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: alm_frictional_mortar_criteria.h:335
TableStreamUtility::Pointer TablePrinterPointerType
The table stream definition TODO: Replace by logger.
Definition: alm_frictional_mortar_criteria.h:89
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: alm_frictional_mortar_criteria.h:367
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: alm_frictional_mortar_criteria.h:83
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_frictional_mortar_criteria.h:158
static constexpr double Tolerance
The epsilon tolerance definition.
Definition: alm_frictional_mortar_criteria.h:92
ALMFrictionalMortarConvergenceCriteria(const bool PureSlip=false, const bool PrintingOutput=false, const bool ComputeDynamicFactor=false, const bool IODebug=false)
Default constructors.
Definition: alm_frictional_mortar_criteria.h:99
void ResetWeightedGap(ModelPart &rModelPart) override
This method resets the weighted gap in the nodes of the problem.
Definition: alm_frictional_mortar_criteria.h:380
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: alm_frictional_mortar_criteria.h:311
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: alm_frictional_mortar_criteria.h:86
typename BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: base_mortar_criteria.h:88
ConvergenceCriteriaBaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: alm_frictional_mortar_criteria.h:144
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: alm_frictional_mortar_criteria.h:341
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
KRATOS_CLASS_POINTER_DEFINITION(ALMFrictionalMortarConvergenceCriteria)
Pointer definition of ALMFrictionalMortarConvergenceCriteria.
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: alm_frictional_mortar_criteria.h:272
Flags mOptions
Definition: base_mortar_criteria.h:461
KRATOS_DEFINE_LOCAL_FLAG(PRINTING_OUTPUT)
Local Flags.
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: alm_frictional_mortar_criteria.h:180
ALMFrictionalMortarConvergenceCriteria(ALMFrictionalMortarConvergenceCriteria const &rOther)
Copy constructor.
Definition: alm_frictional_mortar_criteria.h:124
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
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: alm_frictional_mortar_criteria.h:80
~ALMFrictionalMortarConvergenceCriteria() override=default
Destructor.
#define KRATOS_INFO(label)
Definition: logger.h:250
array_1d< std::size_t, 2 > ComputeALMFrictionalActiveSet(ModelPart &rModelPart, const bool PureSlip, const SizeType EchoLevel)
This function computes the active set for penalty frictional cases.
Definition: active_set_utilities.cpp:265
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561