Final adjustments, format of verbose corrected and minor modifications

to the input case cylFlow.
This commit is contained in:
Jorge Gonzalez 2020-10-18 00:21:13 +02:00
commit bf6caad56a
11 changed files with 189 additions and 117 deletions

View file

@ -37,6 +37,7 @@ MODULE moduleErrors
errorMsg = msg
WRITE (*, '(A)') errorMsg
WRITE (*, *)
END SUBROUTINE verboseError

View file

@ -23,6 +23,18 @@ MODULE moduleInject
TYPE(injectGeneric), ALLOCATABLE:: inject(:)
CONTAINS
!Injection of particles
SUBROUTINE doInjects()
IMPLICIT NONE
INTEGER:: i
DO i=1, nInject
CALL inject(i)%addParticles()
END DO
END SUBROUTINE doInjects
SUBROUTINE initInject(self, i, v, n, T, flow, pt, physicalSurface)
USE moduleMesh
USE moduleMeshCyl
@ -109,7 +121,7 @@ MODULE moduleInject
INTEGER:: n1 = 0, n2 = 0
!Edge nodes coordinates
REAL(8):: p1(1:3) = 0.D0, p2(1:3) = 0.D0
INTEGER:: nMin, nMax !Min and Max index in part_inj array
INTEGER:: nMin, nMax !Min and Max index in partInj array
INTEGER:: n
vVec = self%v * self%n
@ -120,10 +132,10 @@ MODULE moduleInject
nMin = 1
nMax = self%nParticles
!Assign particle type
part_inj(nMin:nMax)%pt = self%pt
partInj(nMin:nMax)%pt = self%pt
!Assign weight to particle.
part_inj(nMin:nMax)%weight = species(self%pt)%obj%weight
part_inj(nMin:nMax)%n_in = .TRUE.
partInj(nMin:nMax)%weight = species(self%pt)%obj%weight
partInj(nMin:nMax)%n_in = .TRUE.
DO n = nMin, nMax
!Select edge randomly from which inject particle
randomX = RAND()*self%sumWeight
@ -157,29 +169,29 @@ MODULE moduleInject
!Volume associated to the edge:
IF (DOT_PRODUCT(self%n, mesh%edges(randomEdge)%obj%normal) >= 0.D0) THEN
part_inj(n)%e_p = mesh%edges(randomEdge)%obj%e1%n
partInj(n)%e_p = mesh%edges(randomEdge)%obj%e1%n
ELSE
part_inj(n)%e_p = mesh%edges(randomEdge)%obj%e2%n
partInj(n)%e_p = mesh%edges(randomEdge)%obj%e2%n
END IF
part_inj(n)%v = (/ vBC(vVec(1), vTh(1)), &
partInj(n)%v = (/ vBC(vVec(1), vTh(1)), &
vBC(vVec(2), vTh(2)), &
vBC(vVec(3), vTh(3)) /)
!Random position in edge
!TODO: Use edge coordinates and transformations for this process
randomPos = RAND()
part_inj(n)%r(1) = p1(1) + randomPos*(p2(1) - p1(1))
part_inj(n)%r(2) = p1(2) + randomPos*(p2(2) - p1(2))
part_inj(n)%r(3) = p1(3) + randomPos*(p2(3) - p1(3))
partInj(n)%r(1) = p1(1) + randomPos*(p2(1) - p1(1))
partInj(n)%r(2) = p1(2) + randomPos*(p2(2) - p1(2))
partInj(n)%r(3) = p1(3) + randomPos*(p2(3) - p1(3))
!Push new particle
CALL push(part_inj(n))
CALL push(partInj(n))
!Assign cell to new particle
CALL mesh%vols(part_inj(n)%e_p)%obj%findCell(part_inj(n))
CALL mesh%vols(partInj(n)%e_p)%obj%findCell(partInj(n))
END DO

View file

@ -19,6 +19,7 @@ MODULE moduleInput
CALL config%initialize()
!Loads the config file
CALL verboseError('Loading input file...')
CALL config%load(filename = inputFile)
!Reads reference parameters
@ -40,12 +41,15 @@ MODULE moduleInput
CALL readBoundary(config)
!Read Geometry
CALL verboseError('Reading Geometry...')
CALL readGeometry(config)
!Read injection of particles
CALL verboseError('Reading Interactions between species...')
CALL readInject(config)
!Read parallel parameters
CALL verboseError('Reading Parallel configuration...')
CALL readParallel(config)
END SUBROUTINE readConfig
@ -196,7 +200,7 @@ MODULE moduleInput
!Set number of particles to 0 for init state
!TODO: In a future, this should include the particles from init states
n_part_old = 0
nPartOld = 0
END SUBROUTINE readSpecies
@ -363,7 +367,7 @@ MODULE moduleInput
!Allocate array for injected particles
IF (nPartInj > 0) THEN
ALLOCATE(part_inj(1:nPartInj))
ALLOCATE(partInj(1:nPartInj))
END IF
@ -390,6 +394,8 @@ MODULE moduleInput
END IF
CALL initParallel()
END SUBROUTINE readParallel

View file

@ -317,7 +317,7 @@ MODULE moduleMeshCylRead
DO i = 1, nSpecies
WRITE(tstring, '(I6.6)') t
fileName='OUTPUT_' // tstring// '_' // species(i)%obj%name // '.msh'
PRINT *, "Creado archivo de datos:", fileName
WRITE(*, "(6X,A15,A)") "Creating file: ", fileName
OPEN (60, file = path // folder // '/' // fileName)
WRITE(60, "(A)") '$MeshFormat'
WRITE(60, "(A)") '2.2 0 8'
@ -400,7 +400,7 @@ MODULE moduleMeshCylRead
WRITE(tstring, '(I6.6)') t
fileName='OUTPUT_' // tstring// '_Collisions.msh'
PRINT *, "Creado archivo de datos:", fileName
WRITE(*, "(6X,A15,A)") "Creating file: ", fileName
OPEN (60, file = path // folder // '/' // fileName)
WRITE(60, "(A)") '$MeshFormat'
WRITE(60, "(A)") '2.2 0 8'

View file

@ -20,7 +20,6 @@ MODULE moduleOutput
LOGICAL:: collOutput = .FALSE.
CONTAINS
FUNCTION outerProduct(a,b) RESULT(s)
IMPLICIT NONE
@ -89,33 +88,34 @@ MODULE moduleOutput
INTEGER, INTENT(in):: t
LOGICAL, INTENT(in), OPTIONAL:: first
CHARACTER(:), ALLOCATABLE:: filename
CHARACTER(:), ALLOCATABLE:: fileName
filename = 'cpuTime.dat'
fileName = 'cpuTime.dat'
IF (timeOutput) THEN
IF (PRESENT(first)) THEN
IF (first) THEN
OPEN(20, file = path // folder // '/' // filename, action = 'write')
OPEN(20, file = path // folder // '/' // fileName, action = 'write')
WRITE(20, "(A1, 8X, A1, 9X, A1, 5(A20))") "#","t","n","total","push","reset","collision","weighting"
WRITE(*, "(6X,A15,A)") "Creating file: ", fileName
ELSE
END IF
OPEN(20, file = path // folder // '/' // filename, position = 'append', action = 'write')
OPEN(20, file = path // folder // '/' // fileName, position = 'append', action = 'write')
ELSE
OPEN(20, file = path // folder // '/' // filename, position = 'append', action = 'write')
OPEN(20, file = path // folder // '/' // fileName, position = 'append', action = 'write')
END IF
WRITE (20, "(I10, I10, 5(ES20.6E3))") t, n_part_old, tStep, tPush, tReset, tColl, tWeight
WRITE (20, "(I10, I10, 5(ES20.6E3))") t, nPartOld, tStep, tPush, tReset, tColl, tWeight
CLOSE(20)
END IF
END SUBROUTINE
END SUBROUTINE printTime
END MODULE moduleOutput

View file

@ -1,4 +1,5 @@
MODULE moduleParallel
IMPLICIT NONE
TYPE openMP_type
INTEGER:: nThreads
@ -7,4 +8,13 @@ MODULE moduleParallel
TYPE(openMP_type):: openMP
CONTAINS
SUBROUTINE initParallel()
IMPLICIT NONE
!Starts threads for OpenMP parallelization
CALL OMP_SET_NUM_THREADS(openMP%nThreads)
END SUBROUTINE initParallel
END MODULE moduleParallel

View file

@ -1,24 +1,25 @@
MODULE moduleSolver
CONTAINS
SUBROUTINE scatterGrid(meshIn, partArray)
SUBROUTINE doPushes()
USE moduleSpecies
USE moduleMesh
IMPLICIT NONE
CLASS(meshGeneric), INTENT(in):: meshIn
TYPE(particle), INTENT(in):: partArray(:)
INTEGER:: n
!Loops over the particles to scatter them
!$OMP DO
DO n=1, n_part_old
CALL meshIn%vols(partArray(n)%e_p)%obj%scatter(partArray(n))
DO n=1, nPartOld
CALL push(partOld(n))
CALL mesh%vols(partOld(n)%e_p)%obj%findCell(partOld(n))
END DO
!$OMP END DO
END SUBROUTINE scatterGrid
END SUBROUTINE doPushes
!Push one particle. Boris pusher for 2D Cyl
!TODO: make general for any pusher
PURE SUBROUTINE push(part)
USE moduleSpecies
USE moduleMesh
@ -57,28 +58,58 @@ MODULE moduleSolver
END SUBROUTINE push
SUBROUTINE resetParticles(partInj, partOld)
USE moduleSpecies, ONLY: particle, &
n_part_old, n_part_new, nPartInj
!Do the collisions in all the cells
SUBROUTINE doCollisions()
USE moduleMesh
IMPLICIT NONE
INTEGER:: e
!$OMP DO
DO e=1, mesh%numVols
CALL mesh%vols(e)%obj%collision()
END DO
!$OMP END DO
END SUBROUTINE doCollisions
!Scatter particles in the grid
SUBROUTINE doScatter
USE moduleSpecies
USE moduleMesh
INTEGER:: n
!Loops over the particles to scatter them
!$OMP DO
DO n=1, nPartOld
CALL mesh%vols(partOld(n)%e_p)%obj%scatter(partOld(n))
END DO
!$OMP END DO
END SUBROUTINE doScatter
SUBROUTINE doReset()
USE moduleSpecies
IMPLICIT NONE
TYPE(particle), INTENT(in), ALLOCATABLE:: partInj(:)
TYPE(particle), INTENT(inout), ALLOCATABLE:: partOld(:)
INTEGER:: nn, n
INTEGER, SAVE:: n_inj_in, n_old_in
INTEGER:: nPartNew
INTEGER, SAVE:: nInjIn, nOldIn
TYPE(particle), ALLOCATABLE:: partTemp(:)
!$OMP SECTIONS
!$OMP SECTION
n_inj_in = 0
nInjIn = 0
IF (ALLOCATED(partInj)) THEN
n_inj_in = COUNT(partInj%n_in)
nInjIn = COUNT(partInj%n_in)
END IF
!$OMP SECTION
n_old_in = 0
nOldIn = 0
IF (ALLOCATED(partOld)) THEN
n_old_in = COUNT(partOld%n_in)
nOldIn = COUNT(partOld%n_in)
END IF
!$OMP END SECTIONS
@ -87,8 +118,8 @@ MODULE moduleSolver
!$OMP SINGLE
CALL MOVE_ALLOC(partOld, partTemp)
n_part_new = n_inj_in + n_old_in
ALLOCATE(partOld(1:n_part_new))
nPartNew = nInjIn + nOldIn
ALLOCATE(partOld(1:nPartNew))
nn = 0
DO n = 1, nPartInj
@ -100,7 +131,7 @@ MODULE moduleSolver
END DO
DO n = 1, n_part_old
DO n = 1, nPartOld
IF (partTemp(n)%n_in) THEN
nn = nn + 1
partOld(nn) = partTemp(n)
@ -109,10 +140,50 @@ MODULE moduleSolver
END DO
n_part_old = n_part_new
nPartOld = nPartNew
!$OMP END SINGLE
END SUBROUTINE resetParticles
END SUBROUTINE doReset
SUBROUTINE doOutput(t)
USE moduleMesh
USE moduleOutput
USE moduleSpecies
USE moduleCompTime
IMPLICIT NONE
INTEGER, INTENT(in):: t
counterOutput=counterOutput+1
IF (counterOutput>=triggerOutput .OR. &
t == tmax .OR. t == 0) THEN
!Resets output counter
counterOutput=0
CALL mesh%printOutput(t)
CALL printTime(t, t == 0)
CALL mesh%printColl(t)
WRITE(*, "(5X,A21,I10,A1,I8)") "t/tmax: ", t, "/", tmax
WRITE(*, "(5X,A21,I10)") "Particles: ", nPartOld
IF (t == 0) THEN
WRITE(*, "(5X,A21,F8.1,A2)") " init time: ", 1.D3*tStep, "ms"
ELSE
WRITE(*, "(5X,A21,F8.1,A2)") "iteration time: ", 1.D3*tStep, "ms"
END IF
IF (nPartOld > 0) THEN
WRITE(*, "(5X,A21,F8.1,A2)") "avg t/particle: ", 1.D9*(tPush+tReset+tColl+tWeight)/DBLE(nPartOld), "ns"
END IF
WRITE(*,*)
END IF
END SUBROUTINE doOutput
END MODULE moduleSolver

View file

@ -37,12 +37,12 @@ MODULE moduleSpecies
END TYPE particle
INTEGER:: n_part_old, n_part_new
!Number of old particles
INTEGER:: nPartOld
INTEGER:: nPartInj
!Arrays that define the particles
TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: part_old
TYPE(particle), ALLOCATABLE, DIMENSION(:):: part_new
TYPE(particle), ALLOCATABLE, DIMENSION(:):: part_inj !array of inject particles
!Arrays that contain the particles
TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: partOld
TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: partInj !array of inject particles
CONTAINS
FUNCTION speciesName2Index(speciesName) RESULT(pt)