57 template<
class TSparseSpace,
102 static constexpr
double Tolerance = std::numeric_limits<double>::epsilon();
141 const double DispRatioTolerance,
142 const double DispAbsTolerance,
143 const double RotRatioTolerance,
144 const double RotAbsTolerance,
145 const double LMRatioTolerance,
146 const double LMAbsTolerance,
147 const bool EnsureContact =
false,
148 const bool PrintingOutput =
false
153 mOptions.
Set(DisplacementLagrangeMultiplierMixedContactCriteria::ENSURE_CONTACT, EnsureContact);
154 mOptions.
Set(DisplacementLagrangeMultiplierMixedContactCriteria::PRINTING_OUTPUT, PrintingOutput);
155 mOptions.
Set(DisplacementLagrangeMultiplierMixedContactCriteria::TABLE_IS_INITIALIZED,
false);
156 mOptions.
Set(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED,
false);
157 mOptions.
Set(DisplacementLagrangeMultiplierMixedContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
160 mDispRatioTolerance = DispRatioTolerance;
161 mDispAbsTolerance = DispAbsTolerance;
164 mRotRatioTolerance = RotRatioTolerance;
165 mRotAbsTolerance = RotAbsTolerance;
168 mLMRatioTolerance = LMRatioTolerance;
169 mLMAbsTolerance = LMAbsTolerance;
175 ,mOptions(rOther.mOptions)
176 ,mDispRatioTolerance(rOther.mDispRatioTolerance)
177 ,mDispAbsTolerance(rOther.mDispAbsTolerance)
178 ,mDispInitialResidualNorm(rOther.mDispInitialResidualNorm)
179 ,mDispCurrentResidualNorm(rOther.mDispCurrentResidualNorm)
180 ,mRotRatioTolerance(rOther.mRotRatioTolerance)
181 ,mRotAbsTolerance(rOther.mRotAbsTolerance)
182 ,mRotInitialResidualNorm(rOther.mRotInitialResidualNorm)
183 ,mRotCurrentResidualNorm(rOther.mRotCurrentResidualNorm)
184 ,mLMRatioTolerance(rOther.mLMRatioTolerance)
185 ,mLMAbsTolerance(rOther.mLMAbsTolerance)
206 return Kratos::make_shared<ClassType>(ThisParameters);
228 double disp_residual_solution_norm = 0.0, rot_residual_solution_norm = 0.0, lm_solution_norm = 0.0, lm_increase_norm = 0.0;
229 IndexType disp_dof_num(0),rot_dof_num(0),lm_dof_num(0);
233 std::size_t dof_id = 0;
234 double residual_dof_value = 0.0, dof_value = 0.0, dof_incr = 0.0;
238 const std::size_t number_active_dofs = rb.size();
242 [](
const VariableData& rCurrVar) ->
bool {
return true;};
244 [](
const VariableData& rCurrVar) ->
bool {
return ((rCurrVar == DISPLACEMENT_X) || (rCurrVar == DISPLACEMENT_Y) || (rCurrVar == DISPLACEMENT_Z));};
245 const auto* p_check_disp = (mOptions.
Is(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED)) ? &check_with_rot : &check_without_rot;
249 std::tie(disp_residual_solution_norm, rot_residual_solution_norm, lm_solution_norm, lm_increase_norm, disp_dof_num, rot_dof_num, lm_dof_num) = block_for_each<SevenReduction>(rDofSet, AuxValues(), [
this,p_check_disp,&number_active_dofs,&rb,&rDx](
Dof<double>& rDof, AuxValues& aux_values) {
253 if (aux_values.dof_id < number_active_dofs) {
254 if (mActiveDofs[aux_values.dof_id] == 1) {
255 const auto& r_curr_var = rDof.GetVariable();
256 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)) {
257 aux_values.dof_value = rDof.GetSolutionStepValue(0);
258 aux_values.dof_incr = rDx[aux_values.dof_id];
259 return std::make_tuple(0.0,0.0,std::pow(aux_values.dof_value, 2),std::pow(aux_values.dof_incr, 2),0,0,1);
260 } else if ((*p_check_disp)(r_curr_var)) {
261 aux_values.residual_dof_value = rb[aux_values.dof_id];
262 return std::make_tuple(std::pow(aux_values.residual_dof_value, 2),0.0,0.0,0.0,1,0,0);
264 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;
265 aux_values.residual_dof_value = rb[aux_values.dof_id];
266 return std::make_tuple(0.0,std::pow(aux_values.residual_dof_value, 2),0.0,0.0,0,1,0);
270 return std::make_tuple(0.0,0.0,0.0,0.0,0,0,0);
273 if(lm_increase_norm <
Tolerance) lm_increase_norm = 1.0;
274 KRATOS_ERROR_IF(mOptions.
Is(DisplacementLagrangeMultiplierMixedContactCriteria::ENSURE_CONTACT) && lm_solution_norm <
Tolerance) <<
"ERROR::CONTACT LOST::ARE YOU SURE YOU ARE SUPPOSED TO HAVE CONTACT?" << std::endl;
276 mDispCurrentResidualNorm = disp_residual_solution_norm;
277 mRotCurrentResidualNorm = rot_residual_solution_norm;
278 const double lm_ratio = lm_solution_norm >
Tolerance ? std::sqrt(lm_increase_norm/lm_solution_norm) : 0.0;
279 const double lm_abs = std::sqrt(lm_increase_norm)/
static_cast<double>(lm_dof_num);
281 double residual_disp_ratio, residual_rot_ratio;
284 if (mOptions.
IsNot(DisplacementLagrangeMultiplierMixedContactCriteria::INITIAL_RESIDUAL_IS_SET)) {
285 mDispInitialResidualNorm = (disp_residual_solution_norm <
Tolerance) ? 1.0 : disp_residual_solution_norm;
286 residual_disp_ratio = 1.0;
287 if (mOptions.
Is(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
288 mRotInitialResidualNorm = (rot_residual_solution_norm <
Tolerance) ? 1.0 : rot_residual_solution_norm;
289 residual_rot_ratio = 1.0;
291 mOptions.
Set(DisplacementLagrangeMultiplierMixedContactCriteria::INITIAL_RESIDUAL_IS_SET,
true);
295 residual_disp_ratio = mDispCurrentResidualNorm/mDispInitialResidualNorm;
298 residual_rot_ratio = mRotCurrentResidualNorm/mRotInitialResidualNorm;
301 double residual_disp_abs = mDispCurrentResidualNorm/disp_dof_num;
302 double residual_rot_abs = mRotCurrentResidualNorm/rot_dof_num;
309 if (r_process_info.
Has(TABLE_UTILITY)) {
310 std::cout.precision(4);
312 auto& r_table = p_table->GetTable();
313 if (mOptions.
Is(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
314 r_table << residual_disp_ratio << mDispRatioTolerance << residual_disp_abs << mDispAbsTolerance << residual_rot_ratio << mRotRatioTolerance << residual_rot_abs << mRotAbsTolerance << lm_ratio << mLMRatioTolerance << lm_abs << mLMAbsTolerance;
316 r_table << residual_disp_ratio << mDispRatioTolerance << residual_disp_abs << mDispAbsTolerance << lm_ratio << mLMRatioTolerance << lm_abs << mLMAbsTolerance;
319 std::cout.precision(4);
320 if (mOptions.
IsNot(DisplacementLagrangeMultiplierMixedContactCriteria::PRINTING_OUTPUT)) {
321 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
BOLDFONT(
"MIXED CONVERGENCE CHECK") <<
"\tSTEP: " << r_process_info[STEP] <<
"\tNL ITERATION: " << r_process_info[NL_ITERATION_NUMBER] << std::endl << std::scientific;
322 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
BOLDFONT(
"\tDISPLACEMENT: RATIO = ") << residual_disp_ratio <<
BOLDFONT(
" EXP.RATIO = ") << mDispRatioTolerance <<
BOLDFONT(
" ABS = ") << residual_disp_abs <<
BOLDFONT(
" EXP.ABS = ") << mDispAbsTolerance << std::endl;
323 if (mOptions.
Is(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
324 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
BOLDFONT(
"\tROTATION: RATIO = ") << residual_rot_ratio <<
BOLDFONT(
" EXP.RATIO = ") << mRotRatioTolerance <<
BOLDFONT(
" ABS = ") << residual_rot_abs <<
BOLDFONT(
" EXP.ABS = ") << mRotAbsTolerance << std::endl;
326 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
BOLDFONT(
"\tLAGRANGE MUL: RATIO = ") << lm_ratio <<
BOLDFONT(
" EXP.RATIO = ") << mLMRatioTolerance <<
BOLDFONT(
" ABS = ") << lm_abs <<
BOLDFONT(
" EXP.ABS = ") << mLMAbsTolerance << std::endl;
328 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
"MIXED CONVERGENCE CHECK" <<
"\tSTEP: " << r_process_info[STEP] <<
"\tNL ITERATION: " << r_process_info[NL_ITERATION_NUMBER] << std::endl << std::scientific;
329 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
"\tDISPLACEMENT: RATIO = " << residual_disp_ratio <<
" EXP.RATIO = " << mDispRatioTolerance <<
" ABS = " << residual_disp_abs <<
" EXP.ABS = " << mDispAbsTolerance << std::endl;
330 if (mOptions.
Is(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
331 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
"\tROTATION: RATIO = " << residual_rot_ratio <<
" EXP.RATIO = " << mRotRatioTolerance <<
" ABS = " << residual_rot_abs <<
" EXP.ABS = " << mRotAbsTolerance << std::endl;
333 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
"\tLAGRANGE MUL: RATIO = " << lm_ratio <<
" EXP.RATIO = " << mLMRatioTolerance <<
" ABS = " << lm_abs <<
" EXP.ABS = " << mLMAbsTolerance << std::endl;
338 r_process_info[CONVERGENCE_RATIO] = (residual_disp_ratio > lm_ratio) ? residual_disp_ratio : lm_ratio;
339 r_process_info[RESIDUAL_NORM] = (lm_abs > mLMAbsTolerance) ? lm_abs : mLMAbsTolerance;
342 const bool disp_converged = (residual_disp_ratio <= mDispRatioTolerance || residual_disp_abs <= mDispAbsTolerance);
343 const bool rot_converged = (mOptions.
Is(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED)) ? (residual_rot_ratio <= mRotRatioTolerance || residual_rot_abs <= mRotAbsTolerance) :
true;
344 const bool lm_converged = (mOptions.
IsNot(DisplacementLagrangeMultiplierMixedContactCriteria::ENSURE_CONTACT) && lm_solution_norm <
Tolerance) ?
true : (lm_ratio <= mLMRatioTolerance || lm_abs <= mLMAbsTolerance);
346 if ( disp_converged && rot_converged && lm_converged ) {
348 if (r_process_info.
Has(TABLE_UTILITY)) {
350 auto& r_table = p_table->GetTable();
351 if (mOptions.
IsNot(DisplacementLagrangeMultiplierMixedContactCriteria::PRINTING_OUTPUT))
354 r_table <<
"Achieved";
356 if (mOptions.
IsNot(DisplacementLagrangeMultiplierMixedContactCriteria::PRINTING_OUTPUT))
359 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
"\tConvergence is achieved" << std::endl;
365 if (r_process_info.
Has(TABLE_UTILITY)) {
367 auto& r_table = p_table->GetTable();
368 if (mOptions.
IsNot(DisplacementLagrangeMultiplierMixedContactCriteria::PRINTING_OUTPUT))
371 r_table <<
"Not achieved";
373 if (mOptions.
IsNot(DisplacementLagrangeMultiplierMixedContactCriteria::PRINTING_OUTPUT))
374 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
BOLDFONT(
"\tConvergence") <<
" is " <<
BOLDFONT(
FRED(
" not achieved")) << std::endl;
376 KRATOS_INFO(
"DisplacementLagrangeMultiplierMixedContactCriteria") <<
"\tConvergence is not achieved" << std::endl;
392 BaseType::mConvergenceCriteriaIsInitialized =
true;
399 if (r_process_info.
Has(TABLE_UTILITY) && mOptions.IsNot(DisplacementLagrangeMultiplierMixedContactCriteria::TABLE_IS_INITIALIZED)) {
401 auto& r_table = p_table->GetTable();
402 r_table.AddColumn(
"DP RATIO", 10);
403 r_table.AddColumn(
"EXP. RAT", 10);
404 r_table.AddColumn(
"ABS", 10);
405 r_table.AddColumn(
"EXP. ABS", 10);
406 if (mOptions.Is(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
407 r_table.AddColumn(
"RT RATIO", 10);
408 r_table.AddColumn(
"EXP. RAT", 10);
409 r_table.AddColumn(
"ABS", 10);
410 r_table.AddColumn(
"EXP. ABS", 10);
412 r_table.AddColumn(
"LM RATIO", 10);
413 r_table.AddColumn(
"EXP. RAT", 10);
414 r_table.AddColumn(
"ABS", 10);
415 r_table.AddColumn(
"EXP. ABS", 10);
416 r_table.AddColumn(
"CONVERGENCE", 15);
417 mOptions.
Set(DisplacementLagrangeMultiplierMixedContactCriteria::TABLE_IS_INITIALIZED,
true);
438 mOptions.Set(DisplacementLagrangeMultiplierMixedContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
452 "name" : "displacement_lagrange_multiplier_mixed_contact_criteria",
453 "ensure_contact" : false,
454 "print_convergence_criterion" : false,
455 "residual_relative_tolerance" : 1.0e-4,
456 "residual_absolute_tolerance" : 1.0e-9,
457 "rotation_residual_relative_tolerance" : 1.0e-4,
458 "rotation_residual_absolute_tolerance" : 1.0e-9,
459 "contact_displacement_relative_tolerance" : 1.0e-4,
460 "contact_displacement_absolute_tolerance" : 1.0e-9
464 const Parameters base_default_parameters = BaseType::GetDefaultParameters();
466 return default_parameters;
475 return "displacement_lagrange_multiplier_mixed_contact_criteria";
491 std::string
Info()
const override
493 return "DisplacementLagrangeMultiplierMixedContactCriteria";
527 BaseType::AssignSettings(ThisParameters);
530 mDispRatioTolerance = ThisParameters[
"residual_relative_tolerance"].
GetDouble();
531 mDispAbsTolerance = ThisParameters[
"residual_absolute_tolerance"].
GetDouble();
534 mRotRatioTolerance = ThisParameters[
"rotation_residual_relative_tolerance"].
GetDouble();
535 mRotAbsTolerance = ThisParameters[
"rotation_residual_absolute_tolerance"].
GetDouble();
538 mLMRatioTolerance = ThisParameters[
"contact_displacement_relative_tolerance"].
GetDouble();
539 mLMAbsTolerance = ThisParameters[
"contact_displacement_absolute_tolerance"].
GetDouble();
542 mOptions.Set(DisplacementLagrangeMultiplierMixedContactCriteria::ENSURE_CONTACT, ThisParameters[
"ensure_contact"].GetBool());
543 mOptions.Set(DisplacementLagrangeMultiplierMixedContactCriteria::PRINTING_OUTPUT, ThisParameters[
"print_convergence_criterion"].GetBool());
544 mOptions.Set(DisplacementLagrangeMultiplierMixedContactCriteria::TABLE_IS_INITIALIZED,
false);
545 mOptions.Set(DisplacementLagrangeMultiplierMixedContactCriteria::ROTATION_DOF_IS_CONSIDERED,
false);
546 mOptions.Set(DisplacementLagrangeMultiplierMixedContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
560 double mDispRatioTolerance;
561 double mDispAbsTolerance;
562 double mDispInitialResidualNorm;
563 double mDispCurrentResidualNorm;
565 double mRotRatioTolerance;
566 double mRotAbsTolerance;
567 double mRotInitialResidualNorm;
568 double mRotCurrentResidualNorm;
570 double mLMRatioTolerance;
571 double mLMAbsTolerance;
573 std::vector<int> mActiveDofs;
582 template<
class TSparseSpace,
class TDenseSpace>
584 template<
class TSparseSpace,
class TDenseSpace>
586 template<
class TSparseSpace,
class TDenseSpace>
588 template<
class TSparseSpace,
class TDenseSpace>
590 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
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