dune-grid  2.5-git
albertagrid/dgfparser.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_ALBERTA_DGFPARSER_HH
4 #define DUNE_ALBERTA_DGFPARSER_HH
5 
6 #include <vector>
7 
10 
13 
16 
17 #if HAVE_ALBERTA
18 
19 namespace Dune
20 {
21 
22  // External Forward Declarations
23  // -----------------------------
24 
25  template< class GridImp, class IntersectionImp >
26  class Intersection;
27 
28 
29 
30  // DGFGridFactory for AlbertaGrid
31  // ------------------------------
32 
33  template< int dim, int dimworld >
34  struct DGFGridFactory< AlbertaGrid< dim, dimworld > >
35  {
37  const static int dimension = Grid::dimension;
38  typedef MPIHelper::MPICommunicator MPICommunicatorType;
39  typedef typename Grid::template Codim<0>::Entity Element;
40  typedef typename Grid::template Codim<dimension>::Entity Vertex;
42 
43  explicit DGFGridFactory ( std::istream &input,
44  MPICommunicatorType comm = MPIHelper::getCommunicator() );
45  explicit DGFGridFactory ( const std::string &filename,
46  MPICommunicatorType comm = MPIHelper::getCommunicator() );
47 
48  Grid *grid () const
49  {
50  return grid_;
51  }
52 
53  template< class Intersection >
54  bool wasInserted ( const Intersection &intersection ) const
55  {
56  return factory_.wasInserted( intersection );
57  }
58 
59  template< class Intersection >
60  int boundaryId ( const Intersection &intersection ) const
61  {
62  return Grid::getRealImplementation( intersection ).boundaryId();
63  }
64 
65  // return true if boundary parameters found
66  bool haveBoundaryParameters () const
67  {
68  return dgf_.haveBndParameters;
69  }
70 
71  template < class GG, class II >
73  boundaryParameter ( const Intersection< GG, II > & intersection ) const
74  {
76  typename Intersection::Entity entity = intersection.inside();
77  const int face = intersection.indexInInside();
78 
79  const ReferenceElement< double, dimension > & refElem =
80  ReferenceElements< double, dimension >::general( entity.type() );
81  int corners = refElem.size( face, 1, dimension );
82  std :: vector< unsigned int > bound( corners );
83  for( int i=0; i < corners; ++i )
84  {
85  const int k = refElem.subEntity( face, 1, i, dimension );
86  bound[ i ] = factory_.insertionIndex( entity.template subEntity< dimension >( k ) );
87  }
88 
89  DuneGridFormatParser::facemap_t::key_type key( bound, false );
90  const DuneGridFormatParser::facemap_t::const_iterator pos = dgf_.facemap.find( key );
91  if( pos != dgf_.facemap.end() )
92  return dgf_.facemap.find( key )->second.second;
93  else
95  }
96 
97  template< int codim >
98  int numParameters () const
99  {
100  if( codim == 0 )
101  return dgf_.nofelparams;
102  else if( codim == dimension )
103  return dgf_.nofvtxparams;
104  else
105  return 0;
106  }
107 
108  std::vector< double > &parameter ( const Element &element )
109  {
110  if( numParameters< 0 >() <= 0 )
111  {
112  DUNE_THROW( InvalidStateException,
113  "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
114  }
115  return dgf_.elParams[ factory_.insertionIndex( element ) ];
116  }
117 
118  std::vector< double > &parameter ( const Vertex &vertex )
119  {
120  if( numParameters< dimension >() <= 0 )
121  {
122  DUNE_THROW( InvalidStateException,
123  "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
124  }
125  return dgf_.vtxParams[ factory_.insertionIndex( vertex ) ];
126  }
127 
128  private:
129  bool generate( std::istream &input );
130 
131  Grid *grid_;
132  GridFactory factory_;
134  };
135 
136 
137 
138  // DGFGridInfo for AlbertaGrid
139  // ---------------------------
140 
141  template< int dim, int dimworld >
142  struct DGFGridInfo< AlbertaGrid< dim, dimworld > >
143  {
144  static int refineStepsForHalf ()
145  {
146  return dim;
147  }
148 
149  static double refineWeight ()
150  {
151  return 0.5;
152  }
153  };
154 
155 
156 
157  // Implementation of DGFGridFactory for AlbertaGrid
158  // ------------------------------------------------
159 
160  template< int dim, int dimworld >
162  ::DGFGridFactory ( std::istream &input, MPICommunicatorType comm )
163  : dgf_( 0, 1 )
164  {
165  input.clear();
166  input.seekg( 0 );
167  if( !input )
168  DUNE_THROW(DGFException, "Error resetting input stream." );
169  generate( input );
170  }
171 
172 
173  template< int dim, int dimworld >
175  ::DGFGridFactory ( const std::string &filename, MPICommunicatorType comm )
176  : dgf_( 0, 1 )
177  {
178  std::ifstream input( filename.c_str() );
179  if( !input )
180  DUNE_THROW( DGFException, "Macrofile " << filename << " not found." );
181  if( !generate( input ) )
182  grid_ = new AlbertaGrid< dim, dimworld >( filename.c_str() );
183  input.close();
184  }
185 
186 }
187 
188 #endif // #if HAVE_ALBERTA
189 
190 #endif // #ifndef DUNE_ALBERTA_DGFPARSER_HH
int numParameters() const
Definition: albertagrid/dgfparser.hh:98
int boundaryId(const Intersection &intersection) const
Definition: albertagrid/dgfparser.hh:60
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: albertagrid/dgfparser.hh:26
std::vector< double > & parameter(const Vertex &vertex)
Definition: albertagrid/dgfparser.hh:118
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in...
Definition: common/intersection.hh:374
const DGFBoundaryParameter::type & boundaryParameter(const Intersection< GG, II > &intersection) const
Definition: albertagrid/dgfparser.hh:73
bool haveBoundaryParameters() const
Definition: albertagrid/dgfparser.hh:66
DGFGridFactory(std::istream &input, MPICommunicatorType comm=MPIHelper::getCommunicator())
Definition: dgfgridfactory.hh:47
Entity inside() const
return Entity on the inside of this intersection. That is the Entity where we started this...
Definition: common/intersection.hh:278
GridImp::template Codim< 0 >::Entity Entity
Type of entity that this Intersection belongs to.
Definition: common/intersection.hh:186
[ provides Dune::Grid ]
Definition: agrid.hh:137
Grid::template Codim< dimension >::Entity Vertex
Definition: albertagrid/dgfparser.hh:40
static int refineStepsForHalf()
Definition: albertagrid/dgfparser.hh:144
bool wasInserted(const Intersection &intersection) const
Definition: albertagrid/dgfparser.hh:54
static double refineWeight()
Definition: albertagrid/dgfparser.hh:149
AlbertaGrid< dim, dimworld > Grid
Definition: albertagrid/dgfparser.hh:36
Definition: common.hh:179
std::string type
type of additional boundary parameters
Definition: parser.hh:23
Include standard header files.
Definition: agrid.hh:59
Definition: agrid.hh:66
specialization of the generic GridFactory for AlbertaGrid
exception class for IO errors in the DGF parser
Definition: dgfexception.hh:12
Grid * grid() const
Definition: albertagrid/dgfparser.hh:48
Dune::GridFactory< Grid > GridFactory
Definition: albertagrid/dgfparser.hh:41
Some simple static information for a given GridType.
Definition: io/file/dgfparser/dgfparser.hh:54
The DuneGridFormatParser class: reads a DGF file and stores build information in vector structures us...
Definition: parser.hh:44
static const int dimension
Definition: dgfgridfactory.hh:38
static const type & defaultValue()
default constructor
Definition: parser.hh:26
The dimension of the grid.
Definition: common/grid.hh:387
std::vector< double > & parameter(const Element &element)
Definition: albertagrid/dgfparser.hh:108
Grid::template Codim< 0 >::Entity Element
Definition: albertagrid/dgfparser.hh:39
MPIHelper::MPICommunicator MPICommunicatorType
Definition: albertagrid/dgfparser.hh:38