32 template<
short_t d,
class T>
36 typedef memory::shared_ptr< gsTensorBasis >
Ptr;
37 typedef memory::unique_ptr< gsTensorBasis >
uPtr;
53 typedef Basis_t*
const* const_iterator;
55 typedef typename Basis_t::domainIter domainIter;
63 gsTensorBasis(
const gsTensorBasis & o);
64 gsTensorBasis& operator=(
const gsTensorBasis & o);
66 #if EIGEN_HAS_RVALUE_REFERENCES
67 gsTensorBasis(gsTensorBasis&& other)
69 util::copy(other.m_bases, other.m_bases+d, m_bases);
70 std::fill (other.m_bases, other.m_bases+d,
nullptr);
72 gsTensorBasis & operator=(gsTensorBasis&&other)
75 util::copy(other.m_bases, other.m_bases+d, m_bases);
76 std::fill (other.m_bases, other.m_bases+d,
nullptr);
80 bool isValid()
const {
return std::find(m_bases,m_bases+d,
81 static_cast<Basis_t*>(0)) == m_bases+d; }
84 gsTensorBasis( Basis_t* x, Basis_t* y);
90 gsTensorBasis( Basis_t* x, Basis_t* y, Basis_t* z ) ;
93 gsTensorBasis( Basis_t* x, Basis_t* y, Basis_t* z, Basis_t* w ) ;
111 for (
short_t i = 0; i < d; ++i)
112 r *= m_bases[i]->
size();
117 size_t numTotalElements()
const
120 for (
short_t dim = 1; dim < d; ++dim)
128 if (0==s.index())
return this->numTotalElements();
129 const short_t dir = s.direction();
131 for (
short_t dim = 0; dim < d; ++dim)
145 size_t ElIndex = m_bases[d-1]->
elementIndex( u.row(d-1) );
146 for (
short_t i=d-2; i>=0; --i )
160 for (
short_t dim = 0; dim < d; ++dim)
161 result(dim) =
static_cast<unsigned>(m_bases[dim]->
numElements());
261 bool sameElement =
false)
const;
282 static void deriv2_tp(
const std::vector<
gsMatrix<T> > values[],
312 virtual std::ostream &
print(std::ostream &os)
const = 0;
318 for (
short_t j = 0; j < d; ++j)
351 for (
short_t j = 0; j < d; ++j)
363 for (
short_t j = 0; j < d; ++j)
369 "Invalid basis component requested" );
379 for (
short_t j = 0; j < d; ++j)
385 "Invalid basis component requested" );
395 for (
short_t j = 0; j < d; ++j)
401 "Invalid basis component requested" );
411 "Invalid basis component requested" );
412 for (
short_t j = 0; j < d; ++j)
419 {
return &m_bases[0]; }
423 const_iterator
end()
const
424 {
return &m_bases[d]; }
429 {
return &m_bases[0]; }
434 {
return &m_bases[d]; }
444 for (
short_t k = 0; k!=d; ++k )
445 result[k] = m_bases[k]->
size();
467 return m_bases[i]->
degree(0);
475 td = math::max(td, m_bases[k]->
degree(0));
484 td = math::min(td, m_bases[k]->
degree(0));
492 td = + m_bases[k]->
degree(0);
500 deg[k] = m_bases[k]->
degree(0);
506 inline unsigned index(
unsigned i,
unsigned j,
unsigned k=0)
const;
516 for (
short_t i=1; i != d; ++i )
517 result[i] = result[i-1] * m_bases[i-1]->
size();
533 ind(i)= mm %
size(i);
540 void swapDirections(
const unsigned i,
const unsigned j)
543 "Invalid basis components "<<i<<
" and "<<j<<
" requested" );
544 std::swap(m_bases[i],m_bases[j]);
551 for (
short_t i = 0; i < d; ++i )
552 if ( ind[i] ==
size(i)-1 )
554 return ((0 == ind.array()).any() );
584 if (d > 1)
return *m_bases[1];
599 "Invalid basis component requested" );
600 return *m_bases[dir];
606 "Invalid basis component requested" );
607 return *m_bases[dir];
616 { std::swap_ranges(m_bases, m_bases+d, o.m_bases); }
623 template<
typename T>
class gsTensorBasis<0,T>
624 {
using T::GISMO_ERROR_gsTensorBasis_cannot_have_dimension_zero;};
636 class gsTensorBasis<1,T> :
public gsBasis<T>
639 typedef memory::shared_ptr< gsTensorBasis<1,T> > Ptr;
640 typedef memory::unique_ptr< gsTensorBasis<1,T> > uPtr;
644 typedef gsBasis<T> Base;
646 typedef gsTensorBasis<1,T> Self_t;
648 typedef gsBasis<T> Basis_t;
653 typedef gsBasis<T> CoordinateBasis;
657 typedef Basis_t*
const* const_iterator;
659 typedef gsBasis<T> ** base_iterator;
663 gsTensorBasis() : Base()
667 gsTensorBasis(
const gsTensorBasis & o)
674 gsTensorBasis& operator=(
const gsTensorBasis & o)
676 this->Base::operator=(o);
682 virtual ~gsTensorBasis()
687 #if EIGEN_HAS_RVALUE_REFERENCES
688 gsTensorBasis(gsTensorBasis&& other)
689 { gsTensorBasis::operator=(std::forward<gsTensorBasis>(other)); }
690 gsTensorBasis & operator=(gsTensorBasis&&other)
692 other.m_address = m_address;
693 other.m_address =
nullptr;
697 bool isValid()
const {
return static_cast<Basis_t*
>(0) != m_address; }
701 explicit gsTensorBasis(Base * x)
711 explicit gsTensorBasis(base_iterator it)
722 short_t dim()
const {
return 1;}
729 gsVector<index_t,1>& low,
730 gsVector<index_t,1>& upp )
const
732 gsMatrix<index_t> act;
735 upp[0]= act(act.size()-1, 0 );
746 const_iterator
begin()
const
747 {
return &m_address; }
751 const_iterator
end()
const
752 {
return (&m_address)+1; }
757 {
return &m_address; }
762 {
return (&m_address)+1; }
781 void size_cwise(gsVector<index_t,1> & result)
const
782 { result[0] = this->
size(); }
784 gsVector<int> cwiseDegree()
const
786 gsVector<int> deg(1);
791 void swapDirections(
const unsigned i,
const unsigned j)
795 GISMO_ASSERT( static_cast<int>(i) == 0 && static_cast<int>(j) == 0,
796 "Invalid basis components "<<i<<
" and "<<j<<
" requested" );
810 inline unsigned index(
unsigned i)
const
814 inline unsigned index(
unsigned ,
unsigned )
const
831 inline index_t index(gsVector<index_t,1>
const & v)
const
838 return gsVector<index_t,1>::Constant(1,m);
841 const Basis_t& x()
const
870 template<
short_t d,
class Basis_t >
876 for (
int i=d-2; i>=0; --i )
877 ind = ind * size(i) + v(i) ;
881 template<
short_t d,
class Basis_t >
884 return size(0) * (size(1) * k + j) + i;
888 template<
short_t d,
class Basis_t >
892 "Something went wrong with requested direction." );
894 for (
short_t i=0; i<dir; ++i )
902 #ifndef GISMO_BUILD_LIB
903 #include GISMO_HPP_HEADER(gsTensorBasis.hpp)
short_t degree(short_t i) const
Returns the degree of the basis wrt variable i.
Definition: gsTensorBasis.h:465
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: gsTensorBasis.hpp:410
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
index_t size() const
Returns the number of elements in the basis.
Definition: gsTensorBasis.h:108
virtual void degreeIncrease(short_t const &i=1, short_t const dir=-1)
Elevate the degree of the basis by the given amount, preserve knots multiplicity. ...
Definition: gsBasis.hpp:588
virtual 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: gsTensorBasis.hpp:454
void uniformCoarsen_withTransfer(gsSparseMatrix< T, RowMajor > &transfer, int numKnots=1)
Coarsen the basis uniformly and produce a sparse matrix which maps coarse coefficient vectors to refi...
Definition: gsTensorBasis.hpp:876
#define short_t
Definition: gsConfig.h:35
Provides structs and classes related to interfaces and boundaries.
void anchor_into(index_t i, gsMatrix< T > &result) const
Returns the anchors (graville absissae) that represent the members of the basis.
Definition: gsTensorBasis.hpp:148
virtual short_t degree(short_t i) const
Degree with respect to the i-th variable. If the basis is a tensor product of (piecewise) polynomial ...
Definition: gsBasis.hpp:650
virtual std::ostream & print(std::ostream &os) const =0
Prints the object as a string, pure virtual function of gsTensorBasis.
Basis_t ** iterator
Iterators on coordinate bases.
Definition: gsTensorBasis.h:52
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: gsTensorBasis.h:603
virtual void connectivity(const gsMatrix< T > &nodes, gsMesh< T > &mesh) const
Definition: gsTensorBasis.hpp:163
Provides declaration of Basis abstract interface.
virtual index_t size() const
size
Definition: gsFunctionSet.h:578
const_iterator end() const
Definition: gsTensorBasis.h:423
virtual size_t elementIndex(const gsVector< T > &u) const
Returns an index for the element which contains point u.
Definition: gsBasis.hpp:506
#define index_t
Definition: gsConfig.h:32
virtual void uniformCoarsen(int numKnots=1)
Coarsen the basis uniformly by removing groups of numKnots consecutive knots, each knot removed mul t...
Definition: gsTensorBasis.h:349
virtual void degreeReduce(short_t const &i=1, short_t const dir=-1)
Reduce the degree of the basis by the given amount, preserve smoothness.
Definition: gsTensorBasis.h:407
size_t elementIndex(const gsVector< T > &u) const
Returns an index for the element which contains point u.
Definition: gsTensorBasis.h:141
virtual size_t numElements(boxSide const &s=0) const
The number of elements on side s.
Definition: gsBasis.hpp:502
size_t numElements(boxSide const &s=boundary::none) const
The number of elements on side s.
Definition: gsTensorBasis.h:126
virtual void uniformRefine(int numKnots=1, int mul=1, int dir=-1)
Refine the basis uniformly by inserting numKnots new knots with multiplicity mul on each knot span...
Definition: gsTensorBasis.h:315
void refineElements(std::vector< index_t > const &elements)
Refine elements defined by their tensor-index.
Definition: gsTensorBasis.hpp:795
iterator begin()
Definition: gsTensorBasis.h:428
virtual void degreeIncrease(short_t const &i=1, short_t const dir=-1)
Elevate the degree of the basis by the given amount, preserve knots multiplicity. ...
Definition: gsTensorBasis.h:375
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
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
short_t maxDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the maximum po...
Definition: gsTensorBasis.h:470
T Scalar_t
Coefficient type.
Definition: gsTensorBasis.h:46
virtual void uniformRefine(int numKnots=1, int mul=1, int dir=-1)
Refine the basis uniformly by inserting numKnots new knots with multiplicity mul on each knot span...
Definition: gsBasis.hpp:554
gsMatrix< T > elementInSupportOf(index_t j) const
Returns (the coordinates of) an element in the support of basis function j.
Definition: gsTensorBasis.hpp:1066
virtual void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates nonzero basis functions at point u into result.
Definition: gsTensorBasis.hpp:502
Class Representing a triangle mesh with 3D vertices.
Definition: gsMesh.h:31
virtual void degreeElevate(short_t const &i=1, short_t const dir=-1)
Elevate the degree of the basis by the given amount, preserve smoothness.
Definition: gsTensorBasis.h:359
virtual void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero functions and their derivatives up to order n at points u into result...
Definition: gsTensorBasis.hpp:634
virtual void degreeDecrease(short_t const &i=1, short_t const dir=-1)
Lower the degree of the basis by the given amount, preserving knots multiplicity. ...
Definition: gsBasis.hpp:592
short_t totalDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the total poly...
Definition: gsTensorBasis.h:488
virtual T getMinCellLength() const
Get the minimum mesh size, as expected for inverse inequalities.
Definition: gsTensorBasis.hpp:1042
Basis_t & component(short_t dir)
For a tensor product basis, return the 1-d basis for the i-th parameter component.
Definition: gsTensorBasis.h:596
memory::shared_ptr< gsBasis > Ptr
Shared pointer for gsBasis.
Definition: gsBasis.h:86
virtual 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: gsTensorBasis.hpp:429
virtual void degreeDecrease(short_t const &i=1, short_t const dir=-1)
Lower the degree of the basis by the given amount, preserving knots multiplicity. ...
Definition: gsTensorBasis.h:391
iterator end()
Definition: gsTensorBasis.h:433
index_t size(short_t k) const
The number of basis functions in the direction of the k-th parameter component.
Definition: gsTensorBasis.h:437
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition: gsMemory.h:312
bool indexOnBoundary(const gsVector< index_t, d > &ind) const
Returns true iff the basis function with multi-index ind is on the boundary.
Definition: gsTensorBasis.h:549
bool isActive(const index_t i, const gsVector< T > &u) const
Returns true if there the point u with non-zero value or derivatives when evaluated at the basis func...
Definition: gsTensorBasis.hpp:239
Abstract base class for tensor product bases.
Definition: gsTensorBasis.h:33
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
gsMatrix< T > support() const
Returns (a bounding box for) the domain of the whole basis.
Definition: gsTensorBasis.hpp:390
void getComponentsForSide(boxSide const &s, std::vector< Basis_t * > &rr) const
Returns the components for a basis on the face s.
Definition: gsTensorBasis.hpp:377
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: gsTensorBasis.hpp:204
unsigned index(unsigned i, unsigned j, unsigned k=0) const
Definition: gsTensorBasis.h:882
void anchors_into(gsMatrix< T > &result) const
Returns the anchors (graville absissae) that represent the members of the basis.
Definition: gsTensorBasis.hpp:124
memory::unique_ptr< gsGeometry > uPtr
Unique pointer for gsGeometry.
Definition: gsGeometry.h:100
gsGeometry< T >::uPtr interpolateGrid(gsMatrix< T > const &vals, std::vector< gsMatrix< T > >const &grid) const
Definition: gsTensorBasis.hpp:921
bool indexOnBoundary(const index_t m) const
Returns true iff the basis function indexed m is on the boundary.
Definition: gsTensorBasis.h:559
void stride_cwise(gsVector< index_t, d > &result) const
Returns the strides for all dimensions.
Definition: gsTensorBasis.h:512
memory::unique_ptr< gsBasis > uPtr
Unique pointer for gsBasis.
Definition: gsBasis.h:89
virtual void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the first partial derivatives of the nonzero basis function.
Definition: gsTensorBasis.hpp:594
gsMatrix< index_t > coefSlice(short_t dir, index_t k) const
Returns all the basis functions with tensor-numbering.
Definition: gsTensorBasis.hpp:250
static const short_t Dim
Dimension of the parameter domain.
Definition: gsTensorBasis.h:49
unsigned stride(short_t dir) const
Returns the stride for dimension dir.
Definition: gsTensorBasis.h:889
gsMatrix< index_t > boundaryOffset(boxSide const &s, index_t offset) const
Definition: gsTensorBasis.hpp:304
const_iterator begin() const
Definition: gsTensorBasis.h:418
virtual void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the second derivatives of all active basis function at points u.
Definition: gsTensorBasis.hpp:731
short_t minDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the minimum po...
Definition: gsTensorBasis.h:479
#define GISMO_UNUSED(x)
Definition: gsDebug.h:112
gsVector< index_t, d > tensorIndex(const index_t &m) const
Returns the tensor index of the basis function with global index m.
Definition: gsTensorBasis.h:527
gsMatrix< index_t > allBoundary() const
Definition: gsTensorBasis.hpp:283
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
virtual void degreeElevate(short_t const &i=1, short_t const dir=-1)
Elevate the degree of the basis by the given amount, preserve smoothness.
Definition: gsBasis.hpp:580
gsBasis< T >::domainIter makeDomainIterator() const
Create a domain iterator for the computational mesh of this basis, that points to the first element o...
Definition: gsTensorBasis.hpp:891
void uniformRefine_withCoefs(gsMatrix< T > &coefs, int numKnots=1, int mul=1, int dir=-1)
Definition: gsTensorBasis.hpp:824
Struct which represents an interface between two patches.
Definition: gsBoundary.h:649
void uniformRefine_withTransfer(gsSparseMatrix< T, RowMajor > &transfer, int numKnots=1, int mul=1)
Definition: gsTensorBasis.hpp:861
void numElements_cwise(gsVector< unsigned > &result) const
Returns the number of elements (component wise)
Definition: gsTensorBasis.h:157
short_t domainDim() const
Dimension of the (source) domain.
Definition: gsTensorBasis.h:105
virtual T getMaxCellLength() const
Get the maximum mesh size, as expected for approximation error estimates.
Definition: gsTensorBasis.hpp:1054
Struct which represents a certain corner of a hyper-cube.
Definition: gsBoundary.h:291
virtual gsGeometry< T >::uPtr interpolateAtAnchors(gsMatrix< T > const &vals) const
Applies interpolation of values pts using the anchors as parameter points. May be reimplemented in de...
Definition: gsTensorBasis.hpp:908
gsTensorBasis(iterator it)
Constructor nD (takes ownership of the passed bases)
Definition: gsTensorBasis.h:96
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
void copy(T begin, T end, U *result)
Small wrapper for std::copy mimicking std::copy for a raw pointer destination, copies n positions sta...
Definition: gsMemory.h:391
void active_cwise(const gsMatrix< T > &u, gsVector< index_t, d > &low, gsVector< index_t, d > &upp) const