6#ifndef DUNE_ALBERTA_STRUCTUREDGRIDFACTORY_HH
7#define DUNE_ALBERTA_STRUCTUREDGRIDFACTORY_HH
19#include <dune/common/exceptions.hh>
20#include <dune/common/fvector.hh>
31 class StructuredGridFactory;
33 template <
int dim,
int dimworld>
49 template <
int dim,
int dimworld>
55 using ctype =
typename GridType::ctype;
60 const GeometryType& type,
61 const std::vector<unsigned int>& vertices)
64 static const auto reference_cubes = std::make_tuple(
65 std::array<std::array<int,2>,1>{
66 std::array<int,2>{0,1}},
67 std::array<std::array<int,3>,2>{
68 std::array<int,3>{3,0,1}, std::array<int,3>{0,3,2}},
69 std::array<std::array<int,4>,6>{
70 std::array<int,4>{0,7,3,1}, std::array<int,4>{0,7,5,1},
71 std::array<int,4>{0,7,5,4}, std::array<int,4>{0,7,3,2},
72 std::array<int,4>{0,7,6,2}, std::array<int,4>{0,7,6,4}} );
74 const auto& simplices = std::get<dim-1>(reference_cubes);
75 std::vector<unsigned int> corners(dim+1);
76 for (
const auto& simplex : simplices) {
77 for (std::size_t i = 0; i < simplex.size(); ++i)
78 corners[i] = vertices[simplex[i]];
86 const FieldVector<ctype,dimworld>& lowerLeft,
87 const FieldVector<ctype,dimworld>& upperRight,
88 const std::array<unsigned int,dim>& vertices)
90 FactoryUtilities::MultiIndex<dim> index(vertices);
93 int numVertices = index.cycle();
96 for (
int i=0; i<numVertices; i++, ++index) {
99 FieldVector<double,dimworld> pos(0);
100 for (
int j=0; j<dim; j++)
101 pos[j] = lowerLeft[j] + index[j] * (upperRight[j]-lowerLeft[j])/(vertices[j]-1);
102 for (
int j=dim; j<dimworld; j++)
103 pos[j] = lowerLeft[j];
113 static std::array<unsigned int, dim> computeUnitOffsets (
114 const std::array<unsigned int,dim>& vertices)
116 std::array<unsigned int, dim> unitOffsets;
120 for (
int i=1; i<dim; i++)
121 unitOffsets[i] = unitOffsets[i-1] * vertices[i-1];
138 const FieldVector<ctype,dimworld>& lowerLeft,
139 const FieldVector<ctype,dimworld>& upperRight,
140 const std::array<unsigned int,dim>& elements)
142 if (factory.
comm().rank() == 0)
145 std::array<unsigned int,dim> vertices = elements;
146 for (std::size_t i=0; i<vertices.size(); ++i)
149 insertVertices(factory, lowerLeft, upperRight, vertices);
153 std::array<unsigned int, dim> unitOffsets =
154 computeUnitOffsets(vertices);
158 unsigned int nCorners = 1<<dim;
160 std::vector<unsigned int> cornersTemplate(nCorners,0);
161 for (std::size_t i=0; i<nCorners; ++i)
162 for (
int j=0; j<dim; ++j)
164 cornersTemplate[i] += unitOffsets[j];
167 FactoryUtilities::MultiIndex<dim> index(elements);
170 int numElements = index.cycle();
172 for (
int i=0; i<numElements; ++i, ++index) {
175 unsigned int base = 0;
176 for (
int j=0; j<dim; j++)
177 base += index[j] * unitOffsets[j];
180 std::vector<unsigned int> corners = cornersTemplate;
181 for (std::size_t j=0; j<corners.size(); ++j)
184 insertElement(factory, GeometryTypes::simplex(dim), corners);
199 const FieldVector<ctype,dimworld>& lowerLeft,
200 const FieldVector<ctype,dimworld>& upperRight,
201 const std::array<unsigned int,dim>& elements)
205 return std::unique_ptr<GridType>(factory.
createGrid());
210 const FieldVector<ctype,dimworld>& lowerLeft,
211 const FieldVector<ctype,dimworld>& upperRight,
212 const std::array<unsigned int,dim>& elements)
214 DUNE_THROW(Dune::NotImplemented,
215 "Cube grids are not supported by AlbertaGrid. Use createSimplexGrid instead.");
219 const FieldVector<ctype,dimworld>& lowerLeft,
220 const FieldVector<ctype,dimworld>& upperRight,
221 const std::array<unsigned int,dim>& elements)
223 DUNE_THROW(Dune::NotImplemented,
224 "Cube grids are not supported by AlbertaGrid. Use createSimplexGrid instead.");
[ provides Dune::Grid ]
Definition: agrid.hh:109
Communication comm() const
Return the Communication used by the grid factory.
Definition: gridfactory.hh:258
Provide a generic factory class for unstructured grids.
Definition: gridfactory.hh:275
virtual void insertElement(const GeometryType &type, const std::vector< unsigned int > &vertices)
Insert an element into the coarse grid.
Definition: gridfactory.hh:307
virtual void insertVertex(const FieldVector< ctype, dimworld > &pos)
Insert a vertex into the coarse grid.
Definition: gridfactory.hh:296
virtual std::unique_ptr< GridType > createGrid()
Finalize grid creation and hand over the grid.
Definition: gridfactory.hh:333
static void createSimplexGrid(GridFactory< GridType > &factory, const FieldVector< ctype, dimworld > &lowerLeft, const FieldVector< ctype, dimworld > &upperRight, const std::array< unsigned int, dim > &elements)
Create a structured simplex grid for AlbertaGrid.
Definition: structuredgridfactory.hh:137
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 for AlbertaGrid.
Definition: structuredgridfactory.hh:198
Construct structured cube and simplex grids in unstructured grid managers.
Definition: structuredgridfactory.hh:31
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: structuredgridfactory.hh:181
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: structuredgridfactory.hh:91
Provide a generic factory class for unstructured grids.
Implements a multiindex with arbitrary dimension and fixed index ranges This is used by various facto...
Include standard header files.
Definition: agrid.hh:60
A class to construct structured cube and simplex grids using the grid factory.