Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

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
22 // External Forward Declarations
23 // -----------------------------
24 template< class GridImp, class IntersectionImp >
25 class Intersection;
26
27
28 // StructuredGridFactory for MMesh
29 // -------------------------------
30 template< class Grid >
31 struct MMeshStructuredGridFactory
32 {
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;
39 typedef Dune::MMeshImplicitGridFactory<Grid> GridFactory;
40
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() )
47 {
48 grid_ = createStructuredGrid (lowerLeft, upperRight, elements);
49 }
50
52 const std::shared_ptr<Grid> grid() const
53 {
54 return grid_;
55 }
56
58 template< class Intersection >
59 bool wasInserted ( const Intersection &intersection ) const
60 {
61 return factory_.wasInserted( intersection );
62 }
63
65 template< class Intersection >
66 int boundaryId ( const Intersection &intersection ) const
67 {
68 DUNE_THROW( NotImplemented, "BoundaryId in structured grid factory" );
69 }
70
71public:
72
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)
86 {
87 // The grid factory
88 GridFactory factory;
89
90 // Insert uniformly spaced vertices
91 std::array<unsigned int,dim> vertices = elements;
92 for( size_t i = 0; i < vertices.size(); ++i )
93 vertices[i]++;
94
95 FactoryUtilities::MultiIndex<dim> index(vertices);
96
97 // Compute the total number of vertices to be created
98 int numVertices = index.cycle();
99
100 // Create vertices
101 for (int i=0; i<numVertices; i++, ++index)
102 {
103 // scale the multiindex to obtain a world position
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];
109
110 factory.insertVertex(pos);
111 }
112
113 // Create the grid and hand it to the calling method
114 return factory.createGrid();
115
116 }
117
118private:
119 std::shared_ptr<Grid> grid_;
120 GridFactory factory_;
121 };
122
123} // end namespace Dune
124
125#endif // #ifndef DUNE_MMESH_STRUCTURED_GRID_FACTORY_HH
specialization of the implicit GridFactory for MMesh
Definition: implicitgridfactory.hh:38
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 6, 22:49, 2025)