dune-grid 2.8.0
Loading...
Searching...
No Matches
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
19namespace 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 intersection.impl().boundaryId();
63 }
64
65 // return true if boundary parameters found
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 auto refElem = referenceElement< double, dimension >( entity.type() );
80 int corners = refElem.size( face, 1, dimension );
81 std :: vector< unsigned int > bound( corners );
82 for( int i=0; i < corners; ++i )
83 {
84 const int k = refElem.subEntity( face, 1, i, dimension );
85 bound[ i ] = factory_.insertionIndex( entity.template subEntity< dimension >( k ) );
86 }
87
88 DuneGridFormatParser::facemap_t::key_type key( bound, false );
89 const DuneGridFormatParser::facemap_t::const_iterator pos = dgf_.facemap.find( key );
90 if( pos != dgf_.facemap.end() )
91 return dgf_.facemap.find( key )->second.second;
92 else
94 }
95
96 template< int codim >
97 int numParameters () const
98 {
99 if( codim == 0 )
100 return dgf_.nofelparams;
101 else if( codim == dimension )
102 return dgf_.nofvtxparams;
103 else
104 return 0;
105 }
106
107 std::vector< double > &parameter ( const Element &element )
108 {
109 if( numParameters< 0 >() <= 0 )
110 {
111 DUNE_THROW( InvalidStateException,
112 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
113 }
114 return dgf_.elParams[ factory_.insertionIndex( element ) ];
115 }
116
117 std::vector< double > &parameter ( const Vertex &vertex )
118 {
119 if( numParameters< dimension >() <= 0 )
120 {
121 DUNE_THROW( InvalidStateException,
122 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
123 }
124 return dgf_.vtxParams[ factory_.insertionIndex( vertex ) ];
125 }
126
127 private:
128 bool generate( std::istream &input );
129
130 Grid *grid_;
131 GridFactory factory_;
133 };
134
135
136
137 // DGFGridInfo for AlbertaGrid
138 // ---------------------------
139
140 template< int dim, int dimworld >
141 struct DGFGridInfo< AlbertaGrid< dim, dimworld > >
142 {
143 static int refineStepsForHalf ()
144 {
145 return dim;
146 }
147
148 static double refineWeight ()
149 {
150 return 0.5;
151 }
152 };
153
154
155
156 // Implementation of DGFGridFactory for AlbertaGrid
157 // ------------------------------------------------
158
159 template< int dim, int dimworld >
160 inline DGFGridFactory< AlbertaGrid< dim, dimworld > >
161 ::DGFGridFactory ( std::istream &input, MPICommunicatorType /* comm */ )
162 : dgf_( 0, 1 )
163 {
164 input.clear();
165 input.seekg( 0 );
166 if( !input )
167 DUNE_THROW(DGFException, "Error resetting input stream." );
168 generate( input );
169 }
170
171
172 template< int dim, int dimworld >
174 ::DGFGridFactory ( const std::string &filename, MPICommunicatorType /* comm */ )
175 : dgf_( 0, 1 )
176 {
177 std::ifstream input( filename.c_str() );
178 if( !input )
179 DUNE_THROW( DGFException, "Macrofile " << filename << " not found." );
180 if( !generate( input ) )
181 grid_ = new AlbertaGrid< dim, dimworld >( filename.c_str() );
182 input.close();
183 }
184
185}
186
187#endif // #if HAVE_ALBERTA
188
189#endif // #ifndef DUNE_ALBERTA_DGFPARSER_HH
Include standard header files.
Definition: agrid.hh:58
Definition: dgfgridfactory.hh:36
static const int dimension
Definition: dgfgridfactory.hh:38
[ provides Dune::Grid ]
Definition: agrid.hh:107
Intersection of a mesh entity of codimension 0 ("element") with a "neighboring" element or with the d...
Definition: common/intersection.hh:162
int indexInInside() const
Local index of codim 1 entity in the inside() entity where intersection is contained in.
Definition: common/intersection.hh:344
Entity inside() const
return Entity on the inside of this intersection. That is the Entity where we started this.
Definition: common/intersection.hh:248
Implementation & impl()
access to the underlying implementation
Definition: common/intersection.hh:176
GridImp::template Codim< 0 >::Entity Entity
Type of entity that this Intersection belongs to.
Definition: common/intersection.hh:190
MPIHelper::MPICommunicator MPICommunicatorType
Definition: albertagrid/dgfparser.hh:38
bool haveBoundaryParameters() const
Definition: albertagrid/dgfparser.hh:66
Grid::template Codim< 0 >::Entity Element
Definition: albertagrid/dgfparser.hh:39
AlbertaGrid< dim, dimworld > Grid
Definition: albertagrid/dgfparser.hh:36
std::vector< double > & parameter(const Element &element)
Definition: albertagrid/dgfparser.hh:107
int numParameters() const
Definition: albertagrid/dgfparser.hh:97
Dune::GridFactory< Grid > GridFactory
Definition: albertagrid/dgfparser.hh:41
std::vector< double > & parameter(const Vertex &vertex)
Definition: albertagrid/dgfparser.hh:117
bool wasInserted(const Intersection &intersection) const
Definition: albertagrid/dgfparser.hh:54
const DGFBoundaryParameter::type & boundaryParameter(const Intersection< GG, II > &intersection) const
Definition: albertagrid/dgfparser.hh:73
Grid * grid() const
Definition: albertagrid/dgfparser.hh:48
int boundaryId(const Intersection &intersection) const
Definition: albertagrid/dgfparser.hh:60
Grid::template Codim< dimension >::Entity Vertex
Definition: albertagrid/dgfparser.hh:40
static int refineStepsForHalf()
Definition: albertagrid/dgfparser.hh:143
static double refineWeight()
Definition: albertagrid/dgfparser.hh:148
Grid abstract base class.
Definition: common/grid.hh:372
@ dimension
The dimension of the grid.
Definition: common/grid.hh:386
Provide a generic factory class for unstructured grids.
Definition: common/gridfactory.hh:312
exception class for IO errors in the DGF parser
Definition: dgfexception.hh:14
Some simple static information for a given GridType.
Definition: io/file/dgfparser/dgfparser.hh:54
static const type & defaultValue()
default constructor
Definition: parser.hh:26
std::string type
type of additional boundary parameters
Definition: parser.hh:23
The DuneGridFormatParser class: reads a DGF file and stores build information in vector structures us...
Definition: parser.hh:45
specialization of the generic GridFactory for AlbertaGrid