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;
47 explicit DGFGridFactory ( std::istream &input,
51 DUNE_THROW( DGFException,
"DGF factories using old MacroGrid implementation"
52 "don't support creation from std::istream." );
55 explicit DGFGridFactory (
const std::string &filename,
57 : macroGrid_( filename.c_str(), comm )
59 grid_ = macroGrid_.template createGrid< Grid >();
61 if( macroGrid_.nofelparams > 0 )
63 const size_t nofElements = macroGrid_.elements.size();
64 for(
size_t i = 0; i < nofElements; ++i )
66 std::vector< double > coord;
69 const size_t nofCorners = macroGrid_.elements[i].size();
70 for (
size_t k=0; k<nofCorners; ++k)
72 p[j]+=macroGrid_.vtx[macroGrid_.elements[i][k]][j];
73 p/=
double(nofCorners);
75 elInsertOrder_.insert( std::make_pair( p, i ) );
79 if( macroGrid_.nofvtxparams > 0 )
81 const size_t nofVertices = macroGrid_.vtx.size();
82 for(
size_t i = 0; i < nofVertices; ++i )
84 std::vector< double > coord;
88 p[ k ] = macroGrid_.vtx[i][k];
90 vtxInsertOrder_.insert( std::make_pair( p, i ) );
100 template <
class Intersection>
101 bool wasInserted(
const Intersection &intersection)
const
103 return intersection.boundary();
106 template <
class Intersection>
107 int boundaryId(
const Intersection &intersection)
const
109#if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
110 return intersection.boundaryId();
112 return (intersection.boundary()) ? int(intersection.indexInInside()+1) : int(0);
116 template<
int codim >
117 int numParameters ()
const
120 return macroGrid_.nofelparams;
121 else if( codim == dimension )
122 return macroGrid_.nofvtxparams;
127 template <
class Entity >
128 int numParameters (
const Entity & )
const
130 return numParameters< Entity::codimension >();
133 std::vector<double>& parameter(
const Element &element)
135 const typename Element::Geometry &geo = element.geometry();
136 DomainType coord( geo.corner( 0 ) );
137 for(
int i = 1; i < geo.corners(); ++i )
138 coord += geo.corner( i );
139 coord /= double( geo.corners() );
141 InsertOrderIterator it = elInsertOrder_.find( coord );
142 if( it != elInsertOrder_.end() )
143 return macroGrid_.elParams[ it->second ];
148 std::vector<double>& parameter(
const Vertex &vertex)
150 const typename Vertex::Geometry &geo = vertex.geometry();
151 DomainType coord( geo.corner( 0 ) );
153 InsertOrderIterator it = vtxInsertOrder_.find( coord );
154 if( it != vtxInsertOrder_.end() )
155 return macroGrid_.vtxParams[ it->second ];
160 bool haveBoundaryParameters ()
const
165 template<
class GG,
class II >
167 boundaryParameter (
const Intersection< GG, II > & intersection )
const
173 typedef FieldVector<typename Grid::ctype,Grid::dimensionworld> DomainType;
176 bool operator() (
const DomainType &a,
const DomainType &b )
const
179 const DomainType c = a - b;
180 const double eps = 1e-8;
192 typedef std::map< DomainType, size_t, Compare > InsertOrderMap;
193 typedef typename InsertOrderMap::const_iterator InsertOrderIterator;
195 MacroGrid macroGrid_;
197 InsertOrderMap elInsertOrder_;
198 InsertOrderMap vtxInsertOrder_;
199 std::vector<double> emptyParam;
@ dimension
The size of this vector.
Definition: fvector.hh:101
@ dimension
The dimension of the grid.
Definition: grid.hh:402
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:173
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:181
#define DUNE_DEPRECATED
Mark some entity as deprecated.
Definition: deprecated.hh:84
#define DUNE_THROW(E, m)
Definition: exceptions.hh:243
Helpers for dealing with MPI.
Dune namespace.
Definition: alignment.hh:10
static const type & defaultValue()
default constructor
Definition: parser.hh:26
std::string type
type of additional boundary parameters
Definition: parser.hh:23