Dune Core Modules (2.5.2)

dgfgridfactory.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_DGF_GRIDFACTORY_HH
4#define DUNE_DGF_GRIDFACTORY_HH
5
6#include <iostream>
7#include <string>
8#include <vector>
9#include <map>
10#include <assert.h>
11
13#include <dune/grid/io/file/dgfparser/dgfexception.hh>
14#include <dune/grid/io/file/dgfparser/macrogrid.hh>
15
16#include <dune/grid/io/file/dgfparser/parser.hh>
17#include <dune/grid/common/intersection.hh>
18
19
20namespace Dune
21{
22
23 // External Forward Declarations
24 // -----------------------------
25
26 template < class GridImp, class IntersectionImp >
27 class Intersection;
28
29
30
31 // DGFGridFactory
32 // --------------
33
34 template < class G >
35 struct DGFGridFactory
36 {
37 typedef G Grid;
38 const static int dimension = Grid::dimension;
39 typedef MPIHelper::MPICommunicator MPICommunicatorType;
40
41 private:
42 typedef typename Grid::template Codim< 0 >::Entity Element;
43
44 typedef typename Grid::template Codim< dimension >::Entity Vertex;
45
46 public:
47 explicit DGFGridFactory ( std::istream &input,
48 MPICommunicatorType comm = MPIHelper::getCommunicator() ) DUNE_DEPRECATED
49 : macroGrid_( comm )
50 {
51 DUNE_THROW( DGFException, "DGF factories using old MacroGrid implementation"
52 "don't support creation from std::istream." );
53 }
54
55 explicit DGFGridFactory ( const std::string &filename,
56 MPICommunicatorType comm = MPIHelper::getCommunicator() ) DUNE_DEPRECATED
57 : macroGrid_( filename.c_str(), comm )
58 {
59 grid_ = macroGrid_.template createGrid< Grid >();
60
61 if( macroGrid_.nofelparams > 0 )
62 {
63 const size_t nofElements = macroGrid_.elements.size();
64 for( size_t i = 0; i < nofElements; ++i )
65 {
66 std::vector< double > coord;
67
68 DomainType p(0);
69 const size_t nofCorners = macroGrid_.elements[i].size();
70 for (size_t k=0; k<nofCorners; ++k)
71 for (int j=0; j<DomainType::dimension; ++j)
72 p[j]+=macroGrid_.vtx[macroGrid_.elements[i][k]][j];
73 p/=double(nofCorners);
74
75 elInsertOrder_.insert( std::make_pair( p, i ) );
76 }
77 }
78
79 if( macroGrid_.nofvtxparams > 0 )
80 {
81 const size_t nofVertices = macroGrid_.vtx.size();
82 for( size_t i = 0; i < nofVertices; ++i )
83 {
84 std::vector< double > coord;
85
86 DomainType p;
87 for( int k = 0; k < DomainType::dimension; ++k )
88 p[ k ] = macroGrid_.vtx[i][k];
89
90 vtxInsertOrder_.insert( std::make_pair( p, i ) );
91 }
92 }
93 }
94
95 Grid *grid()
96 {
97 return grid_;
98 }
99
100 template <class Intersection>
101 bool wasInserted(const Intersection &intersection) const
102 {
103 return intersection.boundary();
104 }
105
106 template <class Intersection>
107 int boundaryId(const Intersection &intersection) const
108 {
109#if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS
110 return intersection.boundaryId();
111#else
112 return (intersection.boundary()) ? int(intersection.indexInInside()+1) : int(0);
113#endif
114 }
115
116 template< int codim >
117 int numParameters () const
118 {
119 if( codim == 0 )
120 return macroGrid_.nofelparams;
121 else if( codim == dimension )
122 return macroGrid_.nofvtxparams;
123 else
124 return 0;
125 }
126
127 template < class Entity >
128 int numParameters ( const Entity & ) const
129 {
130 return numParameters< Entity::codimension >();
131 }
132
133 std::vector<double>& parameter(const Element &element)
134 {
135 const typename Element::Geometry &geo = element.geometry();
136 DomainType coord( geo.corner( 0 ) );
137 for( int i = 1; i < geo.corners(); ++i )
138 coord += geo.corner( i );
139 coord /= double( geo.corners() );
140
141 InsertOrderIterator it = elInsertOrder_.find( coord );
142 if( it != elInsertOrder_.end() )
143 return macroGrid_.elParams[ it->second ];
144 assert(0);
145 return emptyParam;
146 }
147
148 std::vector<double>& parameter(const Vertex &vertex)
149 {
150 const typename Vertex::Geometry &geo = vertex.geometry();
151 DomainType coord( geo.corner( 0 ) );
152
153 InsertOrderIterator it = vtxInsertOrder_.find( coord );
154 if( it != vtxInsertOrder_.end() )
155 return macroGrid_.vtxParams[ it->second ];
156 return emptyParam;
157 }
158
159 // return true if boundary parameters found
160 bool haveBoundaryParameters () const
161 {
162 return false;
163 }
164
165 template< class GG, class II >
166 const typename DGFBoundaryParameter::type &
167 boundaryParameter ( const Intersection< GG, II > & intersection ) const
168 {
170 }
171
172 private:
173 typedef FieldVector<typename Grid::ctype,Grid::dimensionworld> DomainType;
174 struct Compare
175 {
176 bool operator() ( const DomainType &a, const DomainType &b ) const
177 {
178 // returns true, if a < b; c[i] < -eps;
179 const DomainType c = a - b;
180 const double eps = 1e-8;
181
182 for( int i = 0; i < DomainType::dimension; ++i )
183 {
184 if( c[ i ] <= -eps )
185 return true;
186 if( c[ i ] >= eps )
187 return false;
188 }
189 return false;
190 }
191 };
192 typedef std::map< DomainType, size_t, Compare > InsertOrderMap;
193 typedef typename InsertOrderMap::const_iterator InsertOrderIterator;
194
195 MacroGrid macroGrid_;
196 Grid *grid_;
197 InsertOrderMap elInsertOrder_;
198 InsertOrderMap vtxInsertOrder_;
199 std::vector<double> emptyParam;
200 };
201
202} // end namespace Dune
203
204#endif
@ dimension
The size of this vector.
Definition: fvector.hh:100
@ dimension
The dimension of the grid.
Definition: grid.hh:387
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_DEPRECATED
Mark some entity as deprecated.
Definition: deprecated.hh:84
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Helpers for dealing with MPI.
Dune namespace.
Definition: alignment.hh:11
static const type & defaultValue()
default constructor
Definition: parser.hh:26
std::string type
type of additional boundary parameters
Definition: parser.hh:23
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)