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.
explicit_hamilton_strategy.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosSolidMechanicsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: November 2015 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_EXPLICIT_HAMILTON_STRATEGY)
11 #define KRATOS_EXPLICIT_HAMILTON_STRATEGY
12 
13 /* System includes */
14 
15 
16 /* External includes */
17 //#include "boost/smart_ptr.hpp"
18 
19 
20 /* Project includes */
21 #include "includes/model_part.h"
23 
24 //default builder and solver
26 
27 
28 namespace Kratos
29 {
30 
31 template<class TSparseSpace,
32  class TDenseSpace, // = DenseSpace<double>,
33  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
34  >
36  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
37 {
38 public:
39 
43 
45 
46  typedef typename BaseType::BuilderAndSolverType BuilderAndSolverType;
47 
48  typedef TLinearSolver LinearSolverType;
49 
50  typedef TSparseSpace SparseSpaceType;
51 
52  typedef typename BaseType::SchemeType SchemeType;
53 
55 
56  typedef typename BaseType::SystemMatrixType SystemMatrixType;
57 
58  typedef typename BaseType::SystemVectorType SystemVectorType;
59 
60  typedef typename BaseType::SystemMatrixPointerType SystemMatrixPointerType;
61 
62  typedef typename BaseType::SystemVectorPointerType SystemVectorPointerType;
63 
64 
69  bool MoveMeshFlag = false
70  )
71  : ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(model_part, MoveMeshFlag)
72  {
73  }
74 
77  typename SchemeType::Pointer pScheme,
78  typename LinearSolverType::Pointer pNewLinearSolver,
79  bool CalculateReactions = false,
80  bool ReformDofSetAtEachStep = false,
81  bool MoveMeshFlag = false
82  )
83  : ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(model_part, MoveMeshFlag)
84  {
86 
87  //set flags to default values
89 
90  mReformDofSetAtEachStep = ReformDofSetAtEachStep;
91 
92  //saving the scheme
93  mpScheme = pScheme;
94 
95  //saving the linear solver
96  mpLinearSolver = pNewLinearSolver; //Not used in explicit strategies
97 
98  //setting up the default builder and solver
99  mpBuilderAndSolver = typename BuilderAndSolverType::Pointer
100  (
102  );
103 
104  //set flags to start correcty the calculations
106 
107  mInitializeWasPerformed = false;
108 
109  //set EchoLevel to the deffault value (only time is displayed)
110  SetEchoLevel(1);
111 
112  ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
113 
114  rCurrentProcessInfo[ALPHA_TRAPEZOIDAL_RULE] = 0.5; //Alpha [0,1] trapezoidal rule
115  rCurrentProcessInfo[POSITION_UPDATE_LABEL] = false;
116  rCurrentProcessInfo[ROTATION_UPDATE_LABEL] = false;
117  rCurrentProcessInfo[MOMENTUM_UPDATE_LABEL] = false;
118 
119  BaseType::SetRebuildLevel(0); //# if (BaseType::mRebuildLevel > 0) the mass matrix is rebuild
120 
121  KRATOS_CATCH( "" )
122  }
123 
127  {
128  }
129 
133  //Set and Get Scheme ... containing Builder, Update and other
134 
135  void SetScheme(typename SchemeType::Pointer pScheme)
136  {
137  mpScheme = pScheme;
138  };
139 
140  typename SchemeType::Pointer GetScheme()
141  {
142  return mpScheme;
143  };
144 
145  //Set and Get the BuilderAndSolver
146 
147  void SetBuilderAndSolver(typename BuilderAndSolverType::Pointer pNewBuilderAndSolver)
148  {
149  mpBuilderAndSolver = pNewBuilderAndSolver;
150  };
151 
152  typename BuilderAndSolverType::Pointer GetBuilderAndSolver()
153  {
154  return mpBuilderAndSolver;
155  };
156 
157  //Ser and Get Flags
158 
159  void SetInitializePerformedFlag(bool InitializePerformedFlag = true)
160  {
161  mInitializeWasPerformed = InitializePerformedFlag;
162  }
163 
165  {
167  }
168 
169  void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
170  {
171  mCalculateReactionsFlag = CalculateReactionsFlag;
172  }
173 
175  {
177  }
178 
180  {
181 
183 
184  }
185 
187  {
189  }
190 
191  //level of echo for the solving strategy
192  // 0 -> mute... no echo at all
193  // 1 -> printing time and basic informations
194  // 2 -> printing linear solver data
195  // 3 -> Print of debug informations:
196  // Echo of stiffness matrix, Dx, b...
197 
198  void SetEchoLevel(int Level)
199  {
200  BaseType::mEchoLevel = Level;
201  mpBuilderAndSolver->SetEchoLevel(Level);
202  }
203 
204  //**********************************************************************
205  //**********************************************************************
206 
207  void Initialize()
208  {
209  KRATOS_TRY
210 
211  //pointers needed in the solution
212  typename SchemeType::Pointer pScheme = GetScheme();
213  typename BuilderAndSolverType::Pointer pBuilderAndSolver = GetBuilderAndSolver();
214  ModelPart& r_model_part = BaseType::GetModelPart();
215 
216  SystemMatrixType mA = SystemMatrixType(); //dummy initialization. Not used in builder and solver.
219 
220  //Initialize The Scheme - OPERATIONS TO BE DONE ONCE
221  if (pScheme->SchemeIsInitialized() == false)
222  pScheme->Initialize(BaseType::GetModelPart());
223 
224  //Initialize The Elements - OPERATIONS TO BE DONE ONCE
225  if (pScheme->ElementsAreInitialized() == false)
226  pScheme->InitializeElements(BaseType::GetModelPart());
227 
228  //Initialize The Conditions- OPERATIONS TO BE DONE ONCE
229  if (pScheme->ConditionsAreInitialized() == false)
230  pScheme->InitializeConditions(BaseType::GetModelPart());
231 
232  pBuilderAndSolver->BuildLHS(pScheme, r_model_part, mA); //calculate and store nodal variables: NODAL_MASS and INERTIA_DYADIC
233 
235 
236  KRATOS_CATCH( "" )
237  }
238 
239  //**********************************************************************
240  //**********************************************************************
241 
243  {
244  KRATOS_TRY
245 
246  typename SchemeType::Pointer pScheme = GetScheme();
247  typename BuilderAndSolverType::Pointer pBuilderAndSolver = GetBuilderAndSolver();
248  ModelPart& r_model_part = BaseType::GetModelPart();
249 
250  SystemMatrixType mA = SystemMatrixType(); //dummy initialization. Not used in builder and solver.
253 
254  //initial operations ... things that are constant over the Solution Step
255  pScheme->InitializeSolutionStep(BaseType::GetModelPart(), mA, mDx, mb);
256 
258  {
259  pBuilderAndSolver->BuildLHS(pScheme, r_model_part, mA); //calculate and store nodal variables: NODAL_MASS and INERTIA_DYADIC
260  }
261 
262  // if(BaseType::GetModelPart().GetProcessInfo()[TIME]<=BaseType::GetModelPart().GetProcessInfo()[DELTA_TIME]){
263  // std::cout<<" INITIAL CONDITIONS:: initial exernal forces "<<std::endl;
264  // pBuilderAndSolver->BuildRHS(pScheme, BaseType::GetModelPart(), mb); //fills FORCE_RESIDUAL and MOMENT_RESIDUAL nodal variables
265  // //Position_Momentum and Rotation_Momentum Update (assign nodal contributions):
266  // DofsArrayType rDofSet; //dummy initialization. Not used in builder and solver
267  // BaseType::GetModelPart().GetProcessInfo()[POSITION_UPDATE_LABEL] = false;
268  // BaseType::GetModelPart().GetProcessInfo()[ROTATION_UPDATE_LABEL] = false;
269  // BaseType::GetModelPart().GetProcessInfo()[MOMENTUM_UPDATE_LABEL] = true;
270  // pScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb); //SECOND CALL: updates Nodal Momentum Variables ->POSITION_MOMENTUM,ROTATION_MOMENTUM :: (FORCE_RESIDUAL,MOMENT_RESIDUAL) needed -> (Scheme::mUpdateMomentumFlag = true)
271  // }
272 
274 
275  KRATOS_CATCH( "" )
276  }
277 
278 
279  //**********************************************************************
280  //**********************************************************************
281  /*
282  SOLUTION OF THE PROBLEM OF INTEREST
283  */
284  //**********************************************************************
285 
286 
287  double Solve()
288  {
289  KRATOS_TRY
290 
291  DofsArrayType rDofSet; //dummy initialization. Not used in builder and solver
295 
296  //pointers needed in the solution
297  typename SchemeType::Pointer pScheme = GetScheme();
298  typename BuilderAndSolverType::Pointer pBuilderAndSolver = GetBuilderAndSolver();
299 
300  //OPERATIONS THAT SHOULD BE DONE ONCE - internal check to avoid repetitions
301  //if the operations needed were already performed this does nothing
302  if(mInitializeWasPerformed == false)
303  Initialize();
304 
305  //prints informations about the current time
306  if (this->GetEchoLevel() != 0 && BaseType::GetModelPart().GetCommunicator().MyPID() == 0 )
307  {
308  std::cout << " " << std::endl;
309  std::cout << "CurrentTime = " << BaseType::GetModelPart().GetProcessInfo()[TIME] << std::endl;
310  }
311 
312  //initialize solution step
313  if(mSolutionStepIsInitialized == false)
315 
316  //1) Position explicit strategy:
317 
318  //1.1) Update nodal displacements:
319  bool update_at_start = false;
320  if( update_at_start ){
321  BaseType::GetModelPart().GetProcessInfo()[POSITION_UPDATE_LABEL] = true;
322  BaseType::GetModelPart().GetProcessInfo()[ROTATION_UPDATE_LABEL] = false;
323  BaseType::GetModelPart().GetProcessInfo()[MOMENTUM_UPDATE_LABEL] = false;
324  pScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb); //FIST CALL: updates Nodal Movement Variables ->DISPLACEMENT,VELOCITY,ACCELERATION (FORCE_RESIDUAL,MOMENT_RESIDUAL,POSITION_MOMENTUM) needed -> (Scheme::mUpdatePositionFlag = true)
325  }
326  //1.2) Update nodal positions: (at end)
327  //if (BaseType::MoveMeshFlag() == true) BaseType::MoveMesh();
328 
329  //2) Rotation explicit strategy (nodally implicit):
330 
331  //2.1) Build RHS and Solve nodal implicit scheme:
332  pBuilderAndSolver->BuildAndSolve(pScheme, BaseType::GetModelPart(), mA, mDx, mb); // Implicitly integrates the equation of rotation ->fills STEP_ROTATION (MOMENT_RESIDUAL,ROTATION_MOMENTUM) needed
333 
334  //2.2) Update nodal rotations:
335  BaseType::GetModelPart().GetProcessInfo()[POSITION_UPDATE_LABEL] = false;
336  BaseType::GetModelPart().GetProcessInfo()[ROTATION_UPDATE_LABEL] = true;
337  BaseType::GetModelPart().GetProcessInfo()[MOMENTUM_UPDATE_LABEL] = false;
338  pScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb); //FIST CALL: updates Nodal Movement Variables ->DISPLACEMENT,VELOCITY,ACCELERATION,ROTATION,ANGULAR_VELOCITY,ANGULAR_ACCELERATION (FORCE_RESIDUAL,MOMENT_RESIDUAL,POSITION_MOMENTUM) needed -> (Scheme::mUpdateRotationFlag = true)
339 
340  if( !update_at_start ){
341  BaseType::GetModelPart().GetProcessInfo()[POSITION_UPDATE_LABEL] = true;
342  BaseType::GetModelPart().GetProcessInfo()[ROTATION_UPDATE_LABEL] = false;
343  BaseType::GetModelPart().GetProcessInfo()[MOMENTUM_UPDATE_LABEL] = false;
344  pScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb); //FIST CALL: updates Nodal Movement Variables ->DISPLACEMENT,VELOCITY,ACCELERATION (FORCE_RESIDUAL,MOMENT_RESIDUAL,POSITION_MOMENTUM) needed -> (Scheme::mUpdatePositionFlag = true)
345  }
346 
347  //calculate reactions if required
348  //if (mCalculateReactionsFlag == true)
349  //{
350  // pBuilderAndSolver->CalculateReactions(pScheme, BaseType::GetModelPart(), mA, mDx, mb);
351  //}
352 
353  //ProcessInfo& rCurrentProcessInfo = BaseType::GetModelPart().GetProcessInfo();
354 
355  //3) Update momentum equations:
356 
357  //3.1) Build RHS (redual forces and moments update):
358  pBuilderAndSolver->BuildRHS(pScheme, BaseType::GetModelPart(), mb); //fills FORCE_RESIDUAL and MOMENT_RESIDUAL nodal variables
359 
360  //3.2) Position_Momentum and Rotation_Momentum Update (assign nodal contributions):
361  BaseType::GetModelPart().GetProcessInfo()[POSITION_UPDATE_LABEL] = false;
362  BaseType::GetModelPart().GetProcessInfo()[ROTATION_UPDATE_LABEL] = false;
363  BaseType::GetModelPart().GetProcessInfo()[MOMENTUM_UPDATE_LABEL] = true;
364  pScheme->Update(BaseType::GetModelPart(), rDofSet, mA, mDx, mb); //SECOND CALL: updates Nodal Momentum Variables ->POSITION_MOMENTUM,ROTATION_MOMENTUM :: (FORCE_RESIDUAL,MOMENT_RESIDUAL) needed -> (Scheme::mUpdateMomentumFlag = true)
365 
367 
368  //Finalisation of the solution step,
369  //operations to be done after achieving convergence, for example the
370  //Final Residual Vector (mb) has to be saved in there
371  //to avoid error accumulation
372  pScheme->FinalizeSolutionStep(BaseType::GetModelPart(), mA, mDx, mb); //FinalizeSolution step of elements and conditions
373 
374 
375  //Cleaning memory after the solution
376  pScheme->Clean();
377 
378  //reset flags for next step
380 
381  return 0.00;
382 
383  KRATOS_CATCH( "" )
384 
385  }
386 
387  //**********************************************************************
388  //**********************************************************************
389 
390  void Clear()
391  {
392  KRATOS_TRY
393  std::cout << "Explicit strategy Clear function used" << std::endl;
394 
395  //setting to zero the internal flag to ensure that the dof sets are recalculated
396  //GetBuilderAndSolver()->SetDofSetIsInitializedFlag(false);
397  //GetBuilderAndSolver()->Clear();
398 
399  GetScheme()->Clear();
400 
401  KRATOS_CATCH( "" )
402  }
403 
404 
405 
406 
435 private:
474 protected:
483  typename SchemeType::Pointer mpScheme;
484 
485  typename LinearSolverType::Pointer mpLinearSolver;
486 
487  typename BuilderAndSolverType::Pointer mpBuilderAndSolver;
488 
492 
493 
503 
510 
512 
514 
516 
517 
522  //**********************************************************************
523  //**********************************************************************
524 
525 
527  {
528 
529  }
530 
531  //**********************************************************************
532  //**********************************************************************
533 
539  int Check()
540  {
541  KRATOS_TRY
542 
543  BaseType::Check();
544 
545  GetScheme()->Check(BaseType::GetModelPart());
546 
547  return 0;
548 
549  KRATOS_CATCH( "" )
550  }
551 
552 
553 //***************************************************************************
554 //***************************************************************************
555 
556 
579  {
580  };
581 
582 
585 }; /* Class ExplicitHamiltonStrategy */
586 
595 } /* namespace Kratos.*/
596 
597 #endif /* KRATOS_EXPLICIT_HAMILTON_BEAM_STRATEGY defined */
598 
Definition: explicit_hamilton_builder_and_solver.hpp:55
Definition: explicit_hamilton_strategy.hpp:37
BaseType::SystemVectorType SystemVectorType
Definition: explicit_hamilton_strategy.hpp:58
SchemeType::Pointer mpScheme
Definition: explicit_hamilton_strategy.hpp:483
SystemVectorPointerType mpb
Definition: explicit_hamilton_strategy.hpp:490
BuilderAndSolverType::Pointer mpBuilderAndSolver
Definition: explicit_hamilton_strategy.hpp:487
BaseType::BuilderAndSolverType BuilderAndSolverType
Definition: explicit_hamilton_strategy.hpp:46
LinearSolverType::Pointer mpLinearSolver
Definition: explicit_hamilton_strategy.hpp:485
SystemMatrixPointerType mpA
Definition: explicit_hamilton_strategy.hpp:491
void SetEchoLevel(int Level)
This sets the level of echo for the solving strategy.
Definition: explicit_hamilton_strategy.hpp:198
void SetCalculateReactionsFlag(bool CalculateReactionsFlag)
Definition: explicit_hamilton_strategy.hpp:169
BuilderAndSolverType::Pointer GetBuilderAndSolver()
Definition: explicit_hamilton_strategy.hpp:152
BaseType::SystemVectorPointerType SystemVectorPointerType
Definition: explicit_hamilton_strategy.hpp:62
double Solve()
The problem of interest is solved.
Definition: explicit_hamilton_strategy.hpp:287
KRATOS_CLASS_POINTER_DEFINITION(ExplicitHamiltonStrategy)
TLinearSolver LinearSolverType
Definition: explicit_hamilton_strategy.hpp:48
BaseType::SchemeType SchemeType
Definition: explicit_hamilton_strategy.hpp:52
bool GetCalculateReactionsFlag()
Definition: explicit_hamilton_strategy.hpp:174
void SetReformDofSetAtEachStepFlag(bool flag)
Definition: explicit_hamilton_strategy.hpp:179
SystemVectorPointerType mpDx
Definition: explicit_hamilton_strategy.hpp:489
int Check()
Definition: explicit_hamilton_strategy.hpp:539
bool mReformDofSetAtEachStep
Definition: explicit_hamilton_strategy.hpp:502
void Clear()
Clears the internal storage.
Definition: explicit_hamilton_strategy.hpp:390
void SetScheme(typename SchemeType::Pointer pScheme)
Definition: explicit_hamilton_strategy.hpp:135
bool mCalculateReactionsFlag
Definition: explicit_hamilton_strategy.hpp:509
SchemeType::Pointer GetScheme()
Definition: explicit_hamilton_strategy.hpp:140
bool mComputeTime
Definition: explicit_hamilton_strategy.hpp:515
BaseType::DofsArrayType DofsArrayType
Definition: explicit_hamilton_strategy.hpp:54
BaseType::SystemMatrixPointerType SystemMatrixPointerType
Definition: explicit_hamilton_strategy.hpp:60
ExplicitHamiltonStrategy(const ExplicitHamiltonStrategy &Other)
Definition: explicit_hamilton_strategy.hpp:578
void InitializeSolutionStep()
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: explicit_hamilton_strategy.hpp:242
void SetInitializePerformedFlag(bool InitializePerformedFlag=true)
Definition: explicit_hamilton_strategy.hpp:159
TSparseSpace SparseSpaceType
Definition: explicit_hamilton_strategy.hpp:50
bool mInitializeWasPerformed
Definition: explicit_hamilton_strategy.hpp:513
ExplicitHamiltonStrategy(ModelPart &model_part, bool MoveMeshFlag=false)
Definition: explicit_hamilton_strategy.hpp:67
BaseType::SystemMatrixType SystemMatrixType
Definition: explicit_hamilton_strategy.hpp:56
ExplicitHamiltonStrategy(ModelPart &model_part, typename SchemeType::Pointer pScheme, typename LinearSolverType::Pointer pNewLinearSolver, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Definition: explicit_hamilton_strategy.hpp:75
bool GetReformDofSetAtEachStepFlag()
Definition: explicit_hamilton_strategy.hpp:186
void CalculateReactions()
Definition: explicit_hamilton_strategy.hpp:526
bool GetInitializePerformedFlag()
Definition: explicit_hamilton_strategy.hpp:164
bool mSolutionStepIsInitialized
Definition: explicit_hamilton_strategy.hpp:511
void SetBuilderAndSolver(typename BuilderAndSolverType::Pointer pNewBuilderAndSolver)
Definition: explicit_hamilton_strategy.hpp:147
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: explicit_hamilton_strategy.hpp:44
void Initialize()
Initialization of member variables and prior operations.
Definition: explicit_hamilton_strategy.hpp:207
virtual ~ExplicitHamiltonStrategy()
Definition: explicit_hamilton_strategy.hpp:126
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
void SetRebuildLevel(int Level) override
This sets the build level.
Definition: implicit_solving_strategy.h:207
int mRebuildLevel
Definition: implicit_solving_strategy.h:263
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solving_strategy.h:350
int GetEchoLevel()
This returns the level of echo for the solving strategy.
Definition: solving_strategy.h:271
virtual int Check()
Function to perform expensive checks.
Definition: solving_strategy.h:377
bool MoveMeshFlag()
This function returns the flag that says if the mesh is moved.
Definition: solving_strategy.h:290
int mEchoLevel
Definition: solving_strategy.h:485
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
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