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.
backward_euler_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 
13 #pragma once
14 
17 
18 namespace Kratos
19 {
20 
21 template <class TSparseSpace, class TDenseSpace>
22 class BackwardEulerScheme : public GeoMechanicsTimeIntegrationScheme<TSparseSpace, TDenseSpace>
23 {
24 public:
25  BackwardEulerScheme(const std::vector<FirstOrderScalarVariable>& rFirstOrderScalarVariables,
26  const std::vector<SecondOrderVectorVariable>& rSecondOrderVectorVariables)
27  : GeoMechanicsTimeIntegrationScheme<TSparseSpace, TDenseSpace>(rFirstOrderScalarVariables, rSecondOrderVectorVariables)
28  {
29  }
30 
31 protected:
32  inline void SetTimeFactors(ModelPart& rModelPart) override
33  {
35 
37 
38  for (const auto& r_first_order_scalar_variable : this->GetFirstOrderScalarVariables()) {
39  rModelPart.GetProcessInfo()[r_first_order_scalar_variable.delta_time_coefficient] =
40  1.0 / this->GetDeltaTime();
41  }
42 
43  if (!this->GetSecondOrderVectorVariables().empty()) {
44  rModelPart.GetProcessInfo()[VELOCITY_COEFFICIENT] = 1.0 / this->GetDeltaTime();
45  }
46 
47  KRATOS_CATCH("")
48  }
49 
50  inline void UpdateVariablesDerivatives(ModelPart& rModelPart) override
51  {
53 
54  block_for_each(rModelPart.Nodes(), [this](Node& rNode) {
55  // For the Backward Euler schemes the first derivatives should be
56  // updated before calculating the second derivatives
57  UpdateVectorTimeDerivatives(rNode);
58 
59  for (const auto& r_first_order_scalar_variable : this->GetFirstOrderScalarVariables()) {
60  SetDerivative(r_first_order_scalar_variable.first_time_derivative,
61  r_first_order_scalar_variable.instance, rNode);
62  }
63  });
64 
65  KRATOS_CATCH("")
66  }
67 
68  void UpdateVectorTimeDerivatives(Node& rNode) const
69  {
70  for (const auto& r_second_order_vector_variable : this->GetSecondOrderVectorVariables()) {
71  if (!rNode.SolutionStepsDataHas(r_second_order_vector_variable.instance)) continue;
72 
73  SetDerivative(r_second_order_vector_variable.first_time_derivative,
74  r_second_order_vector_variable.instance, rNode);
75 
76  // Make sure that setting the second_time_derivative is done
77  // after setting the first_time_derivative.
78  SetDerivative(r_second_order_vector_variable.second_time_derivative,
79  r_second_order_vector_variable.first_time_derivative, rNode);
80  }
81  }
82 
83  template <class T>
84  void SetDerivative(const Variable<T>& derivative_variable, const Variable<T>& instance_variable, Node& rNode) const
85  {
86  rNode.FastGetSolutionStepValue(derivative_variable) =
87  (rNode.FastGetSolutionStepValue(instance_variable, 0) -
88  rNode.FastGetSolutionStepValue(instance_variable, 1)) /
89  this->GetDeltaTime();
90  }
91 };
92 
93 } // namespace Kratos
Definition: backward_euler_scheme.hpp:23
void SetDerivative(const Variable< T > &derivative_variable, const Variable< T > &instance_variable, Node &rNode) const
Definition: backward_euler_scheme.hpp:84
void UpdateVariablesDerivatives(ModelPart &rModelPart) override
Definition: backward_euler_scheme.hpp:50
void UpdateVectorTimeDerivatives(Node &rNode) const
Definition: backward_euler_scheme.hpp:68
void SetTimeFactors(ModelPart &rModelPart) override
Definition: backward_euler_scheme.hpp:32
BackwardEulerScheme(const std::vector< FirstOrderScalarVariable > &rFirstOrderScalarVariables, const std::vector< SecondOrderVectorVariable > &rSecondOrderVectorVariables)
Definition: backward_euler_scheme.hpp:25
Definition: geomechanics_time_integration_scheme.hpp:50
const std::vector< FirstOrderScalarVariable > & GetFirstOrderScalarVariables() const
Definition: geomechanics_time_integration_scheme.hpp:338
double GetDeltaTime() const
Definition: geomechanics_time_integration_scheme.hpp:331
virtual void SetTimeFactors(ModelPart &rModelPart)
Definition: geomechanics_time_integration_scheme.hpp:324
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
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
bool SolutionStepsDataHas(const VariableData &rThisVariable) const
Definition: node.h:427
#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