55 template<
class TSparseSpace,
173 return Kratos::make_shared<ClassType>(ThisParameters);
219 KRATOS_INFO_IF(
"RESIDUAL CRITERION", has_achieved_convergence && this->
GetEchoLevel() > 0 && rank == 0) <<
"Convergence is achieved" << std::endl;
220 return has_achieved_convergence;
280 "name" : "residual_criteria",
281 "residual_absolute_tolerance" : 1.0e-4,
282 "residual_relative_tolerance" : 1.0e-9
288 return default_parameters;
297 return "residual_criteria";
313 std::string
Info()
const override
315 return "ResidualCriteria";
392 const IndexType dof_id = rDof.EquationId();
393 if constexpr (!TSparseSpace::IsDistributedSpace()) {
414 if constexpr (!TSparseSpace::IsDistributedSpace()) {
415 return rDof.IsFree();
417 return (rDof.IsFree() && (rDof.GetSolutionStepValue(PARTITION_INDEX) == Rank));
442 const int rank = r_data_communicator.
Rank();
446 unsigned int dof_num = 0;
452 struct TLS {
TDataType residual_dof_value{};};
456 std::tie(residual_solution_norm, dof_num) = block_for_each<CustomReduction>(rDofSet, TLS(), [
this, &rb, &rank](
auto& rDof, TLS& rTLS) {
459 return std::make_tuple(std::pow(rTLS.residual_dof_value, 2), 1);
465 std::tie(residual_solution_norm, dof_num) = block_for_each<CustomReduction>(rDofSet, TLS(), [
this, &rb, &rank](
auto& rDof, TLS& rTLS) {
468 return std::make_tuple(std::pow(rTLS.residual_dof_value, 2), 1);
475 rDofNum =
static_cast<SizeType>(r_data_communicator.SumAll(dof_num));
476 rResidualSolutionNorm = std::sqrt(r_data_communicator.SumAll(residual_solution_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
bool mActualizeRHSIsNeeded
Definition: convergence_criteria.h:447
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
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 class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
SizeType NumberOfMasterSlaveConstraints(IndexType ThisIndex=0) const
Definition: model_part.h:649
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
This is a convergence criteria that considers the residual as criteria.
Definition: residual_criteria.h:60
std::size_t SizeType
Definition of the size type.
Definition: residual_criteria.h:93
KRATOS_CLASS_POINTER_DEFINITION(ResidualCriteria)
Pointer definition of ResidualCriteria.
virtual void CalculateResidualNorm(ModelPart &rModelPart, TDataType &rResidualSolutionNorm, SizeType &rDofNum, DofsArrayType &rDofSet, const TSystemVectorType &rb)
This method computes the norm of the residual.
Definition: residual_criteria.h:430
std::size_t IndexType
Definition of the IndexType.
Definition: residual_criteria.h:90
ResidualCriteria(ResidualCriteria const &rOther)
Copy constructor.
Definition: residual_criteria.h:138
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residual_criteria.h:483
void FinalizeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function finalizes the solution step.
Definition: residual_criteria.h:261
std::string Info() const override
Turn back information as a string.
Definition: residual_criteria.h:313
typename BaseType::TDataType TDataType
The data type.
Definition: residual_criteria.h:75
ResidualCriteria(Kratos::Parameters ThisParameters)
Default constructor. (with parameters)
Definition: residual_criteria.h:109
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Criterion that need to be called after getting the solution.
Definition: residual_criteria.h:186
BaseType::Pointer Create(Parameters ThisParameters) const override
Create method.
Definition: residual_criteria.h:171
TDataType mRatioTolerance
Definition: residual_criteria.h:343
ResidualCriteria & operator=(ResidualCriteria const &rOther)=delete
Deleted assignment operator.
bool IsFreeAndLocalDof(const DofType &rDof, const int Rank)
Check if a Degree of Freedom (Dof) is free.
Definition: residual_criteria.h:409
IndexType mInitialDoFId
This vector contains the dofs that are active.
Definition: residual_criteria.h:355
ResidualCriteria()
Default constructor.
Definition: residual_criteria.h:100
TDataType mAlwaysConvergedNorm
The current norm of the residual.
Definition: residual_criteria.h:349
TDataType mInitialResidualNorm
The ratio threshold for the norm of the residual.
Definition: residual_criteria.h:345
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residual_criteria.h:319
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function initializes the solution step.
Definition: residual_criteria.h:234
~ResidualCriteria() override
Destructor.
Definition: residual_criteria.h:154
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residual_criteria.h:295
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residual_criteria.h:325
ResidualCriteria(TDataType NewRatioTolerance, TDataType AlwaysConvergedNorm)
Constructor 2 arguments.
Definition: residual_criteria.h:124
std::vector< int > mActiveDofs
The norm at the beginning of the iterations.
Definition: residual_criteria.h:353
TDataType mReferenceDispNorm
The absolute value threshold for the norm of the residual.
Definition: residual_criteria.h:351
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residual_criteria.h:276
virtual void ComputeActiveDofs(ModelPart &rModelPart, const ModelPart::DofsArrayType &rDofSet)
This method computes the active dofs.
Definition: residual_criteria.h:370
TDataType mCurrentResidualNorm
The reference norm of the residual.
Definition: residual_criteria.h:347
bool IsActiveAndLocalDof(const DofType &rDof, const int Rank)
Check if a Degree of Freedom (Dof) is active.
Definition: residual_criteria.h:387
typename Node::DofType DofType
The definition of the DoF data type.
Definition: residual_criteria.h:81
utility function to do a sum reduction
Definition: reduction_utilities.h:68
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
void ComputeActiveDofs(ModelPart &rModelPart, std::vector< int > &rActiveDofs, const ModelPart::DofsArrayType &rDofSet)
This method computes the active dofs.
Definition: constraint_utilities.cpp:26
static double max(double a, double b)
Definition: GeometryFunctions.h:79
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
Parameters GetValue(Parameters &rParameters, const std::string &rEntry)
Definition: add_kratos_parameters_to_python.cpp:53
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Definition: reduction_utilities.h:310