1 #ifndef DUNE_GRID_FILE_IO_DGFPARSER_DGFONED_HH
2 #define DUNE_GRID_FILE_IO_DGFPARSER_DGFONED_HH
12 #include <dune/common/exceptions.hh>
25 double getfirst ( std::vector< double > v )
74 generate( input, comm );
83 std::ifstream input( filename.c_str() );
84 generate( input, comm );
94 template <
class GG,
template<
class >
class II >
100 template <
class GG,
template<
class >
class II >
109 template<
class Entity >
116 template<
int codim >
122 template<
class Entity >
125 return parameter< Entity::codimension >( entity );
129 template<
int codim >
132 return emptyParameters_;
142 template <
class GG,
template<
class >
class II >
153 std::vector< double > emptyParameters_;
161 inline void DGFGridFactory< OneDGrid >::generate ( std::istream &input, MPICommunicatorType comm )
164 dgf::IntervalBlock intervalBlock( input );
168 dgf::VertexBlock vertexBlock( input, dimensionworld );
171 if( !( vertexBlock.isactive() || intervalBlock.isactive() ))
172 DUNE_THROW( DGFException,
"No readable block found" );
174 std::vector< std::vector< double > > vertices;
177 if( vertexBlock.isactive() )
180 std::vector< std::vector< double > >
parameter;
181 vertexBlock.get( vertices, parameter, nparameter );
184 std::cerr <<
"Warning: vertex parameters will be ignored" << std::endl;
188 if ( intervalBlock.isactive() )
190 if( intervalBlock.dimw() != dimensionworld )
192 DUNE_THROW( DGFException,
"Error: wrong coordinate dimension in interval block \
193 (got " << intervalBlock.dimw() <<
", expected " << dimensionworld <<
")" );
196 int nintervals = intervalBlock.numIntervals();
197 for(
int i = 0; i < nintervals; ++i )
198 intervalBlock.getVtx( i, vertices );
202 std::vector< double > vtx( vertices.size() );
203 transform( vertices.begin(), vertices.end(), vtx.begin(), getfirst );
206 std::sort( vtx.begin(), vtx.end() );
207 std::vector< double >::iterator it = std::unique( vtx.begin(), vtx.end() );
208 vtx.erase( it, vtx.end() );
209 if( vertices.size() != vtx.size() )
210 std::cerr <<
"Warning: removed duplicate vertices" << std::endl;
213 grid_ =
new OneDGrid( vtx );
218 #endif // #ifndef DUNE_GRID_FILE_IO_DGFPARSER_DGFONED_HH