G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsCrossApPatch.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>
26 {
27  const short_t dim = m_boundary.dim();
28 
29  delete m_result;
30  m_result = NULL;
31 
32  switch ( dim ) // dispatch to implementation
33  {
34  case 1:
35  compute_impl<2>();
36  break;
37  /*
38  case 2:
39  compute_impl<3>();
40  break;
41  case 3:
42  compute_impl<4>();
43  break;
44  */
45  default:
46  GISMO_ERROR("Dimension "<< dim << "is invalid.");
47  break;
48  }
49  return *m_result;
50 }
51 
52 template <typename T>
53 template <unsigned d>
55 {
56  GISMO_STATIC_ASSERT(d==2,"gsCrossApPatch<T>::compute_impl only works for d=2 dimensions.");
57 
58  gsTensorBSplineBasis<d,T> resultBasis; // Basis
59  gsMatrix<T> coefs; // CPs
60 
61  // Resolve boundary configuration and set boundary coefficients
62  this->preparePatch(resultBasis, coefs);
63 
65  // Check whether there are any interior points to fill in
66  resultBasis.size_cwise(sz);
67  if ( (sz.array() < 3).all() )
68  {
69  gsWarn<<"There where no interior control points.\n";
70  m_result = resultBasis.makeGeometry( give(coefs) ).release();
71  return;
72  }
73 
74  gsMatrix<T> tmp0(sz[0],2), tmp1(sz[1],2), tmp;
75  gsMatrix<T,d,d> cross;
76 
77  for (index_t i = 0; i!=coefs.cols(); ++i)
78  {
79  tmp0.col(0) = m_boundary[0].coefs().col(i);
80  tmp0.col(1) = m_boundary[1].coefs().col(i);
81  tmp1.col(0) = m_boundary[2].coefs().col(i);
82  tmp1.col(1) = m_boundary[3].coefs().col(i);
83  cross(0,0) = tmp0(0 ,0);
84  cross(1,0) = tmp0(sz[0]-1,0);
85  cross(0,1) = tmp0(0 ,1);
86  cross(1,1) = tmp0(sz[0]-1,1);
87 
88  if ( math::abs(cross.determinant()) < (T)(1e-11) )
89  {
90  gsWarn <<"Corner data is rank-deficient ("<<i<<")\n";
91  //gsDebugVar(cross);
92  tmp = tmp0 *
93  cross.colPivHouseholderQr().solve(gsMatrix<T,2,2>::Identity())
94  * tmp1.transpose();
95  }
96  else
97  {
98  tmp = tmp0 * cross.inverse() * tmp1.transpose();
99  }
100 
101  coefs.col(i) = tmp.asVector();
102  }
103 
104  // return the patch
105  m_result = resultBasis.makeGeometry( give(coefs) ).release();
106 }
107 
108 
109 }// namespace gismo
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
#define short_t
Definition: gsConfig.h:35
S give(S &x)
Definition: gsMemory.h:266
#define index_t
Definition: gsConfig.h:32
void size_cwise(gsVector< index_t, s > &result) const
The number of basis functions in the direction of the k-th parameter component.
Definition: gsTensorBasis.h:441
A tensor product B-spline basis.
Definition: gsTensorBSplineBasis.h:36
#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.
Definition: gsCrossApPatch.hpp:25
Represents a B-spline curve/function with one parameter.
Provides cross approximation parameterizations from boundary data.
Computes a parametrization based on low rank cross approximation, given a set of boundary geometries...
Definition: gsCrossApPatch.h:26
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition: gsExpressions.h:4486
gsAsVector< T, Dynamic > asVector()
Returns the entries of the matrix resized to a n*m vector column-wise.
Definition: gsMatrix.h:240
Provides iteration over integer or numeric points in a (hyper-)cube.
Provides declaration of TensorBSplineBasis abstract interface.