13 #if !defined(KRATOS_FEMDEM_RESIDUAL_CRITERIA )
14 #define KRATOS_FEMDEM_RESIDUAL_CRITERIA
53 template<
class TSparseSpace,
94 if (Settings.
Has(
"residual_absolute_tolerance")) {
95 mAlwaysConvergedNorm = Settings[
"residual_absolute_tolerance"].
GetDouble();
96 }
else if (Settings.
Has(
"absolute_tolerance")) {
97 mAlwaysConvergedNorm = Settings[
"absolute_tolerance"].
GetDouble();
99 KRATOS_WARNING(
"FemDemResidualCriteria") <<
"residual_absolute_tolerance or absolute_tolerance nor defined on settings. Using default 1.0e-9" << std::endl;
100 mAlwaysConvergedNorm = 1.0e-9;
102 if (Settings.
Has(
"residual_relative_tolerance")) {
103 mRatioTolerance = Settings[
"residual_relative_tolerance"].
GetDouble();
104 }
else if (Settings.
Has(
"relative_tolerance")) {
105 mRatioTolerance = Settings[
"relative_tolerance"].
GetDouble();
107 KRATOS_WARNING(
"FemDemResidualCriteria") <<
"residual_relative_tolerance or relative_tolerance nor defined on settings. Using default 1.0e-4" << std::endl;
108 mRatioTolerance = 1.0e-4;
110 if (Settings.
Has(
"max_iteration")) {
111 mMaxIterations = Settings[
"max_iteration"].
GetInt();
119 TDataType NewRatioTolerance,
122 mRatioTolerance(NewRatioTolerance),
123 mAlwaysConvergedNorm(AlwaysConvergedNorm)
131 ,mRatioTolerance(rOther.mRatioTolerance)
132 ,mInitialResidualNorm(rOther.mInitialResidualNorm)
133 ,mCurrentResidualNorm(rOther.mCurrentResidualNorm)
134 ,mAlwaysConvergedNorm(rOther.mAlwaysConvergedNorm)
135 ,mReferenceDispNorm(rOther.mReferenceDispNorm)
166 KRATOS_INFO(
"") <<
"___________________________________________________________________" << std::endl;
167 KRATOS_INFO(
"") <<
"| ITER | RATIO | ABS_NORM | CONVERGED |" << std::endl;
176 if(mInitialResidualNorm < std::numeric_limits<TDataType>::epsilon()) {
179 ratio = mCurrentResidualNorm/mInitialResidualNorm;
183 const TDataType absolute_norm = (mCurrentResidualNorm / float_size_residual);
188 if (ratio <= mRatioTolerance || absolute_norm < mAlwaysConvergedNorm) {
190 std::cout <<
"| " << rModelPart.
GetProcessInfo()[NL_ITERATION_NUMBER] <<
" | "
191 << std::scientific << ratio <<
" | "
192 << absolute_norm <<
" |" <<
" TRUE |"<< std::endl;
194 std::cout <<
"| " << rModelPart.
GetProcessInfo()[NL_ITERATION_NUMBER] <<
" | "
195 << std::scientific << ratio <<
" | "
196 << absolute_norm <<
" |" <<
" TRUE |"<< std::endl;
201 std::cout <<
"| " << rModelPart.
GetProcessInfo()[NL_ITERATION_NUMBER] <<
" | "
202 << std::scientific << ratio <<
" | "
203 << absolute_norm <<
" |" <<
" FALSE |"<< std::endl;
205 std::cout <<
"| " << rModelPart.
GetProcessInfo()[NL_ITERATION_NUMBER] <<
" | "
206 << std::scientific << ratio <<
" | "
207 << absolute_norm <<
" |" <<
" FALSE |"<< std::endl;
209 if (rModelPart.
GetProcessInfo()[NL_ITERATION_NUMBER] == mMaxIterations) {
210 KRATOS_INFO(
"") <<
" ATTENTION! SOLUTION STEP NOT CONVERGED AFTER " << mMaxIterations <<
"ITERATIONS" << std::endl;
248 mActiveDofs.resize(rDofSet.
size());
250 #pragma omp parallel for
251 for(
int i=0; i<static_cast<int>(mActiveDofs.size()); ++
i) {
252 mActiveDofs[
i] =
true;
255 #pragma omp parallel for
256 for (
int i = 0; i<static_cast<int>(rDofSet.
size()); ++
i) {
257 const auto it_dof = rDofSet.
begin() +
i;
258 if (it_dof->IsFixed()) {
259 mActiveDofs[it_dof->EquationId()] =
false;
264 for (
const auto& r_dof : r_mpc.GetMasterDofsVector()) {
265 mActiveDofs[r_dof->EquationId()] =
false;
267 for (
const auto& r_dof : r_mpc.GetSlaveDofsVector()) {
268 mActiveDofs[r_dof->EquationId()] =
false;
294 KRATOS_INFO(
"") <<
"|_____________|________________|________________|_________________|" << std::endl;
315 std::string
Info()
const override
317 return "FemDemResidualCriteria";
377 const auto it_dof_begin = rDofSet.
begin();
378 const int number_of_dof =
static_cast<int>(rDofSet.
size());
382 #pragma omp parallel for firstprivate(residual_dof_value) reduction(+:residual_solution_norm, dof_num)
383 for (
int i = 0;
i < number_of_dof;
i++) {
384 auto it_dof = it_dof_begin +
i;
386 const IndexType dof_id = it_dof->EquationId();
388 if (mActiveDofs[dof_id]) {
390 residual_solution_norm += std::pow(residual_dof_value, 2);
395 #pragma omp parallel for firstprivate(residual_dof_value) reduction(+:residual_solution_norm, dof_num)
396 for (
int i = 0;
i < number_of_dof;
i++) {
397 auto it_dof = it_dof_begin +
i;
399 if (!it_dof->IsFixed()) {
400 const IndexType dof_id = it_dof->EquationId();
402 residual_solution_norm += std::pow(residual_dof_value, 2);
409 rResidualSolutionNorm = std::sqrt(residual_solution_norm);
444 std::vector<bool> mActiveDofs;
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
bool mActualizeRHSIsNeeded
Definition: convergence_criteria.h:447
TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: convergence_criteria.h:72
virtual void Initialize(ModelPart &rModelPart)
This function initialize the convergence criteria.
Definition: convergence_criteria.h:276
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
This is a convergence criteria that employes the residual as criteria.
Definition: femdem_residual_criteria.h:58
virtual void CalculateResidualNorm(ModelPart &rModelPart, TDataType &rResidualSolutionNorm, SizeType &rDofNum, DofsArrayType &rDofSet, const TSystemVectorType &rb)
This method computes the norm of the residual.
Definition: femdem_residual_criteria.h:363
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: femdem_residual_criteria.h:327
KRATOS_CLASS_POINTER_DEFINITION(FemDemResidualCriteria)
std::string Info() const override
Turn back information as a string.
Definition: femdem_residual_criteria.h:315
FemDemResidualCriteria(FemDemResidualCriteria const &rOther)
Definition: femdem_residual_criteria.h:129
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: femdem_residual_criteria.h:321
std::size_t SizeType
Definition of the size type.
Definition: femdem_residual_criteria.h:84
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
Criterias that need to be called after getting the solution.
Definition: femdem_residual_criteria.h:157
ConvergenceCriteria< TSparseSpace, TDenseSpace > BaseType
The definition of the base ConvergenceCriteria.
Definition: femdem_residual_criteria.h:66
BaseType::TSystemVectorType TSystemVectorType
The dense vector type.
Definition: femdem_residual_criteria.h:78
FemDemResidualCriteria(TDataType NewRatioTolerance, TDataType AlwaysConvergedNorm)
Definition: femdem_residual_criteria.h:118
void Initialize(ModelPart &rModelPart) override
This function initialize the convergence criteria.
Definition: femdem_residual_criteria.h:223
~FemDemResidualCriteria() override
Definition: femdem_residual_criteria.h:141
std::size_t IndexType
Definition of the IndexType.
Definition: femdem_residual_criteria.h:81
BaseType::DofsArrayType DofsArrayType
The dofs array type.
Definition: femdem_residual_criteria.h:72
BaseType::TDataType TDataType
The data type.
Definition: femdem_residual_criteria.h:69
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function initializes the solution step.
Definition: femdem_residual_criteria.h:236
void FinalizeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const TSystemMatrixType &rA, const TSystemVectorType &rDx, const TSystemVectorType &rb) override
This function finalizes the solution step.
Definition: femdem_residual_criteria.h:285
BaseType::TSystemMatrixType TSystemMatrixType
The sparse matrix type.
Definition: femdem_residual_criteria.h:75
FemDemResidualCriteria(Kratos::Parameters Settings)
Definition: femdem_residual_criteria.h:91
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MasterSlaveConstraintContainerType & MasterSlaveConstraints(IndexType ThisIndex=0)
Definition: model_part.h:654
SizeType NumberOfMasterSlaveConstraints(IndexType ThisIndex=0) const
Definition: model_part.h:649
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
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
bool Has(const std::string &rEntry) const
This method checks if the Parameter contains a certain entry.
Definition: kratos_parameters.cpp:520
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
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
#define KRATOS_INFO(label)
Definition: logger.h:250
#define KRATOS_WARNING(label)
Definition: logger.h:265
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
integer i
Definition: TensorModule.f:17