G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsSpringPatch.hpp
Go to the documentation of this file.
1 
14 #pragma once
15 
18 #include<gsNurbs/gsBSpline.h>
20 
21 namespace gismo
22 {
23 template <typename T>
25 {
26  const short_t dim = m_boundary.dim();
27 
28  delete m_result;
29  m_result = NULL;
30 
31  switch ( dim ) // dispatch to implementation
32  {
33  case 1:
34  compute_impl<2>();
35  break;
36  case 2:
37  compute_impl<3>();
38  break;
39  case 3:
40  compute_impl<4>();
41  break;
42  default:
43  GISMO_ERROR("Dimension "<< dim << "is invalid.");
44  break;
45  }
46  return *m_result;
47 }
48 
49 template <typename T>
50 template <unsigned d>
52 {
53  gsTensorBSplineBasis<d,T> resultBasis; // Basis for the Coon's patch
54  gsMatrix<T> coefs; // CPs of the Coon's patch
55 
56  // Resolve boundary configuration and set boundary coefficients
57  this->preparePatch(resultBasis, coefs);
58 
59  gsVector<index_t,d> stride; // tensor strides
60 
61  // Check whether there are any interior points to fill in
62  resultBasis.size_cwise(stride);
63  if ( (stride.array() < 3).all() )
64  {
65  gsWarn<<"There where no interior control points.\n";
66  m_result = resultBasis.makeGeometry( give(coefs) ).release();
67  return;
68  }
69 
70  // Compute the tensor strides
71  resultBasis.stride_cwise(stride);
72 
73  // Initialize mapper
74  const int sz = resultBasis.size();
75  gsDofMapper mapper(resultBasis);
76  // boundary control point indices
77  gsMatrix<index_t> bnd = resultBasis.allBoundary();
78  mapper.markBoundary(0,bnd);
79  mapper.finalize();
80 
81  // Sparse system
82  gsSparseMatrix<T> A(mapper.freeSize(), mapper.freeSize() );
83  gsMatrix<T> b(mapper.freeSize(), coefs.cols() );
84  A.reserve( gsVector<int>::Constant(A.cols(), 2*d) );
85  A.setZero();
86  b.setZero();
87 
88  const T dd = 2*d;
89 
90  // Fill in system matrix A and right-hand side b
91  // 2 d c_i - sum neib(c_i) = 0
92  for ( int i = 0; i<sz ; i++ )
93  {
94  const index_t ii = mapper.index(i,0);// get i-index in the matrix
95 
96  if ( !mapper.is_free_index(ii))
97  continue;
98 
99  A(ii,ii) = dd;
100 
101  for ( unsigned k = 0; k<d; k++ ) // for all neighbors
102  {
103  for ( int s = -1; s<2; s+=2 ) // +/- (up or down)
104  {
105  const unsigned j = i + s * stride[k];
106  const index_t jj = mapper.index(j,0);// get j-index in the matrix
107 
108  if ( mapper.is_free_index(jj) ) // interior node ?
109  A(ii,jj) = -1;
110  else // boundary node
111  b.row(ii) += coefs.row(j);
112  }
113  }
114  }
115 
116  A.makeCompressed();
117 
118  // Solve system
119  // too slow to large-scale problem
120 // typename gsSparseSolver<T>::QR solver(A);
121  typename gsSparseSolver<T>::LU solver(A);
122  gsMatrix<T> solution = solver.solve ( b );
123 
124  // Fill in interior coefficients
125  for ( int i = 0; i<sz; i++ )
126  {
127  const index_t ii = mapper.index(i,0);
128 
129  if ( mapper.is_free_index(ii) ) // interior node?
130  {
131  coefs.row(i) = solution.row(ii);
132  }
133  }
134 
135  // return the spring patch
136  m_result = resultBasis.makeGeometry( give(coefs) ).release();
137 }
138 
139 
140 }// namespace gismo
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
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
Provides spring patch construction from boundary data.
#define index_t
Definition: gsConfig.h:32
const gsGeometry< T > & compute()
Main routine that performs the computation.
Definition: gsSpringPatch.hpp:24
Computes a parametrization based on the spring patch technique, given a set of boundary geometries...
Definition: gsSpringPatch.h:26
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.
Represents a B-spline curve/function with one parameter.
void stride_cwise(gsVector< index_t, d > &result) const
Returns the strides for all dimensions.
Definition: gsTensorBasis.h:512
gsMatrix< index_t > allBoundary() const
Definition: gsTensorBasis.hpp:283
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
Provides iteration over integer or numeric points in a (hyper-)cube.
Provides declaration of TensorBSplineBasis abstract interface.