Skip to content

Commit

Permalink
Update particles_run call to allow accurate particle advection using …
Browse files Browse the repository at this point in the history
…u, v or uh, vh

The drifters package is able to run in 2 different modes: one where the particles are advected using u and v, and one where they are advected using uh and vh. When u and v are used (i.e. the drifters are advected using the resolved velocities only, with no sub-grd component), the particles package needs the layer thickness that is consistent with these velocities, so particles_run needs to be called before any subgrid scale parameterizations are applied. This was not implemented correctly in my last PR, and is corrected here.

The particles package also needs the correct timestep for particle advection. This is added here.
  • Loading branch information
cspencerjones committed Dec 23, 2024
1 parent e6e0870 commit 7295f7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions config_src/external/drifters/MOM_particles.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ subroutine particles_init(parts, Grid, Time, dt, u, v, h)
end subroutine particles_init

!> The main driver the steps updates particles
subroutine particles_run(parts, time, uo, vo, ho, tv, use_uh, stagger)
subroutine particles_run(parts, time, uo, vo, ho, tv, dt_adv, use_uh)
! Arguments
type(particles), pointer :: parts !< Container for all types and memory
type(time_type), intent(in) :: time !< Model time
Expand All @@ -40,8 +40,8 @@ subroutine particles_run(parts, time, uo, vo, ho, tv, use_uh, stagger)
!! that are used to advect tracers [H L2 ~> m3 or kg]
real, dimension(:,:,:), intent(in) :: ho !< Ocean layer thickness [H ~> m or kg m-2]
type(thermo_var_ptrs), intent(in) :: tv !< structure containing pointers to available thermodynamic fields
real, intent(in) :: dt_adv !< timestep for advecting particles [s]
logical :: use_uh !< Flag for whether u and v are weighted by thickness
integer, optional, intent(in) :: stagger !< Flag for whether velocities are staggered

end subroutine particles_run

Expand Down
26 changes: 18 additions & 8 deletions src/core/MOM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,18 @@ subroutine step_MOM_dynamics(forces, p_surf_begin, p_surf_end, dt, dt_thermo, &

endif ! -------------------------------------------------- end SPLIT

if (CS%use_particles .and. CS%do_dynamics .and. (.not. CS%use_uh_particles)) then
if (CS%thickness_diffuse_first) call MOM_error(WARNING,"particles_run: "//&
"Thickness_diffuse_first is true and use_uh_particles is false. "//&
"This is usually a bad combination.")
!Run particles using unweighted velocity
call particles_run(CS%particles, Time_local, CS%u, CS%v, CS%h, &
CS%tv, dt, CS%use_uh_particles)
call particles_to_z_space(CS%particles, h)
endif



! Update the model's current to reflect wind-wave growth
if (Waves%Stokes_DDT .and. (.not.Waves%Passive_Stokes_DDT)) then
do J=jsq,jeq ; do i=is,ie
Expand Down Expand Up @@ -1364,23 +1376,21 @@ subroutine step_MOM_dynamics(forces, p_surf_begin, p_surf_end, dt, dt_thermo, &
endif
call disable_averaging(CS%diag)

! Advance the dynamics time by dt.
CS%t_dyn_rel_adv = CS%t_dyn_rel_adv + dt

if (CS%use_particles .and. CS%do_dynamics .and. CS%use_uh_particles) then
!Run particles using thickness-weighted velocity
call particles_run(CS%particles, Time_local, CS%uhtr, CS%vhtr, CS%h, &
CS%tv, CS%use_uh_particles)
elseif (CS%use_particles .and. CS%do_dynamics) then
!Run particles using unweighted velocity
call particles_run(CS%particles, Time_local, CS%u, CS%v, CS%h, &
CS%tv, CS%use_uh_particles)
CS%tv, CS%t_dyn_rel_adv, CS%use_uh_particles)
endif


! Advance the dynamics time by dt.
CS%t_dyn_rel_adv = CS%t_dyn_rel_adv + dt
CS%n_dyn_steps_in_adv = CS%n_dyn_steps_in_adv + 1
if (CS%alternate_first_direction) then
call set_first_direction(G, MODULO(G%first_direction+1,2))
CS%first_dir_restart = real(G%first_direction)
elseif (CS%use_particles .and. CS%do_dynamics .and. (.not.CS%use_uh_particles)) then
call particles_to_k_space(CS%particles, h)
endif
CS%t_dyn_rel_thermo = CS%t_dyn_rel_thermo + dt
if (abs(CS%t_dyn_rel_thermo) < 1e-6*dt) CS%t_dyn_rel_thermo = 0.0
Expand Down

0 comments on commit 7295f7e

Please sign in to comment.