Skip to content

Commit

Permalink
cleanups in get_hit_times/l_correct_step
Browse files Browse the repository at this point in the history
Make use of vectorized functions any/where instead of explicit loops
  • Loading branch information
tgastine committed Jul 30, 2024
1 parent 7752c52 commit 555c3a2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/horizontal.f90
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ subroutine horizontal()
! Gauss-Legendre integration of the plms:
call gauleg(-one,one,theta_ord,tmp_gauss,n_theta_max)

! Get dP for all degrees and order m=0 at the equator only
! Usefull to estimate the flow velocity at the equator
call plm_theta(half*pi,l_max,0,0,minc,Pl0Eq,dPl0Eq,l_max+1,norm)

!-- Legendre polynomials and cos(theta) derivative:
do n_theta=1,n_theta_max/2 ! Loop over colat in NHS

colat=theta_ord(n_theta)

! Get dP for all degrees and order m=0 at the equator only
! Usefull to estimate the flow velocity at the equator
call plm_theta(half*pi,l_max,0,0,minc,Pl0Eq,dPl0Eq,l_max+1,norm)

if ( l_scramble_theta ) then
O_sin_theta(2*n_theta-1) =one/sin(colat)
O_sin_theta(2*n_theta ) =one/sin(colat)
Expand Down
18 changes: 4 additions & 14 deletions src/preCalculations.f90
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,8 @@ subroutine get_hit_times(t,t_start,t_stop,dt,n_tot,n_step,string,time,&
!-- Local variables:
logical :: l_t
real(cp) :: tmp(size(t))
integer :: n, n_t_max, n_t
integer :: n, n_t

n_t_max = size(t)
t_start=t_start/tScale
t_stop =t_stop/tScale
dt =dt/tScale
Expand All @@ -905,13 +904,8 @@ subroutine get_hit_times(t,t_start,t_stop,dt,n_tot,n_step,string,time,&
!-- Check whether any time is given explicitly:
l_t=.false.
n_t=0
do n=1,n_t_max
if ( t(n) >= 0.0_cp ) then
t(n)=t(n)/tScale
l_t=.true.
n_t=n_t+1
end if
end do
where ( t >= 0.0_cp ) t=t/tScale
if ( maxval(t(:)) >= 0.0_cp ) l_t=.true.; n_t=count(t(:)>=0.0)

!-- Properly reallocate at the right size
if ( l_t ) then
Expand All @@ -938,11 +932,7 @@ subroutine get_hit_times(t,t_start,t_stop,dt,n_tot,n_step,string,time,&

deallocate(t) ! Deallocate to get the proper size
allocate(t(n_t))
t(1)=t_start
do n=2,n_t
t(n)=t(n-1)+dt
end do

t(:) = [(t_start+(n-1)*dt, n=1,n_t)]
end if

!-- In case only n_step or n_tot is specified such that l_t=.false.
Expand Down
10 changes: 1 addition & 9 deletions src/useful.f90
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ logical function l_correct_step(n,t,t_last,n_max,n_step,n_intervals, &

!-- Local variables:
integer :: n_offset ! offset with no action
integer :: n_t ! counter for times
integer :: n_steps ! local step width

if ( n_step /= 0 .and. n_intervals /= 0 ) then
Expand All @@ -56,11 +55,9 @@ logical function l_correct_step(n,t,t_last,n_max,n_step,n_intervals, &
end if

l_correct_step=.false.

if ( n_intervals /= 0 ) then
n_steps=n_max/n_intervals
n_offset=n_max-n_steps*n_intervals

if ( n > n_offset .and. mod(n-n_offset,n_steps) == 0 ) l_correct_step=.true.
else if ( n_step /= 0 ) then
if ( n == n_max .or. mod(n,n_step) == 0 ) l_correct_step=.true.
Expand All @@ -74,12 +71,7 @@ logical function l_correct_step(n,t,t_last,n_max,n_step,n_intervals, &
end if
else if ( size(times) > 1 ) then
!-- Time array contains multiple entries
do n_t=1,size(times)
if ( times(n_t) < t .and. times(n_t) >= t_last ) then
l_correct_step=.true.
exit
end if
end do
l_correct_step=any((times(:) >= t_last) .and. (times(:) < t), dim=1)
end if

end function l_correct_step
Expand Down

0 comments on commit 555c3a2

Please sign in to comment.