5#ifndef DUNE_DGF_GRIDFACTORY_HH
6#define DUNE_DGF_GRIDFACTORY_HH
15#include <dune/grid/io/file/dgfparser/dgfexception.hh>
16#include <dune/grid/io/file/dgfparser/macrogrid.hh>
18#include <dune/grid/io/file/dgfparser/parser.hh>
19#include <dune/grid/common/intersection.hh>
28 template <
class Gr
idImp,
class IntersectionImp >
44 typedef typename Grid::template Codim< 0 >::Entity Element;
46 typedef typename Grid::template Codim< dimension >::Entity Vertex;
50 explicit DGFGridFactory (
const std::string &filename,
52 : macroGrid_( filename.c_str(), comm )
54 grid_ = macroGrid_.template createGrid< Grid >();
56 if( macroGrid_.nofelparams > 0 )
58 const size_t nofElements = macroGrid_.elements.size();
59 for(
size_t i = 0; i < nofElements; ++i )
61 std::vector< double > coord;
64 const size_t nofCorners = macroGrid_.elements[i].size();
65 for (
size_t k=0; k<nofCorners; ++k)
67 p[j]+=macroGrid_.vtx[macroGrid_.elements[i][k]][j];
68 p/=
double(nofCorners);
70 elInsertOrder_.insert( std::make_pair( p, i ) );
74 if( macroGrid_.nofvtxparams > 0 )
76 const size_t nofVertices = macroGrid_.vtx.size();
77 for(
size_t i = 0; i < nofVertices; ++i )
79 std::vector< double > coord;
83 p[ k ] = macroGrid_.vtx[i][k];
85 vtxInsertOrder_.insert( std::make_pair( p, i ) );
95 template <
class Intersection>
96 bool wasInserted(
const Intersection &intersection)
const
98 return intersection.boundary();
101 template <
class Intersection>
102 int boundaryId(
const Intersection &intersection)
const
104 return (intersection.boundary()) ? int(intersection.indexInInside()+1) : int(0);
107 template<
int codim >
108 int numParameters ()
const
111 return macroGrid_.nofelparams;
112 else if( codim == dimension )
113 return macroGrid_.nofvtxparams;
118 template <
class Entity >
119 int numParameters (
const Entity & )
const
121 return numParameters< Entity::codimension >();
124 std::vector<double>& parameter(
const Element &element)
126 const typename Element::Geometry &geo = element.geometry();
127 DomainType coord( geo.corner( 0 ) );
128 for(
int i = 1; i < geo.corners(); ++i )
129 coord += geo.corner( i );
130 coord /= double( geo.corners() );
132 InsertOrderIterator it = elInsertOrder_.find( coord );
133 if( it != elInsertOrder_.end() )
134 return macroGrid_.elParams[ it->second ];
139 std::vector<double>& parameter(
const Vertex &
vertex)
141 const typename Vertex::Geometry &geo =
vertex.geometry();
142 DomainType coord( geo.corner( 0 ) );
144 InsertOrderIterator it = vtxInsertOrder_.find( coord );
145 if( it != vtxInsertOrder_.end() )
146 return macroGrid_.vtxParams[ it->second ];
151 bool haveBoundaryParameters ()
const
156 template<
class GG,
class II >
158 boundaryParameter (
const Intersection< GG, II > & intersection )
const
164 typedef FieldVector<typename Grid::ctype,Grid::dimensionworld> DomainType;
167 bool operator() (
const DomainType &a,
const DomainType &b )
const
170 const DomainType c = a - b;
171 const double eps = 1e-8;
183 typedef std::map< DomainType, size_t, Compare > InsertOrderMap;
184 typedef typename InsertOrderMap::const_iterator InsertOrderIterator;
186 MacroGrid macroGrid_;
188 InsertOrderMap elInsertOrder_;
189 InsertOrderMap vtxInsertOrder_;
190 std::vector<double> emptyParam;
static constexpr int dimension
The size of this vector.
Definition: fvector.hh:96
static constexpr int dimension
The dimension of the grid.
Definition: grid.hh:387
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:192
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:200
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:492
Helpers for dealing with MPI.
Dune namespace.
Definition: alignedallocator.hh:13
static const type & defaultValue()
default constructor
Definition: parser.hh:28
std::string type
type of additional boundary parameters
Definition: parser.hh:25