3 #ifndef DUNE_DGFWRITER_HH 4 #define DUNE_DGFWRITER_HH 15 #include <dune/geometry/referenceelements.hh> 45 typedef typename GridView::template Codim< 0 >::Iterator ElementIterator;
48 typedef typename ElementIterator :: Entity Element ;
49 typedef typename Element :: EntitySeed ElementSeed ;
53 typedef ReferenceElement< typename Grid::ctype, dimGrid > RefElement;
54 typedef ReferenceElements< typename Grid::ctype, dimGrid > RefElements;
72 void write ( std::ostream &gridout,
73 const std::vector< Index >& newElemOrder,
74 const std::stringstream& addParams = std::stringstream() )
const;
80 void write ( std::ostream &gridout )
const;
88 void write ( std::ostream &gridout,
89 const std::stringstream& addParams )
const;
95 void write (
const std::string &fileName )
const;
107 const IndexSet& indexSet,
109 const std::vector< Index >& vertexIndex,
110 std::ostream &gridout )
const 112 if (!elementSeeds.empty()) {
114 for (
const auto& seed : elementSeeds) {
115 const Element element = gridView_.grid().entity(seed);
116 writeElement(element, indexSet, elementType, vertexIndex, gridout);
121 for (
const auto& element : elements(gridView_))
122 writeElement(element, indexSet, elementType, vertexIndex, gridout);
128 const IndexSet& indexSet,
130 const std::vector< Index >& vertexIndex,
131 std::ostream &gridout )
const 134 if( element.type() != elementType )
138 const size_t vxSize = element.subEntities( Element::dimension );
139 std::vector<Index> vertices(vxSize);
140 for(
size_t i = 0; i < vxSize; ++i )
141 vertices[ i ] = vertexIndex[ indexSet.subIndex( element, i, dimGrid ) ];
143 gridout << vertices[ 0 ];
144 for(
size_t i = 1; i < vxSize; ++i )
145 gridout <<
" " << vertices[ i ];
146 gridout << std::endl;
154 const std::vector< Index >& newElemOrder,
155 const std::stringstream& addParams )
const 158 gridout.setf( std::ios_base::scientific, std::ios_base::floatfield );
159 gridout.precision( 16 );
161 const IndexSet &indexSet =
gridView_.indexSet();
164 std::vector< ElementSeed > elementSeeds;
167 const size_t orderSize = newElemOrder.size() ;
168 if( orderSize == indexSet.size( 0 ) )
170 const ElementIterator end =
gridView_.template end< 0 >();
171 ElementIterator it =
gridView_.template begin< 0 >();
175 elementSeeds.resize( orderSize, (*it).seed() ) ;
176 size_t countElements = 0 ;
177 for( ; it != end; ++it, ++countElements )
179 const Element& element = *it ;
180 assert( newElemOrder[ indexSet.index( element ) ] < orderSize );
181 elementSeeds[ newElemOrder[ indexSet.index( element ) ] ] = element.seed();
186 if( countElements != orderSize )
187 DUNE_THROW(InvalidStateException,
"DGFWriter::write: IndexSet not consecutive");
192 gridout <<
"DGF" << std::endl;
194 const Index vxSize = indexSet.size(
dimGrid );
195 std::vector< Index > vertexIndex( vxSize, vxSize );
197 gridout <<
"%" <<
" Elements = " << indexSet.size( 0 ) <<
" | Vertices = " << vxSize << std::endl;
200 gridout << std::endl <<
"VERTEX" << std::endl;
201 Index vertexCount = 0;
202 const ElementIterator end =
gridView_.template end< 0 >();
203 for( ElementIterator it =
gridView_.template begin< 0 >(); it != end; ++it )
205 const Element& element = *it ;
206 const int numCorners = element.subEntities(
dimGrid );
207 for(
int i=0; i<numCorners; ++i )
209 const Index vxIndex = indexSet.subIndex( element, i,
dimGrid );
210 assert( vxIndex < vxSize );
211 if( vertexIndex[ vxIndex ] == vxSize )
213 vertexIndex[ vxIndex ] = vertexCount++;
214 gridout << element.geometry().corner( i ) << std::endl;
218 gridout <<
"#" << std::endl;
219 if( vertexCount != vxSize )
220 DUNE_THROW(
GridError,
"Index set reports wrong number of vertices." );
228 if( indexSet.size( simplex ) > 0 )
231 gridout << std::endl <<
"SIMPLEX" << std::endl;
237 gridout <<
"#" << std::endl;
246 if( indexSet.size( cube ) > 0 )
249 gridout << std::endl <<
"CUBE" << std::endl;
255 gridout <<
"#" << std::endl;
260 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS 261 gridout << std::endl <<
"BOUNDARYSEGMENTS" << std::endl;
262 for( ElementIterator it =
gridView_.template begin< 0 >(); it != end; ++it )
264 const Element& element = *it ;
265 if( !it->hasBoundaryIntersections() )
268 const RefElement &refElement = RefElements::general( element.type() );
270 const IntersectionIterator iend =
gridView_.iend( element ) ;
271 for( IntersectionIterator iit =
gridView_.ibegin( element ); iit != iend; ++iit )
273 if( !iit->boundary() )
276 const int boundaryId = iit->boundaryId();
277 if( boundaryId <= 0 )
279 std::cerr <<
"Warning: Ignoring nonpositive boundary id: " 280 << boundaryId <<
"." << std::endl;
284 const int faceNumber = iit->indexInInside();
285 const unsigned int faceSize = refElement.size( faceNumber, 1,
dimGrid );
286 std::vector< Index > vertices( faceSize );
287 for(
unsigned int i = 0; i < faceSize; ++i )
289 const int j = refElement.subEntity( faceNumber, 1, i,
dimGrid );
290 vertices[ i ] = vertexIndex[ indexSet.subIndex( element, j,
dimGrid ) ];
292 gridout << boundaryId <<
" " << vertices[ 0 ];
293 for(
unsigned int i = 1; i < faceSize; ++i )
294 gridout <<
" " << vertices[ i ];
295 gridout << std::endl;
298 gridout <<
"#" << std::endl << std::endl;
299 #endif // #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS 302 gridout << addParams.str() << std::endl;
304 gridout << std::endl <<
"#" << std::endl;
309 write ( std::ostream &gridout)
const 312 std::vector< Index > noNewOrdering ;
313 std::stringstream addParams;
314 write( gridout, noNewOrdering, addParams );
319 write ( std::ostream &gridout,
const std::stringstream& addParams )
const 322 std::vector< Index > noNewOrdering ;
323 write( gridout, noNewOrdering, addParams );
329 std::ofstream gridout( fileName.c_str() );
333 std::cerr <<
"Couldn't open file `"<< fileName <<
"'!"<< std::endl;
338 #endif // #ifndef DUNE_DGFWRITER_HH Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
GridView gridView_
Definition: dgfwriter.hh:98
DGFWriter(const GridView &gridView)
constructor
Definition: dgfwriter.hh:61
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:178
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90
Traits ::IntersectionIterator IntersectionIterator
type of the intersection iterator
Definition: common/gridview.hh:87
GV GridView
type of grid view
Definition: dgfwriter.hh:36
static const int dimGrid
dimension of the grid
Definition: dgfwriter.hh:41
void write(std::ostream &gridout, const std::vector< Index > &newElemOrder, const std::stringstream &addParams=std::stringstream()) const
write the GridView into a std::ostream
Definition: dgfwriter.hh:153
void writeAllElements(const std::vector< ElementSeed > &elementSeeds, const IndexSet &indexSet, const GeometryType &elementType, const std::vector< Index > &vertexIndex, std::ostream &gridout) const
Definition: dgfwriter.hh:106
Include standard header files.
Definition: agrid.hh:59
void writeElement(const Element &element, const IndexSet &indexSet, const GeometryType &elementType, const std::vector< Index > &vertexIndex, std::ostream &gridout) const
Definition: dgfwriter.hh:127
The dimension of the grid.
Definition: common/gridview.hh:128
Traits ::Grid Grid
type of the grid
Definition: common/gridview.hh:78
write a GridView to a DGF file
Definition: dgfwriter.hh:30
Traits ::IndexSet IndexSet
type of the index set
Definition: common/gridview.hh:81
GridView::Grid Grid
type of underlying hierarchical grid
Definition: dgfwriter.hh:38
Different resources needed by all grid implementations.