Intermediate push

I still have to figure out how to do this properly, but I am tired of
working on my laptop.
This commit is contained in:
Jorge Gonzalez 2023-09-22 18:18:46 +02:00
commit 286e858d66
10 changed files with 166 additions and 139 deletions

View file

@ -3,7 +3,7 @@ MODULE moduleSolver
!Generic type for pusher of particles
TYPE, PUBLIC:: pusherGeneric
PROCEDURE(push_interafece), POINTER, NOPASS:: pushParticle => NULL()
PROCEDURE(push_interface), POINTER, NOPASS:: pushParticle => NULL()
!Boolean to indicate if the species is moved in the iteration
LOGICAL:: pushSpecies
!How many interations between advancing the species
@ -29,13 +29,13 @@ MODULE moduleSolver
INTERFACE
!Push a particle
PURE SUBROUTINE push_interafece(part, tauIn)
PURE SUBROUTINE push_interface(part, tauIn)
USE moduleSpecies
TYPE(particle), INTENT(inout):: part
REAL(8), INTENT(in):: tauIn
END SUBROUTINE push_interafece
END SUBROUTINE push_interface
!Solve the electromagnetic field
SUBROUTINE solveEM_interface()
@ -169,24 +169,75 @@ MODULE moduleSolver
USE moduleMesh
IMPLICIT NONE
INTEGER:: n
INTEGER:: sp
INTEGER:: p
INTEGER:: s, sp
INTEGER:: e
!$OMP DO
DO n = 1, nPartOld
!Select species type
sp = partOld(n)%species%n
!$OMP SINGLE
!Allocate the array of particles to push
nSpeciesToPush = COUNT(solver%pusher(:)%pushSpecies)
ALLOCATE(particlesToPush(1:nSpeciesToPush))
ALLOCATE(nPartOldToPush(1:nSpeciesToPush))
!Point the arrays to the location of the particles
sp = 0
DO s = 1, nSpecies
!Checks if the species sp is update this iteration
IF (solver%pusher(sp)%pushSpecies) THEN
!Push particle
CALL solver%pusher(sp)%pushParticle(partOld(n), tau(sp))
!Find cell in wich particle reside
CALL solver%updateParticleCell(partOld(n))
sp = sp + 1
particlesToPush(sp)%p = partOld(s)%p
nPartOldToPush(sp) = nPartOld(s)
END IF
END DO
!$OMP END DO
!Delete list of particles in cells for collisions if the particle is pushed
IF (listInCells) THEN
DO e = 1, mesh%numCells
DO s = 1, nSpecies
IF (solver%pusher(s)%pushSpecies) THEN
CALL mesh%cells(e)%obj%listPart_in(s)%erase()
mesh%cells(e)%obj%totalWeight(s) = 0.D0
END IF
END DO
END DO
END IF
!Erase the list of particles inside the cell in coll mesh if the particle is pushed
IF (doubleMesh) THEN
DO e = 1, meshColl%numCells
DO s = 1, nSpecies
IF (solver%pusher(s)%pushSpecies) THEN
CALL meshColl%cells(e)%obj%listPart_in(s)%erase()
meshColl%cells(e)%obj%totalWeight(s) = 0.D0
END IF
END DO
END DO
END IF
!$OMP END SINGLE
!Now, push particles
!$OMP DO
DO sp = 1, nSpeciesToPush
DO p = 1, nPartOldToPush(sp)
!Push particle
CALL solver%pusher(sp)%pushParticle(particlesToPush(sp)%p(p), tau(sp))
!Find cell in which particle reside
CALL solver%updateParticleCell(particlesToPush(sp)%p(p))
END DO
END DO
!$END OMP DO
END SUBROUTINE doPushes
@ -247,7 +298,10 @@ MODULE moduleSolver
!$OMP SECTION
nOldIn = 0
IF (ALLOCATED(partOld)) THEN
nOldIn = COUNT(partOld%n_in)
DO s = 1, nSpecies
nOldIn = nOldin + COUNT(partOld(s)%p(:)%n_in)
END DO
END IF
!$OMP SECTION
@ -324,40 +378,6 @@ MODULE moduleSolver
END DO
!$OMP SECTION
!Erase the list of particles inside the cell if particles have been pushed
IF (listInCells) THEN
DO s = 1, nSpecies
DO e = 1, mesh%numCells
IF (solver%pusher(s)%pushSpecies) THEN
CALL mesh%cells(e)%obj%listPart_in(s)%erase()
mesh%cells(e)%obj%totalWeight(s) = 0.D0
END IF
END DO
END DO
END IF
!$OMP SECTION
!Erase the list of particles inside the cell in coll mesh
IF (doubleMesh) THEN
DO s = 1, nSpecies
DO e = 1, meshColl%numCells
IF (solver%pusher(s)%pushSpecies) THEN
CALL meshColl%cells(e)%obj%listPart_in(s)%erase()
meshColl%cells(e)%obj%totalWeight(s) = 0.D0
END IF
END DO
END DO
END IF
!$OMP END SECTIONS
!$OMP SINGLE
@ -372,14 +392,17 @@ MODULE moduleSolver
USE moduleMesh
IMPLICIT NONE
INTEGER:: n
INTEGER:: n, sp
CLASS(meshCell), POINTER:: cell
!Loops over the particles to scatter them
!$OMP DO
DO n = 1, nPartOld
cell => mesh%cells(partOld(n)%cell)%obj
CALL cell%scatter(cell%nNodes, partOld(n))
DO sp = 1, nSpeciesToPush
DO n = 1, nPartOldToPush(sp)
cell => mesh%cells(particlesToPush(sp)%p(n)%cell)%obj
CALL cell%scatter(cell%nNodes, particlesToPush(sp)%p(n))
END DO
END DO
!$OMP END DO
@ -549,8 +572,8 @@ MODULE moduleSolver
END IF
IF (nPartOld > 0) THEN
WRITE(*, "(5X,A21,F8.1,A2)") "avg t/particle: ", 1.D9*tStep/DBLE(nPartOld), "ns"
IF (nPartOldTotal > 0) THEN
WRITE(*, "(5X,A21,F8.1,A2)") "avg t/particle: ", 1.D9*tStep/DBLE(nPartOldTotal), "ns"
END IF
WRITE(*,*)