38 integer,
parameter,
private :: radstream=0, fdisc=1, fdisc_cutoff=2
56 real(8),
allocatable,
private :: ay(:), wy(:), aphi(:), wphi(:)
59 real(8),
private :: cak_gamma
62 real(8),
private :: lum, dlum, drstar, dke, dclight
65 real(8),
private :: tfloor
79 character(len=*),
intent(in) :: files(:)
89 open(
unitpar, file=trim(files(n)), status=
"old")
90 read(
unitpar, cak_list,
end=111)
100 real(8),
intent(in) :: phys_gamma
102 cak_gamma = phys_gamma
115 gcak1_ = var_set_extravar(
"gcak1",
"gcak1")
116 fdf_ = var_set_extravar(
"fdfac",
"fdfac")
120 gcak1_ = var_set_extravar(
"gcak1",
"gcak1")
121 gcak2_ = var_set_extravar(
"gcak2",
"gcak2")
122 gcak3_ = var_set_extravar(
"gcak3",
"gcak3")
128 call mpistop(
'CAK error: choose alpha in [0,1[')
132 call mpistop(
'CAK error: chosen Qbar or Q0 is < 0')
136 call mpistop(
'CAK error: choose either 1-D or vector force')
146 real(8),
intent(in) :: rstar, twind
161 integer,
intent(in) :: ixI^L, ixO^L
162 real(8),
intent(in) :: qdt, x(ixI^S,1:ndim), wCT(ixI^S,1:nw)
163 real(8),
intent(inout) :: w(ixI^S,1:nw)
164 logical,
intent(in) :: energy, qsourcesplit
165 logical,
intent(inout) :: active
169 real(8) :: gl(ixO^S,1:3), ge(ixO^S), etherm(ixI^S), emin(ixI^S)
178 gl(ixo^s,1:3) = 0.0d0
185 call mpistop(
"No valid force option")
190 if (idir == 1) gl(ixo^s,idir) = gl(ixo^s,idir) + ge(ixo^s)
192 w(ixo^s,iw_mom(idir)) = w(ixo^s,iw_mom(idir)) &
193 + qdt * gl(ixo^s,idir) * wct(ixo^s,iw_rho)
196 w(ixo^s,iw_e) = w(ixo^s,iw_e) + qdt * gl(ixo^s,idir) * wct(ixo^s,iw_mom(idir))
199 call phys_get_pthermal(w,x,ixi^l,ixo^l,etherm)
200 etherm(ixo^s) = etherm(ixo^s) / (cak_gamma - 1.0d0)
201 emin(ixo^s) = w(ixo^s,iw_rho)*tfloor / (cak_gamma - 1.0d0)
203 where (etherm < emin)
204 w(ixo^s,iw_e) = w(ixo^s,iw_e) - etherm(ixo^s) + emin(ixo^s)
216 integer,
intent(in) :: ixI^L, ixO^L
217 real(8),
intent(in) :: wCT(ixI^S,1:nw), x(ixI^S,1:ndim)
218 real(8),
intent(inout) :: w(ixI^S,1:nw)
219 real(8),
intent(inout) :: gcak(ixO^S,1:3)
222 real(8) :: vr(ixI^S), dvrdr(ixO^S)
223 real(8) :: beta_fd(ixO^S), fdfac(ixO^S), taus(ixO^S), ge(ixO^S)
225 vr(ixi^s) = wct(ixi^s,iw_mom(1)) / wct(ixi^s,iw_rho)
228 if (physics_type ==
'hd')
then
230 dvrdr(ixo^s) = abs(dvrdr(ixo^s))
233 dvrdr(ixo^s) = max(dvrdr(ixo^s), smalldouble)
241 case(radstream, fdisc)
242 taus(ixo^s) =
gayley_qbar * dke * dclight * wct(ixo^s,iw_rho)/dvrdr(ixo^s)
247 taus(ixo^s) =
gayley_q0 * dke * dclight * wct(ixo^s,iw_rho)/dvrdr(ixo^s)
249 * ( (1.0d0 + taus(ixo^s))**(1.0d0 -
cak_alpha) - 1.0d0 ) &
252 call mpistop(
"Error in force computation.")
256 beta_fd(ixo^s) = ( 1.0d0 - vr(ixo^s)/(x(ixo^s,1) * dvrdr(ixo^s)) ) &
257 * (drstar/x(ixo^s,1))**2.0d0
262 case(fdisc, fdisc_cutoff)
263 where (beta_fd(ixo^s) >= 1.0d0)
265 elsewhere (beta_fd(ixo^s) < -1.0d10)
267 elsewhere (abs(beta_fd) > 1.0
d-3)
268 fdfac(ixo^s) = (1.0d0 - (1.0d0 - beta_fd(ixo^s))**(1.0d0 +
cak_alpha)) &
271 fdfac(ixo^s) = 1.0d0 - 0.5d0*
cak_alpha*beta_fd(ixo^s) &
272 * (1.0d0 + 1.0d0/3.0d0 * (1.0d0 -
cak_alpha)*beta_fd(ixo^s))
277 gcak(ixo^s,1) = gcak(ixo^s,1) * fdfac(ixo^s)
278 gcak(ixo^s,2) = 0.0d0
279 gcak(ixo^s,3) = 0.0d0
282 w(ixo^s,
gcak1_) = gcak(ixo^s,1)
283 w(ixo^s,
fdf_) = fdfac(ixo^s)
293 integer,
intent(in) :: ixI^L, ixO^L
294 real(8),
intent(in) :: wCT(ixI^S,1:nw), x(ixI^S,1:ndim)
295 real(8),
intent(inout) :: w(ixI^S,1:nw)
296 real(8),
intent(inout) :: gcak(ixO^S,1:3)
299 integer :: ix^D, itray, ipray
300 real(8) :: a1, a2, a3, wyray, y, wpray, phiray, wtot, mustar, dvndn
301 real(8) :: costp, costp2, sintp, cospp, sinpp, cott0
302 real(8) :: vr(ixI^S), vt(ixI^S), vp(ixI^S)
303 real(8) :: vrr(ixI^S), vtr(ixI^S), vpr(ixI^S)
304 real(8) :: dvrdr(ixO^S), dvtdr(ixO^S), dvpdr(ixO^S)
305 real(8) :: dvrdt(ixO^S), dvtdt(ixO^S), dvpdt(ixO^S)
306 real(8) :: dvrdp(ixO^S), dvtdp(ixO^S), dvpdp(ixO^S)
309 vt(ixo^s) = 0.0d0; vtr(ixo^s) = 0.0d0
310 vp(ixo^s) = 0.0d0; vpr(ixo^s) = 0.0d0
312 dvrdr(ixo^s) = 0.0d0; dvtdr(ixo^s) = 0.0d0; dvpdr(ixo^s) = 0.0d0
313 dvrdt(ixo^s) = 0.0d0; dvtdt(ixo^s) = 0.0d0; dvpdt(ixo^s) = 0.0d0
314 dvrdp(ixo^s) = 0.0d0; dvtdp(ixo^s) = 0.0d0; dvpdp(ixo^s) = 0.0d0
317 vr(ixi^s) = wct(ixi^s,iw_mom(1)) / wct(ixi^s,iw_rho)
318 vrr(ixi^s) = vr(ixi^s) / x(ixi^s,1)
321 vt(ixi^s) = wct(ixi^s,iw_mom(2)) / wct(ixi^s,iw_rho)
322 vtr(ixi^s) = vt(ixi^s) / x(ixi^s,1)
325 vp(ixi^s) = wct(ixi^s,iw_mom(3)) / wct(ixi^s,iw_rho)
326 vpr(ixi^s) = vp(ixi^s) / x(ixi^s,1)
350 {
do ix^db=ixomin^db,ixomax^db\}
371 mustar = sqrt(max(1.0d0 - (drstar/x(ix^d,1))**2.0d0, 0.0d0))
372 costp = 1.0d0 - y*(1.0d0 - mustar)
374 sintp = sqrt(max(1.0d0 - costp2, 0.0d0))
377 {^nooned cott0 = cos(x(ix^d,2))/sin(x(ix^d,2))}
380 wtot = wyray * wpray * (1.0d0 - mustar)
388 dvndn = a1*a1 * dvrdr(ix^d) + a2*a2 * (dvtdt(ix^d) + vrr(ix^d)) &
389 + a3*a3 * (dvpdp(ix^d) + cott0 * vtr(ix^d) + vrr(ix^d)) &
390 + a1*a2 * (dvtdr(ix^d) + dvrdt(ix^d) - vtr(ix^d)) &
391 + a1*a3 * (dvpdr(ix^d) + dvrdp(ix^d) - vpr(ix^d)) &
392 + a2*a3 * (dvpdt(ix^d) + dvtdp(ix^d) - cott0 * vpr(ix^d))
399 gcak(ix^d,1) = gcak(ix^d,1) + (dvndn/wct(ix^d,iw_rho))**
cak_alpha * a1 * wtot
400 gcak(ix^d,2) = gcak(ix^d,2) + (dvndn/wct(ix^d,iw_rho))**
cak_alpha * a2 * wtot
401 gcak(ix^d,3) = gcak(ix^d,3) + (dvndn/wct(ix^d,iw_rho))**
cak_alpha * a3 * wtot
409 * dlum/(4.0d0*dpi*drstar**2.0d0 * dclight**(1.0d0+
cak_alpha)) &
413 gcak(ixo^s,2) = 0.0d0
414 gcak(ixo^s,3) = 0.0d0
418 w(ixo^s,
gcak1_) = gcak(ixo^s,1)
419 w(ixo^s,
gcak2_) = gcak(ixo^s,2)
420 w(ixo^s,
gcak3_) = gcak(ixo^s,3)
428 integer,
intent(in) :: ixI^L, ixO^L
429 real(8),
intent(in) :: w(ixI^S,1:nw), x(ixI^S,1:ndim)
430 real(8),
intent(out):: ge(ixO^S)
432 ge(ixo^s) = dke * dlum/(4.0d0*dpi * dclight * x(ixo^s,1)**2.0d0)
440 integer,
intent(in) :: ixI^L, ixO^L
441 real(8),
intent(in) :: dx^D, x(ixI^S,1:ndim)
442 real(8),
intent(in) :: w(ixI^S,1:nw)
443 real(8),
intent(inout) :: dtnew
446 real(8) :: ge(ixO^S), max_gr, dt_cak
453 max_gr = max( maxval(abs(ge(ixo^s) + w(ixo^s,
gcak1_))), epsilon(1.0d0) )
454 dt_cak = minval( sqrt(
block%dx(ixo^s,1)/max_gr) )
459 max_gr = max( maxval(abs(w(ixo^s,
gcak2_))), epsilon(1.0d0) )
460 dt_cak = minval( sqrt(
block%dx(ixo^s,1) *
block%dx(ixo^s,2)/max_gr) )
464 max_gr = max( maxval(abs(w(ixo^s,
gcak3_))), epsilon(1.0d0) )
465 dt_cak = minval( sqrt(
block%dx(ixo^s,1) * sin(
block%dx(ixo^s,3))/max_gr) )
477 integer,
intent(in) :: ixI^L, ixO^L, idir
478 real(8),
intent(in) :: vfield(ixI^S), x(ixI^S,1:ndim)
479 real(8),
intent(out) :: grad_vn(ixO^S)
482 real(8) :: forw(ixO^S), backw(ixO^S), cent(ixO^S)
483 integer :: jrx^L, hrx^L{^NOONED,jtx^L, htx^L}{^IFTHREED,jpx^L, hpx^L}
486 jrx^l=ixo^l+
kr(1,^
d);
487 hrx^l=ixo^l-
kr(1,^
d);
491 jtx^l=ixo^l+
kr(2,^
d);
492 htx^l=ixo^l-
kr(2,^
d);
497 jpx^l=ixo^l+
kr(3,^
d);
498 hpx^l=ixo^l-
kr(3,^
d);
504 forw(ixo^s) = (x(ixo^s,1) - x(hrx^s,1)) * vfield(jrx^s) &
505 / ((x(jrx^s,1) - x(ixo^s,1)) * (x(jrx^s,1) - x(hrx^s,1)))
507 backw(ixo^s) = -(x(jrx^s,1) - x(ixo^s,1)) * vfield(hrx^s) &
508 / ((x(ixo^s,1) - x(hrx^s,1)) * (x(jrx^s,1) - x(hrx^s,1)))
510 cent(ixo^s) = (x(jrx^s,1) + x(hrx^s,1) - 2.0d0*x(ixo^s,1)) * vfield(ixo^s) &
511 / ((x(ixo^s,1) - x(hrx^s,1)) * (x(jrx^s,1) - x(ixo^s,1)))
514 forw(ixo^s) = (x(ixo^s,2) - x(htx^s,2)) * vfield(jtx^s) &
515 / (x(ixo^s,1) * (x(jtx^s,2) - x(ixo^s,2)) * (x(jtx^s,2) - x(htx^s,2)))
517 backw(ixo^s) = -(x(jtx^s,2) - x(ixo^s,2)) * vfield(htx^s) &
518 / ( x(ixo^s,1) * (x(ixo^s,2) - x(htx^s,2)) * (x(jtx^s,2) - x(htx^s,2)))
520 cent(ixo^s) = (x(jtx^s,2) + x(htx^s,2) - 2.0d0*x(ixo^s,2)) * vfield(ixo^s) &
521 / ( x(ixo^s,1) * (x(ixo^s,2) - x(htx^s,2)) * (x(jtx^s,2) - x(ixo^s,2)))
525 forw(ixo^s) = (x(ixo^s,3) - x(hpx^s,3)) * vfield(jpx^s) &
526 / ( x(ixo^s,1)*sin(x(ixo^s,2)) * (x(jpx^s,3) - x(ixo^s,3)) * (x(jpx^s,3) - x(hpx^s,3)))
528 backw(ixo^s) = -(x(jpx^s,3) - x(ixo^s,3)) * vfield(hpx^s) &
529 / ( x(ixo^s,1)*sin(x(ixo^s,2)) * (x(ixo^s,3) - x(hpx^s,3)) * (x(jpx^s,3) - x(hpx^s,3)))
531 cent(ixo^s) = (x(jpx^s,3) + x(hpx^s,3) - 2.0d0*x(ixo^s,3)) * vfield(ixo^s) &
532 / ( x(ixo^s,1)*sin(x(ixo^s,2)) * (x(ixo^s,3) - x(hpx^s,3)) * (x(jpx^s,3) - x(ixo^s,3)))
537 grad_vn(ixo^s) = backw(ixo^s) + cent(ixo^s) + forw(ixo^s)
546 integer,
intent(in) :: ntheta_point, nphi_point
549 real(8) :: ymin, ymax, phipmin, phipmax, adum
561 allocate(ay(ntheta_point))
562 allocate(wy(ntheta_point))
563 allocate(aphi(nphi_point))
564 allocate(wphi(nphi_point))
589 print*,
'==========================='
590 print*,
' Radiation ray setup '
591 print*,
'==========================='
592 print*,
'Theta ray points + weights '
593 do ii = 1,ntheta_point
594 print*,ii,ay(ii),wy(ii)
597 print*,
'Phi ray points + weights '
599 print*,ii,aphi(ii),wphi(ii)
610 call mpi_bcast(ntheta_point,1,mpi_integer,0,
icomm,
ierrmpi)
611 call mpi_bcast(nphi_point,1,mpi_integer,0,
icomm,
ierrmpi)
614 allocate(ay(ntheta_point))
615 allocate(wy(ntheta_point))
616 allocate(aphi(nphi_point))
617 allocate(wphi(nphi_point))
620 call mpi_bcast(ay,ntheta_point,mpi_double_precision,0,
icomm,
ierrmpi)
621 call mpi_bcast(wy,ntheta_point,mpi_double_precision,0,
icomm,
ierrmpi)
622 call mpi_bcast(aphi,nphi_point,mpi_double_precision,0,
icomm,
ierrmpi)
623 call mpi_bcast(wphi,nphi_point,mpi_double_precision,0,
icomm,
ierrmpi)
636 real(8),
intent(in) :: xlow, xhi
637 integer,
intent(in) :: n
638 real(8),
intent(out) :: x(n), w(n)
642 real(8) :: p1, p2, p3, pp, xl, xm, z, z1
643 real(8),
parameter :: error=3.0
d-14
646 xm = 0.5d0*(xhi + xlow)
647 xl = 0.5d0*(xhi - xlow)
650 z = cos( dpi * (i - 0.25d0)/(n + 0.5d0) )
653 do while (abs(z1 - z) > error)
660 p1 = ( (2.0d0*j - 1.0d0)*z*p2 - (j - 1.0d0)*p3 )/j
663 pp = n*(z*p1 - p2) / (z*z - 1.0d0)
670 w(i) = 2.0d0*xl / ((1.0d0 - z*z) * pp*pp)
subroutine mpistop(message)
Exit MPI-AMRVAC with an error message.
Module to include CAK radiation line force in (magneto)hydrodynamic models Computes both the force fr...
subroutine get_gelectron(ixIL, ixOL, w, x, ge)
Compute continuum radiation force from Thomson scattering.
real(8), public gayley_qbar
subroutine get_velocity_gradient(ixIL, ixOL, vfield, x, idir, grad_vn)
Compute velocity gradient in direction 'idir' on a non-uniform grid.
real(8), public gayley_q0
subroutine cak_get_dt(w, ixIL, ixOL, dtnew, dxD, x)
Check time step for total radiation contribution.
logical cak_split
To treat source term in split or unsplit (default) fashion.
subroutine cak_init(phys_gamma)
Initialize the module.
subroutine cak_params_read(files)
Public method.
subroutine gauss_legendre_quadrature(xlow, xhi, n, x, w)
Fast Gauss-Legendre N-point quadrature algorithm by G. Rybicki.
real(8), public cak_alpha
Line-ensemble parameters in the Gayley (1995) formalism.
subroutine, public set_cak_force_norm(rstar, twind)
Compute some (unitless) variables for CAK force normalisation.
subroutine get_cak_force_radial(ixIL, ixOL, wCT, w, x, gcak)
1-D CAK line force in the Gayley line-ensemble distribution parametrisation
logical fix_vector_force_1d
To activate the pure radial vector CAK line force computation.
integer gcak1_
Extra slots to store quantities in w-array.
logical cak_vector_force
To activate the vector CAK line force computation.
subroutine cak_add_source(qdt, ixIL, ixOL, wCT, w, x, energy, qsourcesplit, active)
w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
integer cak_1d_opt
Switch to choose between the 1-D CAK line force options.
subroutine get_cak_force_vector(ixIL, ixOL, wCT, w, x, gcak)
Vector CAK line force in the Gayley line-ensemble distribution parametrisation.
logical cak_1d_force
To activate the original CAK 1-D line force computation.
integer nthetaray
Amount of rays in radiation polar and radiation azimuthal direction.
subroutine rays_init(ntheta_point, nphi_point)
Initialise (theta',phi') radiation angles coming from stellar disc.
Module for physical and numeric constants.
double precision, parameter dpi
Pi.
double precision, parameter const_kappae
double precision, parameter const_c
double precision, parameter const_sigma
This module contains definitions of global parameters and variables and some generic functions/subrou...
type(state), pointer block
Block pointer for using one block and its previous state.
double precision unit_time
Physical scaling factor for time.
double precision unit_density
Physical scaling factor for density.
integer, parameter unitpar
file handle for IO
integer, dimension(3, 3) kr
Kronecker delta tensor.
double precision unit_length
Physical scaling factor for length.
character(len=std_len), dimension(:), allocatable par_files
Which par files are used as input.
integer icomm
The MPI communicator.
integer mype
The rank of the current MPI task.
integer, dimension(:), allocatable, parameter d
integer ndir
Number of spatial dimensions (components) for vector variables.
double precision courantpar
The Courant (CFL) number used for the simulation.
integer ierrmpi
A global MPI error return code.
integer npe
The number of MPI tasks.
double precision unit_velocity
Physical scaling factor for velocity.
double precision unit_temperature
Physical scaling factor for temperature.
This module defines the procedures of a physics module. It contains function pointers for the various...
procedure(sub_get_pthermal), pointer phys_get_pthermal
character(len=name_len) physics_type
String describing the physics type of the simulation.
Module with all the methods that users can customize in AMRVAC.