Shifting towards constant number of particles per edge

So now each edge has the same number of particles and the weight of each
particle is calculated based on the surface of each edge compared to the
total one.

Only in 2DCyl, still to extend to other geometries.

Not perfect constant density, but the issue might be the node volume.
This commit is contained in:
Jorge Gonzalez 2024-07-09 17:49:42 +02:00
commit b36f9c2615
5 changed files with 36 additions and 49 deletions

View file

@ -63,6 +63,7 @@ MODULE moduleInject
INTEGER, ALLOCATABLE:: edges(:) !Array with edges
REAL(8), ALLOCATABLE:: cumWeight(:) !Array of cummulative probability
REAL(8):: sumWeight
REAL(8):: surface ! Total surface of injection
TYPE(velDistCont):: v(1:3) !Velocity distribution function in each direction
CONTAINS
PROCEDURE, PASS:: init => initInject
@ -164,15 +165,12 @@ MODULE moduleInject
END DO
!Calculates cumulative probability
ALLOCATE(self%cumWeight(1:self%nEdges))
et = 1
self%cumWeight(1) = mesh%edges(self%edges(et))%obj%weight
DO et = 2, self%nEdges
self%cumWeight(et) = mesh%edges(self%edges(et))%obj%weight + self%cumWeight(et-1)
!Calculates total area
self%surface = 0.D0
DO et = 1, self%nEdges
self%surface = self%surface + mesh%edges(self%edges(et))%obj%surface
END DO
self%sumWeight = self%cumWeight(self%nEdges)
END SUBROUTINE initInject
@ -313,12 +311,12 @@ MODULE moduleInject
!$OMP DO
DO n = nMin, nMax
randomX = randomWeighted(self%cumWeight, self%sumWeight)
randomX = random(1, self%nEdges)
randomEdge => mesh%edges(self%edges(randomX))%obj
!Random position in edge
partInj(n)%r = randomEdge%randPos()
!Assign weight to particle.
partInj(n)%weight = self%species%weight
partInj(n)%weight = self%species%weight * randomEdge%surface / self%surface
!Volume associated to the edge:
IF (ASSOCIATED(randomEdge%e1)) THEN
partInj(n)%cell = randomEdge%e1%n