Modification to Probes to use all particles

Now, probes check all particles in the domain.
This is done only when probes are outputed to save CPU time.
However, still some issues and distribution functions are not properly
being calculated.
This commit is contained in:
Jorge Gonzalez 2021-10-18 16:00:28 +02:00
commit e683c66ff8
4 changed files with 132 additions and 83 deletions

View file

@ -1,11 +1,9 @@
MODULE moduleProbe
USE moduleMesh
USE moduleSpecies
TYPE:: probeDistFunc
INTEGER:: id
REAL(8), DIMENSION(1:3):: r
CLASS(meshVol), POINTER:: cell
CLASS(speciesGeneric), POINTER:: species
REAL(8), ALLOCATABLE, DIMENSION(:):: vi, vj, vk
REAL(8), ALLOCATABLE, DIMENSION(:,:,:):: f
@ -13,6 +11,9 @@ MODULE moduleProbe
REAL(8), DIMENSION(1:3):: vrange
REAL(8):: dvInv
INTEGER:: every
LOGICAL:: update
INTEGER(KIND=OMP_LOCK_KIND):: lock
REAL(8):: maxR
CONTAINS
PROCEDURE, PASS:: init
PROCEDURE, PASS:: findLowerIndex
@ -41,7 +42,7 @@ MODULE moduleProbe
REAL(8), INTENT(in):: v1(1:2), v2(1:2), v3(1:2)
INTEGER, INTENT(in):: points(1:3)
REAL(8), INTENT(in):: timeStep
INTEGER:: sp, e, i
INTEGER:: sp, i
REAL(8):: dv(1:3)
!Assign id
@ -53,9 +54,6 @@ MODULE moduleProbe
!Find cell
self%r = r/L_ref
e = findCellBrute(mesh, self%r)
IF (e == 0) CALL criticalError("No cell found for position in probe", 'init')
self%cell => mesh%vols(e)%obj
!Allocates velocity grid
self%nv = points
@ -94,6 +92,13 @@ MODULE moduleProbe
!Number of iterations between output
self%every = NINT(timeStep/ tauMin / ti_ref)
!Maximum radius
!TODO: Make this an input parameter
self%maxR = 1.D-1/L_ref
!Init the probe lock
CALL OMP_INIT_LOCK(self%lock)
END SUBROUTINE init
@ -114,32 +119,28 @@ MODULE moduleProbe
END SUBROUTINE findLowerIndex
SUBROUTINE calculate(self)
SUBROUTINE calculate(self, part)
USE moduleSpecies
USE moduleList
IMPLICIT NONE
CLASS(probeDistFunc), INTENT(inout):: self
TYPE(particle), POINTER:: part
TYPE(lNode), POINTER:: node
TYPE(particle), INTENT(in):: part
REAL(8):: deltaR
INTEGER:: i, j, k
LOGICAL:: inside
REAL(8):: weight
REAL(8):: fi, fi1
REAL(8):: fj, fj1
REAL(8):: fk, fk1
!Reset distribution function
self%f = 0.D0
!If particle is of desired type, include in the distribution function
IF (part%species%n == self%species%n) THEN
!Calculate distance between particle and probe
deltaR = NORM2(self%r - part%r)
!Loop over particles in cell
node => self%cell%listPart_in%head
DO WHILE(ASSOCIATED(node))
!Selects particle on list
part => node%part
!If particle is of desired type, include in the distribution function
IF (part%species%n == self%species%n) THEN
!Only include particle if it is inside the maximum radius
IF (deltaR < self%maxR) THEN
!find lower index for all dimensions
CALL self%findLowerIndex(part%v, i, j, k, inside)
@ -153,28 +154,31 @@ MODULE moduleProbe
fk = self%vk(k+1) - part%v(3)
fk1 = part%v(3) - self%vk(k)
! weight = part%weight * DEXP(deltaR/self%maxR)
weight = part%weight
!Lock the probe
CALL OMP_SET_LOCK(self%lock)
!Assign particle weight to distribution function
self%f(i , j , k ) = fi * fj * fk * part%weight
self%f(i+1, j , k ) = fi1 * fj * fk * part%weight
self%f(i , j+1, k ) = fi * fj1 * fk * part%weight
self%f(i+1, j+1, k ) = fi1 * fj1 * fk * part%weight
self%f(i , j , k+1) = fi * fj * fk1 * part%weight
self%f(i+1, j , k+1) = fi1 * fj * fk1 * part%weight
self%f(i , j+1, k+1) = fi * fj1 * fk1 * part%weight
self%f(i+1, j+1, k+1) = fi1 * fj1 * fk1 * part%weight
self%f(i , j , k ) = fi * fj * fk * weight
self%f(i+1, j , k ) = fi1 * fj * fk * weight
self%f(i , j+1, k ) = fi * fj1 * fk * weight
self%f(i+1, j+1, k ) = fi1 * fj1 * fk * weight
self%f(i , j , k+1) = fi * fj * fk1 * weight
self%f(i+1, j , k+1) = fi1 * fj * fk1 * weight
self%f(i , j+1, k+1) = fi * fj1 * fk1 * weight
self%f(i+1, j+1, k+1) = fi1 * fj1 * fk1 * weight
!Unlock the probe
CALL OMP_UNSET_LOCK(self%lock)
END IF
END IF
!Move to next particle in the list
node => node%next
END DO
!Divide by the velocity cube volume
self%f = self%f * self%dvInv
END IF
END SUBROUTINE calculate
SUBROUTINE output(self, t)
@ -182,13 +186,16 @@ MODULE moduleProbe
USE moduleRefParam
IMPLICIT NONE
CLASS(probeDistFunc), INTENT(in):: self
CLASS(probeDistFunc), INTENT(inout):: self
INTEGER, INTENT(in):: t
CHARACTER (LEN=iterationDigits):: tstring
CHARACTER (LEN=3):: pstring
CHARACTER(:), ALLOCATABLE:: filename
INTEGER:: i, j, k
!Divide by the velocity cube volume
self%f = self%f * self%dvInv
WRITE(tstring, iterationFormat) t
WRITE(pstring, "(I3.3)") self%id
fileName='OUTPUT_' // tstring// '_f_' // pstring // '.dat'
@ -215,18 +222,21 @@ MODULE moduleProbe
CLOSE(10)
!Reset distribution function
self%f = 0.D0
END SUBROUTINE output
SUBROUTINE doProbes(t)
SUBROUTINE doProbes(part)
IMPLICIT NONE
INTEGER, INTENT(in):: t
TYPE(particle), INTENT(in):: part
INTEGER:: i
DO i = 1, SIZE(probe)
IF (MOD(t, probe(i)%every) == 0 .OR. t == tFinal) THEN
CALL probe(i)%calculate()
CALL probe(i)%output(t)
!Do it so they are only calculated when output
DO i = 1, nProbes
IF (probe(i)%update) THEN
CALL probe(i)%calculate(part)
END IF
@ -234,4 +244,34 @@ MODULE moduleProbe
END SUBROUTINE doProbes
SUBROUTINE outputProbes(t)
IMPLICIT NONE
INTEGER, INTENT(in):: t
INTEGER:: i
DO i = 1, nProbes
IF (probe(i)%update) THEN
CALL probe(i)%output(t)
END IF
END DO
END SUBROUTINE outputProbes
SUBROUTINE resetProbes(t)
IMPLICIT NONE
INTEGER, INTENT(in):: t
INTEGER:: i
DO i = 1, nProbes
probe(i)%f = 0.D0
probe(i)%update = MOD(t, probe(i)%every) == 0 .OR. t == tFinal
END DO
END SUBROUTINE resetProbes
END MODULE moduleProbe