1 #include <config.h>
2 
3 // iostream includes
4 #include <iostream>
5 #include <fstream>
6 #include<vector>
7 
8 #include <dune/common/mpihelper.hh>
9 
10 #include <dune/grid/io/file/dgfparser/dgfyasp.hh>
11 #include <dune/grid/yaspgrid.hh>
12 
13 #include <dune/grid/parallelgrid/sfciterator.hh>
14 
15 // print space filling curve
16 template <class HGridType>
printCurve(HGridType & grid,std::ostream & out)17 void printCurve( HGridType &grid, std::ostream& out )
18 {
19   typedef typename HGridType :: LeafGridView LeafView ;
20   typedef typename HGridType :: template Codim< 0 > :: Geometry Geometry;
21 
22   int count = 0;
23   Dune :: SpaceFillingCurveIterator< LeafView > it( grid.leafGridView() );
24   for( it.first(); !it.done(); it.next(), ++count )
25   {
26     const Geometry& geo = it.item().geometry();
27     out << geo.center() << std::endl;
28   }
29   if( count != grid.size( 0 ) )
30     DUNE_THROW( Dune :: InvalidStateException, "SFC iterator worng" );
31 }
32 
33 // print space filling curve
34 template <class HGridType>
printGrid(HGridType & grid,std::ostream & out)35 void printGrid( HGridType &grid, std::ostream& out )
36 {
37   typedef typename HGridType :: LeafGridView LeafView ;
38   typedef typename HGridType :: template Codim< 0 > :: Geometry Geometry;
39   Dune :: SpaceFillingCurveIterator< LeafView > it( grid.leafGridView() );
40   for( it.first(); !it.done(); it.next() )
41   {
42     const Geometry& geo = it.item().geometry();
43 
44     const int corners = geo.corners();
45     for( int i=0; i<corners; ++i )
46       out << geo.corner( i ) << std::endl;
47   }
48 }
49 
50 
51 // main
52 // ----
53 
main(int argc,char ** argv)54 int main ( int argc, char **argv )
55 try
56 {
57   // initialize MPI, if necessary
58   Dune::MPIHelper::instance( argc, argv );
59 
60   // type of hierarchical grid
61   //typedef Dune :: AlbertaGrid< 2 , 2 > GridType;
62   typedef Dune :: YaspGrid< 3 > HGridType ;
63   //typedef Dune :: GridSelector :: GridType  HGridType ;
64 
65   std::string gridfile( "3dcube.dgf" );
66 
67   // construct macro using the DGF Parser
68   Dune::GridPtr< HGridType > gridPtr( gridfile );
69   HGridType& grid = *gridPtr ;
70 
71   std::ofstream file( "curve.gnu" );
72   printCurve( grid, file );
73 
74   std::ofstream gridout( "grid.gnu" );
75   printGrid( grid, gridout );
76 
77   return 0;
78 }
79 catch( const Dune::Exception &exception )
80 {
81   std::cerr << "Error: " << exception << std::endl;
82   return 1;
83 }
84