module moduleTableBC use constantParameters, only: dp type:: tableBC real(dp):: t_min, t_max real(dp):: n_min, n_max real(dp):: u_min, u_max real(dp):: Temp_min, Temp_max real(dp), allocatable, dimension(:):: t real(dp), allocatable, dimension(:):: n, u, Temp real(dp), allocatable, dimension(:):: n_k, u_k, Temp_k contains procedure, pass:: init => initTableBC procedure, pass:: get => getValueTableBC end type tableBC contains subroutine initTableBC(self, tableFile) use constantParameters, only: eV_to_K use referenceValues, only: t_ref, n_ref, u_ref, Temp_ref implicit none class(tableBC), 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%t(1:amount)) allocate( self%n(1:amount), self%u(1:amount), self%Temp(1:amount)) allocate(self%n_k(1:amount), self%u_k(1:amount), self%Temp_k(1:amount)) self%t = 0.0_dp self%n = 0.0_dp self%u = 0.0_dp self%Temp = 0.0_dp self%n_k = 0.0_dp self%u_k = 0.0_dp self%Temp_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%t(i), self%n(i), self%u(i), self%Temp(i) end do self%t = self%t / t_ref self%n = self%n / n_ref self%u = self%u / u_ref self%Temp = self%Temp * eV_to_K / Temp_ref close(id) self%t_min = self%t(1) self%t_max = self%t(amount) self%n_min = self%n(1) self%n_max = self%n(amount) self%u_min = self%u(1) self%u_max = self%u(amount) self%Temp_min = self%Temp(1) self%Temp_max = self%Temp(amount) do i = 1, amount - 1 self%n_k(i) = ( self%n(i+1) - self%n(i))/(self%t(i+1) - self%t(i)) self%u_k(i) = ( self%u(i+1) - self%u(i))/(self%t(i+1) - self%t(i)) self%Temp_k(i) = (self%Temp(i+1) - self%Temp(i))/(self%t(i+1) - self%t(i)) end do end subroutine initTableBC subroutine getValueTableBC(self, t, n, u, Temp) implicit none class(tableBC), intent(in):: self real(dp), intent(in):: t real(dp), intent(out):: n, u, Temp real(dp):: delta_t integer:: i if (t <= self%t_min) THEN n = self%n_min u = self%u_min Temp = self%Temp_min elseif (t >= self%t_max) THEN n = self%n_max u = self%u_max Temp = self%Temp_max else i = minloc(abs(t - self%t), 1) delta_t = t - self%t(i) if (delta_t < 0 ) THEN i = i - 1 delta_t = t - self%t(i) end if n = self%n(i) + self%n_k(i)*delta_t u = self%u(i) + self%u_k(i)*delta_t Temp = self%Temp(i) + self%Temp_k(i)*delta_t end if end subroutine getValueTableBC end module moduleTableBC