G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsRationalTHBSplineBasis.h
Go to the documentation of this file.
1
14#pragma once
15
19
20
21namespace gismo
22{
23
35template<short_t d, class T>
36class gsRationalTHBSplineBasis : public gsRationalBasis<gsTHBSplineBasis<d,T>>
37{
38
39public:
40
43
46
48 typedef Src_t Basis_t;
49
51 typedef T Scalar_t;
52
54
57
60
62 typedef memory::shared_ptr< gsRationalTHBSplineBasis > Ptr;
63
65 typedef memory::unique_ptr< gsRationalTHBSplineBasis > uPtr;
66
67 // typedef typename Base::iterator iterator;
68 // typedef typename Base::const_iterator const_iterator;
69
70public:
71 // Constructors forwarded from the base class
73
75
76 gsRationalTHBSplineBasis( Src_t* basis, gsMatrix<T> w ) : Base(basis, give(w)) { }
77
78 gsRationalTHBSplineBasis( gsConstantBasis<T>* basis, gsMatrix<T>)
79 {GISMO_ERROR("!!"); }
80
81 gsRationalTHBSplineBasis(const gsRationalTHBSplineBasis & o) : Base(o) { }
82
83 GISMO_CLONE_FUNCTION(gsRationalTHBSplineBasis)
84
85 GISMO_MAKE_GEOMETRY_NEW
86
88 std::ostream &print(std::ostream &os) const
89 {
90 os << "Rational THB-Spline basis: dim=" << this->dim()<< ", size="<< this->size() << ".";
91 // for ( unsigned i = 0; i!=d; ++i )
92 // os << "\n Direction "<< i <<": "<< this->m_src->component(i).knots() <<" ";
93 os << "\n";
94 return os;
95 }
96
97 GISMO_UPTR_FUNCTION_DEF(BoundaryBasisType, boundaryBasis, boxSide const &)
98 {
99 typename Src_t::BoundaryBasisType::uPtr bb = m_src->boundaryBasis(n1);
100 gsMatrix<index_t> ind = m_src->boundary(n1);
101
102 gsMatrix<T> ww( ind.size(),1);
103 for ( index_t i=0; i<ind.size(); ++i)
104 ww(i,0) = m_weights( (ind)(i,0), 0);
105
106 return new BoundaryBasisType(bb.release(), give(ww));// note: constructor consumes the pointer
107 }
108public:
109 void refine_withCoefs(gsMatrix<T> & coefs, gsMatrix<T> const & boxes)
110 {
111 auto tmp = m_src->clone();
112 coefs = m_weights.asDiagonal() * coefs;
113 tmp->refine_withCoefs(coefs, boxes);
114 m_src->refine_withCoefs(m_weights, boxes);
115 coefs.array().colwise() /= m_weights.col(0).array();
116 }
117
119 // void size_cwise(gsVector<index_t,d> & result) const
120 // {
121 // // call the function of the underlying basis
122 // m_src->size_cwise(result);
123 // }
124
125 // /// Returns the strides for all dimensions
126 // void stride_cwise(gsVector<index_t,d> & result) const
127 // {
128 // // call the function of the underlying basis
129 // m_src->stride_cwise(result);
130 // }
131
132 // void swapDirections(const unsigned i, const unsigned j)
133 // {
134 // gsVector<index_t, d> sz;
135 // size_cwise(sz);
136
137 // // First swap the weights
138 // swapTensorDirection(i, j, sz, m_weights);
139
140 // // Then swap the basis components
141 // m_src->swapDirections(i, j);
142 // }
143
144 // void uniformRefine_withCoefs(gsMatrix<T>& coefs, int numKnots=1, int mul=1, int dir=-1)
145 // {
146 // GISMO_ASSERT( coefs.rows() == this->size() && m_weights.rows() == this->size(),
147 // "Invalid dimensions" );
148
149 // gsSparseMatrix<T, RowMajor> transfer;
150 // if (dir==-1)
151 // {
152 // m_src->uniformRefine_withTransfer(transfer, numKnots, mul);
153
154 // coefs = transfer * ( m_weights.asDiagonal() * coefs);
155 // m_weights = transfer * m_weights;
156 // // Alternative way
157 // // gsBasis<T> * tmp = m_src->clone();
158 // // tmp->uniformRefine_withCoefs(coefs, numKnots);
159 // // delete tmp;
160 // // m_src->uniformRefine_withCoefs(m_weights, numKnots);
161
162 // // back to affine coefs
163 // coefs.array().colwise() /= m_weights.col(0).array();
164 // // equiv:
165 // // for (int i = 0; i < coefs.rows(); ++i)
166 // // coefs.row(i) /= m_weights.at(i);
167 // }
168 // else
169 // {
170 // GISMO_ASSERT( dir >= 0 && static_cast<unsigned>(dir) < d,
171 // "Invalid basis component "<< dir <<" requested for degree elevation" );
172
173 // gsVector<index_t,d> sz;
174 // m_src->size_cwise(sz);
175 // m_src->component(dir).uniformRefine_withTransfer( transfer, numKnots, mul );
176
177 // const index_t coefs_cols = coefs.cols();
178 // const index_t weights_cols = m_weights.cols();
179
180 // coefs = m_weights.asDiagonal() * coefs; //<<<<-----this goes wrong!!
181 // swapTensorDirection(0, dir, sz, coefs);
182 // coefs.resize( sz[0], coefs_cols * sz.template tail<static_cast<short_t>(d-1)>().prod() );
183 // coefs = transfer * coefs;
184
185 // swapTensorDirection(0, dir, sz, m_weights);
186 // m_weights.resize( sz[0], weights_cols * sz.template tail<static_cast<short_t>(d-1)>().prod() );
187 // m_weights = transfer * m_weights;
188
189 // sz[0] = coefs.rows();
190
191 // coefs.resize( sz.prod(), coefs_cols );
192 // m_weights.resize( sz.prod(), weights_cols );
193 // swapTensorDirection(0, dir, sz, coefs);
194 // swapTensorDirection(0, dir, sz, m_weights);
195
196 // coefs.array().colwise() /= m_weights.col(0).array();
197 // }
198 // }
199
200#ifdef __DOXYGEN__
203#endif
204
205 // GISMO_UPTR_FUNCTION_DEF(BoundaryBasisType, boundaryBasis, boxSide const &)
206 // {
207 // typename Src_t::BoundaryBasisType::uPtr bb = m_src->boundaryBasis(n1);
208 // gsMatrix<index_t> ind = m_src->boundary(n1);
209
210 // gsMatrix<T> ww( ind.size(),1);
211 // for ( index_t i=0; i<ind.size(); ++i)
212 // ww(i,0) = m_weights( (ind)(i,0), 0);
213
214 // return new BoundaryBasisType(bb.release(), give(ww));// note: constructor consumes the pointer
215 // }
216
217 // void matchWith(const boundaryInterface & bi, const gsBasis<T> & other,
218 // gsMatrix<index_t> & bndThis, gsMatrix<index_t> & bndOther) const
219 // {
220 // this->matchWith(bi,other,bndThis,bndOther,0);
221 // }
222
223 // // see gsBasis for documentation
224 // void matchWith(const boundaryInterface & bi, const gsBasis<T> & other,
225 // gsMatrix<index_t> & bndThis, gsMatrix<index_t> & bndOther, index_t offset) const
226 // {
227 // if ( const gsRationalTHBSplineBasis<d,T> * _other = dynamic_cast<const gsRationalTHBSplineBasis<d,T> *>(&other) )
228 // m_src->matchWith(bi,_other->source(),bndThis,bndOther,offset);
229 // else if ( const gsTensorBasis<d,T> * __other = dynamic_cast<const gsTensorBasis<d,T> *>(&other) )
230 // m_src->matchWith(bi,*__other,bndThis,bndOther,offset);
231 // else
232 // gsWarn<<"Cannot match with "<<other<<"\n";
233 // }
234
235
236protected:
237 using Base::m_src;
238 using Base::m_weights;
239
240};
241
242
243} // namespace gismo
Struct which represents a certain side of a box.
Definition gsBoundary.h:85
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
Class that creates a rational counterpart for a given basis.
Definition gsRationalBasis.h:48
index_t size() const
Definition gsRationalBasis.h:137
A rational Truncated Hierarchical B-Spline basis.
Definition gsRationalTHBSplineBasis.h:37
GISMO_MAKE_GEOMETRY_NEW std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsRationalTHBSplineBasis.h:88
gsRationalTHBSpline< d, T > GeometryType
Associated geometry type.
Definition gsRationalTHBSplineBasis.h:56
gsRationalTHBSplineBasis<(1< d?d-1:d), T > BoundaryBasisType
Associated Boundary basis type.
Definition gsRationalTHBSplineBasis.h:59
T Scalar_t
Coefficient type.
Definition gsRationalTHBSplineBasis.h:51
BoundaryBasisType::uPtr boundaryBasis(boxSide const &s)
The number of basis functions in the direction of the k-th parameter component.
gsTHBSplineBasis< d, T > Src_t
Source basis type.
Definition gsRationalTHBSplineBasis.h:45
gsRationalBasis< gsTHBSplineBasis< d, T > > Base
Base type.
Definition gsRationalTHBSplineBasis.h:42
Src_t Basis_t
Coordinate basis type.
Definition gsRationalTHBSplineBasis.h:48
memory::unique_ptr< gsRationalTHBSplineBasis > uPtr
Unique pointer for gsRationalTHBSplineBasis.
Definition gsRationalTHBSplineBasis.h:65
memory::shared_ptr< gsRationalTHBSplineBasis > Ptr
Shared pointer for gsRationalTHBSplineBasis.
Definition gsRationalTHBSplineBasis.h:62
A rational truncated hierarchical B-Spline function of parametric dimension d, with arbitrary target ...
Definition gsRationalTHBSpline.h:40
Truncated hierarchical B-spline basis.
Definition gsTHBSplineBasis.h:36
memory::unique_ptr< gsTHBSplineBasis > uPtr
Unique pointer for gsTHBSplineBasis.
Definition gsTHBSplineBasis.h:53
A tensor product B-spline basis.
Definition gsTensorBSplineBasis.h:37
#define index_t
Definition gsConfig.h:32
#define GISMO_ERROR(message)
Definition gsDebug.h:118
Provides forward declarations of types and structs.
Provides declaration of RationalBasis class.
Represents a rational truncated hierarchical B-Spline patch.
The G+Smo namespace, containing all definitions for the library.
S give(S &x)
Definition gsMemory.h:266