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.
nurbs_utilities.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: Thomas Oberbichler
11 //
12 // Ported from the ANurbs library (https://github.com/oberbichler/ANurbs)
13 //
14 
15 #if !defined(KRATOS_NURBS_UTILITY_H_INCLUDED )
16 #define KRATOS_NURBS_UTILITY_H_INCLUDED
17 
18 // System includes
19 
20 // External includes
21 
22 // Project includes
23 #include "containers/array_1d.h"
24 
25 namespace Kratos {
26 
29 
31 /*
32 * Provides universal geometrical utiltity functions for the computation of
33 * curve and surface NURBS/ B-Spline shape functions.
34  */
35 namespace NurbsUtilities
36 {
39 
40  typedef typename std::size_t IndexType;
41  typedef typename std::size_t SizeType;
42 
46  /*
47  * @brief the index of the upper limit of the span in which the ParameterT lays.
48  * From Piegl and Tiller, The NURBS Book, Algorithm A2.1
49  */
51  const SizeType PolynomialDegree,
52  const Vector& rKnots,
53  const double ParameterT)
54  {
55  const auto span = std::upper_bound(std::begin(rKnots) + PolynomialDegree,
56  std::end(rKnots) - PolynomialDegree, ParameterT) - std::begin(rKnots) - 1;
57  return span;
58  }
59 
60  /*
61  * @brief the index of the lower limit of the span in which the ParameterT lays.
62  * From Piegl and Tiller, The NURBS Book, Algorithm A2.1
63  */
65  const SizeType PolynomialDegree,
66  const Vector& rKnots,
67  const double ParameterT)
68  {
69  const auto span = std::lower_bound(std::begin(rKnots) + PolynomialDegree,
70  std::end(rKnots) - PolynomialDegree, ParameterT) - std::begin(rKnots) - 1;
71  return span;
72  }
73 
74  /*
75  * @brief Computes the degree of a nurbs/ b-spline shape by:
76  * @param NumberOfKnots and
77  * @param NumberOfControlPoints
78  */
79  inline SizeType GetPolynomialDegree(const SizeType NumberOfKnots, const SizeType NumberOfControlPoints)
80  {
81  return NumberOfKnots - NumberOfControlPoints + 1;
82  }
83 
84  /*
85  * @brief Computes the number of knots of a nurbs/ b-spline shape by:
86  * @param PolynomialDegree and
87  * @param NumberOfControlPoints
88  */
89  inline SizeType GetNumberOfKnots(const SizeType PolynomialDegree, const SizeType NumberOfControlPoints)
90  {
91  return NumberOfControlPoints + PolynomialDegree - 1;
92  }
93 
94  /*
95  * @brief Computes the number of control points of a nurbs/ b-spline shape by:
96  * @param PolynomialDegree and
97  * @param NumberOfKnots
98  */
99  inline SizeType GetNumberOfControlPoints(const SizeType PolynomialDegree, const SizeType NumberOfKnots)
100  {
101  return NumberOfKnots - PolynomialDegree + 1;
102  }
103 
104  /*
105  * @brief Computes the number of spans of a nurbs/ b-spline shape by:
106  * @param PolynomialDegree and
107  * @param NumberOfKnots
108  */
109  inline SizeType GetNumberOfSpans(const SizeType PolynomialDegree, const SizeType NumberOfKnots)
110  {
111  return NumberOfKnots - 2 * PolynomialDegree + 1;
112  }
113 
114  /*
115  * @brief Computes the binomial coefficient for (N || K).
116  */
117  static constexpr inline SizeType GetBinomCoefficient(const SizeType N, const SizeType K) noexcept
118  {
119  return
120  (K > N) ? 0 : // out of range
121  (K == 0 || K == N) ? 1 : // edge
122  (K == 1 || K == N - 1) ? N : // first
123  (K + K < N) ? // recursive:
124  (GetBinomCoefficient(N - 1, K - 1) * N) / K : // path to K = 1 faster
125  (GetBinomCoefficient(N - 1, K) * N) / (N - K); // path to K = n - 1 faster
126  }
127 
128 
129  /*
130  * @brief Computes a vector index from two matrix indicies.
131  * @return index within vector
132  */
134  const SizeType NumberPerRow, const SizeType NumberPerColumn,
135  const IndexType RowIndex, const IndexType ColumnIndex) noexcept
136  {
137  return ColumnIndex * NumberPerRow + RowIndex;
138  }
139 
146  const SizeType NumberPerRow, const SizeType NumberPerColumn, const SizeType NumberPerDepth,
147  const IndexType RowIndex, const IndexType ColumnIndex, const IndexType DepthIndex) noexcept
148  {
149  return DepthIndex * (NumberPerColumn*NumberPerRow) + ColumnIndex * NumberPerRow + RowIndex;
150  }
151 
152  /*
153  * @brief Computes two matrix indices from vector index.
154  * @return indices within Matrix
155  */
156  static inline std::pair<IndexType, IndexType> GetMatrixIndicesFromVectorIndex(
157  const SizeType NumberPerRow,
158  const SizeType NumberPerColumn,
159  const IndexType Index) noexcept
160  {
161  const IndexType row = Index % NumberPerRow;
162  const IndexType col = Index / NumberPerRow;
163 
164  return std::make_pair(row, col);
165  }
166 
173  const SizeType NumberPerRow,
174  const SizeType NumberPerColumn,
175  const SizeType NumberPerDepth,
176  const IndexType Index) noexcept
177  {
178  array_1d<IndexType,3> result;
179  const IndexType index_in_row_column_plane = Index % (NumberPerRow*NumberPerColumn);
180  result[0] = index_in_row_column_plane % NumberPerRow; // row
181  result[1] = index_in_row_column_plane / NumberPerRow; // column
182  result[2] = Index / (NumberPerRow*NumberPerColumn); // depth
183 
184  return result;
185  }
187 }; // class NurbsUtility
189 } // namespace Kratos
190 
191 #endif // KRATOS_NURBS_UTILITY_H_INCLUDED defined
Short class definition.
Definition: array_1d.h:61
end
Definition: DEM_benchmarks.py:180
std::size_t IndexType
Definition: nurbs_utilities.h:40
IndexType GetLowerSpan(const SizeType PolynomialDegree, const Vector &rKnots, const double ParameterT)
Definition: nurbs_utilities.h:64
SizeType GetNumberOfControlPoints(const SizeType PolynomialDegree, const SizeType NumberOfKnots)
Definition: nurbs_utilities.h:99
SizeType GetNumberOfSpans(const SizeType PolynomialDegree, const SizeType NumberOfKnots)
Definition: nurbs_utilities.h:109
std::size_t SizeType
Definition: nurbs_utilities.h:41
static constexpr SizeType GetBinomCoefficient(const SizeType N, const SizeType K) noexcept
Definition: nurbs_utilities.h:117
SizeType GetNumberOfKnots(const SizeType PolynomialDegree, const SizeType NumberOfControlPoints)
Definition: nurbs_utilities.h:89
IndexType GetUpperSpan(const SizeType PolynomialDegree, const Vector &rKnots, const double ParameterT)
Definition: nurbs_utilities.h:50
static std::pair< IndexType, IndexType > GetMatrixIndicesFromVectorIndex(const SizeType NumberPerRow, const SizeType NumberPerColumn, const IndexType Index) noexcept
Definition: nurbs_utilities.h:156
static constexpr IndexType GetVectorIndexFromMatrixIndices(const SizeType NumberPerRow, const SizeType NumberPerColumn, const IndexType RowIndex, const IndexType ColumnIndex) noexcept
Definition: nurbs_utilities.h:133
SizeType GetPolynomialDegree(const SizeType NumberOfKnots, const SizeType NumberOfControlPoints)
Definition: nurbs_utilities.h:79
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
float span
Definition: angle_finder.py:9
def Index()
Definition: hdf5_io_tools.py:38
N
Definition: sensitivityMatrix.py:29
K
Definition: sensitivityMatrix.py:73