ug4
volume_calculation_impl.hpp
Go to the documentation of this file.
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 
38 
39 namespace ug{
40 
41 
42 template <class TAAPos>
43 number CalculateVolume(Volume* elem, TAAPos aaPos)
44 {
45  switch (elem->reference_object_id()) {
46  case ROID_TETRAHEDRON:
47  return CalculateVolume(static_cast<Tetrahedron*>(elem), aaPos);
48  case ROID_PRISM:
49  return CalculateVolume(static_cast<Prism*>(elem), aaPos);
50  case ROID_PYRAMID:
51  return CalculateVolume(static_cast<Pyramid*>(elem), aaPos);
52  case ROID_HEXAHEDRON:
53  return CalculateVolume(static_cast<Hexahedron*>(elem), aaPos);
54  case ROID_OCTAHEDRON:
55  return CalculateVolume(static_cast<Octahedron*>(elem), aaPos);
56  default:
57  UG_THROW("Unknown volume type");
58  break;
59  }
60 
61  return NAN;
62 }
63 
64 template <class TAAPos>
65 number CalculateVolume(Tetrahedron* elem, TAAPos aaPos)
66 {
67  return CalculateTetrahedronVolume(aaPos[elem->vertex(0)],
68  aaPos[elem->vertex(1)],
69  aaPos[elem->vertex(2)],
70  aaPos[elem->vertex(3)]);
71 }
72 
73 template <class TAAPos>
74 number CalculateVolume(Pyramid* elem, TAAPos aaPos)
75 {
76  return CalculatePyramidVolume(aaPos[elem->vertex(0)],
77  aaPos[elem->vertex(1)],
78  aaPos[elem->vertex(2)],
79  aaPos[elem->vertex(3)],
80  aaPos[elem->vertex(4)]);
81 }
82 
83 template <class TAAPos>
84 number CalculateVolume(Prism* elem, TAAPos aaPos)
85 {
86  return CalculatePrismVolume(aaPos[elem->vertex(0)],
87  aaPos[elem->vertex(1)],
88  aaPos[elem->vertex(2)],
89  aaPos[elem->vertex(3)],
90  aaPos[elem->vertex(4)],
91  aaPos[elem->vertex(5)]);
92 }
93 
94 template <class TAAPos>
95 number CalculateVolume(Hexahedron* elem, TAAPos aaPos)
96 {
97  return CalculateHexahedronVolume(aaPos[elem->vertex(0)],
98  aaPos[elem->vertex(1)],
99  aaPos[elem->vertex(2)],
100  aaPos[elem->vertex(3)],
101  aaPos[elem->vertex(4)],
102  aaPos[elem->vertex(5)],
103  aaPos[elem->vertex(6)],
104  aaPos[elem->vertex(7)]);
105 }
106 
107 template <class TAAPos>
108 number CalculateVolume(Octahedron* elem, TAAPos aaPos)
109 {
110  return CalculateOctahedronVolume(aaPos[elem->vertex(0)],
111  aaPos[elem->vertex(1)],
112  aaPos[elem->vertex(2)],
113  aaPos[elem->vertex(3)],
114  aaPos[elem->vertex(4)],
115  aaPos[elem->vertex(5)]);
116 }
117 
118 template <class TAAPos>
119 number CalculateVolume(FaceVertices* elem, TAAPos aaPos)
120 {
121  return FaceArea(elem, aaPos);
122 }
123 
124 
125 template <class TAAPos>
126 number CalculateVolume(EdgeVertices* elem, TAAPos aaPos)
127 {
128  return EdgeLength(elem, aaPos);
129 }
130 
131 template <class 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 
148 template<int dim>
149 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  for(size_t ii = 1; ii < npoints; ++ii)
156  {
157  for(int i = 0; i < dim; ++i)
158  {
159  const MathVector<dim>& v = points[ii];
160  if(v[i] < vMinBB[i]) vMinBB[i] = v[i];
161  else if(v[i] > vMaxBB[i]) vMaxBB[i] = v[i];
162  }
163  }
164 }
165 
166 }// end of namespace
167 
168 #endif
holds the vertices of an Edge or an EdgeDescriptor.
Definition: grid_base_objects.h:362
Definition: grid_base_objects.h:483
A volume element with 6 quadrilateral sides.
Definition: grid_objects_3d.h:227
virtual Vertex * vertex(size_t index) const
Definition: grid_objects_3d.h:243
platonic solid with eight faces.
Definition: grid_objects_3d.h:626
virtual Vertex * vertex(size_t index) const
Definition: grid_objects_3d.h:641
A volume element with 2 triangle and 3 quadrilateral sides.
Definition: grid_objects_3d.h:360
virtual Vertex * vertex(size_t index) const
Definition: grid_objects_3d.h:376
A volume element with 4 triangle and 1 quadrilateral sides.
Definition: grid_objects_3d.h:493
virtual Vertex * vertex(size_t index) const
Definition: grid_objects_3d.h:509
the most simple volume-element.
Definition: grid_objects_3d.h:91
virtual Vertex * vertex(size_t index) const
Definition: grid_objects_3d.h:106
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
virtual ReferenceObjectID reference_object_id() const
Definition: grid_base_objects.h:927
static number FaceArea(TDomain &dom, ISubsetHandler &sh, int si, size_t lvl)
Definition: domain_bridge.cpp:262
UG_API number EdgeLength(const EdgeVertices *e, TAAPosVRT &aaPos)
Calculates the length of the given edge.
Definition: edge_util_impl.hpp:80
number CalculateVolume(Volume *elem, TAAPos aaPos)
Calculates the volume of the given element.
Definition: volume_calculation_impl.hpp:43
static const int dim
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
number CalculateTetrahedronVolume(const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d)
Definition: math_util.cpp:440
number CalculateOctahedronVolume(const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d, const vector3 &e, const vector3 &f)
Definition: math_util.cpp:525
number CalculatePyramidVolume(const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d, const vector3 &e)
Definition: math_util.cpp:465
number CalculatePrismVolume(const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d, const vector3 &e, const vector3 &f)
Definition: math_util.cpp:485
number CalculateHexahedronVolume(const vector3 &a, const vector3 &b, const vector3 &c, const vector3 &d, const vector3 &e, const vector3 &f, const vector3 &g, const vector3 &h)
Definition: math_util.cpp:503
the ug namespace
@ ROID_TETRAHEDRON
Definition: grid_base_objects.h:80
@ ROID_PYRAMID
Definition: grid_base_objects.h:83
@ ROID_PRISM
Definition: grid_base_objects.h:82
@ ROID_OCTAHEDRON
Definition: grid_base_objects.h:84
@ ROID_HEXAHEDRON
Definition: grid_base_objects.h:81
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