Skip to content
Snippets Groups Projects
Commit 8dc0d3ab authored by Oliver Sander's avatar Oliver Sander Committed by sander@FU-BERLIN.DE
Browse files

Move the MultiIndex class into a separate file

[[Imported from SVN: r7120]]
parent a8293e95
No related branches found
No related tags found
Loading
...@@ -11,58 +11,12 @@ ...@@ -11,58 +11,12 @@
#include <dune/gfe/unitvector.hh> #include <dune/gfe/unitvector.hh>
#include <dune/gfe/localgeodesicfefunction.hh> #include <dune/gfe/localgeodesicfefunction.hh>
#include "multiindex.hh"
const double eps = 1e-6; const double eps = 1e-6;
using namespace Dune; using namespace Dune;
/** \brief N-dimensional multi-index
*/
template <int N>
class MultiIndex
: public array<unsigned int,N>
{
// The range of each component
unsigned int limit_;
public:
/** \brief Constructor with a given range for each digit */
MultiIndex(unsigned int limit)
: limit_(limit)
{
std::fill(this->begin(), this->end(), 0);
}
/** \brief Increment the MultiIndex */
MultiIndex& operator++() {
for (int i=0; i<N; i++) {
// Augment digit
(*this)[i]++;
// If there is no carry-over we can stop here
if ((*this)[i]<limit_)
break;
(*this)[i] = 0;
}
return *this;
}
/** \brief Compute how many times you can call operator++ before getting to (0,...,0) again */
size_t cycle() const {
size_t result = 1;
for (int i=0; i<N; i++)
result *= limit_;
return result;
}
};
template <int domainDim> template <int domainDim>
void testDerivativeTangentiality(const RealTuple<1>& x, void testDerivativeTangentiality(const RealTuple<1>& x,
const FieldMatrix<double,1,domainDim>& derivative) const FieldMatrix<double,1,domainDim>& derivative)
......
#ifndef MULTI_INDEX_HH
#define MULTI_INDEX_HH
#include <dune/common/array.hh>
/** \brief N-dimensional multi-index
*/
template <int N>
class MultiIndex
: public Dune::array<unsigned int,N>
{
// The range of each component
unsigned int limit_;
public:
/** \brief Constructor with a given range for each digit */
MultiIndex(unsigned int limit)
: limit_(limit)
{
std::fill(this->begin(), this->end(), 0);
}
/** \brief Increment the MultiIndex */
MultiIndex& operator++() {
for (int i=0; i<N; i++) {
// Augment digit
(*this)[i]++;
// If there is no carry-over we can stop here
if ((*this)[i]<limit_)
break;
(*this)[i] = 0;
}
return *this;
}
/** \brief Compute how many times you can call operator++ before getting to (0,...,0) again */
size_t cycle() const {
size_t result = 1;
for (int i=0; i<N; i++)
result *= limit_;
return result;
}
};
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment