From e44eed8af8d1e04edb2221a9babbd174581e06cb Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 18 Oct 2020 17:00:15 +0200 Subject: [PATCH] Base commit befor trying to use dynamic scheduling to boost parallel performance. --- runs/cylFlow/input.json | 8 ++-- runs/cylFlow/plotCPUTime.gp | 2 +- src/modules/moduleBoundary.f95 | 2 +- src/modules/moduleCollisions.f95 | 36 ++++++++++++------ src/modules/moduleInput.f95 | 2 +- src/modules/moduleList.f95 | 64 +++++++++++++++++--------------- src/modules/moduleMeshCyl.f95 | 11 +++++- src/modules/moduleSpecies.f95 | 2 +- 8 files changed, 77 insertions(+), 50 deletions(-) diff --git a/runs/cylFlow/input.json b/runs/cylFlow/input.json index 1b56a73..04814f7 100644 --- a/runs/cylFlow/input.json +++ b/runs/cylFlow/input.json @@ -11,7 +11,7 @@ "meshFile": "mesh.msh" }, "species": [ - {"name": "Argon", "type": "neutral", "mass": 6.633e-26, "weight": 5.0e6} + {"name": "Argon", "type": "neutral", "mass": 6.633e-26, "weight": 5.0e7} ], "boundary": [ {"name": "Injection", "type": "absorption", "physicalSurface": 1}, @@ -21,17 +21,17 @@ {"name": "Axis", "type": "axis", "physicalSurface": 5} ], "inject": [ - {"name": "Nozzle", "species": "Argon", "flow": 1.0, "units": "sccm", "v": 300.0, "T": [300.0, 300.0, 300.0], "n": [1, 0, 0], "physicalSurface": 1} + {"name": "Nozzle", "species": "Argon", "flow": 10.0, "units": "sccm", "v": 300.0, "T": [300.0, 300.0, 300.0], "n": [1, 0, 0], "physicalSurface": 1} ], "reference": { - "density": 1.0e19, + "density": 1.0e20, "mass": 6.633e-26, "temperature": 300.0, "radius": 1.88e-10 }, "case": { "tau": 6.e-7, - "time": 3.e-4 + "time": 3.e-3 }, "interactions": { "folderCollisions": "./data/collisions/", diff --git a/runs/cylFlow/plotCPUTime.gp b/runs/cylFlow/plotCPUTime.gp index 58d8ba4..2944b5a 100644 --- a/runs/cylFlow/plotCPUTime.gp +++ b/runs/cylFlow/plotCPUTime.gp @@ -1,5 +1,5 @@ reset -set terminal qt enhanced 1 persist size 1800, 400 font "Times ,10" +set terminal qt enhanced 1 persist size 1600, 600 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 diff --git a/src/modules/moduleBoundary.f95 b/src/modules/moduleBoundary.f95 index a2e579c..71caa16 100644 --- a/src/modules/moduleBoundary.f95 +++ b/src/modules/moduleBoundary.f95 @@ -4,7 +4,7 @@ MODULE moduleBoundary INTEGER:: id = 0 CHARACTER(:), ALLOCATABLE:: name INTEGER:: physicalSurface = 0 - CHARACTER(:), ALLOCATABLE:: boundaryType !TODO: substitute for extended types + CHARACTER(:), ALLOCATABLE:: boundaryType END TYPE boundaryGeneric diff --git a/src/modules/moduleCollisions.f95 b/src/modules/moduleCollisions.f95 index 5af2644..59fcbbe 100644 --- a/src/modules/moduleCollisions.f95 +++ b/src/modules/moduleCollisions.f95 @@ -2,7 +2,8 @@ MODULE moduleCollisions USE moduleTable TYPE, ABSTRACT:: collisionBinary - TYPE(table1D):: crossSec + REAL(8):: rMass !reduced mass + TYPE(table1D):: crossSec !cross section of collision CONTAINS PROCEDURE(initBinary_interface), PASS, DEFERRED:: init PROCEDURE(collideBinary_interface), PASS, DEFERRED:: collide @@ -10,10 +11,11 @@ MODULE moduleCollisions END TYPE collisionBinary ABSTRACT INTERFACE - SUBROUTINE initBinary_interface(self, crossSectionFilename) + SUBROUTINE initBinary_interface(self, crossSectionFilename, mass_i, mass_j) IMPORT:: collisionBinary CLASS(collisionBinary), INTENT(inout):: self CHARACTER(:), ALLOCATABLE, INTENT(in):: crossSectionFilename + REAL(8), INTENT(in):: mass_i, mass_j END SUBROUTINE @@ -30,19 +32,23 @@ MODULE moduleCollisions END INTERFACE - !Container for collisions + !Container for binary collisions TYPE:: collisionCont CLASS(collisionBinary), ALLOCATABLE:: obj END TYPE collisionCont TYPE, EXTENDS(collisionBinary):: collisionBinaryElastic + !Weight distribution for Maxwellian function + REAL(8):: w_i = (1.D0+DSQRT(3.D0))/2.D0 + REAL(8):: w_j = (DSQRT(3.D0)-1.D0)/2.D0 CONTAINS PROCEDURE, PASS:: init => initBinaryElastic PROCEDURE, PASS:: collide => collideBinaryElastic END TYPE collisionBinaryElastic + !Type for interaction matrix TYPE:: interactionsBinary INTEGER:: amount TYPE(collisionCont), ALLOCATABLE:: collisions(:) @@ -92,13 +98,14 @@ MODULE moduleCollisions ALLOCATE(self%collisions(1:self%amount)) DO k= 1, self%amount + !TODO: make type dependent ALLOCATE(collisionBinaryElastic:: self%collisions(k)%obj) END DO END SUBROUTINE initInteractionBinary - SUBROUTINE initBinaryElastic(self, crossSectionFilename) + SUBROUTINE initBinaryElastic(self, crossSectionFilename, mass_i, mass_j) USE moduleTable USE moduleRefParam USE moduleConstParam @@ -106,6 +113,7 @@ MODULE moduleCollisions CLASS(collisionBinaryElastic), INTENT(inout):: self CHARACTER(:), ALLOCATABLE, INTENT(in):: crossSectionFilename + REAL(8), INTENT(in):: mass_i, mass_j !Reads data from file CALL self%crossSec%init(crossSectionFilename) @@ -113,6 +121,9 @@ MODULE moduleCollisions !Convert to no-dimensional units CALL self%crossSec%convert(eV2J/(m_ref*v_ref**2), 1.D0/L_ref**2) + !Calculates reduced mass + self%rMass = (mass_i*mass_j)/(mass_i+mass_j) + END SUBROUTINE SUBROUTINE collideBinaryElastic(self, sigmaVrelMax, sigmaVrelMaxNew, & @@ -128,20 +139,23 @@ MODULE moduleCollisions TYPE(particle), INTENT(inout):: part_i, part_j REAL(8):: sigmaVrel REAL(8):: vRel !relative velocity + REAL(8):: eRel !relative energy REAL(8):: vp_i, vp_j, v_i, v_j !post and pre-collision velocities - REAL(8):: alpha + REAL(8):: v_ij !sum of velocities modules + REAL(8):: alpha !random angle of scattering - !v relative (in units of [m][L]^2[s]^-2 - vRel = species(1)%obj%m*NORM2(part_i%v - part_j%v)**2 - sigmaVrel = self%crossSec%get(vRel)*vRel + !eRel (in units of [m][L]^2[s]^-2 + vRel = SUM(DABS(part_i%v-part_j%v)) !TODO make function of norm1 + eRel = self%rMass*vRel**2 + sigmaVrel = self%crossSec%get(eRel)*vRel sigmaVrelMaxNew = sigmaVrelMaxNew + sigmaVrel - PRINT *, sigmaVrelMaxNew/sigmaVrelMax, RAND() IF (sigmaVrelMaxNew/sigmaVrelMax > RAND()) THEN !Applies the collision v_i = NORM2(part_i%v) v_j = NORM2(part_j%v) - vp_j = (v_i + v_j)*(1.D0+DSQRT(3.D0))/2.D0 - vp_i = (v_i + v_j)*(DSQRT(3.D0)-1.D0)/2.D0 + v_ij = v_i+v_j + vp_j = v_ij*self%w_i + vp_i = v_ij*self%w_j alpha = PI*RAND() part_i%v(1) = v_i*DCOS(alpha) part_i%v(2) = v_i*DSIN(alpha) diff --git a/src/modules/moduleInput.f95 b/src/modules/moduleInput.f95 index dc9cf61..926147b 100644 --- a/src/modules/moduleInput.f95 +++ b/src/modules/moduleInput.f95 @@ -241,7 +241,7 @@ MODULE moduleInput WRITE (kString, '(I2)') k CALL config%get(object // '.crossSections(' // TRIM(kString)// ')', crossSecFile) crossSecFilePath = pathCollisions // crossSecFile - CALL interactionMatrix(ij)%collisions(k)%obj%init(crossSecFilePath) + CALL interactionMatrix(ij)%collisions(k)%obj%init(crossSecFilePath, species(pt_i)%obj%m, species(pt_j)%obj%m) END DO diff --git a/src/modules/moduleList.f95 b/src/modules/moduleList.f95 index 2da0cc4..b11ed36 100644 --- a/src/modules/moduleList.f95 +++ b/src/modules/moduleList.f95 @@ -6,6 +6,7 @@ MODULE moduleList TYPE lNode TYPE(particle), POINTER:: part => NULL() TYPE(lNode), POINTER:: next => NULL() + END TYPE lNode TYPE listNode @@ -14,69 +15,74 @@ MODULE moduleList TYPE(lNode),POINTER:: tail => NULL() CONTAINS PROCEDURE,PASS:: add => addToList - PROCEDURE,PASS:: get => getFromList + PROCEDURE,PASS:: convert2Array PROCEDURE,PASS:: erase => eraseList + END TYPE listNode + TYPE pointerArray + TYPE(particle), POINTER:: part + + END TYPE + CONTAINS !Adds element to list - SUBROUTINE addToList(this,part) + SUBROUTINE addToList(self,part) USE moduleSpecies - CLASS(listNode), INTENT(inout):: this + CLASS(listNode), INTENT(inout):: self TYPE(particle),INTENT(in), TARGET:: part TYPE(lNode),POINTER:: temp ALLOCATE(temp) temp%part => part NULLIFY(temp%next) - this%amount = this%amount + 1 - IF (.NOT. ASSOCIATED(this%head)) THEN + self%amount = self%amount + 1 + IF (.NOT. ASSOCIATED(self%head)) THEN !First element - this%head => temp - this%tail => temp + self%head => temp + self%tail => temp ELSE !Append element - this%tail%next => temp - this%tail => temp + self%tail%next => temp + self%tail => temp END IF END SUBROUTINE addToList - FUNCTION getFromList(self, iObj) RESULT(partTemp) - use moduleErrors + FUNCTION convert2Array(self) RESULT(partArray) IMPLICIT NONE - - CLASS(listNode):: self - INTEGER:: iObj - TYPE(particle), POINTER:: partTemp - INTEGER:: i - TYPE(lNode), POINTER:: nodeTemp + CLASS(listNode), INTENT(in):: self + TYPE(pointerArray), ALLOCATABLE:: partArray(:) + TYPE(lNode), POINTER:: tempNode + INTEGER:: n - IF (iObj > self%amount) CALL criticalError('Accessing to element list outisde range','getFromList') - nodeTemp => self%head - DO i = 1, iObj - 1 - nodeTemp => nodeTemp%next + ALLOCATE(partArray(1:self%amount)) + tempNode => self%head + DO n=1, self%amount + !Point element in array to element in list + partArray(n)%part => tempNode%part + !Go to next element + tempNode => tempNode%next END DO - partTemp => nodeTemp%part - END FUNCTION getFromList + END FUNCTION convert2Array !Erase list - SUBROUTINE eraseList(this) - CLASS(listNode):: this + SUBROUTINE eraseList(self) + CLASS(listNode):: self TYPE(lNode),POINTER:: current, next - current => this%head + current => self%head DO WHILE (ASSOCIATED(current)) next => current%next DEALLOCATE(current) current => next END DO - IF (ASSOCIATED(this%head)) NULLIFY(this%head) - IF (ASSOCIATED(this%tail)) NULLIFY(this%tail) - this%amount = 0 + IF (ASSOCIATED(self%head)) NULLIFY(self%head) + IF (ASSOCIATED(self%tail)) NULLIFY(self%tail) + self%amount = 0 END SUBROUTINE eraseList END MODULE moduleList diff --git a/src/modules/moduleMeshCyl.f95 b/src/modules/moduleMeshCyl.f95 index 9291f8f..2696b05 100644 --- a/src/modules/moduleMeshCyl.f95 +++ b/src/modules/moduleMeshCyl.f95 @@ -537,6 +537,7 @@ MODULE moduleMeshCyl INTEGER:: n !collision INTEGER:: ij, k REAL(8):: sigmaVrelMaxNew + TYPE(pointerArray), ALLOCATABLE:: partTemp(:) self%nColl = 0 nPart = self%listPart_in%amount @@ -544,12 +545,18 @@ MODULE moduleMeshCyl pMax = self%totalWeight*self%sigmaVrelMax*tau/self%volume self%nColl = INT(REAL(nPart)*pMax*0.5D0) + !Converts the list of particles to an array for easy access + IF (self%nColl > 0) THEN + partTemp = self%listPart_in%convert2Array() + + END IF + DO n = 1, self%nColl !Select random numbers rnd = 1 + FLOOR(nPart*RAND()) - part_i => self%listPart_in%get(rnd) + part_i => partTemp(rnd)%part rnd = 1 + FLOOR(nPart*RAND()) - part_j => self%listPart_in%get(rnd) + part_j => partTemp(rnd)%part ij = interactionIndex(part_i%pt, part_j%pt) sigmaVrelMaxNew = 0.D0 DO k = 1, interactionMatrix(ij)%amount diff --git a/src/modules/moduleSpecies.f95 b/src/modules/moduleSpecies.f95 index db2de87..9cf9875 100644 --- a/src/modules/moduleSpecies.f95 +++ b/src/modules/moduleSpecies.f95 @@ -41,7 +41,7 @@ MODULE moduleSpecies INTEGER:: nPartOld INTEGER:: nPartInj !Arrays that contain the particles - TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: partOld + TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: partOld !array of particles from previous iteration TYPE(particle), ALLOCATABLE, DIMENSION(:), TARGET:: partInj !array of inject particles CONTAINS