Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (unstable)

structuredgridfactory.hh
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
12#include <dune/common/parallel/mpihelper.hh>
13#include <dune/grid/common/intersection.hh>
14#include <dune/grid/utility/multiindex.hh>
15
16// MMesh includes
17#include <dune/mmesh/grid/implicitgridfactory.hh>
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>
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;
36 typedef Dune::MMeshImplicitGridFactory<Grid> GridFactory;
37
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);
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
84 FactoryUtilities::MultiIndex<dim> index(vertices);
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:
106 std::shared_ptr<Grid> grid_;
107 GridFactory factory_;
108};
109
110} // end namespace Dune
111
112#endif // #ifndef DUNE_MMESH_STRUCTURED_GRID_FACTORY_HH
specialization of the implicit GridFactory for MMesh
Definition: implicitgridfactory.hh:35
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 16, 23:47, 2025)