3#ifndef DUNE_DGF_GRIDFACTORY_HH
4#define DUNE_DGF_GRIDFACTORY_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 >
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,
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)
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;
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;
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 size of this vector.
Definition: fvector.hh:102
@ dimension
The dimension of the grid.
Definition: grid.hh:386
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:188
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:196
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:504
Helpers for dealing with MPI.
Dune namespace.
Definition: alignedallocator.hh:11
static const type & defaultValue()
default constructor
Definition: parser.hh:26
std::string type
type of additional boundary parameters
Definition: parser.hh:23