5#ifndef DUNE_GRID_FILE_IO_DGFPARSER_DGFONED_HH
6#define DUNE_GRID_FILE_IO_DGFPARSER_DGFONED_HH
19#include <dune/grid/common/intersection.hh>
23#include "dgfparser.hh"
29 double getfirst ( std::vector< double > v )
44 struct DGFGridInfo< OneDGrid >
63 struct DGFGridFactory< OneDGrid >
66 typedef OneDGrid Grid;
73 explicit DGFGridFactory ( std::istream &input,
78 generate( input, comm );
82 explicit DGFGridFactory (
const std::string &filename,
87 std::ifstream input( filename.c_str() );
88 generate( input, comm );
98 template<
class GG,
class II >
104 template<
class GG,
class II >
113 template<
class Entity >
114 int numParameters (
const Entity & )
const
120 template<
int codim >
121 int numParameters ()
const
126 template<
class Entity >
127 std::vector< double >& parameter (
const Entity &entity )
129 return parameter< Entity::codimension >( entity );
133 template<
int codim >
136 return emptyParameters_;
140 bool haveBoundaryParameters ()
const
146 template<
class GG,
class II >
154 void generate ( std::istream &input, MPICommunicatorType comm );
157 std::vector< double > emptyParameters_;
165 inline void DGFGridFactory< OneDGrid >::generate ( std::istream &input, [[maybe_unused]] MPICommunicatorType comm )
168 dgf::IntervalBlock intervalBlock( input );
172 dgf::VertexBlock vertexBlock( input, dimensionworld );
175 if( !( vertexBlock.isactive() || intervalBlock.isactive() ))
176 DUNE_THROW( DGFException,
"No readable block found" );
178 std::vector< std::vector< double > > vertices;
181 if( vertexBlock.isactive() )
184 std::vector< std::vector< double > > parameter;
185 vertexBlock.get( vertices, parameter, nparameter );
188 std::cerr <<
"Warning: vertex parameters will be ignored" << std::endl;
192 if ( intervalBlock.isactive() )
194 if( intervalBlock.dimw() != dimensionworld )
196 DUNE_THROW( DGFException,
"Error: wrong coordinate dimension in interval block \
197 (got " << intervalBlock.dimw() <<
", expected " << dimensionworld <<
")" );
200 int nintervals = intervalBlock.numIntervals();
201 for(
int i = 0; i < nintervals; ++i )
202 intervalBlock.getVtx( i, vertices );
206 std::vector< double > vtx( vertices.size() );
207 transform( vertices.begin(), vertices.end(), vtx.begin(), getfirst );
210 std::sort( vtx.begin(), vtx.end() );
211 std::vector< double >::iterator it = std::unique( vtx.begin(), vtx.end() );
212 vtx.erase( it, vtx.end() );
213 if( vertices.size() != vtx.size() )
214 std::cerr <<
"Warning: removed duplicate vertices" << std::endl;
217 grid_ =
new OneDGrid( vtx );
static constexpr int dimension
The dimension of the grid.
Definition: grid.hh:387
static constexpr int dimensionworld
The dimension of the world the grid lives in.
Definition: grid.hh:390
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: intersection.hh:164
size_t boundarySegmentIndex() const
index of the boundary segment within the macro grid
Definition: intersection.hh:236
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:192
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:200
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
static const type & defaultValue()
default constructor
Definition: parser.hh:28
std::string type
type of additional boundary parameters
Definition: parser.hh:25
static double refineWeight()
static int refineStepsForHalf()
number of globalRefine steps needed to refuce h by 0.5
GridFamily::Traits::template Codim< cd >::Entity Entity
A type that is a model of a Dune::Entity<cd,dim,...>.
Definition: grid.hh:419