1 #ifndef DUNE_DGF_GRIDFACTORY_HH
2 #define DUNE_DGF_GRIDFACTORY_HH
10 #include <dune/common/mpihelper.hh>
22 template <
class Gr
idImp,
template <
class >
class IntersectionImp >
33 typedef typename Grid::template Codim< 0 >::Entity Element;
35 typedef typename Grid::template Codim< dimension >::Entity Vertex;
42 DUNE_THROW(
DGFException,
"DGF factories using old MacroGrid implementation"
43 "don't support creation from std::istream." );
48 : macroGrid_( filename.c_str(), comm )
50 grid_ = macroGrid_.template createGrid< Grid >();
54 const size_t nofElements = macroGrid_.
elements.size();
55 for(
size_t i = 0; i < nofElements; ++i )
57 std::vector< double > coord;
60 const size_t nofCorners = macroGrid_.
elements[i].size();
61 for (
size_t k=0;k<nofCorners;++k)
62 for (
int j=0;j<DomainType::dimension;++j)
64 p/=
double(nofCorners);
66 elInsertOrder_.insert( std::make_pair( p, i ) );
72 const size_t nofVertices = macroGrid_.
vtx.size();
73 for(
size_t i = 0; i < nofVertices; ++i )
75 std::vector< double > coord;
78 for(
int k = 0; k < DomainType::dimension; ++k )
79 p[ k ] = macroGrid_.
vtx[i][k];
81 vtxInsertOrder_.insert( std::make_pair( p, i ) );
91 template <
class Intersection>
97 template <
class Intersection>
103 template<
int codim >
114 template <
class Entity >
117 return numParameters< Entity::codimension >();
122 const typename Element::Geometry &geo = element.geometry();
123 DomainType coord( geo.corner( 0 ) );
124 for(
int i = 1; i < geo.corners(); ++i )
125 coord += geo.corner( i );
126 coord /= double( geo.corners() );
128 InsertOrderIterator it = elInsertOrder_.find( coord );
129 if( it != elInsertOrder_.end() )
130 return macroGrid_.
elParams[ it->second ];
137 const typename Vertex::Geometry &geo = vertex.geometry();
138 DomainType coord( geo.corner( 0 ) );
140 InsertOrderIterator it = vtxInsertOrder_.find( coord );
141 if( it != vtxInsertOrder_.end() )
142 return macroGrid_.
vtxParams[ it->second ];
152 template <
class GG,
template <
class >
class II >
160 typedef FieldVector<typename Grid::ctype,Grid::dimensionworld> DomainType;
163 bool operator() (
const DomainType &a,
const DomainType &b )
const
166 const DomainType c = a - b;
167 const double eps = 1e-8;
169 for(
int i = 0; i < DomainType::dimension; ++i )
179 typedef std::map< DomainType, size_t, Compare > InsertOrderMap;
180 typedef typename InsertOrderMap::const_iterator InsertOrderIterator;
182 MacroGrid macroGrid_;
184 InsertOrderMap elInsertOrder_;
185 InsertOrderMap vtxInsertOrder_;
186 std::vector<double> emptyParam;