50 typedef memory::shared_ptr< gsRationalBasis >
Ptr;
51 typedef memory::unique_ptr< gsRationalBasis >
uPtr;
53 typedef typename SrcT::Scalar_t Scalar_t;
57 static const int Dim = SrcT::Dim;
59 static const bool IsRational =
true;
75 m_weights.setOnes(basis->size(), 1);
82 m_weights.setOnes(basis.size(), 1);
87 : m_src (basis), m_weights(
give(w))
90 "Invalid basis/weights ("<<m_weights.rows()<<
"/"<<m_src->size());
96 m_src= o.
source().clone().release();
106 m_src = o.
source().clone();
122 m_weights.size() == m_src->size()
127 {
return m_src->clone(); }
139 int size(
int const& k)
const{
return m_src->size(k); }
148 { m_src->active_into(u, result); }
156 {
return m_src->boundaryOffset(s,offset); }
159 {
return m_src->functionAtCorner(c); }
175 m_src->uniformRefine_withCoefs(m_weights, numKnots, mul, dir);
192 m_src->refineElements_withCoefs( m_weights, boxes );
208 typename SourceBasis::GeometryType tmp(*m_src,
give(m_weights));
209 tmp.degreeElevate(i,dir);
210 tmp.coefs().swap(m_weights);
211 std::swap(*m_src, tmp.basis() );
217 typename SourceBasis::GeometryType tmp(*m_src,
give(m_weights));
218 tmp.degreeIncrease(i,dir);
219 tmp.coefs().swap(m_weights);
220 std::swap(*m_src, tmp.basis() );
225 typename SourceBasis::GeometryType tmp(*m_src,
give(m_weights));
226 tmp.degreeReduce(i,dir);
227 tmp.coefs().swap(m_weights);
228 std::swap(*m_src, tmp.basis() );
233 typename SourceBasis::GeometryType tmp(*m_src,
give(m_weights));
234 tmp.degreeDecrease(i,dir);
235 tmp.coefs().swap(m_weights);
236 std::swap(*m_src, tmp.basis() );
256 {
return m_src->anchors_into(result); }
259 {
return m_src->anchor_into(i,result); }
263 {
return m_src->connectivity(nodes, mesh); }
300 T &
weight(
int i) {
return m_weights(i); }
303 const T &
weight(
int i)
const {
return m_weights(i); }
308 GISMO_ASSERT( w.cols() == 1,
"Weights should be scalars" ) ;
316 if (
const gsRationalBasis * _other = dynamic_cast<const gsRationalBasis*>(&other) )
317 m_src->matchWith(bi,*_other->m_src,bndThis,bndOther, offset);
319 m_src->matchWith(bi,other,bndThis,bndOther, offset);
332 "Invalid basis/coefficients ("<<coefs.rows()<<
"/"<<weights.rows());
333 const index_t n = coefs.cols();
338 rvo.leftCols(n).noalias() = weights.asDiagonal() * coefs;
349 const index_t n = pr_coefs.cols() - 1;
350 weights = pr_coefs.col( n );
351 coefs = pr_coefs.leftCols(n).array().colwise() / weights.col(0).array();
359 return m_src->makeDomainIterator();
365 return m_src->makeDomainIterator(s);
383 m_src->evalSingle_into(i, u, result);
384 result.array() *= m_weights.
at(i);
386 m_src->evalFunc_into(u, m_weights, denom);
388 result.array() /= denom.array();
395 m_src->eval_into(u, result);
399 m_src->evalFunc_into(u, m_weights, denom);
401 for (
index_t j=0; j< act.cols(); ++j)
403 result.col(j) /= denom(j);
404 for (
index_t i=0; i< act.rows(); ++i)
405 result(i,j) *= m_weights( act(i,j) ) ;
414 assert( coefs.rows() == m_weights.rows() ) ;
417 const gsMatrix<T> tmp = m_weights.asDiagonal() * coefs;
422 m_src->evalFunc_into( u, tmp, result);
423 m_src->evalFunc_into( u, m_weights, denom);
426 result.array().rowwise() /= denom.row(0).array();
488 m_src->active_into(u,act);
490 result.resize( act.rows()*Dim, u.cols() );
492 std::vector<gsMatrix<T> > ev(2);
493 m_src->evalAllDers_into(u, 1, ev);
498 for (
index_t i = 0; i!= result.cols(); ++i )
503 for (
index_t k = 0; k != act.rows(); ++k )
505 const T curw = m_weights.
at(act(k,i));
506 W += curw * ev[0](k,i);
507 dW += curw * ev[1].template block<Dim,1>(k*Dim,i);
511 result.col(i) = W * ev[1].col(i);
513 for (
index_t k = 0; k != act.rows() ; ++k)
517 result.template block<Dim,1>(kd,i).noalias() -=
520 result.template block<Dim,1>(kd,i) *= m_weights.
at( act(k,i) ) / (W * W);
533 static const int str = Dim * (Dim+1) / 2;
536 m_src->active_into(u,act);
538 result.resize( act.rows()*str, u.cols() );
542 std::vector<gsMatrix<T> > ev(3);
543 m_src->evalAllDers_into(u, 2, ev);
545 for (
index_t i = 0; i!= u.cols(); ++i )
551 for (
index_t k = 0; k != act.rows(); ++k )
554 const T curw = m_weights.
at(act(k,i));
555 W += curw * ev[0](k,i);
556 dW += curw * ev[1].template block<Dim,1>(k*Dim,i);
557 ddW += curw * ev[2].template block<str,1>(k*str,i);
561 result.col(i) = W * ev[2].col(i);
563 for (
index_t k=0; k != act.rows() ; ++k )
568 result.template block<str,1>(kstr,i) -=
571 result.template block<Dim,1>(kstr,i) +=
573 ( (T)(2) * ev[0](k,i) / W ) * dW.cwiseProduct(dW)
574 - (T)(2) * ev[1].template block<Dim,1>(kd,i).cwiseProduct(dW);
577 for (
int _u=0; _u != Dim; ++_u )
578 for (
int _v=_u+1; _v != Dim; ++_v )
580 result(kstr + m++, i) +=
581 - ev[1](kd+_u,i) * dW.
at(_v)
582 - ev[1](kd+_v,i) * dW.at(_u)
584 + (T)(2) * ev[0](k,i) * dW.at(_u) * dW.at(_v) / W;
587 result.template block<str,1>(kstr,i) *=
588 m_weights.
at( act(k,i) ) / (W*W);
597 GISMO_ASSERT( coefs.rows() == this->size() && m_weights.rows() == this->size(),
598 "Invalid dimensions" );
601 m_src->uniformRefine_withTransfer(transfer, numKnots, mul);
603 coefs = transfer * ( m_weights.asDiagonal() * coefs);
604 m_weights = transfer * m_weights;
612 coefs.array().colwise() /= m_weights.col(0).array();
622 m_src->uniformRefine_withTransfer(transfer, numKnots, mul);
642 m_weights.noalias() = transfer * tmp;
644 transfer = m_weights.cwiseInverse().asDiagonal() * transfer * tmp.asDiagonal();
650 std::vector<index_t>
const & boxes)
655 gsMatrix<T> rw = projectiveCoefs(coefs, m_weights);
658 m_src->refineElements_withCoefs( rw, boxes );
662 setFromProjectiveCoefs(rw, coefs, m_weights);
Class representing a domain. i.e. a collection of elements (triangles, rectangles, cubes, simplices.
Definition: gsDomain.h:31
const T & weight(int i) const
Const access to i-th weight.
Definition: gsRationalBasis.h:303
void refineElements(std::vector< index_t > const &boxes)
Refines specified areas or boxes, depending on underlying basis.
Definition: gsRationalBasis.h:188
void uniformRefine_withTransfer(gsSparseMatrix< T, RowMajor > &transfer, int numKnots=1, int mul=1)
Refine the basis uniformly.
Definition: gsRationalBasis.h:619
std::vector< T * > release(std::vector< unique_ptr< T > > &cont)
Takes a vector of smart pointers, releases them and returns the corresponding raw pointers...
Definition: gsMemory.h:228
size_t numElements(boxSide const &s=0) const
The number of elements on side s.
Definition: gsRationalBasis.h:141
SrcT & source()
Definition: gsRationalBasis.h:286
gsMatrix< index_t > allBoundary() const
Returns the indices of the basis functions that are nonzero at the domain boundary.
Definition: gsRationalBasis.h:153
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: gsRationalBasis.h:173
void refineElements_withCoefs(gsMatrix< T > &coefs, std::vector< index_t > const &boxes)
Refines specified areas or boxes, depending on underlying basis.
Definition: gsRationalBasis.h:649
index_t size() const
size
Definition: gsRationalBasis.h:137
T & weight(int i)
Access to i-th weight.
Definition: gsRationalBasis.h:300
gsMatrix< T > support() const
Returns (a bounding box for) the domain of the whole basis.
Definition: gsRationalBasis.h:265
#define short_t
Definition: gsConfig.h:35
Class that creates a rational counterpart for a given basis.
Definition: gsRationalBasis.h:47
Provides structs and classes related to interfaces and boundaries.
virtual const gsBasis< T > & component(short_t i) const
For a tensor product basis, return the (const) 1-d basis for the i-th parameter component.
Definition: gsRationalBasis.h:150
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: gsRationalBasis.h:223
void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates nonzero basis functions at point u into result.
Definition: gsRationalBasis.h:393
gsRationalBasis(SrcT *basis)
Construct a rational counterpart of basis.
Definition: gsRationalBasis.h:72
Provides declaration of Basis abstract interface.
S give(S &x)
Definition: gsMemory.h:266
void anchor_into(index_t i, gsMatrix< T > &result) const
Returns the anchor point for member i of the basis.
Definition: gsRationalBasis.h:258
#define index_t
Definition: gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
virtual const gsBasis< T > & component(short_t i) const
For a tensor product basis, return the (const) 1-d basis for the i-th parameter component.
Definition: gsBasis.hpp:514
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: gsRationalBasis.h:147
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: gsRationalBasis.h:215
gsBasis< T >::domainIter makeDomainIterator() const
Create a domain iterator for the computational mesh of this basis, that points to the first element o...
Definition: gsRationalBasis.h:356
gsMatrix< T > projectiveCoefs(const gsMatrix< T > &coefs) const
Definition: gsRationalBasis.h:324
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
short_t degree(short_t i=0) const
Degree with respect to the i-th variable. If the basis is a tensor product of (piecewise) polynomial ...
Definition: gsRationalBasis.h:162
SrcT SourceBasis
Associated source basis type.
Definition: gsRationalBasis.h:64
short_t maxDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the maximum po...
Definition: gsRationalBasis.h:165
memory::shared_ptr< gsFunctionSet > Ptr
Shared pointer for gsFunctionSet.
Definition: gsFunctionSet.h:223
bool check() const
Check the rational basis for consistency.
Definition: gsRationalBasis.h:119
void anchors_into(gsMatrix< T > &result) const
Returns the anchor points that represent the members of the basis in result. There is exactly one anc...
Definition: gsRationalBasis.h:255
Class Representing a triangle mesh with 3D vertices.
Definition: gsMesh.h:31
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition: gsMatrix.h:211
gsRationalBasis(const SrcT &basis)
Construct a rational counterpart of basis.
Definition: gsRationalBasis.h:79
void deriv2_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the second derivatives of all active basis function at points u.
Definition: gsRationalBasis.h:526
memory::unique_ptr< gsFunctionSet > uPtr
Unique pointer for gsFunctionSet.
Definition: gsFunctionSet.h:226
gsRationalBasis(SrcT *basis, gsMatrix< T > w)
Construct a rational counterpart of basis.
Definition: gsRationalBasis.h:86
size_t elementIndex(const gsVector< T > &u) const
See gsBasis for a description.
Definition: gsRationalBasis.h:145
const gsBasis< T > & basis(const index_t k) const
Helper which casts and returns the k-th piece of this function set as a gsBasis.
Definition: gsFunctionSet.hpp:33
gsDomain< T > * domain() const
Definition: gsRationalBasis.h:253
short_t domainDim() const
Dimension of the (source) domain.
Definition: gsRationalBasis.h:135
short_t minDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the minimum po...
Definition: gsRationalBasis.h:168
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
Struct which represents a certain side of a box.
Definition: gsBoundary.h:84
const SrcT & source() const
Returns the source basis of the rational basis.
Definition: gsRationalBasis.h:283
uPtr clone()
Clone methode. Produceds a deep copy inside a uPtr.
const gsMatrix< T > & weights() const
Returns the weights of the rational basis.
Definition: gsRationalBasis.h:290
void connectivity(const gsMatrix< T > &nodes, gsMesh< T > &mesh) const
Definition: gsRationalBasis.h:262
short_t totalDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the total poly...
Definition: gsRationalBasis.h:171
void deriv_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the first partial derivatives of the nonzero basis function.
Definition: gsRationalBasis.h:481
memory::unique_ptr< gsBasis< T > > makeNonRational() const
Definition: gsRationalBasis.h:126
void evalFunc_into(const gsMatrix< T > &u, const gsMatrix< T > &coefs, gsMatrix< T > &result) const
Evaluate the function described by coefs at points u, i.e., evaluates a linear combination of coefs x...
Definition: gsRationalBasis.h:412
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: gsRationalBasis.h:231
virtual void matchWith(const boundaryInterface &bi, const gsBasis< T > &other, gsMatrix< index_t > &bndThis, gsMatrix< index_t > &bndOther, index_t offset=0) const
Computes the indices of DoFs that match on the interface bi. The interface is assumed to be a common ...
Definition: gsRationalBasis.h:312
gsBasis< T >::domainIter makeDomainIterator(const boxSide &s) const
Create a boundary domain iterator for the computational mesh this basis, that points to the first ele...
Definition: gsRationalBasis.h:362
gsRationalBasis(const gsRationalBasis &o)
Copy Constructor.
Definition: gsRationalBasis.h:94
void setWeights(gsMatrix< T > const &w)
Set weights.
Definition: gsRationalBasis.h:306
static void setFromProjectiveCoefs(const gsMatrix< T > &pr_coefs, gsMatrix< T > &coefs, gsMatrix< T > &weights)
Definition: gsRationalBasis.h:346
Struct which represents an interface between two patches.
Definition: gsBoundary.h:649
virtual bool isRational() const
Returns true, since by definition a gsRationalBasis is rational.
Definition: gsRationalBasis.h:297
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: gsRationalBasis.h:206
void uniformRefine_withCoefs(gsMatrix< T > &coefs, int numKnots=1, int mul=1, int dir=-1)
Refine the basis uniformly.
Definition: gsRationalBasis.h:595
gsMatrix< T > & weights()
Returns the weights of the rational basis.
Definition: gsRationalBasis.h:293
gsRationalBasis()
Default empty constructor.
Definition: gsRationalBasis.h:69
gsMatrix< T > support(const index_t &i) const
Returns (a bounding box for) the support of the i-th basis function.
Definition: gsRationalBasis.h:267
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: gsRationalBasis.h:381
gsRationalBasis & operator=(const gsRationalBasis &o)
Assignment operator.
Definition: gsRationalBasis.h:101
Struct which represents a certain corner of a hyper-cube.
Definition: gsBoundary.h:291
gsMatrix< index_t > boundaryOffset(boxSide const &s, index_t offset) const
Definition: gsRationalBasis.h:155
static gsMatrix< T > projectiveCoefs(const gsMatrix< T > &coefs, const gsMatrix< T > &weights)
Definition: gsRationalBasis.h:329
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78