3#ifndef DUNE_DGFPARSERALU_HH
4#define DUNE_DGFPARSERALU_HH
10#include <dune/grid/io/file/dgfparser/dgfparser.hh>
11#include <dune/grid/io/file/dgfparser/parser.hh>
12#include <dune/grid/io/file/dgfparser/blocks/projection.hh>
14#include <dune/grid/common/intersection.hh>
22 template<
class Gr
idImp,
class IntersectionImp >
31 template<
int dimg,
int dimw, ALUGr
idElementType eltype, ALUGr
idRefinementType refinementtype,
class Comm >
32 struct DGFGridInfo<
Dune::ALUGrid< dimg, dimw, eltype, refinementtype, Comm > >
34 static int refineStepsForHalf () {
return ( refinementtype == conforming ) ? dimg : 1; }
35 static double refineWeight () {
return ( refinementtype == conforming ) ? 0.5 : 1.0/(std::pow( 2.0,
double(dimg))); }
49 typedef typename Grid::template Codim<0>::Entity Element;
50 typedef typename Grid::template Codim<dimension>::Entity Vertex;
58 explicit DGFBaseFactory ( MPICommunicatorType comm )
60 dgf_( rank(comm), size(comm) )
68 template<
class Intersection >
69 bool wasInserted (
const Intersection &intersection )
const
71 return factory_.wasInserted( intersection );
74 template<
class GG,
class II >
75 int boundaryId (
const Intersection< GG, II > & intersection )
const
80 const int face = intersection.indexInInside();
82 const ReferenceElement< double, dimension > & refElem =
84 int corners = refElem.size( face, 1, dimension );
85 std :: vector< unsigned int > bound( corners );
86 for(
int i=0; i < corners; ++i )
88 const int k = refElem.subEntity( face, 1, i, dimension );
89 bound[ i ] = factory_.insertionIndex( *entity.template subEntity< dimension >( k ) );
92 DuneGridFormatParser::facemap_t::key_type key( bound,
false );
93 const DuneGridFormatParser::facemap_t::const_iterator pos = dgf_.facemap.find( key );
94 if( pos != dgf_.facemap.end() )
95 return dgf_.facemap.find( key )->second.first;
97 return (intersection.boundary() ? 1 : 0);
100 template<
class GG,
class II >
102 boundaryParameter (
const Intersection< GG, II > & intersection )
const
107 const int face = intersection.indexInInside();
109 const ReferenceElement< double, dimension > & refElem =
111 int corners = refElem.size( face, 1, dimension );
112 std :: vector< unsigned int > bound( corners );
113 for(
int i=0; i < corners; ++i )
115 const int k = refElem.subEntity( face, 1, i, dimension );
116 bound[ i ] = factory_.insertionIndex( *entity.template subEntity< dimension >( k ) );
119 DuneGridFormatParser::facemap_t::key_type key( bound,
false );
120 const DuneGridFormatParser::facemap_t::const_iterator pos = dgf_.facemap.find( key );
121 if( pos != dgf_.facemap.end() )
122 return dgf_.facemap.find( key )->second.second;
127 template<
int codim >
128 int numParameters ()
const
131 return dgf_.nofelparams;
132 else if( codim == dimension )
133 return dgf_.nofvtxparams;
139 bool haveBoundaryParameters ()
const
141 return dgf_.haveBndParameters;
144 std::vector< double > ¶meter (
const Element &element )
146 if( numParameters< 0 >() <= 0 )
149 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
151 return dgf_.elParams[ factory_.insertionIndex( element ) ];
154 std::vector< double > ¶meter (
const Vertex &vertex )
156 if( numParameters< dimension >() <= 0 )
159 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
161 return dgf_.vtxParams[ factory_.insertionIndex( vertex ) ];
167 MPICommunicatorType communicator,
168 const std::string &filename );
172 MPICommunicatorType communicator,
173 const std::string &filename );
175 static Grid* callDirectly(
const char* gridname,
177 const char *filename,
178 MPICommunicatorType communicator )
180 #if ALU3DGRID_PARALLEL
182 std :: stringstream tmps;
183 tmps << filename <<
"." << rank;
184 const std :: string &tmp = tmps.str();
187 if( fileExists( tmp.c_str() ) )
188 return new Grid( tmp.c_str(), communicator );
193 if( fileExists( filename ) )
194 return new Grid( filename , communicator );
198 DUNE_THROW( GridError,
"Unable to create " << gridname <<
" from '"
199 << filename <<
"'." );
202 dwarn <<
"WARNING: P[" << rank <<
"]: Creating empty grid!" << std::endl;
205 return new Grid( communicator );
207 static bool fileExists (
const char *fileName )
209 std :: ifstream testfile( fileName );
215 static int rank( MPICommunicatorType MPICOMM )
219 MPI_Comm_rank( MPICOMM, &rank );
223 static int size( MPICommunicatorType MPICOMM )
227 MPI_Comm_size( MPICOMM, &size );
232 GridFactory factory_;
233 DuneGridFormatParser dgf_;
236 template < ALUGr
idElementType eltype, ALUGr
idRefinementType refinementtype,
class Comm >
237 struct DGFGridFactory< ALUGrid<3,3, eltype, refinementtype, Comm > > :
238 public DGFBaseFactory< ALUGrid<3,3, eltype, refinementtype, Comm > >
240 typedef ALUGrid<3,3, eltype, refinementtype, Comm > DGFGridType;
241 typedef DGFBaseFactory< DGFGridType > BaseType;
242 typedef typename BaseType :: MPICommunicatorType MPICommunicatorType;
244 using BaseType :: grid_;
245 using BaseType :: callDirectly;
247 explicit DGFGridFactory ( std::istream &input,
254 DUNE_THROW( DGFException,
"Error resetting input stream." );
255 generate( input, comm );
258 explicit DGFGridFactory (
const std::string &filename,
262 std::ifstream input( filename.c_str() );
263 bool fileFound = input.is_open() ;
265 fileFound = generate( input, comm, filename );
268 grid_ = callDirectly(
"ALUGrid< 3, 3, eltype, ref, comm >", this->rank( comm ), filename.c_str(), comm );
272 bool generate( std::istream &file, MPICommunicatorType comm,
const std::string &filename =
"" );
275 template <
int dimw, ALUGr
idElementType eltype, ALUGr
idRefinementType refinementtype,
class Comm >
276 struct DGFGridFactory< ALUGrid<2, dimw, eltype, refinementtype, Comm > > :
277 public DGFBaseFactory< ALUGrid< 2, dimw, eltype, refinementtype, Comm > >
279 typedef ALUGrid< 2, dimw, eltype, refinementtype, Comm > DGFGridType;
280 typedef DGFBaseFactory< DGFGridType > BaseType;
281 typedef typename BaseType :: MPICommunicatorType MPICommunicatorType;
282 typedef typename BaseType::Grid Grid;
284 typedef typename BaseType::GridFactory GridFactory;
286 explicit DGFGridFactory ( std::istream &input,
293 DUNE_THROW(DGFException,
"Error resetting input stream." );
294 generate( input, comm );
297 explicit DGFGridFactory (
const std::string &filename,
301 std::ifstream input( filename.c_str() );
303 DUNE_THROW( DGFException,
"Macrofile '" << filename <<
"' not found." );
304 if( !generate( input, comm, filename ) )
306 if( BaseType::fileExists( filename.c_str() ) )
307 grid_ =
new Grid( filename );
309 DUNE_THROW( GridError,
"Unable to create a 2d ALUGrid from '" << filename <<
"'." );
314 bool generate( std::istream &file, MPICommunicatorType comm,
const std::string &filename =
"" );
315 using BaseType::grid_;
316 using BaseType::factory_;
317 using BaseType::dgf_;
Provides base classes for ALUGrid.
@ dimension
The dimension of the grid.
Definition: grid.hh:402
Intersection of a mesh entities of codimension 0 ("elements") with a "neighboring" element or with th...
Definition: intersection.hh:161
GridImp::template Codim< 0 >::EntityPointer EntityPointer
Pointer to the type of entities that this Intersection belongs to.
Definition: intersection.hh:188
GridImp::template Codim< 0 >::Entity Entity
Type of entity that this Intersection belongs to.
Definition: intersection.hh:185
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_THROW(E, m)
Definition: exceptions.hh:243
DWarnType dwarn(std::cerr)
Stream for warnings indicating problems.
Definition: stdstreams.hh:159
Dune namespace.
Definition: alignment.hh:10
ALUGridElementType
basic element types for ALUGrid
Definition: declaration.hh:18
static const type & defaultValue()
default constructor
Definition: parser.hh:26
std::string type
type of additional boundary parameters
Definition: parser.hh:23
static double refineWeight()
static int refineStepsForHalf()
number of globalRefine steps needed to refuce h by 0.5
static const ReferenceElement< ctype, dim > & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:484