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.
fluid_adjoint_derivatives.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 #pragma once
14 
15 // System includes
16 #include <tuple>
17 #include <utility>
18 
19 // External includes
20 
21 // Project includes
23 
24 // Application includes
25 
26 namespace Kratos
27 {
30 
41 template<unsigned int TNumNodes, unsigned int TBlockSize>
43 {
44 public:
47 
48  using IndexType = std::size_t;
49 
50  constexpr static IndexType NumNodes = TNumNodes;
51 
52  constexpr static IndexType BlockSize = TBlockSize;
53 
57 
58  template<IndexType TSize, class... TArgs>
60  BoundedVector<double, TSize>& rResidualDerivative,
61  TArgs&... rArgs) const
62  {
63  rResidualDerivative.clear();
64  }
65 
67 };
68 
81 template<class TSubAssemblyType, unsigned int TElementDataHolderIndex, unsigned int TRowStartingIndex, unsigned int TColumnStartingIndex = 0>
82 class SubAssembly : public TSubAssemblyType
83 {
84 public:
87 
88  using IndexType = std::size_t;
89 
90  using SubAssemblyType = TSubAssemblyType;
91 
92  static constexpr unsigned int ElementDataIndex = TElementDataHolderIndex;
93 
94  static constexpr unsigned int RowStartingIndex = TRowStartingIndex;
95 
96  static constexpr unsigned int ColumnStartingIndex = TColumnStartingIndex;
97 
98  static constexpr unsigned int NumNodes = SubAssemblyType::NumNodes;
99 
100  static constexpr unsigned int BlockSize = SubAssemblyType::BlockSize;
101 
102  static constexpr unsigned int ResidualSize = NumNodes * BlockSize;
103 
107 
117  {
118  return mSubVector;
119  }
120 
130  template<class TCombinedElementDataContainer>
131  inline typename std::tuple_element<ElementDataIndex, TCombinedElementDataContainer>::type& GetElementDataContainer(TCombinedElementDataContainer& rCombinedDataContainer) const
132  {
133  static_assert(
134  ElementDataIndex < std::tuple_size_v<TCombinedElementDataContainer>,
135  "Required Element data container index is more than the available element data containers.");
136  return std::get<ElementDataIndex>(rCombinedDataContainer);
137  }
138 
155  template<IndexType TAssemblyRowBlockSize, IndexType TAssemblyColumnBlockSize = TAssemblyRowBlockSize>
157  Matrix& rOutput,
158  const IndexType NodeIndex) const
159  {
160  KRATOS_TRY
161 
162  KRATOS_DEBUG_ERROR_IF(rOutput.size1() != TAssemblyRowBlockSize * NumNodes)
163  << "rOuput.size1() does not have the required size. [ rOutput.size1() = "
164  << rOutput.size1() << ", required_size = TAssemblyRowBlockSize * NumNodes = "
165  << TAssemblyRowBlockSize * NumNodes << " ].\n";
166 
167  KRATOS_DEBUG_ERROR_IF(rOutput.size2() != TAssemblyColumnBlockSize * NumNodes)
168  << "rOuput.size2() does not have the required size. [ rOutput.size2() = "
169  << rOutput.size2() << ", required_size = TAssemblyColumnBlockSize * NumNodes = "
170  << TAssemblyColumnBlockSize * NumNodes << " ].\n";
171 
172  for (IndexType i = 0; i < NumNodes; ++i) {
173  for (IndexType j = 0; j < BlockSize; ++j) {
174  rOutput(TAssemblyRowBlockSize * NodeIndex + RowStartingIndex, i * TAssemblyColumnBlockSize + j + ColumnStartingIndex) += mSubVector[i * BlockSize + j];
175  }
176  }
177 
178  KRATOS_CATCH("");
179  }
180 
189  template<IndexType TAssemblyRowBlockSize>
190  inline void AssembleSubVectorToVector(Vector& rOutput) const
191  {
192  KRATOS_TRY
193 
194  static_assert(ColumnStartingIndex == 0);
195 
196  KRATOS_DEBUG_ERROR_IF(rOutput.size() != TAssemblyRowBlockSize * NumNodes)
197  << "rOuput.size() does not have the required size. [ rOutput.size() = "
198  << rOutput.size() << ", required_size = TAssemblyRowBlockSize * NumNodes = "
199  << TAssemblyRowBlockSize * NumNodes << " ].\n";
200 
201  for (IndexType i = 0; i < NumNodes; ++i) {
202  for (IndexType j = 0; j < BlockSize; ++j) {
203  rOutput[i * TAssemblyRowBlockSize + j] += mSubVector[i * BlockSize + j];
204  }
205  }
206 
207  KRATOS_CATCH("");
208  }
209 
211 private:
214 
216 
218 };
219 
229 template <
230  class TCombinedElementDataContainer,
231  class TCombinedCalculationContainers
232 >
234 {
235 public:
238 
239  using CombinedElementDataContainerType = TCombinedElementDataContainer;
240 
241  using CombinedCalculationContainersType = TCombinedCalculationContainers;
242 
244 };
245 }
This is traits clas sto hold combined data containers and calculation containers.
Definition: fluid_adjoint_derivatives.h:234
TCombinedElementDataContainer CombinedElementDataContainerType
Definition: fluid_adjoint_derivatives.h:239
TCombinedCalculationContainers CombinedCalculationContainersType
Definition: fluid_adjoint_derivatives.h:241
Definition: amatrix_interface.h:41
void clear()
Definition: amatrix_interface.h:284
Assembles sub-vectors to element vectors and matrices.
Definition: fluid_adjoint_derivatives.h:83
std::tuple_element< ElementDataIndex, TCombinedElementDataContainer >::type & GetElementDataContainer(TCombinedElementDataContainer &rCombinedDataContainer) const
Get the Element Data Container.
Definition: fluid_adjoint_derivatives.h:131
std::size_t IndexType
Definition: fluid_adjoint_derivatives.h:88
static constexpr unsigned int RowStartingIndex
Definition: fluid_adjoint_derivatives.h:94
void AssembleSubVectorToVector(Vector &rOutput) const
Assembles sub-vector to a vector.
Definition: fluid_adjoint_derivatives.h:190
static constexpr unsigned int ResidualSize
Definition: fluid_adjoint_derivatives.h:102
static constexpr unsigned int NumNodes
Definition: fluid_adjoint_derivatives.h:98
TSubAssemblyType SubAssemblyType
Definition: fluid_adjoint_derivatives.h:90
void AssembleSubVectorToMatrix(Matrix &rOutput, const IndexType NodeIndex) const
Assembles sub-vector to the element matrix.
Definition: fluid_adjoint_derivatives.h:156
BoundedVector< double, ResidualSize > & GetSubVector()
Get the Sub Vector.
Definition: fluid_adjoint_derivatives.h:116
static constexpr unsigned int BlockSize
Definition: fluid_adjoint_derivatives.h:100
static constexpr unsigned int ElementDataIndex
Definition: fluid_adjoint_derivatives.h:92
static constexpr unsigned int ColumnStartingIndex
Definition: fluid_adjoint_derivatives.h:96
This provides zero derivatives for given any variable.
Definition: fluid_adjoint_derivatives.h:43
void CalculateGaussPointResidualsDerivativeContributions(BoundedVector< double, TSize > &rResidualDerivative, TArgs &... rArgs) const
Definition: fluid_adjoint_derivatives.h:59
std::size_t IndexType
Definition: fluid_adjoint_derivatives.h:48
constexpr static IndexType BlockSize
Definition: fluid_adjoint_derivatives.h:52
constexpr static IndexType NumNodes
Definition: fluid_adjoint_derivatives.h:50
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
type
Definition: generate_gid_list_file.py:35
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17