3#ifndef DUNE_MMESH_STRUCTURED_GRID_FACTORY_HH
4#define DUNE_MMESH_STRUCTURED_GRID_FACTORY_HH
12#include <dune/common/parallel/mpihelper.hh>
13#include <dune/grid/common/intersection.hh>
14#include <dune/grid/utility/multiindex.hh>
17#include <dune/mmesh/grid/implicitgridfactory.hh>
24 template<
class Gr
idImp,
class IntersectionImp >
30 template<
class Gr
id >
31 struct MMeshStructuredGridFactory
33 const static int dimworld = Grid::dimension;
34 typedef MPIHelper::MPICommunicator MPICommunicatorType;
35 typedef typename Grid::template Codim<0>::Entity Element;
36 typedef typename Grid::template Codim<dimworld>::Entity Vertex;
37 typedef typename Grid::FieldType FieldType;
38 typedef FieldVector< FieldType, dimworld > GlobalPosition;
42 template <
long unsigned int dim>
43 explicit MMeshStructuredGridFactory (
const GlobalPosition& lowerLeft,
44 const GlobalPosition& upperRight,
45 const std::array<unsigned int,dim>& elements,
46 MPICommunicatorType comm = MPIHelper::getCommunicator() )
48 grid_ = createStructuredGrid (lowerLeft, upperRight, elements);
52 const std::shared_ptr<Grid> grid()
const
58 template<
class Intersection >
59 bool wasInserted (
const Intersection &intersection )
const
61 return factory_.wasInserted( intersection );
65 template<
class Intersection >
66 int boundaryId (
const Intersection &intersection )
const
68 DUNE_THROW( NotImplemented,
"BoundaryId in structured grid factory" );
82 template <
long unsigned int dim>
83 static typename Grid::GridPtrType createStructuredGrid(
const GlobalPosition& lowerLeft,
84 const GlobalPosition& upperRight,
85 const std::array<unsigned int,dim>& elements)
91 std::array<unsigned int,dim> vertices = elements;
92 for(
size_t i = 0; i < vertices.size(); ++i )
95 FactoryUtilities::MultiIndex<dim> index(vertices);
98 int numVertices = index.cycle();
101 for (
int i=0; i<numVertices; i++, ++index)
104 GlobalPosition pos(0);
105 for (std::size_t j=0; j<dim; j++)
106 pos[j] = lowerLeft[j] + index[j] * (upperRight[j]-lowerLeft[j])/(vertices[j]-1);
107 for (std::size_t j=dim; j<dimworld; j++)
108 pos[j] = lowerLeft[j];
110 factory.insertVertex(pos);
114 return factory.createGrid();
119 std::shared_ptr<Grid> grid_;
120 GridFactory factory_;
specialization of the implicit GridFactory for MMesh
Definition: implicitgridfactory.hh:38