From 21b112a591ae873601ad8a9d1362320b60291dcb Mon Sep 17 00:00:00 2001 From: JGonzalez Date: Wed, 18 Feb 2026 20:38:45 +0100 Subject: [PATCH] Split velocity distribution function. Still don't know how to deal with injects --- src/modules/common/makefile | 3 +- src/modules/common/velocityDistribution.f90 | 88 +++++++++++++++++++++ src/modules/makefile | 3 + src/modules/moduleInject.f90 | 85 +------------------- 4 files changed, 94 insertions(+), 85 deletions(-) create mode 100644 src/modules/common/velocityDistribution.f90 diff --git a/src/modules/common/makefile b/src/modules/common/makefile index a57871b..2491412 100644 --- a/src/modules/common/makefile +++ b/src/modules/common/makefile @@ -1,6 +1,7 @@ OBJS = moduleCompTime.o moduleCaseParam.o moduleConstParam.o \ moduleErrors.o moduleMath.o moduleParallel.o \ - moduleRandom.o moduleRefParam.o moduleTable.o + moduleRandom.o moduleRefParam.o moduleTable.o \ + velocityDistribution.o all: $(OBJS) diff --git a/src/modules/common/velocityDistribution.f90 b/src/modules/common/velocityDistribution.f90 new file mode 100644 index 0000000..5b6c342 --- /dev/null +++ b/src/modules/common/velocityDistribution.f90 @@ -0,0 +1,88 @@ +! Functions that return a random velocity based on the distribution function +module velocityDistribution + use moduleRandom + !Generic type for velocity distribution function + type, abstract:: velDistGeneric + contains + !Returns random velocity from distribution function + procedure(randomVel_interface), deferred, pass:: randomVel + + end type velDistGeneric + + abstract interface + function randomVel_interface(self) result(v) + import velDistGeneric + + class(velDistGeneric), intent(in):: self + real(8):: v + + end function randomVel_interface + + end interface + + !Container for velocity distributions + type:: velDistCont + class(velDistGeneric), allocatable:: obj + + end type velDistCont + + !Maxwellian distribution function + type, extends(velDistGeneric):: velDistMaxwellian + real(8):: vTh !Thermal Velocity + contains + procedure, pass:: randomVel => randomVelMaxwellian + + end type velDistMaxwellian + + type, extends(velDistGeneric):: velDistHalfMaxwellian + real(8):: vTh !Thermal Velocity + contains + procedure, pass:: randomVel => randomVelHalfMaxwellian + + end type velDistHalfMaxwellian + + !Dirac's delta distribution function + type, extends(velDistGeneric):: velDistDelta + contains + procedure, pass:: randomVel => randomVelDelta + + end type velDistDelta + + contains + !Random velocity from Maxwellian distribution + function randomVelMaxwellian(self) result (v) + use moduleRandom + implicit none + + class(velDistMaxwellian), intent(in):: self + real(8):: v + v = 0.D0 + + v = self%vTh*randomMaxwellian()/sqrt(2.d0) + + end function randomVelMaxwellian + + !Random velocity from Half Maxwellian distribution + function randomVelHalfMaxwellian(self) result (v) + implicit none + + class(velDistHalfMaxwellian), intent(in):: self + real(8):: v + v = 0.D0 + + v = self%vTh*randomHalfMaxwellian() + + end function randomVelHalfMaxwellian + + !Random velocity from Dirac's delta distribution + PURE function randomVelDelta(self) result(v) + implicit none + + class(velDistDelta), intent(in):: self + real(8):: v + + v = 0.D0 + + end function randomVelDelta + +end module velocityDistribution diff --git a/src/modules/makefile b/src/modules/makefile index bcb96f6..9f62c85 100644 --- a/src/modules/makefile +++ b/src/modules/makefile @@ -35,6 +35,9 @@ moduleProbe.o: mesh.o moduleProbe.f90 moduleSpecies.o: common.o moduleSpecies.f90 $(FC) $(FCFLAGS) -c $(subst .o,.f90,$@) -o $(OBJDIR)/$@ +moduleInject.o: common.o moduleInject.f90 + $(FC) $(FCFLAGS) -c $(subst .o,.f90,$@) -o $(OBJDIR)/$@ + %.o: %.f90 $(FC) $(FCFLAGS) -c $< -o $(OBJDIR)/$@ diff --git a/src/modules/moduleInject.f90 b/src/modules/moduleInject.f90 index d9a0d4e..ea45079 100644 --- a/src/modules/moduleInject.f90 +++ b/src/modules/moduleInject.f90 @@ -1,53 +1,7 @@ !injection of particles MODULE moduleInject USE moduleSpecies - - !Generic type for velocity distribution function - TYPE, ABSTRACT:: velDistGeneric - CONTAINS - !Returns random velocity from distribution function - PROCEDURE(randomVel_interface), DEFERRED, PASS:: randomVel - - END TYPE velDistGeneric - - ABSTRACT INTERFACE - FUNCTION randomVel_interface(self) RESULT(v) - IMPORT velDistGeneric - - CLASS(velDistGeneric), INTENT(in):: self - REAL(8):: v - - END FUNCTION randomVel_interface - - END INTERFACE - - !Container for velocity distributions - TYPE:: velDistCont - CLASS(velDistGeneric), ALLOCATABLE:: obj - - END TYPE velDistCont - - !Maxwellian distribution function - TYPE, EXTENDS(velDistGeneric):: velDistMaxwellian - REAL(8):: vTh !Thermal Velocity - CONTAINS - PROCEDURE, PASS:: randomVel => randomVelMaxwellian - - END TYPE velDistMaxwellian - - TYPE, EXTENDS(velDistGeneric):: velDistHalfMaxwellian - REAL(8):: vTh !Thermal Velocity - CONTAINS - PROCEDURE, PASS:: randomVel => randomVelHalfMaxwellian - - END TYPE velDistHalfMaxwellian - - !Dirac's delta distribution function - TYPE, EXTENDS(velDistGeneric):: velDistDelta - CONTAINS - PROCEDURE, PASS:: randomVel => randomVelDelta - - END TYPE velDistDelta + use velocityDistribution !Generic injection of particles TYPE:: injectGeneric @@ -280,43 +234,6 @@ MODULE moduleInject END SUBROUTINE initVelDistDelta - !Random velocity from Maxwellian distribution - FUNCTION randomVelMaxwellian(self) RESULT (v) - USE moduleRandom - IMPLICIT NONE - - CLASS(velDistMaxwellian), INTENT(in):: self - REAL(8):: v - v = 0.D0 - - v = self%vTh*randomMaxwellian()/sqrt(2.d0) - - END FUNCTION randomVelMaxwellian - - !Random velocity from Half Maxwellian distribution - FUNCTION randomVelHalfMaxwellian(self) RESULT (v) - USE moduleRandom - IMPLICIT NONE - - CLASS(velDistHalfMaxwellian), INTENT(in):: self - REAL(8):: v - v = 0.D0 - - v = self%vTh*randomHalfMaxwellian() - - END FUNCTION randomVelHalfMaxwellian - - !Random velocity from Dirac's delta distribution - PURE FUNCTION randomVelDelta(self) RESULT(v) - IMPLICIT NONE - - CLASS(velDistDelta), INTENT(in):: self - REAL(8):: v - - v = 0.D0 - - END FUNCTION randomVelDelta - !Add particles for the injection SUBROUTINE addParticles(self) USE moduleSpecies