dune-fem 2.12-git
Loading...
Searching...
No Matches
pointprovider.cc
Go to the documentation of this file.
1// C++ includes
2#include <cassert>
3
4// dune-geometry includes
6
7// dune-fem includes
10
12
13namespace Dune
14{
15
16 namespace Fem
17 {
18
19 template <class ct, int dim>
20 void PointProvider<ct, dim, 0>::
21 registerQuadratureImpl(const QuadratureType& quad)
22 {
23 QuadratureKeyType key( quad.geometryType(), quad.id() );
24
25 if (points_.find( key ) == points_.end() )
26 {
27 // only register when in single thread mode
28 if( ! threadPool_.singleThreadMode() )
29 {
30 DUNE_THROW(SingleThreadModeError, "PointProvider::registerQuadrature: only call in single thread mode!");
31 }
32
33 PointIteratorType it =
34 points_.insert(std::make_pair
35 (key,
36 GlobalPointVectorType(quad.nop()))
37 ).first;
38 for (size_t i = 0; i < quad.nop(); ++i)
39 it->second[i] = quad.point(i);
40
41 // register quadrature to existing storages
43 }
44 }
45
46 template <class ct, int dim>
47 const typename PointProvider<ct, dim, 0>::GlobalPointVectorType&
48 PointProvider<ct, dim, 0>::getPointsImpl(const size_t id, const GeometryType& elementGeo)
49 {
50 QuadratureKeyType key( elementGeo, id );
51
52 typename PointContainerType::const_iterator pos = points_.find( key );
53#ifndef NDEBUG
54 if( pos == points_.end() )
55 {
56 std::cerr << "Unable to find quadrature points in list (key = " << key << ")." << std::endl;
57 for( pos = points_.begin(); pos != points_.end(); ++pos )
58 std::cerr << "found key: " << pos->first << std::endl;
59 std::cerr << "Aborting..." << std::endl;
60 abort();
61 }
62#endif
63 return pos->second;
64 }
65
66 template <class ct, int dim>
67 const typename PointProvider<ct, dim, 1>::MapperVectorPairType&
69 const GeometryType& elementGeo)
70 {
71 QuadratureKeyType key( elementGeo , quad.id() );
72
73 MapperIteratorType it = mappers_.find( key );
74 if (it == mappers_.end())
75 {
77 for (size_t i = 0; i < quad.nop(); ++i)
78 {
79 pts[i] = quad.point(i);
80 }
81 it = addEntryImpl(quad, pts, elementGeo);
82 }
83
84 return it->second;
85 }
86
87 template <class ct, int dim>
90 const LocalPointVectorType& pts,
91 const GeometryType& elementGeo)
92 {
93 QuadratureKeyType key( elementGeo, quad.id() );
94
95 MapperIteratorType it = mappers_.find( key );
96 if (it == mappers_.end()) {
97 it = addEntryImpl(quad, pts, elementGeo);
98 }
99
100 return it->second;
101 }
102
103 template <class ct, int dim>
105 PointProvider<ct, dim, 1>::getPointsImpl(const size_t id, const GeometryType& elementGeo)
106 {
107 QuadratureKeyType key( elementGeo, id );
108
109 assert(points_.find(key) != points_.end());
110 return points_.find(key)->second;
111 }
112
113 template <class ct, int dim>
115 PointProvider<ct, dim, 1>::addEntryImpl(const QuadratureType& quad,
116 const LocalPointVectorType& pts,
117 GeometryType elementGeo)
118 {
119 // only addEntry when in single thread mode
120 if( ! threadPool_.singleThreadMode() )
121 {
122 DUNE_THROW(SingleThreadModeError, "PointProvider::addEntry: only call in single thread mode!");
123 }
124
125 // generate key
126 QuadratureKeyType key ( elementGeo, quad.id() );
127
128 const auto &refElem = Dune::ReferenceElements<ct, dim>::general(elementGeo);
129
130 const int numLocalPoints = pts.size();
131 const int numFaces = refElem.size(codim);
132 const int numGlobalPoints = numFaces*numLocalPoints;
133
134 PointIteratorType pit =
135 points_.insert(std::make_pair(key,
136 GlobalPointVectorType(numGlobalPoints))).first;
137 MapperIteratorType mit =
138 mappers_.insert(std::make_pair(key,
139 std::make_pair(MapperVectorType(numFaces), MapperVectorType(numFaces) ))).first;
140
141 MapperIteratorType iit;
142 std::vector< GlobalPointType > itps = quad.interpolationPoints( dim );
143
144 int globalNum = 0;
145 const size_t nItp = itps.size();
146 for (int face = 0; face < numFaces; ++face)
147 {
148 // Assumption: all faces have the same type
149 // (not true for pyramids and prisms)
150 MapperType pMap(numLocalPoints);
151 MapperType itpMap(numLocalPoints);
152
153 MapperVectorPairType& map = mit->second;
154
155 for (int pt = 0; pt < numLocalPoints; ++pt, ++globalNum)
156 {
157 // Store point on reference element
158 pit->second[globalNum] =
159 refElem.template geometry<codim>(face).global( pts[pt] );
160
161 if( nItp > 0 )
162 {
163 // compare interpolation points with created point to get mapping
164 for( size_t i=0; i<nItp; ++i )
165 {
166 if( (itps[ i ] - pit->second[globalNum]).two_norm() < 1e-12 )
167 {
168 //std::cout << "found match for point " << itps[ i ] << " = ("<< i << "," << pt << ")" << std::endl;
169 itpMap[ pt ] = i;
170 }
171 }
172 }
173
174 // Store point mapping
175 pMap[pt] = globalNum;
176 }
177
178 map.first[face] = pMap; // = face*numLocalPoints+pt
179 if( nItp > 0 )
180 {
181 map.second[face] = itpMap; // = face*numLocalPoints+pt
182 }
183
184 } // end for all faces
185
186 // register quadrature to existing storages
188
189 return mit;
190 }
191
192 } // namespace Fem
193
194} // namespace Dune
size_type dim() const
#define DUNE_THROW(E,...)
Exception thrown when a code segment that is supposed to be only accessed in single thread mode is ac...
Definition mpimanager.hh:43
Definition pointmapper.hh:19
Definition pointprovider.hh:25
static void registerQuadrature(const Quadrature &quadrature)
Definition registry.hh:96
size_t id() const
obtain the identifier of the integration point list
Definition quadratureimp.hh:122
const CoordinateType & point(size_t i) const
obtain coordinates of i-th integration point
Definition quadratureimp.hh:96
size_t nop() const
obtain the number of integration points
Definition quadratureimp.hh:106
T abort(T... args)
T endl(T... args)
T make_pair(T... args)
T size(T... args)