54 template<
class TSparseSpace,
167 return Kratos::make_shared<ClassType>(ThisParameters);
190 const TDataType approx_zero_tolerance = std::numeric_limits<TDataType>::epsilon();
194 const TDataType final_correction_norm = CalculateFinalCorrectionNorm(size_solution, rDofSet, rDx, rModelPart);
198 CalculateReferenceNorm(rDofSet, rModelPart);
200 KRATOS_WARNING(
"DisplacementCriteria") <<
"NaN norm is detected. Setting reference to convergence criteria" << std::endl;
204 if(final_correction_norm < approx_zero_tolerance) {
212 const TDataType absolute_norm = (final_correction_norm/std::sqrt(float_size_solution));
220 KRATOS_INFO_IF(
"DISPLACEMENT CRITERION", has_achieved_convergence && this->
GetEchoLevel() > 0 && rank == 0) <<
"Convergence is achieved" << std::endl;
221 return has_achieved_convergence;
282 return "displacement_criteria";
293 "name" : "displacement_criteria",
294 "displacement_relative_tolerance" : 1.0e-4,
295 "displacement_absolute_tolerance" : 1.0e-9
301 return default_parameters;
317 std::string
Info()
const override
319 return "DisplacementCriteria";
410 bool IsFreeAndLocalDof(
415 if constexpr (!TSparseSpace::IsDistributedSpace()) {
416 return rDof.IsFree();
418 return (rDof.IsFree() && (rDof.GetSolutionStepValue(PARTITION_INDEX) == Rank));
429 void CalculateReferenceNorm(
431 ModelPart& rModelPart
435 const auto& r_data_communicator = rModelPart.GetCommunicator().GetDataCommunicator();
438 const int rank = r_data_communicator.Rank();
443 const TDataType reference_disp_norm = block_for_each<SumReduction<TDataType>>(rDofSet, TLS(), [
this, &rank](
auto& rDof, TLS& rTLS) {
444 if (ClassType::IsFreeAndLocalDof(rDof, rank)) {
445 rTLS.dof_value = rDof.GetSolutionStepValue();
446 return std::pow(rTLS.dof_value, 2);
466 ModelPart& rModelPart
470 const auto& r_data_communicator = rModelPart.GetCommunicator().GetDataCommunicator();
473 const int rank = r_data_communicator.Rank();
477 unsigned int dof_num = 0;
480 using CustomReduction = CombinedReduction<SumReduction<TDataType>,SumReduction<unsigned int>>;
486 std::tie(final_correction_norm, dof_num) = block_for_each<CustomReduction>(rDofSet, TLS(), [
this, &rDx, &rank](
auto& rDof, TLS& rTLS) {
487 if (this->IsFreeAndLocalDof(rDof, rank)) {
489 return std::make_tuple(std::pow(rTLS.variation_dof_value, 2), 1);
495 rDofNum =
static_cast<SizeType>(r_data_communicator.SumAll(dof_num));
496 return std::sqrt(r_data_communicator.SumAll(final_correction_norm));
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
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
virtual Parameters GetDefaultParameters() const
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: convergence_criteria.h:384
TSparseSpace::DataType TDataType
Data type definition.
Definition: convergence_criteria.h:70
TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: convergence_criteria.h:74
virtual void FinalizeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb)
This function finalizes the solution step.
Definition: convergence_criteria.h:337
bool mConvergenceCriteriaIsInitialized
This "flag" is set in order to know if it is necessary to actualize the RHS.
Definition: convergence_criteria.h:448
virtual void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb)
This function initializes the solution step.
Definition: convergence_criteria.h:299
virtual void AssignSettings(const Parameters ThisParameters)
This method assigns settings to member variables.
Definition: convergence_criteria.h:479
virtual int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
This is a convergence criteria that considers the increment on the solution as criteria.
Definition: displacement_criteria.h:59
TDataType mReferenceDispNorm
The absolute value threshold for the norm of the residual.
Definition: displacement_criteria.h:351
DisplacementCriteria & operator=(DisplacementCriteria const &rOther)=delete
Deleted assignment operator.
DisplacementCriteria(DisplacementCriteria const &rOther)
Copy constructor.
Definition: displacement_criteria.h:137
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function initializes the solution step.
Definition: displacement_criteria.h:246
std::string Info() const override
Turn back information as a string.
Definition: displacement_criteria.h:317
typename BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: displacement_criteria.h:89
KRATOS_CLASS_POINTER_DEFINITION(DisplacementCriteria)
Pointer definition of DisplacementCriteria.
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: displacement_criteria.h:280
DisplacementCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: displacement_criteria.h:111
void FinalizeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function finalizes the solution step.
Definition: displacement_criteria.h:265
DisplacementCriteria(TDataType NewRatioTolerance, TDataType AlwaysConvergedNorm)
Constructor 2 arguments.
Definition: displacement_criteria.h:124
TDataType mRatioTolerance
Definition: displacement_criteria.h:347
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: displacement_criteria.h:289
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: displacement_criteria.h:231
TSparseSpace SparseSpaceType
The definition of the sparse space type.
Definition: displacement_criteria.h:74
std::size_t SizeType
Definition of the size type.
Definition: displacement_criteria.h:95
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: displacement_criteria.h:329
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: displacement_criteria.h:365
typename Node::DofType DofType
The definition of the DoF data type.
Definition: displacement_criteria.h:83
BaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: displacement_criteria.h:165
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Compute relative and absolute error.
Definition: displacement_criteria.h:179
typename BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: displacement_criteria.h:80
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: displacement_criteria.h:323
TDataType mAlwaysConvergedNorm
The ratio threshold for the norm of the residual.
Definition: displacement_criteria.h:349
typename BaseType::TDataType TDataType
The data type.
Definition: displacement_criteria.h:77
DisplacementCriteria()
Default constructor.
Definition: displacement_criteria.h:102
~DisplacementCriteria() override
Destructor.
Definition: displacement_criteria.h:148
std::size_t IndexType
Definition of the IndexType.
Definition: displacement_criteria.h:92
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
Dof< double > DofType
Dof type.
Definition: node.h:83
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
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
static TDataType GetValue(const VectorType &x, std::size_t I)
Definition: ublas_space.h:896
static IndexType Size(VectorType const &rV)
return size of vector rV
Definition: ublas_space.h:190
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
#define KRATOS_WARNING(label)
Definition: logger.h:265
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21