gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
bezierBasis.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef BEZIER_BASIS_H
7 #define BEZIER_BASIS_H
8 
9 #include <set>
10 #include <map>
11 #include <vector>
12 #include "fullMatrix.h"
13 #include "FuncSpaceData.h"
14 #include "BasisFactory.h"
15 
16 class MElement;
17 class bezierBasisRaiser;
18 class bezierCoeff;
19 
20 class bezierBasis {
21 private:
22  // Number of corner coeff which are 'real' values of the expanded function
31 
32  friend class bezierBasisRaiser;
33  friend class bezierCoeff;
34 
35 public:
36  // Constructors
38  ~bezierBasis();
39 
40  // get methods
41  inline int getDim() const { return _exponents.size2(); }
42  inline int getType() const { return _funcSpaceData.getType(); }
43  inline int getOrder() const { return _funcSpaceData.getSpaceOrder(); }
44  inline int getDimSimplex() const { return _dimSimplex; }
45  inline int getNumCoeff() const { return _exponents.size1(); }
46  inline int getNumLagCoeff() const { return _numLagCoeff; }
47  inline FuncSpaceData getFuncSpaceData() const { return _funcSpaceData; }
48  const bezierBasisRaiser *getRaiser() const;
49 
51  {
53  }
54 
55 private:
56  void _construct();
57  void _constructPyr();
58 };
59 
61  // Let f, g, h be three function whose Bezier coefficients are given.
62  // This class allows to compute the Bezier coefficients of f*g and f*g*h.
63 private:
64  class _data {
65  friend class bezierBasisRaiser;
66 
67  private:
68  int i, j, k;
69  double val;
70 
71  public:
72  _data(double vv, int ii, int jj = -1, int kk = -1)
73  : i(ii), j(jj), k(kk), val(vv)
74  {
75  }
76  };
77  std::vector<std::vector<_data> > _raiser2, _raiser3;
78  const bezierBasis *_bfs;
79 
80 public:
81  bezierBasisRaiser(const bezierBasis *bezier) : _bfs(bezier)
82  {
84  };
85 
86  void computeCoeff(const fullVector<double> &coeffA,
87  const fullVector<double> &coeffB,
88  fullVector<double> &coeffSquare) const;
89  void computeCoeff(const fullVector<double> &coeffA,
90  const fullVector<double> &coeffB,
91  const fullVector<double> &coeffC,
92  fullVector<double> &coeffCubic) const;
93 
94 private:
95  void _fillRaiserData();
96  void _fillRaiserDataPyr();
97 };
98 
100  // This class is to avoid multiple allocation / deallocation during
101  // the subdivision algorithm.
102 private:
103  std::vector<double> _memory;
104  std::size_t _sizeBlocks;
105  std::size_t _numUsedBlocks;
107  std::size_t _endOfSearch;
108  // if a reallocation is performed, the pointers must be updated, we need to
109  // know which bezierCoeff have to be updated:
110  std::vector<bezierCoeff *> _bezierCoeff;
111 
112 public:
115 
116  // before to be used, the size of the blocks has to be specified
117  void setSizeBlocks(std::size_t size);
118 
119  double *giveBlock(bezierCoeff *bez); // gives a block of size _sizeBlocks[num]
120  void releaseBlock(double *block, bezierCoeff *bez);
121  void freeMemory();
122 
123 private:
124  void _checkEnoughMemory();
125 };
126 
127 class bezierCoeff {
128 private:
129  int _numPool;
132  int _r, _c; // size of the matrix
133  double *_data; // pointer on the first element
134  bool _ownData; // to know if data should be freed when object is deleted
135 
139  // FIXME: not thread safe. We shoud use one pool and one _sub per thread.
140  // The best would be to give the pool to the constructor.
141  // (the pools should be created and deleted e.g. by the plugin
142  // AnalyseMeshQuality)
143 
144 public:
146  bezierCoeff(const bezierCoeff &other, bool swap = false);
147 
148  bezierCoeff(const FuncSpaceData fsData,
149  const fullVector<double> &orderedLagCoeff, int numOfPool = -1);
150  bezierCoeff(const FuncSpaceData fsData,
151  const fullMatrix<double> &orderedLagCoeff, int numOfPool = -1);
152  // [orderedLagCoeff] : the Lagrange coefficients in the order given by
153  // function gmshGenerateOrderedPoints(..)
154  // -> use bezierBasis::getSamplingPointsToComputeBezierCoeff(..) method
155  // to get the sampling points at which compute those coefficients.
156  // [numOfPool] : the number of the pool (0 or 1) that should be used.
157  // To activate this functionality, first call usePools(..) function.
158 
159  ~bezierCoeff();
160 
161  static void usePools(std::size_t size0, std::size_t size1);
162  static void releasePools();
163  void updateDataPtr(long diff);
164 
165  inline int getPolynomialOrder() const
166  {
167  return _funcSpaceData.getSpaceOrder();
168  }
169  inline int getNumCoeff() const { return _r; }
170  inline int getNumColumns() const { return _c; }
171  inline int getNumCornerCoeff() const { return _basis->getNumLagCoeff(); }
172  int getIdxCornerCoeff(int i) const;
173  inline double getCornerCoeff(int k) const
174  {
175  return _data[getIdxCornerCoeff(k)];
176  }
177  inline double getCornerCoeff(int k, int j) const
178  {
179  return _data[getIdxCornerCoeff(k) + _r * j];
180  }
181  void getCornerCoeffs(fullVector<double> &) const;
182  void getCornerCoeffs(fullMatrix<double> &) const;
183  inline double *getDataPtr() { return _data; }
184  inline const bezierBasis *getBezierBasis() const { return _basis; }
185 
186  inline void setMatrixAsProxy(fullMatrix<double> &m) const
187  {
188  m.setAsProxy(_data, _r, _c);
189  }
190  inline void setVectorAsProxy(fullVector<double> &v) const
191  {
192  v.setAsProxy(_data, _r);
193  }
194 
195  void subdivide(std::vector<bezierCoeff *> &subCoeff) const;
196 
197  inline double operator()(int i) const { return _data[i]; }
198  inline double operator()(int i, int j) const { return _data[i + _r * j]; }
199 
200  inline double &operator()(int i) { return _data[i]; }
201  inline double &operator()(int i, int j) { return _data[i + _r * j]; }
202 
203 private:
212  };
213  static void _subdivideTet(SubdivisionTet which, int n, bezierCoeff &coeff);
214 
215  static void _subdivide(fullMatrix<double> &coeff, int npts, int start);
216  static void _subdivide(fullMatrix<double> &coeff, int npts, int start,
217  int inc);
218  static void _subdivideTriangle(const bezierCoeff &coeff, int start,
219  std::vector<bezierCoeff *> &subCoeff);
220  static void _subdivideTetrahedron(const bezierCoeff &coeff,
221  std::vector<bezierCoeff *> &vSubCoeff);
222  static void _subdivideQuadrangle(const bezierCoeff &coeff,
223  std::vector<bezierCoeff *> &subCoeff);
224  static void _subdivideHexahedron(const bezierCoeff &coeff,
225  std::vector<bezierCoeff *> &subCoeff);
226  static void _subdividePrism(const bezierCoeff &coeff,
227  std::vector<bezierCoeff *> &subCoeff);
228  static void _subdividePyramid(const bezierCoeff &coeff,
229  std::vector<bezierCoeff *> &subCoeff);
230  static void _copy(const bezierCoeff &from, int start, int num,
231  bezierCoeff &to);
232  static void _copyLine(const fullMatrix<double> &allSub, int n, int starti,
233  bezierCoeff &sub);
234  static void _copyQuad(const fullMatrix<double> &allSub, int n, int starti,
235  int startj, bezierCoeff &sub);
236  static void _copyHex(const fullMatrix<double> &allSub, int n, int starti,
237  int startj, int startk, bezierCoeff &sub);
238  static void _copyPyr(const fullMatrix<double> &allSub, int nij, int nk,
239  int starti, int startj, int startk, bezierCoeff &sub);
240  inline static int _ij2Index(int i, int j, int n)
241  {
242  return i + j * n - j * (j - 1) / 2;
243  }
244  inline static int _ijk2Index(int i, int j, int k, int n)
245  {
246  // the whole tet - the top tet + current triangle
247  return (n + 2) * (n + 1) * n / 6 - (n - k + 2) * (n - k + 1) * (n - k) / 6 +
248  j * (n - k) - j * (j - 1) / 2 + i;
249  }
250  void _computeCoefficients(const double *lagCoeffData);
251 };
252 
253 #endif
bezierBasis::getDimSimplex
int getDimSimplex() const
Definition: bezierBasis.h:44
bezierBasisRaiser::_data::k
int k
Definition: bezierBasis.h:68
bezierCoeff::usePools
static void usePools(std::size_t size0, std::size_t size1)
Definition: bezierBasis.cpp:818
bezierCoeff::getNumColumns
int getNumColumns() const
Definition: bezierBasis.h:170
bezierBasisRaiser::_data::_data
_data(double vv, int ii, int jj=-1, int kk=-1)
Definition: bezierBasis.h:72
fullVector::setAsProxy
void setAsProxy(const fullVector< scalar > &original, int r_start, int r)
Definition: fullMatrix.h:119
bezierCoeffMemoryPool::releaseBlock
void releaseBlock(double *block, bezierCoeff *bez)
Definition: bezierBasis.cpp:1514
bezierBasisRaiser::_data::j
int j
Definition: bezierBasis.h:68
bezierBasisRaiser::_data::val
double val
Definition: bezierBasis.h:69
bezierBasis::_ordered1dBezPoints
fullVector< double > _ordered1dBezPoints
Definition: bezierBasis.h:29
bezierCoeff::getNumCornerCoeff
int getNumCornerCoeff() const
Definition: bezierBasis.h:171
bezierCoeff::getCornerCoeff
double getCornerCoeff(int k, int j) const
Definition: bezierBasis.h:177
bezierCoeff::_copyPyr
static void _copyPyr(const fullMatrix< double > &allSub, int nij, int nk, int starti, int startj, int startk, bezierCoeff &sub)
Definition: bezierBasis.cpp:1437
fullVector< double >
bezierBasis::_exponents
fullMatrix< double > _exponents
Definition: bezierBasis.h:27
bezierCoeff::_subdivideTriangle
static void _subdivideTriangle(const bezierCoeff &coeff, int start, std::vector< bezierCoeff * > &subCoeff)
Definition: bezierBasis.cpp:1001
bezierCoeff::getBezierBasis
const bezierBasis * getBezierBasis() const
Definition: bezierBasis.h:184
bezierBasis
Definition: bezierBasis.h:20
bezierBasis::getSamplingPointsToComputeBezierCoeff
const fullMatrix< double > & getSamplingPointsToComputeBezierCoeff() const
Definition: bezierBasis.h:50
bezierCoeff::subdivV
@ subdivV
Definition: bezierBasis.h:206
bezierCoeff::operator()
double & operator()(int i)
Definition: bezierBasis.h:200
bezierCoeff::_ij2Index
static int _ij2Index(int i, int j, int n)
Definition: bezierBasis.h:240
bezierBasisRaiser::_raiser2
std::vector< std::vector< _data > > _raiser2
Definition: bezierBasis.h:77
bezierCoeff::_sub
static fullMatrix< double > _sub
Definition: bezierBasis.h:138
bezierCoeff::SubdivisionTet
SubdivisionTet
Definition: bezierBasis.h:204
bezierCoeffMemoryPool::_numUsedBlocks
std::size_t _numUsedBlocks
Definition: bezierBasis.h:105
bezierCoeff::_r
int _r
Definition: bezierBasis.h:132
bezierBasisRaiser::computeCoeff
void computeCoeff(const fullVector< double > &coeffA, const fullVector< double > &coeffB, fullVector< double > &coeffSquare) const
Definition: bezierBasis.cpp:552
bezierCoeff::operator()
double & operator()(int i, int j)
Definition: bezierBasis.h:201
bezierCoeff::_copyQuad
static void _copyQuad(const fullMatrix< double > &allSub, int n, int starti, int startj, bezierCoeff &sub)
Definition: bezierBasis.cpp:1407
bezierCoeff::_basis
const bezierBasis * _basis
Definition: bezierBasis.h:131
bezierCoeff::_copyHex
static void _copyHex(const fullMatrix< double > &allSub, int n, int starti, int startj, int startk, bezierCoeff &sub)
Definition: bezierBasis.cpp:1421
bezierCoeff::_subdividePyramid
static void _subdividePyramid(const bezierCoeff &coeff, std::vector< bezierCoeff * > &subCoeff)
Definition: bezierBasis.cpp:1344
bezierCoeffMemoryPool
Definition: bezierBasis.h:99
bezierCoeff::_funcSpaceData
FuncSpaceData _funcSpaceData
Definition: bezierBasis.h:130
bezierBasisRaiser::_fillRaiserData
void _fillRaiserData()
Definition: bezierBasis.cpp:291
bezierBasisRaiser::_data
Definition: bezierBasis.h:64
bezierCoeff::_subdividePrism
static void _subdividePrism(const bezierCoeff &coeff, std::vector< bezierCoeff * > &subCoeff)
Definition: bezierBasis.cpp:1308
bezierCoeff::_computeCoefficients
void _computeCoefficients(const double *lagCoeffData)
Definition: bezierBasis.cpp:738
bezierCoeff::_data
double * _data
Definition: bezierBasis.h:133
bezierCoeff::subdivide
void subdivide(std::vector< bezierCoeff * > &subCoeff) const
Definition: bezierBasis.cpp:938
fullMatrix< double >
bezierCoeff::_subdivideTet
static void _subdivideTet(SubdivisionTet which, int n, bezierCoeff &coeff)
Definition: bezierBasis.cpp:1086
bezierBasisRaiser::_bfs
const bezierBasis * _bfs
Definition: bezierBasis.h:78
bezierCoeff::_pool0
static bezierCoeffMemoryPool * _pool0
Definition: bezierBasis.h:136
bezierCoeff::_subdivideTetrahedron
static void _subdivideTetrahedron(const bezierCoeff &coeff, std::vector< bezierCoeff * > &vSubCoeff)
Definition: bezierBasis.cpp:1206
bezierCoeff::~bezierCoeff
~bezierCoeff()
Definition: bezierBasis.cpp:723
bezierBasis::_dimSimplex
int _dimSimplex
Definition: bezierBasis.h:24
bezierBasis::_funcSpaceData
const FuncSpaceData _funcSpaceData
Definition: bezierBasis.h:25
bezierBasis::getNumCoeff
int getNumCoeff() const
Definition: bezierBasis.h:45
bezierCoeff::_subdivide
static void _subdivide(fullMatrix< double > &coeff, int npts, int start)
Definition: bezierBasis.cpp:973
bezierCoeff
Definition: bezierBasis.h:127
bezierCoeff::getPolynomialOrder
int getPolynomialOrder() const
Definition: bezierBasis.h:165
bezierBasis::getOrder
int getOrder() const
Definition: bezierBasis.h:43
swap
void swap(double &a, double &b)
Definition: meshTriangulation.cpp:27
bezierBasis::getNumLagCoeff
int getNumLagCoeff() const
Definition: bezierBasis.h:46
bezierCoeffMemoryPool::_endOfSearch
std::size_t _endOfSearch
Definition: bezierBasis.h:107
bezierBasisRaiser::_raiser3
std::vector< std::vector< _data > > _raiser3
Definition: bezierBasis.h:77
bezierCoeff::bezierCoeff
bezierCoeff()
Definition: bezierBasis.h:145
bezierCoeff::getIdxCornerCoeff
int getIdxCornerCoeff(int i) const
Definition: bezierBasis.cpp:846
bezierCoeff::updateDataPtr
void updateDataPtr(long diff)
Definition: bezierBasis.cpp:838
bezierCoeff::getDataPtr
double * getDataPtr()
Definition: bezierBasis.h:183
bezierCoeff::getNumCoeff
int getNumCoeff() const
Definition: bezierBasis.h:169
bezierCoeff::_copyLine
static void _copyLine(const fullMatrix< double > &allSub, int n, int starti, bezierCoeff &sub)
Definition: bezierBasis.cpp:1398
bezierBasis::_constructPyr
void _constructPyr()
Definition: bezierBasis.cpp:257
bezierCoeff::getCornerCoeffs
void getCornerCoeffs(fullVector< double > &) const
Definition: bezierBasis.cpp:921
MElement
Definition: MElement.h:30
bezierCoeff::_subdivideQuadrangle
static void _subdivideQuadrangle(const bezierCoeff &coeff, std::vector< bezierCoeff * > &subCoeff)
Definition: bezierBasis.cpp:1249
bezierBasis::_samplingPntsLagDomain
fullMatrix< double > _samplingPntsLagDomain
Definition: bezierBasis.h:30
FuncSpaceData::getType
int getType() const
Definition: FuncSpaceData.h:65
bezierBasis::_matrixLag2Bez
fullMatrix< double > _matrixLag2Bez
Definition: bezierBasis.h:28
fullMatrix::size2
int size2() const
Definition: fullMatrix.h:275
bezierCoeff::_pool1
static bezierCoeffMemoryPool * _pool1
Definition: bezierBasis.h:137
bezierCoeffMemoryPool::_sizeBlocks
std::size_t _sizeBlocks
Definition: bezierBasis.h:104
bezierCoeff::_ijk2Index
static int _ijk2Index(int i, int j, int k, int n)
Definition: bezierBasis.h:244
FuncSpaceData
Definition: FuncSpaceData.h:16
bezierBasisRaiser::_data::i
int i
Definition: bezierBasis.h:68
bezierCoeff::subdivW
@ subdivW
Definition: bezierBasis.h:207
bezierCoeff::_copy
static void _copy(const bezierCoeff &from, int start, int num, bezierCoeff &to)
Definition: bezierBasis.cpp:1389
bezierCoeffMemoryPool::_bezierCoeff
std::vector< bezierCoeff * > _bezierCoeff
Definition: bezierBasis.h:110
bezierCoeff::node2CrossEdge03
@ node2CrossEdge03
Definition: bezierBasis.h:211
bezierCoeff::node1CrossEdge03
@ node1CrossEdge03
Definition: bezierBasis.h:210
fullMatrix::setAsProxy
void setAsProxy(const fullMatrix< scalar > &original)
Definition: fullMatrix.h:335
bezierBasis::getFuncSpaceData
FuncSpaceData getFuncSpaceData() const
Definition: bezierBasis.h:47
bezierCoeffMemoryPool::giveBlock
double * giveBlock(bezierCoeff *bez)
Definition: bezierBasis.cpp:1475
fullMatrix::size1
int size1() const
Definition: fullMatrix.h:274
FuncSpaceData.h
bezierBasis::_numLagCoeff
int _numLagCoeff
Definition: bezierBasis.h:23
bezierCoeffMemoryPool::_checkEnoughMemory
void _checkEnoughMemory()
Definition: bezierBasis.cpp:1544
bezierBasisRaiser
Definition: bezierBasis.h:60
bezierCoeff::operator()
double operator()(int i) const
Definition: bezierBasis.h:197
bezierCoeff::releasePools
static void releasePools()
Definition: bezierBasis.cpp:830
bezierCoeff::node3CrossEdge12
@ node3CrossEdge12
Definition: bezierBasis.h:209
bezierCoeff::getCornerCoeff
double getCornerCoeff(int k) const
Definition: bezierBasis.h:173
bezierCoeffMemoryPool::bezierCoeffMemoryPool
bezierCoeffMemoryPool()
Definition: bezierBasis.cpp:1454
FuncSpaceData::getSpaceOrder
int getSpaceOrder() const
Definition: FuncSpaceData.h:80
bezierCoeff::_subdivideHexahedron
static void _subdivideHexahedron(const bezierCoeff &coeff, std::vector< bezierCoeff * > &subCoeff)
Definition: bezierBasis.cpp:1272
bezierCoeff::node0CrossEdge12
@ node0CrossEdge12
Definition: bezierBasis.h:208
bezierBasis::getRaiser
const bezierBasisRaiser * getRaiser() const
Definition: bezierBasis.cpp:283
bezierBasis::_raiser
bezierBasisRaiser * _raiser
Definition: bezierBasis.h:26
bezierCoeff::operator()
double operator()(int i, int j) const
Definition: bezierBasis.h:198
bezierBasis::getType
int getType() const
Definition: bezierBasis.h:42
bezierCoeff::setMatrixAsProxy
void setMatrixAsProxy(fullMatrix< double > &m) const
Definition: bezierBasis.h:186
bezierBasis::bezierBasis
bezierBasis(FuncSpaceData data)
Definition: bezierBasis.cpp:185
bezierCoeff::setVectorAsProxy
void setVectorAsProxy(fullVector< double > &v) const
Definition: bezierBasis.h:190
bezierCoeff::subdivU
@ subdivU
Definition: bezierBasis.h:205
bezierCoeffMemoryPool::freeMemory
void freeMemory()
Definition: bezierBasis.cpp:1533
bezierBasisRaiser::_fillRaiserDataPyr
void _fillRaiserDataPyr()
Definition: bezierBasis.cpp:434
bezierCoeffMemoryPool::_currentIndexOfSearch
std::size_t _currentIndexOfSearch
Definition: bezierBasis.h:106
bezierCoeff::_c
int _c
Definition: bezierBasis.h:132
bezierBasis::_construct
void _construct()
Definition: bezierBasis.cpp:201
bezierCoeffMemoryPool::~bezierCoeffMemoryPool
~bezierCoeffMemoryPool()
Definition: bezierBasis.h:114
bezierCoeffMemoryPool::_memory
std::vector< double > _memory
Definition: bezierBasis.h:103
bezierBasisRaiser::bezierBasisRaiser
bezierBasisRaiser(const bezierBasis *bezier)
Definition: bezierBasis.h:81
fullMatrix.h
bezierCoeff::_numPool
int _numPool
Definition: bezierBasis.h:129
bezierBasis::getDim
int getDim() const
Definition: bezierBasis.h:41
bezierBasis::~bezierBasis
~bezierBasis()
Definition: bezierBasis.cpp:194
bezierCoeff::_ownData
bool _ownData
Definition: bezierBasis.h:134
BasisFactory.h
bezierCoeffMemoryPool::setSizeBlocks
void setSizeBlocks(std::size_t size)
Definition: bezierBasis.cpp:1462