11 #if !defined(KRATOS_LINE_SEARCH_STRATEGY_H_INCLUDED)
12 #define KRATOS_LINE_SEARCH_STRATEGY_H_INCLUDED
45 template<
class TSparseSpace,
82 typename SchemeType::Pointer pScheme,
83 typename BuilderAndSolverType::Pointer pBuilderAndSolver,
84 typename ConvergenceCriterionType::Pointer pConvergenceCriterion,
86 unsigned int MaxIterations = 30,
87 unsigned int LineSearchType = 0)
88 :
NewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pBuilderAndSolver, pConvergenceCriterion, rOptions, MaxIterations), mType(LineSearchType)
92 typename SchemeType::Pointer pScheme,
93 typename LinearSolverType::Pointer pLinearSolver,
94 typename ConvergenceCriterionType::Pointer pConvergenceCriterion,
96 unsigned int MaxIterations = 30,
97 unsigned int LineSearchType = 0)
98 :
NewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pLinearSolver, pConvergenceCriterion, rOptions, MaxIterations), mType(LineSearchType)
206 SystemVectorType b0((*this->
mpb).size());
217 ComputeUpdatedSlope(s1,Dx0);
234 unsigned int iterations = 0;
237 while(fabs(s2)>0.5*fabs(s0_0) && iterations<
max_iterations && fabs(s0)>1
e-5 && fabs(s1)>1
e-5 && (s0*s1)<0) {
243 ComputeUpdatedSlope(s2,Dx0);
249 else if( s2 * s0 < 0 ){
263 KRATOS_INFO(
"LineSearch") <<
"alpha: "<<
alpha<<
" iterations: "<<iterations<<std::endl;
296 SystemVectorType b0((*this->
mpb).size());
307 ComputeUpdatedSlope(s1,Dx0);
317 unsigned int iterations = 0;
326 ComputeUpdatedSlope(s1,Dx0);
336 KRATOS_INFO(
"LineSearch") <<
"alpha: "<<
alpha<<
" iterations: "<<iterations<<std::endl;
369 SystemVectorType b0((*this->
mpb).size());
380 ComputeUpdatedSlope(s1,Dx0);
390 double nabla = s0/s1;
393 unsigned int iterations = 0;
399 alpha = nabla/(0.5*(nabla-sqrt(nabla*(nabla-4.0))));
403 else if( nabla > 0 && nabla <= 2 ){
412 ComputeUpdatedSlope(s2,Dx0);
422 KRATOS_INFO(
"LineSearch") <<
"alpha: "<<
alpha<<
" iterations: "<<iterations<<std::endl;
456 SystemVectorType b0((*this->
mpb).size());
467 ComputeUpdatedSlope(s1,Dx0);
481 unsigned int iterations = 0;
484 while(fabs(s2)>0.5*fabs(s0) && iterations<
max_iterations && fabs(s0)>1
e-5 && fabs(s2)>1
e-5 && (s0*s2)<0) {
489 alpha = 0.5*(nabla+std::sqrt(nabla*(nabla-4.0)));
491 else if( nabla > 0 && nabla <= 2 ){
500 ComputeUpdatedSlope(s2,Dx0);
506 KRATOS_INFO(
"LineSearch") <<
"alpha: "<<
alpha<<
" iterations: "<<iterations<<std::endl;
539 SystemVectorType b0((*this->
mpb).size());
550 ComputeUpdatedSlope(s1,Dx0);
562 unsigned int iterations = 0;
565 while(fabs(s1)>0.8*fabs(s0) && iterations<=
max_iterations && fabs(s1)>1
e-5 && fabs(s0)>1
e-5 && (s0*s1)<0) {
576 ComputeUpdatedSlope(s1,Dx0);
582 KRATOS_INFO(
"LineSearch") <<
"alpha: "<<
alpha<<
" iterations: "<<iterations<<std::endl;
615 SystemVectorType b0((*this->
mpb).size());
638 ComputeResidualNorm(ro);
643 ComputeUpdatedResidualNorm(rh);
648 ComputeUpdatedResidualNorm(rf);
657 double parabola_a = 2*rf + 2*ro - 4*rh;
658 double parabola_b = 4*rh - rf - 3*ro;
663 xmax = -0.5 * parabola_b/parabola_a;
680 KRATOS_INFO(
"LineSearch") <<
"alpha: "<<
alpha<<
" iterations: NO "<<std::endl;
703 TSparseSpace::InplaceMult((*this->
mpDx),-1.0);
705 TSparseSpace::InplaceMult((*this->
mpDx),-1.0);
713 TSparseSpace::SetToZero((*this->
mpb));
724 ComputeSlope(rSlope,rDx);
732 void ComputeResidual()
734 TSparseSpace::SetToZero((*this->
mpb));
742 void ComputeResidualNorm(
double& rNorm)
751 void ComputeUpdatedResidualNorm(
double& rNorm)
754 ComputeResidualNorm(rNorm);
Convergence Criterion base class.
Definition: convergence_criterion.hpp:52
Definition: line_search_strategy.hpp:51
BaseType::BuilderAndSolverType BuilderAndSolverType
Definition: line_search_strategy.hpp:67
~LineSearchSolutionStrategy() override
Destructor.
Definition: line_search_strategy.hpp:102
TLinearSolver LinearSolverType
Definition: line_search_strategy.hpp:71
LineSearchSolutionStrategy(ModelPart &rModelPart, typename SchemeType::Pointer pScheme, typename LinearSolverType::Pointer pLinearSolver, typename ConvergenceCriterionType::Pointer pConvergenceCriterion, Flags &rOptions, unsigned int MaxIterations=30, unsigned int LineSearchType=0)
Definition: line_search_strategy.hpp:91
BaseType::LocalFlagType LocalFlagType
Definition: line_search_strategy.hpp:61
BaseType::SystemVectorType SystemVectorType
Definition: line_search_strategy.hpp:63
void Update() override
Operation to update the solution ... if it is not called a trivial updater is used in which the value...
Definition: line_search_strategy.hpp:136
BaseType::SchemeType SchemeType
Definition: line_search_strategy.hpp:69
NewtonRaphsonStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: line_search_strategy.hpp:59
KRATOS_CLASS_POINTER_DEFINITION(LineSearchSolutionStrategy)
LineSearchSolutionStrategy(ModelPart &rModelPart, typename SchemeType::Pointer pScheme, typename BuilderAndSolverType::Pointer pBuilderAndSolver, typename ConvergenceCriterionType::Pointer pConvergenceCriterion, Flags &rOptions, unsigned int MaxIterations=30, unsigned int LineSearchType=0)
Constructor.
Definition: line_search_strategy.hpp:81
ConvergenceCriterion< TSparseSpace, TDenseSpace > ConvergenceCriterionType
Definition: line_search_strategy.hpp:65
SchemeType::Pointer mpScheme
Definition: linear_strategy.hpp:427
SystemVectorPointerType mpDx
The pointer to the builder and solver employed.
Definition: linear_strategy.hpp:430
void Update() override
Here the database is updated.
Definition: linear_strategy.hpp:483
BuilderAndSolverType::Pointer mpBuilderAndSolver
The pointer to the time scheme employed.
Definition: linear_strategy.hpp:428
SystemVectorPointerType mpb
The incremement in the solution.
Definition: linear_strategy.hpp:431
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This is the base Newton Raphson strategy.
Definition: newton_raphson_strategy.hpp:58
BaseType::SystemVectorType SystemVectorType
Definition: newton_raphson_strategy.hpp:84
Solution Buider and Solver base class.
Definition: solution_builder_and_solver.hpp:63
Solution scheme base class.
Definition: solution_scheme.hpp:54
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solution_strategy.hpp:243
Solver local flags class definition.
Definition: solution_local_flags.hpp:48
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO(label)
Definition: logger.h:250
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
double Dot(SparseSpaceType &dummy, SparseSpaceType::VectorType &rX, SparseSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:85
void Assign(const Expression &rExpression, const IndexType EntityIndex, const IndexType EntityDataBeginIndex, TDataType &rValue, std::index_sequence< TIndex... >)
Definition: variable_expression_data_io.cpp:41
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
int max_iterations
Definition: ProjectParameters.py:53
float xmax
Definition: cube_mesher.py:743
float xmin
Definition: cube_mesher.py:742
alpha
Definition: generate_convection_diffusion_explicit_element.py:113
double precision, dimension(3, 3), public delta
Definition: TensorModule.f:16
e
Definition: run_cpp_mpi_tests.py:31