G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsCoonsPatch.hpp
Go to the documentation of this file.
1 
14 #pragma once
15 
18 #include<gsNurbs/gsBSpline.h>
20 
21 namespace gismo
22 {
23 
24 template <typename T> const
26 {
27  const short_t dim = m_boundary.parDim();
28 
29  delete m_result;// delete any previous result
30  m_result = NULL;
31 
32  switch ( dim ) // dispatch to implementation
33  {
34  case 1:
35  compute_impl<2>();
36  break;
37  case 2:
38  compute_impl<3>();
39  break;
40  case 3:
41  compute_impl<4>();
42  break;
43  default:
44  GISMO_ERROR("Dimension "<< dim << "is invalid.");
45  break;
46  }
47 
48  return *m_result;
49 }
50 
51 template <typename T> template <short_t d>
53 {
54  gsTensorBSplineBasis<d,T> resultBasis; // Basis for the Coon's patch
55  gsMatrix<T> coefs; // CPs of the Coon's patch
56 
57  // Resolve boundary configuration and set boundary coefficients
58  this->preparePatch(resultBasis, coefs);
59 
60  //-------- Compute interior control points
61 
62  // Note: assuming that the param. domain is [0,1]^d
63  gsMatrix<T> gr[d]; // component-wise Greville points
64 
65  gsVector<unsigned,d> vend, // Multi-index of the furthest vertex
66  stride, // The strides of the tensor-basis
67  tmp;
68 
69  for (short_t k = 0; k < d; ++k)
70  {
71  gr [k] = resultBasis.component(k).anchors();
72  vend [k] = resultBasis.size(k) - 1;
73  stride[k] = resultBasis.stride(k);
74  }
75 
76  // Check whether there are any interior points to fill in
77  if ( (vend.array() < 2).any() )
78  {
79  gsWarn<<"There were no interior control points.\n";
80  m_result = resultBasis.makeGeometry( give(coefs) ).release();
81  return;
82  }
83 
84  // Multi-index of current interior CP (in iteration)
85  gsGridIterator<unsigned,CUBE,d> grid(gsVector<unsigned,d>::Ones(), vend);
86  // Multi-index of current cube element stencil (in iteration) ( [-1,1]^d --> [0,2]^d )
87  static const gsVector<unsigned,d> twos = gsVector<unsigned,d>::Constant(2);
88  gsGridIterator<unsigned,CUBE,d> cf(twos, false);
89 
90  for(; grid; ++grid) // loop over all interior coefficients
91  {
92  // grab current coefficient
93  typename gsMatrix<T>::RowXpr curCoef = coefs.row(stride.dot(*grid));
94 
95  cf.reset();
96  ++cf;// skip (0..0), ie. the coordinates of CP "*grid"
97 
98  for(; cf; ++cf) // loop over all cube elements (stencil around *grid)
99  {
100  // cf: ***
101  // *+*
102  // ***
103 
104  // Initialize weight sign
105  T w = -1.0;
106 
107  for(short_t k=0; k!=d; k++)
108  {
109  // Compute weight
110  if (0 != cf->at(k) ) // coordinate not equal to cf->at(k) ?
111  {
112  // fetch Greville point
113  const T x = gr[k](0, grid->at(k));
114  // update weight
115  w *= - ( 2 == cf->at(k) ? x : 1.0-x );
116  }
117 
118  // Compute index of contributing coefficient
119  // 0 : CP index coordinate of current CP grid->at(k)
120  // 1 : fixed to corner coordinate 0
121  // 2 : fixed to corner coordinate vend[k]
122  // tmp: *--*--*
123  // | |
124  // * + *
125  // | |
126  // *--*--*
127  tmp[k] = ( cf->at(k)==0 ? grid->at(k) :
128  cf->at(k)==1 ? 0 : vend[k] );
129  }
130 
131  // Add contribution of current cube element "*cf" to curCoef
132  curCoef += w * coefs.row( stride.dot(tmp) ) ;
133 
134  }//cf
135  }//grid
136 
137  // Coons' patch is ready
138  m_result = resultBasis.makeGeometry( give(coefs) ).release();
139 }
140 
141 
142 }// namespace gismo
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
Provides Coons&#39;s patch construction from boundary data.
index_t size() const
Returns the number of elements in the basis.
Definition: gsTensorBasis.h:108
#define short_t
Definition: gsConfig.h:35
S give(S &x)
Definition: gsMemory.h:266
A tensor product B-spline basis.
Definition: gsTensorBSplineBasis.h:36
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition: gsVector.h:35
#define gsWarn
Definition: gsDebug.h:50
virtual memory::unique_ptr< gsGeometry< T > > makeGeometry(gsMatrix< T > coefs) const =0
Create a gsGeometry of proper type for this basis with the given coefficient matrix.
const gsGeometry< T > & compute()
Main routine that performs the computation (to be implemented in derived classes) ...
Definition: gsCoonsPatch.hpp:25
Represents a B-spline curve/function with one parameter.
Computes a Coons&#39; patch parametrization given a set of boundary geometries. Parametrization is not gu...
Definition: gsCoonsPatch.h:32
unsigned stride(short_t dir) const
Returns the stride for dimension dir.
Definition: gsTensorBasis.h:889
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
Provides iteration over integer or numeric points in a (hyper-)cube.
const Basis_t & component(short_t dir) const
For a tensor product basis, return the (const) 1-d basis for the i-th parameter component.
Definition: gsTensorBSplineBasis.h:202
Provides declaration of TensorBSplineBasis abstract interface.