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.
poromechanics_newton_raphson_nonlocal_strategy.hpp
Go to the documentation of this file.
1 
2 // | / |
3 // ' / __| _` | __| _ \ __|
4 // . \ | ( | | ( |\__ `
5 // _|\_\_| \__,_|\__|\___/ ____/
6 // Multi-Physics
7 //
8 // License: BSD License
9 // Kratos default license: kratos/license.txt
10 //
11 // Main authors: Ignasi de Pouplana
12 //
13 
14 
15 #if !defined(KRATOS_POROMECHANICS_NEWTON_RAPHSON_NONLOCAL_STRATEGY)
16 #define KRATOS_POROMECHANICS_NEWTON_RAPHSON_NONLOCAL_STRATEGY
17 
18 // Project includes
23 
24 // Application includes
26 
27 namespace Kratos
28 {
29 
30 template<class TSparseSpace,class TDenseSpace,class TLinearSolver>
31 
32 class PoromechanicsNewtonRaphsonNonlocalStrategy : public PoromechanicsNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
33 {
34 
35 public:
36 
38 
51  using GrandMotherType::mpA; //Tangent matrix
52  using GrandMotherType::mpb; //Residual vector of iteration i
53  using GrandMotherType::mpDx; //Delta x of iteration i
58 
59 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
60 
64  typename TSchemeType::Pointer pScheme,
65  typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria,
66  typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver,
67  Parameters& rParameters,
68  int MaxIterations = 30,
69  bool CalculateReactions = false,
70  bool ReformDofSetAtEachStep = false,
71  bool MoveMeshFlag = false
72  ) : PoromechanicsNewtonRaphsonStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(model_part, pScheme,
73  pNewConvergenceCriteria, pNewBuilderAndSolver, rParameters, MaxIterations, CalculateReactions, ReformDofSetAtEachStep, MoveMeshFlag)
74  {
76  mSearchNeighboursAtEachStep = rParameters["search_neighbours_step"].GetBool();
77  }
78 
79  //------------------------------------------------------------------------------------
80 
83 
84 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
85 
86  void Initialize() override
87  {
89 
90  if (mInitializeWasPerformed == false)
91  {
93 
94  if(mNonlocalDamageIsInitialized == false)
95  {
96  if(BaseType::GetModelPart().GetProcessInfo()[DOMAIN_SIZE]==2)
97  {
99  }
100  else
101  {
103  }
105 
107  }
108  }
109 
110  KRATOS_CATCH( "" )
111  }
112 
113 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
114 
115  void InitializeSolutionStep() override
116  {
117  KRATOS_TRY
118 
120 
121  if(mNonlocalDamageIsInitialized == false)
122  {
123  if(BaseType::GetModelPart().GetProcessInfo()[DOMAIN_SIZE]==2)
124  {
126  }
127  else
128  {
130  }
132 
134  }
135 
136  KRATOS_CATCH( "" )
137  }
138 
139 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
140 
141  bool SolveSolutionStep() override
142  {
143  // ********** Prediction phase **********
144 
145  // Initialize variables
146  DofsArrayType& rDofSet = mpBuilderAndSolver->GetDofSet();
147  TSystemMatrixType& mA = *mpA;
148  TSystemVectorType& mDx = *mpDx;
150 
151  //initializing the parameters of the iteration loop
152  unsigned int iteration_number = 1;
153  BaseType::GetModelPart().GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
154  bool is_converged = false;
155  mpScheme->InitializeNonLinIteration(BaseType::GetModelPart(), mA, mDx, mb);
157  is_converged = mpConvergenceCriteria->PreCriteria(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
158 
159  TSparseSpace::SetToZero(mA);
160  TSparseSpace::SetToZero(mb);
161  TSparseSpace::SetToZero(mDx);
162 
163  mpBuilderAndSolver->BuildAndSolve(mpScheme, BaseType::GetModelPart(), mA, mDx, mb);
164 
165  //update results
166  mpScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
167 
168  //move the mesh if needed
170 
171  // ********** Correction phase (iteration cicle) **********
172  if (is_converged == true)
173  {
174  mpConvergenceCriteria->InitializeSolutionStep(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
175  if (mpConvergenceCriteria->GetActualizeRHSflag() == true)
176  {
177  TSparseSpace::SetToZero(mb);
179  }
180  is_converged = mpConvergenceCriteria->PostCriteria(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
181  }
182 
183  while (is_converged == false && iteration_number++ < mMaxIterationNumber)
184  {
185  //setting the number of iteration
186  BaseType::GetModelPart().GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
187 
188  mpScheme->InitializeNonLinIteration(BaseType::GetModelPart(), mA, mDx, mb);
190 
191  is_converged = mpConvergenceCriteria->PreCriteria(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
192 
193  TSparseSpace::SetToZero(mA);
194  TSparseSpace::SetToZero(mb);
195  TSparseSpace::SetToZero(mDx);
196 
197  mpBuilderAndSolver->BuildAndSolve(mpScheme, BaseType::GetModelPart(), mA, mDx, mb);
198 
199  //update results
200  mpScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
201 
202  //move the mesh if needed
204 
205  mpScheme->FinalizeNonLinIteration(BaseType::GetModelPart(), mA, mDx, mb);
207 
208  // *** Check Convergence ***
209 
210  if (is_converged == true)
211  {
212  if (mpConvergenceCriteria->GetActualizeRHSflag() == true)
213  {
214  TSparseSpace::SetToZero(mb);
216  }
217  is_converged = mpConvergenceCriteria->PostCriteria(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
218  }
219 
220  }//While
221 
222  //plots a warning if the maximum number of iterations is exceeded
223  if (iteration_number >= mMaxIterationNumber && BaseType::GetModelPart().GetCommunicator().MyPID() == 0)
224  {
225  this->MaxIterationsExceeded();
226  }
227 
228  //calculate reactions if required
229  if (mCalculateReactionsFlag == true)
230  {
231  mpBuilderAndSolver->CalculateReactions(mpScheme, BaseType::GetModelPart(), mA, mDx, mb);
232  }
233 
234  return is_converged;
235  }
236 
237 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
238 
239  void FinalizeSolutionStep() override
240  {
241  KRATOS_TRY
242 
244 
245  if(mSearchNeighboursAtEachStep == true)
246  {
249  }
250 
251  KRATOS_CATCH("")
252  }
253 
254 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
255 
256  void Clear() override
257  {
258  KRATOS_TRY
259 
261 
262  if(mSearchNeighboursAtEachStep == false)
263  {
266  }
267 
268  KRATOS_CATCH( "" )
269  }
270 
271 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
272 
273 protected:
274 
279 
280 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
281 
282  bool CheckConvergence() override
283  {
284  // ********** Prediction phase **********
285 
286  // Initialize variables
287  DofsArrayType& rDofSet = mpBuilderAndSolver->GetDofSet();
288  TSystemMatrixType& mA = *mpA;
289  TSystemVectorType& mDx = *mpDx;
291 
292  mpScheme->InitializeNonLinIteration(BaseType::GetModelPart(), mA, mDx, mb);
294 
295  TSparseSpace::SetToZero(mA);
296  TSparseSpace::SetToZero(mb);
297  TSparseSpace::SetToZero(mDx);
298 
299  mpBuilderAndSolver->BuildAndSolve(mpScheme, BaseType::GetModelPart(), mA, mDx, mb);
300 
301  mpScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
302 
303  //move the mesh if needed
305 
306  mpScheme->FinalizeNonLinIteration(BaseType::GetModelPart(), mA, mDx, mb);
307 
308  unsigned int iteration_number = 0;
309  bool is_converged = false;
310  double dofs_ratio = 1000.0;
311  double ReferenceDofsNorm;
312  double NormDx;
313 
314  // ********** Correction phase (iteration cicle) **********
315 
316  while (is_converged == false && iteration_number < mMaxIterationNumber)
317  {
318  //setting the number of iteration
319  iteration_number += 1;
320  BaseType::GetModelPart().GetProcessInfo()[NL_ITERATION_NUMBER] = iteration_number;
321 
322  mpScheme->InitializeNonLinIteration(BaseType::GetModelPart(), mA, mDx, mb);
324 
325  TSparseSpace::SetToZero(mA);
326  TSparseSpace::SetToZero(mb);
327  TSparseSpace::SetToZero(mDx);
328 
329  mpBuilderAndSolver->BuildAndSolve(mpScheme, BaseType::GetModelPart(), mA, mDx, mb);
330 
331  mpScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb);
332 
333  //move the mesh if needed
335 
336  mpScheme->FinalizeNonLinIteration(BaseType::GetModelPart(), mA, mDx, mb);
338 
339  NormDx = TSparseSpace::TwoNorm(mDx);
340  ReferenceDofsNorm = this->CalculateReferenceDofsNorm(rDofSet);
341  dofs_ratio = NormDx/ReferenceDofsNorm;
342  KRATOS_INFO("Newton Raphson Nonlocal Strategy") << "TEST ITERATION: " << iteration_number << std::endl;
343  KRATOS_INFO("Newton Raphson Nonlocal Strategy") << " Dofs Ratio = " << dofs_ratio << std::endl;
344 
345  if(dofs_ratio <= 1.0e-3)
346  is_converged = true;
347  }
348 
349  return is_converged;
350  }
351 
352 }; // Class PoromechanicsNewtonRaphsonNonlocalStrategy
353 
354 } // namespace Kratos
355 
356 #endif // KRATOS_POROMECHANICS_NEWTON_RAPHSON_NONLOCAL_STRATEGY defined
This is the base class to define the different convergence criterion considered.
Definition: convergence_criteria.h:58
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
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > TBuilderAndSolverType
Definition: implicit_solving_strategy.h:84
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
Definition: nonlocal_damage_2D_utilities.hpp:26
Definition: nonlocal_damage_3D_utilities.hpp:26
Definition: nonlocal_damage_utilities.hpp:36
virtual void SearchGaussPointsNeighbours(Parameters *pParameters, ModelPart &rModelPart)
Definition: nonlocal_damage_utilities.hpp:82
void CalculateNonlocalEquivalentStrain(Parameters *pParameters, const ProcessInfo &CurrentProcessInfo)
Definition: nonlocal_damage_utilities.hpp:89
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
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
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:33
PoromechanicsNewtonRaphsonNonlocalStrategy(ModelPart &model_part, typename TSchemeType::Pointer pScheme, typename TConvergenceCriteriaType::Pointer pNewConvergenceCriteria, typename TBuilderAndSolverType::Pointer pNewBuilderAndSolver, Parameters &rParameters, int MaxIterations=30, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Constructor.
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:62
BaseType::TSystemMatrixType TSystemMatrixType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:46
PoromechanicsNewtonRaphsonStrategy< TSparseSpace, TDenseSpace, TLinearSolver > MotherType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:41
bool mSearchNeighboursAtEachStep
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:278
BaseType::DofsArrayType DofsArrayType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:45
ResidualBasedNewtonRaphsonStrategy< TSparseSpace, TDenseSpace, TLinearSolver > GrandMotherType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:40
void Clear() override
Clears the internal storage.
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:256
unsigned int mMaxIterationNumber
Definition: residualbased_newton_raphson_strategy.h:1261
BaseType::TSchemeType TSchemeType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:44
TSystemVectorPointerType mpb
The increment in the solution.
Definition: residualbased_newton_raphson_strategy.h:1237
bool CheckConvergence() override
Name of the nodal variable associated to every SubModelPart.
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:282
BaseType::TBuilderAndSolverType TBuilderAndSolverType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:43
TSystemMatrixPointerType mpA
The RHS vector of the system of equations.
Definition: residualbased_newton_raphson_strategy.h:1238
bool mCalculateReactionsFlag
Flag telling if it is needed or not to compute the reactions.
Definition: residualbased_newton_raphson_strategy.h:1253
Parameters * mpParameters
Member Variables.
Definition: poromechanics_newton_raphson_strategy.hpp:165
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
TSchemeType::Pointer mpScheme
Definition: residualbased_newton_raphson_strategy.h:1232
ConvergenceCriteria< TSparseSpace, TDenseSpace > TConvergenceCriteriaType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:42
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:141
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
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:239
void Initialize() override
Initialization of member variables and prior operations.
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:86
bool mNonlocalDamageIsInitialized
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:277
NonlocalDamageUtilities * mpNonlocalDamageUtility
Member Variables.
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:276
~PoromechanicsNewtonRaphsonNonlocalStrategy() override
Destructor.
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:82
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:115
BaseType::TSystemVectorType TSystemVectorType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:47
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: poromechanics_newton_raphson_nonlocal_strategy.hpp:39
KRATOS_CLASS_POINTER_DEFINITION(PoromechanicsNewtonRaphsonNonlocalStrategy)
Definition: poromechanics_newton_raphson_strategy.hpp:35
Parameters * mpParameters
Member Variables.
Definition: poromechanics_newton_raphson_strategy.hpp:165
void Initialize() override
Initialization of member variables and prior operations.
Definition: poromechanics_newton_raphson_strategy.hpp:115
double CalculateReferenceDofsNorm(DofsArrayType &rDofSet)
Definition: poromechanics_newton_raphson_strategy.hpp:240
This is the base Newton Raphson strategy.
Definition: residualbased_newton_raphson_strategy.h:66
unsigned int mMaxIterationNumber
Definition: residualbased_newton_raphson_strategy.h:1261
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
TSchemeType::Pointer mpScheme
Definition: residualbased_newton_raphson_strategy.h:1232
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: residualbased_newton_raphson_strategy.h:781
void Clear() override
Clears the internal storage.
Definition: residualbased_newton_raphson_strategy.h:707
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
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: residualbased_newton_raphson_strategy.h:848
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
TSparseSpace::MatrixType TSystemMatrixType
Definition: solving_strategy.h:71
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
#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
ProcessInfo & GetProcessInfo(ModelPart &rModelPart)
Definition: add_model_part_to_python.cpp:54
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
model_part
Definition: face_heat.py:14
double precision function mb(a)
Definition: TensorModule.f:849