Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Fixed some minor issues with checking for small values of a sine comp…
Browse files Browse the repository at this point in the history
…utation
  • Loading branch information
daminton committed Jan 30, 2024
1 parent 4e8def6 commit dd97561
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/swiftest/swiftest_sph.f90
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ module subroutine swiftest_sph_g_acc_one(GMcb, r_0, phi_cb, rh, c_lm, g_sph, GMp
cos_theta = cos(theta)
sin_theta = sin(theta)

if(abs(cos_theta) < epsilon(0.0_DP)) then
cos_theta = 0.0_DP
end if
if(abs(sin_theta) < epsilon(0.0_DP)) then
sin_theta = 0.0_DP
end if

! call PlmBar_d1(p, p_deriv, l_max, cos_theta) ! Associated Legendre Polynomials and the 1st Derivative
call PlmBar(p, l_max, cos_theta)

Expand All @@ -89,10 +82,10 @@ module subroutine swiftest_sph_g_acc_one(GMcb, r_0, phi_cb, rh, c_lm, g_sph, GMp
+ c_lm(m+1, l+1, 2) * cos(m * phi_bar) ! - C_lm * sin(m * phi_bar) + S_lm * cos(m * phi_bar)
! cssc * m = first derivative of ccss with respect to phi

if ((m+1) .le. l) then
if ((m+1) <= l) then
lmindex = PlmIndex(l, m+1)
plm1 = p(lmindex)
if(m .eq. 0) then
if(m ==. 0) then
plm1 = plm1 * sqrt(((l + m + 1) * (l - m)) / 2.0) ! renormalize plm1 to the norm of plm
else
plm1 = plm1 * sqrt((l + m + 1) * (l - m) * 1.0) ! renormalize plm1 to the norm of plm
Expand All @@ -101,7 +94,7 @@ module subroutine swiftest_sph_g_acc_one(GMcb, r_0, phi_cb, rh, c_lm, g_sph, GMp
plm1 = 0.0_DP
end if

if(sin_theta .eq. 0) then
if(abs(sin_theta) < epsilon(1.0_DP)) then
fac1 = 0.0_DP
else
fac1 = m * plm / sin_theta
Expand All @@ -110,7 +103,6 @@ module subroutine swiftest_sph_g_acc_one(GMcb, r_0, phi_cb, rh, c_lm, g_sph, GMp
fac2 = plm * (l + m + 1) * sin_theta + plm1 * cos_theta
r_fac = -GMcb * r_0**l / r_mag**(l + 2)

! g_sph(:) = 0.0_DP
g_sph(1) = g_sph(1) + r_fac * (cssc * fac1 * sin(phi) + ccss * (fac2 - fac1) * cos(phi))
g_sph(2) = g_sph(2) + r_fac * (-cssc * fac1 * cos(phi) + ccss * (fac2 - fac1) * sin(phi))
g_sph(3) = g_sph(3) + r_fac * ccss * (plm * (l + m + 1) * cos_theta - plm1 * sin_theta)
Expand Down

0 comments on commit dd97561

Please sign in to comment.