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>
23template <
class Gr
idImp,
class IntersectionImp>
29struct MMeshStructuredGridFactory {
30 const static int dimworld = Grid::dimension;
31 typedef MPIHelper::MPICommunicator MPICommunicatorType;
32 typedef typename Grid::template Codim<0>::Entity Element;
33 typedef typename Grid::template Codim<dimworld>::Entity Vertex;
34 typedef typename Grid::FieldType FieldType;
35 typedef FieldVector<FieldType, dimworld> GlobalPosition;
39 template <
long unsigned int dim>
40 explicit MMeshStructuredGridFactory(
41 const GlobalPosition& lowerLeft,
const GlobalPosition& upperRight,
42 const std::array<unsigned int, dim>& elements,
43 MPICommunicatorType comm = MPIHelper::getCommunicator()) {
44 grid_ = createStructuredGrid(lowerLeft, upperRight, elements);
48 const std::shared_ptr<Grid> grid()
const {
return grid_; }
51 template <
class Intersection>
52 bool wasInserted(
const Intersection& intersection)
const {
53 return factory_.wasInserted(intersection);
57 template <
class Intersection>
58 int boundaryId(
const Intersection& intersection)
const {
59 DUNE_THROW(NotImplemented,
"BoundaryId in structured grid factory");
73 template <
long unsigned int dim>
74 static typename Grid::GridPtrType createStructuredGrid(
75 const GlobalPosition& lowerLeft,
const GlobalPosition& upperRight,
76 const std::array<unsigned int, dim>& elements) {
81 std::array<unsigned int, dim> vertices = elements;
82 for (
size_t i = 0; i < vertices.size(); ++i) vertices[i]++;
84 FactoryUtilities::MultiIndex<dim> index(vertices);
87 int numVertices = index.cycle();
90 for (
int i = 0; i < numVertices; i++, ++index) {
92 GlobalPosition pos(0);
93 for (std::size_t j = 0; j < dim; j++)
94 pos[j] = lowerLeft[j] +
95 index[j] * (upperRight[j] - lowerLeft[j]) / (vertices[j] - 1);
96 for (std::size_t j = dim; j < dimworld; j++) pos[j] = lowerLeft[j];
98 factory.insertVertex(pos);
102 return factory.createGrid();
106 std::shared_ptr<Grid> grid_;
107 GridFactory factory_;
specialization of the implicit GridFactory for MMesh
Definition: implicitgridfactory.hh:35