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);
90 "Invalid basis/weights ("<<m_weights.rows()<<
"/"<<m_src->size());
96 m_src= o.
source().clone().release();
106 m_src = o.
source().clone().release();
122 m_weights.size() == m_src->size()
127 {
return m_src->clone(); }
151 { m_src->active_into(u, result); }
159 {
return m_src->boundaryOffset(s,offset); }
162 {
return m_src->functionAtCorner(c); }
178 m_src->uniformRefine_withCoefs(m_weights, numKnots, mul, dir);
181 void uniformRefine_withCoefs(
gsMatrix<T>& coefs,
int numKnots = 1,
int mul = 1,
short_t const dir = -1);
189 m_src->refine_withCoefs( m_weights, boxes );
202 m_src->refineElements_withCoefs( m_weights, boxes );
219 memory::unique_ptr<gsGeometry<T> > tmp = m_src->makeGeometry(
give(m_weights));
220 tmp->degreeElevate(i,dir);
221 tmp->coefs().swap(m_weights);
223 m_src =
static_cast<SrcT*
>(tmp->basis().clone().release());
228 memory::unique_ptr<gsGeometry<T> > tmp = m_src->makeGeometry(
give(m_weights));
229 tmp->degreeIncrease(i,dir);
230 tmp->coefs().swap(m_weights);
232 m_src =
static_cast<SrcT*
>(tmp->basis().clone().release());
237 memory::unique_ptr<gsGeometry<T> > tmp = m_src->makeGeometry(
give(m_weights));
238 tmp->degreeReduce(i,dir);
239 tmp->coefs().swap(m_weights);
241 m_src =
static_cast<SrcT*
>(tmp->basis().clone().release());
246 memory::unique_ptr<gsGeometry<T> > tmp = m_src->makeGeometry(
give(m_weights));
247 tmp->degreeDecrease(i,dir);
248 tmp->coefs().swap(m_weights);
266 {
return m_src->anchors_into(result); }
269 {
return m_src->anchor_into(i,result); }
273 {
return m_src->connectivity(nodes, mesh); }
310 T &
weight(
int i) {
return m_weights(i); }
313 const T &
weight(
int i)
const {
return m_weights(i); }
318 GISMO_ASSERT( w.cols() == 1,
"Weights should be scalars" ) ;
327 m_src->matchWith(bi,*_other->m_src,bndThis,bndOther, offset);
329 m_src->matchWith(bi,other,bndThis,bndOther, offset);
342 "Invalid basis/coefficients ("<<coefs.rows()<<
"/"<<
weights.rows());
343 const index_t n = coefs.cols();
348 rvo.leftCols(n).noalias() =
weights.asDiagonal() * coefs;
359 const index_t n = pr_coefs.cols() - 1;
361 coefs = pr_coefs.leftCols(n).array().colwise() /
weights.col(0).array();
369 return m_src->makeDomainIterator();
375 return m_src->makeDomainIterator(s);
391void gsRationalBasis<SrcT>::evalSingle_into(
index_t i,
const gsMatrix<T> & u, gsMatrix<T>& result)
const
393 m_src->evalSingle_into(i, u, result);
394 result.array() *= m_weights.
at(i);
396 m_src->evalFunc_into(u, m_weights, denom);
398 result.array() /= denom.array();
403void gsRationalBasis<SrcT>::eval_into(
const gsMatrix<T> & u, gsMatrix<T>& result)
const
405 m_src->eval_into(u, result);
406 const gsMatrix<index_t> act = m_src->active(u);
409 m_src->evalFunc_into(u, m_weights, denom);
411 for (
index_t j=0; j< act.cols(); ++j)
413 result.col(j) /= denom(j);
414 for (
index_t i=0; i< act.rows(); ++i)
415 result(i,j) *= m_weights( act(i,j) ) ;
422void gsRationalBasis<SrcT>::evalFunc_into(
const gsMatrix<T> & u,
const gsMatrix<T> & coefs, gsMatrix<T>& result)
const
424 assert( coefs.rows() == m_weights.rows() ) ;
427 const gsMatrix<T> tmp = m_weights.asDiagonal() * coefs;
432 m_src->evalFunc_into( u, tmp, result);
433 m_src->evalFunc_into( u, m_weights, denom);
436 result.array().rowwise() /= denom.row(0).array();
491void gsRationalBasis<SrcT>::deriv_into(
const gsMatrix<T> & u,
492 gsMatrix<T>& result)
const
497 gsMatrix<index_t> act;
498 m_src->active_into(u,act);
500 result.resize( act.rows()*Dim, u.cols() );
502 std::vector<gsMatrix<T> > ev(2);
503 m_src->evalAllDers_into(u, 1, ev);
506 gsMatrix<T> dW(Dim,1);
508 for (
index_t i = 0; i!= result.cols(); ++i )
513 for (
index_t k = 0; k != act.rows(); ++k )
515 const T curw = m_weights.at(act(k,i));
516 W += curw * ev[0](k,i);
517 dW += curw * ev[1].template block<Dim,1>(k*Dim,i);
521 result.col(i) = W * ev[1].col(i);
523 for (
index_t k = 0; k != act.rows() ; ++k)
527 result.template block<Dim,1>(kd,i).noalias() -=
530 result.template block<Dim,1>(kd,i) *= m_weights.at( act(k,i) ) / (W * W);
536void gsRationalBasis<SrcT>::deriv2_into(
const gsMatrix<T> & u, gsMatrix<T>& result )
const
543 static const int str = Dim * (Dim+1) / 2;
545 gsMatrix<index_t> act;
546 m_src->active_into(u,act);
548 result.resize( act.rows()*str, u.cols() );
551 gsMatrix<T> dW(Dim,1), ddW(str,1);
552 std::vector<gsMatrix<T> > ev(3);
553 m_src->evalAllDers_into(u, 2, ev);
555 for (
index_t i = 0; i!= u.cols(); ++i )
561 for (
index_t k = 0; k != act.rows(); ++k )
564 const T curw = m_weights.at(act(k,i));
565 W += curw * ev[0](k,i);
566 dW += curw * ev[1].template block<Dim,1>(k*Dim,i);
567 ddW += curw * ev[2].template block<str,1>(k*str,i);
571 result.col(i) = W * ev[2].col(i);
573 for (
index_t k=0; k != act.rows() ; ++k )
578 result.template block<str,1>(kstr,i) -=
581 result.template block<Dim,1>(kstr,i) +=
583 ( (T)(2) * ev[0](k,i) / W ) * dW.cwiseProduct(dW)
584 - (T)(2) * ev[1].template block<Dim,1>(kd,i).cwiseProduct(dW);
587 for (
int _u=0; _u != Dim; ++_u )
588 for (
int _v=_u+1; _v != Dim; ++_v )
590 result(kstr + m++, i) +=
591 - ev[1](kd+_u,i) * dW.at(_v)
592 - ev[1](kd+_v,i) * dW.at(_u)
594 + (T)(2) * ev[0](k,i) * dW.at(_u) * dW.at(_v) / W;
597 result.template block<str,1>(kstr,i) *=
598 m_weights.at( act(k,i) ) / (W*W);
605void gsRationalBasis<SrcT>::uniformRefine_withCoefs(gsMatrix<T>& coefs,
int numKnots,
int mul,
int dir)
607 GISMO_ASSERT( coefs.rows() == this->size() && m_weights.rows() == this->size(),
608 "Invalid dimensions" );
619 auto tmp = m_src->clone();
620 coefs *= m_weights.asDiagonal();
621 tmp->uniformRefine_withCoefs(coefs, numKnots);
622 m_src->uniformRefine_withCoefs(m_weights, numKnots,mul,dir);
625 coefs.array().colwise() /= m_weights.col(0).array();
632void gsRationalBasis<SrcT>::uniformRefine_withTransfer(gsSparseMatrix<T,RowMajor> & transfer,
int numKnots,
int mul)
635 m_src->uniformRefine_withTransfer(transfer, numKnots, mul);
654 const gsVector<T> tmp = m_weights ;
655 m_weights.noalias() = transfer * tmp;
657 transfer = m_weights.cwiseInverse().asDiagonal() * transfer * tmp.asDiagonal();
663 std::vector<index_t>
const & boxes)
668 gsMatrix<T> rw = projectiveCoefs(coefs, m_weights);
671 m_src->refineElements_withCoefs( rw, boxes );
675 setFromProjectiveCoefs(rw, coefs, m_weights);
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
A basis represents a family of scalar basis functions defined over a common parameter domain.
Definition gsBasis.h:79
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:563
Class representing a domain. i.e. a collection of elements (triangles, rectangles,...
Definition gsDomain.h:32
uPtr clone()
Clone methode. Produceds a deep copy inside a uPtr.
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
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition gsMatrix.h:211
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
Class that creates a rational counterpart for a given basis.
Definition gsRationalBasis.h:48
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:153
gsRationalBasis(const gsRationalBasis &o)
Copy Constructor.
Definition gsRationalBasis.h:94
void uniformRefine(int numKnots=1, int mul=1, short_t dir=-1)
Refine the basis uniformly by inserting numKnots new knots with multiplicity mul on each knot span.
Definition gsRationalBasis.h:176
memory::unique_ptr< gsBasis< T > > makeNonRational() const
Definition gsRationalBasis.h:126
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:265
short_t maxDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the maximum po...
Definition gsRationalBasis.h:168
gsRationalBasis(const SrcT &basis)
Construct a rational counterpart of basis.
Definition gsRationalBasis.h:79
static void setFromProjectiveCoefs(const gsMatrix< T > &pr_coefs, gsMatrix< T > &coefs, gsMatrix< T > &weights)
Definition gsRationalBasis.h:356
gsRationalBasis(SrcT *basis)
Construct a rational counterpart of basis.
Definition gsRationalBasis.h:72
gsMatrix< index_t > allBoundary() const
Returns the indices of the basis functions that are nonzero at the domain boundary.
Definition gsRationalBasis.h:156
T & weight(int i)
Access to i-th weight.
Definition gsRationalBasis.h:310
gsRationalBasis(SrcT *basis, gsMatrix< T > w)
Construct a rational counterpart of basis.
Definition gsRationalBasis.h:86
void setWeights(gsMatrix< T > const &w)
Set weights.
Definition gsRationalBasis.h:316
void connectivity(const gsMatrix< T > &nodes, gsMesh< T > &mesh) const
Definition gsRationalBasis.h:272
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:244
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:366
short_t totalDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the total poly...
Definition gsRationalBasis.h:174
const T & weight(int i) const
Const access to i-th weight.
Definition gsRationalBasis.h:313
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:235
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:226
bool check() const
Check the rational basis for consistency.
Definition gsRationalBasis.h:119
index_t size() const
size
Definition gsRationalBasis.h:137
const gsMatrix< T > & weights() const
Returns the weights of the rational basis.
Definition gsRationalBasis.h:300
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:150
gsMatrix< index_t > boundaryOffset(boxSide const &s, index_t offset) const
Definition gsRationalBasis.h:158
short_t domainDim() const
Dimension of the (source) domain.
Definition gsRationalBasis.h:135
SrcT & source()
Definition gsRationalBasis.h:296
SrcT SourceBasis
Associated source basis type.
Definition gsRationalBasis.h:64
void anchor_into(index_t i, gsMatrix< T > &result) const
Returns the anchor point for member i of the basis.
Definition gsRationalBasis.h:268
gsMatrix< T > support(const index_t &i) const
Returns (a bounding box for) the support of the i-th basis function.
Definition gsRationalBasis.h:277
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:217
gsMatrix< T > projectiveCoefs(const gsMatrix< T > &coefs) const
Definition gsRationalBasis.h:334
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:165
gsMatrix< T > support() const
Returns (a bounding box for) the domain of the whole basis.
Definition gsRationalBasis.h:275
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:322
static gsMatrix< T > projectiveCoefs(const gsMatrix< T > &coefs, const gsMatrix< T > &weights)
Definition gsRationalBasis.h:339
gsRationalBasis()
Default empty constructor.
Definition gsRationalBasis.h:69
void refineElements_withCoefs(gsMatrix< T > &coefs, std::vector< index_t > const &boxes)
Refines specified areas or boxes, depending on underlying basis.
Definition gsRationalBasis.h:662
gsDomain< T > * domain() const
Definition gsRationalBasis.h:263
gsMatrix< T > & weights()
Returns the weights of the rational basis.
Definition gsRationalBasis.h:303
size_t numElements(boxSide const &s=0) const
The number of elements on side s.
Definition gsRationalBasis.h:141
const SrcT & source() const
Returns the source basis of the rational basis.
Definition gsRationalBasis.h:293
short_t minDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the minimum po...
Definition gsRationalBasis.h:171
gsMatrix< T > elementInSupportOf(index_t j) const
See gsBasis for a description.
Definition gsRationalBasis.h:148
gsRationalBasis & operator=(const gsRationalBasis &o)
Assignment operator.
Definition gsRationalBasis.h:101
void refine(gsMatrix< T > const &boxes, int refExt=0)
See gsBasis.
Definition gsRationalBasis.h:186
void refineElements(std::vector< index_t > const &boxes)
Refines specified areas or boxes, depending on underlying basis.
Definition gsRationalBasis.h:198
size_t elementIndex(const gsVector< T > &u) const
See gsBasis for a description.
Definition gsRationalBasis.h:145
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:372
virtual bool isRational() const
Returns true, since by definition a gsRationalBasis is rational.
Definition gsRationalBasis.h:307
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition gsSparseMatrix.h:139
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
Provides declaration of Basis abstract interface.
Provides structs and classes related to interfaces and boundaries.
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_UNUSED(x)
Definition gsDebug.h:112
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
The G+Smo namespace, containing all definitions for the library.
S give(S &x)
Definition gsMemory.h:266
Struct which represents an interface between two patches.
Definition gsBoundary.h:650
Struct which represents a certain corner of a hyper-cube.
Definition gsBoundary.h:292