Dune Core Modules (2.6.0)

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 return (intersection.boundary()) ? int(intersection.indexInInside()+1) : int(0);
110 }
111
112 template< int codim >
113 int numParameters () const
114 {
115 if( codim == 0 )
116 return macroGrid_.nofelparams;
117 else if( codim == dimension )
118 return macroGrid_.nofvtxparams;
119 else
120 return 0;
121 }
122
123 template < class Entity >
124 int numParameters ( const Entity & ) const
125 {
126 return numParameters< Entity::codimension >();
127 }
128
129 std::vector<double>& parameter(const Element &element)
130 {
131 const typename Element::Geometry &geo = element.geometry();
132 DomainType coord( geo.corner( 0 ) );
133 for( int i = 1; i < geo.corners(); ++i )
134 coord += geo.corner( i );
135 coord /= double( geo.corners() );
136
137 InsertOrderIterator it = elInsertOrder_.find( coord );
138 if( it != elInsertOrder_.end() )
139 return macroGrid_.elParams[ it->second ];
140 assert(0);
141 return emptyParam;
142 }
143
144 std::vector<double>& parameter(const Vertex &vertex)
145 {
146 const typename Vertex::Geometry &geo = vertex.geometry();
147 DomainType coord( geo.corner( 0 ) );
148
149 InsertOrderIterator it = vtxInsertOrder_.find( coord );
150 if( it != vtxInsertOrder_.end() )
151 return macroGrid_.vtxParams[ it->second ];
152 return emptyParam;
153 }
154
155 // return true if boundary parameters found
156 bool haveBoundaryParameters () const
157 {
158 return false;
159 }
160
161 template< class GG, class II >
162 const typename DGFBoundaryParameter::type &
163 boundaryParameter ( const Intersection< GG, II > & intersection ) const
164 {
166 }
167
168 private:
169 typedef FieldVector<typename Grid::ctype,Grid::dimensionworld> DomainType;
170 struct Compare
171 {
172 bool operator() ( const DomainType &a, const DomainType &b ) const
173 {
174 // returns true, if a < b; c[i] < -eps;
175 const DomainType c = a - b;
176 const double eps = 1e-8;
177
178 for( int i = 0; i < DomainType::dimension; ++i )
179 {
180 if( c[ i ] <= -eps )
181 return true;
182 if( c[ i ] >= eps )
183 return false;
184 }
185 return false;
186 }
187 };
188 typedef std::map< DomainType, size_t, Compare > InsertOrderMap;
189 typedef typename InsertOrderMap::const_iterator InsertOrderIterator;
190
191 MacroGrid macroGrid_;
192 Grid *grid_;
193 InsertOrderMap elInsertOrder_;
194 InsertOrderMap vtxInsertOrder_;
195 std::vector<double> emptyParam;
196 };
197
198} // end namespace Dune
199
200#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:178
static MPICommunicator getCommunicator()
get the default communicator
Definition: mpihelper.hh:186
#define DUNE_DEPRECATED
Mark some entity as deprecated.
Definition: deprecated.hh:84
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:727
Helpers for dealing with MPI.
Dune namespace.
Definition: alignedallocator.hh:10
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)