3#ifndef DUNE_DGF_GRIDFACTORY_HH
4#define DUNE_DGF_GRIDFACTORY_HH
12#include <dune/common/parallel/mpihelper.hh>
13#include <dune/grid/io/file/dgfparser/dgfexception.hh>
14#include <dune/grid/io/file/dgfparser/macrogrid.hh>
16#include <dune/grid/io/file/dgfparser/parser.hh>
17#include <dune/grid/common/intersection.hh>
26 template <
class Gr
idImp,
class IntersectionImp >
39 typedef MPIHelper::MPICommunicator MPICommunicatorType;
42 typedef typename Grid::template Codim< 0 >::Entity Element;
44 typedef typename Grid::template Codim< dimension >::Entity Vertex;
48 explicit DGFGridFactory (
const std::string &filename,
49 MPICommunicatorType comm = MPIHelper::getCommunicator() )
50 : macroGrid_( filename.c_str(), comm )
52 grid_ = macroGrid_.template createGrid< Grid >();
54 if( macroGrid_.nofelparams > 0 )
56 const size_t nofElements = macroGrid_.elements.size();
57 for(
size_t i = 0; i < nofElements; ++i )
59 std::vector< double > coord;
62 const size_t nofCorners = macroGrid_.elements[i].size();
63 for (
size_t k=0; k<nofCorners; ++k)
64 for (
int j=0; j<DomainType::dimension; ++j)
65 p[j]+=macroGrid_.vtx[macroGrid_.elements[i][k]][j];
66 p/=
double(nofCorners);
68 elInsertOrder_.insert( std::make_pair( p, i ) );
72 if( macroGrid_.nofvtxparams > 0 )
74 const size_t nofVertices = macroGrid_.vtx.size();
75 for(
size_t i = 0; i < nofVertices; ++i )
77 std::vector< double > coord;
80 for(
int k = 0; k < DomainType::dimension; ++k )
81 p[ k ] = macroGrid_.vtx[i][k];
83 vtxInsertOrder_.insert( std::make_pair( p, i ) );
93 template <
class Intersection>
94 bool wasInserted(
const Intersection &intersection)
const
96 return intersection.boundary();
99 template <
class Intersection>
100 int boundaryId(
const Intersection &intersection)
const
102 return (intersection.boundary()) ? int(intersection.indexInInside()+1) : int(0);
105 template<
int codim >
106 int numParameters ()
const
109 return macroGrid_.nofelparams;
110 else if( codim == dimension )
111 return macroGrid_.nofvtxparams;
116 template <
class Entity >
117 int numParameters (
const Entity & )
const
119 return numParameters< Entity::codimension >();
122 std::vector<double>& parameter(
const Element &element)
124 const typename Element::Geometry &geo = element.geometry();
125 DomainType coord( geo.corner( 0 ) );
126 for(
int i = 1; i < geo.corners(); ++i )
127 coord += geo.corner( i );
128 coord /= double( geo.corners() );
130 InsertOrderIterator it = elInsertOrder_.find( coord );
131 if( it != elInsertOrder_.end() )
132 return macroGrid_.elParams[ it->second ];
137 std::vector<double>& parameter(
const Vertex &vertex)
139 const typename Vertex::Geometry &geo = vertex.geometry();
140 DomainType coord( geo.corner( 0 ) );
142 InsertOrderIterator it = vtxInsertOrder_.find( coord );
143 if( it != vtxInsertOrder_.end() )
144 return macroGrid_.vtxParams[ it->second ];
149 bool haveBoundaryParameters ()
const
154 template<
class GG,
class II >
156 boundaryParameter (
const Intersection< GG, II > & intersection )
const
162 typedef FieldVector<typename Grid::ctype,Grid::dimensionworld> DomainType;
165 bool operator() (
const DomainType &a,
const DomainType &b )
const
168 const DomainType c = a - b;
169 const double eps = 1e-8;
171 for(
int i = 0; i < DomainType::dimension; ++i )
181 typedef std::map< DomainType, size_t, Compare > InsertOrderMap;
182 typedef typename InsertOrderMap::const_iterator InsertOrderIterator;
184 MacroGrid macroGrid_;
186 InsertOrderMap elInsertOrder_;
187 InsertOrderMap vtxInsertOrder_;
188 std::vector<double> emptyParam;
@ dimension
The dimension of the grid.
Definition: grid.hh:386
Include standard header files.
Definition: agrid.hh:58
static const type & defaultValue()
default constructor
Definition: parser.hh:26
std::string type
type of additional boundary parameters
Definition: parser.hh:23