14 #if !defined(KRATOS_LINE_SEARCH_STRATEGY )
15 #define KRATOS_LINE_SEARCH_STRATEGY
78 template<
class TSparseSpace,
158 typename TSchemeType::Pointer pScheme,
159 typename TLinearSolver::Pointer pNewLinearSolver,
160 typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
161 int MaxIterations = 30,
162 bool CalculateReactions =
false,
163 bool ReformDofSetAtEachStep =
false,
165 ) :
BaseType(rModelPart, pScheme, pNewLinearSolver,pNewConvergenceCriteria,MaxIterations,CalculateReactions,ReformDofSetAtEachStep,
MoveMeshFlag)
185 typename TSchemeType::Pointer pScheme,
186 typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
187 typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
188 int MaxIterations = 30,
189 bool CalculateReactions =
false,
190 bool ReformDofSetAtEachStep =
false,
192 ) :
BaseType(rModelPart, pScheme, pNewConvergenceCriteria, pNewBuilderAndSolver, MaxIterations, CalculateReactions, ReformDofSetAtEachStep,
MoveMeshFlag)
215 typename TLinearSolver::Pointer pNewLinearSolver,
218 int MaxIterations = 30,
219 bool CalculateReactions = false,
220 bool ReformDofSetAtEachStep = false,
222 ) :
BaseType(rModelPart, pScheme, pNewLinearSolver,pNewConvergenceCriteria,pNewBuilderAndSolver,MaxIterations,CalculateReactions,ReformDofSetAtEachStep,
MoveMeshFlag)
239 typename TSchemeType::Pointer pScheme,
240 typename TLinearSolver::Pointer pNewLinearSolver,
241 typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
260 typename TSchemeType::Pointer pScheme,
261 typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
262 typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
294 typename SolvingStrategyType::Pointer
Create(
299 return Kratos::make_shared<ClassType>(rModelPart, ThisParameters);
310 "name" : "line_search_strategy",
311 "max_line_search_iterations" : 5,
312 "first_alpha_value" : 0.5,
313 "second_alpha_value" : 1.0,
316 "line_search_tolerance" : 0.5
322 return default_parameters;
331 return "line_search_strategy";
348 std::string
Info()
const override
350 return "LineSearchStrategy";
381 int mMaxLineSearchIterations;
382 double mFirstAlphaValue;
383 double mSecondAlphaValue;
386 double mLineSearchTolerance;
444 typename TSchemeType::Pointer pScheme = this->
GetScheme();
447 TSystemVectorType aux(Dx);
449 double x1 = mFirstAlphaValue;
450 double x2 = mSecondAlphaValue;
452 bool converged =
false;
454 double xprevious = 0.0;
462 TSparseSpace::SetToZero(
b);
466 double rmax = std::abs(r1);
467 while(!converged && it < mMaxLineSearchIterations) {
475 TSparseSpace::SetToZero(
b);
482 double rmin =
std::min(std::abs(r1),std::abs(r2));
486 if(std::abs(r1 - r2) > 1
e-10)
487 x = (r1*
x2 - r2*
x1)/(r1 - r2);
491 }
else if(
x > mMaxAlpha) {
499 if(rmin < mLineSearchTolerance*rmax) {
500 KRATOS_INFO(
"LineSearchStrategy") <<
"LINE SEARCH it " << it <<
" coeff = " <<
x <<
" r1 = " << r1 <<
" r2 = " << r2 << std::endl;
507 TSparseSpace::SetToZero(
b);
511 KRATOS_INFO(
"LineSearchStrategy") <<
"LINE SEARCH it " << it <<
" coeff = " <<
x <<
" rf = " << rf <<
" r1 = " << r1 <<
" r2 = " << r2 << std::endl;
514 if(std::abs(rf) < rmax*mLineSearchTolerance) {
518 if(std::abs(r1)>std::abs(r2)) {
533 TSparseSpace::SetToZero(
b);
543 mMaxLineSearchIterations = ThisParameters[
"max_line_search_iterations"].
GetInt();
544 mFirstAlphaValue = ThisParameters[
"first_alpha_value"].
GetDouble();
545 mSecondAlphaValue = ThisParameters[
"second_alpha_value"].
GetDouble();
546 mMinAlpha = ThisParameters[
"min_alpha"].
GetDouble();
547 mMaxAlpha = ThisParameters[
"max_alpha"].
GetDouble();
548 mLineSearchTolerance = ThisParameters[
"line_search_tolerance"].
GetDouble();
560 const double MaxIterations,
561 const bool ReformDofSetAtEachStep,
562 const bool CalculateReactions
565 rDefaultSettings[
"max_iteration"].
SetInt(MaxIterations);
566 rDefaultSettings[
"reform_dofs_at_each_step"].
SetBool(ReformDofSetAtEachStep);
567 rDefaultSettings[
"compute_reactions"].
SetBool(CalculateReactions);
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
BaseType::TSystemVectorType TSystemVectorType
Definition: implicit_solving_strategy.h:72
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
Short class definition.
Definition: line_search_strategy.h:84
ResidualBasedNewtonRaphsonStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: line_search_strategy.h:94
BaseType::TSystemMatrixType TSystemMatrixType
Definition: line_search_strategy.h:109
BaseType::TSystemVectorType TSystemVectorType
Definition: line_search_strategy.h:111
TSparseSpace SparseSpaceType
Definition: line_search_strategy.h:101
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: line_search_strategy.h:306
SolvingStrategy< TSparseSpace, TDenseSpace > SolvingStrategyType
Definition: line_search_strategy.h:93
BaseType::DofsArrayType DofsArrayType
Definition: line_search_strategy.h:107
std::string Info() const override
Turn back information as a string.
Definition: line_search_strategy.h:348
KRATOS_CLASS_POINTER_DEFINITION(LineSearchStrategy)
LineSearchStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, int MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Constructor specifying the builder and solver.
Definition: line_search_strategy.h:183
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: line_search_strategy.h:113
BaseType::TSchemeType TSchemeType
Definition: line_search_strategy.h:103
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: line_search_strategy.h:360
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: line_search_strategy.h:540
SolvingStrategyType::Pointer Create(ModelPart &rModelPart, Parameters ThisParameters) const override
Create method.
Definition: line_search_strategy.h:294
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: line_search_strategy.h:97
LineSearchStrategy()
Default constructor.
Definition: line_search_strategy.h:128
LineSearchStrategy< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
Definition: line_search_strategy.h:95
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: line_search_strategy.h:115
LineSearchStrategy(const LineSearchStrategy &Other)
Definition: line_search_strategy.h:593
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: line_search_strategy.h:354
LineSearchStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, int MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Definition: line_search_strategy.h:156
void UpdateDatabase(TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b, const bool MoveMesh) override
Definition: line_search_strategy.h:437
void OverrideDefaultSettingsWithParameters(Parameters &rDefaultSettings, const double MaxIterations, const bool ReformDofSetAtEachStep, const bool CalculateReactions)
This method overrides the default settings with user provided parameters.
Definition: line_search_strategy.h:558
ConvergenceCriteria< TSparseSpace, TDenseSpace > TConvergenceCriteriaType
Definition: line_search_strategy.h:88
LineSearchStrategy(ModelPart &rModelPart, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: line_search_strategy.h:137
BaseType::TDataType TDataType
Definition: line_search_strategy.h:99
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: line_search_strategy.h:118
LineSearchStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, Parameters ThisParameters)
Definition: line_search_strategy.h:237
LineSearchStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, Parameters ThisParameters)
Definition: line_search_strategy.h:258
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: line_search_strategy.h:117
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: line_search_strategy.h:329
~LineSearchStrategy() override
Definition: line_search_strategy.h:275
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
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
void SetBool(const bool Value)
This method sets the bool contained in the current Parameter.
Definition: kratos_parameters.cpp:803
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
void SetInt(const int Value)
This method sets the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:795
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 the base Newton Raphson strategy.
Definition: residualbased_newton_raphson_strategy.h:66
TBuilderAndSolverType::Pointer GetBuilderAndSolver()
Get method for the builder and solver.
Definition: residualbased_newton_raphson_strategy.h:493
virtual void UpdateDatabase(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb, const bool MoveMesh)
Here the database is updated.
Definition: residualbased_newton_raphson_strategy.h:1278
TSchemeType::Pointer GetScheme()
Get method for the time scheme.
Definition: residualbased_newton_raphson_strategy.h:475
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_newton_raphson_strategy.h:1069
BaseType::TSchemeType TSchemeType
Definition: residualbased_newton_raphson_strategy.h:87
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_newton_raphson_strategy.h:1351
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: residualbased_newton_raphson_strategy.h:81
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
Solving strategy base class This is the base class from which we will derive all the strategies (impl...
Definition: solving_strategy.h:64
TSparseSpace::VectorPointerType TSystemVectorPointerType
Definition: solving_strategy.h:77
TDenseSpace::MatrixType LocalSystemMatrixType
Definition: solving_strategy.h:79
TSparseSpace::DataType TDataType
Definition: solving_strategy.h:69
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: solving_strategy.h:507
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
TSparseSpace::MatrixPointerType TSystemMatrixPointerType
Definition: solving_strategy.h:75
bool MoveMeshFlag()
This function returns the flag that says if the mesh is moved.
Definition: solving_strategy.h:290
TSparseSpace::VectorType TSystemVectorType
Definition: solving_strategy.h:73
virtual void MoveMesh()
This function is designed to move the mesh.
Definition: solving_strategy.h:330
TDenseSpace::VectorType LocalSystemVectorType
Definition: solving_strategy.h:81
#define KRATOS_INFO(label)
Definition: logger.h:250
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
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
namespace KRATOS_DEPRECATED_MESSAGE("Please use std::filesystem directly") filesystem
Definition: kratos_filesystem.h:33
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
A
Definition: sensitivityMatrix.py:70
x
Definition: sensitivityMatrix.py:49
e
Definition: run_cpp_mpi_tests.py:31