38 template<
short_t d,
class T>
41 GISMO_ASSERT(d-1>=0,
"d must be greater or equal than 1");
42 GISMO_ASSERT(dir_fixed>=0 && static_cast<index_t>(dir_fixed)<d,
"cannot fix a dir greater than dim or smaller than 0");
43 const boxSide side(dir_fixed,0);
45 this->m_bases[0]->boundaryBasis(side);
46 typename gsHBSplineBasis<d,T>::BoundaryBasisType* bBasis =
47 new typename gsHBSplineBasis<d,T>::BoundaryBasisType(*bBSplineBasis);
51 std::vector<index_t> boxes;
52 this->getBoxesAlongSlice(dir_fixed,par,boxes);
59 template<
short_t d,
class T>
62 os <<
"Hierarchical B-spline ";
69 template<
short_t d,
class T>
76 template<
short_t d,
class T>
79 int lvl = this->levelOf(i);
80 this->m_bases[lvl]->evalSingle_into(
81 this->m_xmatrix[lvl][ i - this->m_xmatrix_offset[lvl] ], u, result);
84 template<
short_t d,
class T>
87 int lvl = this->levelOf(i);
88 this->m_bases[lvl]->derivSingle_into(
89 this->m_xmatrix[lvl][ i - this->m_xmatrix_offset[lvl] ], u, result);
92 template<
short_t d,
class T>
95 int lvl = this->levelOf(i);
96 this->m_bases[lvl]->deriv2Single_into(
97 this->m_xmatrix[lvl][ i - this->m_xmatrix_offset[lvl] ], u, result);
100 template<
short_t d,
class T>
106 this->numActive_into(u, nact);
108 result.setZero(nact.maxCoeff(), u.cols());
111 for(
index_t j = 0; j < u.cols(); j++)
119 for(
index_t i = 0; i != act.rows(); i++)
122 result(i,j) = curr_res(0,0);
127 template<
short_t d,
class T>
133 this->numActive_into(u, nact);
135 result.setZero( d*nact.maxCoeff(), u.cols() );
138 for(
index_t j = 0; j < u.cols(); j++)
146 for(
index_t i = 0; i < act.rows(); i++)
149 result.block(i*d,j,d,1).noalias() = curr_res;
154 template<
short_t d,
class T>
160 const int blocksize = d*(d + 1)/2;
163 this->numActive_into(u, nact);
164 result.resize( blocksize * nact.maxCoeff(), u.cols() );
171 for(
index_t j = 0; j < u.cols(); j++)
179 for(
index_t i = 0; i < act.rows(); i++)
182 result.block(i*blocksize,j,blocksize,1) = curr_res;
187 template<
short_t d,
class T>
197 std::vector<std::vector<T> > knots(d);
199 std::vector<CMatrix> xmatLvl_i, xmatLvl_i1;
201 this->setActiveToLvl(0, xmatLvl_i );
203 for(
unsigned i = 1; i <= this->maxLevel(); ++i)
205 for(
unsigned dim = 0; dim != d; ++dim)
217 this->setActiveToLvl(i, xmatLvl_i1);
220 result.push_back(crs);
222 xmatLvl_i.swap(xmatLvl_i1);
227 template<
short_t d,
class T>
230 int size1= 0;
int size2 = 0;
232 for(
unsigned int i =0; i< old.size();i++){
233 size1 += old[i].size();
235 for(
unsigned int i =0; i< n.size();i++){
236 size2 += n[i].size();
244 for (
unsigned int i = 0; i < old.size(); i++)
248 for(
unsigned int l =0; l < i; l++)
250 start_lv_i += n[l].size();
253 for (
unsigned int j = 0; j < old[i].size();j++)
256 const unsigned old_ij = old[i][j];
258 if( n[i].bContains(old_ij) )
260 result(start_lv_i +
std::distance(n[i].begin(), n[i].find_it_or_fail(old_ij) ),glob_numb ) = 1;
278 const int pos = start_lv_i + n[i].size() +
std::distance(n[i+1].begin(), n[i+1].find_it_or_fail(k.row()));
279 result(pos,glob_numb) = k.value();
289 template<
short_t d,
class T>
292 int size1= 0;
int size2 = 0;
294 for(
unsigned int i =0; i< old.size();i++){
295 size1 += old[i].
size();
297 for(
unsigned int i =0; i< n.size();i++){
298 size2 += n[i].size();
300 gsSparseMatrix<T> result(size2,size1);
308 std::vector<gsSparseMatrix<T,ColMajor> > temptransfer;
309 temptransfer.resize(transfer.size());
310 for (
unsigned int i = 0; i < transfer.size();i++){
311 temptransfer[i] = transfer[i];
314 for (
unsigned int i = 0; i < old.size(); i++)
318 for(
unsigned int l =0; l < i; l++)
320 start_lv_i += n[l].size();
324 for (
unsigned int j = 0; j < old[i].size();j++)
328 for(
unsigned int l =0; l < i; l++)
330 start_lv_i += n[l].size();
332 const unsigned old_ij = old[i][j];
334 if( n[i].bContains(old_ij) )
336 result(start_lv_i +
std::distance(n[i].begin(), n[i].find_it_or_fail(old_ij) ),glob_numb ) = 1;
340 std::vector<lvl_coef> coeffs;
345 coeffs.push_back(temp);
346 for (
size_t coeff_index = 0; coeff_index < coeffs.size(); ++coeff_index)
348 const lvl_coef coeff = coeffs[coeff_index];
351 for(
unsigned int l =0; l < coeff.lvl; l++)
353 start_lv_i += n[l].size();
356 for(
typename gsSparseMatrix<T,ColMajor>::InnerIterator k(temptransfer[coeff.lvl],coeff.pos); k; ++k)
358 if(n[coeff.lvl+1].bContains(k.row()))
362 const int pos = start_lv_i + n[coeff.lvl].size() +
std::distance(n[coeff.lvl+1].begin(), n[coeff.lvl+1].find_it_or_fail(k.row()));
365 result(pos,glob_numb) += coeff.coef * temptransfer[coeff.lvl](k.row(), coeff.pos);
369 temp.coef = temptransfer[coeff.lvl](k.row(), coeff.pos) * coeff.coef;
370 temp.lvl = coeff.lvl+1;
371 coeffs.push_back(temp);
386 template<
short_t d,
class T>
387 gsSparseMatrix<T> gsHBSplineBasis<d,T>::coarsening_direct2(
const std::vector<gsSortedVector<index_t> >& old,
388 const std::vector<gsSortedVector<index_t> >& n,
389 const std::vector<gsSparseMatrix<T,RowMajor> >& transfer)
const
391 int size1 = 0, size2 = 0;
393 for(
unsigned int i =0; i< old.size();i++){
394 size1 += old[i].size();
396 for(
unsigned int i =0; i< n.size();i++){
397 size2 += n[i].size();
399 gsSparseMatrix<T> result(size2,size1);
407 std::vector<gsSparseMatrix<T,ColMajor> > temptransfer;
408 temptransfer.resize(transfer.size());
409 for (
unsigned int i = 0; i < transfer.size();i++){
410 temptransfer[i] = transfer[i];
414 for (
unsigned int i = 0; i < old.size(); i++)
418 for(
unsigned int l =0; l < i; l++)
420 start_lv_i += n[l].size();
424 for (
unsigned int j = 0; j < old[i].size();j++)
428 for(
unsigned int l =0; l < i; l++)
430 start_lv_i += n[l].size();
432 const unsigned old_ij = old[i][j];
434 if( n[i].bContains(old_ij) )
436 result(start_lv_i +
std::distance(n[i].begin(), n[i].find_it_or_fail(old_ij) ),glob_numb ) = 1;
441 gsMatrix<index_t, d, 2> supp(d, 2);
442 this->m_bases[i]->elementSupport_into(old_ij, supp);
445 gsSparseVector<T,RowMajor> t(this->m_bases[i]->size());
450 for(
unsigned int k = i+1; k < n.size();k++){
452 for(
unsigned int l =0; l < k-1; l++)
454 start_lv_i += n[l].size();
462 gsSparseVector<T,RowMajor> M;
464 M = temptransfer[k-1] * t.transpose();
467 for(
int l = 0 ; l < M.size();l++)
471 if(n[k].bContains(l))
475 const int pos = start_lv_i + n[k-1].size() +
std::distance(n[k].begin(), n[k].find_it_or_fail(l));
478 result(pos,glob_numb) = M[l];
500 template<
short_t d,
class T>
501 class gsXml< gsHBSplineBasis<d,T> >
506 GSXML_COMMON_FUNCTIONS(gsHBSplineBasis<TMPLA2(d,T)>);
507 static std::string tag () {
return "Basis"; }
508 static std::string type () {
return "HBSplineBasis"+ (d>1 ?
to_string(d):
""); }
510 static gsHBSplineBasis<d,T> *
get (gsXmlNode * node)
512 return getHTensorBasisFromXml< gsHBSplineBasis<d,T> > (node);
515 static gsXmlNode * put (
const gsHBSplineBasis<d,T> & obj,
518 return putHTensorBasisToXml< gsHBSplineBasis<d,T> > (obj, data);
Provides definition of HTensorBasis abstract interface.
void deriv2Single_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the (partial) derivatives of the i-th basis function at points u into result.
Definition: gsHBSplineBasis.hpp:93
T distance(gsMatrix< T > const &A, gsMatrix< T > const &B, index_t i=0, index_t j=0, bool cols=false)
compute a distance between the point number in the set and the point number <j> in the set ; by def...
void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the second derivatives of all active basis function at points u.
Definition: gsHBSplineBasis.hpp:155
A hierarchical B-spline basis of parametric dimension d.
Definition: gsHBSplineBasis.h:35
gsSparseMatrix< T > coarsening(const std::vector< gsSortedVector< index_t > > &old, const std::vector< gsSortedVector< index_t > > &n, const gsSparseMatrix< T, RowMajor > &transfer) const
returns a transfer matrix using the characteristic matrix of the old and new basis ...
Definition: gsHBSplineBasis.hpp:228
#define index_t
Definition: gsConfig.h:32
void printBasic(std::ostream &os=gsInfo) const
Prints the spline-space hierarchy.
Definition: gsHTensorBasis.h:560
This class is derived from std::vector, and adds sort tracking.
Definition: gsSortedVector.h:109
void derivSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the (partial) derivatives of the i-th basis function at points u into result.
Definition: gsHBSplineBasis.hpp:85
void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the first partial derivatives of the nonzero basis function.
Definition: gsHBSplineBasis.hpp:128
A tensor product B-spline basis.
Definition: gsTensorBSplineBasis.h:36
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
BoundaryBasisType * basisSlice(index_t dir_fixed, T par) const
Gives back the basis at a slice in dir_fixed at par.
Definition: gsHBSplineBasis.hpp:39
Provides implementation of generic XML functions.
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition: gsHBSplineBasis.hpp:60
std::string to_string(const unsigned &i)
Helper to convert small unsigned to string.
Definition: gsXml.cpp:74
void transferbyLvl(std::vector< gsSparseMatrix< T > > &result)
returns transfer matrices betweend the levels of the given hierarchical spline
Definition: gsHBSplineBasis.hpp:188
index_t size() const
The number of basis functions in this basis.
Definition: gsHTensorBasis.hpp:298
virtual void refineElements(std::vector< index_t > const &boxes)
Insert the given boxes into the quadtree.
Definition: gsHTensorBasis.hpp:843
void initialize()
Initialize the characteristic and coefficient matrices and the internal bspline representations.
Definition: gsHBSplineBasis.hpp:70
virtual void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Returns the indices of active basis functions at points u, as a list of indices, in result...
Definition: gsHTensorBasis.hpp:1383
void symDifference(const gsKnotVector< T > &other, std::vector< T > &result) const
Computes the symmetric difference between this knot-vector and other.
Definition: gsKnotVector.hpp:172
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
void refine_withTransfer(gsSparseMatrix< T, RowMajor > &transfer, const std::vector< std::vector< T > > &refineKnots)
Takes a vector of coordinate wise knot values and inserts these values to the basis.
Definition: gsTensorBSplineBasis.hpp:66
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates nonzero basis functions at point u into result.
Definition: gsHBSplineBasis.hpp:101
memory::unique_ptr< Self_t > uPtr
Smart pointer for gsTensorBSplineBasis.
Definition: gsTensorBSplineBasis.h:69
void evalSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the i-th basis function at points u into result.
Definition: gsHBSplineBasis.hpp:77
Class for representing a knot vector.
Definition: gsKnotVector.h:79
Provides declaration of input/output XML utilities struct.