5#ifndef DUNE_MULTIINDEX_HH
6#define DUNE_MULTIINDEX_HH
13#include <dune/localfunctions/utility/field.hh>
24 template<
int dim,
class Field >
27 template<
int dim,
class Field >
28 std::ostream &operator<< ( std::ostream &,
const MultiIndex< dim,Field > & );
35 template<
int dim,
class Field >
38 typedef MultiIndex< dim, Field > This;
40 friend std::ostream &operator<<<> ( std::ostream &,
const This & );
43 static const int dimension = dim;
52 explicit MultiIndex (
const F &f)
59 MultiIndex (
int,
const This &other )
60 : vecZ_( other.vecOMZ_ ),
61 vecOMZ_( other.vecZ_ ),
62 factor_( other.factor_ )
67 next_ =
new This( *(other.next_) );
73 MultiIndex (
const This &other )
74 : vecZ_( other.vecZ_ ),
75 vecOMZ_( other.vecOMZ_ ),
76 factor_( other.factor_ )
80 next_ =
new This( *(other.next_) );
99 const Field &factor()
const
104 This &operator= (
const This &other )
108 vecOMZ_ = other.vecOMZ_;
109 factor_ = other.factor_;
111 next_ =
new This(*(other.next_));
114 This &operator= (
const Zero<This> &f )
122 This &operator= (
const Unity<This> &f )
131 This &operator= (
const F &f )
136 factor_ = field_cast<Field>(f);
142 assert(!next_ && !other.next_);
143 return (vecZ_==other.vecZ_ && vecOMZ_==other.vecOMZ_ && factor_==other.factor_);
147 This &operator*= (
const F &f )
149 factor_ *= field_cast<Field>(f);
155 This &operator/= (
const F &f )
157 factor_ /= field_cast<Field>(f);
163 This &operator*= (
const This &other )
165 assert(!other.next_);
166 vecZ_ += other.vecZ_;
167 vecOMZ_ += other.vecOMZ_;
168 factor_ *= other.factor_;
173 This &operator/= (
const This &other )
175 assert(!other.next_);
176 vecZ_ -= other.vecZ_;
177 vecOMZ_ -= other.vecOMZ_;
178 factor_ /= other.factor_;
184 This &operator+= (
const This &other )
186 assert(!other.next_);
187 if (std::abs(other.factor_)<1e-10)
189 if (std::abs(factor_)<1e-10)
194 if (!sameMultiIndex(other))
200 next_ =
new This(other);
204 factor_ += other.factor_;
207 This &operator-= (
const This &other )
209 assert(!other.next_);
210 if (!sameMultiIndex(other))
216 next_ =
new This(other);
220 factor_ -= other.factor_;
225 This operator* (
const F &f )
const
231 This operator/ (
const F &f )
const
237 This operator* (
const This &other )
const
242 This operator/ (
const This &other )
const
248 This operator+ (
const This &other )
const
253 This operator- (
const This &other )
const
259 void set (
int d,
int power = 1 )
267 for(
int i = 0; i < dimension; ++i )
268 ret += std::abs( vecZ_[ i ] );
275 for(
int i = 0; i < dimension; ++i )
276 ret += std::abs( vecOMZ_[ i ] );
280 bool sameMultiIndex(
const This &ind)
282 for(
int i = 0; i < dimension; ++i )
284 if ( vecZ_[i] != ind.vecZ_[i] ||
285 vecOMZ_[i] != vecOMZ_[i] )
311 template <
int dim,
class Field,
class F>
312 MultiIndex<dim,Field> operator* (
const F &f,
313 const MultiIndex<dim,Field> &m)
315 MultiIndex<dim,Field> z = m;
318 template <
int dim,
class Field,
class F>
319 MultiIndex<dim,Field> operator/ (
const F &f,
320 const MultiIndex<dim,Field> &m)
322 MultiIndex<dim,Field> z = m;
326 template <
int d,
class F>
327 std::ostream &operator<<(std::ostream& out,
const std::vector<MultiIndex<d,F> >& y) {
328 for (
unsigned int r=0; r<y.size(); ++r) {
329 out <<
"f_{" << r <<
"}(" << char(
'a');
330 for (
int i=1; i<d; ++i)
331 out <<
"," <<
char(
'a'+i);
333 out << y[r] << std::endl;
337 template <
int d,
class F,
int dimR>
338 std::ostream &operator<<(std::ostream& out,
340 out <<
"\\begin{eqnarray*}" << std::endl;
341 for (
unsigned int k=0; k<y.size(); ++k) {
342 out <<
"f_{" << k <<
"}(" << char(
'a');
343 for (
int i=1; i<d; ++i)
344 out <<
"," <<
char(
'a'+i);
347 for (
unsigned int r=1; r<dimR; ++r) {
348 out <<
" , " << y[k][r] ;
350 out <<
" ) \\\\" << std::endl;
352 out <<
"\\end{eqnarray*}" << std::endl;
355 template <
int d,
class F,
int dimR1,
int dimR2>
356 std::ostream &operator<<(std::ostream& out,
358 out <<
"\\begin{eqnarray*}" << std::endl;
359 for (
unsigned int k=0; k<y.size(); ++k) {
360 for (
int q=0; q<dimR2; q++) {
361 out <<
"d_{" << char(
'a'+q) <<
"}f_{" << k <<
"}(" << char(
'a');
362 for (
int i=1; i<d; ++i)
363 out <<
"," <<
char(
'a'+i);
366 for (
unsigned int r=1; r<dimR1; ++r) {
367 out <<
" , " << y[k][r][q] ;
369 out <<
" ) \\\\" << std::endl;
372 out <<
"\\end{eqnarray*}" << std::endl;
375 template <
int d,
class F>
376 std::ostream &operator<<(std::ostream& out,
const MultiIndex<d,F>& val)
379 const MultiIndex<d,F> *m = &val;
381 if (m->absZ()==0 && std::abs(m->factor())<1e-10)
383 if (!m->next_ || !first)
393 if (m->factor()>0 && !first)
395 else if (m->factor()<0)
403 F f = std::abs(m->factor());
407 if ( std::abs(f)<1e-10)
413 if ( std::abs(f_1)>1e-10)
416 for (
int i=0; i<d; ++i) {
419 else if (m->vecZ_[i]==1)
421 else if (m->vecZ_[i]>0)
422 out << char(
'a'+i) <<
"^" << m->vecZ_[i] <<
"";
423 else if (m->vecZ_[i]<0)
424 out << char(
'a'+i) <<
"^" << m->vecZ_[i] <<
"";
425 absVal += m->vecZ_[i];
426 if (absVal<m->absZ()) out <<
"";
450 template<
int dim,
class F>
451 struct Unity< MultiIndex< dim, F > >
453 typedef MultiIndex< dim, F > Field;
455 operator Field ()
const
460 Field operator- (
const Field &other )
const
462 return Field( 1, other );
465 Field operator/ (
const Field &other )
const
467 return Field() / other;
473 template<
int dim,
class F >
474 struct Zero< MultiIndex< dim,F > >
476 typedef MultiIndex< dim,F > Field;
485 template<
int dim,
class Field >
486 bool operator< (
const Zero< MultiIndex< dim,Field > > &,
const MultiIndex< dim,Field > & )
491 template<
int dim,
class Field >
492 bool operator< (
const MultiIndex< dim, Field > &f,
const Zero< MultiIndex< dim,Field > > & )
A dense n x m matrix.
Definition: fmatrix.hh:117
Implements a vector constructed from a given type representing a field and a compile-time given size.
EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:637
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:237
Dune namespace.
Definition: alignedallocator.hh:13
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:159
constexpr Base power(Base m, Exponent p)
Power method for integer exponents.
Definition: math.hh:75