Skip to content

Commit

Permalink
fix: normalise vector for cg
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachlan Grose committed Nov 4, 2021
1 parent 1ce7380 commit f8cf221
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion LoopStructural/interpolators/cython/dsi_helper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def cg(double [:,:,:] EG, long long [:,:] neighbours, long long [:,:] elements,d
cdef double [:,:] e1
cdef double [:,:] e2
cdef double area = 0
cdef double length
cdef long long [:] idl = np.zeros(4,dtype=np.int64)
cdef long long [:] idr = np.zeros(4,dtype=np.int64)
for e in range(ne):
Expand Down Expand Up @@ -67,10 +68,13 @@ def cg(double [:,:,:] EG, long long [:,:] neighbours, long long [:,:] elements,d
norm[1] = v1[2]*v2[0] - v1[0]*v2[2]
norm[2] = v1[0]*v2[1] - v1[1]*v2[0]

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

0 comments on commit f8cf221

Please sign in to comment.