5#ifndef DUNE_STRUCTURED_GRID_FACTORY_HH
6#define DUNE_STRUCTURED_GRID_FACTORY_HH
18#include <dune/common/classname.hh>
19#include <dune/common/exceptions.hh>
20#include <dune/common/fvector.hh>
29 template <
class Gr
idType>
32 typedef typename GridType::ctype ctype;
34 static const int dim = GridType::dimension;
36 static const int dimworld = GridType::dimensionworld;
40 const FieldVector<ctype,dimworld>& lowerLeft,
41 const FieldVector<ctype,dimworld>& upperRight,
42 const std::array<unsigned int,dim>& vertices)
47 int numVertices = index.
cycle();
50 for (
int i=0; i<numVertices; i++, ++index) {
53 FieldVector<double,dimworld> pos(0);
54 for (
int j=0; j<dim; j++)
55 pos[j] = lowerLeft[j] + index[j] * (upperRight[j]-lowerLeft[j])/(vertices[j]-1);
56 for (
int j=dim; j<dimworld; j++)
57 pos[j] = lowerLeft[j];
67 static std::array<unsigned int, dim> computeUnitOffsets(
const std::array<unsigned int,dim>& vertices)
69 std::array<unsigned int, dim> unitOffsets;
73 for (
int i=1; i<dim; i++)
74 unitOffsets[i] = unitOffsets[i-1] * vertices[i-1];
93 const FieldVector<ctype,dimworld>& lowerLeft,
94 const FieldVector<ctype,dimworld>& upperRight,
95 const std::array<unsigned int,dim>& elements)
97 if (factory.
comm().rank() == 0)
100 std::array<unsigned int,dim> vertices = elements;
101 for(
size_t i = 0; i < vertices.size(); ++i )
105 insertVertices(factory, lowerLeft, upperRight, vertices);
109 std::array<unsigned int, dim> unitOffsets =
110 computeUnitOffsets(vertices);
114 unsigned int nCorners = 1<<dim;
116 std::vector<unsigned int> cornersTemplate(nCorners,0);
118 for (
size_t i=0; i<nCorners; i++)
119 for (
int j=0; j<dim; j++)
121 cornersTemplate[i] += unitOffsets[j];
127 int numElements = index.
cycle();
129 for (
int i=0; i<numElements; i++, ++index) {
132 unsigned int base = 0;
133 for (
int j=0; j<dim; j++)
134 base += index[j] * unitOffsets[j];
137 std::vector<unsigned int> corners = cornersTemplate;
138 for (
size_t j=0; j<corners.size(); j++)
158 const FieldVector<ctype,dimworld>& lowerLeft,
159 const FieldVector<ctype,dimworld>& upperRight,
160 const std::array<unsigned int,dim>& elements)
164 return std::unique_ptr<GridType>(factory.
createGrid());
183 const FieldVector<ctype,dimworld>& lowerLeft,
184 const FieldVector<ctype,dimworld>& upperRight,
185 const std::array<unsigned int,dim>& elements)
187 if(factory.
comm().rank() == 0)
190 std::array<unsigned int,dim> vertices = elements;
191 for (std::size_t i=0; i<vertices.size(); i++)
194 insertVertices(factory, lowerLeft, upperRight, vertices);
198 std::array<unsigned int, dim> unitOffsets =
199 computeUnitOffsets(vertices);
204 size_t cycle = elementsIndex.
cycle();
206 for (
size_t i=0; i<cycle; ++elementsIndex, i++) {
209 unsigned int base = 0;
210 for (
int j=0; j<dim; j++)
211 base += elementsIndex[j] * unitOffsets[j];
214 std::vector<unsigned int> permutation(dim);
215 for (
int j=0; j<dim; j++)
221 std::vector<unsigned int> corners(dim+1);
224 for (
int j=0; j<dim; j++)
226 corners[j] + unitOffsets[permutation[j]];
230 }
while (std::next_permutation(permutation.begin(),
252 const FieldVector<ctype,dimworld>& lowerLeft,
253 const FieldVector<ctype,dimworld>& upperRight,
254 const std::array<unsigned int,dim>& elements)
258 return std::unique_ptr<GridType>(factory.
createGrid());
Implements a multiindex with arbitrary dimension and fixed index ranges This is used by various facto...
Include standard header files.
Definition: agrid.hh:60
Construct structured cube and simplex grids in unstructured grid managers.
Definition: utility/structuredgridfactory.hh:31
static std::unique_ptr< GridType > createCubeGrid(const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const std::array< unsigned int, dim > &elements)
Create a structured cube grid.
Definition: utility/structuredgridfactory.hh:157
static void createSimplexGrid(GridFactory< GridType > &factory, const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const std::array< unsigned int, dim > &elements)
insert structured simplex grid into grid factory
Definition: utility/structuredgridfactory.hh:181
static std::unique_ptr< GridType > createSimplexGrid(const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const std::array< unsigned int, dim > &elements)
Create a structured simplex grid.
Definition: utility/structuredgridfactory.hh:251
static void createCubeGrid(GridFactory< GridType > &factory, const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const std::array< unsigned int, dim > &elements)
insert structured cube grid into grid factory
Definition: utility/structuredgridfactory.hh:91
Communication comm() const
Return the Communication used by the grid factory.
Definition: common/gridfactory.hh:297
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:314
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: common/gridfactory.hh:346
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: common/gridfactory.hh:335
virtual std::unique_ptr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: common/gridfactory.hh:372
Definition: multiindex.hh:19
size_t cycle() const
Compute how many times you can call operator++ before getting to (0,...,0) again.
Definition: multiindex.hh:48
Provide a generic factory class for unstructured grids.