1 #ifndef DUNE_MULTIINDEX_HH
2 #define DUNE_MULTIINDEX_HH
7 #include <dune/common/fvector.hh>
20 template<
int dim,
class Field >
23 template<
int dim,
class Field >
24 std::ostream &operator<< ( std::ostream &, const MultiIndex< dim,Field > & );
31 template<
int dim,
class Field >
36 friend std::ostream &operator<<<> ( std::ostream &,
const This & );
56 : vecZ_( other.vecOMZ_ ),
57 vecOMZ_( other.vecZ_ ),
58 factor_( other.factor_ )
63 next_ =
new This( *(other.next_) );
70 : vecZ_( other.vecZ_ ),
71 vecOMZ_( other.vecOMZ_ ),
72 factor_( other.factor_ )
76 next_ =
new This( *(other.next_) );
104 vecOMZ_ = other.vecOMZ_;
105 factor_ = other.factor_;
107 next_ =
new This(*(other.next_));
138 assert(!next_ && !other.next_);
139 return (vecZ_==other.vecZ_ && vecOMZ_==other.vecOMZ_ && factor_==other.factor_);
161 assert(!other.next_);
162 vecZ_ += other.vecZ_;
163 vecOMZ_ += other.vecOMZ_;
164 factor_ *= other.factor_;
171 assert(!other.next_);
172 vecZ_ -= other.vecZ_;
173 vecOMZ_ -= other.vecOMZ_;
174 factor_ /= other.factor_;
182 assert(!other.next_);
183 if (std::abs(other.factor_)<1e-10)
185 if (std::abs(factor_)<1e-10)
196 next_ =
new This(other);
200 factor_ += other.factor_;
205 assert(!other.next_);
212 next_ =
new This(other);
216 factor_ -= other.factor_;
255 void set (
int d,
int power = 1 )
264 ret += std::abs( vecZ_[ i ] );
272 ret += std::abs( vecOMZ_[ i ] );
280 if ( vecZ_[i] != ind.vecZ_[i] ||
281 vecOMZ_[i] != vecOMZ_[i] )
298 typedef Dune::FieldVector< int, dimension > Vector;
307 template <
int dim,
class Field,
class F>
314 template <
int dim,
class Field,
class F>
322 template <
int d,
class F>
323 std::ostream &operator<<(std::ostream& out,const std::vector<MultiIndex<d,F> >& y) {
324 for (
unsigned int r=0;r<y.size();++r) {
325 out <<
"f_{" << r <<
"}(" << char(
'a');
326 for (
int i=1;i<d;++i)
327 out <<
"," <<
char(
'a'+i);
329 out << y[r] << std::endl;
333 template <
int d,
class F,
int dimR>
336 out <<
"\\begin{eqnarray*}" << std::endl;
337 for (
unsigned int k=0;k<y.size();++k) {
338 out <<
"f_{" << k <<
"}(" << char(
'a');
339 for (
int i=1;i<d;++i)
340 out <<
"," <<
char(
'a'+i);
343 for (
unsigned int r=1;r<dimR;++r) {
344 out <<
" , " << y[k][r] ;
346 out <<
" ) \\\\" << std::endl;
348 out <<
"\\end{eqnarray*}" << std::endl;
351 template <
int d,
class F,
int dimR1,
int dimR2>
353 const std::vector<Dune::FieldMatrix<
MultiIndex<d,F>,dimR1,dimR2> >& y) {
354 out <<
"\\begin{eqnarray*}" << std::endl;
355 for (
unsigned int k=0;k<y.size();++k) {
356 for (
int q=0;q<dimR2;q++) {
357 out <<
"d_{" << char(
'a'+q) <<
"}f_{" << k <<
"}(" << char(
'a');
358 for (
int i=1;i<d;++i)
359 out <<
"," <<
char(
'a'+i);
362 for (
unsigned int r=1;r<dimR1;++r) {
363 out <<
" , " << y[k][r][q] ;
365 out <<
" ) \\\\" << std::endl;
368 out <<
"\\end{eqnarray*}" << std::endl;
371 template <
int d,
class F>
372 std::ostream &operator<<(std::ostream& out,const MultiIndex<d,F>& val)
377 if (m->
absZ()==0 && std::abs(m->
factor())<1e-10)
379 if (!m->next_ || !first)
389 if (m->
factor()>0 && !first)
399 F f = std::abs(m->
factor());
403 if ( std::abs(f)<1e-10)
409 if ( std::abs(f_1)>1e-10)
412 for (
int i=0;i<d;++i) {
415 else if (m->vecZ_[i]==1)
417 else if (m->vecZ_[i]>0)
418 out << char(
'a'+i) <<
"^" << m->vecZ_[i] <<
"";
419 else if (m->vecZ_[i]<0)
420 out << char(
'a'+i) <<
"^" << m->vecZ_[i] <<
"";
421 absVal += m->vecZ_[i];
422 if (absVal<m->absZ()) out <<
"";
446 template<
int dim,
class F>
458 return Field( 1, other );
463 return Field() / other;
469 template<
int dim,
class F >
481 template<
int dim,
class Field >
487 template<
int dim,
class Field >
495 #endif // #ifndef DUNE_MULTIINDEX_HH