3#ifndef DUNE_DGFWRITER_HH
4#define DUNE_DGFWRITER_HH
15#include <dune/geometry/referenceelements.hh>
48 typedef typename ElementIterator :: Entity Element ;
49 typedef typename Element :: EntitySeed ElementSeed ;
62 : gridView_( gridView )
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;
106 void writeAllElements(
const std::vector<ElementSeed>& elementSeeds,
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);
127 void writeElement(
const Element& element,
128 const IndexSet& indexSet,
129 const GeometryType& elementType,
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;
153 write ( std::ostream &gridout,
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 )
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 )
228 if( indexSet.size( simplex ) > 0 )
231 gridout << std::endl <<
"SIMPLEX" << std::endl;
234 writeAllElements( elementSeeds, indexSet, simplex, vertexIndex, gridout );
237 gridout <<
"#" << std::endl;
246 if( indexSet.size( cube ) > 0 )
249 gridout << std::endl <<
"CUBE" << std::endl;
252 writeAllElements( elementSeeds, indexSet, cube, vertexIndex, gridout );
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;
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;
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;
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:61
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
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:268
@ cube
Cube element in any nonnegative dimension.
Definition: type.hh:274
@ simplex
Simplicial element in any nonnegative dimension.
Definition: type.hh:273
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
Grid view abstract base class.
Definition: gridview.hh:60
Index Set Interface base class.
Definition: indexidset.hh:76
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:90
IndexType size(GeometryType type) const
Return total number of entities of given geometry type in entity set .
Definition: indexidset.hh:220
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in.
Definition: intersection.hh:374
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:279
This class provides access to geometric and topological properties of a reference element.
Definition: referenceelements.hh:355
int size(int c) const
number of subentities of codimension c
Definition: referenceelements.hh:382
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:418
Different resources needed by all grid implementations.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
const IndexSet & indexSet() const
obtain the index set
Definition: gridview.hh:173
Traits::Grid Grid
type of the grid
Definition: gridview.hh:78
const Grid & grid() const
obtain a const reference to the underlying hierarchic grid
Definition: gridview.hh:162
Traits::IntersectionIterator IntersectionIterator
type of the intersection iterator
Definition: gridview.hh:87
IntersectionIterator ibegin(const typename Codim< 0 > ::Entity &entity) const
obtain begin intersection iterator with respect to this view
Definition: gridview.hh:234
Traits::IndexSet IndexSet
type of the index set
Definition: gridview.hh:81
IntersectionIterator iend(const typename Codim< 0 > ::Entity &entity) const
obtain end intersection iterator with respect to this view
Definition: gridview.hh:241
@ dimension
The dimension of the grid.
Definition: gridview.hh:128
Dune namespace.
Definition: alignment.hh:11
Static tag representing a codimension.
Definition: dimension.hh:22
Class providing access to the singletons of the reference elements.
Definition: referenceelements.hh:753