54 template<
class TSparseSpace,
131 const double DispRatioTolerance,
132 const double DispAbsTolerance,
133 const double RotRatioTolerance,
134 const double RotAbsTolerance,
135 const bool PrintingOutput =
false
140 mOptions.
Set(DisplacementResidualContactCriteria::PRINTING_OUTPUT, PrintingOutput);
141 mOptions.
Set(DisplacementResidualContactCriteria::TABLE_IS_INITIALIZED,
false);
142 mOptions.
Set(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED,
false);
143 mOptions.
Set(DisplacementResidualContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
146 mDispRatioTolerance = DispRatioTolerance;
147 mDispAbsTolerance = DispAbsTolerance;
150 mRotRatioTolerance = RotRatioTolerance;
151 mRotAbsTolerance = RotAbsTolerance;
157 ,mOptions(rOther.mOptions)
158 ,mDispRatioTolerance(rOther.mDispRatioTolerance)
159 ,mDispAbsTolerance(rOther.mDispAbsTolerance)
160 ,mDispInitialResidualNorm(rOther.mDispInitialResidualNorm)
161 ,mDispCurrentResidualNorm(rOther.mDispCurrentResidualNorm)
162 ,mRotRatioTolerance(rOther.mRotRatioTolerance)
163 ,mRotAbsTolerance(rOther.mRotAbsTolerance)
164 ,mRotInitialResidualNorm(rOther.mRotInitialResidualNorm)
165 ,mRotCurrentResidualNorm(rOther.mRotCurrentResidualNorm)
186 return Kratos::make_shared<ClassType>(ThisParameters);
208 double disp_residual_solution_norm = 0.0;
210 double rot_residual_solution_norm = 0.0;
215 std::size_t dof_id = 0;
216 double residual_dof_value = 0.0;
221 [](
const VariableData& rCurrVar) ->
bool {
return true;};
223 [](
const VariableData& rCurrVar) ->
bool {
return ((rCurrVar == DISPLACEMENT_X) || (rCurrVar == DISPLACEMENT_Y) || (rCurrVar == DISPLACEMENT_Z));};
224 const auto* p_check_disp = (mOptions.
Is(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) ? &check_with_rot : &check_without_rot;
228 std::tie(disp_residual_solution_norm,disp_dof_num,rot_residual_solution_norm,rot_dof_num) = block_for_each<FourReduction>(rDofSet, AuxValues(), [&](
Dof<double>& rDof, AuxValues& aux_values) {
230 aux_values.dof_id = rDof.EquationId();
231 aux_values.residual_dof_value = rb[aux_values.dof_id];
233 const auto& r_curr_var = rDof.GetVariable();
234 if ((*p_check_disp)(r_curr_var)) {
235 return std::make_tuple(std::pow(aux_values.residual_dof_value, 2),1,0.0,0);
237 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;
238 return std::make_tuple(0.0,0,std::pow(aux_values.residual_dof_value, 2),1);
241 return std::make_tuple(0.0,0,0.0,0);
244 mDispCurrentResidualNorm = disp_residual_solution_norm;
245 mRotCurrentResidualNorm = rot_residual_solution_norm;
247 double residual_disp_ratio = 1.0;
248 double residual_rot_ratio = 1.0;
251 if (mOptions.
IsNot(DisplacementResidualContactCriteria::INITIAL_RESIDUAL_IS_SET)) {
252 mDispInitialResidualNorm = (disp_residual_solution_norm == 0.0) ? 1.0 : disp_residual_solution_norm;
253 residual_disp_ratio = 1.0;
254 if (mOptions.
Is(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
255 mRotInitialResidualNorm = (rot_residual_solution_norm == 0.0) ? 1.0 : rot_residual_solution_norm;
256 residual_rot_ratio = 1.0;
258 mOptions.
Set(DisplacementResidualContactCriteria::INITIAL_RESIDUAL_IS_SET,
true);
262 residual_disp_ratio = mDispCurrentResidualNorm/mDispInitialResidualNorm;
263 residual_rot_ratio = mRotCurrentResidualNorm/mRotInitialResidualNorm;
266 const double residual_disp_abs = mDispCurrentResidualNorm/disp_dof_num;
267 const double residual_rot_abs = mRotCurrentResidualNorm/rot_dof_num;
274 if (r_process_info.
Has(TABLE_UTILITY)) {
275 std::cout.precision(4);
277 auto& r_table = p_table->GetTable();
278 if (mOptions.
Is(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
279 r_table << residual_disp_ratio << mDispRatioTolerance << residual_disp_abs << mDispAbsTolerance << residual_rot_ratio << mRotRatioTolerance << residual_rot_abs << mRotAbsTolerance;
281 r_table << residual_disp_ratio << mDispRatioTolerance << residual_disp_abs << mDispAbsTolerance;
284 std::cout.precision(4);
285 if (mOptions.
IsNot(DisplacementResidualContactCriteria::PRINTING_OUTPUT)) {
286 KRATOS_INFO(
"DisplacementResidualContactCriteria") <<
BOLDFONT(
"RESIDUAL CONVERGENCE CHECK") <<
"\tSTEP: " << r_process_info[STEP] <<
"\tNL ITERATION: " << r_process_info[NL_ITERATION_NUMBER] << std::endl << std::scientific;
287 KRATOS_INFO(
"DisplacementResidualContactCriteria") <<
BOLDFONT(
"\tDISPLACEMENT: RATIO = ") << residual_disp_ratio <<
BOLDFONT(
" EXP.RATIO = ") << mDispRatioTolerance <<
BOLDFONT(
" ABS = ") << residual_disp_abs <<
BOLDFONT(
" EXP.ABS = ") << mDispAbsTolerance << std::endl;
288 if (mOptions.
Is(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
289 KRATOS_INFO(
"DisplacementResidualContactCriteria") <<
BOLDFONT(
"\tDISPLACEMENT: RATIO = ") << residual_rot_ratio <<
BOLDFONT(
" EXP.RATIO = ") << mRotRatioTolerance <<
BOLDFONT(
" ABS = ") << residual_rot_abs <<
BOLDFONT(
" EXP.ABS = ") << mRotAbsTolerance << std::endl;
292 KRATOS_INFO(
"DisplacementResidualContactCriteria") <<
"RESIDUAL CONVERGENCE CHECK" <<
"\tSTEP: " << r_process_info[STEP] <<
"\tNL ITERATION: " << r_process_info[NL_ITERATION_NUMBER] << std::endl << std::scientific;
293 KRATOS_INFO(
"DisplacementResidualContactCriteria") <<
"\tDISPLACEMENT: RATIO = " << residual_disp_ratio <<
" EXP.RATIO = " << mDispRatioTolerance <<
" ABS = " << residual_disp_abs <<
" EXP.ABS = " << mDispAbsTolerance << std::endl;
294 if (mOptions.
Is(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
295 KRATOS_INFO(
"DisplacementResidualContactCriteria") <<
"\tDISPLACEMENT: RATIO = " << residual_rot_ratio <<
" EXP.RATIO = " << mRotRatioTolerance <<
" ABS = " << residual_rot_abs <<
" EXP.ABS = " << mRotAbsTolerance << std::endl;
301 r_process_info[CONVERGENCE_RATIO] = residual_disp_ratio;
302 r_process_info[RESIDUAL_NORM] = residual_disp_abs;
305 const bool disp_converged = (residual_disp_ratio <= mDispRatioTolerance || residual_disp_abs <= mDispAbsTolerance);
306 const bool rot_converged = (mOptions.
Is(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) ? (residual_rot_ratio <= mRotRatioTolerance || residual_rot_abs <= mRotAbsTolerance) :
true;
308 if (disp_converged && rot_converged) {
310 if (r_process_info.
Has(TABLE_UTILITY)) {
312 auto& r_table = p_table->GetTable();
313 if (mOptions.
IsNot(DisplacementResidualContactCriteria::PRINTING_OUTPUT))
316 r_table <<
"Achieved";
318 if (mOptions.
IsNot(DisplacementResidualContactCriteria::PRINTING_OUTPUT))
321 KRATOS_INFO(
"DisplacementResidualContactCriteria") <<
"\tResidual convergence is achieved" << std::endl;
327 if (r_process_info.
Has(TABLE_UTILITY)) {
329 auto& r_table = p_table->GetTable();
330 if (mOptions.
IsNot(DisplacementResidualContactCriteria::PRINTING_OUTPUT))
333 r_table <<
"Not achieved";
335 if (mOptions.
IsNot(DisplacementResidualContactCriteria::PRINTING_OUTPUT))
338 KRATOS_INFO(
"DisplacementResidualContactCriteria") <<
"\tResidual convergence is not achieved" << std::endl;
354 BaseType::mConvergenceCriteriaIsInitialized =
true;
361 if (r_process_info.
Has(TABLE_UTILITY) && mOptions.IsNot(DisplacementResidualContactCriteria::TABLE_IS_INITIALIZED)) {
363 auto& r_table = p_table->GetTable();
364 r_table.AddColumn(
"DP RATIO", 10);
365 r_table.AddColumn(
"EXP. RAT", 10);
366 r_table.AddColumn(
"ABS", 10);
367 r_table.AddColumn(
"EXP. ABS", 10);
368 if (mOptions.Is(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED)) {
369 r_table.AddColumn(
"RT RATIO", 10);
370 r_table.AddColumn(
"EXP. RAT", 10);
371 r_table.AddColumn(
"ABS", 10);
372 r_table.AddColumn(
"EXP. ABS", 10);
374 r_table.AddColumn(
"CONVERGENCE", 15);
375 mOptions.
Set(DisplacementResidualContactCriteria::TABLE_IS_INITIALIZED,
true);
395 mOptions.Set(DisplacementResidualContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
406 "name" : "displacement_residual_contact_criteria",
407 "ensure_contact" : false,
408 "print_convergence_criterion" : false,
409 "residual_relative_tolerance" : 1.0e-4,
410 "residual_absolute_tolerance" : 1.0e-9,
411 "rotation_residual_relative_tolerance" : 1.0e-4,
412 "rotation_residual_absolute_tolerance" : 1.0e-9
416 const Parameters base_default_parameters = BaseType::GetDefaultParameters();
418 return default_parameters;
427 return "displacement_residual_contact_criteria";
443 std::string
Info()
const override
445 return "DisplacementResidualContactCriteria";
483 BaseType::AssignSettings(ThisParameters);
486 mDispRatioTolerance = ThisParameters[
"residual_relative_tolerance"].
GetDouble();
487 mDispAbsTolerance = ThisParameters[
"residual_absolute_tolerance"].
GetDouble();
490 mRotRatioTolerance = ThisParameters[
"rotation_residual_relative_tolerance"].
GetDouble();
491 mRotAbsTolerance = ThisParameters[
"rotation_residual_absolute_tolerance"].
GetDouble();
494 mOptions.Set(DisplacementResidualContactCriteria::PRINTING_OUTPUT, ThisParameters[
"print_convergence_criterion"].GetBool());
495 mOptions.Set(DisplacementResidualContactCriteria::TABLE_IS_INITIALIZED,
false);
496 mOptions.Set(DisplacementResidualContactCriteria::ROTATION_DOF_IS_CONSIDERED,
false);
497 mOptions.Set(DisplacementResidualContactCriteria::INITIAL_RESIDUAL_IS_SET,
false);
511 double mDispRatioTolerance;
512 double mDispAbsTolerance;
513 double mDispInitialResidualNorm;
514 double mDispCurrentResidualNorm;
516 double mRotRatioTolerance;
517 double mRotAbsTolerance;
518 double mRotInitialResidualNorm;
519 double mRotCurrentResidualNorm;
528 template<
class TSparseSpace,
class TDenseSpace>
530 template<
class TSparseSpace,
class TDenseSpace>
532 template<
class TSparseSpace,
class TDenseSpace>
534 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
bool IsFree() const
Definition: dof.h:382
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_INFO(label)
Definition: logger.h:250
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