31 template<
short_t d,
class T>
32 class gsMvMonomialBasis :
public gsBasis<T>
36 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
41 typedef memory::shared_ptr< gsMvMonomialBasis > Ptr;
44 typedef memory::unique_ptr< gsMvMonomialBasis > uPtr;
48 static const bool IsRational =
false;
50 typedef memory::unique_ptr< gsDomainIterator<T> > domainIter;
57 typedef gsEigen::internal::variable_if_dynamic<unsigned,d> dimType;
60 std::vector<gsVector<index_t> > m_compositions;
63 gsMvMonomialBasis() : m_d(-1), m_degree(-1) { }
65 gsMvMonomialBasis(
unsigned _d,
unsigned p) : m_d(_d), m_degree(p)
67 getCompositions(m_compositions);
71 gsMvMonomialBasis(
unsigned p) : m_d(d), m_degree(p)
73 getCompositions(m_compositions);
77 ~gsMvMonomialBasis() { };
85 void active_into(
const gsMatrix<T> & u, gsMatrix<index_t>& result)
const
87 const int sz = size();
88 result.resize( sz, u.cols() );
89 for (
int i = 0; i< sz; ++i )
90 result.row(i).setConstant(i);
94 gsMatrix<T> support()
const;
97 gsMatrix<T> support(
const index_t & i)
const;
100 void eval_into(
const gsMatrix<T> & u, gsMatrix<T>& result)
const;
103 void evalSingle_into(
index_t i,
const gsMatrix<T> & u, gsMatrix<T>& result)
const;
106 void deriv_into(
const gsMatrix<T> & u, gsMatrix<T>& result )
const;
109 void derivSingle_into(
index_t i,
const gsMatrix<T> & u, gsMatrix<T>& result )
const;
112 void deriv2_into(
const gsMatrix<T> & u, gsMatrix<T>& result )
const;
115 void deriv2Single_into(
index_t i,
const gsMatrix<T> & u, gsMatrix<T>& result )
const;
117 GISMO_CLONE_FUNCTION(gsMvMonomialBasis)
120 memory::unique_ptr<gsGeometry<T> > makeGeometry(gsMatrix<T> coefs )
const
128 std::ostream &print(std::ostream &os)
const
130 os <<
"Multivariate monomial basis basis of degree "
131 << m_degree <<
" and "<<m_d.value()<<
" variables\n";
136 std::string detail()
const
139 std::ostringstream os;
158 {
return m_compositions[k].sum(); }
162 void getCompositions( std::vector<gsVector<index_t> > & compos)
const;
165 void getCompositions( std::vector<gsVector<index_t> > & compos,
index_t degree)
const;
171 int findIndex(gsVector<index_t>
const p, std::vector<gsVector<index_t> >
const compos )
const;
176 template<
short_t d,
class T>
177 short_t gsMvMonomialBasis<d,T>::domainDim()
const {
return m_d.value(); }
179 template<
short_t d,
class T>
180 index_t gsMvMonomialBasis<d,T>::size()
const{
181 return m_compositions.size();
184 template<
short_t d,
class T>
185 gsMatrix<T> gsMvMonomialBasis<d,T>::support(
const index_t & i)
const
186 {
return gsMatrix<T>();}
188 template<
short_t d,
class T>
189 gsMatrix<T> gsMvMonomialBasis<d,T>:: support()
const
190 {
return gsMatrix<T>();}
192 template<
short_t d,
class T>
193 void gsMvMonomialBasis<d,T>::evalSingle_into(
index_t i,
194 const gsMatrix<T> & u,
195 gsMatrix<T>& result)
const
198 result.setZero(1,u.cols() );
199 for(
int j = 0; j < u.cols(); j++)
203 for(
int k = 0; k < m_compositions[i].size(); k++)
205 val = val * math::pow(point[k], static_cast<int>(m_compositions[i][k]));
211 template<
short_t d,
class T>
212 void gsMvMonomialBasis<d,T>::eval_into(
const gsMatrix<T> & u, gsMatrix<T>& result)
const
214 result.setZero(m_compositions.size(), u.cols());
215 gsMatrix<T> single_result;
216 for(
unsigned i = 0; i < m_compositions.size(); i++)
218 evalSingle_into(i, u, single_result);
219 result.row(i) = single_result.row(0);
223 template<
short_t d,
class T>
224 void gsMvMonomialBasis<d,T>::derivSingle_into(
index_t i,
const gsMatrix<T> & u, gsMatrix<T>& result )
const
229 template<
short_t d,
class T>
230 void gsMvMonomialBasis<d,T>::deriv_into(
const gsMatrix<T> & u, gsMatrix<T>& result )
const
232 result.setZero(m_compositions.size()*this->dim(), u.cols());
233 gsMatrix<T> single_result;
234 for(
unsigned i = 0; i < m_compositions.size(); i++)
236 derivSingle_into(i, u, single_result);
237 for(
int j = 0; j < single_result.rows();j++)
239 result.row(m_d.value()*i+j) = single_result.row(j);
244 template<
short_t d,
class T>
245 void gsMvMonomialBasis<d,T>::deriv2Single_into(
index_t i,
const gsMatrix<T> & u,
246 gsMatrix<T>& result )
const
248 result.setZero(m_d.value(), u.cols());
251 for(
index_t j = 0; j < u.cols(); ++j)
254 for(
index_t l = 0; l < m_compositions[i].size(); ++l)
257 for(
index_t k = 0; k < m_compositions[i].size(); ++k)
259 const unsigned ex = m_compositions[i][k];
260 if (ex<1 ) { val=0;
break; }
261 if (ex==1) {
continue; }
262 val = val * ex * math::pow(point[k], static_cast<int>(ex-1));
269 template<
short_t d,
class T>
270 void gsMvMonomialBasis<d,T>::deriv2_into(
const gsMatrix<T> & u, gsMatrix<T>& result )
const
272 result.setZero(m_compositions.size()*((d * (d + 1)) / 2), u.cols());
273 gsMatrix<T> single_result;
274 for(
unsigned i = 0; i < m_compositions.size(); i++)
276 deriv2Single_into(i, u, single_result);
277 for(
int j = 0; j < single_result.rows();j++){
278 result.row(single_result.rows()*i+j) = single_result.row(j);
283 template<
short_t d,
class T>
284 void gsMvMonomialBasis<d,T>::getCompositions(std::vector<gsVector<index_t> > & compos)
const{
285 this->getCompositions(compos,m_degree);
291 bool comp_deg(
const gsVector<index_t> & a,
const gsVector<index_t>& b)
292 {
return a.sum()<b.sum(); }
295 template<
short_t d,
class T>
296 void gsMvMonomialBasis<d,T>::getCompositions(std::vector<gsVector<index_t> > & compos,
index_t degree)
const
299 gsVector<index_t> RR;
303 compos.push_back(RR.tail(m_d.value()));
306 std::sort(compos.begin(), compos.end(), comp_deg );
309 template<
short_t d,
class T>
310 int gsMvMonomialBasis<d,T>::findIndex(gsVector<index_t>
const p,
311 std::vector<gsVector<index_t> >
const compos )
const
314 for(
index_t i = 0; i < compos.size();i++)
316 if(p==compos[i])
return i;
#define GISMO_NO_IMPLEMENTATION
Definition: gsDebug.h:129
virtual domainIter makeDomainIterator(const boxSide &s) const
Create a boundary domain iterator for the computational mesh this basis, that points to the first ele...
Definition: gsBasis.hpp:498
void firstComposition(typename Vec::Scalar sum, index_t dim, Vec &res)
Construct first composition of sum into dim integers.
Definition: gsCombinatorics.h:657
#define short_t
Definition: gsConfig.h:35
Provides structs and classes related to interfaces and boundaries.
Provides definition of the BasisFun class.
Provides declaration of Basis abstract interface.
#define index_t
Definition: gsConfig.h:32
This file contains the debugging and messaging system of G+Smo.
Provides combinatorial unitilies.
bool nextComposition(Vec &v)
Returns (inplace) the next composition in lexicographic order.
Definition: gsCombinatorics.h:667
This is the main header file that collects wrappers of Eigen for linear algebra.
unsigned numCompositions(int sum, short_t dim)
Number of compositions of sum into dim integers.
Definition: gsCombinatorics.h:691