-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathelement_utilities.hpp
More file actions
301 lines (253 loc) · 13.9 KB
/
element_utilities.hpp
File metadata and controls
301 lines (253 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// KRATOS___
// // ) )
// // ___ ___
// // ____ //___) ) // ) )
// // / / // // / /
// ((____/ / ((____ ((___/ / MECHANICS
//
// License: geo_mechanics_application/license.txt
//
// Main authors: Ignasi de Pouplana,
// Vahid Galavi
//
#pragma once
// Project includes
#include "includes/element.h"
#include "includes/kratos_export_api.h"
// Application includes
#include "geo_aliases.h"
#include "geo_mechanics_application_variables.h"
namespace Kratos
{
class KRATOS_API(GEO_MECHANICS_APPLICATION) GeoElementUtilities
{
public:
using IndexType = std::size_t;
using GeometryType = Geometry<Node>;
template <unsigned int TDim, unsigned int TNumNodes>
static void CalculateNuMatrix(BoundedMatrix<double, TDim, TDim * TNumNodes>& rNu,
const Matrix& NContainer,
unsigned int GPoint)
{
CalculateNuMatrix(TDim, TNumNodes, rNu, NContainer, GPoint);
}
template <typename MatrixType1, typename MatrixType2>
static void CalculateNuMatrix(std::size_t Dim,
std::size_t NumNodes,
MatrixType1& rNu,
const MatrixType2& NContainer,
unsigned int GPoint)
{
for (unsigned int i = 0; i < Dim; ++i) {
unsigned int index = i;
for (unsigned int j = 0; j < NumNodes; ++j) {
rNu(i, index) = NContainer(GPoint, j);
index += Dim;
}
}
}
template <unsigned int TDim, unsigned int TNumNodes>
static void InterpolateVariableWithComponents(array_1d<double, TDim>& rVector,
const Matrix& NContainer,
const array_1d<double, TDim * TNumNodes>& VariableWithComponents,
unsigned int GPoint)
{
noalias(rVector) = ZeroVector(TDim);
unsigned int index = 0;
for (unsigned int i = 0; i < TNumNodes; ++i) {
for (unsigned int j = 0; j < TDim; ++j) {
rVector[j] += NContainer(GPoint, i) * VariableWithComponents[index];
index++;
}
}
}
template <unsigned int TDof, unsigned int TNumNodes>
static void InterpolateVariableWithComponents(Vector& rVector,
const Matrix& NContainer,
const Vector& VariableWithComponents,
unsigned int GPoint)
{
if (rVector.size() != TDof) rVector.resize(TDof, false);
KRATOS_ERROR_IF(VariableWithComponents.size() != TDof * TNumNodes)
<< "Wrong size in InterpolateVariableWithComponents" << std::endl;
noalias(rVector) = ZeroVector(TDof);
unsigned int index = 0;
for (unsigned int i = 0; i < TNumNodes; ++i) {
for (unsigned int j = 0; j < TDof; ++j) {
rVector[j] += NContainer(GPoint, i) * VariableWithComponents[index++];
}
}
}
static void FillArray1dOutput(array_1d<double, 3>& rOutputValue, const array_1d<double, 2>& ComputedValue);
static void FillArray1dOutput(array_1d<double, 3>& rOutputValue, const array_1d<double, 3>& ComputedValue);
template <unsigned int TDim, unsigned int TNumNodes>
static void GetNodalVariableVector(array_1d<double, TDim * TNumNodes>& rNodalVariableVector,
const Element::GeometryType& Geom,
const Variable<array_1d<double, 3>>& Variable,
IndexType SolutionStepIndex = 0)
{
array_1d<double, 3> NodalVariableAux;
unsigned int index = 0;
for (unsigned int i = 0; i < TNumNodes; ++i) {
noalias(NodalVariableAux) = Geom[i].FastGetSolutionStepValue(Variable, SolutionStepIndex);
for (unsigned int j = 0; j < TDim; ++j) {
rNodalVariableVector[index] = NodalVariableAux[j];
index++;
}
}
}
static Vector GetNodalVariableVector(const Element::GeometryType& rGeom,
const Variable<array_1d<double, 3>>& rVariable,
IndexType Dimension,
IndexType NumberOfDofs);
static void FillPermeabilityMatrix(BoundedMatrix<double, 1, 1>& rPermeabilityMatrix,
const Element::PropertiesType& rProperties);
static void FillPermeabilityMatrix(BoundedMatrix<double, 2, 2>& rPermeabilityMatrix,
const Element::PropertiesType& rProperties);
static void FillPermeabilityMatrix(BoundedMatrix<double, 3, 3>& rPermeabilityMatrix,
const Element::PropertiesType& rProperties);
static Matrix FillPermeabilityMatrix(const Element::PropertiesType& rProperties, std::size_t Dimension);
static Matrix FillInterfacePermeabilityMatrix(const Element::PropertiesType& rProperties, std::size_t Dimension);
template <typename MatrixType1, typename MatrixType2>
static void AssembleUUBlockMatrix(MatrixType1& rLeftHandSideMatrix, const MatrixType2& rUUBlockMatrix)
{
constexpr auto row_offset = std::size_t{0};
constexpr auto column_offset = row_offset;
AddMatrixAtPosition(rUUBlockMatrix, rLeftHandSideMatrix, row_offset, column_offset);
}
template <typename MatrixType1, typename MatrixType2>
static void AssembleUPBlockMatrix(MatrixType1& rLeftHandSideMatrix, const MatrixType2& rUPBlockMatrix)
{
constexpr auto row_offset = std::size_t{0};
const auto column_offset = rLeftHandSideMatrix.size2() - rUPBlockMatrix.size2();
AddMatrixAtPosition(rUPBlockMatrix, rLeftHandSideMatrix, row_offset, column_offset);
}
template <typename MatrixType1, typename MatrixType2>
static void AssemblePUBlockMatrix(MatrixType1& rLeftHandSideMatrix, const MatrixType2& rPUBlockMatrix)
{
const auto row_offset = rLeftHandSideMatrix.size1() - rPUBlockMatrix.size1();
constexpr auto column_offset = std::size_t{0};
AddMatrixAtPosition(rPUBlockMatrix, rLeftHandSideMatrix, row_offset, column_offset);
}
template <typename MatrixType1, typename MatrixType2>
static void AssemblePPBlockMatrix(MatrixType1& rLeftHandSideMatrix, const MatrixType2& rPPBlockMatrix)
{
const auto row_offset = rLeftHandSideMatrix.size1() - rPPBlockMatrix.size1();
const auto column_offset = row_offset;
AddMatrixAtPosition(rPPBlockMatrix, rLeftHandSideMatrix, row_offset, column_offset);
}
template <typename VectorType1, typename VectorType2>
static void AssembleUBlockVector(VectorType1& rRightHandSideVector, const VectorType2& rUBlockVector)
{
constexpr auto offset = std::size_t{0};
AddVectorAtPosition(rUBlockVector, rRightHandSideVector, offset);
}
template <typename VectorType1, typename VectorType2>
static void AssemblePBlockVector(VectorType1& rRightHandSideVector, const VectorType2& rPBlockVector)
{
const auto offset = rRightHandSideVector.size() - rPBlockVector.size();
AddVectorAtPosition(rPBlockVector, rRightHandSideVector, offset);
}
template <typename MatrixType1, typename MatrixType2>
static void AssignMatrixAtPosition(MatrixType1& rDestinationMatrix,
const MatrixType2& rSourceMatrix,
std::size_t RowOffset,
std::size_t ColumnOffset)
{
KRATOS_DEBUG_ERROR_IF(RowOffset + rSourceMatrix.size1() > rDestinationMatrix.size1())
<< "Can't assign submatrix: last row index (" << RowOffset + rSourceMatrix.size1()
<< ") exceeds the row size of the destination matrix (" << rDestinationMatrix.size1() << ")\n";
KRATOS_DEBUG_ERROR_IF(ColumnOffset + rSourceMatrix.size2() > rDestinationMatrix.size2())
<< "Can't assign submatrix: last column index (" << ColumnOffset + rSourceMatrix.size2()
<< ") exceeds the column size of the destination matrix (" << rDestinationMatrix.size2() << ")\n";
subrange(rDestinationMatrix, RowOffset, RowOffset + rSourceMatrix.size1(), ColumnOffset,
ColumnOffset + rSourceMatrix.size2()) = rSourceMatrix;
}
template <typename MatrixType1, typename MatrixType2>
static void AssignUUBlockMatrix(MatrixType1& rDestinationMatrix, const MatrixType2& rUUBlockMatrix)
{
constexpr auto row_offset = std::size_t{0};
constexpr auto column_offset = std::size_t{0};
AssignMatrixAtPosition(rDestinationMatrix, rUUBlockMatrix, row_offset, column_offset);
}
template <typename MatrixType1, typename MatrixType2>
static void AssignUPBlockMatrix(MatrixType1& rDestinationMatrix, const MatrixType2& rUPBlockMatrix)
{
constexpr auto row_offset = std::size_t{0};
const auto column_offset = rDestinationMatrix.size2() - rUPBlockMatrix.size2();
AssignMatrixAtPosition(rDestinationMatrix, rUPBlockMatrix, row_offset, column_offset);
}
template <typename MatrixType1, typename MatrixType2>
static void AssignPUBlockMatrix(MatrixType1& rDestinationMatrix, const MatrixType2& rPUBlockMatrix)
{
const auto row_offset = rDestinationMatrix.size1() - rPUBlockMatrix.size1();
constexpr auto column_offset = std::size_t{0};
AssignMatrixAtPosition(rDestinationMatrix, rPUBlockMatrix, row_offset, column_offset);
}
template <typename MatrixType1, typename MatrixType2>
static void AssignPPBlockMatrix(MatrixType1& rDestinationMatrix, const MatrixType2& rPPBlockMatrix)
{
const auto row_offset = rDestinationMatrix.size1() - rPPBlockMatrix.size1();
const auto column_offset = rDestinationMatrix.size2() - rPPBlockMatrix.size2();
AssignMatrixAtPosition(rDestinationMatrix, rPPBlockMatrix, row_offset, column_offset);
}
template <typename VectorType1, typename VectorType2>
static void AssignVectorAtPosition(VectorType1& rDestinationVector, const VectorType2& rSourceVector, std::size_t Offset)
{
KRATOS_DEBUG_ERROR_IF(Offset + rSourceVector.size() > rDestinationVector.size())
<< "Can't assign subvector: last index (" << Offset + rSourceVector.size()
<< ") exceeds the size of the destination vector (" << rDestinationVector.size() << ")\n";
subrange(rDestinationVector, Offset, Offset + rSourceVector.size()) = rSourceVector;
}
template <typename VectorType1, typename VectorType2>
static void AssignUBlockVector(VectorType1& rDestinationVector, const VectorType2& rUBlockVector)
{
constexpr auto offset = std::size_t{0};
AssignVectorAtPosition(rDestinationVector, rUBlockVector, offset);
}
template <typename VectorType1, typename VectorType2>
static void AssignPBlockVector(VectorType1& rDestinationVector, const VectorType2& rPBlockVector)
{
const auto offset = rDestinationVector.size() - rPBlockVector.size();
AssignVectorAtPosition(rDestinationVector, rPBlockVector, offset);
}
/**
* Calculates the radius of axisymmetry
* @param rN: The Gauss Point shape function
* @param rGeometry: The geometry studied
* @return Radius: The radius of axisymmetry
*/
static double CalculateRadius(const Vector& rN, const GeometryType& rGeometry);
static double CalculateAxisymmetricCircumference(const Vector& rN, const GeometryType& rGeometry);
static Vector CalculateNodalHydraulicHeadFromWaterPressures(const GeometryType& rGeom,
const Properties& rProp);
static std::size_t GetNumberOfIntegrationPointsOf(const Element& rElement);
static Geo::IntegrationPointVectorType GetIntegrationPointsOf(const Element& rElement);
static std::vector<Vector> EvaluateShapeFunctionsAtIntegrationPoints(const Geo::IntegrationPointVectorType& rIntegrationPoints,
const Geometry<Node>& rGeometry);
static Vector EvaluateDeterminantsOfJacobiansAtIntegrationPoints(const Geo::IntegrationPointVectorType& rIntegrationPoints,
const Geometry<Node>& rGeometry);
template <typename MatrixType1, typename MatrixType2>
static void AddMatrixAtPosition(const MatrixType1& rSourceMatrix,
MatrixType2& rDestinationMatrix,
const std::size_t RowOffset,
const std::size_t ColumnOffset)
{
const std::size_t size1 = rSourceMatrix.size1();
const std::size_t size2 = rSourceMatrix.size2();
for (std::size_t i = 0; i < size1; ++i) {
const std::size_t di = i + RowOffset;
for (std::size_t j = 0; j < size2; ++j) {
rDestinationMatrix(di, j + ColumnOffset) += rSourceMatrix(i, j);
}
}
}
private:
template <typename VectorType1, typename VectorType2>
static void AddVectorAtPosition(const VectorType1& rSourceVector, VectorType2& rDestinationVector, std::size_t Offset)
{
auto pos = std::begin(rDestinationVector) + Offset;
std::transform(std::begin(rSourceVector), std::end(rSourceVector), pos, pos, std::plus<double>{});
}
}; /* Class GeoElementUtilities*/
} /* namespace Kratos.*/