1#ifndef DUNE_ALU3DGRID_HSFC_HH
2#define DUNE_ALU3DGRID_HSFC_HH
15#include <dune/alugrid/impl/parallel/zcurve.hh>
17#include <dune/alugrid/impl/parallel/aluzoltan.hh>
20 extern double Zoltan_HSFC_InvHilbert3d (Zoltan_Struct *zz,
double *coord);
21 extern double Zoltan_HSFC_InvHilbert2d (Zoltan_Struct *zz,
double *coord);
27 template <
class Coordinate>
28 class ZoltanSpaceFillingCurveOrdering
31 typedef Dune :: Communication< typename Dune :: MPIHelper :: MPICommunicator >
35 typedef void Zoltan_Struct;
36 typedef Communication Zoltan;
40 typedef double zoltan_hsfc_inv_t(Zoltan_Struct *zz,
double *coord);
42 static const int dimension = Coordinate::dimension;
47 zoltan_hsfc_inv_t* hsfcInv_;
52 ZoltanSpaceFillingCurveOrdering(
const Coordinate& lower,
53 const Coordinate& upper,
54 const Communication& comm =
59 hsfcInv_( dimension == 3 ? Zoltan_HSFC_InvHilbert3d : Zoltan_HSFC_InvHilbert2d ),
70 double hilbertIndex(
const Coordinate& point )
const
73 assert( point.size() == (
unsigned int)dimension );
75 Coordinate center( 0 ) ;
77 for(
int d=0; d<dimension; ++d )
78 center[ d ] = (point[ d ] - lower_[ d ]) / length_[ d ];
81 return hsfcInv_( zz_.Get_C_Handle(), ¢er[ 0 ] );
89 double index(
const Coordinate& point )
const
91 return hilbertIndex( point );
95 template<
class Gr
idView >
96 void printSpaceFillingCurve (
const GridView& view, std::string name =
"sfc",
const bool vtk =
false )
98 typedef typename GridView :: template
Codim< 0 > :: Iterator Iterator ;
99 typedef typename Iterator :: Entity :: Geometry :: GlobalCoordinate GlobalCoordinate ;
101 std::vector< GlobalCoordinate > vertices;
102 vertices.reserve( view.indexSet().size( 0 ) );
104 const Iterator endit = view.template end< 0 > ();
105 for(Iterator it = view.template begin< 0 > (); it != endit; ++ it )
107 GlobalCoordinate center = (*it).geometry().center();
108 vertices.push_back( center );
111 std::stringstream gnufilename;
112 gnufilename << name <<
".gnu";
113 if( view.grid().comm().size() > 1 )
114 gnufilename <<
"." << view.grid().comm().rank();
116 std::ofstream gnuFile ( gnufilename.str() );
119 for(
size_t i=0; i<vertices.size(); ++i )
121 gnuFile << vertices[ i ] << std::endl;
128 std::stringstream vtkfilename;
129 vtkfilename << name <<
".vtk";
130 if( view.grid().comm().size() > 1 )
131 vtkfilename <<
"." << view.grid().comm().rank();
132 std::ofstream vtkFile ( vtkfilename.str() );
136 vtkFile <<
"# vtk DataFile Version 1.0" << std::endl;
137 vtkFile <<
"Line representation of vtk" << std::endl;
138 vtkFile <<
"ASCII" << std::endl;
139 vtkFile <<
"DATASET POLYDATA" << std::endl;
140 vtkFile <<
"POINTS "<< vertices.size() <<
" FLOAT" << std::endl;
142 for(
size_t i=0; i<vertices.size(); ++i )
144 vtkFile << vertices[ i ];
145 for(
int d=GlobalCoordinate::dimension; d<3; ++d )
147 vtkFile << std::endl;
151 vtkFile <<
"LINES " << vertices.size()-1 <<
" " << (vertices.size()-1)*3 << std::endl;
153 for(
size_t i=0; i<vertices.size()-1; ++i )
154 vtkFile <<
"2 " << i <<
" " << i+1 << std::endl;
165 template <
class Coordinate>
166 class SpaceFillingCurveOrdering
168 typedef ::ALUGridSFC::ZCurve< long int, Coordinate::dimension> ZCurveOrderingType;
169 typedef ::ALUGridSFC::ZoltanSpaceFillingCurveOrdering< Coordinate > HilbertOrderingType;
172 typedef Dune :: Communication< typename MPIHelper :: MPICommunicator >
175 enum CurveType { ZCurve, Hilbert, None };
178 static const CurveType DefaultCurve = Hilbert ;
180 static const CurveType DefaultCurve = ZCurve ;
184 ZCurveOrderingType zCurve_;
185 HilbertOrderingType hilbert_;
187 const CurveType curveType_;
190 SpaceFillingCurveOrdering(
const CurveType& curveType,
191 const Coordinate& lower,
192 const Coordinate& upper,
193 const Communication& comm =
195 : zCurve_ ( lower, upper, comm )
196 , hilbert_( lower, upper, comm )
197 , curveType_( curveType )
201 template <
class OtherComm>
202 SpaceFillingCurveOrdering(
const CurveType& curveType,
203 const Coordinate& lower,
204 const Coordinate& upper,
205 const OtherComm& otherComm )
206 : zCurve_ ( lower, upper,
207 otherComm.size() > 1 ? Communication(
Dune::MPIHelper::getCommunicator() ) :
208 Communication(
Dune::MPIHelper::getLocalCommunicator() ) )
209 , hilbert_( lower, upper,
210 otherComm.size() > 1 ? Communication(
Dune::MPIHelper::getCommunicator() ) :
211 Communication(
Dune::MPIHelper::getLocalCommunicator() ) )
212 , curveType_( curveType )
217 double index(
const Coordinate& point )
const
219 if( curveType_ == ZCurve )
221 return double( zCurve_.index( point ) );
223 else if ( curveType_ == Hilbert )
225 return double( hilbert_.index( point ) );
229 DUNE_THROW(NotImplemented,
"Wrong space filling curve ordering selected");
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:198
Default exception class for OS errors.
Definition: exceptions.hh:271
A few common exception classes.
Implements an utility class that provides collective communication methods for sequential programs.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Implements an utility class that provides MPI's collective communication methods.
Helpers for dealing with MPI.
Dune namespace.
Definition: alignedallocator.hh:13