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.
mpm_explicit_strategy.hpp
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: Peter Wilson (thanks Klaus Sautter)
11 //
12 //
13 
14 
15 #if !defined(KRATOS_MPM_EXPLICIT_STRATEGY )
16 #define KRATOS_MPM_EXPLICIT_STRATEGY
17 
18 // System includes
19 
20 // External includes
21 
22 // Project includes
23 #include "includes/define.h"
24 #include "includes/model_part.h"
26 #include "includes/kratos_flags.h"
28 
29 // Application includes
31 
32 namespace Kratos
33 {
35 
41  template<class TSparseSpace,
42  class TDenseSpace,
43  class TLinearSolver
44  >
46  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
47  {
48  public:
50 
52 
53  typedef typename BaseType::TDataType TDataType;
54 
55  typedef TSparseSpace SparseSpaceType;
56 
58 
60 
62 
64 
66 
68 
71 
73 
75 
77 
80  typename TSchemeType::Pointer pScheme,
81  bool CalculateReactions = false,
82  bool ReformDofSetAtEachStep = false,
83  bool MoveMeshFlag = false
84  )
85  : ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(model_part, MoveMeshFlag),
86  mpScheme(pScheme),
87  mReformDofSetAtEachStep(ReformDofSetAtEachStep),
89  {
91 
95  mFinalizeSolutionStep = true;
96  // Set EchoLevel to the default value (only time is displayed)
97  this->SetEchoLevel(1);
98  // By default the matrices are rebuilt at each solution step
99  this->SetRebuildLevel(1);
100 
101  KRATOS_CATCH("")
102  }
103 
106  {
107  }
108 
109 
110  //Set and Get Scheme ... containing Builder, Update and other
111  void SetScheme(typename TSchemeType::Pointer pScheme)
112  {
113  mpScheme = pScheme;
114  };
115 
116  typename TSchemeType::Pointer GetScheme()
117  {
118  return mpScheme;
119  };
120 
122  void Initialize() override
123  {
124  KRATOS_TRY
125 
126  typename TSchemeType::Pointer pScheme = GetScheme();
127 
128  // OPERATIONS THAT SHOULD BE DONE ONCE - internal check to avoid repetitions
129  // if the operations needed were already performed this does nothing
130  if (mInitializeWasPerformed == false)
131  {
132  KRATOS_INFO_IF("MPM_Explicit_Strategy", this->GetEchoLevel() > 1) << "Initializing solving strategy" << std::endl;
133  KRATOS_ERROR_IF(mInitializeWasPerformed == true) << "Initialization was already performed " << mInitializeWasPerformed << std::endl;
134 
135  // Initialize The Scheme - OPERATIONS TO BE DONE ONCE
136  KRATOS_INFO_IF("MPM_Explicit_Strategy", this->GetEchoLevel() > 1) << "Initializing scheme" << std::endl;
137  if (pScheme->SchemeIsInitialized() == false)
138  pScheme->Initialize(BaseType::GetModelPart());
139 
140  // Initialize The Elements - OPERATIONS TO BE DONE ONCE
141  KRATOS_INFO_IF("MPM_Explicit_Strategy", this->GetEchoLevel() > 1) << "Initializing elements" << std::endl;
142  if (pScheme->ElementsAreInitialized() == false)
143  pScheme->InitializeElements(BaseType::GetModelPart());
144 
145  // Initialize The Conditions - OPERATIONS TO BE DONE ONCE
146  KRATOS_INFO_IF("MPM_Explicit_Strategy", this->GetEchoLevel() > 1) << "Initializing conditions" << std::endl;
147  if (pScheme->ConditionsAreInitialized() == false)
148  pScheme->InitializeConditions(BaseType::GetModelPart());
149 
151  }
152 
153  // Prints informations about the current time
154  KRATOS_INFO_IF("MPM_Explicit_Strategy", this->GetEchoLevel() == 2) << "CurrentTime = " << BaseType::GetModelPart().GetProcessInfo()[TIME] << std::endl;
155 
156  KRATOS_CATCH("")
157  }
158 
159  void InitializeSolutionStep() override
160  {
161  KRATOS_TRY
162 
163  // Initialize solution step
165  {
166  typename TSchemeType::Pointer pScheme = GetScheme();
170 
171  // Initial operations ... things that are constant over the Solution Step
172  pScheme->InitializeSolutionStep(BaseType::GetModelPart(), mA, mDx, mb);
173  }
174 
176 
177  KRATOS_INFO_IF("MPM_Explicit_Strategy", this->GetEchoLevel() >= 3) << "Initialize Solution Step in strategy finished" << std::endl;
178 
179  KRATOS_CATCH("")
180  }
181 
182 
184  bool SolveSolutionStep() override
185  {
186  typename TSchemeType::Pointer pScheme = GetScheme();
187  DofsArrayType dof_set_dummy;
191 
192  // Compute residual forces on the model part
193  this->CalculateAndAddRHS(pScheme, BaseType::GetModelPart());
194  pScheme->Update(BaseType::GetModelPart(), dof_set_dummy, mA, mDx, mb);
195 
196  // Calculate reactions if required
198 
199  return true;
200  }
201 
202  //**********************************************************************
203  //**********************************************************************
204 
205  void Clear() override
206  {
207  KRATOS_TRY
208  GetScheme()->Clear();
209 
210  KRATOS_CATCH("")
211  }
212 
214  {
216  }
217 
219  {
221  }
222 
223  private:
224 
225  protected:
229  typename TSchemeType::Pointer mpScheme;
230 
240 
243 
245 
247 
250 
253 
254  //**********************************************************************
255  //**********************************************************************
256 
257  void FinalizeSolutionStep() override
258  {
259  KRATOS_TRY
260  typename TSchemeType::Pointer pScheme = GetScheme();
264 
265  /*Finalization of the solution step,
266  operations to be done after achieving convergence, for example the
267  Final Residual Vector (mb) has to be saved in there
268  to avoid error accumulation*/
270  {
271  KRATOS_INFO_IF("MPM_Explicit_Strategy", this->GetEchoLevel() >= 3) << "Calling FinalizeSolutionStep" << std::endl;
272 
273  pScheme->FinalizeSolutionStep(BaseType::GetModelPart(), mA, mDx, mb);
275  }
276 
277  // Cleaning memory after the solution
278  pScheme->Clean();
279 
280  // Reset flags for next step
282  KRATOS_CATCH("")
283  }
284 
289  int Check() override
290  {
291  KRATOS_TRY
292 
293  BaseType::Check();
294  GetScheme()->Check(BaseType::GetModelPart());
295  return 0;
296 
297  KRATOS_CATCH("")
298  }
299 
300 
302  typename TSchemeType::Pointer pScheme,
303  ModelPart& rModelPart
304  )
305  {
306  KRATOS_TRY
307 
308  ConditionsArrayType& r_conditions = rModelPart.Conditions();
309  ElementsArrayType& r_elements = rModelPart.Elements();
310 
311  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
312  Element::EquationIdVectorType equation_id_vector_dummy; // Dummy
313 
314  #pragma omp parallel for firstprivate(RHS_Contribution, equation_id_vector_dummy), schedule(guided,512)
315  for (int i = 0; i < static_cast<int>(r_conditions.size()); ++i) {
316  auto it_cond = r_conditions.begin() + i;
317  pScheme->CalculateRHSContribution(*it_cond, RHS_Contribution, equation_id_vector_dummy, rModelPart.GetProcessInfo());
318  }
319 
320  #pragma omp parallel for firstprivate(RHS_Contribution, equation_id_vector_dummy), schedule(guided,512)
321  for (int i = 0; i < static_cast<int>(r_elements.size()); ++i) {
322  auto it_elem = r_elements.begin() + i;
323  pScheme->CalculateRHSContribution(*it_elem, RHS_Contribution, equation_id_vector_dummy, rModelPart.GetProcessInfo());
324  }
325 
326  KRATOS_CATCH("")
327  }
328 
329 
331  typename TSchemeType::Pointer pScheme,
332  ModelPart& rModelPart,
333  TSystemMatrixType& rA,
334  TSystemVectorType& rDx,
336  )
337  {
338  // We iterate over the nodes
339  auto& r_nodes = rModelPart.Nodes();
340 
341  // If we consider rotation dofs
342  const bool has_dof_for_rot_z = (r_nodes.begin())->HasDofFor(ROTATION_Z);
343 
344  // Auxiliar values
345  const array_1d<double, 3> zero_array = ZeroVector(3);
346  array_1d<double, 3> force_residual = ZeroVector(3);
347  array_1d<double, 3> moment_residual = ZeroVector(3);
348 
349  // Getting
350  const auto it_node_begin = r_nodes.begin();
351  const IndexType disppos = it_node_begin->GetDofPosition(DISPLACEMENT_X);
352  const IndexType rotppos = it_node_begin->GetDofPosition(ROTATION_X);
353 
354  // Iterating nodes
355  #pragma omp parallel for firstprivate(force_residual, moment_residual), schedule(guided,512)
356  for (int i = 0; i < static_cast<int>(r_nodes.size()); ++i) {
357  auto it_node = it_node_begin + i;
358 
359  noalias(force_residual) = it_node->FastGetSolutionStepValue(FORCE_RESIDUAL);
360  if (has_dof_for_rot_z) {
361  noalias(moment_residual) = it_node->FastGetSolutionStepValue(MOMENT_RESIDUAL);
362  }
363  else {
364  noalias(moment_residual) = zero_array;
365  }
366 
367  if (it_node->GetDof(DISPLACEMENT_X, disppos).IsFixed()) {
368  double& r_reaction = it_node->FastGetSolutionStepValue(REACTION_X);
369  r_reaction = force_residual[0];
370  }
371  if (it_node->GetDof(DISPLACEMENT_Y, disppos + 1).IsFixed()) {
372  double& r_reaction = it_node->FastGetSolutionStepValue(REACTION_Y);
373  r_reaction = force_residual[1];
374  }
375  if (it_node->GetDof(DISPLACEMENT_Z, disppos + 2).IsFixed()) {
376  double& r_reaction = it_node->FastGetSolutionStepValue(REACTION_Z);
377  r_reaction = force_residual[2];
378  }
379  if (has_dof_for_rot_z) {
380  if (it_node->GetDof(ROTATION_X, rotppos).IsFixed()) {
381  double& r_reaction = it_node->FastGetSolutionStepValue(REACTION_MOMENT_X);
382  r_reaction = moment_residual[0];
383  }
384  if (it_node->GetDof(ROTATION_Y, rotppos + 1).IsFixed()) {
385  double& r_reaction = it_node->FastGetSolutionStepValue(REACTION_MOMENT_Y);
386  r_reaction = moment_residual[1];
387  }
388  if (it_node->GetDof(ROTATION_Z, rotppos + 2).IsFixed()) {
389  double& r_reaction = it_node->FastGetSolutionStepValue(REACTION_MOMENT_Z);
390  r_reaction = moment_residual[2];
391  }
392  }
393  }
394  }
395 
398  {
399  };
400  }; // Class MPMExplicitStrategy
401 }; // namespace Kratos
402 
403 #endif // KRATOS_MPM_EXPLICIT_STRATEGY defined
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
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
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: implicit_solving_strategy.h:80
BaseType::ConditionsArrayType ConditionsArrayType
Definition: implicit_solving_strategy.h:96
BaseType::TSystemMatrixType TSystemMatrixType
Definition: implicit_solving_strategy.h:70
BaseType::ElementsArrayType ElementsArrayType
Definition: implicit_solving_strategy.h:94
Short class definition.
Definition: mpm_explicit_strategy.hpp:47
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: mpm_explicit_strategy.hpp:67
TSparseSpace SparseSpaceType
Definition: mpm_explicit_strategy.hpp:55
BaseType::TSystemVectorType TSystemVectorType
Definition: mpm_explicit_strategy.hpp:63
void InitializeSolutionStep() override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: mpm_explicit_strategy.hpp:159
MPMExplicitStrategy(const MPMExplicitStrategy &Other)
Copy constructor.
Definition: mpm_explicit_strategy.hpp:397
virtual ~MPMExplicitStrategy()
Destructor.
Definition: mpm_explicit_strategy.hpp:105
void Clear() override
Clears the internal storage.
Definition: mpm_explicit_strategy.hpp:205
void SetScheme(typename TSchemeType::Pointer pScheme)
Definition: mpm_explicit_strategy.hpp:111
void SetKeepSystemConstantDuringIterations(bool value)
Definition: mpm_explicit_strategy.hpp:213
bool mInitializeWasPerformed
Definition: mpm_explicit_strategy.hpp:246
bool GetKeepSystemConstantDuringIterations()
Definition: mpm_explicit_strategy.hpp:218
TSchemeType::Pointer GetScheme()
Definition: mpm_explicit_strategy.hpp:116
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: mpm_explicit_strategy.hpp:51
bool mFinalizeSolutionStep
flag to allow to not finalize the solution step, so the historical variables are not updated
Definition: mpm_explicit_strategy.hpp:252
int Check() override
Definition: mpm_explicit_strategy.hpp:289
BaseType::TSchemeType TSchemeType
Definition: mpm_explicit_strategy.hpp:57
KRATOS_CLASS_POINTER_DEFINITION(MPMExplicitStrategy)
bool mSolutionStepIsInitialized
Definition: mpm_explicit_strategy.hpp:244
BaseType::ElementsArrayType ElementsArrayType
Definition: mpm_explicit_strategy.hpp:72
MPMExplicitStrategy(ModelPart &model_part, typename TSchemeType::Pointer pScheme, bool CalculateReactions=false, bool ReformDofSetAtEachStep=false, bool MoveMeshFlag=false)
Definition: mpm_explicit_strategy.hpp:78
BaseType::TSystemMatrixType TSystemMatrixType
Definition: mpm_explicit_strategy.hpp:61
BaseType::DofsArrayType DofsArrayType
Definition: mpm_explicit_strategy.hpp:59
void CalculateAndAddRHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart)
Definition: mpm_explicit_strategy.hpp:301
BaseType::NodesArrayType NodesArrayType
Definition: mpm_explicit_strategy.hpp:74
bool mReformDofSetAtEachStep
Definition: mpm_explicit_strategy.hpp:239
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: mpm_explicit_strategy.hpp:65
BaseType::ConditionsArrayType ConditionsArrayType
Definition: mpm_explicit_strategy.hpp:76
bool SolveSolutionStep() override
the problem of interest is solved
Definition: mpm_explicit_strategy.hpp:184
void CalculateReactions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb)
Definition: mpm_explicit_strategy.hpp:330
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: mpm_explicit_strategy.hpp:70
bool mCalculateReactionsFlag
Flag telling if it is needed or not to compute the reactions, default = true.
Definition: mpm_explicit_strategy.hpp:242
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: mpm_explicit_strategy.hpp:69
TSchemeType::Pointer mpScheme
Definition: mpm_explicit_strategy.hpp:229
void Initialize() override
Initialize members.
Definition: mpm_explicit_strategy.hpp:122
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: mpm_explicit_strategy.hpp:257
BaseType::TDataType TDataType
Definition: mpm_explicit_strategy.hpp:53
bool mKeepSystemConstantDuringIterations
flag to allow keeping system matrix constant during iterations
Definition: mpm_explicit_strategy.hpp:249
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
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
TSparseSpace::VectorPointerType TSystemVectorPointerType
Definition: solving_strategy.h:77
TDenseSpace::MatrixType LocalSystemMatrixType
Definition: solving_strategy.h:79
ModelPart::NodesContainerType NodesArrayType
Definition: solving_strategy.h:89
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
ModelPart::ElementsContainerType ElementsArrayType
Definition: solving_strategy.h:91
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
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: solving_strategy.h:93
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_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
model_part
Definition: face_heat.py:14
integer i
Definition: TensorModule.f:17
double precision function mb(a)
Definition: TensorModule.f:849