Skip to content

Commit de0e287

Browse files
fangjian19fangjian1119mathrack
authored
bug fix for particle with periodic condition (#345)
* bug fix for particle with periodic condition * add lenpe define * remove iface * add periodic_bc to decomp_2d_init * Define periodic_bc in one line * add a comment and format change --------- Co-authored-by: Jian Fang <[email protected]> Co-authored-by: CFLAG <[email protected]>
1 parent 06af91a commit de0e287

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

src/module_param.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ module param
538538
real(mytype),parameter :: twopi=two*acos(-one)
539539
#endif
540540

541+
logical :: periodic_bc(3)
542+
541543
end module param
542544
!############################################################################
543545
!############################################################################

src/parameters.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ subroutine parameter(input_i3d)
137137
nclxS1 = nclx1; nclxSn = nclxn
138138
nclyS1 = ncly1; nclySn = nclyn
139139
nclzS1 = nclz1; nclzSn = nclzn
140+
141+
!! set periodic direction
142+
periodic_bc = (/nclx1.eq.0, ncly1.eq.0, nclz1.eq.0/)
140143

141144
if (numscalar.ne.0) then
142145
iscalar = 1
@@ -842,4 +845,6 @@ subroutine parameter_defaults()
842845
ts_tr_tbl=1.402033_mytype
843846
x0_tr_tbl=3.505082_mytype
844847

848+
periodic_bc=.false.
849+
845850
end subroutine parameter_defaults

src/particle.f90

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ subroutine particle_domain_check(particle,num_active_particles)
19901990

19911991
if(npart>npexit) exit
19921992

1993-
if(pa%x(1)<0) then
1993+
if(pa%x(1)<0._mytype) then
19941994

19951995
! xmin face
19961996
call particle_bc(face=1,bctype=bc_particle(1),particle=pa,particle_deduce=counter)
@@ -2002,7 +2002,7 @@ subroutine particle_domain_check(particle,num_active_particles)
20022002

20032003
endif
20042004

2005-
if(pa%x(2)<0) then
2005+
if(pa%x(2)<0._mytype) then
20062006

20072007
! ymin face
20082008
call particle_bc(face=3,bctype=bc_particle(3),particle=pa,particle_deduce=counter)
@@ -2014,7 +2014,7 @@ subroutine particle_domain_check(particle,num_active_particles)
20142014

20152015
endif
20162016

2017-
if(pa%x(3)<0) then
2017+
if(pa%x(3)<0._mytype) then
20182018

20192019
! zmin face
20202020
call particle_bc(face=5,bctype=bc_particle(5),particle=pa,particle_deduce=counter)
@@ -2087,8 +2087,7 @@ subroutine particle_bc(face,bctype,particle,particle_deduce)
20872087
integer,intent(inout) :: particle_deduce
20882088

20892089
! local data
2090-
real(mytype) :: iface
2091-
real(mytype),save :: bcord(6)
2090+
real(mytype), dimension(6), save :: bcord, lenpe
20922091
logical,save :: firstcal=.true.
20932092
integer :: idir
20942093

@@ -2101,6 +2100,15 @@ subroutine particle_bc(face,bctype,particle,particle_deduce)
21012100
bcord(5)=0.0_mytype
21022101
bcord(6)=zlz
21032102

2103+
! lenpe is to get the particle back to the domain for periodic boundaries.
2104+
! defined as the distance (+ or -) between the two paring periodic boundaries.
2105+
lenpe(1)=xlx
2106+
lenpe(2)=-xlx
2107+
lenpe(3)=yly
2108+
lenpe(4)=-yly
2109+
lenpe(5)=zlz
2110+
lenpe(6)=-zlz
2111+
21042112
firstcal=.false.
21052113
endif
21062114

@@ -2111,14 +2119,8 @@ subroutine particle_bc(face,bctype,particle,particle_deduce)
21112119
call decomp_2d_abort(1,"idir error @ particle_bc")
21122120
endif
21132121

2114-
if(mod(face,2)==0) then
2115-
iface=-1._mytype
2116-
else
2117-
iface= 1._mytype
2118-
endif
2119-
21202122
if(bctype=='periodic') then
2121-
particle%x(idir)=particle%x(idir)+bcord(face)*iface
2123+
particle%x(idir)=particle%x(idir)+lenpe(face)
21222124
elseif(bctype=='reflective') then
21232125
particle%x(idir)=-particle%x(idir)+2.0_mytype*bcord(face)
21242126
elseif(bctype=='outflow') then

src/xcompact3d.f90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ subroutine init_xcompact3d()
126126

127127
use param, only : ilesmod, jles,itype
128128
use param, only : irestart, mhd_active
129+
use param, only : periodic_bc
129130

130131
use variables, only : nx, ny, nz, nxm, nym, nzm
131132
use variables, only : p_row, p_col
@@ -187,7 +188,8 @@ subroutine init_xcompact3d()
187188

188189
call parameter(InputFN)
189190

190-
call decomp_2d_init(nx,ny,nz,p_row,p_col)
191+
call decomp_2d_init(nx,ny,nz,p_row,p_col,periodic_bc)
192+
191193
call decomp_2d_io_init()
192194
call init_coarser_mesh_statS(nstat,nstat,nstat,.true.) !start from 1 == true
193195
call init_coarser_mesh_statV(nvisu,nvisu,nvisu,.true.) !start from 1 == true

0 commit comments

Comments
 (0)