14 #if !defined(KRATOS_RESIDUALBASED_LINEAR_STRATEGY )
15 #define KRATOS_RESIDUALBASED_LINEAR_STRATEGY
58 template<
class TSparseSpace,
125 mSolutionStepIsInitialized =
false;
126 mInitializeWasPerformed =
false;
148 typename TSchemeType::Pointer pScheme,
149 typename TLinearSolver::Pointer pNewLinearSolver,
150 bool CalculateReactionFlag =
false,
151 bool ReformDofSetAtEachStep =
false,
152 bool CalculateNormDxFlag =
false,
156 mReformDofSetAtEachStep(ReformDofSetAtEachStep),
157 mCalculateNormDxFlag(CalculateNormDxFlag),
158 mCalculateReactionsFlag(CalculateReactionFlag)
163 mpBuilderAndSolver =
typename TBuilderAndSolverType::Pointer
169 mSolutionStepIsInitialized =
false;
170 mInitializeWasPerformed =
false;
201 typename TSchemeType::Pointer pScheme,
202 typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
203 bool CalculateReactionFlag =
false,
204 bool ReformDofSetAtEachStep =
false,
205 bool CalculateNormDxFlag =
false,
209 mpBuilderAndSolver(pNewBuilderAndSolver),
210 mReformDofSetAtEachStep(ReformDofSetAtEachStep),
211 mCalculateNormDxFlag(CalculateNormDxFlag),
212 mCalculateReactionsFlag(CalculateReactionFlag)
217 mSolutionStepIsInitialized =
false;
218 mInitializeWasPerformed =
false;
247 if (p_builder_and_solver !=
nullptr) {
248 p_builder_and_solver->Clear();
289 mpBuilderAndSolver = pNewBuilderAndSolver;
298 return mpBuilderAndSolver;
307 mCalculateReactionsFlag = CalculateReactionsFlag;
317 return mCalculateReactionsFlag;
326 mReformDofSetAtEachStep = Flag;
336 return mReformDofSetAtEachStep;
363 typename SolvingStrategyType::Pointer
Create(
368 return Kratos::make_shared<ClassType>(rModelPart, ThisParameters);
381 if(mInitializeWasPerformed ==
false)
385 if (mSolutionStepIsInitialized ==
false)
398 const int local_number_of_constraints = r_constraints_array.size();
399 const int global_number_of_constraints = r_comm.SumAll(local_number_of_constraints);
400 if(global_number_of_constraints != 0) {
407 rConstraint.
Apply(r_process_info);
412 TSparseSpace::SetToZero(rDx);
428 if (mInitializeWasPerformed ==
false)
431 typename TSchemeType::Pointer p_scheme =
GetScheme();
434 if (p_scheme->SchemeIsInitialized() ==
false)
438 if (p_scheme->ElementsAreInitialized() ==
false)
442 if (p_scheme->ConditionsAreInitialized() ==
false)
445 mInitializeWasPerformed =
true;
462 double norm_dx = 0.00;
463 if (mCalculateNormDxFlag ==
true)
479 if (p_builder_and_solver !=
nullptr) {
480 p_builder_and_solver->SetDofSetIsInitializedFlag(
false);
481 p_builder_and_solver->Clear();
494 if (p_scheme !=
nullptr) {
498 mInitializeWasPerformed =
false;
499 mSolutionStepIsInitialized =
false;
529 if (mSolutionStepIsInitialized ==
false)
532 typename TSchemeType::Pointer p_scheme =
GetScheme();
538 if (p_builder_and_solver->GetDofSetIsInitializedFlag() ==
false ||
539 mReformDofSetAtEachStep ==
true)
553 p_builder_and_solver->ResizeAndInitializeVectors(p_scheme, mpA, mpDx, mpb,
570 mSolutionStepIsInitialized =
true;
583 typename TSchemeType::Pointer p_scheme =
GetScheme();
602 mSolutionStepIsInitialized =
false;
605 if (mReformDofSetAtEachStep ==
true)
623 typename TSchemeType::Pointer p_scheme =
GetScheme();
634 TSparseSpace::SetToZero(rA);
635 TSparseSpace::SetToZero(rDx);
636 TSparseSpace::SetToZero(rb);
645 TSparseSpace::SetToZero(rDx);
646 TSparseSpace::SetToZero(rb);
654 DofsArrayType& r_dof_set = p_builder_and_solver->GetDofSet();
663 if (mCalculateReactionsFlag ==
true)
664 p_builder_and_solver->CalculateReactions(p_scheme,
743 "name" : "linear_strategy",
744 "compute_norm_dx" : false,
745 "reform_dofs_at_each_step" : false,
746 "compute_reactions" : false,
747 "builder_and_solver_settings" : {},
748 "linear_solver_settings" : {},
749 "scheme_settings" : {}
755 return default_parameters;
764 return "linear_strategy";
790 std::string
Info()
const override
792 return "ResidualBasedLinearStrategy";
837 mCalculateNormDxFlag = ThisParameters[
"compute_norm_dx"].
GetBool();
838 mReformDofSetAtEachStep = ThisParameters[
"reform_dofs_at_each_step"].
GetBool();
839 mCalculateReactionsFlag = ThisParameters[
"compute_reactions"].
GetBool();
842 if (ThisParameters[
"scheme_settings"].
Has(
"name")) {
843 KRATOS_ERROR <<
"IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
847 if (ThisParameters[
"builder_and_solver_settings"].
Has(
"name")) {
848 KRATOS_ERROR <<
"IMPLEMENTATION PENDING IN CONSTRUCTOR WITH PARAMETERS" << std::endl;
875 typename TSchemeType::Pointer mpScheme =
nullptr;
876 typename TBuilderAndSolverType::Pointer mpBuilderAndSolver =
nullptr;
889 bool mReformDofSetAtEachStep;
891 bool mCalculateNormDxFlag;
897 bool mCalculateReactionsFlag;
899 bool mSolutionStepIsInitialized;
901 bool mInitializeWasPerformed;
910 virtual void EchoInfo()
918 KRATOS_INFO(
"LHS") <<
"SystemMatrix = " << rA << std::endl;
919 KRATOS_INFO(
"Dx") <<
"Solution obtained = " << rDx << std::endl;
924 std::stringstream matrix_market_name;
928 std::stringstream matrix_market_vectname;
Definition: builtin_timer.h:26
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
BaseType::TSystemVectorType TSystemVectorType
Definition: implicit_solving_strategy.h:72
Scheme< TSparseSpace, TDenseSpace > TSchemeType
Definition: implicit_solving_strategy.h:82
void SetRebuildLevel(int Level) override
This sets the build level.
Definition: implicit_solving_strategy.h:207
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: implicit_solving_strategy.h:283
int mRebuildLevel
Definition: implicit_solving_strategy.h:263
bool mStiffnessMatrixIsBuilt
The current rebuild level.
Definition: implicit_solving_strategy.h:264
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > TBuilderAndSolverType
Definition: implicit_solving_strategy.h:84
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: implicit_solving_strategy.h:169
A class that implements the interface for different master-slave constraints to be applied on a syste...
Definition: master_slave_constraint.h:76
virtual void ResetSlaveDofs(const ProcessInfo &rCurrentProcessInfo)
This method resets the values of the slave dofs.
Definition: master_slave_constraint.h:373
virtual void Apply(const ProcessInfo &rCurrentProcessInfo)
This method directly applies the master/slave relationship.
Definition: master_slave_constraint.h:382
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
Communicator & GetCommunicator()
Definition: model_part.h:1821
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
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
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
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
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
This is a very simple strategy to solve linearly the problem.
Definition: residualbased_linear_strategy.h:64
ResidualBasedLinearStrategy< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
Definition: residualbased_linear_strategy.h:76
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_linear_strategy.h:74
double Solve() override
The problem of interest is solved.
Definition: residualbased_linear_strategy.h:457
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_linear_strategy.h:88
void Initialize() override
Initialization of member variables and prior operations.
Definition: residualbased_linear_strategy.h:424
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: residualbased_linear_strategy.h:580
TSchemeType::Pointer GetScheme()
Get method for the time scheme.
Definition: residualbased_linear_strategy.h:278
ResidualBasedLinearStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, bool CalculateReactionFlag=false, bool ReformDofSetAtEachStep=false, bool CalculateNormDxFlag=false, bool MoveMeshFlag=false)
Default constructor.
Definition: residualbased_linear_strategy.h:146
double GetResidualNorm() override
This method returns the residual norm.
Definition: residualbased_linear_strategy.h:708
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residualbased_linear_strategy.h:762
TSystemVectorType & GetSystemVector() override
This method returns the RHS vector.
Definition: residualbased_linear_strategy.h:686
void Clear() override
Clears the internal storage.
Definition: residualbased_linear_strategy.h:473
bool GetReformDofSetAtEachStepFlag()
This method returns the flag mReformDofSetAtEachStep.
Definition: residualbased_linear_strategy.h:334
ResidualBasedLinearStrategy(ModelPart &rModelPart, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: residualbased_linear_strategy.h:117
void CalculateOutputData() override
This operations should be called before printing the results when non trivial results (e....
Definition: residualbased_linear_strategy.h:509
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: residualbased_linear_strategy.h:525
bool GetCalculateReactionsFlag()
This method returns the flag mCalculateReactionsFlag.
Definition: residualbased_linear_strategy.h:315
std::string Info() const override
Turn back information as a string.
Definition: residualbased_linear_strategy.h:790
SolvingStrategyType::Pointer Create(ModelPart &rModelPart, Parameters ThisParameters) const override
Create method.
Definition: residualbased_linear_strategy.h:363
~ResidualBasedLinearStrategy() override
Destructor.
Definition: residualbased_linear_strategy.h:240
TSparseSpace SparseSpaceType
Definition: residualbased_linear_strategy.h:80
TSystemMatrixType & GetSystemMatrix() override
This method returns the LHS matrix.
Definition: residualbased_linear_strategy.h:675
SolvingStrategy< TSparseSpace, TDenseSpace > SolvingStrategyType
Definition: residualbased_linear_strategy.h:72
int Check() override
Function to perform expensive checks.
Definition: residualbased_linear_strategy.h:720
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: residualbased_linear_strategy.h:620
void SetScheme(typename TSchemeType::Pointer pScheme)
Set method for the time scheme.
Definition: residualbased_linear_strategy.h:269
TBuilderAndSolverType::Pointer GetBuilderAndSolver()
Get method for the builder and solver.
Definition: residualbased_linear_strategy.h:296
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_linear_strategy.h:739
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_linear_strategy.h:834
BaseType::TSchemeType TSchemeType
Definition: residualbased_linear_strategy.h:82
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residualbased_linear_strategy.h:802
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residualbased_linear_strategy.h:796
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: residualbased_linear_strategy.h:96
ResidualBasedLinearStrategy()
Default constructor.
Definition: residualbased_linear_strategy.h:108
ResidualBasedLinearStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, bool CalculateReactionFlag=false, bool ReformDofSetAtEachStep=false, bool CalculateNormDxFlag=false, bool MoveMeshFlag=false)
Constructor specifying the builder and solver.
Definition: residualbased_linear_strategy.h:199
TSystemVectorType & GetSolutionVector() override
This method returns the solution vector.
Definition: residualbased_linear_strategy.h:697
void SetBuilderAndSolver(typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver)
Set method for the builder and solver.
Definition: residualbased_linear_strategy.h:287
void Predict() override
Operation to predict the solution ... if it is not called a trivial predictor is used in which the va...
Definition: residualbased_linear_strategy.h:375
BaseType::TDataType TDataType
Definition: residualbased_linear_strategy.h:78
void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
This method sets the flag mCalculateReactionsFlag.
Definition: residualbased_linear_strategy.h:305
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_linear_strategy.h:92
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_linear_strategy.h:90
void SetEchoLevel(int Level) override
It sets the level of echo for the solving strategy.
Definition: residualbased_linear_strategy.h:349
void SetReformDofSetAtEachStepFlag(bool Flag)
This method sets the flag mReformDofSetAtEachStep.
Definition: residualbased_linear_strategy.h:324
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: residualbased_linear_strategy.h:84
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: residualbased_linear_strategy.h:98
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_linear_strategy.h:94
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_linear_strategy.h:86
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedLinearStrategy)
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
virtual void SetEchoLevel(const int Level)
This sets the level of echo for the solving strategy.
Definition: solving_strategy.h:255
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
int GetEchoLevel()
This returns the level of echo for the solving strategy.
Definition: solving_strategy.h:271
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
virtual int Check()
Function to perform expensive checks.
Definition: solving_strategy.h:377
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
virtual double Solve()
The problem of interest is solved.
Definition: solving_strategy.h:183
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
static void Clear(MatrixPointerType &pA)
Definition: ublas_space.h:578
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_INFO(label)
Definition: logger.h:250
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
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
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
bool WriteMatrixMarketVector(const char *FileName, VectorType &V)
Definition: matrix_market_interface.h:539
bool WriteMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M, bool Symmetric)
Definition: matrix_market_interface.h:308
double precision function mb(a)
Definition: TensorModule.f:849