Organized injection

This commit is contained in:
Jorge Gonzalez 2026-04-04 22:49:14 +02:00
commit 6b72dbb108
6 changed files with 63 additions and 60 deletions

View file

@ -1431,7 +1431,6 @@ MODULE moduleInput
CALL config%info('inject', found, n_children = nInject) CALL config%info('inject', found, n_children = nInject)
ALLOCATE(injects(1:nInject)) ALLOCATE(injects(1:nInject))
nPartInj = 0
DO i = 1, nInject DO i = 1, nInject
WRITE(iString, '(i2)') i WRITE(iString, '(i2)') i
object = 'inject(' // trim(iString) // ')' object = 'inject(' // trim(iString) // ')'
@ -1442,12 +1441,6 @@ MODULE moduleInput
END DO END DO
!Allocate array for injected particles
IF (nPartInj > 0) THEN
ALLOCATE(partInj(1:nPartInj))
END IF
END SUBROUTINE readInject END SUBROUTINE readInject
SUBROUTINE readAverage(config) SUBROUTINE readAverage(config)

View file

@ -14,7 +14,7 @@ output.o: moduleSpecies.o common.o
mesh.o: moduleList.o moduleSpecies.o moduleCollisions.o moduleCoulomb.o output.o common.o mesh.o: moduleList.o moduleSpecies.o moduleCollisions.o moduleCoulomb.o output.o common.o
$(MAKE) -C mesh all $(MAKE) -C mesh all
solver.o: moduleSpecies.o moduleProbe.o common.o output.o mesh.o solver.o: moduleInject.o moduleSpecies.o moduleProbe.o common.o output.o mesh.o
$(MAKE) -C solver all $(MAKE) -C solver all
init.o: common.o solver.o moduleInject.o init.o: common.o solver.o moduleInject.o

View file

@ -313,23 +313,21 @@ MODULE moduleInject
end subroutine updateQuasiNeutral end subroutine updateQuasiNeutral
!Add particles for the injection !Add particles for the injection
SUBROUTINE addParticles(self, partArray) SUBROUTINE addParticles(self)
USE moduleSpecies USE moduleSpecies
USE moduleMesh USE moduleMesh
USE moduleRandom USE moduleRandom
USE moduleErrors USE moduleErrors
use moduleList, only: partInj
IMPLICIT NONE IMPLICIT NONE
CLASS(injectGeneric), INTENT(in):: self CLASS(injectGeneric), INTENT(in):: self
type(particle), allocatable, intent(inout):: partArray(:) type(particle), pointer:: part
INTEGER:: i, e INTEGER:: i, e
INTEGER:: n, sp INTEGER:: sp
CLASS(meshEdge), POINTER:: edge CLASS(meshEdge), POINTER:: edge
REAL(8):: direction(1:3)
!$omp single REAL(8):: direction(1:3)
n = 0
!$omp end single
!Insert particles !Insert particles
!$OMP DO !$OMP DO
@ -338,30 +336,30 @@ MODULE moduleInject
edge => self%edges(e)%obj edge => self%edges(e)%obj
! Inject particles in edge ! Inject particles in edge
DO i = 1, self%particlesPerEdge(e) DO i = 1, self%particlesPerEdge(e)
allocate(part)
! Index in the partInj array ! Index in the partInj array
n = n + 1 !Particle is considered to be inside the domain
!Particle is considered to be outside the domain for now part%n_in = .true.
partArray(n)%n_in = .FALSE.
!Random position in edge !Random position in edge
partArray(n)%r = edge%randPos() part%r = edge%randPos()
!Assign weight to particle. !Assign weight to particle.
partArray(n)%weight = self%weightPerEdge(e) part%weight = self%weightPerEdge(e)
!Volume associated to the edge: !Volume associated to the edge:
IF (ASSOCIATED(edge%e1)) THEN IF (ASSOCIATED(edge%e1)) THEN
partArray(n)%cell = edge%e1%n part%cell = edge%e1%n
ELSEIF (ASSOCIATED(edge%e2)) THEN ELSEIF (ASSOCIATED(edge%e2)) THEN
partArray(n)%cell = edge%e2%n part%cell = edge%e2%n
ELSE ELSE
CALL criticalError("No Volume associated to edge", 'addParticles') CALL criticalError("No Volume associated to edge", 'addParticles')
END IF END IF
partArray(n)%cellColl = edge%eColl%n part%cellColl = edge%eColl%n
sp = self%species%n sp = self%species%n
!Assign particle type !Assign particle type
partArray(n)%species => self%species part%species => self%species
if (all(self%n == 0.D0)) then if (all(self%n == 0.D0)) then
direction = edge%normal direction = edge%normal
@ -371,23 +369,28 @@ MODULE moduleInject
end if end if
partArray(n)%v = 0.D0 part%v = 0.D0
! do while(dot_product(partInj(n)%v, direction) <= 0.d0) ! do while(dot_product(partInj(n)%v, direction) <= 0.d0)
partArray(n)%v = self%vMod*direction + (/ self%v(1)%obj%randomVel(), & part%v = self%vMod*direction + (/ self%v(1)%obj%randomVel(), &
self%v(2)%obj%randomVel(), & self%v(2)%obj%randomVel(), &
self%v(3)%obj%randomVel() /) self%v(3)%obj%randomVel() /)
!If injecting a no-drift distribution and velocity is negative, reflect !If injecting a no-drift distribution and velocity is negative, reflect
if ((self%vMod == 0.D0) .and. & if ((self%vMod == 0.D0) .and. &
(dot_product(partArray(n)%v, direction) <= 0.D0)) then (dot_product(part%v, direction) <= 0.D0)) then
partArray(n)%v = - partArray(n)%v part%v = - part%v
end if end if
! end do ! end do
!Obtain natural coordinates of particle in cell !Obtain natural coordinates of particle in cell
partArray(n)%Xi = mesh%cells(partArray(n)%cell)%obj%phy2log(partArray(n)%r) part%Xi = mesh%cells(part%cell)%obj%phy2log(part%r)
! Add particle to global list
call partInj%setLock()
call partInj%add(part)
call partInj%unsetLock()
END DO END DO

View file

@ -23,6 +23,7 @@ MODULE moduleList
END TYPE listNode END TYPE listNode
TYPE(listNode):: partInj !Particles comming from injections
TYPE(listNode):: partWScheme !Particles comming from the nonAnalogue scheme TYPE(listNode):: partWScheme !Particles comming from the nonAnalogue scheme
TYPE(listNode):: partCollisions !Particles created in collisional process TYPE(listNode):: partCollisions !Particles created in collisional process
TYPE(listNode):: partSurfaces !Particles created in surface interactions TYPE(listNode):: partSurfaces !Particles created in surface interactions

View file

@ -48,11 +48,8 @@ MODULE moduleSpecies
!Number of old particles !Number of old particles
INTEGER:: nPartOld INTEGER:: nPartOld
!Number of injected particles
INTEGER:: nPartInj
!Arrays that contain the particles !Arrays that contain the particles
TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: partOld !array of particles from previous iteration TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: partOld !array of particles from previous iteration
TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: partInj !array of inject particles
CONTAINS CONTAINS
FUNCTION speciesName2Index(speciesName) RESULT(sp) FUNCTION speciesName2Index(speciesName) RESULT(sp)

View file

@ -235,23 +235,21 @@ MODULE moduleSolver
INTEGER:: nn, n, e INTEGER:: nn, n, e
INTEGER, SAVE:: nPartNew INTEGER, SAVE:: nPartNew
INTEGER, SAVE:: nInjIn, nOldIn, nWScheme, nCollisions, nSurfaces INTEGER, SAVE:: nOldIn, nInj, nWScheme, nCollisions, nSurfaces
TYPE(particle), ALLOCATABLE, SAVE:: partTemp(:) TYPE(particle), ALLOCATABLE, SAVE:: partTemp(:)
INTEGER:: s INTEGER:: s
!$OMP SECTIONS !$OMP SECTIONS
!$OMP SECTION !$OMP SECTION
nInjIn = 0
IF (ALLOCATED(partInj)) THEN
nInjIn = COUNT(partInj%n_in)
END IF
!$OMP SECTION
nOldIn = 0 nOldIn = 0
IF (ALLOCATED(partOld)) THEN IF (ALLOCATED(partOld)) THEN
nOldIn = COUNT(partOld%n_in) nOldIn = COUNT(partOld%n_in)
END IF END IF
!$OMP SECTION
nInj = partInj%amount
!$OMP SECTION !$OMP SECTION
nWScheme = partWScheme%amount nWScheme = partWScheme%amount
@ -267,30 +265,14 @@ MODULE moduleSolver
!$OMP SINGLE !$OMP SINGLE
CALL MOVE_ALLOC(partOld, partTemp) CALL MOVE_ALLOC(partOld, partTemp)
nPartNew = nInjIn + nOldIn + nWScheme + nCollisions + nSurfaces nPartNew = nInj + nOldIn + nWScheme + nCollisions + nSurfaces
ALLOCATE(partOld(1:nPartNew)) ALLOCATE(partOld(1:nPartNew))
!$OMP END SINGLE !$OMP END SINGLE
!$OMP SECTIONS !$OMP SECTIONS
!$OMP SECTION
!Reset particles from injection
nn = 0
DO n = 1, nPartInj
IF (partInj(n)%n_in) THEN
nn = nn + 1
partOld(nn) = partInj(n)
IF (nProbes > 0) THEN
CALL doProbes(partOld(nn))
END IF
END IF
END DO
!$OMP SECTION !$OMP SECTION
!Reset particles from previous iteration !Reset particles from previous iteration
nn = nInjIn nn = 0
DO n = 1, nPartOld DO n = 1, nPartOld
IF (partTemp(n)%n_in) THEN IF (partTemp(n)%n_in) THEN
nn = nn + 1 nn = nn + 1
@ -304,19 +286,24 @@ MODULE moduleSolver
END DO END DO
!$OMP SECTION
!Reset particles from injection
nn = nOldIn
call resetList(partInj, partOld, nn)
!$OMP SECTION !$OMP SECTION
!Reset particles from weighting scheme !Reset particles from weighting scheme
nn = nInjIn + nOldIn nn = nOldIn + nInj
CALL resetList(partWScheme, partOld, nn) CALL resetList(partWScheme, partOld, nn)
!$OMP SECTION !$OMP SECTION
!Reset particles from collisional process !Reset particles from collisional process
nn = nInjIn + nOldIn + nWScheme nn = nOldIn + nInj + nWScheme
CALL resetList(partCollisions, partOld, nn) CALL resetList(partCollisions, partOld, nn)
!$OMP SECTION !$OMP SECTION
!Reset particles from surface process !Reset particles from surface process
nn = nInjIn + nOldIn + nWScheme + nCollisions nn = nOldIn + nInj + nWScheme + nCollisions
CALL resetList(partSurfaces, partOld, nn) CALL resetList(partSurfaces, partOld, nn)
!$OMP SECTION !$OMP SECTION
@ -473,6 +460,28 @@ MODULE moduleSolver
END SUBROUTINE splitParticle END SUBROUTINE splitParticle
!Injection of particles
SUBROUTINE doInjects()
USE moduleSpecies
use moduleInject
IMPLICIT NONE
INTEGER:: i, n, sp
DO i=1, nInject
associate(inject => injects(i)%obj)
sp = inject%species%n
IF (solver%pusher(sp)%pushSpecies) THEN
CALL inject%addParticles()
END IF
end associate
END DO
END SUBROUTINE doInjects
SUBROUTINE updateParticleCell(self, part) SUBROUTINE updateParticleCell(self, part)
USE moduleSpecies USE moduleSpecies
USE moduleMesh USE moduleMesh