Skip to content

Commit

Permalink
Merge pull request #298 from matt-frey/2d-merge-periodic-on-posm
Browse files Browse the repository at this point in the history
Apply pull request #297 to master branch
  • Loading branch information
matt-frey authored Jan 21, 2022
2 parents 19614cf + 4eaad3f commit 97ea7a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/2d/parcels/parcel_container.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,23 @@ module parcel_container
! @param[in] x1 first horizontal position
! @param[in] x2 second horizontal position
! @returns delx = x1 - x2
! WARNING input needs to be between lower and upper (see debug statement)
#ifndef NDEBUG
function get_delx(x1, x2) result (delx)
#else
elemental function get_delx(x1, x2) result (delx)
#endif
double precision, intent(in) :: x1, x2
double precision :: delx

delx = x1 - x2
#ifndef NDEBUG
if ((x1 < lower(1)) .or. (x2 < lower(1)) .or. (x1 > upper(1)) .or. (x2 > upper(1))) then
write(*,*) 'point outside domain was fed into get_delx'
write(*,*) 'x1, x2, lower(1), upper(1)'
write(*,*) x1, x2, lower(1), upper(1)
endif
#endif
! works across periodic edge
delx = delx - extent(1) * dble(int(delx * hli(1)))
end function get_delx
Expand Down
10 changes: 9 additions & 1 deletion src/2d/parcels/parcel_merge.f90
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,20 @@ subroutine do_group_merge(parcels, isma, iclo, n_merge, B11m, B12m, B22m, vm)
! temporary scalar containing 1 / vm(m)
vmerge = one / vm(m)

! need to sanitise input and output, but first to determine input
posm(m, 1) = - vmerge * posm(m, 1)

call apply_periodic_bc(posm(m, :))

! x centre of merged parcel, modulo periodicity
posm(m, 1) = get_delx(x0(m), - vmerge * posm(m, 1))
posm(m, 1) = get_delx(x0(m), posm(m, 1))

! z centre of merged parcel
posm(m, 2) = vmerge * posm(m, 2)

! need to correct position
call apply_periodic_bc(posm(m, :))

! buoyancy and humidity
buoym(m) = vmerge * buoym(m)
#ifndef ENABLE_DRY_MODE
Expand Down

0 comments on commit 97ea7a0

Please sign in to comment.