KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
hexahedra_newton_raphson_strategy.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ \.
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Alejandro Cornejo
11 //
12 
13 #if !defined(KRATOS_HEXAHEDRA_NEWTON_RAPHSON_STRATEGY)
14 #define KRATOS_HEXAHEDRA_NEWTON_RAPHSON_STRATEGY
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "includes/define.h"
24 
25 //default builder and solver
28 
29 // Extrapolation process
31 
32 
33 namespace Kratos
34 {
35 
38 
42 
44 
47 
51 
55 
63 template <class TSparseSpace,
64  class TDenseSpace, // = DenseSpace<double>,
65  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
66  >
68  : public ResidualBasedNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
69 {
70  public:
74 
75  // Counted pointer of ClassName
77 
80  typedef typename BaseType::TDataType TDataType;
81  typedef TSparseSpace SparseSpaceType;
90 
93 
95 
108  ModelPart& rModelPart,
109  typename TSchemeType::Pointer pScheme,
110  typename TLinearSolver::Pointer pNewLinearSolver,
111  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
112  int MaxIterations = 30,
113  bool CalculateReactions = false,
114  bool ReformDofSetAtEachStep = false,
115  bool MoveMeshFlag = false)
116  : ResidualBasedNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pNewLinearSolver, pNewConvergenceCriteria, MaxIterations, CalculateReactions, ReformDofSetAtEachStep, MoveMeshFlag)
117  {
118  KRATOS_TRY;
119 
121 
122  // Set flags to default values
123  BaseType::SetMaxIterationNumber(MaxIterations);
124  BaseType::mCalculateReactionsFlag = CalculateReactions;
125 
126  BaseType::mReformDofSetAtEachStep = ReformDofSetAtEachStep;
127 
128  // Saving the convergence criteria to be used
129  BaseType::mpConvergenceCriteria = pNewConvergenceCriteria;
130 
131  // Saving the scheme
132  BaseType::mpScheme = pScheme;
133 
134  // Saving the linear solver
135  BaseType::mpLinearSolver = pNewLinearSolver;
136 
137  // Setting up the default builder and solver
138  BaseType::mpBuilderAndSolver = typename TBuilderAndSolverType::Pointer(
140 
141  // Set flags to start correcty the calculations
142  BaseType::mSolutionStepIsInitialized = false;
144 
145  // Tells to the builder and solver if the reactions have to be Calculated or not
147 
148  // Tells to the Builder And Solver if the system matrix and vectors need to
149  // be reshaped at each step or not
151 
152  // Set EchoLevel to the default value (only time is displayed)
154 
155  // By default the matrices are rebuilt at each iteration
156  this->SetRebuildLevel(2);
157 
161 
162  KRATOS_CATCH("");
163  }
164 
178  ModelPart& rModelPart,
179  typename TSchemeType::Pointer pScheme,
180  typename TLinearSolver::Pointer pNewLinearSolver,
181  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
182  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
183  int MaxIterations = 30,
184  bool CalculateReactions = false,
185  bool ReformDofSetAtEachStep = false,
186  bool MoveMeshFlag = false)
187  : ResidualBasedNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, pScheme, pNewLinearSolver, pNewConvergenceCriteria, MaxIterations, CalculateReactions, ReformDofSetAtEachStep, MoveMeshFlag)
188  {
189  KRATOS_TRY
190 
192 
193  // Set flags to default values
194  BaseType::SetMaxIterationNumber(MaxIterations);
195  BaseType::mCalculateReactionsFlag = CalculateReactions;
196 
197  BaseType::mReformDofSetAtEachStep = ReformDofSetAtEachStep;
198 
199  // Saving the convergence criteria to be used
200  BaseType::mpConvergenceCriteria = pNewConvergenceCriteria;
201 
202  // Saving the scheme
203  BaseType::mpScheme = pScheme;
204 
205  // Saving the linear solver
206  BaseType::mpLinearSolver = pNewLinearSolver;
207 
208  // Setting up the default builder and solver
209  BaseType::mpBuilderAndSolver = pNewBuilderAndSolver;
210 
211  // Set flags to start correcty the calculations
212  BaseType::mSolutionStepIsInitialized = false;
214 
215  // Tells to the builder and solver if the reactions have to be Calculated or not
217 
218  // Tells to the Builder And Solver if the system matrix and vectors need to
219  //be reshaped at each step or not
221 
222  // Set EchoLevel to the default value (only time is displayed)
224 
225  // By default the matrices are rebuilt at each iteration
226  this->SetRebuildLevel(2);
227 
231 
232  KRATOS_CATCH("")
233  }
234 
240  {
241  BaseType::Clear();
242  }
243 
247  bool SolveSolutionStep() override
248  {
249  // Pointers needed in the solution
250  typename TSchemeType::Pointer p_scheme = BaseType::GetScheme();
251  typename TBuilderAndSolverType::Pointer p_builder_and_solver = BaseType::GetBuilderAndSolver();
252 
256 
257  //initializing the parameters of the Newton-Raphson cycle
258  unsigned int iteration_number = 1;
259  BaseType::GetModelPart().GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
260  bool is_converged = false;
261  bool residual_is_updated = false;
262  p_scheme->InitializeNonLinIteration(BaseType::GetModelPart(), rA, rDx, rb);
263 
264  // We extrapolate the stress to the nodes to perform the smoothing
265  ModelPart& rModelPart = BaseType::GetModelPart();
266  Parameters extrapolation_parameters(R"(
267  {
268  "list_of_variables": ["STRESS_VECTOR","STRAIN_VECTOR"]
269  })");
270  auto extrapolation_process = IntegrationValuesExtrapolationToNodesProcess(rModelPart, extrapolation_parameters);
271  extrapolation_process.Execute();
272 
273  is_converged = BaseType::mpConvergenceCriteria->PreCriteria(BaseType::GetModelPart(), p_builder_and_solver->GetDofSet(), rA, rDx, rb);
274 
275  //function to perform the building and the solving phase.
277  TSparseSpace::SetToZero(rA);
278  TSparseSpace::SetToZero(rDx);
279  TSparseSpace::SetToZero(rb);
280  p_builder_and_solver->BuildAndSolve(p_scheme, BaseType::GetModelPart(), rA, rDx, rb);
281  } else {
282  TSparseSpace::SetToZero(rDx); //Dx=0.00;
283  TSparseSpace::SetToZero(rb);
284  p_builder_and_solver->BuildRHSAndSolve(p_scheme, BaseType::GetModelPart(), rA, rDx, rb);
285  }
286 
287  // Debugging info
288  BaseType::EchoInfo(iteration_number);
289 
290  // Updating the results stored in the database
292 
293  p_scheme->FinalizeNonLinIteration(BaseType::GetModelPart(), rA, rDx, rb);
294 
295  if (is_converged == true) {
296  //initialisation of the convergence criteria
297  BaseType::mpConvergenceCriteria->InitializeSolutionStep(BaseType::GetModelPart(), p_builder_and_solver->GetDofSet(), rA, rDx, rb);
298 
299  if (BaseType::mpConvergenceCriteria->GetActualizeRHSflag() == true) {
300  TSparseSpace::SetToZero(rb);
301  p_builder_and_solver->BuildRHS(p_scheme, BaseType::GetModelPart(), rb);
302  }
303  is_converged = BaseType::mpConvergenceCriteria->PostCriteria(BaseType::GetModelPart(), p_builder_and_solver->GetDofSet(), rA, rDx, rb);
304  }
305 
306  //Iteration Cycle... performed only for NonLinearProblems
307  while (is_converged == false && iteration_number++ < BaseType::mMaxIterationNumber) {
308  //setting the number of iteration
309  BaseType::GetModelPart().GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
310  p_scheme->InitializeNonLinIteration(BaseType::GetModelPart(), rA, rDx, rb);
311  is_converged = BaseType::mpConvergenceCriteria->PreCriteria(BaseType::GetModelPart(), p_builder_and_solver->GetDofSet(), rA, rDx, rb);
312  extrapolation_process.Execute();
313 
314  //call the linear system solver to find the correction mDx for the
315  //it is not called if there is no system to solve
316  if (SparseSpaceType::Size(rDx) != 0) {
319  TSparseSpace::SetToZero(rA);
320  TSparseSpace::SetToZero(rDx);
321  TSparseSpace::SetToZero(rb);
322  p_builder_and_solver->BuildAndSolve(p_scheme, BaseType::GetModelPart(), rA, rDx, rb);
323  } else {
324  TSparseSpace::SetToZero(rDx);
325  TSparseSpace::SetToZero(rb);
326  p_builder_and_solver->BuildRHSAndSolve(p_scheme, BaseType::GetModelPart(), rA, rDx, rb);
327  }
328  } else {
329  TSparseSpace::SetToZero(rDx);
330  TSparseSpace::SetToZero(rb);
331  p_builder_and_solver->BuildRHSAndSolve(p_scheme, BaseType::GetModelPart(), rA, rDx, rb);
332  }
333  } else {
334  KRATOS_WARNING("NO DOFS") << "ATTENTION: no free DOFs!! " << std::endl;
335  }
336 
337  // Debugging info
338  BaseType::EchoInfo(iteration_number);
339 
340  // Updating the results stored in the database
342 
343  p_scheme->FinalizeNonLinIteration(BaseType::GetModelPart(), rA, rDx, rb);
344 
345  residual_is_updated = false;
346 
347  if (is_converged == true) {
348  if (BaseType::mpConvergenceCriteria->GetActualizeRHSflag() == true) {
349  TSparseSpace::SetToZero(rb);
350 
351  p_builder_and_solver->BuildRHS(p_scheme, BaseType::GetModelPart(), rb);
352  residual_is_updated = true;
353  }
354 
355  is_converged = BaseType::mpConvergenceCriteria->PostCriteria(BaseType::GetModelPart(), p_builder_and_solver->GetDofSet(), rA, rDx, rb);
356  }
357  }
358 
359  //plots a warning if the maximum number of iterations is exceeded
360  if (iteration_number >= BaseType::mMaxIterationNumber && BaseType::GetModelPart().GetCommunicator().MyPID() == 0)
362 
363  //calculate reactions if required
365  p_builder_and_solver->CalculateReactions(p_scheme, BaseType::GetModelPart(), rA, rDx, rb);
366 
367  return is_converged;
368  }
369 
373 
377 
379 
380  private:
383 
387 
391 
395 
399 
403 
407 
409 
410  protected:
413 
417 
421 
425 
429 
433 
437 
443 
445 
446 }; /* Class HexahedraNewtonRaphsonStrategy */
447 
449 
452 
454 
455 } /* namespace Kratos. */
456 
457 #endif /* KRATOS_RESIDUALBASED_NEWTON_RAPHSON_STRATEGY defined */
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
This is the base Newton Raphson strategy.
Definition: hexahedra_newton_raphson_strategy.h:69
BaseType::TSystemVectorType TSystemVectorType
Definition: hexahedra_newton_raphson_strategy.h:85
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: hexahedra_newton_raphson_strategy.h:86
BaseType::TSchemeType TSchemeType
Definition: hexahedra_newton_raphson_strategy.h:82
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: hexahedra_newton_raphson_strategy.h:247
KRATOS_CLASS_POINTER_DEFINITION(HexahedraNewtonRaphsonStrategy)
ConvergenceCriteria< TSparseSpace, TDenseSpace > TConvergenceCriteriaType
Definition: hexahedra_newton_raphson_strategy.h:73
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: hexahedra_newton_raphson_strategy.h:89
BaseType::TSystemMatrixType TSystemMatrixType
Definition: hexahedra_newton_raphson_strategy.h:84
BaseType::DofsArrayType DofsArrayType
Definition: hexahedra_newton_raphson_strategy.h:83
HexahedraNewtonRaphsonStrategy(const HexahedraNewtonRaphsonStrategy &Other)
Definition: hexahedra_newton_raphson_strategy.h:442
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: hexahedra_newton_raphson_strategy.h:88
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: hexahedra_newton_raphson_strategy.h:87
TSparseSpace SparseSpaceType
Definition: hexahedra_newton_raphson_strategy.h:81
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: hexahedra_newton_raphson_strategy.h:79
HexahedraNewtonRaphsonStrategy(ModelPart &rModelPart, typename TSchemeType::Pointer pScheme, typename TLinearSolver::Pointer pNewLinearSolver, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, int MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Definition: hexahedra_newton_raphson_strategy.h:177
ResidualBasedNewtonRaphsonStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: hexahedra_newton_raphson_strategy.h:78
~HexahedraNewtonRaphsonStrategy() override
Destructor.
Definition: hexahedra_newton_raphson_strategy.h:239
BaseType::TDataType TDataType
Definition: hexahedra_newton_raphson_strategy.h:80
HexahedraNewtonRaphsonStrategy(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: hexahedra_newton_raphson_strategy.h:107
BaseType::TSystemVectorType TSystemVectorType
Definition: implicit_solving_strategy.h:72
void SetRebuildLevel(int Level) override
This sets the build level.
Definition: implicit_solving_strategy.h:207
int mRebuildLevel
Definition: implicit_solving_strategy.h:263
bool mStiffnessMatrixIsBuilt
The current rebuild level.
Definition: implicit_solving_strategy.h:264
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
This process extrapolates vales from the integration points to the nodes.
Definition: integration_values_extrapolation_to_nodes_process.h:59
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
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
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 the base Newton Raphson strategy.
Definition: residualbased_newton_raphson_strategy.h:66
void SetMaxIterationNumber(unsigned int MaxIterationNumber)
This method sets the flag mMaxIterationNumber.
Definition: residualbased_newton_raphson_strategy.h:575
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
bool mKeepSystemConstantDuringIterations
Flag to set as initialized the strategy.
Definition: residualbased_newton_raphson_strategy.h:1265
unsigned int mMaxIterationNumber
Definition: residualbased_newton_raphson_strategy.h:1261
TSchemeType::Pointer GetScheme()
Get method for the time scheme.
Definition: residualbased_newton_raphson_strategy.h:475
TSystemVectorPointerType mpb
The increment in the solution.
Definition: residualbased_newton_raphson_strategy.h:1237
TSystemMatrixPointerType mpA
The RHS vector of the system of equations.
Definition: residualbased_newton_raphson_strategy.h:1238
virtual void MaxIterationsExceeded()
This method prints information after reach the max number of iterations.
Definition: residualbased_newton_raphson_strategy.h:1340
bool mCalculateReactionsFlag
Flag telling if it is needed or not to compute the reactions.
Definition: residualbased_newton_raphson_strategy.h:1253
TSystemVectorPointerType mpDx
The pointer to the convergence criteria employed.
Definition: residualbased_newton_raphson_strategy.h:1236
TBuilderAndSolverType::Pointer mpBuilderAndSolver
The pointer to the time scheme employed.
Definition: residualbased_newton_raphson_strategy.h:1233
BaseType::TSchemeType TSchemeType
Definition: residualbased_newton_raphson_strategy.h:87
TSchemeType::Pointer mpScheme
Definition: residualbased_newton_raphson_strategy.h:1232
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: residualbased_newton_raphson_strategy.h:81
void SetEchoLevel(int Level) override
It sets the level of echo for the solving strategy.
Definition: residualbased_newton_raphson_strategy.h:599
bool GetKeepSystemConstantDuringIterations()
Get method for the flag mKeepSystemConstantDuringIterations.
Definition: residualbased_newton_raphson_strategy.h:1158
void Clear() override
Clears the internal storage.
Definition: residualbased_newton_raphson_strategy.h:707
virtual void EchoInfo(const unsigned int IterationNumber)
This method returns the components of the system of equations depending of the echo level.
Definition: residualbased_newton_raphson_strategy.h:1298
TConvergenceCriteriaType::Pointer mpConvergenceCriteria
The pointer to the builder and solver employed.
Definition: residualbased_newton_raphson_strategy.h:1234
bool mInitializeWasPerformed
The maximum number of iterations, 30 by default.
Definition: residualbased_newton_raphson_strategy.h:1263
bool mReformDofSetAtEachStep
The LHS matrix of the system of equations.
Definition: residualbased_newton_raphson_strategy.h:1247
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
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
TDenseSpace::VectorType LocalSystemVectorType
Definition: solving_strategy.h:81
static IndexType Size(VectorType const &rV)
return size of vector rV
Definition: ublas_space.h:190
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_WARNING(label)
Definition: logger.h:265
TSpaceType::VectorPointerType CreateEmptyVectorPointer(TSpaceType &dummy)
Definition: add_strategies_to_python.cpp:187
TSpaceType::MatrixPointerType CreateEmptyMatrixPointer(TSpaceType &dummy)
Definition: add_strategies_to_python.cpp:181
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21