fpakc/src/modules/moduleList.f90
JGonzalez cbb5fe0bf2 Merge branch 'feature/collisionPairs' into feature/electromagnetic
Merging branches and fixing a number of important issues:

- Initial particles were not being assigned to the list of particles.

- List of particles was being erased every iteration, even if species
  was not pushed.

These caused issues with the calculation of collisions when a species
was frozen.

Now, things should work properly. All particles are properly added to
the volume list and the list is erased ONLY if the species has been
updated.

I hope that collisions are now properly accounted for per species pair.
2022-04-23 20:48:34 +02:00

98 lines
2.6 KiB
Fortran

!Linked list of particles
MODULE moduleList
USE moduleSpecies
IMPLICIT NONE
TYPE lNode
TYPE(particle), POINTER:: part => NULL()
TYPE(lNode), POINTER:: next => NULL()
END TYPE lNode
TYPE listNode
INTEGER:: amount = 0
TYPE(lNode),POINTER:: head => NULL()
TYPE(lNode),POINTER:: tail => NULL()
CONTAINS
PROCEDURE,PASS:: add => addToList
PROCEDURE,PASS:: convert2Array
PROCEDURE,PASS:: erase => eraseList
END TYPE listNode
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
INTEGER(KIND=OMP_LOCK_KIND):: lockCollisions !Lock for the NA list of particles
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 pointerArray
TYPE(particle), POINTER:: part
END TYPE
CONTAINS
!Adds element to list
SUBROUTINE addToList(self,part)
USE moduleSpecies
CLASS(listNode), INTENT(inout):: self
TYPE(particle),INTENT(in), TARGET:: part
TYPE(lNode),POINTER:: temp
ALLOCATE(temp)
temp%part => part
temp%next => NULL()
self%amount = self%amount + 1
IF (.NOT. ASSOCIATED(self%head)) THEN
!First element
self%head => temp
self%tail => temp
ELSE
!Append element
self%tail%next => temp
self%tail => temp
END IF
END SUBROUTINE addToList
!converts list to array
FUNCTION convert2Array(self) RESULT(partArray)
IMPLICIT NONE
CLASS(listNode), INTENT(in):: self
TYPE(pointerArray), ALLOCATABLE:: partArray(:)
TYPE(lNode), POINTER:: tempNode
INTEGER:: n
ALLOCATE(partArray(1:self%amount))
tempNode => self%head
DO n=1, self%amount
!Point element in array to element in list
partArray(n)%part => tempNode%part
!Go to next element
tempNode => tempNode%next
END DO
END FUNCTION convert2Array
!Erase list
SUBROUTINE eraseList(self)
CLASS(listNode):: self
TYPE(lNode),POINTER:: current, next
current => self%head
DO WHILE (ASSOCIATED(current))
next => current%next
DEALLOCATE(current)
current => next
END DO
IF (ASSOCIATED(self%head)) NULLIFY(self%head)
IF (ASSOCIATED(self%tail)) NULLIFY(self%tail)
self%amount = 0
END SUBROUTINE eraseList
END MODULE moduleList