From 56b827265d9632db68c6573b2f9fed7a0b8bb005 Mon Sep 17 00:00:00 2001 From: Jian Fang Date: Tue, 11 Mar 2025 13:56:43 +0000 Subject: [PATCH 1/6] bug fix for particle with periodic condition --- src/particle.f90 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/particle.f90 b/src/particle.f90 index cb17eae5..39295367 100644 --- a/src/particle.f90 +++ b/src/particle.f90 @@ -1990,7 +1990,7 @@ subroutine particle_domain_check(particle,num_active_particles) if(npart>npexit) exit - if(pa%x(1)<0) then + if(pa%x(1)<0._mytype) then ! xmin face 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) endif - if(pa%x(2)<0) then + if(pa%x(2)<0._mytype) then ! ymin face 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) endif - if(pa%x(3)<0) then + if(pa%x(3)<0._mytype) then ! zmin face call particle_bc(face=5,bctype=bc_particle(5),particle=pa,particle_deduce=counter) @@ -2101,6 +2101,13 @@ subroutine particle_bc(face,bctype,particle,particle_deduce) bcord(5)=0.0_mytype bcord(6)=zlz + lenpe(1)=xlx + lenpe(2)=-xlx + lenpe(3)=yly + lenpe(4)=-yly + lenpe(5)=zlz + lenpe(6)=-zlz + firstcal=.false. endif @@ -2111,14 +2118,8 @@ subroutine particle_bc(face,bctype,particle,particle_deduce) call decomp_2d_abort(1,"idir error @ particle_bc") endif - if(mod(face,2)==0) then - iface=-1._mytype - else - iface= 1._mytype - endif - if(bctype=='periodic') then - particle%x(idir)=particle%x(idir)+bcord(face)*iface + particle%x(idir)=particle%x(idir)+lenpe(face) elseif(bctype=='reflective') then particle%x(idir)=-particle%x(idir)+2.0_mytype*bcord(face) elseif(bctype=='outflow') then From 3c807dc99a1c19388aa8be778053de674b79acb0 Mon Sep 17 00:00:00 2001 From: Jian Fang Date: Tue, 11 Mar 2025 15:01:33 +0000 Subject: [PATCH 2/6] add lenpe define --- src/particle.f90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/particle.f90 b/src/particle.f90 index 39295367..5cf1eb34 100644 --- a/src/particle.f90 +++ b/src/particle.f90 @@ -2088,7 +2088,7 @@ subroutine particle_bc(face,bctype,particle,particle_deduce) ! local data real(mytype) :: iface - real(mytype),save :: bcord(6) + real(mytype),save :: bcord(6),lenpe(6) logical,save :: firstcal=.true. integer :: idir From 6c123ad53c8730fbb1a41a31192d0a5eebf15194 Mon Sep 17 00:00:00 2001 From: fangjian19 Date: Wed, 12 Mar 2025 11:35:16 +0000 Subject: [PATCH 3/6] remove iface --- src/particle.f90 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/particle.f90 b/src/particle.f90 index 5cf1eb34..2f9bfc32 100644 --- a/src/particle.f90 +++ b/src/particle.f90 @@ -2087,7 +2087,6 @@ subroutine particle_bc(face,bctype,particle,particle_deduce) integer,intent(inout) :: particle_deduce ! local data - real(mytype) :: iface real(mytype),save :: bcord(6),lenpe(6) logical,save :: firstcal=.true. integer :: idir From a247b03a112ad80e43ffd20a8a4c6cccc375bf50 Mon Sep 17 00:00:00 2001 From: fangjian19 Date: Wed, 12 Mar 2025 14:16:55 +0000 Subject: [PATCH 4/6] add periodic_bc to decomp_2d_init --- src/module_param.f90 | 2 ++ src/parameters.f90 | 7 +++++++ src/xcompact3d.f90 | 4 +++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/module_param.f90 b/src/module_param.f90 index db7eb8ab..8ca94d3b 100644 --- a/src/module_param.f90 +++ b/src/module_param.f90 @@ -538,6 +538,8 @@ module param real(mytype),parameter :: twopi=two*acos(-one) #endif + logical :: periodic_bc(3) + end module param !############################################################################ !############################################################################ diff --git a/src/parameters.f90 b/src/parameters.f90 index 8b39a1cc..b427afb5 100644 --- a/src/parameters.f90 +++ b/src/parameters.f90 @@ -137,6 +137,11 @@ subroutine parameter(input_i3d) nclxS1 = nclx1; nclxSn = nclxn nclyS1 = ncly1; nclySn = nclyn nclzS1 = nclz1; nclzSn = nclzn + + !! set periodic direction + if (nclx1.eq.0 .and. nclxn.eq.0) periodic_bc(1)=.true. + if (ncly1.eq.0 .and. nclyn.eq.0) periodic_bc(2)=.true. + if (nclz1.eq.0 .and. nclzn.eq.0) periodic_bc(3)=.true. if (numscalar.ne.0) then iscalar = 1 @@ -842,4 +847,6 @@ subroutine parameter_defaults() ts_tr_tbl=1.402033_mytype x0_tr_tbl=3.505082_mytype + periodic_bc=.false. + end subroutine parameter_defaults diff --git a/src/xcompact3d.f90 b/src/xcompact3d.f90 index cac805e9..6b6bd3d7 100644 --- a/src/xcompact3d.f90 +++ b/src/xcompact3d.f90 @@ -126,6 +126,7 @@ subroutine init_xcompact3d() use param, only : ilesmod, jles,itype use param, only : irestart, mhd_active + use param, only : periodic_bc use variables, only : nx, ny, nz, nxm, nym, nzm use variables, only : p_row, p_col @@ -187,7 +188,8 @@ subroutine init_xcompact3d() call parameter(InputFN) - call decomp_2d_init(nx,ny,nz,p_row,p_col) + call decomp_2d_init(nx,ny,nz,p_row,p_col,periodic_bc) + call decomp_2d_io_init() call init_coarser_mesh_statS(nstat,nstat,nstat,.true.) !start from 1 == true call init_coarser_mesh_statV(nvisu,nvisu,nvisu,.true.) !start from 1 == true From 9cb09e2d9280280dff9dc4be9b5d2f628cc675f5 Mon Sep 17 00:00:00 2001 From: CFLAG Date: Wed, 12 Mar 2025 18:58:30 +0100 Subject: [PATCH 5/6] Define periodic_bc in one line --- src/parameters.f90 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/parameters.f90 b/src/parameters.f90 index b427afb5..4ecdf56c 100644 --- a/src/parameters.f90 +++ b/src/parameters.f90 @@ -139,9 +139,7 @@ subroutine parameter(input_i3d) nclzS1 = nclz1; nclzSn = nclzn !! set periodic direction - if (nclx1.eq.0 .and. nclxn.eq.0) periodic_bc(1)=.true. - if (ncly1.eq.0 .and. nclyn.eq.0) periodic_bc(2)=.true. - if (nclz1.eq.0 .and. nclzn.eq.0) periodic_bc(3)=.true. + periodic_bc = (/nclx1.eq.0, ncly1.eq.0, nclz1.eq.0/) if (numscalar.ne.0) then iscalar = 1 From 6cb06722a6a7afc22dc54d2cd00ad2a509cbeab2 Mon Sep 17 00:00:00 2001 From: fangjian19 Date: Thu, 20 Mar 2025 11:56:26 +0000 Subject: [PATCH 6/6] add a comment and format change --- src/particle.f90 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/particle.f90 b/src/particle.f90 index 2f9bfc32..8fb946dc 100644 --- a/src/particle.f90 +++ b/src/particle.f90 @@ -2087,7 +2087,7 @@ subroutine particle_bc(face,bctype,particle,particle_deduce) integer,intent(inout) :: particle_deduce ! local data - real(mytype),save :: bcord(6),lenpe(6) + real(mytype), dimension(6), save :: bcord, lenpe logical,save :: firstcal=.true. integer :: idir @@ -2100,6 +2100,8 @@ subroutine particle_bc(face,bctype,particle,particle_deduce) bcord(5)=0.0_mytype bcord(6)=zlz + ! lenpe is to get the particle back to the domain for periodic boundaries. + ! defined as the distance (+ or -) between the two paring periodic boundaries. lenpe(1)=xlx lenpe(2)=-xlx lenpe(3)=yly