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.
geometry_shape_function_container.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: Tobias Teschemacher
11 // Pooyan Dadvand
12 //
13 //
14 
15 #if !defined(KRATOS_GEOMETRY_SHAPE_FUNCTION_CONTAINER_H_INCLUDED )
16 #define KRATOS_GEOMETRY_SHAPE_FUNCTION_CONTAINER_H_INCLUDED
17 
18 // System includes
19 #include<array>
20 #include<vector>
21 
22 // External includes
23 
24 // Project includes
25 #include "includes/define.h"
27 #include "includes/serializer.h"
29 
30 namespace Kratos
31 {
32 
33 
36 
40 
44 
48 
52 
58 template<typename TIntegrationMethodType>
60 {
61 public:
62 
65 
68 
70  using IntegrationMethod = TIntegrationMethodType;
71 
73  typedef std::size_t IndexType;
74  typedef std::size_t SizeType;
75 
78  typedef std::vector<IntegrationPointType> IntegrationPointsArrayType;
79  typedef std::array<IntegrationPointsArrayType, static_cast<int>(IntegrationMethod::NumberOfIntegrationMethods)> IntegrationPointsContainerType;
80 
83 
86  typedef std::array<DenseVector<Matrix>, static_cast<int>(IntegrationMethod::NumberOfIntegrationMethods)> ShapeFunctionsLocalGradientsContainerType;
87 
89  typedef DenseVector<Matrix>
93  typedef std::array<ShapeFunctionsDerivativesIntegrationPointArrayType, static_cast<int>(IntegrationMethod::NumberOfIntegrationMethods)>
95 
99 
102  IntegrationMethod ThisDefaultMethod,
103  const IntegrationPointsContainerType& ThisIntegrationPoints,
104  const ShapeFunctionsValuesContainerType& ThisShapeFunctionsValues,
105  const ShapeFunctionsLocalGradientsContainerType& ThisShapeFunctionsLocalGradients )
106  : mDefaultMethod(ThisDefaultMethod)
107  , mIntegrationPoints(ThisIntegrationPoints)
108  , mShapeFunctionsValues( ThisShapeFunctionsValues )
109  , mShapeFunctionsLocalGradients( ThisShapeFunctionsLocalGradients )
110  {
111  }
112 
115  IntegrationMethod ThisDefaultMethod,
116  const IntegrationPointType& ThisIntegrationPoint,
117  const Matrix& ThisShapeFunctionsValues,
118  const Matrix& ThisShapeFunctionsGradients)
119  : mDefaultMethod(ThisDefaultMethod)
120  {
122  ips[0] = ThisIntegrationPoint;
123  mIntegrationPoints[static_cast<int>(ThisDefaultMethod)] = ips;
124 
125  mShapeFunctionsValues[static_cast<int>(ThisDefaultMethod)] = ThisShapeFunctionsValues;
126 
127  ShapeFunctionsGradientsType DN_De_array(1);
128  DN_De_array[0] = ThisShapeFunctionsGradients;
129  mShapeFunctionsLocalGradients[static_cast<int>(ThisDefaultMethod)] = DN_De_array;
130  }
131 
134  IntegrationMethod ThisDefaultMethod,
135  const IntegrationPointType& ThisIntegrationPoint,
136  const Matrix& ThisShapeFunctionsValues,
137  const DenseVector<Matrix>& ThisShapeFunctionsDerivatives)
138  : mDefaultMethod(ThisDefaultMethod)
139  {
141  ips[0] = ThisIntegrationPoint;
142  mIntegrationPoints[static_cast<int>(ThisDefaultMethod)] = ips;
143 
144  mShapeFunctionsValues[static_cast<int>(ThisDefaultMethod)] = ThisShapeFunctionsValues;
145 
146  if (ThisShapeFunctionsDerivatives.size() > 0)
147  {
148  ShapeFunctionsGradientsType DN_De_array(1);
149  DN_De_array[0] = ThisShapeFunctionsDerivatives[0];
150  mShapeFunctionsLocalGradients[static_cast<int>(ThisDefaultMethod)] = DN_De_array;
151  }
152  if (ThisShapeFunctionsDerivatives.size() > 1)
153  {
154  ShapeFunctionsDerivativesIntegrationPointArrayType derivatives_array(ThisShapeFunctionsDerivatives.size() - 1);
155  for (IndexType i = 1; i < ThisShapeFunctionsDerivatives.size(); ++i)
156  {
157  ShapeFunctionsDerivativesType DN_De_i_array(1);
158  DN_De_i_array[0] = ThisShapeFunctionsDerivatives[i];
159  derivatives_array[i - 1] = DN_De_i_array;
160  }
161  mShapeFunctionsDerivatives[static_cast<int>(ThisDefaultMethod)] = derivatives_array;
162  }
163  }
164 
167  : mIntegrationPoints({})
168  , mShapeFunctionsValues({})
169  , mShapeFunctionsLocalGradients({})
170  , mShapeFunctionsDerivatives({})
171  {
172  }
173 
176  : mDefaultMethod(rOther.mDefaultMethod)
177  , mIntegrationPoints(rOther.mIntegrationPoints)
178  , mShapeFunctionsValues( rOther.mShapeFunctionsValues )
179  , mShapeFunctionsLocalGradients( rOther.mShapeFunctionsLocalGradients )
180  , mShapeFunctionsDerivatives( rOther.mShapeFunctionsDerivatives )
181  {
182  }
183 
186 
190 
192  const GeometryShapeFunctionContainer& rOther )
193  {
194  mDefaultMethod = rOther.mDefaultMethod;
195  mIntegrationPoints = rOther.mIntegrationPoints;
196  mShapeFunctionsValues = rOther.mShapeFunctionsValues;
197  mShapeFunctionsLocalGradients = rOther.mShapeFunctionsLocalGradients;
198  mShapeFunctionsDerivatives = rOther.mShapeFunctionsDerivatives;
199 
200  return *this;
201  }
202 
206 
208  {
209  return mDefaultMethod;
210  }
211 
213  {
214  return (!mIntegrationPoints[static_cast<int>(ThisMethod)].empty());
215  }
216 
220 
222  {
223  return mIntegrationPoints[static_cast<int>(mDefaultMethod)].size();
224  }
225 
227  {
228  return mIntegrationPoints[static_cast<int>(ThisMethod)].size();
229  }
230 
232  {
233  return mIntegrationPoints[static_cast<int>(mDefaultMethod)];
234  }
235 
237  {
238  return mIntegrationPoints[static_cast<int>(ThisMethod)];
239  }
240 
244 
246  {
247  return mShapeFunctionsValues[static_cast<int>(mDefaultMethod)];
248  }
249 
251  IntegrationMethod ThisMethod ) const
252  {
253  return mShapeFunctionsValues[static_cast<int>(ThisMethod)];
254  }
255 
257  IndexType IntegrationPointIndex,
258  IndexType ShapeFunctionIndex,
259  IntegrationMethod ThisMethod ) const
260  {
261  KRATOS_DEBUG_ERROR_IF(mShapeFunctionsValues[static_cast<int>(ThisMethod)].size1() <= IntegrationPointIndex )
262  << "No existing integration point" << std::endl;
263 
264  KRATOS_DEBUG_ERROR_IF(mShapeFunctionsValues[static_cast<int>(ThisMethod)].size2() <= ShapeFunctionIndex )
265  << "No existing shape function value" << std::endl;
266 
267  return mShapeFunctionsValues[static_cast<int>(ThisMethod)]( IntegrationPointIndex, ShapeFunctionIndex );
268  }
269 
270  double ShapeFunctionValue(IndexType IntegrationPointIndex, IndexType ShapeFunctionIndex) const
271  {
272  return mShapeFunctionsValues[static_cast<int>(mDefaultMethod)](IntegrationPointIndex, ShapeFunctionIndex);
273  }
274 
276  {
277  return mShapeFunctionsLocalGradients[static_cast<int>(mDefaultMethod)];
278  }
279 
281  IntegrationMethod ThisMethod ) const
282  {
283  return mShapeFunctionsLocalGradients[static_cast<int>(ThisMethod)];
284  }
285 
287  IndexType IntegrationPointIndex) const
288  {
289  return ShapeFunctionLocalGradient(IntegrationPointIndex, mDefaultMethod);
290  }
291 
293  IndexType IntegrationPointIndex,
294  IntegrationMethod ThisMethod ) const
295  {
296  KRATOS_DEBUG_ERROR_IF(mShapeFunctionsLocalGradients[static_cast<int>(ThisMethod)].size() <= IntegrationPointIndex )
297  << "No existing integration point" << std::endl;
298 
299  return mShapeFunctionsLocalGradients[static_cast<int>(ThisMethod)][IntegrationPointIndex];
300  }
301 
303  IndexType IntegrationPointIndex,
304  IndexType ShapeFunctionIndex,
305  IntegrationMethod ThisMethod ) const
306  {
307  KRATOS_DEBUG_ERROR_IF(mShapeFunctionsLocalGradients[static_cast<int>(ThisMethod)].size() <= IntegrationPointIndex )
308  << "No existing integration point" << std::endl;
309 
310  return mShapeFunctionsLocalGradients[static_cast<int>(ThisMethod)][IntegrationPointIndex];
311  }
312 
313  /*
314  * @brief access to the shape function derivatives.
315  * @param DerivativeOrderIndex defines the wanted order of the derivative
316  * @param IntegrationPointIndex the corresponding contorl point of this geometry
317  * @return the shape function or derivative value related to the input parameters
318  * The matrix is structured: (the corresponding node, derivative direction)
319  * The derivative direction within the matrix is structured as following:
320  * [0] - Not possible -> error
321  * [1] - dN_de: (du, dv, dw)
322  * [2] - second order vectors:
323  * 1D: du^2 (size2 = 1)
324  * 2D: du^2, dudv, dv^2 (size2 = 2)
325  * 3D: du^2, dudv, dudw, dv^2, dvdw, dw^2 (size2 = 6)
326  * [3] - third order vectors:
327  * 1D: du^3 (size2 = 1)
328  * 2D: du^3, du^2dv, dudv^2, dv^3 (size2 = 4)
329  */
331  IndexType DerivativeOrderIndex,
332  IndexType IntegrationPointIndex,
333  IntegrationMethod ThisMethod) const
334  {
335  /* Shape function values are stored within a Matrix, however, only one row
336  should be provided here. Thus, currently it is not possible to provide the
337  needed source to this object.*/
338  KRATOS_DEBUG_ERROR_IF(DerivativeOrderIndex == 0)
339  << "Shape functions cannot be accessed through ShapeFunctionDerivatives()" << std::endl;
340 
341  if (DerivativeOrderIndex == 1)
342  {
343  return mShapeFunctionsLocalGradients[static_cast<int>(ThisMethod)][IntegrationPointIndex];
344  }
345 
346  KRATOS_DEBUG_ERROR_IF(mShapeFunctionsDerivatives[static_cast<int>(ThisMethod)][DerivativeOrderIndex - 2].size() < IntegrationPointIndex)
347  << "Not enough integration points within geometry_shape_function_container. Geometry_shape_function_container has "
348  << mShapeFunctionsDerivatives[static_cast<int>(ThisMethod)][DerivativeOrderIndex - 2].size()
349  << " integration points. Called integration point index: " << IntegrationPointIndex << std::endl;
350 
351  return mShapeFunctionsDerivatives[static_cast<int>(ThisMethod)][DerivativeOrderIndex - 2][IntegrationPointIndex];
352  }
353 
354  /*
355  * @brief access each item separateley.
356  * @param DerivativeOrderIndex defines the wanted order of the derivative
357  * @param DerivativeOrderRowIndex within each derivative the entries can
358  * be accessed differently.
359  * DerivativeOrderIndex:,
360  * [0] - N
361  * [1] - dN_de, DerivativeOrderRowIndex:
362  * [0] du, [1] dv, [2] dw
363  * [2] - ddN_dde, DerivativeOrderRowIndex:
364  * 1D: [0] du^2
365  * 2D: [0] du^2, [1] dudv, [2] dv^2
366  * 3D: [0] du^2, [1] dudv, [2] dudw, [3] dv^2, [4] dvdw, [5] dw^2
367  * [3] - third order vectors:
368  * 1D: [0] du^3
369  * 2D: [0] du^3, [1] du^2dv, [2] dudv^2, [3] dv^3
370  * @return the shape function or derivative value related to the input parameters.
371  */
373  IndexType IntegrationPointIndex,
374  IndexType DerivativeOrderIndex,
375  IndexType DerivativeOrderRowIndex,
376  IndexType ShapeFunctionIndex,
377  IntegrationMethod ThisMethod)
378  {
379  if (DerivativeOrderIndex == 0)
380  return mShapeFunctionsValues[static_cast<int>(ThisMethod)](IntegrationPointIndex, ShapeFunctionIndex);
381  if (DerivativeOrderIndex == 1)
382  return mShapeFunctionsLocalGradients[static_cast<int>(ThisMethod)][IntegrationPointIndex](ShapeFunctionIndex, DerivativeOrderRowIndex);
383 
384  return mShapeFunctionsDerivatives[static_cast<int>(ThisMethod)][DerivativeOrderIndex - 2][IntegrationPointIndex](ShapeFunctionIndex, DerivativeOrderRowIndex);
385  }
386 
390 
392  virtual std::string Info() const
393  {
394  return "shape function container";
395  }
396 
398  virtual void PrintInfo( std::ostream& rOStream ) const
399  {
400  rOStream << "shape function container";
401  }
402 
404  virtual void PrintData( std::ostream& rOStream ) const
405  {
406  }
407 
409 
410 private:
413 
414  IntegrationMethod mDefaultMethod;
415 
416  IntegrationPointsContainerType mIntegrationPoints;
417 
418  ShapeFunctionsValuesContainerType mShapeFunctionsValues;
419 
420  ShapeFunctionsLocalGradientsContainerType mShapeFunctionsLocalGradients;
421 
422  ShapeFunctionsDerivativesContainerType mShapeFunctionsDerivatives;
423 
427 
428  friend class Serializer;
429 
430  virtual void save( Serializer& rSerializer ) const
431  {
432  rSerializer.save("IntegrationPoints", mIntegrationPoints);
433  rSerializer.save("ShapeFunctionsValues", mShapeFunctionsValues);
434  rSerializer.save("ShapeFunctionsLocalGradients", mShapeFunctionsLocalGradients);
435  rSerializer.save("ShapeFunctionsDerivatives", mShapeFunctionsDerivatives);
436  }
437 
438  virtual void load( Serializer& rSerializer )
439  {
440  KRATOS_ERROR << "load function for geometry_shape_function_container not yet implemented." << std::endl;
441  rSerializer.load("IntegrationPoints", mIntegrationPoints);
442  rSerializer.load("ShapeFunctionsValues", mShapeFunctionsValues);
443  rSerializer.load("ShapeFunctionsLocalGradients", mShapeFunctionsLocalGradients);
444  rSerializer.load("ShapeFunctionsDerivatives", mShapeFunctionsDerivatives);
445  }
446 
448 
449 }; // Class GeometryShapeFunctionContainer
450 
454 
456 template<typename TIntegrationMethodType>
457 inline std::istream& operator >> ( std::istream& rIStream,
459 
461 template<typename TIntegrationMethodType>
462 inline std::ostream& operator << ( std::ostream& rOStream,
464 {
465  rThis.PrintInfo( rOStream );
466  rOStream << std::endl;
467  rThis.PrintData( rOStream );
468 
469  return rOStream;
470 }
471 
473 
474 } // namespace Kratos.
475 
476 #endif // KRATOS_GEOMETRY_SHAPE_FUNCTION_CONTAINER_H_INCLUDED defined
IntegrationMethod
Definition: geometry_data.h:76
Definition: geometry_shape_function_container.h:60
const Matrix & ShapeFunctionsValues() const
Definition: geometry_shape_function_container.h:245
IntegrationPoint< 3 > IntegrationPointType
Integration points.
Definition: geometry_shape_function_container.h:77
const IntegrationPointsArrayType & IntegrationPoints() const
Definition: geometry_shape_function_container.h:231
DenseVector< ShapeFunctionsDerivativesType > ShapeFunctionsDerivativesIntegrationPointArrayType
Definition: geometry_shape_function_container.h:92
DenseVector< Matrix > ShapeFunctionsGradientsType
First derivatives/ gradients.
Definition: geometry_shape_function_container.h:85
double ShapeFunctionValue(IndexType IntegrationPointIndex, IndexType ShapeFunctionIndex) const
Definition: geometry_shape_function_container.h:270
GeometryShapeFunctionContainer & operator=(const GeometryShapeFunctionContainer &rOther)
Definition: geometry_shape_function_container.h:191
const ShapeFunctionsGradientsType & ShapeFunctionsLocalGradients(IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:280
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: geometry_shape_function_container.h:398
std::vector< IntegrationPointType > IntegrationPointsArrayType
Definition: geometry_shape_function_container.h:78
const ShapeFunctionsGradientsType & ShapeFunctionsLocalGradients() const
Definition: geometry_shape_function_container.h:275
KRATOS_CLASS_POINTER_DEFINITION(GeometryShapeFunctionContainer)
Pointer definition of GeometryShapeFunctionContainer.
const Matrix & ShapeFunctionLocalGradient(IndexType IntegrationPointIndex, IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:292
SizeType IntegrationPointsNumber(IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:226
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: geometry_shape_function_container.h:404
virtual std::string Info() const
Turn back information as a string.
Definition: geometry_shape_function_container.h:392
GeometryShapeFunctionContainer(IntegrationMethod ThisDefaultMethod, const IntegrationPointsContainerType &ThisIntegrationPoints, const ShapeFunctionsValuesContainerType &ThisShapeFunctionsValues, const ShapeFunctionsLocalGradientsContainerType &ThisShapeFunctionsLocalGradients)
Constructor for single integration point having the full containers.
Definition: geometry_shape_function_container.h:101
const Matrix & ShapeFunctionsValues(IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:250
DenseVector< Matrix > ShapeFunctionsDerivativesType
Higher order derivatives.
Definition: geometry_shape_function_container.h:90
GeometryShapeFunctionContainer(IntegrationMethod ThisDefaultMethod, const IntegrationPointType &ThisIntegrationPoint, const Matrix &ThisShapeFunctionsValues, const DenseVector< Matrix > &ThisShapeFunctionsDerivatives)
Constructor ONLY for single integration point with multiple derivatives.
Definition: geometry_shape_function_container.h:133
std::array< Matrix, static_cast< int >IntegrationMethod::NumberOfIntegrationMethods)> ShapeFunctionsValuesContainerType
Shape functions.
Definition: geometry_shape_function_container.h:82
SizeType IntegrationPointsNumber() const
Definition: geometry_shape_function_container.h:221
std::array< IntegrationPointsArrayType, static_cast< int >IntegrationMethod::NumberOfIntegrationMethods)> IntegrationPointsContainerType
Definition: geometry_shape_function_container.h:79
std::array< ShapeFunctionsDerivativesIntegrationPointArrayType, static_cast< int >IntegrationMethod::NumberOfIntegrationMethods)> ShapeFunctionsDerivativesContainerType
Definition: geometry_shape_function_container.h:94
double & ShapeFunctionDerivativeValue(IndexType IntegrationPointIndex, IndexType DerivativeOrderIndex, IndexType DerivativeOrderRowIndex, IndexType ShapeFunctionIndex, IntegrationMethod ThisMethod)
Definition: geometry_shape_function_container.h:372
std::size_t IndexType
Size types.
Definition: geometry_shape_function_container.h:73
TIntegrationMethodType IntegrationMethod
Defining enum of integration method.
Definition: geometry_shape_function_container.h:70
std::size_t SizeType
Definition: geometry_shape_function_container.h:74
bool HasIntegrationMethod(IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:212
std::array< DenseVector< Matrix >, static_cast< int >IntegrationMethod::NumberOfIntegrationMethods)> ShapeFunctionsLocalGradientsContainerType
Definition: geometry_shape_function_container.h:86
const IntegrationPointsArrayType & IntegrationPoints(IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:236
double ShapeFunctionValue(IndexType IntegrationPointIndex, IndexType ShapeFunctionIndex, IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:256
GeometryShapeFunctionContainer(IntegrationMethod ThisDefaultMethod, const IntegrationPointType &ThisIntegrationPoint, const Matrix &ThisShapeFunctionsValues, const Matrix &ThisShapeFunctionsGradients)
Constructor ONLY for single integration point with first derivatives.
Definition: geometry_shape_function_container.h:114
const Matrix & ShapeFunctionLocalGradient(IndexType IntegrationPointIndex, IndexType ShapeFunctionIndex, IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:302
virtual ~GeometryShapeFunctionContainer()
Destructor. Do nothing!!!
Definition: geometry_shape_function_container.h:185
IntegrationMethod DefaultIntegrationMethod() const
Definition: geometry_shape_function_container.h:207
GeometryShapeFunctionContainer()
Default Constructor.
Definition: geometry_shape_function_container.h:166
const Matrix & ShapeFunctionLocalGradient(IndexType IntegrationPointIndex) const
Definition: geometry_shape_function_container.h:286
const Matrix & ShapeFunctionDerivatives(IndexType DerivativeOrderIndex, IndexType IntegrationPointIndex, IntegrationMethod ThisMethod) const
Definition: geometry_shape_function_container.h:330
GeometryShapeFunctionContainer(const GeometryShapeFunctionContainer &rOther)
Copy constructor.
Definition: geometry_shape_function_container.h:175
Short class definition.
Definition: integration_point.h:52
Definition: amatrix_interface.h:41
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
def load(f)
Definition: ode_solve.py:307
integer i
Definition: TensorModule.f:17