Skip to content

Commit 4e306df

Browse files
committed
avoid dividing by zero in MTHINC
1 parent 8bb2f25 commit 4e306df

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/simulation/m_thinc.fpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,17 @@ contains
271271
if (abs(nr_y) < mthinc_align_tol*nmax) nr_y = 0._wp
272272
if (abs(nr_z) < mthinc_align_tol*nmax) nr_z = 0._wp
273273
nmag = sqrt(nr_x*nr_x + nr_y*nr_y + nr_z*nr_z)
274-
nr_x = nr_x/nmag
275-
nr_y = nr_y/nmag
276-
nr_z = nr_z/nmag
274+
if (nmag > verysmall) then
275+
nr_x = nr_x/nmag
276+
nr_y = nr_y/nmag
277+
nr_z = nr_z/nmag
277278

278-
mthinc_nhat(1, j, k, l) = nr_x
279-
mthinc_nhat(2, j, k, l) = nr_y
280-
mthinc_nhat(3, j, k, l) = nr_z
279+
mthinc_nhat(1, j, k, l) = nr_x
280+
mthinc_nhat(2, j, k, l) = nr_y
281+
mthinc_nhat(3, j, k, l) = nr_z
281282

282-
mthinc_d(j, k, l) = f_mthinc_solve_d(nr_x, nr_y, nr_z, ic_beta, ac, num_dims)
283+
mthinc_d(j, k, l) = f_mthinc_solve_d(nr_x, nr_y, nr_z, ic_beta, ac, num_dims)
284+
end if
283285
end if
284286
end if
285287
end do

0 commit comments

Comments
 (0)