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.
surface_in_nurbs_volume_geometry.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: Manuel Messmer
11 //
12 
13 #if !defined(KRATOS_SURFACE_IN_NURBS_VOLUME_INCLUDE_H )
14 #define KRATOS_SURFACE_IN_NURBS_VOLUME_INCLUDE_H
15 
16 // Project includes
17 #include "geometries/geometry.h"
18 
21 
22 namespace Kratos {
23 
24 template <int TWorkingSpaceDimension, class TVolumeContainerPointType>
25 class SurfaceInNurbsVolumeGeometry : public Geometry<typename TVolumeContainerPointType::value_type>
26 {
27 public:
30 
31  typedef typename TVolumeContainerPointType::value_type NodeType;
32 
34  typedef typename GeometryType::Pointer GeometryPointerType;
35 
37 
38  typedef typename BaseType::IndexType IndexType;
39  typedef typename BaseType::SizeType SizeType;
40 
42  typedef typename NurbsVolumeType::Pointer NurbsVolumePointerType;
43 
48 
49  // using base class functionalities.
51  using BaseType::pGetPoint;
52  using BaseType::GetPoint;
53 
54  static constexpr IndexType VOLUME_INDEX = -1;
55 
58 
62 
65  NurbsVolumePointerType pVolume,
66  GeometryPointerType pSurface)
67  : BaseType(PointsArrayType(), &msGeometryData)
68  , mpNurbsVolume(pVolume)
69  , mpSurface(pSurface)
70  {
71  }
72 
75  : BaseType(PointsArrayType(), &msGeometryData)
76  {};
77 
80  : BaseType(rOther)
81  , mpNurbsVolume(rOther.mpNurbsVolume)
82  , mpSurface(rOther.mpSurface)
83  {
84  }
85 
87  template<class TOtherVolumeContainerPointType>
89  : BaseType(rOther, &msGeometryData)
90  , mpNurbsVolume(rOther.mpNurbsVolume)
91  , mpSurface(rOther.mpSurface)
92  {
93  }
94 
96  ~SurfaceInNurbsVolumeGeometry() override = default;
97 
101 
104  {
105  BaseType::operator=(rOther);
106  mpNurbsVolume = rOther.mpNurbsVolume;
107  mpSurface = rOther.mpSurface;
108  return *this;
109  }
110 
112  template<class TOtherVolumeContainerPointType>
115  {
116  BaseType::operator=(rOther);
117  mpNurbsVolume = rOther.mpNurbsVolume;
118  mpSurface = rOther.mpSurface;
119  return *this;
120  }
121 
125 
126  typename BaseType::Pointer Create(
127  TVolumeContainerPointType const& ThisPoints) const override
128  {
129  KRATOS_ERROR << "SurfaceInNurbsVolumeGeometry cannot be created with 'PointsArrayType const& ThisPoints'. "
130  << "'Create' is not allowed as it would not contain the required pointers to the surface and the nurbs volume."
131  << std::endl;
132  }
133 
137 
145  {
146  const auto& const_this = *this;
147  return std::const_pointer_cast<GeometryType>(
148  const_this.pGetGeometryPart(Index));
149  }
150 
158  {
160  return mpNurbsVolume;
161 
162  KRATOS_ERROR << "Index " << Index << " not existing in SurfaceInNurbsVolume with ID: "
163  << this->Id() << std::endl;
164  }
165 
172  bool HasGeometryPart(const IndexType Index) const override
173  {
175  }
176 
180 
183  {
184  return mpSurface;
185  }
186 
189  {
190  return mpSurface;
191  }
192 
196 
198  Point Center() const override
199  {
200  Point local_center = mpSurface->Center();
201  Point global_center;
202  mpNurbsVolume->GlobalCoordinates(global_center, local_center);
203 
204  return global_center;
205  }
206 
208  double Area() const override
209  {
210  IntegrationPointsArrayType integration_points;
211  IntegrationInfo integration_info = this->GetDefaultIntegrationInfo();
212  CreateIntegrationPoints(integration_points, integration_info);
213 
214  double area = 0.0;
215  for (IndexType i = 0; i < integration_points.size(); ++i) {
216  const double determinant_jacobian = DeterminantOfJacobian(integration_points[i]);
217  area += integration_points[i].Weight() * determinant_jacobian;
218  }
219 
220  return area;
221  }
222 
226 
228  const CoordinatesArrayType& rPoint) const override
229  {
230  std::vector<CoordinatesArrayType> global_space_derivatives(3);
231  this->GlobalSpaceDerivatives( global_space_derivatives, rPoint, 1);
232 
233  BoundedMatrix<double,3,2> global_tangents;
234 
235  column(global_tangents,0) = global_space_derivatives[1];
236  column(global_tangents,1) = global_space_derivatives[2];
237 
238  return MathUtils<double>::GeneralizedDet( global_tangents );
239  }
240 
244 
247  {
248  return mpSurface->GetDefaultIntegrationInfo();
249  }
250 
254 
260  IntegrationPointsArrayType& rIntegrationPoints,
261  IntegrationInfo& rIntegrationInfo) const override
262  {
263  const auto surface_method = mpSurface->GetDefaultIntegrationMethod();
264  rIntegrationPoints = mpSurface->IntegrationPoints(surface_method);
265  }
266 
279  GeometriesArrayType& rResultGeometries,
280  IndexType NumberOfShapeFunctionDerivatives,
281  const IntegrationPointsArrayType& rIntegrationPoints,
282  IntegrationInfo& rIntegrationInfo) override
283  {
284 
285  // Shape function container.
286  NurbsVolumeShapeFunction shape_function_container(
287  mpNurbsVolume->PolynomialDegreeU(), mpNurbsVolume->PolynomialDegreeV(), mpNurbsVolume->PolynomialDegreeW(),
288  NumberOfShapeFunctionDerivatives);
289 
290  auto default_method = this->GetDefaultIntegrationMethod();
291  SizeType num_nonzero_cps = shape_function_container.NumberOfNonzeroControlPoints();
292 
293  Matrix N(1, num_nonzero_cps);
294  DenseVector<Matrix> shape_function_derivatives(NumberOfShapeFunctionDerivatives - 1);
295 
296  for (IndexType i = 0; i < NumberOfShapeFunctionDerivatives - 1; ++i) {
297  const IndexType num_derivatives = (2 + i) * (3 + i) / 2;
298  shape_function_derivatives[i].resize(num_nonzero_cps, num_derivatives);
299  }
300 
301  // Get integration points from surface
302  const SizeType number_of_points = rIntegrationPoints.size();
303 
304  // Resize containers.
305  if (rResultGeometries.size() != rIntegrationPoints.size() ){
306  rResultGeometries.resize(rIntegrationPoints.size());
307  }
308 
309  for (IndexType point_index = 0; point_index < number_of_points; ++point_index)
310  {
311 
312  array_1d<double,3> global_coordinates;
313  mpSurface->GlobalCoordinates(global_coordinates, rIntegrationPoints[point_index]);
314 
315  shape_function_container.ComputeBSplineShapeFunctionValues(
316  mpNurbsVolume->KnotsU(), mpNurbsVolume->KnotsV(), mpNurbsVolume->KnotsW(),
317  global_coordinates[0], global_coordinates[1], global_coordinates[2]);
318 
320  PointsArrayType nonzero_control_points(num_nonzero_cps);
321  auto cp_indices = shape_function_container.ControlPointIndices(
322  mpNurbsVolume->NumberOfControlPointsU(), mpNurbsVolume->NumberOfControlPointsV(), mpNurbsVolume->NumberOfControlPointsW());
323  for (IndexType j = 0; j < num_nonzero_cps; j++) {
324  nonzero_control_points(j) = mpNurbsVolume->pGetPoint(cp_indices[j]);
325  }
326 
328  for (IndexType j = 0; j < num_nonzero_cps; j++) {
329  N(0, j) = shape_function_container(j, 0);
330  }
331 
333  if (NumberOfShapeFunctionDerivatives > 0) {
334  IndexType shape_derivative_index = 1;
335  for (IndexType n = 0; n < NumberOfShapeFunctionDerivatives - 1; ++n) {
336  const IndexType num_derivatives = (2 + n) * (3 + n) / 2;
337  for (IndexType k = 0; k < num_derivatives; ++k) {
338  for (IndexType j = 0; j < num_nonzero_cps; ++j) {
339  shape_function_derivatives[n](j, k) = shape_function_container(j, shape_derivative_index + k);
340  }
341  }
342  shape_derivative_index += num_derivatives;
343  }
344  }
345 
347  default_method, rIntegrationPoints[point_index],
348  N, shape_function_derivatives);
349 
350  Matrix jacobian_surface;
351  mpSurface->Jacobian(jacobian_surface, rIntegrationPoints[point_index]);
352 
354  data_container, nonzero_control_points,
355  jacobian_surface, this);
356  }
357  }
358 
362 
371  CoordinatesArrayType& rResult,
372  const CoordinatesArrayType& rLocalCoordinates
373  ) const override
374  {
375  // Compute the coordinates of the embedded curve in the parametric space of the surface
376  CoordinatesArrayType result_local = mpSurface->GlobalCoordinates(rResult, rLocalCoordinates);
377 
378  // Compute and return the coordinates of the surface in the geometric space
379  return mpNurbsVolume->GlobalCoordinates(rResult, result_local);
380  }
381 
391  std::vector<CoordinatesArrayType>& rGlobalSpaceDerivatives,
392  const CoordinatesArrayType& rCoordinates,
393  const SizeType DerivativeOrder) const override
394  {
395 
396  KRATOS_ERROR_IF( DerivativeOrder > 1 ) << "SurfaceInNurbsVolume :: Global Space Derivatives are not yet "
397  << "implemented for derivative orders > 1." << std::endl;
398 
399  // Check size of output
400  if (rGlobalSpaceDerivatives.size() != 3) {
401  rGlobalSpaceDerivatives.resize(3);
402  }
403 
404  // Map rCoordinates into local space.
405  array_1d<double,3> global_coordinates;
406  mpSurface->GlobalCoordinates(global_coordinates, rCoordinates);
407 
408  // Compute the gradients of the volume in the geometric space
409  std::vector<CoordinatesArrayType> volume_derivatives(1 + DerivativeOrder*3);
410  mpNurbsVolume->GlobalSpaceDerivatives(volume_derivatives, global_coordinates, DerivativeOrder);
411 
412  rGlobalSpaceDerivatives[0] = global_coordinates;
413 
414  BoundedMatrix<double,3,3> volume_jacobian;
415  column(volume_jacobian,0) = volume_derivatives[1];
416  column(volume_jacobian,1) = volume_derivatives[2];
417  column(volume_jacobian,2) = volume_derivatives[3];
418 
419  Matrix jacobian_surface;
420  mpSurface->Jacobian(jacobian_surface, rCoordinates);
421 
422  BoundedMatrix<double,3,2> global_tangents = prod(volume_jacobian, jacobian_surface);
423  rGlobalSpaceDerivatives[1] = column(global_tangents,0);
424  rGlobalSpaceDerivatives[2] = column(global_tangents,1);
425  }
426 
430 
432  {
434  }
435 
437  {
439  }
440 
444 
446  std::string Info() const override
447  {
448  return "2 dimensional surface in 3D nurbs volume.";
449  }
450 
452  void PrintInfo(std::ostream& rOStream) const override
453  {
454  rOStream << "2 dimensional surface in 3D nurbs volume.";
455  }
456 
458  void PrintData(std::ostream& rOStream) const override
459  {
460  }
461 
463 private:
466 
467  static const GeometryData msGeometryData;
468 
469  static const GeometryDimension msGeometryDimension;
470 
474 
475  NurbsVolumePointerType mpNurbsVolume;
476  GeometryPointerType mpSurface;
477 
481 
482  friend class Serializer;
483 
484  void save(Serializer& rSerializer) const override
485  {
487  rSerializer.save("pNurbsVolume", mpNurbsVolume);
488  rSerializer.save("pSurface", mpSurface);
489  }
490 
491  void load(Serializer& rSerializer) override
492  {
494  rSerializer.load("pNurbsVolume", mpNurbsVolume);
495  rSerializer.load("pSurface", mpSurface);
496  }
497 
499 
500 }; // class SurfaceInNurbsVolumeGeometry
501 
502 template<int TWorkingSpaceDimension, class TVolumeContainerPointType>
503 const GeometryData SurfaceInNurbsVolumeGeometry<TWorkingSpaceDimension, TVolumeContainerPointType>::msGeometryData(
506  {}, {}, {});
507 
508 template<int TWorkingSpaceDimension, class TVolumeContainerPointType>
510 
511 } // namespace Kratos
512 
513 #endif // KRATOS_SURFACE_IN_NURBS_VOLUME_INCLUDE_H defined
static GeometryPointerType CreateQuadraturePointSurfaceInVolume(GeometryShapeFunctionContainer< GeometryData::IntegrationMethod > &rShapeFunctionContainer, PointsArrayType rPoints, Matrix LocalTangentMatrix, GeometryType *pGeometryParent)
Definition: quadrature_points_utility.h:133
Definition: geometry_data.h:60
KratosGeometryType
Definition: geometry_data.h:110
KratosGeometryFamily
Definition: geometry_data.h:91
Definition: geometry_dimension.h:42
Geometry base class.
Definition: geometry.h:71
Geometry & operator=(const Geometry &rOther)
Definition: geometry.h:400
std::vector< IntegrationPointType > IntegrationPointsArrayType
Definition: geometry.h:161
std::size_t SizeType
Definition: geometry.h:144
const TPointType::Pointer pGetPoint(const int Index) const
Definition: geometry.h:1790
std::size_t IndexType
Definition: geometry.h:137
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
virtual void CreateQuadraturePointGeometries(GeometriesArrayType &rResultGeometries, IndexType NumberOfShapeFunctionDerivatives, const IntegrationPointsArrayType &rIntegrationPoints, IntegrationInfo &rIntegrationInfo)
Definition: geometry.h:2331
static constexpr IndexType BACKGROUND_GEOMETRY_INDEX
Definition: geometry.h:220
IntegrationMethod GetDefaultIntegrationMethod() const
Definition: geometry.h:2004
TPointType const & GetPoint(const int Index) const
Definition: geometry.h:1816
Definition: geometry_shape_function_container.h:60
Integration information for the creation of integration points.
Definition: integration_info.h:35
Definition: amatrix_interface.h:41
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
static double GeneralizedDet(const TMatrixType &rA)
Calculates the determinant of any matrix (no check performed on matrix size)
Definition: math_utils.h:634
A volume geometry based on a full 3-dimensional BSpline tensor product.
Definition: nurbs_volume_geometry.h:46
Definition: nurbs_volume_shape_functions.h:32
void ComputeBSplineShapeFunctionValues(const Vector &rKnotsU, const Vector &rKnotsV, const Vector &rKnotsW, const double ParameterU, const double ParameterV, const double ParameterW)
Computes the shape function values at the given parameter.
Definition: nurbs_volume_shape_functions.h:383
std::vector< int > ControlPointIndices(SizeType NumberOfControlPointsU, SizeType NumberOfControlPointsV, SizeType NumberOfControlPointsW) const
Definition: nurbs_volume_shape_functions.h:240
SizeType NumberOfNonzeroControlPoints() const
Definition: nurbs_volume_shape_functions.h:201
Point class.
Definition: point.h:59
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
size_type size() const
Definition: pointer_vector.h:255
void resize(size_type dim)
Definition: pointer_vector.h:314
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
Definition: surface_in_nurbs_volume_geometry.h:26
GeometryType::Pointer GeometryPointerType
Definition: surface_in_nurbs_volume_geometry.h:34
BaseType::Pointer Create(TVolumeContainerPointType const &ThisPoints) const override
Definition: surface_in_nurbs_volume_geometry.h:126
~SurfaceInNurbsVolumeGeometry() override=default
Destructor.
GeometryPointerType pGetSurface()
Returns the NurbsSurface::Pointer of this brep.
Definition: surface_in_nurbs_volume_geometry.h:182
IntegrationInfo GetDefaultIntegrationInfo() const override
Provides the default integration dependent on the polynomial degree.
Definition: surface_in_nurbs_volume_geometry.h:246
SurfaceInNurbsVolumeGeometry(NurbsVolumePointerType pVolume, GeometryPointerType pSurface)
Constructor.
Definition: surface_in_nurbs_volume_geometry.h:64
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: surface_in_nurbs_volume_geometry.h:452
double DeterminantOfJacobian(const CoordinatesArrayType &rPoint) const override
Definition: surface_in_nurbs_volume_geometry.h:227
void GlobalSpaceDerivatives(std::vector< CoordinatesArrayType > &rGlobalSpaceDerivatives, const CoordinatesArrayType &rCoordinates, const SizeType DerivativeOrder) const override
This method maps from dimension space to working space and computes the number of derivatives at the ...
Definition: surface_in_nurbs_volume_geometry.h:390
TVolumeContainerPointType::value_type NodeType
Definition: surface_in_nurbs_volume_geometry.h:31
BaseType::PointsArrayType PointsArrayType
Definition: surface_in_nurbs_volume_geometry.h:45
bool HasGeometryPart(const IndexType Index) const override
This function is used to check if the index is GeometryType::BACKGROUND_GEOMETRY_INDEX.
Definition: surface_in_nurbs_volume_geometry.h:172
Geometry< NodeType > GeometryType
Definition: surface_in_nurbs_volume_geometry.h:33
const GeometryPointerType pGetGeometryPart(const IndexType Index) const override
This function returns the pointer of the geometry which is corresponding to the BACKGROUND_GEOMETRY_I...
Definition: surface_in_nurbs_volume_geometry.h:157
SurfaceInNurbsVolumeGeometry()
Default constructor.
Definition: surface_in_nurbs_volume_geometry.h:74
NurbsVolumeGeometry< TVolumeContainerPointType > NurbsVolumeType
Definition: surface_in_nurbs_volume_geometry.h:41
Geometry< NodeType > BaseType
Definition: surface_in_nurbs_volume_geometry.h:36
GeometryData::KratosGeometryFamily GetGeometryFamily() const override
Definition: surface_in_nurbs_volume_geometry.h:431
double Area() const override
Computes the area of the underlying surface.
Definition: surface_in_nurbs_volume_geometry.h:208
Point Center() const override
Provides the center of the underlying surface.
Definition: surface_in_nurbs_volume_geometry.h:198
BaseType::SizeType SizeType
Definition: surface_in_nurbs_volume_geometry.h:39
SurfaceInNurbsVolumeGeometry(SurfaceInNurbsVolumeGeometry< TWorkingSpaceDimension, TOtherVolumeContainerPointType > const &rOther)
Copy constructor, with different point type.
Definition: surface_in_nurbs_volume_geometry.h:88
static constexpr IndexType VOLUME_INDEX
Definition: surface_in_nurbs_volume_geometry.h:54
GeometryData::KratosGeometryType GetGeometryType() const override
Definition: surface_in_nurbs_volume_geometry.h:436
CoordinatesArrayType & GlobalCoordinates(CoordinatesArrayType &rResult, const CoordinatesArrayType &rLocalCoordinates) const override
This method maps from dimension space to working space.
Definition: surface_in_nurbs_volume_geometry.h:370
void CreateIntegrationPoints(IntegrationPointsArrayType &rIntegrationPoints, IntegrationInfo &rIntegrationInfo) const override
Returns the integration points of the surface.
Definition: surface_in_nurbs_volume_geometry.h:259
NurbsVolumeType::Pointer NurbsVolumePointerType
Definition: surface_in_nurbs_volume_geometry.h:42
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: surface_in_nurbs_volume_geometry.h:458
SurfaceInNurbsVolumeGeometry(SurfaceInNurbsVolumeGeometry const &rOther)
Copy constructor.
Definition: surface_in_nurbs_volume_geometry.h:79
BaseType::IntegrationPointsArrayType IntegrationPointsArrayType
Definition: surface_in_nurbs_volume_geometry.h:47
const GeometryPointerType pGetSurface() const
Returns the const NurbsSurface::Pointer of this brep.
Definition: surface_in_nurbs_volume_geometry.h:188
SurfaceInNurbsVolumeGeometry & operator=(const SurfaceInNurbsVolumeGeometry &rOther)
Assignment operator.
Definition: surface_in_nurbs_volume_geometry.h:103
BaseType::IndexType IndexType
Definition: surface_in_nurbs_volume_geometry.h:38
BaseType::GeometriesArrayType GeometriesArrayType
Definition: surface_in_nurbs_volume_geometry.h:46
void CreateQuadraturePointGeometries(GeometriesArrayType &rResultGeometries, IndexType NumberOfShapeFunctionDerivatives, const IntegrationPointsArrayType &rIntegrationPoints, IntegrationInfo &rIntegrationInfo) override
This method creates a list of quadrature point geometries from a list of integration points.
Definition: surface_in_nurbs_volume_geometry.h:278
GeometryPointerType pGetGeometryPart(const IndexType Index) override
This function returns the pointer of the geometry which is corresponding to the BACKGROUND_GEOMETRY_I...
Definition: surface_in_nurbs_volume_geometry.h:144
BaseType::CoordinatesArrayType CoordinatesArrayType
Definition: surface_in_nurbs_volume_geometry.h:44
KRATOS_CLASS_POINTER_DEFINITION(SurfaceInNurbsVolumeGeometry)
Counted pointer of SurfaceInNurbsVolumeGeometry.
SurfaceInNurbsVolumeGeometry & operator=(SurfaceInNurbsVolumeGeometry< TWorkingSpaceDimension, TOtherVolumeContainerPointType > const &rOther)
Assignment operator for geometries with different point type.
Definition: surface_in_nurbs_volume_geometry.h:113
std::string Info() const override
Turn back information as a string.
Definition: surface_in_nurbs_volume_geometry.h:446
Short class definition.
Definition: array_1d.h:61
#define KRATOS_SERIALIZE_SAVE_BASE_CLASS(Serializer, BaseType)
Definition: define.h:812
#define KRATOS_SERIALIZE_LOAD_BASE_CLASS(Serializer, BaseType)
Definition: define.h:815
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
const GeometryData BrepCurve< TContainerPointType, TContainerPointEmbeddedType >::msGeometryData & msGeometryDimension
Definition: brep_curve.h:483
AMatrix::MatrixColumn< const TExpressionType > column(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t ColumnIndex)
Definition: amatrix_interface.h:637
def Index()
Definition: hdf5_io_tools.py:38
def load(f)
Definition: ode_solve.py:307
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17