3 #ifndef DUNE_GRID_FILE_IO_DGFPARSER_DGFONED_HH
4 #define DUNE_GRID_FILE_IO_DGFPARSER_DGFONED_HH
14 #include <dune/common/exceptions.hh>
21 #include "dgfparser.hh"
27 double getfirst ( std::vector< double > v )
76 generate( input, comm );
85 std::ifstream input( filename.c_str() );
86 generate( input, comm );
96 template<
class GG,
class II >
102 template<
class GG,
class II >
111 template<
class Entity >
118 template<
int codim >
124 template<
class Entity >
127 return parameter< Entity::codimension >( entity );
131 template<
int codim >
134 return emptyParameters_;
144 template<
class GG,
class II >
155 std::vector< double > emptyParameters_;
163 inline void DGFGridFactory< OneDGrid >::generate ( std::istream &input, MPICommunicatorType comm )
166 dgf::IntervalBlock intervalBlock( input );
170 dgf::VertexBlock vertexBlock( input, dimensionworld );
173 if( !( vertexBlock.isactive() || intervalBlock.isactive() ))
174 DUNE_THROW( DGFException,
"No readable block found" );
176 std::vector< std::vector< double > > vertices;
179 if( vertexBlock.isactive() )
182 std::vector< std::vector< double > >
parameter;
183 vertexBlock.get( vertices, parameter, nparameter );
186 std::cerr <<
"Warning: vertex parameters will be ignored" << std::endl;
190 if ( intervalBlock.isactive() )
192 if( intervalBlock.dimw() != dimensionworld )
194 DUNE_THROW( DGFException,
"Error: wrong coordinate dimension in interval block \
195 (got " << intervalBlock.dimw() <<
", expected " << dimensionworld <<
")" );
198 int nintervals = intervalBlock.numIntervals();
199 for(
int i = 0; i < nintervals; ++i )
200 intervalBlock.getVtx( i, vertices );
204 std::vector< double > vtx( vertices.size() );
205 transform( vertices.begin(), vertices.end(), vtx.begin(), getfirst );
208 std::sort( vtx.begin(), vtx.end() );
209 std::vector< double >::iterator it = std::unique( vtx.begin(), vtx.end() );
210 vtx.erase( it, vtx.end() );
211 if( vertices.size() != vtx.size() )
212 std::cerr <<
"Warning: removed duplicate vertices" << std::endl;
215 grid_ =
new OneDGrid( vtx );
220 #endif // #ifndef DUNE_GRID_FILE_IO_DGFPARSER_DGFONED_HH