Line data Source code
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"
37 : #include "geom_obj_util/face_util.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 0 : CalculateOuterNormal(Edge* e, int sideIndex, TAAPos aaPos)
54 : {
55 : typename TAAPos::ValueType n;
56 0 : VecSubtract(n, aaPos[e->vertex(sideIndex)],
57 0 : aaPos[e->vertex((sideIndex + 1) % 2)]);
58 0 : VecNormalize(n, n);
59 0 : return n;
60 : }
61 :
62 : template <class TAAPos>
63 : inline typename TAAPos::ValueType
64 0 : CalculateOuterNormal(Face* f, int sideIndex, TAAPos aaPos)
65 : {
66 : typename TAAPos::ValueType c, n;
67 0 : c = CalculateCenter(f, aaPos);
68 0 : EdgeDescriptor ed;
69 0 : f->edge_desc(sideIndex, ed);
70 :
71 0 : DropAPerpendicular(n, c, aaPos[ed.vertex(0)], aaPos[ed.vertex(1)]);
72 : VecSubtract(n, n, c);
73 0 : VecNormalize(n, n);
74 0 : return n;
75 : }
76 :
77 : template <class TAAPos>
78 : inline typename TAAPos::ValueType
79 0 : CalculateOuterNormal(Volume* v, int sideIndex, TAAPos aaPos)
80 : {
81 : typename TAAPos::ValueType n;
82 0 : FaceDescriptor fd;
83 0 : v->face_desc(sideIndex, fd);
84 0 : CalculateNormal(n, &fd, aaPos);
85 0 : 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
108 : CalculateNormal(EdgeVertices* edge,
109 : Grid::AttachmentAccessor<Vertex, Attachment<vector2> >& aaPos)
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
119 : CalculateNormal(FaceVertices* face,
120 : Grid::AttachmentAccessor<Vertex, Attachment<vector3> >& aaPos)
121 : {
122 : vector3 n;
123 : CalculateNormal(n, face, aaPos);
124 : return n;
125 : }
126 :
127 : }// end of namespace
128 :
129 : #endif
|