14 integer,
parameter :: iRmin = 2, irmax = 20
15 integer,
parameter :: iTmin = 7, itmax = 76
19 logical :: set_custom_tabledir = .false.
22 double precision,
public ::
kappa_vals(itmin:itmax,irmin:irmax)
34 character(len=*),
intent(in) :: tabledir
35 logical,
optional,
intent(in) :: set_custom_tabledir
38 character(len=256) :: amrvac_dir, path_table_dir
40 if (
present(set_custom_tabledir) .and. set_custom_tabledir)
then
41 path_table_dir = trim(tabledir)
43 call get_environment_variable(
"AMRVAC_DIR", amrvac_dir)
44 path_table_dir = trim(amrvac_dir)//
"/src/tables/OPAL_tables/"//trim(tabledir)
51 write(*,*)
' Initialized OPAL tables: read in the table from', path_table_dir
60 double precision,
intent(in) :: rho, temp
61 double precision,
intent(out) :: kappa
63 double precision :: logr_in, logt_in, logkappa_out
65 if (temp <= 0.0d0)
call mpistop(
'Input temperature < 0 in set_opal_opacity.')
66 if (rho <= 0.0d0)
call mpistop(
'Input density < 0 in set_opal_opacity.')
69 logr_in = log10(rho/(temp*1.0
d-6)**3.0d0)
89 kappa = 10.0d0**logkappa_out
95 subroutine read_table(R, T, K, filename)
97 character(*),
intent(in) :: filename
98 double precision,
intent(out) :: k(itmin:itmax,irmin:irmax), r(irmin:irmax), t(itmin:itmax)
102 integer :: row, col, funit=98
105 inquire(file=trim(filename), exist=alive)
108 open(funit, file=trim(filename), status=
'unknown')
110 call mpistop(
'Table file you want to use cannot be found: '//filename)
119 read(funit,*) dum, r(irmin:irmax)
124 read(funit,
'(f4.2,19f7.3)') t(row), k(row,irmin:irmax)
129 end subroutine read_table
133 subroutine get_kappa(Kappa_vals, logR_list, logT_list, R, T, K)
135 double precision,
intent(in) ::
kappa_vals(itmin:itmax,irmin:irmax)
137 double precision,
intent(in) :: r, t
138 double precision,
intent(out) :: k
141 integer :: low_r_index, up_r_index
142 integer :: low_t_index, up_t_index
147 low_r_index = irmax-1
153 call get_low_up_index(r,
logr_list, irmin, irmax, low_r_index, up_r_index)
157 low_t_index = itmax-1
163 call get_low_up_index(t,
logt_list, itmin, itmax, low_t_index, up_t_index)
168 end subroutine get_kappa
172 subroutine get_low_up_index(var_in, var_list, imin, imax, low_i, up_i)
174 integer,
intent(in) :: imin, imax
175 double precision,
intent(in) :: var_in, var_list(imin:imax)
176 integer,
intent(out) :: low_i, up_i
179 double precision :: low_val, up_val, res(imin:imax)
181 res = var_list - var_in
184 up_val = minval(res, mask = res >= 0) + var_in
185 low_val = maxval(res, mask = res <= 0) + var_in
188 up_i = minloc(abs(var_list - up_val),1) + imin -1
189 low_i = minloc(abs(var_list - low_val),1) + imin -1
191 if (up_i == low_i) low_i = low_i - 1
193 end subroutine get_low_up_index
196 subroutine interpolate_krt(low_r, up_r, low_t, up_t, logR_list, logT_list, Kappa_vals, R, T, kappa_interp)
198 integer,
intent(in) :: low_r, up_r, low_t, up_t
199 double precision,
intent(in) ::
kappa_vals(itmin:itmax,irmin:irmax)
201 double precision,
intent(in) :: r, t
202 double precision,
intent(out) :: kappa_interp
205 double precision :: r1, r2, t1, t2, k1, k2, k3, k4, ka, kb
234 call interpolate1d(r1,r2,r,k1,k2,ka)
235 call interpolate1d(r1,r2,r,k3,k4,kb)
236 call interpolate1d(t1,t2,t,ka,kb,kappa_interp)
238 end subroutine interpolate_krt
241 subroutine interpolate1d(x1, x2, x, y1, y2, y)
243 double precision,
intent(in) :: x, x1, x2, y1, y2
244 double precision,
intent(out) :: y
246 y = y1 + (x-x1)*(y2-y1)/(x2-x1)
248 end subroutine interpolate1d
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer mype
The rank of the current MPI task.
double precision, dimension(:), allocatable, parameter d
This module reads in Rosseland-mean opacities from OPAL tables. Table opacity values are given in bas...
subroutine, public init_opal_table(tabledir, set_custom_tabledir)
This subroutine is called when the FLD radiation module is initialised. The OPAL tables for different...
double precision, dimension(itmin:itmax), public logt_list
double precision, dimension(itmin:itmax, irmin:irmax), public kappa_vals
The opacity tables are read once and stored globally in Kappa_vals.
subroutine, public set_opal_opacity(rho, temp, kappa)
This subroutine calculates the opacity for a given temperature-density structure. Opacities are read ...
double precision, dimension(irmin:irmax), public logr_list