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.
newmark_dynamic_U_Pw_scheme.hpp
Go to the documentation of this file.
1 // KRATOS___
2 // // ) )
3 // // ___ ___
4 // // ____ //___) ) // ) )
5 // // / / // // / /
6 // ((____/ / ((____ ((___/ / MECHANICS
7 //
8 // License: geo_mechanics_application/license.txt
9 //
10 // Main authors: Ignasi de Pouplana,
11 // Vahid Galavi
12 //
13 
14 #pragma once
15 
17 
18 // Application includes
21 
22 namespace Kratos
23 {
24 
25 template <class TSparseSpace, class TDenseSpace>
26 class NewmarkDynamicUPwScheme : public NewmarkQuasistaticUPwScheme<TSparseSpace, TDenseSpace>
27 {
28 public:
30 
37 
38  NewmarkDynamicUPwScheme(double beta, double gamma, double theta)
39  : NewmarkQuasistaticUPwScheme<TSparseSpace, TDenseSpace>(beta, gamma, theta)
40  {
41  // Allocate auxiliary memory
43  mMassMatrix.resize(num_threads);
44  mAccelerationVector.resize(num_threads);
45  mDampingMatrix.resize(num_threads);
46  mVelocityVector.resize(num_threads);
47  }
48 
50  {
52 
53  PredictVariables(rModelPart);
54  // Update (Angular) Acceleration, (Angular) Velocity and DtPressure
55  this->UpdateVariablesDerivatives(rModelPart);
56 
57  KRATOS_CATCH("")
58  }
59 
60  void PredictVariables(const ModelPart& rModelPart)
61  {
62  block_for_each(rModelPart.Nodes(), [this](Node& rNode) { PredictVariablesForNode(rNode); });
63  }
64 
66  {
67  for (const auto& r_second_order_vector_variable : this->GetSecondOrderVectorVariables()) {
68  if (!rNode.SolutionStepsDataHas(r_second_order_vector_variable.instance)) continue;
69  PredictVariableForNode(rNode, r_second_order_vector_variable);
70  }
71  }
72 
73  void PredictVariableForNode(Node& rNode, const SecondOrderVectorVariable& rSecondOrderVariables)
74  {
75  const std::vector<std::string> components = {"X", "Y", "Z"};
76 
77  for (const auto& component : components) {
78  const auto& instance_component =
79  this->GetComponentFromVectorVariable(rSecondOrderVariables.instance, component);
80 
81  if (!rNode.HasDofFor(instance_component)) continue;
82 
83  const auto& first_time_derivative_component = this->GetComponentFromVectorVariable(
84  rSecondOrderVariables.first_time_derivative, component);
85  const auto& second_time_derivative_component = this->GetComponentFromVectorVariable(
86  rSecondOrderVariables.second_time_derivative, component);
87 
88  const double previous_variable = rNode.FastGetSolutionStepValue(instance_component, 1);
89  const double current_first_time_derivative =
90  rNode.FastGetSolutionStepValue(first_time_derivative_component, 0);
91  const double previous_first_time_derivative =
92  rNode.FastGetSolutionStepValue(first_time_derivative_component, 1);
93  const double current_second_time_derivative =
94  rNode.FastGetSolutionStepValue(second_time_derivative_component, 0);
95  const double previous_second_time_derivative =
96  rNode.FastGetSolutionStepValue(second_time_derivative_component, 1);
97 
98  if (rNode.IsFixed(second_time_derivative_component)) {
99  rNode.FastGetSolutionStepValue(instance_component) =
100  previous_variable + this->GetDeltaTime() * previous_first_time_derivative +
101  this->GetDeltaTime() * this->GetDeltaTime() *
102  ((0.5 - this->GetBeta()) * previous_second_time_derivative +
103  this->GetBeta() * current_second_time_derivative);
104  } else if (rNode.IsFixed(first_time_derivative_component)) {
105  rNode.FastGetSolutionStepValue(instance_component) =
106  previous_variable +
107  this->GetDeltaTime() * ((this->GetBeta() / this->GetGamma()) *
108  (current_first_time_derivative - previous_first_time_derivative) +
109  previous_first_time_derivative);
110  } else if (!rNode.IsFixed(instance_component)) {
111  rNode.FastGetSolutionStepValue(instance_component) =
112  previous_variable + this->GetDeltaTime() * previous_first_time_derivative +
113  0.5 * this->GetDeltaTime() * this->GetDeltaTime() * previous_second_time_derivative;
114  }
115  }
116  }
117 
118  void CalculateSystemContributions(Condition& rCurrentCondition,
119  LocalSystemMatrixType& LHS_Contribution,
120  LocalSystemVectorType& RHS_Contribution,
122  const ProcessInfo& CurrentProcessInfo) override
123  {
124  KRATOS_TRY
125 
126  int thread = OpenMPUtils::ThisThread();
127 
128  rCurrentCondition.CalculateLocalSystem(LHS_Contribution, RHS_Contribution, CurrentProcessInfo);
129 
130  rCurrentCondition.CalculateMassMatrix(mMassMatrix[thread], CurrentProcessInfo);
131 
132  rCurrentCondition.CalculateDampingMatrix(mDampingMatrix[thread], CurrentProcessInfo);
133 
134  this->AddDynamicsToLHS(LHS_Contribution, mMassMatrix[thread], mDampingMatrix[thread], CurrentProcessInfo);
135 
136  this->AddDynamicsToRHS(rCurrentCondition, RHS_Contribution, mMassMatrix[thread],
137  mDampingMatrix[thread], CurrentProcessInfo);
138 
139  rCurrentCondition.EquationIdVector(EquationId, CurrentProcessInfo);
140 
141  KRATOS_CATCH("")
142  }
143 
144  void CalculateSystemContributions(Element& rCurrentElement,
145  LocalSystemMatrixType& LHS_Contribution,
146  LocalSystemVectorType& RHS_Contribution,
148  const ProcessInfo& CurrentProcessInfo) override
149  {
150  KRATOS_TRY
151 
152  int thread = OpenMPUtils::ThisThread();
153 
154  rCurrentElement.CalculateLocalSystem(LHS_Contribution, RHS_Contribution, CurrentProcessInfo);
155 
156  rCurrentElement.CalculateMassMatrix(mMassMatrix[thread], CurrentProcessInfo);
157 
158  rCurrentElement.CalculateDampingMatrix(mDampingMatrix[thread], CurrentProcessInfo);
159 
160  this->AddDynamicsToLHS(LHS_Contribution, mMassMatrix[thread], mDampingMatrix[thread], CurrentProcessInfo);
161 
162  this->AddDynamicsToRHS(rCurrentElement, RHS_Contribution, mMassMatrix[thread],
163  mDampingMatrix[thread], CurrentProcessInfo);
164 
165  rCurrentElement.EquationIdVector(EquationId, CurrentProcessInfo);
166 
167  KRATOS_CATCH("")
168  }
169 
170  void CalculateRHSContribution(Element& rCurrentElement,
171  LocalSystemVectorType& RHS_Contribution,
173  const ProcessInfo& CurrentProcessInfo) override
174  {
175  KRATOS_TRY
176 
177  int thread = OpenMPUtils::ThisThread();
178 
179  rCurrentElement.CalculateRightHandSide(RHS_Contribution, CurrentProcessInfo);
180 
181  rCurrentElement.CalculateMassMatrix(mMassMatrix[thread], CurrentProcessInfo);
182 
183  rCurrentElement.CalculateDampingMatrix(mDampingMatrix[thread], CurrentProcessInfo);
184 
185  this->AddDynamicsToRHS(rCurrentElement, RHS_Contribution, mMassMatrix[thread],
186  mDampingMatrix[thread], CurrentProcessInfo);
187 
188  rCurrentElement.EquationIdVector(EquationId, CurrentProcessInfo);
189 
190  KRATOS_CATCH("")
191  }
192 
193  void CalculateRHSContribution(Condition& rCurrentCondition,
194  LocalSystemVectorType& rRHS_Contribution,
195  Element::EquationIdVectorType& rEquationIds,
196  const ProcessInfo& rCurrentProcessInfo) override
197  {
198  KRATOS_TRY
199 
200  int thread = OpenMPUtils::ThisThread();
201 
202  rCurrentCondition.CalculateRightHandSide(rRHS_Contribution, rCurrentProcessInfo);
203 
204  rCurrentCondition.CalculateMassMatrix(mMassMatrix[thread], rCurrentProcessInfo);
205 
206  rCurrentCondition.CalculateDampingMatrix(mDampingMatrix[thread], rCurrentProcessInfo);
207 
208  this->AddDynamicsToRHS(rCurrentCondition, rRHS_Contribution, mMassMatrix[thread],
209  mDampingMatrix[thread], rCurrentProcessInfo);
210 
211  rCurrentCondition.EquationIdVector(rEquationIds, rCurrentProcessInfo);
212 
213  KRATOS_CATCH("")
214  }
215 
216  void CalculateLHSContribution(Condition& rCurrentCondition,
217  LocalSystemMatrixType& LHS_Contribution,
219  const ProcessInfo& CurrentProcessInfo) override
220  {
221  KRATOS_TRY
222 
223  int thread = OpenMPUtils::ThisThread();
224 
225  rCurrentCondition.CalculateLeftHandSide(LHS_Contribution, CurrentProcessInfo);
226 
227  rCurrentCondition.CalculateMassMatrix(mMassMatrix[thread], CurrentProcessInfo);
228 
229  rCurrentCondition.CalculateDampingMatrix(mDampingMatrix[thread], CurrentProcessInfo);
230 
231  this->AddDynamicsToLHS(LHS_Contribution, mMassMatrix[thread], mDampingMatrix[thread], CurrentProcessInfo);
232 
233  rCurrentCondition.EquationIdVector(EquationId, CurrentProcessInfo);
234 
235  KRATOS_CATCH("")
236  }
237 
238  void CalculateLHSContribution(Element& rCurrentElement,
239  LocalSystemMatrixType& LHS_Contribution,
241  const ProcessInfo& CurrentProcessInfo) override
242  {
243  KRATOS_TRY
244 
245  int thread = OpenMPUtils::ThisThread();
246 
247  rCurrentElement.CalculateLeftHandSide(LHS_Contribution, CurrentProcessInfo);
248 
249  rCurrentElement.CalculateMassMatrix(mMassMatrix[thread], CurrentProcessInfo);
250 
251  rCurrentElement.CalculateDampingMatrix(mDampingMatrix[thread], CurrentProcessInfo);
252 
253  this->AddDynamicsToLHS(LHS_Contribution, mMassMatrix[thread], mDampingMatrix[thread], CurrentProcessInfo);
254 
255  rCurrentElement.EquationIdVector(EquationId, CurrentProcessInfo);
256 
257  KRATOS_CATCH("")
258  }
259 
260 protected:
261  void AddDynamicsToLHS(LocalSystemMatrixType& LHS_Contribution,
264  const ProcessInfo& CurrentProcessInfo)
265  {
266  KRATOS_TRY
267 
268  // adding mass contribution
269  if (M.size1() != 0)
270  noalias(LHS_Contribution) +=
271  (1.0 / (this->GetBeta() * this->GetDeltaTime() * this->GetDeltaTime())) * M;
272 
273  // adding damping contribution
274  if (C.size1() != 0)
275  noalias(LHS_Contribution) += (this->GetGamma() / (this->GetBeta() * this->GetDeltaTime())) * C;
276 
277  KRATOS_CATCH("")
278  }
279 
280  void AddDynamicsToRHS(Condition& rCurrentCondition,
281  LocalSystemVectorType& RHS_Contribution,
284  const ProcessInfo& CurrentProcessInfo)
285  {
286  KRATOS_TRY
287 
288  int thread = OpenMPUtils::ThisThread();
289 
290  // adding inertia contribution
291  if (M.size1() != 0) {
292  rCurrentCondition.GetSecondDerivativesVector(mAccelerationVector[thread], 0);
293  noalias(RHS_Contribution) -= prod(M, mAccelerationVector[thread]);
294  }
295 
296  // adding damping contribution
297  if (C.size1() != 0) {
298  rCurrentCondition.GetFirstDerivativesVector(mVelocityVector[thread], 0);
299  noalias(RHS_Contribution) -= prod(C, mVelocityVector[thread]);
300  }
301 
302  KRATOS_CATCH("")
303  }
304 
305  void AddDynamicsToRHS(Element& rCurrentElement,
306  LocalSystemVectorType& RHS_Contribution,
309  const ProcessInfo& CurrentProcessInfo)
310  {
311  KRATOS_TRY
312 
313  int thread = OpenMPUtils::ThisThread();
314 
315  // adding inertia contribution
316  if (M.size1() != 0) {
317  rCurrentElement.GetSecondDerivativesVector(mAccelerationVector[thread], 0);
318  noalias(RHS_Contribution) -= prod(M, mAccelerationVector[thread]);
319  }
320 
321  // adding damping contribution
322  if (C.size1() != 0) {
323  rCurrentElement.GetFirstDerivativesVector(mVelocityVector[thread], 0);
324  noalias(RHS_Contribution) -= prod(C, mVelocityVector[thread]);
325  }
326 
327  KRATOS_CATCH("")
328  }
329 
330 private:
331  std::vector<Matrix> mMassMatrix;
332  std::vector<Vector> mAccelerationVector;
333  std::vector<Matrix> mDampingMatrix;
334  std::vector<Vector> mVelocityVector;
335 }; // Class NewmarkDynamicUPwScheme
336 
337 } // namespace Kratos
Base class for all Conditions.
Definition: condition.h:59
virtual void GetSecondDerivativesVector(Vector &values, int Step=0) const
Definition: condition.h:323
virtual void GetFirstDerivativesVector(Vector &values, int Step=0) const
Definition: condition.h:313
virtual void CalculateLeftHandSide(MatrixType &rLeftHandSideMatrix, const ProcessInfo &rCurrentProcessInfo)
Definition: condition.h:426
virtual void CalculateMassMatrix(MatrixType &rMassMatrix, const ProcessInfo &rCurrentProcessInfo)
Definition: condition.h:574
virtual void CalculateDampingMatrix(MatrixType &rDampingMatrix, const ProcessInfo &rCurrentProcessInfo)
Definition: condition.h:586
virtual void EquationIdVector(EquationIdVectorType &rResult, const ProcessInfo &rCurrentProcessInfo) const
Definition: condition.h:260
virtual void CalculateRightHandSide(VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo)
Definition: condition.h:440
virtual void CalculateLocalSystem(MatrixType &rLeftHandSideMatrix, VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo)
Definition: condition.h:408
Base class for all Elements.
Definition: element.h:60
virtual void GetFirstDerivativesVector(Vector &values, int Step=0) const
Definition: element.h:310
virtual void CalculateLeftHandSide(MatrixType &rLeftHandSideMatrix, const ProcessInfo &rCurrentProcessInfo)
Definition: element.h:423
virtual void CalculateMassMatrix(MatrixType &rMassMatrix, const ProcessInfo &rCurrentProcessInfo)
Definition: element.h:570
virtual void CalculateRightHandSide(VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo)
Definition: element.h:437
virtual void CalculateDampingMatrix(MatrixType &rDampingMatrix, const ProcessInfo &rCurrentProcessInfo)
Definition: element.h:583
virtual void EquationIdVector(EquationIdVectorType &rResult, const ProcessInfo &rCurrentProcessInfo) const
Definition: element.h:258
virtual void GetSecondDerivativesVector(Vector &values, int Step=0) const
Definition: element.h:320
virtual void CalculateLocalSystem(MatrixType &rLeftHandSideMatrix, VectorType &rRightHandSideVector, const ProcessInfo &rCurrentProcessInfo)
Definition: element.h:405
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
double GetGamma() const
Definition: generalized_newmark_scheme.hpp:96
void UpdateVariablesDerivatives(ModelPart &rModelPart) override
Definition: generalized_newmark_scheme.hpp:57
double GetBeta() const
Definition: generalized_newmark_scheme.hpp:94
void EquationId(const Element &rElement, Element::EquationIdVectorType &rEquationId, const ProcessInfo &rCurrentProcessInfo) override
This method gets the eqaution id corresponding to the current element.
Definition: geomechanics_time_integration_scheme.hpp:96
double GetDeltaTime() const
Definition: geomechanics_time_integration_scheme.hpp:331
const Variable< double > & GetComponentFromVectorVariable(const Variable< array_1d< double, 3 >> &rSource, const std::string &rComponent) const
Definition: geomechanics_time_integration_scheme.hpp:318
const std::vector< SecondOrderVectorVariable > & GetSecondOrderVectorVariables() const
Definition: geomechanics_time_integration_scheme.hpp:333
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
Definition: newmark_dynamic_U_Pw_scheme.hpp:27
void CalculateSystemContributions(Condition &rCurrentCondition, LocalSystemMatrixType &LHS_Contribution, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId, const ProcessInfo &CurrentProcessInfo) override
Functions totally analogous to the precedent but applied to the "condition" objects.
Definition: newmark_dynamic_U_Pw_scheme.hpp:118
void CalculateSystemContributions(Element &rCurrentElement, LocalSystemMatrixType &LHS_Contribution, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId, const ProcessInfo &CurrentProcessInfo) override
This function is designed to be called in the builder and solver to introduce the selected time integ...
Definition: newmark_dynamic_U_Pw_scheme.hpp:144
void AddDynamicsToRHS(Element &rCurrentElement, LocalSystemVectorType &RHS_Contribution, LocalSystemMatrixType &M, LocalSystemMatrixType &C, const ProcessInfo &CurrentProcessInfo)
Definition: newmark_dynamic_U_Pw_scheme.hpp:305
void CalculateRHSContribution(Condition &rCurrentCondition, LocalSystemVectorType &rRHS_Contribution, Element::EquationIdVectorType &rEquationIds, const ProcessInfo &rCurrentProcessInfo) override
Functions totally analogous to the precedent but applied to the "condition" objects.
Definition: newmark_dynamic_U_Pw_scheme.hpp:193
NewmarkDynamicUPwScheme(double beta, double gamma, double theta)
Definition: newmark_dynamic_U_Pw_scheme.hpp:38
void CalculateLHSContribution(Condition &rCurrentCondition, LocalSystemMatrixType &LHS_Contribution, Element::EquationIdVectorType &EquationId, const ProcessInfo &CurrentProcessInfo) override
Functions totally analogous to the precedent but applied to the "condition" objects.
Definition: newmark_dynamic_U_Pw_scheme.hpp:216
void Predict(ModelPart &rModelPart, DofsArrayType &rDofSet, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Performing the prediction of the solution.
Definition: newmark_dynamic_U_Pw_scheme.hpp:49
void CalculateRHSContribution(Element &rCurrentElement, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId, const ProcessInfo &CurrentProcessInfo) override
This function is designed to calculate just the RHS contribution.
Definition: newmark_dynamic_U_Pw_scheme.hpp:170
void PredictVariables(const ModelPart &rModelPart)
Definition: newmark_dynamic_U_Pw_scheme.hpp:60
void AddDynamicsToRHS(Condition &rCurrentCondition, LocalSystemVectorType &RHS_Contribution, LocalSystemMatrixType &M, LocalSystemMatrixType &C, const ProcessInfo &CurrentProcessInfo)
Definition: newmark_dynamic_U_Pw_scheme.hpp:280
void AddDynamicsToLHS(LocalSystemMatrixType &LHS_Contribution, LocalSystemMatrixType &M, LocalSystemMatrixType &C, const ProcessInfo &CurrentProcessInfo)
Definition: newmark_dynamic_U_Pw_scheme.hpp:261
void PredictVariablesForNode(Node &rNode)
Definition: newmark_dynamic_U_Pw_scheme.hpp:65
void PredictVariableForNode(Node &rNode, const SecondOrderVectorVariable &rSecondOrderVariables)
Definition: newmark_dynamic_U_Pw_scheme.hpp:73
KRATOS_CLASS_POINTER_DEFINITION(NewmarkDynamicUPwScheme)
void CalculateLHSContribution(Element &rCurrentElement, LocalSystemMatrixType &LHS_Contribution, Element::EquationIdVectorType &EquationId, const ProcessInfo &CurrentProcessInfo) override
This function is designed to calculate just the LHS contribution.
Definition: newmark_dynamic_U_Pw_scheme.hpp:238
Definition: newmark_quasistatic_U_Pw_scheme.hpp:27
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
bool HasDofFor(const VariableData &rDofVariable) const
Definition: node.h:887
bool SolutionStepsDataHas(const VariableData &rThisVariable) const
Definition: node.h:427
bool IsFixed(const VariableData &rDofVariable) const
Definition: node.h:897
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
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
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
typename TSparseSpace::MatrixType TSystemMatrixType
Matrix type definition.
Definition: scheme.h:71
typename TSparseSpace::VectorType TSystemVectorType
Vector type definition.
Definition: scheme.h:74
typename TDenseSpace::VectorType LocalSystemVectorType
Local system vector type definition.
Definition: scheme.h:80
ModelPart::DofsArrayType DofsArrayType
DoF array type definition.
Definition: scheme.h:86
typename TDenseSpace::MatrixType LocalSystemMatrixType
Local system matrix type definition.
Definition: scheme.h:77
#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
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
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
int C
Definition: generate_hyper_elastic_simo_taylor_neo_hookean.py:27
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
float gamma
Definition: generate_two_fluid_navier_stokes.py:131
def num_threads
Definition: script.py:75
A
Definition: sensitivityMatrix.py:70
Definition: geomechanics_time_integration_scheme.hpp:35
Variable< array_1d< double, 3 > > instance
Definition: geomechanics_time_integration_scheme.hpp:36
Variable< array_1d< double, 3 > > first_time_derivative
Definition: geomechanics_time_integration_scheme.hpp:37
Variable< array_1d< double, 3 > > second_time_derivative
Definition: geomechanics_time_integration_scheme.hpp:38