57 template<
class TSparseSpace,
138 const double DispRatioTolerance,
139 const double DispAbsTolerance,
140 const double RotRatioTolerance,
141 const double RotAbsTolerance,
142 const double LMRatioTolerance,
143 const double LMAbsTolerance,
144 const bool EnsureContact =
false,
145 const bool PrintingOutput =
false
150 mOptions.
Set(DisplacementLagrangeMultiplierResidualContactCriteria::ENSURE_CONTACT, EnsureContact);
151 mOptions.
Set(DisplacementLagrangeMultiplierResidualContactCriteria::PRINTING_OUTPUT, PrintingOutput);
152 mOptions.
Set(DisplacementLagrangeMultiplierResidualContactCriteria::TABLE_IS_INITIALIZED,
false);
153 mOptions.
Set(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED,
false);
154 mOptions.
Set(DisplacementLagrangeMultiplierResidualContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
157 mDispRatioTolerance = DispRatioTolerance;
158 mDispAbsTolerance = DispAbsTolerance;
161 mRotRatioTolerance = RotRatioTolerance;
162 mRotAbsTolerance = RotAbsTolerance;
165 mLMRatioTolerance = LMRatioTolerance;
166 mLMAbsTolerance = LMAbsTolerance;
172 ,mOptions(rOther.mOptions)
173 ,mDispRatioTolerance(rOther.mDispRatioTolerance)
174 ,mDispAbsTolerance(rOther.mDispAbsTolerance)
175 ,mDispInitialResidualNorm(rOther.mDispInitialResidualNorm)
176 ,mDispCurrentResidualNorm(rOther.mDispCurrentResidualNorm)
177 ,mRotRatioTolerance(rOther.mRotRatioTolerance)
178 ,mRotAbsTolerance(rOther.mRotAbsTolerance)
179 ,mRotInitialResidualNorm(rOther.mRotInitialResidualNorm)
180 ,mRotCurrentResidualNorm(rOther.mRotCurrentResidualNorm)
181 ,mLMRatioTolerance(rOther.mLMRatioTolerance)
182 ,mLMAbsTolerance(rOther.mLMAbsTolerance)
183 ,mLMInitialResidualNorm(rOther.mLMInitialResidualNorm)
184 ,mLMCurrentResidualNorm(rOther.mLMCurrentResidualNorm)
205 return Kratos::make_shared<ClassType>(ThisParameters);
227 double disp_residual_solution_norm = 0.0, rot_residual_solution_norm = 0.0, lm_residual_solution_norm = 0.0;
228 IndexType disp_dof_num(0), rot_dof_num(0), lm_dof_num(0);
232 std::size_t dof_id = 0;
233 double residual_dof_value = 0.0;
237 const std::size_t number_active_dofs = rb.size();
241 [](
const VariableData& rCurrVar) ->
bool {
return true;};
243 [](
const VariableData& rCurrVar) ->
bool {
return ((rCurrVar == DISPLACEMENT_X) || (rCurrVar == DISPLACEMENT_Y) || (rCurrVar == DISPLACEMENT_Z));};
244 const auto* p_check_disp = (mOptions.
Is(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) ? &check_with_rot : &check_without_rot;
248 std::tie(disp_residual_solution_norm,rot_residual_solution_norm,lm_residual_solution_norm,disp_dof_num,rot_dof_num,lm_dof_num) = block_for_each<SixReduction>(rDofSet, AuxValues(), [
this,p_check_disp,&number_active_dofs,&rb](
Dof<double>& rDof, AuxValues& aux_values) {
252 if (aux_values.dof_id < number_active_dofs) {
253 if (mActiveDofs[aux_values.dof_id] == 1) {
254 aux_values.residual_dof_value = rb[aux_values.dof_id];
256 const auto& r_curr_var = rDof.GetVariable();
257 if ((r_curr_var == VECTOR_LAGRANGE_MULTIPLIER_X) || (r_curr_var == VECTOR_LAGRANGE_MULTIPLIER_Y) || (r_curr_var == VECTOR_LAGRANGE_MULTIPLIER_Z) || (r_curr_var == LAGRANGE_MULTIPLIER_CONTACT_PRESSURE)) {
258 return std::make_tuple(0.0,0.0,std::pow(aux_values.residual_dof_value, 2),0,0,1);
259 } else if ((*p_check_disp)(r_curr_var)) {
260 return std::make_tuple(std::pow(aux_values.residual_dof_value, 2),0.0,0.0,1,0,0);
262 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;
263 return std::make_tuple(0.0,std::pow(aux_values.residual_dof_value, 2),0.0,0,1,0);
267 return std::make_tuple(0.0,0.0,0.0,0,0,0);
270 mDispCurrentResidualNorm = disp_residual_solution_norm;
271 mRotCurrentResidualNorm = rot_residual_solution_norm;
272 mLMCurrentResidualNorm = lm_residual_solution_norm;
274 double residual_disp_ratio = 1.0;
275 double residual_rot_ratio = 1.0;
276 double residual_lm_ratio = 1.0;
279 if (mOptions.
IsNot(DisplacementLagrangeMultiplierResidualContactCriteria::INITIAL_RESIDUAL_IS_SET)) {
280 mDispInitialResidualNorm = (disp_residual_solution_norm == 0.0) ? 1.0 : disp_residual_solution_norm;
281 mLMInitialResidualNorm = (lm_residual_solution_norm == 0.0) ? 1.0 : lm_residual_solution_norm;
282 residual_disp_ratio = 1.0;
283 residual_lm_ratio = 1.0;
284 if (mOptions.
Is(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
285 mRotInitialResidualNorm = (rot_residual_solution_norm == 0.0) ? 1.0 : rot_residual_solution_norm;
286 residual_rot_ratio = 1.0;
288 mOptions.
Set(DisplacementLagrangeMultiplierResidualContactCriteria::INITIAL_RESIDUAL_IS_SET,
true);
292 residual_disp_ratio = mDispCurrentResidualNorm/mDispInitialResidualNorm;
295 residual_rot_ratio = mRotCurrentResidualNorm/mRotInitialResidualNorm;
298 residual_lm_ratio = mLMCurrentResidualNorm/mLMInitialResidualNorm;
300 KRATOS_ERROR_IF(mOptions.
Is(DisplacementLagrangeMultiplierResidualContactCriteria::ENSURE_CONTACT) && residual_lm_ratio == 0.0) <<
"ERROR::CONTACT LOST::ARE YOU SURE YOU ARE SUPPOSED TO HAVE CONTACT?" << std::endl;
303 const double residual_disp_abs = mDispCurrentResidualNorm/disp_dof_num;
304 const double residual_rot_abs = mRotCurrentResidualNorm/rot_dof_num;
305 const double residual_lm_abs = mLMCurrentResidualNorm/lm_dof_num;
312 if (r_process_info.
Has(TABLE_UTILITY)) {
313 std::cout.precision(4);
315 auto&
Table = p_table->GetTable();
316 if (mOptions.
Is(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
317 Table << residual_disp_ratio << mDispRatioTolerance << residual_disp_abs << mDispAbsTolerance << residual_rot_ratio << mRotRatioTolerance << residual_rot_abs << mRotAbsTolerance << residual_lm_ratio << mLMRatioTolerance << residual_lm_abs << mLMAbsTolerance;
319 Table << residual_disp_ratio << mDispRatioTolerance << residual_disp_abs << mDispAbsTolerance << residual_lm_ratio << mLMRatioTolerance << residual_lm_abs << mLMAbsTolerance;
322 std::cout.precision(4);
323 if (mOptions.
IsNot(DisplacementLagrangeMultiplierResidualContactCriteria::PRINTING_OUTPUT)) {
324 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
BOLDFONT(
"RESIDUAL CONVERGENCE CHECK") <<
"\tSTEP: " << r_process_info[STEP] <<
"\tNL ITERATION: " << r_process_info[NL_ITERATION_NUMBER] << std::endl << std::scientific;
325 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
BOLDFONT(
"\tDISPLACEMENT: RATIO = ") << residual_disp_ratio <<
BOLDFONT(
" EXP.RATIO = ") << mDispRatioTolerance <<
BOLDFONT(
" ABS = ") << residual_disp_abs <<
BOLDFONT(
" EXP.ABS = ") << mDispAbsTolerance << std::endl;
326 if (mOptions.
Is(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
327 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
BOLDFONT(
"\tROTATION: RATIO = ") << residual_rot_ratio <<
BOLDFONT(
" EXP.RATIO = ") << mRotRatioTolerance <<
BOLDFONT(
" ABS = ") << residual_rot_abs <<
BOLDFONT(
" EXP.ABS = ") << mRotAbsTolerance << std::endl;
329 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
BOLDFONT(
"\tLAGRANGE MUL: RATIO = ") << residual_lm_ratio <<
BOLDFONT(
" EXP.RATIO = ") << mLMRatioTolerance <<
BOLDFONT(
" ABS = ") << residual_lm_abs <<
BOLDFONT(
" EXP.ABS = ") << mLMAbsTolerance << std::endl;
331 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
"RESIDUAL CONVERGENCE CHECK" <<
"\tSTEP: " << r_process_info[STEP] <<
"\tNL ITERATION: " << r_process_info[NL_ITERATION_NUMBER] << std::endl << std::scientific;
332 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
"\tDISPLACEMENT: RATIO = " << residual_disp_ratio <<
" EXP.RATIO = " << mDispRatioTolerance <<
" ABS = " << residual_disp_abs <<
" EXP.ABS = " << mDispAbsTolerance << std::endl;
333 if (mOptions.
Is(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
334 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
"\tROTATION: RATIO = " << residual_rot_ratio <<
" EXP.RATIO = " << mRotRatioTolerance <<
" ABS = " << residual_rot_abs <<
" EXP.ABS = " << mRotAbsTolerance << std::endl;
336 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
"\tLAGRANGE MUL: RATIO = " << residual_lm_ratio <<
" EXP.RATIO = " << mLMRatioTolerance <<
" ABS = " << residual_lm_abs <<
" EXP.ABS = " << mLMAbsTolerance << std::endl;
341 r_process_info[CONVERGENCE_RATIO] = (residual_disp_ratio > residual_lm_ratio) ? residual_disp_ratio : residual_lm_ratio;
342 r_process_info[RESIDUAL_NORM] = (residual_lm_abs > mLMAbsTolerance) ? residual_lm_abs : mLMAbsTolerance;
345 const bool disp_converged = (residual_disp_ratio <= mDispRatioTolerance || residual_disp_abs <= mDispAbsTolerance);
346 const bool rot_converged = (mOptions.
Is(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) ? (residual_rot_ratio <= mRotRatioTolerance || residual_rot_abs <= mRotAbsTolerance) :
true;
347 const bool lm_converged = (mOptions.
IsNot(DisplacementLagrangeMultiplierResidualContactCriteria::ENSURE_CONTACT) && residual_lm_ratio == 0.0) ?
true : (residual_lm_ratio <= mLMRatioTolerance || residual_lm_abs <= mLMAbsTolerance);
349 if (disp_converged && rot_converged && lm_converged ) {
351 if (r_process_info.
Has(TABLE_UTILITY)) {
353 auto&
Table = p_table->GetTable();
354 if (mOptions.
IsNot(DisplacementLagrangeMultiplierResidualContactCriteria::PRINTING_OUTPUT))
359 if (mOptions.
IsNot(DisplacementLagrangeMultiplierResidualContactCriteria::PRINTING_OUTPUT))
360 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
BOLDFONT(
"\tResidual") <<
" convergence is " <<
BOLDFONT(
FGRN(
"achieved")) << std::endl;
362 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
"\tResidual convergence is achieved" << std::endl;
368 if (r_process_info.
Has(TABLE_UTILITY)) {
370 auto& r_table = p_table->GetTable();
371 if (mOptions.
IsNot(DisplacementLagrangeMultiplierResidualContactCriteria::PRINTING_OUTPUT))
374 r_table <<
"Not achieved";
376 if (mOptions.
IsNot(DisplacementLagrangeMultiplierResidualContactCriteria::PRINTING_OUTPUT))
377 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
BOLDFONT(
"\tResidual") <<
" convergence is " <<
BOLDFONT(
FRED(
" not achieved")) << std::endl;
379 KRATOS_INFO(
"DisplacementLagrangeMultiplierResidualContactCriteria") <<
"\tResidual convergence is not achieved" << std::endl;
395 BaseType::mConvergenceCriteriaIsInitialized =
true;
402 if (r_process_info.
Has(TABLE_UTILITY) && mOptions.IsNot(DisplacementLagrangeMultiplierResidualContactCriteria::TABLE_IS_INITIALIZED)) {
404 auto& r_table = p_table->GetTable();
405 r_table.AddColumn(
"DP RATIO", 10);
406 r_table.AddColumn(
"EXP. RAT", 10);
407 r_table.AddColumn(
"ABS", 10);
408 r_table.AddColumn(
"EXP. ABS", 10);
409 if (mOptions.Is(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
410 r_table.AddColumn(
"RT RATIO", 10);
411 r_table.AddColumn(
"EXP. RAT", 10);
412 r_table.AddColumn(
"ABS", 10);
413 r_table.AddColumn(
"EXP. ABS", 10);
415 r_table.AddColumn(
"LM RATIO", 10);
416 r_table.AddColumn(
"EXP. RAT", 10);
417 r_table.AddColumn(
"ABS", 10);
418 r_table.AddColumn(
"EXP. ABS", 10);
419 r_table.AddColumn(
"CONVERGENCE", 15);
420 mOptions.
Set(DisplacementLagrangeMultiplierResidualContactCriteria::TABLE_IS_INITIALIZED,
true);
441 mOptions.Set(DisplacementLagrangeMultiplierResidualContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
455 "name" : "displacement_lagrangemultiplier_residual_contact_criteria",
456 "ensure_contact" : false,
457 "print_convergence_criterion" : false,
458 "residual_relative_tolerance" : 1.0e-4,
459 "residual_absolute_tolerance" : 1.0e-9,
460 "rotation_residual_relative_tolerance" : 1.0e-4,
461 "rotation_residual_absolute_tolerance" : 1.0e-9,
462 "contact_residual_relative_tolerance" : 1.0e-4,
463 "contact_residual_absolute_tolerance" : 1.0e-9
467 const Parameters base_default_parameters = BaseType::GetDefaultParameters();
469 return default_parameters;
478 return "displacement_lagrangemultiplier_residual_contact_criteria";
494 std::string
Info()
const override
496 return "DisplacementLagrangeMultiplierResidualContactCriteria";
534 BaseType::AssignSettings(ThisParameters);
537 mDispRatioTolerance = ThisParameters[
"residual_relative_tolerance"].
GetDouble();
538 mDispAbsTolerance = ThisParameters[
"residual_absolute_tolerance"].
GetDouble();
541 mRotRatioTolerance = ThisParameters[
"rotation_residual_relative_tolerance"].
GetDouble();
542 mRotAbsTolerance = ThisParameters[
"rotation_residual_absolute_tolerance"].
GetDouble();
545 mLMRatioTolerance = ThisParameters[
"contact_displacement_absolute_tolerance"].
GetDouble();
546 mLMAbsTolerance = ThisParameters[
"contact_residual_absolute_tolerance"].
GetDouble();
549 mOptions.Set(DisplacementLagrangeMultiplierResidualContactCriteria::ENSURE_CONTACT, ThisParameters[
"ensure_contact"].GetBool());
550 mOptions.Set(DisplacementLagrangeMultiplierResidualContactCriteria::PRINTING_OUTPUT, ThisParameters[
"print_convergence_criterion"].GetBool());
551 mOptions.Set(DisplacementLagrangeMultiplierResidualContactCriteria::TABLE_IS_INITIALIZED,
false);
552 mOptions.Set(DisplacementLagrangeMultiplierResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED,
false);
553 mOptions.Set(DisplacementLagrangeMultiplierResidualContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
567 double mDispRatioTolerance;
568 double mDispAbsTolerance;
569 double mDispInitialResidualNorm;
570 double mDispCurrentResidualNorm;
572 double mRotRatioTolerance;
573 double mRotAbsTolerance;
574 double mRotInitialResidualNorm;
575 double mRotCurrentResidualNorm;
577 double mLMRatioTolerance;
578 double mLMAbsTolerance;
579 double mLMInitialResidualNorm;
580 double mLMCurrentResidualNorm;
582 std::vector<int> mActiveDofs;
591 template<
class TSparseSpace,
class TDenseSpace>
593 template<
class TSparseSpace,
class TDenseSpace>
595 template<
class TSparseSpace,
class TDenseSpace>
597 template<
class TSparseSpace,
class TDenseSpace>
599 template<
class TSparseSpace,
class TDenseSpace>
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
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
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
EquationIdType EquationId() const
Definition: dof.h:324
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
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
#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