G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsPointGrid.hpp
Go to the documentation of this file.
1 
15 #pragma once
16 
17 
18 namespace gismo
19 {
20 
21 /* **************** Utility functions **************** */
22 
23 
24 template<typename T> //cwiseSampleCount
25 gsVector<unsigned> uniformSampleCount (const gsVector<T>& lower,
26  const gsVector<T>& upper,
27  int numPoints)
28 {
29  const index_t d = lower.rows();
30  assert( d == upper.rows() );
31 
32  // TO do : phys. volume criterion
33  gsVector<T> span = upper - lower;
34  const T volume = span.prod();
35  const T h = math::pow(volume / (T)(numPoints), (T)(1) / (T)(d));
36 
37  gsVector<unsigned> np(d);
38 
39  for (index_t i = 0; i < d; ++i)
40  {
41  np[i] = cast<T,unsigned>(math::ceil( span[i] / h ) );
42  GISMO_ASSERT( np[i] > 0, "Something went wrong, number of points is zero..");
43  }
44 
45  return np;
46 }
47 
48 template<typename T>
49 void uniformIntervals(const gsVector<T>& lower,
50  const gsVector<T>& upper,
51  std::vector< std::vector<T> >& intervals,
52  int numIntervals)
53 {
54  const int d = lower.rows();
55  assert( d == upper.rows() );
56 
57  gsVector<unsigned> np = uniformSampleCount( lower, upper, numIntervals );
58 
59  // resize to dimension d without copying old contents, if any
60  intervals.clear();
61  intervals.resize(d);
62 
63  for (int i = 0; i < d; ++i)
64  {
65  int numInt = np[i] - 1;
66  if (numInt <= 1)
67  numInt = 1;
68 
69  const T h = (T)(1) / (T)(numInt);
70 
71  intervals[i].resize(numInt + 1);
72  for (int j = 0; j <= numInt; ++j)
73  intervals[i][j] = (T)(j) * h;
74  }
75 }
76 
77 
78 /* **************** Uniform grids described by limits/corners **************** */
79 
80 
81 template<class T>
83  gsVector<T> const & b,
84  gsVector<unsigned> const & np )
85 {
86  gsMatrix<T> res(a.size(), np.prod() );
87  gsGridIterator<T,CUBE> pt(a, b, np.cast<index_t>());
88  for(index_t c = 0; pt; ++pt, ++c)
89  res.col(c) = *pt;
90  return res;
91 }
92 
93 template<typename T>
95  const gsVector<T>& upper,
96  int numPoints)
97 {
98  const gsVector<unsigned> cwisePoints = uniformSampleCount(lower, upper, numPoints);
99  return gsPointGrid(lower, upper, cwisePoints); // note: structure lost
100 }
101 
102 };// namespace gismo
#define index_t
Definition: gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
gsMatrix< T > uniformPointGrid(const gsVector< T > &lower, const gsVector< T > &upper, int numPoints=1000)
Definition: gsPointGrid.hpp:94
gsMatrix< T > gsPointGrid(gsVector< T > const &a, gsVector< T > const &b, gsVector< unsigned > const &np)
Construct a Cartesian grid of uniform points in a hypercube, using np[i] points in direction i...
Definition: gsPointGrid.hpp:82