3#ifndef DUNE_MULTIINDEX_HH
4#define DUNE_MULTIINDEX_HH
11#include <dune/localfunctions/utility/field.hh>
22 template<
int dim,
class Field >
25 template<
int dim,
class Field >
26 std::ostream &operator<< ( std::ostream &,
const MultiIndex< dim,Field > & );
33 template<
int dim,
class Field >
36 typedef MultiIndex< dim, Field > This;
38 friend std::ostream &operator<<<> ( std::ostream &,
const This & );
41 static const int dimension = dim;
50 explicit MultiIndex (
const F &f)
57 MultiIndex (
int,
const This &other )
58 : vecZ_( other.vecOMZ_ ),
59 vecOMZ_( other.vecZ_ ),
60 factor_( other.factor_ )
65 next_ =
new This( *(other.next_) );
71 MultiIndex (
const This &other )
72 : vecZ_( other.vecZ_ ),
73 vecOMZ_( other.vecOMZ_ ),
74 factor_( other.factor_ )
78 next_ =
new This( *(other.next_) );
97 const Field &factor()
const
102 This &operator= (
const This &other )
106 vecOMZ_ = other.vecOMZ_;
107 factor_ = other.factor_;
109 next_ =
new This(*(other.next_));
112 This &operator= (
const Zero<This> &f )
120 This &operator= (
const Unity<This> &f )
129 This &operator= (
const F &f )
134 factor_ = field_cast<Field>(f);
140 assert(!next_ && !other.next_);
141 return (vecZ_==other.vecZ_ && vecOMZ_==other.vecOMZ_ && factor_==other.factor_);
145 This &operator*= (
const F &f )
147 factor_ *= field_cast<Field>(f);
153 This &operator/= (
const F &f )
155 factor_ /= field_cast<Field>(f);
161 This &operator*= (
const This &other )
163 assert(!other.next_);
164 vecZ_ += other.vecZ_;
165 vecOMZ_ += other.vecOMZ_;
166 factor_ *= other.factor_;
171 This &operator/= (
const This &other )
173 assert(!other.next_);
174 vecZ_ -= other.vecZ_;
175 vecOMZ_ -= other.vecOMZ_;
176 factor_ /= other.factor_;
182 This &operator+= (
const This &other )
184 assert(!other.next_);
185 if (std::abs(other.factor_)<1e-10)
187 if (std::abs(factor_)<1e-10)
192 if (!sameMultiIndex(other))
198 next_ =
new This(other);
202 factor_ += other.factor_;
205 This &operator-= (
const This &other )
207 assert(!other.next_);
208 if (!sameMultiIndex(other))
214 next_ =
new This(other);
218 factor_ -= other.factor_;
223 This operator* (
const F &f )
const
229 This operator/ (
const F &f )
const
235 This operator* (
const This &other )
const
240 This operator/ (
const This &other )
const
246 This operator+ (
const This &other )
const
251 This operator- (
const This &other )
const
257 void set (
int d,
int power = 1 )
265 for(
int i = 0; i < dimension; ++i )
266 ret += std::abs( vecZ_[ i ] );
273 for(
int i = 0; i < dimension; ++i )
274 ret += std::abs( vecOMZ_[ i ] );
278 bool sameMultiIndex(
const This &ind)
280 for(
int i = 0; i < dimension; ++i )
282 if ( vecZ_[i] != ind.vecZ_[i] ||
283 vecOMZ_[i] != vecOMZ_[i] )
309 template <
int dim,
class Field,
class F>
310 MultiIndex<dim,Field> operator* (
const F &f,
311 const MultiIndex<dim,Field> &m)
313 MultiIndex<dim,Field> z = m;
316 template <
int dim,
class Field,
class F>
317 MultiIndex<dim,Field> operator/ (
const F &f,
318 const MultiIndex<dim,Field> &m)
320 MultiIndex<dim,Field> z = m;
324 template <
int d,
class F>
325 std::ostream &operator<<(std::ostream& out,
const std::vector<MultiIndex<d,F> >& y) {
326 for (
unsigned int r=0; r<y.size(); ++r) {
327 out <<
"f_{" << r <<
"}(" << char(
'a');
328 for (
int i=1; i<d; ++i)
329 out <<
"," <<
char(
'a'+i);
331 out << y[r] << std::endl;
335 template <
int d,
class F,
int dimR>
336 std::ostream &operator<<(std::ostream& out,
338 out <<
"\\begin{eqnarray*}" << std::endl;
339 for (
unsigned int k=0; k<y.size(); ++k) {
340 out <<
"f_{" << k <<
"}(" << char(
'a');
341 for (
int i=1; i<d; ++i)
342 out <<
"," <<
char(
'a'+i);
345 for (
unsigned int r=1; r<dimR; ++r) {
346 out <<
" , " << y[k][r] ;
348 out <<
" ) \\\\" << std::endl;
350 out <<
"\\end{eqnarray*}" << std::endl;
353 template <
int d,
class F,
int dimR1,
int dimR2>
354 std::ostream &operator<<(std::ostream& out,
356 out <<
"\\begin{eqnarray*}" << std::endl;
357 for (
unsigned int k=0; k<y.size(); ++k) {
358 for (
int q=0; q<dimR2; q++) {
359 out <<
"d_{" << char(
'a'+q) <<
"}f_{" << k <<
"}(" << char(
'a');
360 for (
int i=1; i<d; ++i)
361 out <<
"," <<
char(
'a'+i);
364 for (
unsigned int r=1; r<dimR1; ++r) {
365 out <<
" , " << y[k][r][q] ;
367 out <<
" ) \\\\" << std::endl;
370 out <<
"\\end{eqnarray*}" << std::endl;
373 template <
int d,
class F>
374 std::ostream &operator<<(std::ostream& out,
const MultiIndex<d,F>& val)
377 const MultiIndex<d,F> *m = &val;
379 if (m->absZ()==0 && std::abs(m->factor())<1e-10)
381 if (!m->next_ || !first)
391 if (m->factor()>0 && !first)
393 else if (m->factor()<0)
401 F f = std::abs(m->factor());
405 if ( std::abs(f)<1e-10)
411 if ( std::abs(f_1)>1e-10)
414 for (
int i=0; i<d; ++i) {
417 else if (m->vecZ_[i]==1)
419 else if (m->vecZ_[i]>0)
420 out << char(
'a'+i) <<
"^" << m->vecZ_[i] <<
"";
421 else if (m->vecZ_[i]<0)
422 out << char(
'a'+i) <<
"^" << m->vecZ_[i] <<
"";
423 absVal += m->vecZ_[i];
424 if (absVal<m->absZ()) out <<
"";
448 template<
int dim,
class F>
449 struct Unity< MultiIndex< dim, F > >
451 typedef MultiIndex< dim, F > Field;
453 operator Field ()
const
458 Field operator- (
const Field &other )
const
460 return Field( 1, other );
463 Field operator/ (
const Field &other )
const
465 return Field() / other;
471 template<
int dim,
class F >
472 struct Zero< MultiIndex< dim,F > >
474 typedef MultiIndex< dim,F > Field;
483 template<
int dim,
class Field >
484 bool operator< (
const Zero< MultiIndex< dim,Field > > &,
const MultiIndex< dim,Field > & )
489 template<
int dim,
class Field >
490 bool operator< (
const MultiIndex< dim, Field > &f,
const Zero< MultiIndex< dim,Field > > & )
A dense n x m matrix.
Definition: fmatrix.hh:68
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:629
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:233
Dune namespace.
Definition: alignedallocator.hh:10
void field_cast(const F1 &f1, F2 &f2)
a helper class to cast from one field to another
Definition: field.hh:157