Line data Source code
1 : /*
2 : * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 : * Authors: Sebastian Reiter, Martin Stepniewski, Martin Scherer
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__UG__volume_calculation_impl__
34 : #define __H__UG__volume_calculation_impl__
35 :
36 : #include "common/math/misc/math_util.h"
37 : #include "geom_obj_util/face_util.h"
38 :
39 : namespace ug{
40 :
41 :
42 : template <class TAAPos>
43 0 : number CalculateVolume(Volume* elem, TAAPos aaPos)
44 : {
45 0 : switch (elem->reference_object_id()) {
46 : case ROID_TETRAHEDRON:
47 0 : return CalculateVolume(static_cast<Tetrahedron*>(elem), aaPos);
48 : case ROID_PRISM:
49 0 : return CalculateVolume(static_cast<Prism*>(elem), aaPos);
50 : case ROID_PYRAMID:
51 0 : return CalculateVolume(static_cast<Pyramid*>(elem), aaPos);
52 : case ROID_HEXAHEDRON:
53 0 : return CalculateVolume(static_cast<Hexahedron*>(elem), aaPos);
54 : case ROID_OCTAHEDRON:
55 0 : return CalculateVolume(static_cast<Octahedron*>(elem), aaPos);
56 0 : default:
57 0 : UG_THROW("Unknown volume type");
58 : break;
59 : }
60 :
61 : return NAN;
62 : }
63 :
64 : template <class TAAPos>
65 0 : number CalculateVolume(Tetrahedron* elem, TAAPos aaPos)
66 : {
67 0 : return CalculateTetrahedronVolume(aaPos[elem->vertex(0)],
68 0 : aaPos[elem->vertex(1)],
69 0 : aaPos[elem->vertex(2)],
70 0 : aaPos[elem->vertex(3)]);
71 : }
72 :
73 : template <class TAAPos>
74 0 : number CalculateVolume(Pyramid* elem, TAAPos aaPos)
75 : {
76 0 : return CalculatePyramidVolume(aaPos[elem->vertex(0)],
77 0 : aaPos[elem->vertex(1)],
78 0 : aaPos[elem->vertex(2)],
79 0 : aaPos[elem->vertex(3)],
80 0 : aaPos[elem->vertex(4)]);
81 : }
82 :
83 : template <class TAAPos>
84 0 : number CalculateVolume(Prism* elem, TAAPos aaPos)
85 : {
86 0 : return CalculatePrismVolume(aaPos[elem->vertex(0)],
87 0 : aaPos[elem->vertex(1)],
88 0 : aaPos[elem->vertex(2)],
89 0 : aaPos[elem->vertex(3)],
90 0 : aaPos[elem->vertex(4)],
91 0 : aaPos[elem->vertex(5)]);
92 : }
93 :
94 : template <class TAAPos>
95 0 : number CalculateVolume(Hexahedron* elem, TAAPos aaPos)
96 : {
97 0 : return CalculateHexahedronVolume(aaPos[elem->vertex(0)],
98 0 : aaPos[elem->vertex(1)],
99 0 : aaPos[elem->vertex(2)],
100 0 : aaPos[elem->vertex(3)],
101 0 : aaPos[elem->vertex(4)],
102 0 : aaPos[elem->vertex(5)],
103 0 : aaPos[elem->vertex(6)],
104 0 : aaPos[elem->vertex(7)]);
105 : }
106 :
107 : template <class TAAPos>
108 0 : number CalculateVolume(Octahedron* elem, TAAPos aaPos)
109 : {
110 0 : return CalculateOctahedronVolume(aaPos[elem->vertex(0)],
111 0 : aaPos[elem->vertex(1)],
112 0 : aaPos[elem->vertex(2)],
113 0 : aaPos[elem->vertex(3)],
114 0 : aaPos[elem->vertex(4)],
115 0 : aaPos[elem->vertex(5)]);
116 : }
117 :
118 : template <class TAAPos>
119 : number CalculateVolume(FaceVertices* elem, TAAPos aaPos)
120 : {
121 0 : return FaceArea(elem, aaPos);
122 : }
123 :
124 :
125 : template <class TAAPos>
126 : number CalculateVolume(EdgeVertices* elem, TAAPos aaPos)
127 : {
128 0 : return EdgeLength(elem, aaPos);
129 : }
130 :
131 : template <class TAAPos>
132 : number CalculateVolume(Vertex*, TAAPos)
133 : {
134 : return 0;
135 : }
136 :
137 : template <class TIterator, class TAAPos>
138 : number CalculateVolume(TIterator begin, TIterator end, TAAPos aaPos)
139 : {
140 : number totalVolume = 0;
141 : for(TIterator iter = begin; iter != end; ++iter){
142 : totalVolume += CalculateVolume(*iter, aaPos);
143 : }
144 : return totalVolume;
145 : }
146 :
147 : //! Determine the bounding box for a set of points.
148 : template<int dim>
149 0 : void CalculateBoundingBox(size_t npoints, const MathVector<dim> points[], MathVector<dim> &vMinBB, MathVector<dim> &vMaxBB)
150 : {
151 : // determine bounding box
152 : vMinBB= points[0];
153 : vMaxBB = points[0];
154 :
155 0 : for(size_t ii = 1; ii < npoints; ++ii)
156 : {
157 0 : for(int i = 0; i < dim; ++i)
158 : {
159 0 : const MathVector<dim>& v = points[ii];
160 0 : if(v[i] < vMinBB[i]) vMinBB[i] = v[i];
161 0 : else if(v[i] > vMaxBB[i]) vMaxBB[i] = v[i];
162 : }
163 : }
164 0 : }
165 :
166 : }// end of namespace
167 :
168 : #endif
|