Add reader modules for TtoZ table
This commit is contained in:
parent
57b111c24d
commit
b73bc86a36
3 changed files with 267 additions and 1 deletions
4
makefile
4
makefile
|
|
@ -3,7 +3,9 @@ all:
|
|||
gfortran moduleReferenceValues.f90 -c -lopenblas -Ofast -fopenmp -Wall
|
||||
gfortran moduleOutput.f90 -c -lopenblas -Ofast -fopenmp -Wall
|
||||
gfortran moduleTableBC.f90 -c -lopenblas -Ofast -fopenmp -Wall
|
||||
gfortran vlaplex.f90 moduleConstantParameters.o moduleReferenceValues.o moduleOutput.o moduleTableBC.o -lopenblas -Ofast -fopenmp -Wall -o vlaplex
|
||||
gfortran moduleTableTtoZ.f90 -c -lopenblas -Ofast -fopenmp -Wall
|
||||
gfortran moduleTableTtoZne.f90 -c -lopenblas -Ofast -fopenmp -Wall
|
||||
gfortran vlaplex.f90 moduleConstantParameters.o moduleReferenceValues.o moduleOutput.o moduleTableBC.o moduleTableTtoZ.o moduleTableTtoZne.o -lopenblas -Ofast -fopenmp -Wall -o vlaplex
|
||||
|
||||
clean:
|
||||
rm -f vlaplex
|
||||
|
|
|
|||
116
moduleTableTtoZ.f90
Normal file
116
moduleTableTtoZ.f90
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
module moduleTableTtoZ
|
||||
use constantParameters, only: dp
|
||||
|
||||
type:: tableTtoZ
|
||||
real(dp):: Z_min, Z_max
|
||||
real(dp):: Temp_min, Temp_max
|
||||
real(dp), allocatable, dimension(:):: Temp
|
||||
real(dp), allocatable, dimension(:):: Z
|
||||
real(dp), allocatable, dimension(:):: Z_k
|
||||
contains
|
||||
procedure, pass:: init => initTableTtoZ
|
||||
procedure, pass:: get => getValueTableTtoZ
|
||||
|
||||
end type tableTtoZ
|
||||
|
||||
contains
|
||||
subroutine initTableTtoZ(self, tableFile)
|
||||
use constantParameters, only: eV_to_K
|
||||
use referenceValues, only: Temp_ref
|
||||
implicit none
|
||||
|
||||
class(tableTtoZ), 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 = -1 ! Remove header
|
||||
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
|
||||
|
||||
!Go bback to initial point
|
||||
rewind(id)
|
||||
|
||||
!Allocate table arrays
|
||||
allocate(self%Temp(1:amount))
|
||||
allocate(self%Z(1:amount))
|
||||
allocate(self%Z_k(1:amount))
|
||||
self%Temp = 0.0_dp
|
||||
self%Z = 0.0_dp
|
||||
self%Z_k = 0.0_dp
|
||||
|
||||
i = 0
|
||||
read(id, *) ! Skip header
|
||||
do
|
||||
read(id, '(A)', iostat = stat) dummy
|
||||
!TOdo: Make this a function
|
||||
if (stat /= 0) EXIT
|
||||
!Add data
|
||||
!TODO: substitute with extracting information from dummy
|
||||
backspace(id)
|
||||
i = i + 1
|
||||
read(id, *) self%Temp(i), self%Z(i)
|
||||
|
||||
end do
|
||||
self%Temp = self%Temp * eV_to_K / Temp_ref
|
||||
|
||||
close(id)
|
||||
|
||||
self%Temp_min = self%Temp(1)
|
||||
self%Temp_max = self%Temp(amount)
|
||||
self%Z_min = self%Z(1)
|
||||
self%Z_max = self%Z(amount)
|
||||
|
||||
do i = 1, amount - 1
|
||||
self%Z_k(i) = ( self%Z(i+1) - self%Z(i))/(self%Temp(i+1) - self%Temp(i))
|
||||
|
||||
end do
|
||||
|
||||
end subroutine initTableTtoZ
|
||||
|
||||
subroutine getValueTableTtoZ(self, Temp, Z)
|
||||
implicit none
|
||||
|
||||
class(tableTtoZ), intent(in):: self
|
||||
real(dp), intent(in):: Temp
|
||||
real(dp), intent(out):: Z
|
||||
real(dp):: delta_Temp
|
||||
integer:: i
|
||||
|
||||
if (Temp <= self%Temp_min) THEN
|
||||
Z = self%Z_min
|
||||
|
||||
elseif (Temp >= self%Temp_max) THEN
|
||||
Z = self%Z_max
|
||||
|
||||
else
|
||||
i = minloc(abs(Temp - self%Temp), 1)
|
||||
delta_Temp = Temp - self%Temp(i)
|
||||
if (delta_Temp < 0 ) THEN
|
||||
i = i - 1
|
||||
delta_Temp = Temp - self%Temp(i)
|
||||
|
||||
end if
|
||||
|
||||
Z = self%Z(i) + self%Z_k(i)*delta_Temp
|
||||
|
||||
end if
|
||||
|
||||
end subroutine getValueTableTtoZ
|
||||
|
||||
|
||||
|
||||
end module moduleTableTtoZ
|
||||
|
||||
148
moduleTableTtoZne.f90
Normal file
148
moduleTableTtoZne.f90
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
module moduleTableTtoZne
|
||||
use constantParameters, only: dp
|
||||
|
||||
type:: tableTtoZne
|
||||
real(dp) :: Z_min, Z_max
|
||||
real(dp) :: Temp_min, Temp_max
|
||||
real(dp), allocatable, dimension(:):: Temp
|
||||
real(dp), allocatable, dimension(:,:):: Z
|
||||
real(dp), allocatable, dimension(:,:):: Z_k
|
||||
real(dp), allocatable, dimension(:):: ne
|
||||
contains
|
||||
procedure, pass:: init => initTableTtoZne
|
||||
procedure, pass:: get => getValueTableTtoZne
|
||||
|
||||
end type tableTtoZne
|
||||
|
||||
contains
|
||||
subroutine initTableTtoZne(self, tableFile)
|
||||
use constantParameters, only: eV_to_K
|
||||
use referenceValues, only: Temp_ref, n_ref
|
||||
implicit none
|
||||
|
||||
class(tableTtoZne), intent(inout):: self
|
||||
character(:), allocatable, intent(in):: tableFile
|
||||
character(100):: dummy
|
||||
character(len=512) :: line
|
||||
character(len=20), allocatable :: ne_headers(:)
|
||||
integer:: amount, num_ne
|
||||
integer:: i,j
|
||||
integer:: stat
|
||||
integer:: id = 20
|
||||
num_ne = 0
|
||||
|
||||
open(id, file = tableFile)
|
||||
amount = -1 ! Remove header
|
||||
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
|
||||
|
||||
!Go bback to initial point
|
||||
rewind(id)
|
||||
read(id, '(A)', iostat = stat) dummy
|
||||
do i = 1, len_trim(dummy)
|
||||
if (dummy(i:i) == ",") num_ne = num_ne + 1
|
||||
end do
|
||||
allocate(ne_headers(num_ne))
|
||||
allocate(self%ne(num_ne))
|
||||
|
||||
rewind(id)
|
||||
read(id, '(A)') line
|
||||
|
||||
! Read values while skipping the first entry
|
||||
read(line, *) dummy, (self%ne(i), i=1, num_ne)
|
||||
|
||||
|
||||
! read(id, *) ! Skip 'x'
|
||||
! do i = 1, num_ne
|
||||
! read(dummy, *) ne_headers(i)
|
||||
! read(ne_headers(i), *) self%ne(i)
|
||||
! print *, self%ne(i)
|
||||
! end do
|
||||
rewind(id)
|
||||
|
||||
|
||||
!Allocate table arrays
|
||||
allocate(self%Temp(1:amount))
|
||||
allocate(self%Z(1:amount, 1:num_ne))
|
||||
allocate(self%Z_k(1:amount, 1:num_ne))
|
||||
self%Temp = 0.0_dp
|
||||
self%Z = 0.0_dp
|
||||
self%Z_k = 0.0_dp
|
||||
|
||||
i = 0
|
||||
read(id, *) ! Skip header
|
||||
do
|
||||
read(id, '(A)', iostat = stat) dummy
|
||||
!TOdo: Make this a function
|
||||
if (stat /= 0) EXIT
|
||||
!Add data
|
||||
!TODO: substitute with extracting information from dummy
|
||||
backspace(id)
|
||||
i = i + 1
|
||||
read(id, *, iostat= stat) self%Temp(i), (self%Z(i, j), j = 1, num_ne)
|
||||
|
||||
end do
|
||||
self%Temp = self%Temp * eV_to_K / Temp_ref
|
||||
self%ne = self%ne / n_ref
|
||||
|
||||
close(id)
|
||||
|
||||
self%Temp_min = self%Temp(1)
|
||||
self%Temp_max = self%Temp(amount)
|
||||
self%Z_min = self%Z(1,1)
|
||||
self%Z_max = self%Z(amount,num_ne)
|
||||
do i = 1, amount - 1
|
||||
do j = 1, num_ne
|
||||
self%Z_k(i,j) = ( self%Z(i+1,j) - self%Z(i,j))/(self%Temp(i+1) - self%Temp(i))
|
||||
end do
|
||||
end do
|
||||
|
||||
end subroutine initTableTtoZne
|
||||
|
||||
subroutine getValueTableTtoZne(self, Temp, ne, Z)
|
||||
implicit none
|
||||
|
||||
class(tableTtoZne), intent(in):: self
|
||||
real(dp), intent(in):: Temp, ne
|
||||
real(dp), intent(out):: Z
|
||||
real(dp):: delta_Temp
|
||||
integer:: i, j
|
||||
|
||||
j = minloc(abs(ne - self%ne), 1)
|
||||
! print *, "ne : ", ne
|
||||
! print *, "Temp : ", Temp
|
||||
|
||||
|
||||
if (Temp <= self%Temp_min) THEN
|
||||
Z = self%Z_min
|
||||
|
||||
elseif (Temp >= self%Temp_max) THEN
|
||||
Z = self%Z_max
|
||||
|
||||
else
|
||||
i = minloc(abs(Temp - self%Temp), 1)
|
||||
delta_Temp = Temp - self%Temp(i)
|
||||
if (delta_Temp < 0 ) THEN
|
||||
i = i - 1
|
||||
delta_Temp = Temp - self%Temp(i)
|
||||
|
||||
end if
|
||||
|
||||
Z = self%Z(i,j) + self%Z_k(i,j)*delta_Temp
|
||||
|
||||
end if
|
||||
|
||||
end subroutine getValueTableTtoZne
|
||||
|
||||
|
||||
|
||||
end module moduleTableTtoZne
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue