Reducing overhead when no collisions are present

Particles are added to lists only if there are MCC collisions. Hopefully
this will reduce overhead when OpenMP is used and no collisions are
active.
This commit is contained in:
Jorge Gonzalez 2023-01-07 12:12:37 +01:00
commit 7ce1b7a4dd
13 changed files with 142 additions and 114 deletions

View file

@ -43,14 +43,14 @@ MODULE moduleSolver
END SUBROUTINE solveEM_interface
!Apply nonAnalogue scheme to a particle
SUBROUTINE weightingScheme_interface(part, volOld, volNew)
SUBROUTINE weightingScheme_interface(part, cellOld, cellNew)
USE moduleSpecies
USE moduleMesh
IMPLICIT NONE
TYPE(particle), INTENT(inout):: part
CLASS(meshCell), POINTER, INTENT(in):: volOld
CLASS(meshCell), POINTER, INTENT(inout):: volNew
CLASS(meshCell), POINTER, INTENT(in):: cellOld
CLASS(meshCell), POINTER, INTENT(inout):: cellNew
END SUBROUTINE weightingScheme_interface
@ -322,31 +322,37 @@ MODULE moduleSolver
!$OMP SECTION
!Erase the list of particles inside the cell if particles have been pushed
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
IF (doMCC) 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 IF
END DO
END DO
END DO
END IF
!$OMP SECTION
!Erase the list of particles inside the cell in coll mesh
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
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 IF
END DO
END DO
END DO
END IF
!$OMP END SECTIONS
@ -368,7 +374,7 @@ MODULE moduleSolver
!Loops over the particles to scatter them
!$OMP DO
DO n = 1, nPartOld
cell => mesh%cells(partOld(n)%vol)%obj
cell => mesh%cells(partOld(n)%cell)%obj
CALL cell%scatter(cell%nNodes, partOld(n))
END DO
@ -387,28 +393,28 @@ MODULE moduleSolver
END SUBROUTINE doEMField
!Split particles as a function of cell volume and splits particle
SUBROUTINE volumeWScheme(part, volOld, volNew)
SUBROUTINE volumeWScheme(part, cellOld, cellNew)
USE moduleSpecies
USE moduleMesh
USE moduleRandom
IMPLICIT NONE
TYPE(particle), INTENT(inout):: part
CLASS(meshCell), POINTER, INTENT(in):: volOld
CLASS(meshCell), POINTER, INTENT(inout):: volNew
CLASS(meshCell), POINTER, INTENT(in):: cellOld
CLASS(meshCell), POINTER, INTENT(inout):: cellNew
REAL(8):: fractionVolume, pSplit
!If particle changes volume to smaller cell
IF (volOld%volume > volNew%volume .AND. &
IF (cellOld%volume > cellNew%volume .AND. &
part%weight >= part%species%weight*1.0D-1) THEN
fractionVolume = volOld%volume/volNew%volume
fractionVolume = cellOld%volume/cellNew%volume
!Calculate probability of splitting particle
pSplit = 1.D0 - DEXP(-fractionVolume*1.0D-1)
IF (random() < pSplit) THEN
!Split particle in two
CALL splitParticle(part, 2, volNew)
CALL splitParticle(part, 2, cellNew)
END IF
@ -418,7 +424,7 @@ MODULE moduleSolver
!Subroutine to split the particle 'part' into a number 'nSplit' of particles.
!'nSplit-1' particles are added to the partNAScheme list
SUBROUTINE splitParticle(part, nSplit, vol)
SUBROUTINE splitParticle(part, nSplit, cell)
USE moduleSpecies
USE moduleList
USE moduleMesh
@ -427,7 +433,7 @@ MODULE moduleSolver
TYPE(particle), INTENT(inout):: part
INTEGER, INTENT(in):: nSplit
CLASS(meshCell), INTENT(inout):: vol
CLASS(meshCell), INTENT(inout):: cell
REAL(8):: newWeight
TYPE(particle), POINTER:: newPart
INTEGER:: p
@ -449,10 +455,13 @@ MODULE moduleSolver
CALL partWScheme%add(newPart)
CALL partWScheme%unsetLock()
!Add particle to cell list
CALL OMP_SET_lock(vol%lock)
sp = part%species%n
CALL vol%listPart_in(sp)%add(newPart)
CALL OMP_UNSET_lock(vol%lock)
IF (doMCC) THEN
CALL OMP_SET_lock(cell%lock)
CALL cell%listPart_in(sp)%add(newPart)
CALL OMP_UNSET_lock(cell%lock)
END IF
END DO
@ -465,18 +474,18 @@ MODULE moduleSolver
CLASS(solverGeneric), INTENT(in):: self
TYPE(particle), INTENT(inout):: part
CLASS(meshCell), POINTER:: volOld, volNew
CLASS(meshCell), POINTER:: cellOld, cellNew
!Assume that particle is outside the domain
part%n_in = .FALSE.
volOld => mesh%cells(part%vol)%obj
CALL volOld%findCell(part)
cellOld => mesh%cells(part%cell)%obj
CALL cellOld%findCell(part)
CALL findCellColl(part)
!Call the NA shcme
IF (ASSOCIATED(self%weightingScheme)) THEN
volNew => mesh%cells(part%vol)%obj
CALL self%weightingScheme(part, volOld, volNew)
cellNew => mesh%cells(part%cell)%obj
CALL self%weightingScheme(part, cellOld, cellNew)
END IF