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;
47 typedef typename GridView::template Codim< dimGrid >::EntityPointer VertexPointer;
49 typedef typename ElementIterator :: Entity Element ;
50 typedef typename Element :: EntityPointer ElementPointer;
51 typedef typename Element :: EntitySeed ElementSeed ;
64 : gridView_( gridView )
74 void write ( std::ostream &gridout,
75 const std::vector< Index >& newElemOrder,
76 const std::stringstream& addParams = std::stringstream() )
const;
82 void write ( std::ostream &gridout )
const;
90 void write ( std::ostream &gridout,
91 const std::stringstream& addParams )
const;
97 void write (
const std::string &fileName )
const;
108 void writeAllElements(
const std::vector<ElementSeed>& elementSeeds,
111 const std::vector< Index >& vertexIndex,
112 std::ostream &gridout )
const
114 if( elementSeeds.size() > 0 )
117 typedef typename std::vector<ElementSeed> :: const_iterator iterator ;
118 const iterator end = elementSeeds.
end();
119 for( iterator it = elementSeeds.begin(); it != end ; ++ it )
122 const ElementPointer ep = gridView_.
grid().entityPointer( *it );
124 writeElement( *ep, indexSet, elementType, vertexIndex, gridout );
130 const ElementIterator end = gridView_.template end< 0 >();
131 for( ElementIterator it = gridView_.template begin< 0 >(); it != end; ++it )
134 writeElement( *it, indexSet, elementType, vertexIndex, gridout );
140 void writeElement(
const Element& element,
141 const IndexSet& indexSet,
142 const GeometryType& elementType,
143 const std::vector< Index >& vertexIndex,
144 std::ostream &gridout )
const
147 if( element.type() != elementType )
151 const size_t vxSize = element.template count< Element::dimension > ();
152 std::vector<Index> vertices(vxSize);
153 for(
size_t i = 0; i < vxSize; ++i )
154 vertices[ i ] = vertexIndex[ indexSet.subIndex( element, i,
dimGrid ) ];
156 gridout << vertices[ 0 ];
157 for(
size_t i = 1; i < vxSize; ++i )
158 gridout <<
" " << vertices[ i ];
159 gridout << std::endl;
166 write ( std::ostream &gridout,
167 const std::vector< Index >& newElemOrder,
168 const std::stringstream& addParams )
const
171 gridout.setf( std::ios_base::scientific, std::ios_base::floatfield );
172 gridout.precision( 16 );
174 const IndexSet &indexSet = gridView_.
indexSet();
177 std::vector< ElementSeed > elementSeeds;
180 const size_t orderSize = newElemOrder.
size() ;
181 if( orderSize == indexSet.size( 0 ) )
183 const ElementIterator end = gridView_.template end< 0 >();
184 ElementIterator it = gridView_.template begin< 0 >();
188 elementSeeds.resize( orderSize, (*it).seed() ) ;
189 size_t countElements = 0 ;
190 for( ; it != end; ++it, ++countElements )
192 const Element& element = *it ;
193 assert( newElemOrder[ indexSet.index( element ) ] < orderSize );
194 elementSeeds[ newElemOrder[ indexSet.index( element ) ] ] = element.seed();
199 if( countElements != orderSize )
205 gridout <<
"DGF" << std::endl;
207 const Index vxSize = indexSet.size( dimGrid );
208 std::vector< Index > vertexIndex( vxSize, vxSize );
210 gridout <<
"%" <<
" Elements = " << indexSet.size( 0 ) <<
" | Vertices = " << vxSize << std::endl;
213 gridout << std::endl <<
"VERTEX" << std::endl;
214 Index vertexCount = 0;
215 const ElementIterator end = gridView_.template end< 0 >();
216 for( ElementIterator it = gridView_.template begin< 0 >(); it != end; ++it )
218 const Element& element = *it ;
219 const int numCorners = element.template count< dimGrid > ();
220 for(
int i=0; i<numCorners; ++i )
222 const Index vxIndex = indexSet.subIndex( element, i, dimGrid );
223 assert( vxIndex < vxSize );
224 if( vertexIndex[ vxIndex ] == vxSize )
226 vertexIndex[ vxIndex ] = vertexCount++;
227 gridout << element.geometry().corner( i ) << std::endl;
231 gridout <<
"#" << std::endl;
232 if( vertexCount != vxSize )
241 if( indexSet.size( simplex ) > 0 )
244 gridout << std::endl <<
"SIMPLEX" << std::endl;
247 writeAllElements( elementSeeds, indexSet, simplex, vertexIndex, gridout );
250 gridout <<
"#" << std::endl;
259 if( indexSet.size( cube ) > 0 )
262 gridout << std::endl <<
"CUBE" << std::endl;
265 writeAllElements( elementSeeds, indexSet, cube, vertexIndex, gridout );
268 gridout <<
"#" << std::endl;
273#if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
274 gridout << std::endl <<
"BOUNDARYSEGMENTS" << std::endl;
275 for( ElementIterator it = gridView_.template begin< 0 >(); it != end; ++it )
277 const Element& element = *it ;
278 if( !it->hasBoundaryIntersections() )
281 const RefElement &refElement = RefElements::general( element.type() );
283 const IntersectionIterator iend = gridView_.
iend( element ) ;
284 for( IntersectionIterator iit = gridView_.
ibegin( element ); iit != iend; ++iit )
286 if( !iit->boundary() )
289 const int boundaryId = iit->boundaryId();
290 if( boundaryId <= 0 )
292 std::cerr <<
"Warning: Ignoring nonpositive boundary id: "
293 << boundaryId <<
"." << std::endl;
298 const unsigned int faceSize = refElement.
size( faceNumber, 1, dimGrid );
299 std::vector< Index > vertices( faceSize );
300 for(
unsigned int i = 0; i < faceSize; ++i )
302 const int j = refElement.
subEntity( faceNumber, 1, i, dimGrid );
303 vertices[ i ] = vertexIndex[ indexSet.subIndex( element, j, dimGrid ) ];
305 gridout << boundaryId <<
" " << vertices[ 0 ];
306 for(
unsigned int i = 1; i < faceSize; ++i )
307 gridout <<
" " << vertices[ i ];
308 gridout << std::endl;
311 gridout <<
"#" << std::endl << std::endl;
315 gridout << addParams.str() << std::endl;
317 gridout << std::endl <<
"#" << std::endl;
322 write ( std::ostream &gridout)
const
325 std::vector< Index > noNewOrdering ;
326 std::stringstream addParams;
327 write( gridout, noNewOrdering, addParams );
332 write ( std::ostream &gridout,
const std::stringstream& addParams )
const
335 std::vector< Index > noNewOrdering ;
336 write( gridout, noNewOrdering, addParams );
342 std::ofstream gridout( fileName.c_str() );
346 std::cerr <<
"Couldn't open file `"<< fileName <<
"'!"<< std::endl;
write a GridView to a DGF file
Definition: dgfwriter.hh:31
static const int dimGrid
dimension of the grid
Definition: dgfwriter.hh:41
DGFWriter(const GridView &gridView)
constructor
Definition: dgfwriter.hh:63
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:166
GV GridView
type of grid view
Definition: dgfwriter.hh:36
GridView::Grid Grid
type of underlying hierarchical grid
Definition: dgfwriter.hh:38
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:25
@ cube
Cube element in any nonnegative dimension.
Definition: type.hh:31
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:30
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Grid view abstract base class.
Definition: gridview.hh:57
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:158
Traits::Grid Grid
type of the grid
Definition: gridview.hh:67
const Grid & grid() const
obtain a const reference to the underlying hierarchic grid
Definition: gridview.hh:147
Codim< cd >::Iterator end() const
obtain end iterator for this view
Definition: gridview.hh:196
Traits::IntersectionIterator IntersectionIterator
type of the intersection iterator
Definition: gridview.hh:76
IntersectionIterator ibegin(const typename Codim< 0 > ::Entity &entity) const
obtain begin intersection iterator with respect to this view
Definition: gridview.hh:219
Traits::IndexSet IndexSet
type of the index set
Definition: gridview.hh:70
IntersectionIterator iend(const typename Codim< 0 > ::Entity &entity) const
obtain end intersection iterator with respect to this view
Definition: gridview.hh:226
@ dimension
The dimension of the grid.
Definition: gridview.hh:120
Index Set Interface base class.
Definition: indexidset.hh:78
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:204
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:85
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in.
Definition: intersection.hh:363
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:307
This class provides access to geometric and topological properties of a reference element....
Definition: referenceelements.hh:58
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:86
int subEntity(int i, int c, int ii, int cc) const
obtain number of ii-th subentity with codim cc of (i,c)
Definition: referenceelements.hh:122
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
Class providing access to the singletons of the reference elements. Special methods are available for...
Definition: referenceelements.hh:563