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.
velocity_bossak_sensitivity_builder_scheme.h
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: Suneth Warnakulasuriya
11 //
12 
13 #if !defined(KRATOS_VELOCITY_BOSSAK_SENSITIVITY_BUILDER_SCHEME_H_INCLUDED)
14 #define KRATOS_VELOCITY_BOSSAK_SENSITIVITY_BUILDER_SCHEME_H_INCLUDED
15 
16 // System includes
17 #include <vector>
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
24 #include "utilities/openmp_utils.h"
25 
26 // Application includes
28 
29 namespace Kratos
30 {
33 
35 {
36 public:
39 
41 
43 
44  using NodeType = typename BaseType::NodeType;
45 
47 
49 
51 
52  using IndexType = std::size_t;
53 
57 
60  const double NewAlphaBossak,
61  const IndexType Dimension,
62  const IndexType BlockSize)
63  : BaseType(Dimension, BlockSize)
64  {
65  //default values for the Newmark Scheme
66  mAlphaBossak = NewAlphaBossak;
67  mBetaNewmark = 0.25 * pow((1.00 - mAlphaBossak), 2);
68  mGammaNewmark = 0.5 - mAlphaBossak;
69 
70  const int number_of_threads = ParallelUtilities::GetNumThreads();
71  mMassMatrices.resize(number_of_threads);
72  mDampingMatrices.resize(number_of_threads);
73  mSecondDerivativesVectors.resize(number_of_threads);
74  }
75 
78 
82 
83  void Clear() override
84  {
86  mMassMatrices.clear();
87  mDampingMatrices.clear();
88  mSecondDerivativesVectors.clear();
89  }
90 
94 
96  ModelPart& rModelPart,
97  ModelPart& rSensitivityModelPart,
98  AdjointResponseFunction& rResponseFunction) override
99  {
100  KRATOS_TRY
101 
102  BaseType::InitializeSolutionStep(rModelPart, rSensitivityModelPart, rResponseFunction);
103 
104  const double delta_time = -rModelPart.GetProcessInfo()[DELTA_TIME];
105  KRATOS_ERROR_IF(delta_time < 1.0e-12)
106  << "Detected delta_time > 0 in the adjoint Bossak scheme. Adjoints "
107  "are calculated in reverse time, therefore DELTA_TIME should be "
108  "negative."
109  << std::endl;
110 
111  // initializing constants
112  ma1 = delta_time * mBetaNewmark / mGammaNewmark;
113  mam = (1.0 - mAlphaBossak) / (mGammaNewmark * delta_time);
114 
115  KRATOS_CATCH("");
116  }
117 
121 
123  std::string Info() const override
124  {
125  return "VelocityBossakSensitivityBuilderScheme";
126  }
127 
129 
130 private:
133 
134  double mAlphaBossak;
135  double mBetaNewmark;
136  double mGammaNewmark;
137 
138  double ma1;
139  double mam;
140 
141  std::vector<Matrix> mMassMatrices;
142  std::vector<Matrix> mDampingMatrices;
143  std::vector<Vector> mSecondDerivativesVectors;
144 
148 
149  void CalculateLHSAndRHS(
150  ElementType& rElement,
151  Matrix& rLHS,
152  Vector& rRHS,
153  const ProcessInfo& rProcessInfo) override
154  {
155  CalculateEntityLHSAndRHS(rElement, rLHS, rRHS, rProcessInfo);
156  }
157 
158  void CalculateLHSAndRHS(
159  ConditionType& rCondition,
160  Matrix& rLHS,
161  Vector& rRHS,
162  const ProcessInfo& rProcessInfo) override
163  {
164  CalculateEntityLHSAndRHS(rCondition, rLHS, rRHS, rProcessInfo);
165  }
166 
167  template<class EntityType>
168  void CalculateEntityLHSAndRHS(
169  EntityType& rEntity,
170  Matrix& rLHS,
171  Vector& rRHS,
172  const ProcessInfo& rProcessInfo)
173  {
174  const int k = OpenMPUtils::ThisThread();
175 
176  auto& mass_matrix = mMassMatrices[k];
177  auto& damping_matrix = mDampingMatrices[k];
178  auto& second_derivatives_vector = mSecondDerivativesVectors[k];
179 
180  // following calls uses the same method calls as in the primal scheme to be consistent
181  rEntity.CalculateLocalSystem(rLHS, rRHS, rProcessInfo);
182  rEntity.CalculateMassMatrix(mass_matrix, rProcessInfo);
183  rEntity.CalculateLocalVelocityContribution(damping_matrix, rRHS, rProcessInfo);
184 
185  AddDynamicsToLHS(rLHS, damping_matrix, mass_matrix);
186  AddDynamicsToRHS(rRHS, second_derivatives_vector, mass_matrix, rEntity, rProcessInfo);
187  }
188 
189  void AddDynamicsToLHS(
190  Matrix& rLHS,
191  const Matrix& rDampingMatrix,
192  const Matrix& rMassMatrix) const
193  {
194  // multipling time scheme factor
195  rLHS *= ma1;
196 
197  // adding mass contribution to the dynamic stiffness
198  if (rMassMatrix.size1() != 0) {
199  noalias(rLHS) += mam * rMassMatrix;
200  }
201 
202  // adding damping contribution
203  if (rDampingMatrix.size1() != 0) {
204  noalias(rLHS) += rDampingMatrix;
205  }
206  }
207 
208  template <class TEntityType>
209  void AddDynamicsToRHS(
210  Vector& rRHS,
211  Vector& rSecondDerivativesVector,
212  const Matrix& rMassMatrix,
213  TEntityType& rEntity,
214  const ProcessInfo& rProcessInfo)
215  {
216  // adding inertia contribution
217  if (rMassMatrix.size1() != 0) {
218  rEntity.Calculate(PRIMAL_RELAXED_SECOND_DERIVATIVE_VALUES, rSecondDerivativesVector, rProcessInfo);
219  noalias(rRHS) -= prod(rMassMatrix, rSecondDerivativesVector);
220  }
221  }
222 
224 
225 }; /* Class VelocityBossakSensitivityBuilderScheme */
226 
228 
229 } /* namespace Kratos.*/
230 
231 #endif /* KRATOS_VELOCITY_BOSSAK_SENSITIVITY_BUILDER_SCHEME_H_INCLUDED defined */
A base class for adjoint response functions.
Definition: adjoint_response_function.h:39
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
Geometry base class.
Definition: geometry.h:71
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
This class defines the node.
Definition: node.h:65
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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Scheme used in the Sensitivity Builder.
Definition: sensitivity_builder_scheme.h:53
Definition: simple_steady_sensitivity_builder_scheme.h:45
BaseType::ElementType ElementType
Definition: simple_steady_sensitivity_builder_scheme.h:58
BaseType::NodeType NodeType
Definition: simple_steady_sensitivity_builder_scheme.h:54
std::size_t IndexType
Definition: simple_steady_sensitivity_builder_scheme.h:60
BaseType::ConditionType ConditionType
Definition: simple_steady_sensitivity_builder_scheme.h:56
void InitializeSolutionStep(ModelPart &rModelPart, ModelPart &rSensitivityModelPart, AdjointResponseFunction &rResponseFunction) override
Definition: simple_steady_sensitivity_builder_scheme.h:113
SimpleSteadySensitivityBuilderScheme(const IndexType Dimension, const IndexType BlockSize)
Constructor.
Definition: simple_steady_sensitivity_builder_scheme.h:67
void Clear() override
Definition: simple_steady_sensitivity_builder_scheme.h:411
Definition: velocity_bossak_sensitivity_builder_scheme.h:35
void Clear() override
Definition: velocity_bossak_sensitivity_builder_scheme.h:83
void InitializeSolutionStep(ModelPart &rModelPart, ModelPart &rSensitivityModelPart, AdjointResponseFunction &rResponseFunction) override
Definition: velocity_bossak_sensitivity_builder_scheme.h:95
std::string Info() const override
Turn back information as a string.
Definition: velocity_bossak_sensitivity_builder_scheme.h:123
~VelocityBossakSensitivityBuilderScheme()=default
Destructor.
VelocityBossakSensitivityBuilderScheme(const double NewAlphaBossak, const IndexType Dimension, const IndexType BlockSize)
Constructor.
Definition: velocity_bossak_sensitivity_builder_scheme.h:59
KRATOS_CLASS_POINTER_DEFINITION(VelocityBossakSensitivityBuilderScheme)
#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
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
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
delta_time
Definition: generate_frictional_mortar_condition.py:130
int k
Definition: quadrature.py:595