3#ifndef DUNE_STRUCTURED_GRID_FACTORY_HH
4#define DUNE_STRUCTURED_GRID_FACTORY_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;
42 const array<unsigned int,dim>& vertices)
44 FactoryUtilities::MultiIndex<dim> index(vertices);
47 int numVertices = index.cycle();
50 for (
int i=0; i<numVertices; i++, ++index) {
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 array<unsigned int, dim> computeUnitOffsets(
const array<unsigned int,dim>& vertices)
69 array<unsigned int, dim> unitOffsets;
73 for (
int i=1; i<dim; i++)
74 unitOffsets[i] = unitOffsets[i-1] * vertices[i-1];
92 const array<unsigned int,dim>& elements)
97 if (MPIHelper::getCollectiveCommunication().rank() == 0)
100 array<unsigned int,dim> vertices = elements;
101 for(
size_t i = 0; i < vertices.size(); ++i )
105 insertVertices(factory, lowerLeft, upperRight, vertices);
109 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];
124 FactoryUtilities::MultiIndex<dim> index(elements);
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++)
149 return shared_ptr<GridType>(factory.
createGrid());
168 const array<unsigned int,dim>& elements)
173 if(MPIHelper::getCollectiveCommunication().rank() == 0)
176 array<unsigned int,dim> vertices = elements;
177 for (std::size_t i=0; i<vertices.size(); i++)
180 insertVertices(factory, lowerLeft, upperRight, vertices);
184 array<unsigned int, dim> unitOffsets =
185 computeUnitOffsets(vertices);
188 std::vector<unsigned int> corners(dim+1);
192 FactoryUtilities::MultiIndex<dim> elementsIndex(elements);
193 size_t cycle = elementsIndex.cycle();
195 for (
size_t i=0; i<cycle; ++elementsIndex, i++) {
198 unsigned int base = 0;
199 for (
int j=0; j<dim; j++)
200 base += elementsIndex[j] * unitOffsets[j];
203 std::vector<unsigned int> permutation(dim);
204 for (
int j=0; j<dim; j++)
210 std::vector<unsigned int> corners(dim+1);
213 for (
int j=0; j<dim; j++)
215 corners[j] + unitOffsets[permutation[j]];
221 }
while (std::next_permutation(permutation.begin(),
229 return shared_ptr<GridType>(factory.
createGrid());
243 template<
class ctype,
int dim>
246 static const int dimworld = GridType::dimensionworld;
259 static shared_ptr<GridType>
262 const array<unsigned int,dim>& elements)
265 for(
int d = 0; d < dimworld; ++d)
266 if(abs(lowerLeft[d]) > abs(upperRight[d])*1e-10)
268 <<
"::createCubeGrid(): You have to use Yaspgrid<dim"
269 ", EquidistantOffsetCoordinates<ctype,dim> > as your"
270 "grid type for non-trivial origin." );
273 array<int, dim> elem;
274 std::copy(elements.begin(), elements.end(), elem.begin());
276 return shared_ptr<GridType>
278 std::bitset<dim>(), 0));
286 static shared_ptr<GridType>
289 const array<unsigned int,dim>& elements)
292 <<
"::createSimplexGrid(): Simplices are not supported "
307 template<
class ctype,
int dim>
310 static const int dimworld = GridType::dimensionworld;
319 static shared_ptr<GridType>
322 const array<unsigned int,dim>& elements)
325 array<int, dim> elem;
326 std::copy(elements.begin(), elements.end(), elem.begin());
328 return shared_ptr<GridType>
329 (
new GridType(lowerLeft, upperRight, elem,
330 std::bitset<dim>(), 0));
338 static shared_ptr<GridType>
341 const array<unsigned int,dim>& elements)
344 <<
"::createSimplexGrid(): Simplices are not supported "
Fallback implementation of the std::array class (a static array)
Container for equidistant coordinates in a YaspGrid.
Definition: coordinates.hh:27
Container for equidistant coordinates in a YaspGrid with non-trivial origin.
Definition: coordinates.hh:125
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
@ cube
Cube element in any nonnegative dimension.
Definition: type.hh:31
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Provide a generic factory class for unstructured grids.
Definition: gridfactory.hh:263
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: gridfactory.hh:290
virtual GridType * createGrid()
Finalize grid creation and hand over the grid.
Definition: gridfactory.hh:316
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: gridfactory.hh:279
static shared_ptr< GridType > createCubeGrid(const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const array< unsigned int, dim > &elements)
Create a structured cube grid.
Definition: structuredgridfactory.hh:260
static shared_ptr< GridType > createSimplexGrid(const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const array< unsigned int, dim > &elements)
Create a structured simplex grid.
Definition: structuredgridfactory.hh:287
static shared_ptr< GridType > createSimplexGrid(const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const array< unsigned int, dim > &elements)
Create a structured simplex grid.
Definition: structuredgridfactory.hh:339
static shared_ptr< GridType > createCubeGrid(const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const array< unsigned int, dim > &elements)
Create a structured cube grid.
Definition: structuredgridfactory.hh:320
Construct structured cube and simplex grids in unstructured grid managers.
Definition: structuredgridfactory.hh:31
static shared_ptr< GridType > createCubeGrid(const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const array< unsigned int, dim > &elements)
Create a structured cube grid.
Definition: structuredgridfactory.hh:90
static shared_ptr< GridType > createSimplexGrid(const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const array< unsigned int, dim > &elements)
Create a structured simplex grid.
Definition: structuredgridfactory.hh:166
[ provides Dune::Grid ]
Definition: yaspgrid.hh:166
A free function to provide the demangled class name of a given object or type as a string.
Provide a generic factory class for unstructured grids.
A few common exception classes.
Implements a vector constructed from a given type representing a field and a compile-time given size.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Helpers for dealing with MPI.
Implements a multiindex with arbitrary dimension and fixed index ranges This is used by various facto...
Dune namespace.
Definition: alignment.hh:10
This file implements the class shared_ptr (a reference counting pointer), for those systems that don'...