SPEED
MAKE_NORMAL.f90
Go to the documentation of this file.
1! Copyright (C) 2012 The SPEED FOUNDATION
2! Author: Ilario Mazzieri
3!
4! This file is part of SPEED.
5!
6! SPEED is free software; you can redistribute it and/or modify it
7! under the terms of the GNU Affero General Public License as
8! published by the Free Software Foundation, either version 3 of the
9! License, or (at your option) any later version.
10!
11! SPEED is distributed in the hope that it will be useful, but
12! WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14! Affero General Public License for more details.
15!
16! You should have received a copy of the GNU Affero General Public License
17! along with SPEED. If not, see <http://www.gnu.org/licenses/>.
18
19
42
43
44 subroutine make_normal(ind, xs1, xs2, xs3, xs4, &
45 ys1, ys2, ys3, ys4, &
46 zs1, zs2, zs3, zs4, &
47 nx,ny,nz, par, arr)
48
49 implicit none
50
51 integer*4, intent(in) :: ind, par, arr
52
53 real*8 :: a1,a2,a3,b1,b2,b3,aplane,bplane,cplane
54 real*8 :: norm1, norm2, norm3, norm4
55 real*8 :: nx1, nx2, nx3, nx4
56 real*8 :: ny1, ny2, ny3, ny4
57 real*8 :: nz1, nz2, nz3, nz4
58
59 real*8, intent(in) :: xs1, xs2, xs3, xs4, ys1, ys2, ys3, ys4, zs1, zs2, zs3, zs4
60 real*8, intent(out) :: nx,ny,nz
61
62 select case (ind)
63
64 case(1,3,5)
65 a1 = xs4-xs1
66 a2 = ys4-ys1
67 a3 = zs4-zs1
68 b1 = xs2-xs1
69 b2 = ys2-ys1
70 b3 = zs2-zs1
71 aplane = a2*b3 - a3*b2
72 bplane = -a1*b3 + a3*b1
73 cplane = a1*b2 - a2*b1
74
75 norm1 = aplane**2.d0 + bplane**2.d0 + cplane**2.d0
76 nx1 = aplane/dsqrt(norm1)
77 ny1 = bplane/dsqrt(norm1)
78 nz1 = cplane/dsqrt(norm1)
79
80
81 a1 = xs1-xs2
82 a2 = ys1-ys2
83 a3 = zs1-zs2
84 b1 = xs3-xs2
85 b2 = ys3-ys2
86 b3 = zs3-zs2
87 aplane = a2*b3 - a3*b2
88 bplane = -a1*b3 + a3*b1
89 cplane = a1*b2 - a2*b1
90
91 norm2 = aplane**2.d0 + bplane**2.d0 + cplane**2.d0
92 nx2 = aplane/dsqrt(norm2)
93 ny2 = bplane/dsqrt(norm2)
94 nz2 = cplane/dsqrt(norm2)
95
96
97 a1 = xs2-xs3
98 a2 = ys2-ys3
99 a3 = zs2-zs3
100 b1 = xs4-xs3
101 b2 = ys4-ys3
102 b3 = zs4-zs3
103 aplane = a2*b3 - a3*b2
104 bplane = -a1*b3 + a3*b1
105 cplane = a1*b2 - a2*b1
106
107 norm3 = aplane**2.d0 + bplane**2.d0 + cplane**2.d0
108 nx3 = aplane/dsqrt(norm3)
109 ny3 = bplane/dsqrt(norm3)
110 nz3 = cplane/dsqrt(norm3)
111
112
113 a1 = xs3-xs4
114 a2 = ys3-ys4
115 a3 = zs3-zs4
116 b1 = xs1-xs4
117 b2 = ys1-ys4
118 b3 = zs1-zs4
119 aplane = a2*b3 - a3*b2
120 bplane = -a1*b3 + a3*b1
121 cplane = a1*b2 - a2*b1
122
123 norm4 = aplane**2.d0 + bplane**2.d0 + cplane**2.d0
124 nx4 = aplane/dsqrt(norm4)
125 ny4 = bplane/dsqrt(norm4)
126 nz4 = cplane/dsqrt(norm4)
127
128 nx = (nx1 + nx2 + nx3 + nx4)/4.d0
129 ny = (ny1 + ny2 + ny3 + ny4)/4.d0
130 nz = (nz1 + nz2 + nz3 + nz4)/4.d0
131
132
133 case(2,4,6)
134
135 a1 = xs2-xs1
136 a2 = ys2-ys1
137 a3 = zs2-zs1
138 b1 = xs4-xs1
139 b2 = ys4-ys1
140 b3 = zs4-zs1
141 aplane = a2*b3 - a3*b2
142 bplane = -a1*b3 + a3*b1
143 cplane = a1*b2 - a2*b1
144
145 norm1 = aplane**2.d0 + bplane**2.d0 + cplane**2.d0
146 nx1 = aplane/dsqrt(norm1)
147 ny1 = bplane/dsqrt(norm1)
148 nz1 = cplane/dsqrt(norm1)
149
150
151 a1 = xs3-xs2
152 a2 = ys3-ys2
153 a3 = zs3-zs2
154 b1 = xs1-xs2
155 b2 = ys1-ys2
156 b3 = zs1-zs2
157 aplane = a2*b3 - a3*b2
158 bplane = -a1*b3 + a3*b1
159 cplane = a1*b2 - a2*b1
160
161 norm2 = aplane**2.d0 + bplane**2.d0 + cplane**2.d0
162 nx2 = aplane/dsqrt(norm2)
163 ny2 = bplane/dsqrt(norm2)
164 nz2 = cplane/dsqrt(norm2)
165
166
167 a1 = xs4-xs3
168 a2 = ys4-ys3
169 a3 = zs4-zs3
170 b1 = xs2-xs3
171 b2 = ys2-ys3
172 b3 = zs2-zs3
173 aplane = a2*b3 - a3*b2
174 bplane = -a1*b3 + a3*b1
175 cplane = a1*b2 - a2*b1
176
177 norm3 = aplane**2.d0 + bplane**2.d0 + cplane**2.d0
178 nx3 = aplane/dsqrt(norm3)
179 ny3 = bplane/dsqrt(norm3)
180 nz3 = cplane/dsqrt(norm3)
181
182
183 a1 = xs1-xs4
184 a2 = ys1-ys4
185 a3 = zs1-zs4
186 b1 = xs3-xs4
187 b2 = ys3-ys4
188 b3 = zs3-zs4
189 aplane = a2*b3 - a3*b2
190 bplane = -a1*b3 + a3*b1
191 cplane = a1*b2 - a2*b1
192
193 norm4 = aplane**2.d0 + bplane**2.d0 + cplane**2.d0
194 nx4 = aplane/dsqrt(norm4)
195 ny4 = bplane/dsqrt(norm4)
196 nz4 = cplane/dsqrt(norm4)
197
198
199 nx = (nx1 + nx2 + nx3 + nx4)/4.d0
200 ny = (ny1 + ny2 + ny3 + ny4)/4.d0
201 nz = (nz1 + nz2 + nz3 + nz4)/4.d0
202
203
204 end select
205
206
207
208end subroutine make_normal
subroutine make_normal(ind, xs1, xs2, xs3, xs4, ys1, ys2, ys3, ys4, zs1, zs2, zs3, zs4, nx, ny, nz, par, arr)
Makes normal vector of a given surface.