10 #if !defined(KRATOS_RESIDUAL_CRITERION_H_INCLUDED )
11 #define KRATOS_RESIDUAL_CRITERION_H_INCLUDED
49 template<
class TSparseSpace,
class TDenseSpace>
83 :
BaseType(), mRatioTolerance(RatioTolerance), mAbsoluteTolerance(AbsoluteTolerance)
85 mpScalarVariable =
nullptr;
86 mpVectorVariable =
nullptr;
87 this->
Set(LocalFlagType::SUPPLIED_DOF,
false);
94 :
BaseType(), mRatioTolerance(RatioTolerance), mAbsoluteTolerance(AbsoluteTolerance)
96 mpScalarVariable = &rScalarVariable;
97 mpVectorVariable =
nullptr;
98 this->
Set(LocalFlagType::SUPPLIED_DOF,
true);
105 :
BaseType(), mRatioTolerance(RatioTolerance), mAbsoluteTolerance(AbsoluteTolerance)
107 mpVectorVariable = &rVectorVariable;
108 mpScalarVariable =
nullptr;
109 this->
Set(LocalFlagType::SUPPLIED_DOF,
true);
115 ,mRatioTolerance(rOther.mRatioTolerance)
116 ,mAbsoluteTolerance(rOther.mAbsoluteTolerance)
117 ,mInitialResidualNorm(rOther.mInitialResidualNorm)
118 ,mpScalarVariable(rOther.mpScalarVariable)
119 ,mpVectorVariable(rOther.mpVectorVariable)
142 std::size_t size = 0;
144 if( this->
IsNot(LocalFlagType::INITIALIZED) )
146 size = CalculateResidualNorm(rDofSet,rb,mInitialResidualNorm);
147 this->
Set(LocalFlagType::INITIALIZED,
true);
152 size = CalculateResidualNorm(rDofSet,rb,CurrentResidualNorm);
155 KRATOS_WARNING(
"") << GetDofName() <<
" Residual Dofs vector has size: " << size << std::endl;
159 if(mInitialResidualNorm == 0.00)
165 ratio = CurrentResidualNorm/mInitialResidualNorm;
168 const DataType absolute_norm = (CurrentResidualNorm/
static_cast<DataType>(size));
174 std::cout <<
"RESIDUAL (" << GetDofName() <<
") ["<<rModelPart.
GetProcessInfo()[NL_ITERATION_NUMBER]<<
"] :: Ratio = "<< ratio <<
"; Norm = " << absolute_norm <<std::endl;
181 if (ratio <= mRatioTolerance || absolute_norm < mAbsoluteTolerance)
187 std::cout <<
"Convergence is achieved" << std::endl;
210 this->
Set(LocalFlagType::INITIALIZED,
false);
293 std::size_t size = 0;
296 if( this->
Is(CriterionLocalFlags::SUPPLIED_DOF) ){
298 if( mpVectorVariable !=
nullptr ){
305 if(CheckVectorDof(i_dof))
307 temp = rb[i_dof->EquationId()];
314 else if( mpScalarVariable !=
nullptr ){
322 if(i_dof->GetVariable() == *mpScalarVariable)
324 temp = rb[i_dof->EquationId()];
333 KRATOS_ERROR <<
" No variable dof supplied to the convergence criterion " << std::endl;
336 rResidualNorm = std::sqrt(rResidualNorm);
352 const std::string& variable_name = mpVectorVariable->Name();
353 const Variable<double>& var_x = KratosComponents<Variable<double> >::Get(variable_name+
"_X");
354 const Variable<double>& var_y = KratosComponents<Variable<double> >::Get(variable_name+
"_Y");
355 const Variable<double>& var_z = KratosComponents<Variable<double> >::Get(variable_name+
"_Z");
357 if( rDofIter->GetVariable() == var_x || rDofIter->GetVariable() == var_y || rDofIter->GetVariable() == var_z )
365 std::string GetDofName()
367 std::string name =
"DOFS";
369 if( this->
Is(CriterionLocalFlags::SUPPLIED_DOF) ){
371 if( mpVectorVariable !=
nullptr ){
372 name = mpVectorVariable->Name();
374 else if( mpScalarVariable !=
nullptr ){
375 name = mpScalarVariable->Name();
virtual int MyPID() const
Definition: communicator.cpp:91
Convergence Criterion base class.
Definition: convergence_criterion.hpp:52
TSparseSpace::DataType DataType
Definition: convergence_criterion.hpp:58
int GetEchoLevel()
Definition: convergence_criterion.hpp:109
TSparseSpace::MatrixType SystemMatrixType
Definition: convergence_criterion.hpp:60
TSparseSpace::VectorType SystemVectorType
Definition: convergence_criterion.hpp:61
Solver local flags class definition.
Definition: solution_local_flags.hpp:74
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool Is(Flags const &rOther) const
Definition: flags.h:274
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
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
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
This convergence criteria checks the residual.
Definition: residual_criterion.hpp:51
BaseType::SystemMatrixType SystemMatrixType
Definition: residual_criterion.hpp:61
BaseType::DofsArrayType DofsArrayType
Definition: residual_criterion.hpp:60
BaseType::SystemVectorType SystemVectorType
Definition: residual_criterion.hpp:62
Variable< double > VectorComponentType
Definition: residual_criterion.hpp:65
BaseType::DataType DataType
Definition: residual_criterion.hpp:59
ResidualCriterion(ResidualCriterion const &rOther)
Copy constructor.
Definition: residual_criterion.hpp:113
BaseType::LocalFlagType LocalFlagType
Definition: residual_criterion.hpp:58
const VariableVectorType * VariableVectorPointer
Definition: residual_criterion.hpp:68
ResidualCriterion(const VariableVectorType &rVectorVariable, DataType RatioTolerance, DataType AbsoluteTolerance)
Constructor.
Definition: residual_criterion.hpp:102
ResidualCriterion(const VariableScalarType &rScalarVariable, DataType RatioTolerance, DataType AbsoluteTolerance)
Constructor.
Definition: residual_criterion.hpp:91
Variable< double > VariableScalarType
Definition: residual_criterion.hpp:67
ConvergenceCriterion< TSparseSpace, TDenseSpace > BaseType
Definition: residual_criterion.hpp:57
KRATOS_CLASS_POINTER_DEFINITION(ResidualCriterion)
Pointer definition of ResidualCriterion.
bool PostCriteria(ModelPart &rModelPart, DofsArrayType &rDofSet, const SystemMatrixType &rA, const SystemVectorType &rDx, const SystemVectorType &rb) override
Definition: residual_criterion.hpp:132
ResidualCriterion(DataType RatioTolerance, DataType AbsoluteTolerance)
Constructor.
Definition: residual_criterion.hpp:81
const VariableScalarType * VariableScalarPointer
Definition: residual_criterion.hpp:69
void InitializeSolutionStep(ModelPart &rModelPart, DofsArrayType &rDofSet, const SystemMatrixType &rA, const SystemVectorType &rDx, const SystemVectorType &rb) override
Definition: residual_criterion.hpp:204
std::vector< Variable< double > > ComponentVariableVector
Definition: residual_criterion.hpp:71
Variable< VectorType > VariableVectorType
Definition: residual_criterion.hpp:66
~ResidualCriterion() override
Destructor.
Definition: residual_criterion.hpp:124
array_1d< double, 3 > VectorType
Definition: residual_criterion.hpp:64
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_WARNING(label)
Definition: logger.h:265
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
float temp
Definition: rotating_cone.py:85