ug4
normal_calculation_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-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__UG_NORMAL_CALCULATION_IMPL__
34 #define __H__UG_NORMAL_CALCULATION_IMPL__
35 
36 #include "normal_calculation.h"
38 #include "common/math/ugmath.h"
39 
40 namespace ug{
41 
42 template <class TAAPos>
43 inline typename TAAPos::ValueType
44 CalculateOuterNormal(Vertex* v, int sideIndex, TAAPos aaPos)
45 {
46  typename TAAPos::ValueType n;
47  VecSet(n, 0);
48  return n;
49 }
50 
51 template <class TAAPos>
52 inline typename TAAPos::ValueType
53 CalculateOuterNormal(Edge* e, int sideIndex, TAAPos aaPos)
54 {
55  typename TAAPos::ValueType n;
56  VecSubtract(n, aaPos[e->vertex(sideIndex)],
57  aaPos[e->vertex((sideIndex + 1) % 2)]);
58  VecNormalize(n, n);
59  return n;
60 }
61 
62 template <class TAAPos>
63 inline typename TAAPos::ValueType
64 CalculateOuterNormal(Face* f, int sideIndex, TAAPos aaPos)
65 {
66  typename TAAPos::ValueType c, n;
67  c = CalculateCenter(f, aaPos);
68  EdgeDescriptor ed;
69  f->edge_desc(sideIndex, ed);
70 
71  DropAPerpendicular(n, c, aaPos[ed.vertex(0)], aaPos[ed.vertex(1)]);
72  VecSubtract(n, n, c);
73  VecNormalize(n, n);
74  return n;
75 }
76 
77 template <class TAAPos>
78 inline typename TAAPos::ValueType
79 CalculateOuterNormal(Volume* v, int sideIndex, TAAPos aaPos)
80 {
81  typename TAAPos::ValueType n;
82  FaceDescriptor fd;
83  v->face_desc(sideIndex, fd);
84  CalculateNormal(n, &fd, aaPos);
85  return n;
86 }
87 
88 template <class TAAPos>
89 inline typename TAAPos::ValueType
90 CalculateOuterNormal(GridObject* o, int sideIndex, TAAPos aaPos)
91 {
92  int baseObjId = o->base_object_id();
93  switch(baseObjId){
94  case VERTEX:
95  return CalculateOuterNormal(static_cast<Vertex*>(o), sideIndex, aaPos);
96  case EDGE:
97  return CalculateOuterNormal(static_cast<Edge*>(o), sideIndex, aaPos);
98  case FACE:
99  return CalculateOuterNormal(static_cast<Face*>(o), sideIndex, aaPos);
100  case VOLUME:
101  return CalculateOuterNormal(static_cast<Volume*>(o), sideIndex, aaPos);
102  }
103  UG_THROW("Unsupported base object id in CalculateOuterNormal");
104 }
105 
106 
107 inline vector2
110 {
111  vector2 d;
112  VecSubtract(d, aaPos[edge->vertex(1)], aaPos[edge->vertex(0)]);
113  VecNormalize(d, d);
114  return vector2(d.y(), -d.x());
115 }
116 
117 
118 inline vector3
121 {
122  vector3 n;
123  CalculateNormal(n, face, aaPos);
124  return n;
125 }
126 
127 }// end of namespace
128 
129 #endif
A generic specialization of IAttachment.
Definition: attachment_pipe.h:263
Can be used to store information about an edge and to construct an edge.
Definition: grid_base_objects.h:464
Base-class for edges.
Definition: grid_base_objects.h:397
holds the vertices of an Edge or an EdgeDescriptor.
Definition: grid_base_objects.h:362
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:366
Can be queried for the edges and vertices of a face.
Definition: grid_base_objects.h:684
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
virtual EdgeDescriptor edge_desc(int index) const
returns the i-th edge of the face.
Definition: grid_base_objects.h:537
Definition: grid_base_objects.h:483
the generic attachment-accessor for access to grids attachment pipes.
Definition: grid.h:182
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
virtual int base_object_id() const =0
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
virtual FaceDescriptor face_desc(int index) const
Definition: grid_base_objects.h:784
int CalculateNormal(vector3 &vNormOut, Grid &grid, Edge *e, Grid::AttachmentAccessor< Vertex, APosition > &aaPos, Grid::AttachmentAccessor< Face, ANormal > *paaNormFACE)
Calculates the normal of the given edge.
Definition: edge_util.cpp:314
TAAPos::ValueType CalculateOuterNormal(Vertex *v, int sideIndex, TAAPos aaPos)
Calculates the outer normal of the i-th side of the given grid object.
Definition: normal_calculation_impl.h:44
#define UG_THROW(msg)
Definition: error.h:57
number DropAPerpendicular(vector_t &vOut, const vector_t &v, const vector_t &v0, const vector_t &v1)
finds the projection of v onto the line defined by v0 and v1
Definition: math_util_impl.hpp:123
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
MathVector< 2, number > vector2
a 2d vector
Definition: ugmath_types.h:69
void VecSet(vector_t &vInOut, typename vector_t::value_type s)
Set each vector component to scalar (componentwise)
Definition: math_vector_functions_common_impl.hpp:539
void VecNormalize(vector_t &vOut, const vector_t &v)
scales a vector_t to unit length
Definition: math_vector_functions_common_impl.hpp:501
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition: math_vector_functions_common_impl.hpp:226
MathVector< 3, number > vector3
a 3d vector
Definition: ugmath_types.h:72
the ug namespace
@ VOLUME
Definition: grid_base_objects.h:63
@ VERTEX
Definition: grid_base_objects.h:60
@ EDGE
Definition: grid_base_objects.h:61
@ FACE
Definition: grid_base_objects.h:62