dune-grid-glue 2.5-git
overlappingmerge.cc
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_GRIDGLUE_OVERLAPPINGMERGE_CC
5#define DUNE_GRIDGLUE_OVERLAPPINGMERGE_CC
6//#include <algorithm>
7
8namespace Dune {
9namespace GridGlue {
10
11template<int dim1, int dim2, int dimworld, typename T>
12bool OverlappingMerge<dim1,dim2,dimworld, T>::inPlane(std::vector<FieldVector<T,dimworld> >& points) {
13
14 T eps = 1e-8;
15
16 assert(dim1 == 3 && dim2 == 3 && dimworld == 3);
17 assert(points.size() == 4);
18
19 FieldVector<T,dimworld> v1 = points[1]-points[0];
20 FieldVector<T,dimworld> v2 = points[2]-points[0];
21 FieldVector<T,dimworld> v3 = points[3]-points[0];
22
23 FieldVector<T,dimworld> v1xv2;
24 v1xv2[0] = v1[1]*v2[2] - v1[2]*v2[1];
25 v1xv2[1] = v1[2]*v2[0] - v1[0]*v2[2];
26 v1xv2[2] = v1[0]*v2[1] - v1[1]*v2[0];
27
28 return (std::abs(v3.dot(v1xv2)) < eps);
29}
30
31template<int dim1, int dim2, int dimworld, typename T>
32void OverlappingMerge<dim1,dim2,dimworld, T>::computeIntersections(const Dune::GeometryType& grid1ElementType,
33 const std::vector<Dune::FieldVector<T,dimworld> >& grid1ElementCorners,
34 std::bitset<(1<<dim1)>& neighborIntersects1,
35 unsigned int grid1Index,
36 const Dune::GeometryType& grid2ElementType,
37 const std::vector<Dune::FieldVector<T,dimworld> >& grid2ElementCorners,
38 std::bitset<(1<<dim2)>& neighborIntersects2,
39 unsigned int grid2Index,
40 std::vector<RemoteSimplicialIntersection>& intersections)
41{
42 using std::min;
43
44 this->counter++;
45 intersections.clear();
46
48
49#ifndef NDEBUG
50 const Dune::ReferenceElement<T,dim1>& refElement1 = Dune::ReferenceElements<T,dim1>::general(grid1ElementType);
51 const Dune::ReferenceElement<T,dim2>& refElement2 = Dune::ReferenceElements<T,dim2>::general(grid2ElementType);
52
53 // A few consistency checks
54 assert((unsigned int)(refElement1.size(dim1)) == grid1ElementCorners.size());
55 assert((unsigned int)(refElement2.size(dim2)) == grid2ElementCorners.size());
56#endif
57
58 // Make generic geometries representing the grid1- and grid2 element.
59 // this eases computation of local coordinates.
60 typedef MultiLinearGeometry<T,dim1,dimworld> Geometry1;
61 typedef MultiLinearGeometry<T,dim2,dimworld> Geometry2;
62
63 Geometry1 grid1Geometry(grid1ElementType, grid1ElementCorners);
64 Geometry2 grid2Geometry(grid2ElementType, grid2ElementCorners);
65
66 // Dirty workaround for the intersection computation scaling problem (part 1/2)
67 std::vector<Dune::FieldVector<T,dimworld> > scaledGrid1ElementCorners(grid1ElementCorners.size());
68 std::vector<Dune::FieldVector<T,dimworld> > scaledGrid2ElementCorners(grid2ElementCorners.size());
69
70 // the scaling parameter is the length minimum of the lengths of the first edge in the grid1 geometry
71 // and the first edge in the grid2 geometry
72 T scaling = min((grid1ElementCorners[0] - grid1ElementCorners[1]).two_norm(),
73 (grid2ElementCorners[0] - grid2ElementCorners[1]).two_norm());
74
75 // scale the coordinates according to scaling parameter
76 for (unsigned int i = 0; i < grid1ElementCorners.size(); ++i) {
77 scaledGrid1ElementCorners[i] = grid1ElementCorners[i];
78 scaledGrid1ElementCorners[i] *= (1.0/scaling);
79 }
80 for (unsigned int i = 0; i < grid2ElementCorners.size(); ++i) {
81 scaledGrid2ElementCorners[i] = grid2ElementCorners[i];
82 scaledGrid2ElementCorners[i] *= (1.0/scaling);
83 }
84
85 // get size_type for all the vectors we are using
86 typedef typename std::vector<Empty>::size_type size_type;
87
88 const int dimis = dim1 < dim2 ? dim1 : dim2;
89 const size_type n_intersectionnodes = dimis+1;
90 size_type i;
91
92 std::vector<FieldVector<T,dimworld> > scaledP(0), P(0);
93 std::vector<std::vector<int> > H,SX(1<<dim1),SY(1<<dim2);
94 FieldVector<T,dimworld> centroid;
95 // local grid1 coordinates of the intersections
96 std::vector<FieldVector<T,dim1> > g1local(n_intersectionnodes);
97 // local grid2 coordinates of the intersections
98 std::vector<FieldVector<T,dim2> > g2local(n_intersectionnodes);
99
100 // compute the intersection nodes
101 IntersectionComputation<CM>::computeIntersection(scaledGrid1ElementCorners,
102 scaledGrid2ElementCorners,
103 SX,SY,scaledP);
104
105 // Dirty workaround - rescale the result (part 2/2)
106 P.resize(scaledP.size());
107 for (unsigned int i = 0; i < scaledP.size(); ++i) {
108 P[i] = scaledP[i];
109 P[i] *= scaling;
110 }
111
112 for (size_type i = 0; i < neighborIntersects1.size(); ++i) {
113 if (i < SX.size())
114 neighborIntersects1[i] = (SX[i].size() > 0);
115 else
116 neighborIntersects1[i] = false;
117 }
118 for (size_type i = 0; i < neighborIntersects2.size(); ++i) {
119 if (i < SY.size())
120 neighborIntersects2[i] = (SY[i].size() > 0);
121 else
122 neighborIntersects2[i] = false;
123 }
124
125 // P is an simplex of dimension dimis
126 if (P.size() == n_intersectionnodes) {
127
128 for (i = 0; i < n_intersectionnodes; ++i) {
129 g1local[i] = grid1Geometry.local(P[i]);
130 g2local[i] = grid2Geometry.local(P[i]);
131 }
132
133 intersections.push_back(RemoteSimplicialIntersection(grid1Index, grid2Index));
134 for (i = 0; i < n_intersectionnodes; ++i) {
135 intersections.back().grid1Local_[0][i] = g1local[i];
136 intersections.back().grid2Local_[0][i] = g2local[i];
137 }
138
139 } else if (P.size() > n_intersectionnodes) { // P is a union of simplices of dimension dimis
140
141 assert(dimis != 1);
142 std::vector<FieldVector<T,dimworld> > global(n_intersectionnodes);
143
144 // Compute the centroid
145 centroid=0;
146 for (size_type i=0; i < P.size(); i++)
147 centroid += P[i] ;
148 centroid /= static_cast<T>(P.size()) ;
149
150 // order the points and get intersection face indices
151 H.clear() ;
152 IntersectionComputation<CM>::template orderPoints<dimis,dimworld>(centroid,SX,SY,P,H);
153
154 // Loop over all intersection elements
155 for (size_type i=0; i < H.size(); i++) {
156 int hs = H[i].size(); // number of nodes of the intersection
157
158 // if the intersection element is not degenerated
159 if (hs==dimis) {
160
161 // create the intersection geometry
162 for ( size_type j=0 ; j < dimis; ++j) {
163 global[j]= P[H[i][j]]; // get the intersection face
164 }
165
166 // intersection face + centroid = new element
167 global[dimis]=centroid;
168
169 // create local representation of the intersection
170 for (size_type j = 0; j < n_intersectionnodes; ++j) {
171 g1local[j] = grid1Geometry.local(global[j]);
172 g2local[j] = grid2Geometry.local(global[j]);
173 }
174
175 intersections.push_back(RemoteSimplicialIntersection(grid1Index,grid2Index));
176 for (size_type j = 0; j < n_intersectionnodes; ++j) {
177 intersections.back().grid1Local_[0][j] = g1local[j];
178 intersections.back().grid2Local_[0][j] = g2local[j];
179 }
180 }
181 }
182 }
183}
184
185} /* namespace Dune::GridGlue */
186} /* namespace Dune */
187
188#endif // DUNE_GRIDGLUE_OVERLAPPINGMERGE_CC
Definition gridglue.hh:30
IteratorRange<... > intersections(const GridGlue<... > &glue, const Reverse<... > &reverse=!reversed)
Iterate over all intersections of a GridGlue.
Intersection computation method for two elements of arbitrary dimension.
Definition computeintersection.hh:37
static bool computeIntersection(const std::vector< V > X, const std::vector< V > Y, std::vector< std::vector< int > > &SX, std::vector< std::vector< int > > &SY, std::vector< V > &P)
Compute the intersection of two elements X and Y Compute the intersection of two elements X and Y,...
Definition computeintersection.cc:12
void computeIntersections(const Dune::GeometryType &grid1ElementType, const std::vector< Dune::FieldVector< T, dimworld > > &grid1ElementCorners, std::bitset<(1<< dim1)> &neighborIntersects1, unsigned int grid1Index, const Dune::GeometryType &grid2ElementType, const std::vector< Dune::FieldVector< T, dimworld > > &grid2ElementCorners, std::bitset<(1<< dim2)> &neighborIntersects2, unsigned int grid2Index, std::vector< RemoteSimplicialIntersection > &intersections)
Compute the intersection between two overlapping elements.
Definition overlappingmerge.cc:32
Definition simplexintersection.cc:28