dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
grid/dgfparser.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_GRID_DGFPARSER_HH
4#define DUNE_MMESH_GRID_DGFPARSER_HH
5
6// System includes
7#include <memory>
8#include <utility>
9#include <vector>
10
11// Dune includes
12#include <dune/grid/common/intersection.hh>
13#include <dune/grid/io/file/dgfparser/blocks/projection.hh>
14#include <dune/grid/io/file/dgfparser/dgfparser.hh>
16
17// MMesh includes
19
20namespace Dune {
21
22// External Forward Declarations
23// -----------------------------
24template <class GridImp, class IntersectionImp>
25class Intersection;
26
27// DGFGridFactory for MMesh
28// ------------------------
29template <class HostGrid, int dim>
30struct DGFGridFactory<MMesh<HostGrid, dim> > {
32 const static int dimension = Grid::dimension;
37
38 explicit DGFGridFactory(
39 std::istream &input,
41 explicit DGFGridFactory(
42 const std::string &filename,
44
46 Grid *grid() const { return grid_; }
47
49 template <class Intersection>
50 bool wasInserted(const Intersection &intersection) const {
51 return factory_.wasInserted(intersection);
52 }
53
55 template <class Intersection>
56 int boundaryId(const Intersection &intersection) const {
57 return intersection.impl().boundaryId();
58 }
59
62 if (numParameters<0>() <= 0) {
64 "Calling DGFGridFactory::parameter is only allowed if there "
65 "are parameters.");
66 }
67 return dgf_.elParams[factory_.insertionIndex(element)];
68 }
69
72 if (numParameters<dimension>() <= 0) {
74 "Calling DGFGridFactory::parameter is only allowed if there "
75 "are parameters.");
76 }
77 return dgf_.vtxParams[factory_.insertionIndex(vertex)];
78 }
79
81 bool haveBoundaryParameters() const { return dgf_.haveBndParameters; }
82
83 template <class GG, class II>
85 const Intersection<GG, II> &intersection) const {
87 }
88
89 template <int codim>
90 int numParameters() const {
91 return 0;
92 }
93
94 private:
95 bool generate(std::istream &input) {
96 dgf_.element = DuneGridFormatParser::Simplex;
97 dgf_.dimgrid = dimension;
98 dgf_.dimw = dimension;
99
100 if (!dgf_.readDuneGrid(input, dimension, dimension)) return false;
101
102 // Insert vertices
103 for (int n = 0; n < dgf_.nofvtx; ++n) {
104 typename GridFactory::WorldVector coord;
105 for (std::size_t i = 0; i < dimension; ++i) coord[i] = dgf_.vtx[n][i];
106 factory_.insertVertex(coord);
107 }
108
109 // Insert elements
110 for (int n = 0; n < dgf_.nofelements; ++n)
111 factory_.insertElement(GeometryTypes::simplex(dimension),
112 dgf_.elements[n]);
113
114 // Insert boundary segments and ids
115 for (const auto &face : dgf_.facemap) {
116 const auto &entityKey = face.first;
117 const std::size_t boundaryId = face.second.first;
118
120 for (int i = 0; i < entityKey.size(); ++i)
121 vertices.push_back(entityKey[i]);
122
123 std::sort(vertices.begin(), vertices.end());
124
125 // insert boundary segment
126 factory_.insertBoundarySegment(vertices);
127
128 // insert boundary id
129 std::size_t index = factory_.boundarySegments().size() - 1;
130 factory_.addBoundaryId(index, boundaryId);
131 }
132
133 grid_ = factory_.createGrid().release();
134 return true;
135 }
136
137 Grid *grid_;
138 GridFactory factory_;
139 DuneGridFormatParser dgf_;
140};
141
142// DGFGridInfo for MMesh
143// ---------------------
144
145template <class HostGrid, int dim>
146struct DGFGridInfo<MMesh<HostGrid, dim> > {
147 static int refineStepsForHalf() { return 2; }
148
149 static double refineWeight() { return -1; }
150};
151
152// Implementation of DGFGridFactory for MMesh
153// ------------------------------------------
154
156template <class HostGrid, int dim>
157inline DGFGridFactory<MMesh<HostGrid, dim> >::DGFGridFactory(
159 : dgf_(0, 1) {
160 input.clear();
161 input.seekg(0);
162 if (!input) DUNE_THROW(DGFException, "Error resetting input stream.");
163 generate(input);
164}
165
167template <class HostGrid, int dim>
168inline DGFGridFactory<MMesh<HostGrid, dim> >::DGFGridFactory(
169 const std::string &filename, MPICommunicatorType comm)
170 : dgf_(0, 1) {
171 std::ifstream input(filename.c_str());
172 if (!input)
173 DUNE_THROW(DGFException, "Macrofile " << filename << " not found.");
174 if (!generate(input))
176 "Could not generate MMesh from macrofile " << filename);
177 input.close();
178}
179
180} // namespace Dune
181
182#endif
size_type dim() const
std::ptrdiff_t index() const
#define DUNE_THROW(E,...)
MPI_Comm MPICommunicator
static MPICommunicator getCommunicator()
int boundaryId(const Intersection &intersection) const
static const int dimension
Implementation & impl()
The MMesh class templatized by the CGAL host grid type and the dimension. .
Definition grid/mmesh.hh:158
typename HostGridEntityChooser_< HostGridType, dimension, cd >::type HostGridEntity
The type of the underlying entities.
Definition grid/mmesh.hh:209
std::vector< double > & parameter(const Element &element)
Returns dgf element parameters for given element.
Definition grid/dgfparser.hh:61
Grid * grid() const
return grid pointer
Definition grid/dgfparser.hh:46
bool haveBoundaryParameters() const
Returns true if boundary parameters found.
Definition grid/dgfparser.hh:81
Dune::MMeshExplicitGridFactory< Grid > GridFactory
Definition grid/dgfparser.hh:36
int boundaryId(const Intersection &intersection) const
Return boundary id of intersection.
Definition grid/dgfparser.hh:56
std::vector< double > & parameter(const Vertex &vertex)
Returns dgf vertex parameters for given vertex.
Definition grid/dgfparser.hh:71
Grid::template Codim< dimension >::Entity Vertex
Definition grid/dgfparser.hh:35
bool wasInserted(const Intersection &intersection) const
Returns if intersection was inserted.
Definition grid/dgfparser.hh:50
const DGFBoundaryParameter::type boundaryParameter(const Intersection< GG, II > &intersection) const
Definition grid/dgfparser.hh:84
MMesh< HostGrid, dim > Grid
Definition grid/dgfparser.hh:31
MPIHelper::MPICommunicator MPICommunicatorType
Definition grid/dgfparser.hh:33
int numParameters() const
Definition grid/dgfparser.hh:90
Grid::template Codim< 0 >::Entity Element
Definition grid/dgfparser.hh:34
static int refineStepsForHalf()
Definition grid/dgfparser.hh:147
static double refineWeight()
Definition grid/dgfparser.hh:149
specialization of the explicit GridFactory for MMesh
Definition explicitgridfactory.hh:32
T c_str(T... args)
T clear(T... args)
T close(T... args)
T seekg(T... args)
T sort(T... args)