Dune Core Modules (2.4.1)

dgfs.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_DGFS_HH
4#define DUNE_DGFS_HH
5
6#include <dune/grid/common/intersection.hh>
7#include <dune/grid/sgrid.hh>
8#include "dgfparser.hh"
9
10namespace Dune
11{
12
13 // External Forward Declarations
14 // -----------------------------
15
16 template< class GridImp, class IntersectionImp >
17 class Intersection;
18
19
20
21 // DGFGridFactory for SGrid
22 // ------------------------
23
24 template< int dim, int dimworld, class ctype >
25 struct DGFGridFactory< SGrid< dim, dimworld, ctype > >
26 {
27 typedef SGrid< dim, dimworld, ctype > Grid;
28
29 const static int dimension = Grid::dimension;
30
31 typedef MPIHelper::MPICommunicator MPICommunicatorType;
32
33 private:
34 typedef FieldVector< double, dimension > Point;
35
36 typedef dgf::BoundaryDomBlock BoundaryDomainBlock;
37
38 public:
39 explicit DGFGridFactory ( std::istream &input,
40 MPICommunicatorType comm = MPIHelper::getCommunicator() )
41 {
42 generate( input, comm );
43 }
44
45 explicit DGFGridFactory ( const std::string &filename,
46 MPICommunicatorType comm = MPIHelper::getCommunicator() )
47 {
48 std::ifstream input( filename.c_str() );
49 generate( input, comm );
50 }
51
52 Grid *grid() const
53 {
54 return grid_;
55 }
56
57 template< class Intersection >
58 bool wasInserted ( const Intersection &intersection ) const
59 {
60 return false;
61 }
62
63 template< class Intersection >
64 int boundaryId ( const Intersection &intersection ) const
65 {
66 if( boundaryDomainBlock_->isactive() )
67 {
68 std::vector< Point > corners;
69 getCorners( intersection.geometry(), corners );
70 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
71 if( data )
72 return data->id();
73 else
74 return intersection.indexInInside();
75 }
76 else
77 return intersection.indexInInside();
78 }
79
80 template< int codim >
81 int numParameters () const
82 {
83 return 0;
84 }
85
86 // return true if boundary parameters found
87 bool haveBoundaryParameters () const
88 {
89 return boundaryDomainBlock_->isactive();
90 }
91
92 template< class GG, class II >
93 const typename DGFBoundaryParameter::type &
94 boundaryParameter ( const Intersection< GG, II > & intersection ) const
95 {
96 if( haveBoundaryParameters() )
97 {
98 std::vector< Point > corners;
99 getCorners( intersection.geometry(), corners );
100 const dgf::DomainData *data = boundaryDomainBlock_->contains( corners );
101 if( data )
102 return data->parameter();
103 else
105 }
106 else
108 }
109
110
111 template< class Entity >
112 std::vector< double > &parameter ( const Entity &entity )
113 {
114 return emptyParam;
115 }
116
117 private:
118 void generate( std::istream &gridin, MPICommunicatorType comm );
119
120 template< class Geometry >
121 static void getCorners ( const Geometry &geometry, std::vector< Point > &corners )
122 {
123 corners.resize( geometry.corners() );
124 for( int i = 0; i < geometry.corners(); ++i )
125 {
126 const typename Geometry::GlobalCoordinate corner = geometry.corner( i );
127 for( int j = 0; j < dimension; ++j )
128 corners[ i ][ j ] = corner[ j ];
129 }
130 }
131
132 Grid *grid_;
133 dgf::BoundaryDomBlock *boundaryDomainBlock_;
134 std::vector< double > emptyParam;
135 };
136
137
138
139 template< int dim, int dimworld, class ctype >
140 inline void DGFGridFactory< SGrid< dim, dimworld, ctype > >
141 ::generate ( std::istream &gridin, MPICommunicatorType comm )
142 {
143 dgf::IntervalBlock intervalBlock( gridin );
144
145 if( !intervalBlock.isactive() )
146 DUNE_THROW( DGFException, "SGrid can only be created from an interval block." );
147
148 if( intervalBlock.numIntervals() != 1 )
149 DUNE_THROW( DGFException, "SGrid can only handle 1 interval block." );
150
151 if( intervalBlock.dimw() != dim )
152 {
153 DUNE_THROW( DGFException,
154 "Cannot read an interval of dimension " << intervalBlock.dimw()
155 << "into a SGrid< " << dim << ", " << dimworld << " >." );
156 }
157
158 const dgf::IntervalBlock::Interval &interval = intervalBlock.get( 0 );
159
160 FieldVector< double, dimension > lower, upper;
162 for( int i = 0; i < dimension; ++i )
163 {
164 lower[ i ] = interval.p[ 0 ][ i ];
165 upper[ i ] = interval.p[ 1 ][ i ];
166 anz[ i ] = interval.n[ i ];
167 }
168
169 grid_ = new Grid( anz, lower, upper );
170
171 boundaryDomainBlock_ = new dgf::BoundaryDomBlock( gridin, dimension );
172 }
173
174
175
176 template< int dim, int dimworld, class ctype >
177 struct DGFGridInfo< SGrid< dim, dimworld, ctype > >
178 {
179 static int refineStepsForHalf ()
180 {
181 return 1;
182 }
183
184 static double refineWeight ()
185 {
186 return 1.0 / double( 1 << dim );
187 }
188 };
189
190}
191#endif // #ifndef DUNE_DGFS_HH
FieldVector< ctype, cdim > GlobalCoordinate
type of the global coordinates
Definition: geometry.hh:104
@ 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_THROW(E, m)
Definition: exceptions.hh:243
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
static double refineWeight()
static int refineStepsForHalf()
number of globalRefine steps needed to refuce h by 0.5
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)