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>
25 template<
class Gr
idImp,
class IntersectionImp >
30 template<
class HostGr
id,
int dim >
31 struct DGFGridFactory< MMesh<HostGrid, dim> >
33 typedef MMesh<HostGrid, dim> Grid;
34 const static int dimension = Grid::dimension;
35 typedef MPIHelper::MPICommunicator MPICommunicatorType;
36 typedef typename Grid::template Codim<0>::Entity Element;
37 typedef typename Grid::template Codim<dimension>::Entity Vertex;
40 explicit DGFGridFactory ( std::istream &input,
41 MPICommunicatorType comm = MPIHelper::getCommunicator() );
42 explicit DGFGridFactory (
const std::string &filename,
43 MPICommunicatorType comm = MPIHelper::getCommunicator() );
52 template<
class Intersection >
53 bool wasInserted (
const Intersection &intersection )
const
55 return factory_.wasInserted( intersection );
59 template<
class Intersection >
60 int boundaryId (
const Intersection &intersection )
const
62 return intersection.impl().boundaryId();
66 std::vector< double > ¶meter (
const Element &element )
68 if( numParameters< 0 >() <= 0 )
70 DUNE_THROW( InvalidStateException,
71 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
73 return dgf_.elParams[ factory_.insertionIndex( element ) ];
77 std::vector< double > ¶meter (
const Vertex &vertex )
79 if( numParameters< dimension >() <= 0 )
81 DUNE_THROW( InvalidStateException,
82 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
84 return dgf_.vtxParams[ factory_.insertionIndex( vertex ) ];
88 bool haveBoundaryParameters ()
const
90 return dgf_.haveBndParameters;
93 template <
class GG,
class II >
94 const DGFBoundaryParameter::type
95 boundaryParameter (
const Intersection< GG, II > & intersection )
const {
return DGFBoundaryParameter::type(); }
98 int numParameters ()
const {
return 0; }
101 bool generate( std::istream &input )
103 dgf_.element = DuneGridFormatParser::Simplex;
104 dgf_.dimgrid = dimension;
105 dgf_.dimw = dimension;
107 if( !dgf_.readDuneGrid( input, dimension, dimension ) )
111 for(
int n = 0; n < dgf_.nofvtx; ++n )
113 typename GridFactory::WorldVector coord;
114 for( std::size_t i = 0; i < dimension; ++i )
115 coord[ i ] = dgf_.vtx[ n ][ i ];
116 factory_.insertVertex( coord );
120 for(
int n = 0; n < dgf_.nofelements; ++n )
121 factory_.insertElement( GeometryTypes::simplex(dimension), dgf_.elements[ n ] );
124 for(
const auto& face : dgf_.facemap )
126 const auto& entityKey = face.first;
127 const std::size_t boundaryId = face.second.first;
129 std::vector< unsigned int > vertices;
130 for(
int i = 0; i < entityKey.size(); ++i )
131 vertices.push_back( entityKey[i] );
133 std::sort( vertices.begin(), vertices.end() );
136 factory_.insertBoundarySegment( vertices );
139 std::size_t index = factory_.boundarySegments().size()-1;
140 factory_.addBoundaryId( index, boundaryId );
143 grid_ = factory_.createGrid().release();
148 GridFactory factory_;
149 DuneGridFormatParser dgf_;
156 template<
class HostGr
id,
int dim >
157 struct DGFGridInfo< MMesh<HostGrid, dim> >
159 static int refineStepsForHalf ()
164 static double refineWeight ()
175 template<
class HostGr
id,
int dim >
176 inline DGFGridFactory< MMesh<HostGrid, dim> >
177 ::DGFGridFactory ( std::istream &input, MPICommunicatorType comm )
183 DUNE_THROW(DGFException,
"Error resetting input stream." );
188 template<
class HostGr
id,
int dim >
189 inline DGFGridFactory< MMesh<HostGrid, dim> >
190 ::DGFGridFactory (
const std::string &filename, MPICommunicatorType comm )
193 std::ifstream input( filename.c_str() );
195 DUNE_THROW( DGFException,
"Macrofile " << filename <<
" not found." );
196 if( !generate( input ) )
197 DUNE_THROW( DGFException,
"Could not generate MMesh from macrofile " << filename );
specialization of the explicit GridFactory for MMesh
Definition: explicitgridfactory.hh:35