3#ifndef DUNE_MMESH_GRID_DGFPARSER_HH
4#define DUNE_MMESH_GRID_DGFPARSER_HH
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>
15#include <dune/grid/io/file/dgfparser/parser.hh>
18#include <dune/mmesh/grid/explicitgridfactory.hh>
24template <
class Gr
idImp,
class IntersectionImp>
29template <
class HostGr
id,
int dim>
30struct DGFGridFactory<MMesh<HostGrid, dim> > {
31 typedef MMesh<HostGrid, dim> Grid;
32 const static int dimension = Grid::dimension;
33 typedef MPIHelper::MPICommunicator MPICommunicatorType;
34 typedef typename Grid::template Codim<0>::Entity Element;
35 typedef typename Grid::template Codim<dimension>::Entity Vertex;
38 explicit DGFGridFactory(
40 MPICommunicatorType comm = MPIHelper::getCommunicator());
41 explicit DGFGridFactory(
42 const std::string &filename,
43 MPICommunicatorType comm = MPIHelper::getCommunicator());
46 Grid *grid()
const {
return grid_; }
49 template <
class Intersection>
50 bool wasInserted(
const Intersection &intersection)
const {
51 return factory_.wasInserted(intersection);
55 template <
class Intersection>
56 int boundaryId(
const Intersection &intersection)
const {
57 return intersection.impl().boundaryId();
61 std::vector<double> ¶meter(
const Element &element) {
62 if (numParameters<0>() <= 0) {
63 DUNE_THROW(InvalidStateException,
64 "Calling DGFGridFactory::parameter is only allowed if there "
67 return dgf_.elParams[factory_.insertionIndex(element)];
71 std::vector<double> ¶meter(
const Vertex &vertex) {
72 if (numParameters<dimension>() <= 0) {
73 DUNE_THROW(InvalidStateException,
74 "Calling DGFGridFactory::parameter is only allowed if there "
77 return dgf_.vtxParams[factory_.insertionIndex(vertex)];
81 bool haveBoundaryParameters()
const {
return dgf_.haveBndParameters; }
83 template <
class GG,
class II>
84 const DGFBoundaryParameter::type boundaryParameter(
85 const Intersection<GG, II> &intersection)
const {
86 return DGFBoundaryParameter::type();
90 int numParameters()
const {
95 bool generate(std::istream &input) {
96 dgf_.element = DuneGridFormatParser::Simplex;
97 dgf_.dimgrid = dimension;
98 dgf_.dimw = dimension;
100 if (!dgf_.readDuneGrid(input, dimension, dimension))
return false;
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);
110 for (
int n = 0; n < dgf_.nofelements; ++n)
111 factory_.insertElement(GeometryTypes::simplex(dimension),
115 for (
const auto &face : dgf_.facemap) {
116 const auto &entityKey = face.first;
117 const std::size_t boundaryId = face.second.first;
119 std::vector<unsigned int> vertices;
120 for (
int i = 0; i < entityKey.size(); ++i)
121 vertices.push_back(entityKey[i]);
123 std::sort(vertices.begin(), vertices.end());
126 factory_.insertBoundarySegment(vertices);
129 std::size_t index = factory_.boundarySegments().size() - 1;
130 factory_.addBoundaryId(index, boundaryId);
133 grid_ = factory_.createGrid().release();
138 GridFactory factory_;
139 DuneGridFormatParser dgf_;
145template <
class HostGr
id,
int dim>
146struct DGFGridInfo<MMesh<HostGrid, dim> > {
147 static int refineStepsForHalf() {
return 2; }
149 static double refineWeight() {
return -1; }
156template <
class HostGr
id,
int dim>
157inline DGFGridFactory<MMesh<HostGrid, dim> >::DGFGridFactory(
158 std::istream &input, MPICommunicatorType comm)
162 if (!input) DUNE_THROW(DGFException,
"Error resetting input stream.");
167template <
class HostGr
id,
int dim>
168inline DGFGridFactory<MMesh<HostGrid, dim> >::DGFGridFactory(
169 const std::string &filename, MPICommunicatorType comm)
171 std::ifstream input(filename.c_str());
173 DUNE_THROW(DGFException,
"Macrofile " << filename <<
" not found.");
174 if (!generate(input))
175 DUNE_THROW(DGFException,
176 "Could not generate MMesh from macrofile " << filename);
specialization of the explicit GridFactory for MMesh
Definition: explicitgridfactory.hh:32