Skip to content

Commit f8cf221

Browse files
author
Lachlan Grose
committed
fix: normalise vector for cg
1 parent 1ce7380 commit f8cf221

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

LoopStructural/interpolators/cython/dsi_helper.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def cg(double [:,:,:] EG, long long [:,:] neighbours, long long [:,:] elements,d
2525
cdef double [:,:] e1
2626
cdef double [:,:] e2
2727
cdef double area = 0
28+
cdef double length
2829
cdef long long [:] idl = np.zeros(4,dtype=np.int64)
2930
cdef long long [:] idr = np.zeros(4,dtype=np.int64)
3031
for e in range(ne):
@@ -67,10 +68,13 @@ def cg(double [:,:,:] EG, long long [:,:] neighbours, long long [:,:] elements,d
6768
norm[1] = v1[2]*v2[0] - v1[0]*v2[2]
6869
norm[2] = v1[0]*v2[1] - v1[1]*v2[0]
6970

71+
length = np.linalg.norm(norm)
7072
# we want to weight the cg by the area of the shared face
7173
# area of triangle is half area of parallelogram
7274
# https://math.stackexchange.com/questions/128991/how-to-calculate-the-area-of-a-3d-triangle
73-
area = 0.5*sqrt(norm[0]*norm[0]+norm[1]*norm[1]+norm[2]*norm[2])#np.linalg.norm(norm)
75+
area = 0.5*length#sqrt(norm[0]*norm[0]+norm[1]*norm[1]+norm[2]*norm[2])#np.linalg.norm(norm)
76+
for i in range(3):
77+
norm[i]/=length
7478
for itr_left in range(Na):
7579
idc[ncons,itr_left] = idl[itr_left]
7680
for i in range(3):

0 commit comments

Comments
 (0)