Minor improvements in performance and code clarity.

Still no solution for the reset subroutine. It is really time
consumming.
This commit is contained in:
Jorge Gonzalez 2020-10-13 18:16:18 +02:00
commit ffb03e634b
12 changed files with 233 additions and 117 deletions

View file

@ -13,7 +13,7 @@ INCDIR :=
INCDIR += $(JSONINC) INCDIR += $(JSONINC)
# compile flags # compile flags
FCFLAGS := -fopenmp -Ofast -J $(MODDIR) -I $(INCDIR) -Wall FCFLAGS := -fopenmp -Ofast -J $(MODDIR) -I $(INCDIR) -Wall -fno-stack-arrays -g
#Output file #Output file
OUTPUT = DSMC_Neutrals OUTPUT = DSMC_Neutrals

View file

@ -1,5 +1,5 @@
set terminal qt enhanced 1 size 1600, 1000 font "Times ,10" set terminal qt enhanced 1 persist size 1600, 1000 font "Times ,10"
set style line 1 pt 4 lc rgb "#B50427" #Squares red set style line 1 pt 4 lc rgb "#B50427" #Squares red
set style line 2 pt 6 lc rgb "#3B4CC1" #Circles blue set style line 2 pt 6 lc rgb "#3B4CC1" #Circles blue
@ -8,47 +8,109 @@ set style line 4 pt 2 lc rgb "#FE7F0E" #Exes orange
set style line 5 pt 8 lc rgb "#D6696B" #Triangles light red set style line 5 pt 8 lc rgb "#D6696B" #Triangles light red
set style line 10 lt 1 lw 2.0 lc rgb "black" #Black solid line set style line 10 lt 1 lw 2.0 lc rgb "black" #Black solid line
folder1 = "2020-09-27_10.46.31/" folder1 = "base_case/"
folder2 = "2020-09-28_10.49.22/" name1 = "Base Case"
folder3 = "2020-09-30_20.40.04/" folder2 = "2020-10-11_17.58.30/"
folder4 = "2020-10-01_08.53.50/" name2 = "New Version"
folder3 = "2020-10-13_17.53.32/"
name3 = "Sections"
folder4 = "2020-10-11_15.20.09/"
name4 = "New list"
set key box opaque set key box opaque
set pointsize 1.5 set pointsize 1.5
set ylabel "Time per particle (ms)" set ylabel "Time per particle (ms)"
set xrange [0:8000] set xrange [0:500]
set xlabel "Iteration" set xlabel "Iteration"
set multiplot layout 2,3 set multiplot layout 2,3
set title "Total" set title "Total"
plot folder1."cpuTime.dat" u 1:(1e3*$3) t "Step 1" ls 1, \ plot folder1."cpuTime.dat" u 1:(1e3*$3) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e3*$3) t "Step 2" ls 2, \ folder2."cpuTime.dat" u 1:(1e3*$3) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e3*$3) t "Step 3" ls 3, \ folder3."cpuTime.dat" u 1:(1e3*$3) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e3*$3) t "Step 4" ls 4 folder4."cpuTime.dat" u 1:(1e3*$3) t name4 ls 4
set title "Push" set title "Push"
plot folder1."cpuTime.dat" u 1:(1e3*$4) t "Step 1" ls 1, \ plot folder1."cpuTime.dat" u 1:(1e3*$4) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e3*$4) t "Step 2" ls 2, \ folder2."cpuTime.dat" u 1:(1e3*$4) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e3*$4) t "Step 3" ls 3, \ folder3."cpuTime.dat" u 1:(1e3*$4) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e3*$4) t "Step 4" ls 4 folder4."cpuTime.dat" u 1:(1e3*$4) t name4 ls 4
set title "Reset" set title "Reset"
plot folder1."cpuTime.dat" u 1:(1e3*$5) t "Step 1" ls 1, \ plot folder1."cpuTime.dat" u 1:(1e3*$5) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e3*$5) t "Step 2" ls 2, \ folder2."cpuTime.dat" u 1:(1e3*$5) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e3*$5) t "Step 3" ls 3, \ folder3."cpuTime.dat" u 1:(1e3*$5) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e3*$5) t "Step 4" ls 4 folder4."cpuTime.dat" u 1:(1e3*$5) t name4 ls 4
set title "Collisions" set title "Collisions"
plot folder1."cpuTime.dat" u 1:(1e3*$6) t "Step 1" ls 1, \ plot folder1."cpuTime.dat" u 1:(1e3*$6) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e3*$6) t "Step 2" ls 2, \ folder2."cpuTime.dat" u 1:(1e3*$6) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e3*$6) t "Step 3" ls 3, \ folder3."cpuTime.dat" u 1:(1e3*$6) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e3*$6) t "Step 4" ls 4 folder4."cpuTime.dat" u 1:(1e3*$6) t name4 ls 4
set title "Weighting" set title "Weighting"
plot folder1."cpuTime.dat" u 1:(1e3*$7) t "Step 1" ls 1, \ plot folder1."cpuTime.dat" u 1:(1e3*$7) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e3*$7) t "Step 2" ls 2, \ folder2."cpuTime.dat" u 1:(1e3*$7) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e3*$7) t "Step 3" ls 3, \ folder3."cpuTime.dat" u 1:(1e3*$7) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e3*$7) t "Step 4" ls 4 folder4."cpuTime.dat" u 1:(1e3*$7) t name4 ls 4
set title "Num. particles"
plot folder1."cpuTime.dat" u 1:($2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:($2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:($2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:($2) t name4 ls 4
unset multiplot
set terminal qt enhanced 2 persist size 1600, 1000 font "Times ,10"
set style line 1 pt 4 lc rgb "#B50427" #Squares red
set style line 2 pt 6 lc rgb "#3B4CC1" #Circles blue
set style line 3 pt 1 lc rgb "#2CA02C" #Crosses green
set style line 4 pt 2 lc rgb "#FE7F0E" #Exes orange
set style line 5 pt 8 lc rgb "#D6696B" #Triangles light red
set style line 10 lt 1 lw 2.0 lc rgb "black" #Black solid line
set key box opaque
set pointsize 1.5
set ylabel "Time per particle (micros)"
set xrange [0:500]
set xlabel "Iteration"
set multiplot layout 2,3
set title "Total"
plot folder1."cpuTime.dat" u 1:(1e6*$3/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$3/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$3/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$3/$2) t name4 ls 4
set title "Push"
plot folder1."cpuTime.dat" u 1:(1e6*$4/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$4/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$4/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$4/$2) t name4 ls 4
set title "Reset"
plot folder1."cpuTime.dat" u 1:(1e6*$5/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$5/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$5/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$5/$2) t name4 ls 4
set title "Collisions"
plot folder1."cpuTime.dat" u 1:(1e6*$6/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$6/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$6/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$6/$2) t name4 ls 4
set title "Weighting"
plot folder1."cpuTime.dat" u 1:(1e6*$7/$2) t name1 ls 1, \
folder2."cpuTime.dat" u 1:(1e6*$7/$2) t name2 ls 2, \
folder3."cpuTime.dat" u 1:(1e6*$7/$2) t name3 ls 3, \
folder4."cpuTime.dat" u 1:(1e6*$7/$2) t name4 ls 4
unset multiplot

View file

@ -1,5 +1,5 @@
reset reset
set terminal qt enhanced 1 size 1800, 400 font "Times ,10" set terminal qt enhanced 1 persist size 1800, 400 font "Times ,10"
set style line 1 pt 4 lc rgb "#B50427" #Squares red set style line 1 pt 4 lc rgb "#B50427" #Squares red
set style line 2 pt 6 lc rgb "#3B4CC1" #Circles blue set style line 2 pt 6 lc rgb "#3B4CC1" #Circles blue

View file

@ -43,9 +43,9 @@ PROGRAM DSMC_Neutrals
!$OMP PARALLEL PRIVATE(t) DEFAULT(SHARED) !$OMP PARALLEL PRIVATE(t) DEFAULT(SHARED)
DO t = 1, tmax DO t = 1, tmax
tStep = omp_get_wtime()
!Insert new particles !Insert new particles
!$OMP SINGLE !$OMP SINGLE
tStep = omp_get_wtime()
tPush = omp_get_wtime() tPush = omp_get_wtime()
DO i=1, nInject DO i=1, nInject
CALL inject(i)%addParticles() CALL inject(i)%addParticles()
@ -55,6 +55,7 @@ PROGRAM DSMC_Neutrals
!$OMP DO !$OMP DO
DO n=1, n_part_old DO n=1, n_part_old
CALL push(part_old(n)) CALL push(part_old(n))
CALL mesh%vols(part_old(n)%e_p)%obj%findCell(part_old(n))
END DO END DO
!$OMP END DO !$OMP END DO
@ -62,10 +63,12 @@ PROGRAM DSMC_Neutrals
!$OMP SINGLE !$OMP SINGLE
tPush = omp_get_wtime() - tPush tPush = omp_get_wtime() - tPush
tReset = omp_get_wtime() tReset = omp_get_wtime()
!$OMP END SINGLE
!Reset particles !Reset particles
CALL resetParticles() CALL resetParticles(part_inj, part_old)
!$OMP SINGLE
tReset = omp_get_wtime() - tReset tReset = omp_get_wtime() - tReset
tColl = omp_get_wtime() tColl = omp_get_wtime()
!$OMP END SINGLE !$OMP END SINGLE
@ -73,7 +76,6 @@ PROGRAM DSMC_Neutrals
!Collisions !Collisions
!$OMP DO !$OMP DO
DO e=1, mesh%numVols DO e=1, mesh%numVols
mesh%vols(e)%obj%nColl = 0 !Reset number of collisions
CALL mesh%vols(e)%obj%collision() CALL mesh%vols(e)%obj%collision()
END DO END DO
!$OMP END DO !$OMP END DO
@ -85,7 +87,7 @@ PROGRAM DSMC_Neutrals
tWeight = omp_get_wtime() tWeight = omp_get_wtime()
!$OMP END SINGLE !$OMP END SINGLE
CALL scatterGrid() CALL scatterGrid(mesh, part_old)
!$OMP SINGLE !$OMP SINGLE
tWeight = omp_get_wtime() - tWeight tWeight = omp_get_wtime() - tWeight

View file

@ -16,7 +16,7 @@ moduleInput.o: moduleParallel.o moduleRefParam.o moduleCaseParam.o moduleSolver.
moduleInject.o: moduleSpecies.o moduleSolver.o moduleMesh.o moduleMeshCyl.o moduleInject.f95 moduleInject.o: moduleSpecies.o moduleSolver.o moduleMesh.o moduleMeshCyl.o moduleInject.f95
$(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@ $(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@
moduleList.o: moduleErrors.o moduleList.f95 moduleList.o: moduleSpecies.o moduleErrors.o moduleList.f95
$(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@ $(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@
moduleMesh.o: moduleOutput.o moduleList.o moduleSpecies.o moduleMesh.f95 moduleMesh.o: moduleOutput.o moduleList.o moduleSpecies.o moduleMesh.f95
@ -37,7 +37,7 @@ moduleOutput.o: moduleSpecies.o moduleRefParam.o moduleOutput.f95
moduleRefParam.o: moduleConstParam.o moduleRefParam.f95 moduleRefParam.o: moduleConstParam.o moduleRefParam.f95
$(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@ $(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@
moduleSpecies.o: moduleCaseParam.o moduleList.o moduleSpecies.f95 moduleSpecies.o: moduleCaseParam.o moduleSpecies.f95
$(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@ $(FC) $(FCFLAGS) -c $(subst .o,.f95, $@) -o $(OBJDIR)/$@
moduleSolver.o: moduleSpecies.o moduleRefParam.o moduleMesh.o moduleOutput.o moduleSolver.f95 moduleSolver.o: moduleSpecies.o moduleRefParam.o moduleMesh.o moduleOutput.o moduleSolver.f95

View file

@ -17,13 +17,13 @@ MODULE moduleCollisions
END SUBROUTINE END SUBROUTINE
SUBROUTINE collideBinary_interface(self, sigmaVRelMax, sigmaVrel, part_i, part_j) SUBROUTINE collideBinary_interface(self, sigmaVRelMax, sigmaVrelMaxNew, part_i, part_j)
USE moduleSpecies USE moduleSpecies
IMPORT:: collisionBinary IMPORT:: collisionBinary
CLASS(collisionBinary), INTENT(in):: self CLASS(collisionBinary), INTENT(in):: self
REAL(8), INTENT(in):: sigmaVrelMax REAL(8), INTENT(in):: sigmaVrelMax
REAL(8), INTENT(out):: sigmaVrel REAL(8), INTENT(inout):: sigmaVrelMaxNew
TYPE(particle), INTENT(inout):: part_i, part_j TYPE(particle), INTENT(inout):: part_i, part_j
END SUBROUTINE END SUBROUTINE
@ -115,7 +115,8 @@ MODULE moduleCollisions
END SUBROUTINE END SUBROUTINE
SUBROUTINE collideBinaryElastic(self, sigmaVrelMax, sigmaVrel, part_i, part_j) SUBROUTINE collideBinaryElastic(self, sigmaVrelMax, sigmaVrelMaxNew, &
part_i, part_j)
USE moduleConstParam USE moduleConstParam
USE moduleSpecies USE moduleSpecies
USE moduleTable USE moduleTable
@ -123,8 +124,9 @@ MODULE moduleCollisions
CLASS(collisionBinaryElastic), INTENT(in):: self CLASS(collisionBinaryElastic), INTENT(in):: self
REAL(8), INTENT(in):: sigmaVrelMax REAL(8), INTENT(in):: sigmaVrelMax
REAL(8), INTENT(out):: sigmaVrel REAL(8), INTENT(inout):: sigmaVrelMaxNew
TYPE(particle), INTENT(inout):: part_i, part_j TYPE(particle), INTENT(inout):: part_i, part_j
REAL(8):: sigmaVrel
REAL(8):: vRel !relative velocity REAL(8):: vRel !relative velocity
REAL(8):: vp_i, vp_j, v_i, v_j !post and pre-collision velocities REAL(8):: vp_i, vp_j, v_i, v_j !post and pre-collision velocities
REAL(8):: alpha REAL(8):: alpha
@ -132,7 +134,8 @@ MODULE moduleCollisions
!v relative (in units of [m][L]^2[s]^-2 !v relative (in units of [m][L]^2[s]^-2
vRel = species(1)%obj%m*NORM2(part_i%v - part_j%v)**2 vRel = species(1)%obj%m*NORM2(part_i%v - part_j%v)**2
sigmaVrel = self%crossSec%get(vRel)*vRel sigmaVrel = self%crossSec%get(vRel)*vRel
IF (sigmaVrel/sigmaVrelMax > RAND()) THEN sigmaVrelMaxNew = sigmaVrelMaxNew + sigmaVrel
IF (sigmaVrelMaxNew/sigmaVrelMax > RAND()) THEN
!Applies the collision !Applies the collision
v_i = NORM2(part_i%v) v_i = NORM2(part_i%v)
v_j = NORM2(part_j%v) v_j = NORM2(part_j%v)
@ -147,6 +150,7 @@ MODULE moduleCollisions
END IF END IF
END SUBROUTINE END SUBROUTINE
END MODULE moduleCollisions END MODULE moduleCollisions

View file

@ -178,6 +178,8 @@ MODULE moduleInject
!Push new particle !Push new particle
CALL push(part_inj(n)) CALL push(part_inj(n))
!Assign cell to new particle
CALL mesh%vols(part_inj(n)%e_p)%obj%findCell(part_inj(n))
END DO END DO

View file

@ -1,8 +1,10 @@
!Linked list of particles !Linked list of particles
MODULE moduleList MODULE moduleList
USE moduleSpecies
IMPLICIT NONE IMPLICIT NONE
TYPE lNode TYPE lNode
INTEGER:: n = 0 TYPE(particle), POINTER:: part => NULL()
TYPE(lNode), POINTER:: next => NULL() TYPE(lNode), POINTER:: next => NULL()
END TYPE lNode END TYPE lNode
@ -17,46 +19,48 @@ MODULE moduleList
END TYPE listNode END TYPE listNode
CONTAINS CONTAINS
!Finalize node
!Adds element to list !Adds element to list
SUBROUTINE addToList(this,n) SUBROUTINE addToList(this,part)
INTEGER,INTENT(in):: n USE moduleSpecies
CLASS(listNode):: this CLASS(listNode), INTENT(inout):: this
TYPE(particle),INTENT(in), TARGET:: part
TYPE(lNode),POINTER:: temp TYPE(lNode),POINTER:: temp
ALLOCATE(temp) ALLOCATE(temp)
temp%n = n temp%part => part
NULLIFY(temp%next) NULLIFY(temp%next)
this%amount = this%amount + 1
IF (.NOT. ASSOCIATED(this%head)) THEN IF (.NOT. ASSOCIATED(this%head)) THEN
!First element !First element
this%head => temp this%head => temp
this%tail => temp this%tail => temp
this%amount = 1
ELSE ELSE
!Append element !Append element
this%tail%next => temp this%tail%next => temp
this%tail => temp this%tail => temp
this%amount = this%amount + 1
END IF END IF
END SUBROUTINE addToList END SUBROUTINE addToList
FUNCTION getFromList(self, iObj) RESULT(n) FUNCTION getFromList(self, iObj) RESULT(partTemp)
use moduleErrors use moduleErrors
IMPLICIT NONE IMPLICIT NONE
CLASS(listNode):: self CLASS(listNode):: self
INTEGER:: iObj INTEGER:: iObj
INTEGER:: n TYPE(particle), POINTER:: partTemp
INTEGER:: i INTEGER:: i
TYPE(lNode), POINTER:: tempNode TYPE(lNode), POINTER:: nodeTemp
IF (iObj > self%amount) CALL criticalError('Accessing to element list outisde range','getFromList') IF (iObj > self%amount) CALL criticalError('Accessing to element list outisde range','getFromList')
tempNode => self%head nodeTemp => self%head
DO i = 1, iObj - 1 DO i = 1, iObj - 1
tempNode => tempNode%next nodeTemp => nodeTemp%next
END DO END DO
n = tempNode%n partTemp => nodeTemp%part
END FUNCTION getFromList END FUNCTION getFromList

View file

@ -97,6 +97,7 @@ MODULE moduleMesh
PROCEDURE(scatter_interface), DEFERRED, PASS:: scatter PROCEDURE(scatter_interface), DEFERRED, PASS:: scatter
PROCEDURE(collision_interface), DEFERRED, PASS:: collision PROCEDURE(collision_interface), DEFERRED, PASS:: collision
PROCEDURE(findCell_interface), DEFERRED, PASS:: findCell PROCEDURE(findCell_interface), DEFERRED, PASS:: findCell
PROCEDURE(resetOutput_interface), DEFERRED, PASS:: resetOutput
END TYPE meshVol END TYPE meshVol
@ -128,12 +129,18 @@ MODULE moduleMesh
USE moduleSpecies USE moduleSpecies
IMPORT:: meshVol IMPORT:: meshVol
CLASS(meshVol), INTENT(in):: self CLASS(meshVol), INTENT(inout):: self
CLASS(meshVol), OPTIONAL, INTENT(in):: oldCell CLASS(meshVol), OPTIONAL, INTENT(in):: oldCell
CLASS(particle), INTENT(inout):: part CLASS(particle), INTENT(inout):: part
END SUBROUTINE findCell_interface END SUBROUTINE findCell_interface
SUBROUTINE resetOutput_interface(self)
IMPORT:: meshVol
CLASS(meshVol), INTENT(inout):: self
END SUBROUTINE resetOutput_interface
END INTERFACE END INTERFACE
!Containers for volumes in the mesh !Containers for volumes in the mesh

View file

@ -73,6 +73,7 @@ MODULE moduleMeshCyl
PROCEDURE, PASS:: scatter => scatterQuad PROCEDURE, PASS:: scatter => scatterQuad
PROCEDURE, PASS:: phy2log => phy2logQuad PROCEDURE, PASS:: phy2log => phy2logQuad
PROCEDURE, PASS:: findCell => findCellCylQuad PROCEDURE, PASS:: findCell => findCellCylQuad
PROCEDURE, PASS:: resetOutput => resetOutputQuad
END TYPE meshVolCylQuad END TYPE meshVolCylQuad
@ -430,7 +431,7 @@ MODULE moduleMeshCyl
USE moduleSpecies USE moduleSpecies
IMPLICIT NONE IMPLICIT NONE
CLASS(meshVolCylQuad), INTENT(in):: self CLASS(meshVolCylQuad), INTENT(inout):: self
CLASS(meshVol), OPTIONAL, INTENT(in):: oldCell CLASS(meshVol), OPTIONAL, INTENT(in):: oldCell
CLASS(particle), INTENT(inout):: part CLASS(particle), INTENT(inout):: part
REAL(8):: xLog(1:2) REAL(8):: xLog(1:2)
@ -482,6 +483,36 @@ MODULE moduleMeshCyl
END SUBROUTINE findCellCylQuad END SUBROUTINE findCellCylQuad
PURE SUBROUTINE resetOutputQuad(self)
USE moduleSpecies
USE moduleOutput
IMPLICIT NONE
CLASS(meshVolCylQuad), INTENT(inout):: self
INTEGER:: k
DO k = 1, nSpecies
self%n1%output(k)%den = 0.D0
self%n1%output(k)%mom = 0.D0
self%n1%output(k)%tensorS = 0.D0
self%n2%output(k)%den = 0.D0
self%n2%output(k)%mom = 0.D0
self%n2%output(k)%tensorS = 0.D0
self%n3%output(k)%den = 0.D0
self%n3%output(k)%mom = 0.D0
self%n3%output(k)%tensorS = 0.D0
self%n4%output(k)%den = 0.D0
self%n4%output(k)%mom = 0.D0
self%n4%output(k)%tensorS = 0.D0
END DO
END SUBROUTINE resetOutputQuad
SUBROUTINE collision2DCyl(self) SUBROUTINE collision2DCyl(self)
USE moduleRefParam USE moduleRefParam
USE moduleConstParam USE moduleConstParam
@ -492,45 +523,41 @@ MODULE moduleMeshCyl
CLASS(meshVolCyl), INTENT(inout):: self CLASS(meshVolCyl), INTENT(inout):: self
INTEGER:: Npart !Number of particles inside the cell INTEGER:: Npart !Number of particles inside the cell
INTEGER:: Ncoll !Maximum number of collisions
REAL(8):: Fn !Specific weight REAL(8):: Fn !Specific weight
REAL(8):: Pmax !Maximum probability of collision REAL(8):: Pmax !Maximum probability of collision
INTEGER:: i,j !random particles index
INTEGER:: rnd !random index INTEGER:: rnd !random index
TYPE(particle), POINTER:: part_i, part_j TYPE(particle), POINTER:: part_i, part_j
INTEGER:: n !collision INTEGER:: n !collision
INTEGER:: ij, k INTEGER:: ij, k
REAL(8):: sigmaVrel
REAL(8):: sigmaVrelMaxNew REAL(8):: sigmaVrelMaxNew
Fn = species(1)%obj%weight!Check how to do this for multiple species Fn = species(1)%obj%weight!TODO: Check how to do this for multiple species
Npart = self%listPart_in%amount Npart = self%listPart_in%amount
Pmax = Fn*self%sigmaVrelMax*tau/self%volume Pmax = Fn*self%sigmaVrelMax*tau/self%volume
Ncoll = INT(REAL(Npart*(Npart-1))*Pmax*0.5D0) self%nColl = INT(REAL(Npart*(Npart-1))*Pmax*0.5D0)
self%nColl = Ncoll
DO n = 1, NColl DO n = 1, self%NColl
!Select random numbers !Select random numbers
rnd = 1 + FLOOR(Npart*RAND()) rnd = 1 + FLOOR(Npart*RAND())
i = self%listPart_in%get(rnd) part_i => self%listPart_in%get(rnd)
part_i => part_old(i)
rnd = 1 + FLOOR(Npart*RAND()) rnd = 1 + FLOOR(Npart*RAND())
j = self%listPart_in%get(rnd) part_j => self%listPart_in%get(rnd)
part_j => part_old(j)
ij = interactionIndex(part_i%pt, part_j%pt) ij = interactionIndex(part_i%pt, part_j%pt)
sigmaVrelMaxNew = 0.D0 sigmaVrelMaxNew = 0.D0
DO k = 1, interactionMatrix(ij)%amount DO k = 1, interactionMatrix(ij)%amount
CALL interactionMatrix(ij)%collisions(k)%obj%collide(self%sigmaVrelMax, sigmaVrel, part_i, part_j) CALL interactionMatrix(ij)%collisions(k)%obj%collide(self%sigmaVrelMax, sigmaVrelMaxNew, part_i, part_j)
sigmaVrelMaxNew = sigmaVrel + SigmaVrelMaxNew
END DO END DO
!Update maximum cross section times vrelative per each collision !Update maximum cross section times vrelative per each collision
IF (sigmaVrelMaxNew > self%sigmaVrelMax) self%sigmaVrelMax = sigmaVrelMaxNew IF (sigmaVrelMaxNew > self%sigmaVrelMax) self%sigmaVrelMax = sigmaVrelMaxNew
END DO END DO
!Reset output in nodes
CALL self%resetOutput()
!Erase the list of particles inside the cell
CALL self%listPart_in%erase() CALL self%listPart_in%erase()
END SUBROUTINE collision2DCyl END SUBROUTINE collision2DCyl

View file

@ -2,38 +2,25 @@ MODULE moduleSolver
CONTAINS CONTAINS
SUBROUTINE scatterGrid() SUBROUTINE scatterGrid(meshIn, partArray)
USE moduleSpecies USE moduleSpecies
USE moduleRefParam
USE moduleMesh USE moduleMesh
USE moduleOutput
INTEGER:: n, e, k
!Cleans previous output CLASS(meshGeneric), INTENT(in):: meshIn
!$OMP DO PRIVATE(k) TYPE(particle), INTENT(in):: partArray(:)
DO e = 1, mesh%numNodes INTEGER:: n
DO k= 1, nSpecies
mesh%nodes(e)%obj%output(k)%den = 0.D0
mesh%nodes(e)%obj%output(k)%mom = 0.D0
mesh%nodes(e)%obj%output(k)%tensorS = 0.D0
END DO
END DO
!$OMP END DO
!Loops over the particles to scatter them !Loops over the particles to scatter them
!$OMP DO !$OMP DO
DO n=1, n_part_old DO n=1, n_part_old
CALL mesh%vols(part_old(n)%e_p)%obj%scatter(part_old(n)) CALL meshIn%vols(partArray(n)%e_p)%obj%scatter(partArray(n))
END DO END DO
!$OMP END DO !$OMP END DO
END SUBROUTINE scatterGrid END SUBROUTINE scatterGrid
SUBROUTINE push(part) PURE SUBROUTINE push(part)
USE moduleSpecies USE moduleSpecies
USE moduleMesh USE moduleMesh
IMPLICIT NONE IMPLICIT NONE
@ -68,44 +55,66 @@ MODULE moduleSolver
part_temp%e_p = part%e_p part_temp%e_p = part%e_p
!Assign cell to particle !Assign cell to particle
part=part_temp part=part_temp
CALL mesh%vols(part%e_p)%obj%findCell(part)
END SUBROUTINE push END SUBROUTINE push
SUBROUTINE resetParticles() SUBROUTINE resetParticles(partInj, partOld)
USE moduleSpecies USE moduleSpecies
USE moduleList USE moduleList
USE moduleMesh USE moduleMesh
IMPLICIT NONE IMPLICIT NONE
TYPE(particle), INTENT(in), ALLOCATABLE:: partInj(:)
TYPE(particle), INTENT(inout), ALLOCATABLE:: partOld(:)
INTEGER:: nn, n INTEGER:: nn, n
INTEGER, SAVE:: n_inj_in, n_old_in
TYPE(particle), ALLOCATABLE:: partTemp(:) TYPE(particle), ALLOCATABLE:: partTemp(:)
IF (n_part_old > 0) THEN !$OMP SECTIONS
n_part_new = COUNT(part_old%n_in) + COUNT(part_inj%n_in) !$OMP SECTION
ELSE n_inj_in = 0
n_part_new = COUNT(part_inj%n_in) IF (ALLOCATED(partInj)) THEN
END IF n_inj_in = COUNT(partInj%n_in)
END IF
!$OMP SECTION
n_old_in = 0
IF (ALLOCATED(partOld)) THEN
n_old_in = COUNT(partOld%n_in)
END IF
!$OMP END SECTIONS
!$OMP BARRIER
!$OMP SINGLE
CALL MOVE_ALLOC(part_old, partTemp) CALL MOVE_ALLOC(part_old, partTemp)
ALLOCATE(part_old(1:n_part_new)) n_part_new = n_inj_in + n_old_in
ALLOCATE(partOld(1:n_part_new))
nn = 0 nn = 0
DO n = 1, nPartInj DO n = 1, nPartInj
IF (part_inj(n)%n_in) THEN IF (part_inj(n)%n_in) THEN
nn = nn + 1 nn = nn + 1
part_old(nn) = part_inj(n) part_old(nn) = part_inj(n)
CALL mesh%vols(part_old(nn)%e_p)%obj%listPart_in%add(nn) CALL mesh%vols(part_old(nn)%e_p)%obj%listPart_in%add(part_old(nn))
END IF END IF
END DO END DO
DO n = 1, n_part_old DO n = 1, n_part_old
IF (partTemp(n)%n_in) THEN IF (partTemp(n)%n_in) THEN
nn = nn + 1 nn = nn + 1
part_old(nn) = partTemp(n) partOld(nn) = partTemp(n)
CALL mesh%vols(part_old(nn)%e_p)%obj%listPart_in%add(nn) CALL mesh%vols(partOld(nn)%e_p)%obj%listPart_in%add(partOld(nn))
END IF END IF
END DO END DO
n_part_old = n_part_new n_part_old = n_part_new
!$OMP END SINGLE
END SUBROUTINE resetParticles END SUBROUTINE resetParticles

View file

@ -1,7 +1,6 @@
!Contains the information about species (particles) !Contains the information about species (particles)
MODULE moduleSpecies MODULE moduleSpecies
USE moduleCaseParam USE moduleCaseParam
USE moduleList
IMPLICIT NONE IMPLICIT NONE
TYPE, ABSTRACT:: speciesGeneric TYPE, ABSTRACT:: speciesGeneric