dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
structuredgridfactory.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_MMESH_STRUCTURED_GRID_FACTORY_HH
4#define DUNE_MMESH_STRUCTURED_GRID_FACTORY_HH
5
6// System includes
7#include <memory>
8#include <utility>
9#include <vector>
10
11// Dune includes
13#include <dune/grid/common/intersection.hh>
15
16// MMesh includes
18
19namespace Dune {
20
21// External Forward Declarations
22// -----------------------------
23template <class GridImp, class IntersectionImp>
24class Intersection;
25
26// StructuredGridFactory for MMesh
27// -------------------------------
28template <class Grid>
30 const static int dimworld = Grid::dimension;
32 typedef typename Grid::template Codim<0>::Entity Element;
33 typedef typename Grid::template Codim<dimworld>::Entity Vertex;
34 typedef typename Grid::FieldType FieldType;
37
39 template <long unsigned int dim>
41 const GlobalPosition& lowerLeft, const GlobalPosition& upperRight,
42 const std::array<unsigned int, dim>& elements,
44 grid_ = createStructuredGrid(lowerLeft, upperRight, elements);
45 }
46
48 const std::shared_ptr<Grid> grid() const { return grid_; }
49
51 template <class Intersection>
52 bool wasInserted(const Intersection& intersection) const {
53 return factory_.wasInserted(intersection);
54 }
55
57 template <class Intersection>
58 int boundaryId(const Intersection& intersection) const {
59 DUNE_THROW(NotImplemented, "BoundaryId in structured grid factory");
60 }
61
62 public:
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) {
77 // The grid factory
78 GridFactory factory;
79
80 // Insert uniformly spaced vertices
81 std::array<unsigned int, dim> vertices = elements;
82 for (size_t i = 0; i < vertices.size(); ++i) vertices[i]++;
83
85
86 // Compute the total number of vertices to be created
87 int numVertices = index.cycle();
88
89 // Create vertices
90 for (int i = 0; i < numVertices; i++, ++index) {
91 // scale the multiindex to obtain a world position
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];
97
98 factory.insertVertex(pos);
99 }
100
101 // Create the grid and hand it to the calling method
102 return factory.createGrid();
103 }
104
105 private:
107 GridFactory factory_;
108};
109
110} // end namespace Dune
111
112#endif // #ifndef DUNE_MMESH_STRUCTURED_GRID_FACTORY_HH
size_type dim() const
std::ptrdiff_t index() const
#define DUNE_THROW(E,...)
MPI_Comm MPICommunicator
static MPICommunicator getCommunicator()
virtual bool wasInserted(const typename GridType::LeafIntersection &intersection) const
specialization of the implicit GridFactory for MMesh
Definition implicitgridfactory.hh:35
std::unique_ptr< Grid > createGrid()
finalize grid creation and hand over the grid
Definition implicitgridfactory.hh:258
void insertVertex(const WorldVector &pos)
Insert a vertex into the macro grid.
Definition implicitgridfactory.hh:183
Definition structuredgridfactory.hh:29
Grid::template Codim< 0 >::Entity Element
Definition structuredgridfactory.hh:32
FieldVector< FieldType, dimworld > GlobalPosition
Definition structuredgridfactory.hh:35
int boundaryId(const Intersection &intersection) const
return boundary id
Definition structuredgridfactory.hh:58
Dune::MMeshImplicitGridFactory< Grid > GridFactory
Definition structuredgridfactory.hh:36
Grid::template Codim< dimworld >::Entity Vertex
Definition structuredgridfactory.hh:33
MMeshStructuredGridFactory(const GlobalPosition &lowerLeft, const GlobalPosition &upperRight, const std::array< unsigned int, dim > &elements, MPICommunicatorType comm=MPIHelper::getCommunicator())
Constructor.
Definition structuredgridfactory.hh:40
static const int dimworld
Definition structuredgridfactory.hh:30
Grid::FieldType FieldType
Definition structuredgridfactory.hh:34
MPIHelper::MPICommunicator MPICommunicatorType
Definition structuredgridfactory.hh:31
bool wasInserted(const Intersection &intersection) const
returns if intersection was inserted
Definition structuredgridfactory.hh:52
const std::shared_ptr< Grid > grid() const
return grid pointer
Definition structuredgridfactory.hh:48
static Grid::GridPtrType createStructuredGrid(const GlobalPosition &lowerLeft, const GlobalPosition &upperRight, const std::array< unsigned int, dim > &elements)
Create a structured simplicial mmesh grid.
Definition structuredgridfactory.hh:74