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.
generalized_newmark_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: Richard Faasse
11 //
12 #pragma once
13 
15 #include <optional>
16 
17 namespace Kratos
18 {
19 
20 template <class TSparseSpace, class TDenseSpace>
21 class GeneralizedNewmarkScheme : public GeoMechanicsTimeIntegrationScheme<TSparseSpace, TDenseSpace>
22 {
23 public:
24  GeneralizedNewmarkScheme(const std::vector<FirstOrderScalarVariable>& rFirstOrderScalarVariables,
25  const std::vector<SecondOrderVectorVariable>& rSecondOrderVectorVariables,
26  std::optional<double> theta,
27  std::optional<double> beta,
28  std::optional<double> gamma)
29  : GeoMechanicsTimeIntegrationScheme<TSparseSpace, TDenseSpace>(rFirstOrderScalarVariables,
30  rSecondOrderVectorVariables),
31  mTheta(theta),
32  mBeta(beta),
33  mGamma(gamma)
34  {
35  KRATOS_ERROR_IF(!rFirstOrderScalarVariables.empty() && !mTheta.has_value())
36  << "Theta must be set when first order scalar variables are used\n";
37  KRATOS_ERROR_IF(!rSecondOrderVectorVariables.empty() && !mBeta.has_value())
38  << "Beta must be set when second order vector variables are used\n";
39  KRATOS_ERROR_IF(!rSecondOrderVectorVariables.empty() && !mGamma.has_value())
40  << "Gamma must be set when second order vector variables are used\n";
41 
42  KRATOS_ERROR_IF(mTheta.has_value() && mTheta.value() <= 0)
43  << "Theta must be larger than zero, but got " << mTheta.value() << "\n";
44  KRATOS_ERROR_IF(mBeta.has_value() && mBeta.value() <= 0)
45  << "Beta must be larger than zero, but got " << mBeta.value() << "\n";
46  KRATOS_ERROR_IF(mGamma.has_value() && mGamma.value() <= 0)
47  << "Gamma must be larger than zero, but got " << mGamma.value() << "\n";
48  }
49 
50  GeneralizedNewmarkScheme(const std::vector<FirstOrderScalarVariable>& rFirstOrderScalarVariables, double theta)
51  : GeneralizedNewmarkScheme<TSparseSpace, TDenseSpace>(
52  rFirstOrderScalarVariables, {}, theta, std::nullopt, std::nullopt)
53  {
54  }
55 
56 protected:
57  inline void UpdateVariablesDerivatives(ModelPart& rModelPart) override
58  {
60 
61  block_for_each(rModelPart.Nodes(), [this](Node& rNode) {
62  // For the Newmark schemes the second derivatives should be updated before calculating the first derivatives
63  UpdateVectorSecondTimeDerivative(rNode);
64  UpdateVectorFirstTimeDerivative(rNode);
65 
66  for (const auto& r_first_order_scalar_variable : this->GetFirstOrderScalarVariables()) {
67  UpdateScalarTimeDerivative(rNode, r_first_order_scalar_variable.instance,
68  r_first_order_scalar_variable.first_time_derivative);
69  }
70  });
71 
72  KRATOS_CATCH("")
73  }
74 
75  inline void SetTimeFactors(ModelPart& rModelPart) override
76  {
78 
80 
81  for (const auto& r_first_order_scalar_variable : this->GetFirstOrderScalarVariables()) {
82  rModelPart.GetProcessInfo()[r_first_order_scalar_variable.delta_time_coefficient] =
83  1.0 / (GetTheta() * this->GetDeltaTime());
84  }
85 
86  if (!this->GetSecondOrderVectorVariables().empty()) {
87  rModelPart.GetProcessInfo()[VELOCITY_COEFFICIENT] =
88  GetGamma() / (GetBeta() * this->GetDeltaTime());
89  }
90 
91  KRATOS_CATCH("")
92  }
93 
94  double GetBeta() const { return mBeta.value(); }
95 
96  double GetGamma() const { return mGamma.value(); }
97 
98  double GetTheta() const { return mTheta.value(); }
99 
100 private:
101  void UpdateScalarTimeDerivative(Node& rNode, const Variable<double>& variable, const Variable<double>& dt_variable) const
102  {
103  const auto delta_variable =
104  rNode.FastGetSolutionStepValue(variable, 0) - rNode.FastGetSolutionStepValue(variable, 1);
105  const auto previous_dt_variable = rNode.FastGetSolutionStepValue(dt_variable, 1);
106 
107  rNode.FastGetSolutionStepValue(dt_variable, 0) =
108  (delta_variable - (1.0 - GetTheta()) * this->GetDeltaTime() * previous_dt_variable) /
109  (GetTheta() * this->GetDeltaTime());
110  }
111 
112  void UpdateVectorFirstTimeDerivative(Node& rNode) const
113  {
114  for (const auto& r_second_order_vector_variable : this->GetSecondOrderVectorVariables()) {
115  if (!rNode.SolutionStepsDataHas(r_second_order_vector_variable.instance)) continue;
116 
117  noalias(rNode.FastGetSolutionStepValue(r_second_order_vector_variable.first_time_derivative, 0)) =
118  rNode.FastGetSolutionStepValue(r_second_order_vector_variable.first_time_derivative, 1) +
119  (1.0 - GetGamma()) * this->GetDeltaTime() *
120  rNode.FastGetSolutionStepValue(r_second_order_vector_variable.second_time_derivative, 1) +
121  GetGamma() * this->GetDeltaTime() *
122  rNode.FastGetSolutionStepValue(r_second_order_vector_variable.second_time_derivative, 0);
123  }
124  }
125 
126  void UpdateVectorSecondTimeDerivative(Node& rNode) const
127  {
128  for (const auto& r_second_order_vector_variable : this->GetSecondOrderVectorVariables()) {
129  if (!rNode.SolutionStepsDataHas(r_second_order_vector_variable.instance)) continue;
130 
131  noalias(rNode.FastGetSolutionStepValue(r_second_order_vector_variable.second_time_derivative, 0)) =
132  ((rNode.FastGetSolutionStepValue(r_second_order_vector_variable.instance, 0) -
133  rNode.FastGetSolutionStepValue(r_second_order_vector_variable.instance, 1)) -
134  this->GetDeltaTime() * rNode.FastGetSolutionStepValue(
135  r_second_order_vector_variable.first_time_derivative, 1) -
136  (0.5 - GetBeta()) * this->GetDeltaTime() * this->GetDeltaTime() *
137  rNode.FastGetSolutionStepValue(r_second_order_vector_variable.second_time_derivative, 1)) /
138  (GetBeta() * this->GetDeltaTime() * this->GetDeltaTime());
139  }
140  }
141 
142  std::optional<double> mTheta;
143  std::optional<double> mBeta;
144  std::optional<double> mGamma;
145 };
146 
147 } // namespace Kratos
Definition: generalized_newmark_scheme.hpp:22
double GetTheta() const
Definition: generalized_newmark_scheme.hpp:98
double GetGamma() const
Definition: generalized_newmark_scheme.hpp:96
void SetTimeFactors(ModelPart &rModelPart) override
Definition: generalized_newmark_scheme.hpp:75
void UpdateVariablesDerivatives(ModelPart &rModelPart) override
Definition: generalized_newmark_scheme.hpp:57
GeneralizedNewmarkScheme(const std::vector< FirstOrderScalarVariable > &rFirstOrderScalarVariables, const std::vector< SecondOrderVectorVariable > &rSecondOrderVectorVariables, std::optional< double > theta, std::optional< double > beta, std::optional< double > gamma)
Definition: generalized_newmark_scheme.hpp:24
GeneralizedNewmarkScheme(const std::vector< FirstOrderScalarVariable > &rFirstOrderScalarVariables, double theta)
Definition: generalized_newmark_scheme.hpp:50
double GetBeta() const
Definition: generalized_newmark_scheme.hpp:94
Definition: geomechanics_time_integration_scheme.hpp:50
virtual void SetTimeFactors(ModelPart &rModelPart)
Definition: geomechanics_time_integration_scheme.hpp:324
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
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
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
float gamma
Definition: generate_two_fluid_navier_stokes.py:131