• R/O
  • SSH

treelm: 提交

Repository of the treelm library. Now found at https://github.com/apes-suite/treelm


Commit MetaInfo

修訂8f58ec6af121b3e7d049822233a9eaa3fbd6d9bb (tree)
時間2023-03-10 17:36:28
作者Gregspi <gregoriogerardo.spinelli@dlr....>
CommiterGregspi

Log Message

Created a function to calculate outward normal for triangles

Change Summary

差異

diff -r 5cdaafb19cde -r 8f58ec6af121 source/shapes/tem_triangle_module.fpp
--- a/source/shapes/tem_triangle_module.fpp Mon Feb 13 16:27:57 2023 +0100
+++ b/source/shapes/tem_triangle_module.fpp Fri Mar 10 09:36:28 2023 +0100
@@ -49,12 +49,14 @@
4949 public :: tem_triangleCubeOverlap
5050 public :: tem_load_triangle
5151 public :: tem_triangle_out
52+ public :: tem_evaluate_normal_triangle
5253
5354 !> This type contains three vertices of the triangle
5455 type tem_triangle_type
5556 !> 1st index contains x,y,z coordinates
5657 !! and 2nd index the vertex number.
5758 real(kind=rk) :: nodes(3,3)
59+ real(kind=rk) :: normal(3)
5860 end type tem_triangle_type
5961
6062 ?? copy :: GA_decltxt(triangle, type(tem_triangle_type))
@@ -182,6 +184,7 @@
182184 end subroutine tem_load_triangle_single
183185 ! ****************************************************************************
184186
187+
185188 ! ****************************************************************************
186189 !> Compute, if the triangle intersects the cube.
187190 function tem_triangleCubeOverlap(triangle, cube) result(overlaps)
@@ -203,6 +206,52 @@
203206 end function tem_triangleCubeOverlap
204207 ! ****************************************************************************
205208
209+ ! ****************************************************************************
210+ !> Compute, the outward normal of a triangle. To work nodes must be in
211+ !> counter-clockwise order. For STL this is the standard.
212+ !> It follows pg 136 of Jiri Blaze, CFD Principles and Applications
213+ subroutine tem_evaluate_normal_triangle(triangle)
214+ !--------------------------------------------------------------------------!
215+ type(tem_triangle_type), intent(inout) :: triangle
216+ !--------------------------------------------------------------------------!
217+ real(kind=rk) :: outward_vector(3), delta_x(3), delta_y(3), delta_z(3)
218+ real(kind=rk) :: magnitude_normal
219+ !--------------------------------------------------------------------------!
220+
221+ ! Eq.s 5.8
222+ delta_x(1) = ( triangle%nodes(1,1) - triangle%nodes(1,2) ) * &
223+ & ( triangle%nodes(2,1) + triangle%nodes(2,2) )
224+ delta_x(2) = ( triangle%nodes(1,2) - triangle%nodes(1,3) ) * &
225+ & ( triangle%nodes(2,2) + triangle%nodes(2,3) )
226+ delta_x(3) = ( triangle%nodes(1,3) - triangle%nodes(1,1) ) * &
227+ & ( triangle%nodes(2,3) + triangle%nodes(2,1) )
228+ delta_y(1) = ( triangle%nodes(2,1) - triangle%nodes(2,2) ) * &
229+ & ( triangle%nodes(3,1) + triangle%nodes(3,2) )
230+ delta_y(2) = ( triangle%nodes(2,2) - triangle%nodes(2,3) ) * &
231+ & ( triangle%nodes(3,2) + triangle%nodes(3,3) )
232+ delta_y(3) = ( triangle%nodes(2,3) - triangle%nodes(2,1) ) * &
233+ & ( triangle%nodes(3,3) + triangle%nodes(3,1) )
234+ delta_z(1) = ( triangle%nodes(3,1) - triangle%nodes(3,2) ) * &
235+ & ( triangle%nodes(1,1) + triangle%nodes(1,2) )
236+ delta_z(2) = ( triangle%nodes(3,2) - triangle%nodes(3,3) ) * &
237+ & ( triangle%nodes(1,2) + triangle%nodes(1,3) )
238+ delta_z(3) = ( triangle%nodes(3,3) - triangle%nodes(3,1) ) * &
239+ & ( triangle%nodes(1,3) + triangle%nodes(1,1) )
240+
241+ ! Eq.s 5.9
242+ outward_vector(1) = 0.5_rk * ( delta_y(1) + delta_y(2) + delta_y(3) )
243+ outward_vector(2) = 0.5_rk * ( delta_z(1) + delta_z(2) + delta_z(3) )
244+ outward_vector(3) = 0.5_rk * ( delta_x(1) + delta_x(2) + delta_x(3) )
245+
246+ ! Eq.s 5.12
247+ magnitude_normal = sqrt( outward_vector(1)**2 + outward_vector(2)**2 + outward_vector(3)**2 )
248+
249+ ! normalization of the outward_vector
250+ triangle%normal(:) = outward_vector(:) / magnitude_normal
251+
252+ end subroutine tem_evaluate_normal_triangle
253+ ! ****************************************************************************
254+
206255 ! ***************************************************************************
207256 !> This routine checks for triangle box overlap
208257 !!
Show on old repository browser