#ifndef TURING_GRID_HH #define TURING_GRID_HH #include class structured_grid { public: // create a 2d grid structured_grid(int x, int y, double h_) : dim(2), h(h_) { // parallel: parallele Aufteilung berechnen und lokalen Patch bestimmen N[0] = x; N[1] = y; N[2] = 0; } // create a 3d grid structured_grid(int x, int y, int z, double h_) : dim(3), h(h_) { N[0] = x; N[1] = y; N[2] = z; } // query number of vertices in the grid unsigned int size() const { return (N[0]+1)*(N[1]+1)*(N[2]+1); } // query number of vertices in direction d unsigned int size(unsigned int d) const { return N[d]+1; } // query number of cells in direction d unsigned int cells(unsigned int d) const { return N[d]; } // query meshwidth double meshwidth() const { return h; } // compute linear ordering based on muti-index unsigned int index(unsigned int i[3]) const { return (i[0]*size(1)+i[1])*size(2)+i[2]; } // compute multi-index based on linear ordering unsigned int index(unsigned int i, unsigned int d) const { switch (d) { case 0: return (i/(size(1)*size(2)))%size(0); case 1: return (i/(size(2)))%size(1); case 2: return i%(size(2)); default: return 0; } } // compute neighbors for a given cell std::vector neighbors(unsigned int i[3]) const { std::vector n(6,0); // allocate space for 6 neighbors n.resize(0); // tmp copy index unsigned int j[3]; for (unsigned int d=0; d 0) n.push_back(index(j)); j[d]++; j[d]++; // right if (i[d] < N[d]) n.push_back(index(j)); j[d]--; } return n; } private: // domain const unsigned int dim; unsigned int N[3]; const double h; }; #endif // TURING_GRID_HH