Merge branch 'issue/collisionWeight' into 'development'

Adjusting weights for collisions

See merge request JorgeGonz/fpakc!32
This commit is contained in:
Jorge Gonzalez 2022-12-31 10:25:33 +00:00
commit c82cd50cf9
5 changed files with 106 additions and 36 deletions

View file

@ -612,7 +612,7 @@ MODULE moduleInput
nPartOld = 0 nPartOld = 0
!Initialize the lock for the non-analogue (NA) list of particles !Initialize the lock for the non-analogue (NA) list of particles
CALL OMP_INIT_LOCK(lockWScheme) CALL OMP_INIT_LOCK(partWScheme%lock)
END SUBROUTINE readSpecies END SUBROUTINE readSpecies
@ -676,7 +676,7 @@ MODULE moduleInput
CALL config%get('interactions.folderCollisions', pathCollisions, found) CALL config%get('interactions.folderCollisions', pathCollisions, found)
!Inits lock for list of particles !Inits lock for list of particles
CALL OMP_INIT_LOCK(lockCollisions) CALL OMP_INIT_LOCK(partCollisions%lock)
CALL config%info('interactions.collisions', found, n_children = nPairs) CALL config%info('interactions.collisions', found, n_children = nPairs)
DO i = 1, nPairs DO i = 1, nPairs
@ -770,6 +770,7 @@ MODULE moduleInput
USE moduleErrors USE moduleErrors
USE moduleSpecies USE moduleSpecies
USE moduleRefParam USE moduleRefParam
USE moduleList, ONLY: partSurfaces
USE json_module USE json_module
IMPLICIT NONE IMPLICIT NONE
@ -862,6 +863,9 @@ MODULE moduleInput
END DO END DO
!Init the list of particles from surfaces
CALL OMP_INIT_LOCK(partSurfaces%lock)
END SUBROUTINE readBoundary END SUBROUTINE readBoundary
!Read the geometry (mesh) for the case !Read the geometry (mesh) for the case

View file

@ -169,10 +169,10 @@ MODULE moduleMeshBoundary
newIon%n_in = .TRUE. newIon%n_in = .TRUE.
!Add particles to list !Add particles to list
CALL OMP_SET_LOCK(lockSurfaces) CALL partSurfaces%setLock()
CALL partSurfaces%add(newElectron) CALL partSurfaces%add(newElectron)
CALL partSurfaces%add(newIon) CALL partSurfaces%add(newIon)
CALL OMP_UNSET_LOCK(lockSurfaces) CALL partSurfaces%unsetLock()
!Electron loses energy due to ionization !Electron loses energy due to ionization
eRel = eRel - bound%eThreshold eRel = eRel - bound%eThreshold

View file

@ -305,7 +305,7 @@ MODULE moduleCollisions
REAL(8):: rMass, eRel REAL(8):: rMass, eRel
TYPE(particle), POINTER:: electron => NULL(), neutral => NULL() TYPE(particle), POINTER:: electron => NULL(), neutral => NULL()
REAL(8), DIMENSION(1:3):: vChange REAL(8), DIMENSION(1:3):: vChange
TYPE(particle), POINTER:: newElectron TYPE(particle), POINTER:: newElectron => NULL(), remainingNeutral => NULL()
rMass = reducedMass(part_i%weight*part_i%species%m, part_j%weight*part_j%species%m) rMass = reducedMass(part_i%weight*part_i%species%m, part_j%weight*part_j%species%m)
eRel = rMass*vRel**2 eRel = rMass*vRel**2
@ -324,6 +324,38 @@ MODULE moduleCollisions
END IF END IF
!Exchange of velocity between particles
vChange = self%deltaV*randomDirectionVHS()
!Energy is loss by the primary electron
electron%v = electron%v - vChange
!Creates a new electron from ionization
ALLOCATE(newElectron)
!Copy basic information from primary electron
newElectron = electron
!Secondary electorn gains energy from ionization
newElectron%v = vChange
!Correct the weight of the particles
IF (electron%weight >= neutral%weight) THEN
!If primary electron is hevier than neutral, reduce weight to secondary electron
newElectron%weight = neutral%weight
ELSEIF (electron%weight < neutral%weight) THEN
!If primary electron is ligther than neutral, change weight of neutral and create new neutral
ALLOCATE(remainingNeutral)
remainingNeutral = neutral
remainingNeutral%weight = neutral%weight - electron%weight
neutral%weight = electron%weight
END IF
!Ionize neutral particle !Ionize neutral particle
SELECT TYPE(sp => neutral%species) SELECT TYPE(sp => neutral%species)
TYPE IS(speciesNeutral) TYPE IS(speciesNeutral)
@ -335,28 +367,14 @@ MODULE moduleCollisions
END SELECT END SELECT
!Exchange of velocity between particles !Adds new particles to the list
vChange = self%deltaV*randomDirectionVHS() CALL partCollisions%setLock()
!Energy is loss by the primary electron
electron%v = electron%v - vChange
!Creates a new electron from ionization
ALLOCATE(newElectron)
newElectron%species => electron%species
!Secondary electorn gains energy from ionization
newElectron%v = vChange
newElectron%r = neutral%r
newElectron%xi = neutral%xi
newElectron%n_in = .TRUE.
newElectron%vol = neutral%vol
newElectron%volColl = neutral%volColl
newElectron%weight = neutral%weight
!Adds new electron to list of new particles from collisions
CALL OMP_SET_LOCK(lockCollisions)
CALL partCollisions%add(newElectron) CALL partCollisions%add(newElectron)
CALL OMP_UNSET_LOCK(lockCollisions) IF (ASSOCIATED(remainingNeutral)) THEN
CALL partCollisions%add(remainingNeutral)
END IF
CALL partCollisions%unsetLock()
END IF END IF
@ -399,7 +417,8 @@ MODULE moduleCollisions
collision%electron => sp collision%electron => sp
CLASS DEFAULT CLASS DEFAULT
CALL criticalError("Species " // sp%name // " chosen for ionization is not a charged species", 'initBinaryIonization') CALL criticalError("Species " // sp%name // " chosen for recombination is not a charged species", &
'initBinaryRecombination')
END SELECT END SELECT
@ -422,6 +441,7 @@ MODULE moduleCollisions
TYPE(particle), POINTER:: electron => NULL(), ion => NULL() TYPE(particle), POINTER:: electron => NULL(), ion => NULL()
REAL(8):: sigmaVrel REAL(8):: sigmaVrel
REAL(8), DIMENSION(1:3):: vp_i REAL(8), DIMENSION(1:3):: vp_i
TYPE(particle), POINTER:: remainingIon => NULL()
IF (ASSOCIATED(part_i%species, self%electron)) THEN IF (ASSOCIATED(part_i%species, self%electron)) THEN
electron => part_i electron => part_i
@ -440,9 +460,28 @@ MODULE moduleCollisions
!TODO: This energy should be transformed into photons !TODO: This energy should be transformed into photons
vp_i = ion%v* (1.D0 - (vRel + self%deltaV)/NORM2(ion%v)) vp_i = ion%v* (1.D0 - (vRel + self%deltaV)/NORM2(ion%v))
IF (electron%weight > ion%weight) THEN
!Reduce weight of primary electron but particle continues
electron%weight = electron%weight - ion%weight
ELSE
!Remove electron from simulation !Remove electron from simulation
electron%n_in = .FALSE. electron%n_in = .FALSE.
!There is some ion remaining
IF (electron%weight < ion%weight) THEN
ALLOCATE(remainingIon)
remainingIon = ion
remainingIon%weight = ion%weight - electron%weight
ion%weight = electron%weight
END IF
END IF
!Neutralize ion particle !Neutralize ion particle
SELECT TYPE(sp => ion%species) SELECT TYPE(sp => ion%species)
TYPE IS(speciesCharged) TYPE IS(speciesCharged)
@ -453,6 +492,13 @@ MODULE moduleCollisions
END SELECT END SELECT
!Adds new particles to the list
IF (ASSOCIATED(remainingIon)) THEN
CALL partCollisions%setLock()
CALL partCollisions%add(remainingIon)
CALL partCollisions%unsetLock()
END IF
END SUBROUTINE collideBinaryRecombination END SUBROUTINE collideBinaryRecombination
!RESONANT CHARGE EXCHANGE !RESONANT CHARGE EXCHANGE

View file

@ -13,19 +13,19 @@ MODULE moduleList
INTEGER:: amount = 0 INTEGER:: amount = 0
TYPE(lNode),POINTER:: head => NULL() TYPE(lNode),POINTER:: head => NULL()
TYPE(lNode),POINTER:: tail => NULL() TYPE(lNode),POINTER:: tail => NULL()
INTEGER(KIND=OMP_LOCK_KIND):: lock
CONTAINS CONTAINS
PROCEDURE,PASS:: add => addToList PROCEDURE,PASS:: add => addToList
PROCEDURE,PASS:: convert2Array PROCEDURE,PASS:: convert2Array
PROCEDURE,PASS:: erase => eraseList PROCEDURE,PASS:: erase => eraseList
PROCEDURE,PASS:: setLock
PROCEDURE,PASS:: unsetLock
END TYPE listNode END TYPE listNode
TYPE(listNode):: partWScheme !Particles comming from the nonAnalogue scheme TYPE(listNode):: partWScheme !Particles comming from the nonAnalogue scheme
INTEGER(KIND=OMP_LOCK_KIND):: lockWScheme !Lock for the NA list of particles
TYPE(listNode):: partCollisions !Particles created in collisional process TYPE(listNode):: partCollisions !Particles created in collisional process
INTEGER(KIND=OMP_LOCK_KIND):: lockCollisions !Lock for the NA list of particles
TYPE(listNode):: partSurfaces !Particles created in surface interactions TYPE(listNode):: partSurfaces !Particles created in surface interactions
INTEGER(KIND=OMP_LOCK_KIND):: lockSurfaces !Lock for the NA list of particles
TYPE(listNode):: partInitial !Initial distribution of particles TYPE(listNode):: partInitial !Initial distribution of particles
TYPE pointerArray TYPE pointerArray
@ -80,8 +80,10 @@ MODULE moduleList
END FUNCTION convert2Array END FUNCTION convert2Array
!Erase list !Erase list
SUBROUTINE eraseList(self) PURE SUBROUTINE eraseList(self)
CLASS(listNode):: self IMPLICIT NONE
CLASS(listNode), INTENT(inout):: self
TYPE(lNode),POINTER:: current, next TYPE(lNode),POINTER:: current, next
current => self%head current => self%head
@ -95,4 +97,22 @@ MODULE moduleList
self%amount = 0 self%amount = 0
END SUBROUTINE eraseList END SUBROUTINE eraseList
SUBROUTINE setLock(self)
USE OMP_LIB
IMPLICIT NONE
CLASS(listNode):: self
CALL OMP_SET_LOCK(self%lock)
END SUBROUTINE setLock
SUBROUTINE unsetLock(self)
USE OMP_LIB
IMPLICIT NONE
CLASS(listNode):: self
CALL OMP_UNSET_LOCK(self%lock)
END SUBROUTINE unsetLock
END MODULE moduleList END MODULE moduleList

View file

@ -434,9 +434,9 @@ MODULE moduleSolver
!Copy data from original particle !Copy data from original particle
newPart = part newPart = part
!Add particle to list of new particles from weighting scheme !Add particle to list of new particles from weighting scheme
CALL OMP_SET_LOCK(lockWScheme) CALL partWScheme%setLock()
CALL partWScheme%add(newPart) CALL partWScheme%add(newPart)
CALL OMP_UNSET_LOCK(lockWScheme) CALL partWScheme%unsetLock()
!Add particle to cell list !Add particle to cell list
CALL OMP_SET_lock(vol%lock) CALL OMP_SET_lock(vol%lock)
sp = part%species%n sp = part%species%n