ug4
misc_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__LIB_GRID__MISC_UTIL__
34 #define __H__LIB_GRID__MISC_UTIL__
35 
36 #include "lib_grid/grid/grid.h"
39 
40 namespace ug
41 {
53 template <class TElem>
54 UG_API
55 typename TElem::side*
56 GetSharedSide(Grid& grid, TElem* e1, TElem* e2);
57 
58 
60 // CalculateGridObjectCenter
62 template<class TAAPosVRT>
63 UG_API
64 inline
65 typename TAAPosVRT::ValueType
66 CalculateGridObjectCenter(const GridObject* o, TAAPosVRT& aaPosVRT);
67 
68 
71 
74 template<class TAAPosVRT, class TAAWeightVRT>
75 UG_API
76 inline
77 typename TAAPosVRT::ValueType
78 CalculateGridObjectCenter(const GridObject* o, TAAPosVRT& aaPosVRT,
79  TAAWeightVRT& aaWeight);
80 
82 // CalculateCenter
84 
87 template <class TIterator, class TAAPosVRT>
88 UG_API
89 typename TAAPosVRT::ValueType
90 CalculateCenter(TIterator begin, TIterator end, TAAPosVRT& aaPos);
91 
93 // FindClosestByCoordinate
95 
104 template<class TElem, class TVertexPositionAttachmentAccessor>
105 UG_API
106 TElem* FindClosestByCoordinate(const typename TVertexPositionAttachmentAccessor::ValueType& coord,
107  typename geometry_traits<TElem>::iterator iterBegin,
108  typename geometry_traits<TElem>::iterator iterEnd,
109  TVertexPositionAttachmentAccessor& aaPosVRT);
110 
113 
118 template<class vector_t, class TIterator, class TAAPos>
119 UG_API
120 void CalculateBoundingBox(vector_t& vMinOut, vector_t& vMaxOut,
121  TIterator begin, TIterator end,
122  TAAPos& aaPos);
123 
125 // NumSharedVertices
127 
132 template <class TElemPtr1, class TElemPtr2>
133 UG_API
134 size_t NumSharedVertices(Grid& grid, TElemPtr1 elem1, TElemPtr2 elem2);
135 
137 // EraseConnectingElements
139 UG_API
140 void EraseConnectingElements(Grid& grid, Vertex* v1, Vertex* v2);
141 
143 // EraseElements
145 template <class TElem>
146 UG_API
147 void EraseElements(Grid& grid, typename geometry_traits<TElem>::iterator iterBegin,
148  typename geometry_traits<TElem>::iterator iterEnd);
149 
151 // ElementDiameter
153 template <class TElem, class TAAPos>
154 number ElementDiameterSq(Grid& grid,
155  TAAPos& aaPos,
156  TElem* elem);
157 
159 template <class TAAPos>
160 number ElementDiameterSq(Grid& grid,
161  TAAPos& aaPos,
162  GridObject* elem);
163 
165 template <class TElem, class TAAPos>
166 number ElementDiameter(Grid& grid,
167  TAAPos& aaPos,
168  TElem* elem);
169 
171 
172 template <class TAAPos, class TIterator>
173 number MaxElementDiameter(Grid& grid, TAAPos& aaPos,
174  TIterator iterBegin, TIterator iterEnd);
175 
177 
178 template <class TAAPos, class TIterator>
179 number MinElementDiameter(Grid& grid, TAAPos& aaPos,
180  TIterator iterBegin, TIterator iterEnd);
181 
182 
184 template <class TElem1, class TElem2, class TAAPos>
185 typename TAAPos::ValueType
186 GetDirection (TElem1* e1, TElem2* e2, const TAAPos& aaPos);
187 
189 
192 template <class TElem1, class TElem2, class TAAPos>
193 bool CheckDirection (TElem1* e1,
194  TElem2* e2,
195  const TAAPos& aaPos,
196  const typename TAAPos::ValueType& dir,
197  number minAngle,
198  number maxAngle);
199 
200 
202 }// end of namespace
203 
205 // include implementation of template methods.
206 #include "misc_util_impl.hpp"
207 
208 #endif
number ElementDiameter(const TElem &elem, TDomain &domain)
returns the maximal distance between to element vertices
number ElementDiameterSq(const TElem &elem, TDomain &domain)
returns the maximal squared distance between to element vertices
number MinElementDiameter(TDomain &domain, int level)
returns the minimal diameter of all elements between iterBegin and iterEnd.
Definition: domain_util.cpp:113
number MaxElementDiameter(TDomain &domain, int level)
returns the maximal diameter of all elements between iterBegin and iterEnd.
Definition: domain_util.cpp:104
UG_API void EraseElements(Grid &grid, typename geometry_traits< TElem >::iterator iterBegin, typename geometry_traits< TElem >::iterator iterEnd)
erases all elements between iterBegin and iterEnd.
Definition: misc_util_impl.hpp:222
void EraseConnectingElements(Grid &grid, Vertex *v1, Vertex *v2)
erases all elements that connect v1 and v2
Definition: misc_util.cpp:42
UG_API TElem * FindClosestByCoordinate(const typename TVertexPositionAttachmentAccessor::ValueType &coord, typename geometry_traits< TElem >::iterator iterBegin, typename geometry_traits< TElem >::iterator iterEnd, TVertexPositionAttachmentAccessor &aaPosVRT)
returns the element of the given type, whose center is closest to coord.
Definition: misc_util_impl.hpp:136
TAAPos::ValueType GetDirection(TElem1 *e1, TElem2 *e2, const TAAPos &aaPos)
Returns the direction from the center of e1 to the center of e2.
Definition: misc_util_impl.hpp:326
UG_API TAAPosVRT::ValueType CalculateGridObjectCenter(const GridObject *o, TAAPosVRT &aaPosVRT)
calculates the center for arbitrary geometric object
Definition: misc_util_impl.hpp:81
UG_API size_t NumSharedVertices(Grid &grid, TElemPtr1 elem1, TElemPtr2 elem2)
returns the number of vertices that are shared by two objects
Definition: misc_util_impl.hpp:200
UG_API TElem::side * GetSharedSide(Grid &grid, TElem *e1, TElem *e2)
returns the shared side between the two elements or NULL if no such side exists.
Definition: misc_util_impl.hpp:52
bool CheckDirection(TElem1 *e1, TElem2 *e2, const TAAPos &aaPos, const typename TAAPos::ValueType &dir, number minAngle, number maxAngle)
Checks whether the center of e2 can be reached from the center of e1 in the given direction.
Definition: misc_util_impl.hpp:338
#define UG_API
Definition: ug_config.h:65
double number
Definition: types.h:124
void CalculateCenter(vector_t &centerOut, const vector_t *pointSet, size_t numPoints)
calculates the center of a point-set
Definition: math_util_impl.hpp:98
the ug namespace
AABox< typename TAAPos::ValueType > CalculateBoundingBox(Vertex *e, TAAPos aaPos)
calculates the smallest axis aligned box that contains the given vertex
Definition: bounding_box_util.h:43