Most of modules organized
Most of the modules are organized in subfolders. Maybe some big re-organization is needed in the future, but for now I am happy.
This commit is contained in:
parent
d9a1869564
commit
9484502d0b
13 changed files with 37 additions and 15 deletions
11
src/modules/common/makefile
Normal file
11
src/modules/common/makefile
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
OBJS = moduleCompTime.o moduleCaseParam.o moduleConstParam.o \
|
||||
moduleErrors.o moduleMath.o moduleParallel.o \
|
||||
moduleRandom.o moduleRefParam.o moduleTable.o
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
moduleTable.o: moduleErrors.o moduleTable.f90
|
||||
$(FC) $(FCFLAGS) -c $(subst .o,.f90,$@) -o $(OBJDIR)/$@
|
||||
|
||||
%.o: %.f90
|
||||
$(FC) $(FCFLAGS) -c $< -o $(OBJDIR)/$@
|
||||
10
src/modules/common/moduleCaseParam.f90
Normal file
10
src/modules/common/moduleCaseParam.f90
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
!Problems of the case
|
||||
MODULE moduleCaseParam
|
||||
!Final and initial iterations
|
||||
INTEGER:: tFinal, tInitial = 0
|
||||
REAL(8), ALLOCATABLE:: tau(:)
|
||||
REAL(8):: tauMin
|
||||
REAL(8):: tauColl
|
||||
|
||||
END MODULE moduleCaseParam
|
||||
|
||||
16
src/modules/common/moduleCompTime.f90
Normal file
16
src/modules/common/moduleCompTime.f90
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
!Information to calculate computation time
|
||||
MODULE moduleCompTime
|
||||
IMPLICIT NONE
|
||||
|
||||
PUBLIC
|
||||
|
||||
REAL(8):: tStep = 0.D0
|
||||
REAL(8):: tPush = 0.D0
|
||||
REAL(8):: tReset = 0.D0
|
||||
REAL(8):: tColl = 0.D0
|
||||
REAL(8):: tCoul = 0.D0
|
||||
REAL(8):: tWeight = 0.D0
|
||||
REAL(8):: tEMField = 0.D0
|
||||
|
||||
END MODULE moduleCompTime
|
||||
|
||||
17
src/modules/common/moduleConstParam.f90
Normal file
17
src/modules/common/moduleConstParam.f90
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
!Physical and mathematical constants
|
||||
MODULE moduleConstParam
|
||||
IMPLICIT NONE
|
||||
|
||||
PUBLIC
|
||||
|
||||
REAL(8), PARAMETER:: PI = 4.D0*DATAN(1.D0) !number pi
|
||||
REAL(8), PARAMETER:: PI2 = 2.D0*PI !2*pi
|
||||
REAL(8), PARAMETER:: PI8 = 8.D0*PI !2*pi
|
||||
REAL(8), PARAMETER:: sccm2atomPerS = 4.5D17 !sccm to atom s^-1
|
||||
REAL(8), PARAMETER:: qe = 1.60217662D-19 !Elementary charge
|
||||
REAL(8), PARAMETER:: kb = 1.38064852D-23 !Boltzmann constants SI
|
||||
REAL(8), PARAMETER:: eV2J = qe !Electron volt to Joule conversion
|
||||
REAL(8), PARAMETER:: eps_0 = 8.8542D-12 !Epsilon_0
|
||||
|
||||
END MODULE moduleConstParam
|
||||
|
||||
43
src/modules/common/moduleErrors.f90
Normal file
43
src/modules/common/moduleErrors.f90
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
!moduleErrors: Manages the different type of errors the program can produce.
|
||||
! By errors we understand critical errors (that stop the program),
|
||||
! warnings (that only output a message with a WARNING tag),
|
||||
! o verbose outputs that can be used for debugging porpouse.
|
||||
MODULE moduleErrors
|
||||
CONTAINS
|
||||
SUBROUTINE criticalError(msg, pgr)
|
||||
IMPLICIT NONE
|
||||
|
||||
CHARACTER(*), INTENT(in):: msg, pgr
|
||||
CHARACTER(:), ALLOCATABLE:: errorMsg
|
||||
|
||||
errorMsg = "CRITICAL error in " // pgr // " with message:" // NEW_LINE('A') // msg
|
||||
|
||||
ERROR STOP errorMsg
|
||||
|
||||
END SUBROUTINE criticalError
|
||||
|
||||
SUBROUTINE warningError(msg)
|
||||
IMPLICIT NONE
|
||||
|
||||
CHARACTER(*), INTENT(in):: msg
|
||||
CHARACTER(:), ALLOCATABLE:: errorMsg
|
||||
|
||||
errorMsg = "WARNING: " // msg
|
||||
|
||||
WRITE (*, '(A)') errorMsg
|
||||
|
||||
END SUBROUTINE warningError
|
||||
|
||||
SUBROUTINE verboseError(msg)
|
||||
IMPLICIT NONE
|
||||
|
||||
CHARACTER(*), INTENT(in):: msg
|
||||
CHARACTER(:), ALLOCATABLE:: errorMsg
|
||||
|
||||
errorMsg = msg
|
||||
|
||||
WRITE (*, '(A)') errorMsg
|
||||
|
||||
END SUBROUTINE verboseError
|
||||
|
||||
END MODULE moduleErrors
|
||||
73
src/modules/common/moduleMath.f90
Normal file
73
src/modules/common/moduleMath.f90
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
MODULE moduleMath
|
||||
IMPLICIT NONE
|
||||
|
||||
CONTAINS
|
||||
!Outer product of two tensors
|
||||
PURE FUNCTION outerProduct(a,b) RESULT(s)
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8), DIMENSION(1:3), INTENT(in):: a, b
|
||||
REAL(8):: s(1:3,1:3)
|
||||
|
||||
s = SPREAD(a, dim = 2, ncopies = 3)*SPREAD(b, dim = 1, ncopies = 3)
|
||||
|
||||
END FUNCTION outerProduct
|
||||
|
||||
!Cross product of two 3D vectors
|
||||
PURE FUNCTION crossProduct(a, b) RESULT(c)
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8), DIMENSION(1:3), INTENT(in):: a, b
|
||||
REAL(8), DIMENSION(1:3):: c
|
||||
|
||||
c = 0.D0
|
||||
|
||||
c(1) = a(2)*b(3) - a(3)*b(2)
|
||||
c(2) = -(a(1)*b(3) - a(3)*b(1))
|
||||
c(3) = a(1)*b(2) - a(2)*b(1)
|
||||
|
||||
END FUNCTION crossProduct
|
||||
|
||||
!Normalizes a 3D vector
|
||||
PURE FUNCTION normalize(a) RESULT(b)
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8), DIMENSION(1:3), INTENT(in):: a
|
||||
REAL(8), DIMENSION(1:3):: b
|
||||
|
||||
b = a / NORM2(a)
|
||||
|
||||
END FUNCTION normalize
|
||||
|
||||
!Norm 1 of vector
|
||||
PURE FUNCTION norm1(a) RESULT(b)
|
||||
IMPLICIT NONE
|
||||
REAL(8), DIMENSION(:), INTENT(in):: a
|
||||
REAL(8):: b
|
||||
|
||||
b = SUM(DABS(a))
|
||||
|
||||
END FUNCTION norm1
|
||||
|
||||
PURE FUNCTION reducedMass(m_i, m_j) RESULT(rMass)
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8), INTENT(in):: m_i, m_j
|
||||
REAL(8):: rMass
|
||||
|
||||
rMass = (m_i * m_j) / (m_i + m_j)
|
||||
|
||||
END FUNCTION
|
||||
|
||||
FUNCTION tensorTrace(a) RESULT(t)
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8), DIMENSION(1:3,1:3):: a
|
||||
REAL(8):: t
|
||||
|
||||
t = 0.D0
|
||||
t = a(1,1)+a(2,2)+a(3,3)
|
||||
|
||||
END FUNCTION tensorTrace
|
||||
|
||||
END MODULE moduleMath
|
||||
22
src/modules/common/moduleParallel.f90
Normal file
22
src/modules/common/moduleParallel.f90
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
MODULE moduleParallel
|
||||
IMPLICIT NONE
|
||||
|
||||
TYPE openMP_type
|
||||
INTEGER:: nThreads
|
||||
|
||||
END TYPE
|
||||
|
||||
TYPE(openMP_type):: openMP
|
||||
|
||||
CONTAINS
|
||||
SUBROUTINE initParallel()
|
||||
IMPLICIT NONE
|
||||
|
||||
EXTERNAL:: OMP_SET_NUM_THREADS
|
||||
|
||||
!Starts threads for OpenMP parallelization
|
||||
CALL OMP_SET_NUM_THREADS(openMP%nThreads)
|
||||
|
||||
END SUBROUTINE initParallel
|
||||
|
||||
END MODULE moduleParallel
|
||||
83
src/modules/common/moduleRandom.f90
Normal file
83
src/modules/common/moduleRandom.f90
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
MODULE moduleRandom
|
||||
!Interface for random number generator
|
||||
INTERFACE random
|
||||
MODULE PROCEDURE randomReal, randomRealAB, randomIntAB
|
||||
|
||||
END INTERFACE random
|
||||
|
||||
CONTAINS
|
||||
!Returns a Real random number between 0 and 1
|
||||
FUNCTION randomReal() RESULT(rnd)
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8):: rnd
|
||||
|
||||
rnd = 0.D0
|
||||
CALL RANDOM_NUMBER(rnd)
|
||||
|
||||
END FUNCTION randomReal
|
||||
|
||||
!Returns a Real random number between a and b
|
||||
FUNCTION randomRealAB(a, b) RESULT(rnd)
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8), INTENT(in):: a, b
|
||||
REAL(8):: rnd
|
||||
REAL(8):: rnd01 !random real between 0 and 1
|
||||
|
||||
rnd = 0.D0
|
||||
CALL RANDOM_NUMBER(rnd01)
|
||||
|
||||
rnd = (b - a) * rnd01 + a
|
||||
|
||||
END FUNCTION randomRealAB
|
||||
|
||||
!Returns an Integer random numnber between a and b
|
||||
FUNCTION randomIntAB(a, b) RESULT(rnd)
|
||||
IMPLICIT NONE
|
||||
|
||||
INTEGER, INTENT(in):: a, b
|
||||
INTEGER:: rnd
|
||||
REAL(8):: rnd01
|
||||
|
||||
rnd = 0.D0
|
||||
CALL RANDOM_NUMBER(rnd01)
|
||||
|
||||
rnd = INT(REAL(b - a) * rnd01) + 1
|
||||
|
||||
END FUNCTION randomIntAB
|
||||
|
||||
!Returns a random number in a Maxwellian distribution of mean 0 and width 1
|
||||
FUNCTION randomMaxwellian() RESULT(rnd)
|
||||
USE moduleConstParam, ONLY: PI
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8):: rnd
|
||||
REAL(8):: x, y
|
||||
|
||||
rnd = 0.D0
|
||||
x = 0.D0
|
||||
DO WHILE (x == 0.D0)
|
||||
CALL RANDOM_NUMBER(x)
|
||||
END DO
|
||||
CALL RANDOM_NUMBER(y)
|
||||
|
||||
rnd = DSQRT(-2.D0*DLOG(x))*DCOS(2.D0*PI*y)
|
||||
|
||||
END FUNCTION randomMaxwellian
|
||||
|
||||
!Returns a random number weighted with the cumWeight array
|
||||
FUNCTION randomWeighted(cumWeight, sumWeight) RESULT(rnd)
|
||||
IMPLICIT NONE
|
||||
|
||||
REAL(8), INTENT(in):: cumWeight(1:)
|
||||
REAL(8), INTENT(in):: sumWeight
|
||||
REAL(8):: rnd0b
|
||||
INTEGER:: rnd
|
||||
|
||||
rnd0b = random(0.D0, sumWeight)
|
||||
rnd = MINLOC(DABS(rnd0b - cumWeight), 1)
|
||||
|
||||
END FUNCTION randomWeighted
|
||||
|
||||
END MODULE moduleRandom
|
||||
9
src/modules/common/moduleRefParam.f90
Normal file
9
src/modules/common/moduleRefParam.f90
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
!Reference parameters
|
||||
MODULE moduleRefParam
|
||||
!Parameters that define the problem (inputs)
|
||||
REAL(8):: n_ref, m_ref, T_ref, r_ref, debye_ref, sigmaVrel_ref
|
||||
!Reference parameters for non-dimensional problem
|
||||
REAL(8):: L_ref, v_ref, ti_ref, Vol_ref, EF_ref, Volt_ref, B_ref
|
||||
|
||||
END MODULE moduleRefParam
|
||||
|
||||
126
src/modules/common/moduleTable.f90
Normal file
126
src/modules/common/moduleTable.f90
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
MODULE moduleTable
|
||||
|
||||
TYPE:: table1D
|
||||
REAL(8):: xMin, xMax
|
||||
REAL(8):: fMin, fMax
|
||||
REAL(8), ALLOCATABLE, DIMENSION(:):: x, f, k
|
||||
CONTAINS
|
||||
PROCEDURE, PASS:: init => initTable1D
|
||||
PROCEDURE, PASS:: get => getValueTable1D
|
||||
PROCEDURE, PASS:: convert => convertUnits
|
||||
|
||||
END TYPE table1D
|
||||
|
||||
CONTAINS
|
||||
SUBROUTINE initTable1D(self, tableFile)
|
||||
USE moduleErrors
|
||||
IMPLICIT NONE
|
||||
|
||||
CLASS(table1D), INTENT(inout):: self
|
||||
CHARACTER(:), ALLOCATABLE, INTENT(IN):: tableFile
|
||||
CHARACTER(100):: dummy
|
||||
INTEGER:: amount
|
||||
INTEGER:: i
|
||||
INTEGER:: stat
|
||||
INTEGER:: id = 20
|
||||
|
||||
OPEN(id, file = tableFile)
|
||||
amount = 0
|
||||
DO
|
||||
READ(id, '(A)', iostat = stat) dummy
|
||||
!If EOF or error, exit file
|
||||
IF (stat /= 0) EXIT
|
||||
!Skip comment
|
||||
IF (INDEX(dummy,'#') /= 0) CYCLE
|
||||
!Add row
|
||||
amount = amount + 1
|
||||
|
||||
END DO
|
||||
|
||||
IF (amount == 0) CALL criticalError('Table ' // tableFile // ' is empty', 'initTable1D')
|
||||
IF (amount == 1) CALL criticalError('Table ' // tableFile // ' has only one row', 'initTable1D')
|
||||
|
||||
!Go bback to initial point
|
||||
REWIND(id)
|
||||
|
||||
!Allocate table arrays
|
||||
ALLOCATE(self%x(1:amount), self%f(1:amount), self%k(1:amount))
|
||||
self%x = 0.D0
|
||||
self%f = 0.D0
|
||||
self%k = 0.D0
|
||||
|
||||
i = 0
|
||||
DO
|
||||
READ(id, '(A)', iostat = stat) dummy
|
||||
!TODO: Make this a function
|
||||
IF (INDEX(dummy,'#') /= 0) CYCLE
|
||||
IF (stat /= 0) EXIT
|
||||
!Add data
|
||||
!TODO: substitute with extracting information from dummy
|
||||
BACKSPACE(id)
|
||||
i = i + 1
|
||||
READ(id, *) self%x(i), self%f(i)
|
||||
|
||||
END DO
|
||||
|
||||
CLOSE(id)
|
||||
|
||||
self%xMin = self%x(1)
|
||||
self%xMax = self%x(amount)
|
||||
self%fMin = self%f(1)
|
||||
self%fMax = self%f(amount)
|
||||
|
||||
DO i = 1, amount - 1
|
||||
self%k(i) = (self%f(i+1) - self%f(i))/(self%x(i+1) - self%x(i))
|
||||
|
||||
END DO
|
||||
|
||||
END SUBROUTINE initTable1D
|
||||
|
||||
FUNCTION getValueTable1D(self, x) RESULT(f)
|
||||
IMPLICIT NONE
|
||||
|
||||
CLASS(table1D), INTENT(in):: self
|
||||
REAL(8):: x
|
||||
REAL(8):: f
|
||||
REAL(8):: deltaX
|
||||
INTEGER:: i
|
||||
|
||||
IF (x <= self%xMin) THEN
|
||||
f = self%fMin
|
||||
|
||||
ELSEIF (x >= self%xMax) THEN
|
||||
f = self%fMax
|
||||
|
||||
ELSE
|
||||
i = MINLOC(x - self%x, 1)
|
||||
deltaX = x - self%x(i)
|
||||
IF (deltaX < 0 ) THEN
|
||||
i = i - 1
|
||||
deltaX = x - self%x(i)
|
||||
|
||||
END IF
|
||||
|
||||
f = self%f(i) + self%k(i)*deltaX
|
||||
|
||||
END IF
|
||||
|
||||
END FUNCTION getValueTable1D
|
||||
|
||||
SUBROUTINE convertUnits(self, data_x, data_f)
|
||||
IMPLICIT NONE
|
||||
|
||||
CLASS(table1D), INTENT(inout):: self
|
||||
REAL(8):: data_x, data_f
|
||||
|
||||
self%x = self%x * data_x
|
||||
self%xMin = self%xMin * data_x
|
||||
self%xMax = self%xMax * data_x
|
||||
self%f = self%f * data_f
|
||||
self%fMin = self%fMin * data_f
|
||||
self%fMax = self%fMax * data_f
|
||||
self%k = self%k * data_f / data_x
|
||||
|
||||
END SUBROUTINE convertUnits
|
||||
|
||||
END MODULE moduleTable
|
||||
Loading…
Add table
Add a link
Reference in a new issue