Dune Core Modules (2.3.1)

dgfparser.hh
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
8#include <dune/grid/albertagrid.hh>
10
11#include <dune/grid/io/file/dgfparser/dgfparser.hh>
12#include <dune/grid/io/file/dgfparser/blocks/projection.hh>
13
14#include <dune/grid/common/intersection.hh>
15#include <dune/grid/io/file/dgfparser/parser.hh>
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 {
36 typedef AlbertaGrid<dim,dimworld> Grid;
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;
41 typedef Dune::GridFactory<Grid> GridFactory;
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 paramters 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 {
75 typedef Dune::Intersection< GG, II > Intersection;
76 typename Intersection::EntityPointer inside = intersection.inside();
77 const typename Intersection::Entity & entity = *inside;
78 const int face = intersection.indexInInside();
79
80 const ReferenceElement< double, dimension > & refElem =
82 int corners = refElem.size( face, 1, dimension );
83 std :: vector< unsigned int > bound( corners );
84 for( int i=0; i < corners; ++i )
85 {
86 const int k = refElem.subEntity( face, 1, i, dimension );
87 bound[ i ] = factory_.insertionIndex( *entity.template subEntity< dimension >( k ) );
88 }
89
90 DuneGridFormatParser::facemap_t::key_type key( bound, false );
91 const DuneGridFormatParser::facemap_t::const_iterator pos = dgf_.facemap.find( key );
92 if( pos != dgf_.facemap.end() )
93 return dgf_.facemap.find( key )->second.second;
94 else
96 }
97
98 template< int codim >
99 int numParameters () const
100 {
101 if( codim == 0 )
102 return dgf_.nofelparams;
103 else if( codim == dimension )
104 return dgf_.nofvtxparams;
105 else
106 return 0;
107 }
108
109 std::vector< double > &parameter ( const Element &element )
110 {
111 if( numParameters< 0 >() <= 0 )
112 {
113 DUNE_THROW( InvalidStateException,
114 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
115 }
116 return dgf_.elParams[ factory_.insertionIndex( element ) ];
117 }
118
119 std::vector< double > &parameter ( const Vertex &vertex )
120 {
121 if( numParameters< dimension >() <= 0 )
122 {
123 DUNE_THROW( InvalidStateException,
124 "Calling DGFGridFactory::parameter is only allowed if there are parameters." );
125 }
126 return dgf_.vtxParams[ factory_.insertionIndex( vertex ) ];
127 }
128
129 private:
130 bool generate( std::istream &input );
131
132 Grid *grid_;
133 GridFactory factory_;
134 DuneGridFormatParser dgf_;
135 };
136
137
138
139 // DGFGridInfo for AlbertaGrid
140 // ---------------------------
141
142 template< int dim, int dimworld >
143 struct DGFGridInfo< AlbertaGrid< dim, dimworld > >
144 {
145 static int refineStepsForHalf ()
146 {
147 return dim;
148 }
149
150 static double refineWeight ()
151 {
152 return 0.5;
153 }
154 };
155
156
157
158 // Implementation of DGFGridFactory for AlbertaGrid
159 // ------------------------------------------------
160
161 template< int dim, int dimworld >
162 inline DGFGridFactory< AlbertaGrid< dim, dimworld > >
163 ::DGFGridFactory ( std::istream &input, MPICommunicatorType comm )
164 : dgf_( 0, 1 )
165 {
166 input.clear();
167 input.seekg( 0 );
168 if( !input )
169 DUNE_THROW(DGFException, "Error resetting input stream." );
170 generate( input );
171 }
172
173
174 template< int dim, int dimworld >
175 inline DGFGridFactory< AlbertaGrid< dim, dimworld > >
176 ::DGFGridFactory ( const std::string &filename, MPICommunicatorType comm )
177 : dgf_( 0, 1 )
178 {
179 std::ifstream input( filename.c_str() );
180 if( !input )
181 DUNE_THROW( DGFException, "Macrofile " << filename << " not found." );
182 if( !generate( input ) )
183 grid_ = new AlbertaGrid< dim, dimworld >( filename.c_str() );
184 input.close();
185 }
186
187}
188
189#endif // #if HAVE_ALBERTA
190
191#endif // #ifndef DUNE_ALBERTA_DGFPARSER_HH
specialization of the generic GridFactory for AlbertaGrid
@ dimension
The dimension of the grid.
Definition: grid.hh:400
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:191
GridImp::template Codim< 0 >::Entity Entity
Type of entity that this Intersection belongs to.
Definition: intersection.hh:188
MPI_Comm MPICommunicator
The type of the mpi communicator.
Definition: mpihelper.hh:174
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:182
#define DUNE_THROW(E, m)
Definition: exceptions.hh:244
Dune namespace.
Definition: alignment.hh:14
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:568
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)