Ignore:
Timestamp:
Sep 6, 2017 3:22:27 PM (4 years ago)
Author:
suehring
Message:

Major bugfix in modeling SGS particle speeds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/lpm_pack_arrays.f90

    r2101 r2417  
    2525! -----------------
    2626! $Id$
     27! New routine which sorts particles into particles that completed and not
     28! completed the LES timestep.
     29!
     30! 2101 2017-01-05 16:42:31Z suehring
    2731!
    2832! 2000 2016-08-20 18:09:15Z knoop
     
    6165!> deletion and move data with higher index values to these free indices.
    6266!> Determine the new number of particles.
     67!> Moreover, particles are also sorted into groups finished and not finished
     68!> its timestep.
    6369!------------------------------------------------------------------------------!
    6470 MODULE lpm_pack_arrays_mod
     
    7076
    7177    PRIVATE
    72     PUBLIC lpm_pack_all_arrays, lpm_pack_arrays
     78    PUBLIC lpm_pack_all_arrays, lpm_pack_arrays, lpm_sort
    7379
    7480    INTERFACE lpm_pack_all_arrays
     
    8086    END INTERFACE lpm_pack_arrays
    8187
    82 CONTAINS
     88    INTERFACE lpm_sort
     89       MODULE PROCEDURE lpm_sort
     90    END INTERFACE lpm_sort
     91
     92
     93 CONTAINS
    8394
    8495!------------------------------------------------------------------------------!
     
    236247    END SUBROUTINE lpm_pack_and_sort
    237248
     249!------------------------------------------------------------------------------!
     250! Description:
     251! ------------
     252!> Sort particles in each sub-grid box into two groups: particles that already
     253!> completed the LES timestep, and particles that need further timestepping to
     254!> complete the LES timestep.
     255!------------------------------------------------------------------------------!
     256    SUBROUTINE lpm_sort
     257
     258       USE control_parameters,                                                 &
     259           ONLY:  dt_3d
     260
     261       USE indices,                                                            &
     262           ONLY: nxl, nxr, nys, nyn, nzb, nzt
     263
     264       USE kinds
     265
     266       IMPLICIT NONE
     267
     268       INTEGER(iwp) :: end_index     !< particle end index for each sub-box
     269       INTEGER(iwp) :: i             !< index of particle grid box in x-direction
     270       INTEGER(iwp) :: j             !< index of particle grid box in y-direction
     271       INTEGER(iwp) :: k             !< index of particle grid box in z-direction
     272       INTEGER(iwp) :: n             !< running index for number of particles
     273       INTEGER(iwp) :: nb            !< index of subgrid boux
     274       INTEGER(iwp) :: nf            !< indices for particles in each sub-box that already finalized their substeps
     275       INTEGER(iwp) :: nnf           !< indices for particles in each sub-box that need further treatment
     276       INTEGER(iwp) :: num_finalized !< number of particles in each sub-box that already finalized their substeps
     277       INTEGER(iwp) :: start_index   !< particle start index for each sub-box
     278
     279       TYPE(particle_type), DIMENSION(:), ALLOCATABLE :: sort_particles  !< temporary particle array
     280
     281       DO  i = nxl, nxr
     282          DO  j = nys, nyn
     283             DO  k = nzb+1, nzt
     284
     285                number_of_particles = prt_count(k,j,i)
     286                IF ( number_of_particles <= 0 )  CYCLE
     287
     288                particles => grid_particles(k,j,i)%particles(1:number_of_particles)
     289
     290                DO  nb = 0, 7
     291!
     292!--                Obtain start and end index for each subgrid box
     293                   start_index = grid_particles(k,j,i)%start_index(nb)
     294                   end_index   = grid_particles(k,j,i)%end_index(nb)
     295!
     296!--                Allocate temporary array used for sorting.
     297                   ALLOCATE( sort_particles(start_index:end_index) )
     298!
     299!--                Determine number of particles already completed the LES
     300!--                timestep, and write them into a temporary array.
     301                   nf = start_index
     302                   num_finalized = 0
     303                   DO  n = start_index, end_index
     304                      IF ( dt_3d - particles(n)%dt_sum < 1E-8_wp )  THEN
     305                         sort_particles(nf) = particles(n)
     306                         nf                 = nf + 1
     307                         num_finalized      = num_finalized + 1
     308                      ENDIF
     309                   ENDDO
     310!
     311!--                Determine number of particles that not completed the LES
     312!--                timestep, and write them into a temporary array.
     313                   nnf = nf
     314                   DO  n = start_index, end_index
     315                      IF ( dt_3d - particles(n)%dt_sum > 1E-8_wp )  THEN
     316                         sort_particles(nnf) = particles(n)
     317                         nnf                 = nnf + 1
     318                      ENDIF
     319                   ENDDO
     320!
     321!--                Write back sorted particles
     322                   particles(start_index:end_index) =                          &
     323                                           sort_particles(start_index:end_index)
     324!
     325!--                Determine updated start_index, used to masked already
     326!--                completed particles.
     327                   grid_particles(k,j,i)%start_index(nb) =                     &
     328                                      grid_particles(k,j,i)%start_index(nb)    &
     329                                    + num_finalized
     330!
     331!--                Deallocate dummy array
     332                   DEALLOCATE ( sort_particles )
     333!
     334!--                Finally, if number of non-completed particles is non zero
     335!--                in any of the sub-boxes, set control flag appropriately.
     336                   IF ( nnf > nf )                                             &
     337                      grid_particles(k,j,i)%time_loop_done = .FALSE.
     338
     339                ENDDO
     340             ENDDO
     341          ENDDO
     342       ENDDO
     343
     344    END SUBROUTINE lpm_sort
     345
    238346
    239347 END module lpm_pack_arrays_mod
Note: See TracChangeset for help on using the changeset viewer.