MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code
Loading...
Searching...
No Matches
mod_cak_force.t
Go to the documentation of this file.
1!> Module to include CAK radiation line force in (magneto)hydrodynamic models
2!> Computes both the force from free electrons and the force from an ensemble of
3!> lines (various possibilities for the latter).
4!> There is an option to only simulate the pure radial CAK force (with various
5!> corrections applied) as well as the full vector CAK force. Depending on the
6!> chosen option additional output are the CAK line force component(s) and,
7!> when doing a 1-D radial force, the finite disc factor.
8!>
9!> USAGE:
10!>
11!> 1. Include a cak_list in the .par file and activate (m)hd_cak_force in the
12!> (m)hd_list
13!> 2. Create a mod_usr.t file for the problem with appropriate initial and
14!> boundary conditions
15!> 3. In the mod_usr.t header call the mod_cak_force module to have access to
16!> global variables from mod_cak_force, which may be handy for printing or
17!> the computation of other variables inside mod_usr.t
18!> 4. In usr_init of mod_usr.t call the set_cak_force_norm routine and pass
19!> along the stellar radius and wind temperature---this is needed to
20!> correctly compute the (initial) force normalisation inside mod_cak_force
21!> 5. Ensure that the order of calls in usr_init is similar as for test problem
22!> CAKwind_spherical_1D: first reading usr.par list; then set unit scales;
23!> then call (M)HD_activate; then call set_cak_force_norm. This order avoids
24!> an incorrect force normalisation and code crash
25!>
26!> Developed by Florian Driessen (2022)
29 implicit none
30
31 !> Line-ensemble parameters in the Gayley (1995) formalism
32 real(8), public :: cak_alpha, gayley_qbar, gayley_q0
33
34 !> Ray positions + weights for impact parameter and azimuthal radiation angle
35 real(8), allocatable, private :: ay(:), wy(:), aphi(:), wphi(:)
36
37 !> The adiabatic index
38 real(8), private :: cak_gamma
39
40 !> Variables needed to compute force normalisation fnorm in initialisation
41 real(8), private :: lum, dlum, drstar, dke, dclight
42
43 !> To enforce a floor temperature when doing adiabatic (M)HD
44 real(8), private :: tfloor
45
46 !> Switch to choose between the 1-D CAK line force options
47 integer :: cak_1d_opt
48
49 ! Avoid magic numbers in code for 1-D CAK line force option
50 integer, parameter, private :: radstream=0, fdisc=1, fdisc_cutoff=2
51
52 !> Amount of rays in radiation polar and radiation azimuthal direction
53 integer :: nthetaray, nphiray
54
55 !> Extra slots to store quantities in w-array
56 integer :: gcak1_, gcak2_, gcak3_, fdf_
57
58 !> To treat source term in split or unsplit (default) fashion
59 logical :: cak_split=.false.
60
61 !> To activate the original CAK 1-D line force computation
62 logical :: cak_1d_force=.false.
63
64 !> To activate the vector CAK line force computation
65 logical :: cak_vector_force=.false.
66
67 !> To activate the pure radial vector CAK line force computation
68 logical :: fix_vector_force_1d=.false.
69
70 !> Public method
71 public :: set_cak_force_norm
72
73contains
74
75 !> Read this module's parameters from a file
76 subroutine cak_params_read(files)
78
79 character(len=*), intent(in) :: files(:)
80
81 ! Local variable
82 integer :: n
83
84 namelist /cak_list/ cak_alpha, gayley_qbar, gayley_q0, cak_1d_opt, &
87
88 do n = 1,size(files)
89 open(unitpar, file=trim(files(n)), status="old")
90 read(unitpar, cak_list, end=111)
91 111 close(unitpar)
92 enddo
93
94 end subroutine cak_params_read
95
96 !> Initialize the module
97 subroutine cak_init(phys_gamma)
99 use mod_comm_lib, only: mpistop
100
101 real(8), intent(in) :: phys_gamma
102
103 cak_gamma = phys_gamma
104
105 ! Set some defaults when user does not
106 cak_alpha = 0.65d0
107 gayley_qbar = 2000.0d0
108 gayley_q0 = 2000.0d0
109 cak_1d_opt = fdisc
110 nthetaray = 6
111 nphiray = 6
112
114
115 if (cak_1d_force) then
116 gcak1_ = var_set_extravar("gcak1", "gcak1")
117 fdf_ = var_set_extravar("fdfac", "fdfac")
118 endif
119
120 if (cak_vector_force) then
121 gcak1_ = var_set_extravar("gcak1", "gcak1")
122 gcak2_ = var_set_extravar("gcak2", "gcak2")
123 gcak3_ = var_set_extravar("gcak3", "gcak3")
125 endif
126
127 ! Some sanity checks
128 if ((cak_alpha <= 0.0d0) .or. (cak_alpha > 1.0d0)) then
129 call mpistop('CAK error: choose alpha in [0,1[')
130 endif
131
132 if ((gayley_qbar < 0.0d0) .or. (gayley_q0 < 0.0d0)) then
133 call mpistop('CAK error: chosen Qbar or Q0 is < 0')
134 endif
135
136 if (cak_1d_force .and. cak_vector_force) then
137 call mpistop('CAK error: choose either 1-D or vector force')
138 endif
139
140 end subroutine cak_init
141
142 !> Compute some (unitless) variables for CAK force normalisation
143 subroutine set_cak_force_norm(rstar,twind)
145 use mod_constants
146
147 real(8), intent(in) :: rstar, twind
148
149 lum = 4.0d0*dpi * rstar**2.0d0 * const_sigma * twind**4.0d0
151 dclight = const_c/unit_velocity
152 dlum = lum/(unit_density * unit_length**5.0d0 / unit_time**3.0d0)
153 drstar = rstar/unit_length
154 tfloor = twind/unit_temperature
155
156 end subroutine set_cak_force_norm
157
158 !> w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
159 subroutine cak_add_source(qdt,ixI^L,ixO^L,wCT,w,x,energy,qsourcesplit,active)
161 use mod_comm_lib, only: mpistop
162
163 integer, intent(in) :: ixI^L, ixO^L
164 real(8), intent(in) :: qdt, x(ixI^S,1:ndim), wCT(ixI^S,1:nw)
165 real(8), intent(inout) :: w(ixI^S,1:nw)
166 logical, intent(in) :: energy, qsourcesplit
167 logical, intent(inout) :: active
168
169 ! Local variables
170 real(8) :: gl(ixO^S,1:3), ge(ixO^S), ptherm(ixI^S), pmin(ixI^S)
171 integer :: idir
172
173 ! By default add source in unsplit fashion together with the fluxes
174 if (qsourcesplit .eqv. cak_split) then
175
176 active = .true.
177
178 ! Thomson force
179 call get_gelectron(ixi^l,ixo^l,wct,x,ge)
180
181 ! CAK line force
182 gl(ixo^s,1:3) = 0.0d0
183
184 if (cak_1d_force) then
185 call get_cak_force_radial(ixi^l,ixo^l,wct,w,x,gl)
186 elseif (cak_vector_force) then
187 call get_cak_force_vector(ixi^l,ixo^l,wct,w,x,gl)
188 else
189 call mpistop("No valid force option")
190 endif
191
192 ! Update conservative vars: w = w + qdt*gsource
193 do idir = 1,ndir
194 if (idir == 1) gl(ixo^s,idir) = gl(ixo^s,idir) + ge(ixo^s)
195
196 w(ixo^s,iw_mom(idir)) = w(ixo^s,iw_mom(idir)) &
197 + qdt * gl(ixo^s,idir) * wct(ixo^s,iw_rho)
198
199 if (energy) then
200 w(ixo^s,iw_e) = w(ixo^s,iw_e) + qdt * gl(ixo^s,idir) * wct(ixo^s,iw_mom(idir))
201 endif
202 enddo
203
204 ! Impose fixed floor temperature to mimic stellar heating
205 if (energy) then
206 call phys_get_pthermal(w,x,ixi^l,ixo^l,ptherm)
207 pmin(ixo^s) = w(ixo^s,iw_rho) * tfloor
208
209 where (ptherm(ixo^s) < pmin(ixo^s))
210 w(ixo^s,iw_e) = w(ixo^s,iw_e) + (pmin(ixo^s) - ptherm(ixo^s))/(cak_gamma - 1.0d0)
211 endwhere
212 endif
213 endif
214
215 end subroutine cak_add_source
216
217 !> 1-D CAK line force in the Gayley line-ensemble distribution parametrisation
218 subroutine get_cak_force_radial(ixI^L,ixO^L,wCT,w,x,gcak)
220 use mod_comm_lib, only: mpistop
221
222 integer, intent(in) :: ixI^L, ixO^L
223 real(8), intent(in) :: wCT(ixI^S,1:nw), x(ixI^S,1:ndim)
224 real(8), intent(inout) :: w(ixI^S,1:nw)
225 real(8), intent(inout) :: gcak(ixO^S,1:3)
226
227 ! Local variables
228 real(8) :: vr(ixI^S), dvrdr(ixO^S)
229 real(8) :: beta_fd(ixO^S), fdfac(ixO^S), taus(ixO^S), ge(ixO^S)
230
231 vr(ixi^s) = wct(ixi^s,iw_mom(1)) / wct(ixi^s,iw_rho)
232 call get_velocity_gradient(ixi^l,ixo^l,vr,x,1,dvrdr)
233
234 if (physics_type == 'hd') then
235 ! Monotonic flow to avoid multiple resonances and radiative coupling
236 dvrdr(ixo^s) = abs(dvrdr(ixo^s))
237 else
238 ! Allow material to fallback to the star in a magnetosphere model
239 dvrdr(ixo^s) = max(dvrdr(ixo^s), smalldouble)
240 endif
241
242 ! Thomson force
243 call get_gelectron(ixi^l,ixo^l,wct,x,ge)
244
245 ! Sobolev optical depth for line ensemble (tau = Qbar * t_r) and the force
246 select case (cak_1d_opt)
247 case(radstream, fdisc)
248 taus(ixo^s) = gayley_qbar * dke * dclight * wct(ixo^s,iw_rho)/dvrdr(ixo^s)
249 gcak(ixo^s,1) = gayley_qbar/(1.0d0 - cak_alpha) &
250 * ge(ixo^s)/taus(ixo^s)**cak_alpha
251
252 case(fdisc_cutoff)
253 taus(ixo^s) = gayley_q0 * dke * dclight * wct(ixo^s,iw_rho)/dvrdr(ixo^s)
254 gcak(ixo^s,1) = gayley_qbar * ge(ixo^s) &
255 * ( (1.0d0 + taus(ixo^s))**(1.0d0 - cak_alpha) - 1.0d0 ) &
256 / ( (1.0d0 - cak_alpha) * taus(ixo^s) )
257 case default
258 call mpistop("Error in force computation.")
259 end select
260
261 ! Finite disk factor parameterisation (Owocki & Puls 1996)
262 beta_fd(ixo^s) = ( 1.0d0 - vr(ixo^s)/(x(ixo^s,1) * dvrdr(ixo^s)) ) &
263 * (drstar/x(ixo^s,1))**2.0d0
264
265 select case (cak_1d_opt)
266 case(radstream)
267 fdfac(ixo^s) = 1.0d0
268 case(fdisc, fdisc_cutoff)
269 where (beta_fd(ixo^s) >= 1.0d0)
270 fdfac(ixo^s) = 1.0d0/(1.0d0 + cak_alpha)
271 elsewhere (beta_fd(ixo^s) < -1.0d10)
272 fdfac(ixo^s) = abs(beta_fd(ixo^s))**cak_alpha / (1.0d0 + cak_alpha)
273 elsewhere (abs(beta_fd(ixo^s)) > 1.0d-3)
274 fdfac(ixo^s) = (1.0d0 - (1.0d0 - beta_fd(ixo^s))**(1.0d0 + cak_alpha)) &
275 / (beta_fd(ixo^s)*(1.0d0 + cak_alpha))
276 elsewhere
277 fdfac(ixo^s) = 1.0d0 - 0.5d0*cak_alpha*beta_fd(ixo^s) &
278 * (1.0d0 + 1.0d0/3.0d0 * (1.0d0 - cak_alpha)*beta_fd(ixo^s))
279 endwhere
280 end select
281
282 ! Correct radial line force for finite disc (if applicable)
283 gcak(ixo^s,1) = gcak(ixo^s,1) * fdfac(ixo^s)
284 gcak(ixo^s,2) = 0.0d0
285 gcak(ixo^s,3) = 0.0d0
286
287 ! Fill the nwextra slots for output
288 w(ixo^s,gcak1_) = gcak(ixo^s,1)
289 w(ixo^s,fdf_) = fdfac(ixo^s)
290
291 end subroutine get_cak_force_radial
292
293 !> Vector CAK line force in the Gayley line-ensemble distribution parametrisation
294 subroutine get_cak_force_vector(ixI^L,ixO^L,wCT,w,x,gcak)
297
298 ! Subroutine arguments
299 integer, intent(in) :: ixI^L, ixO^L
300 real(8), intent(in) :: wCT(ixI^S,1:nw), x(ixI^S,1:ndim)
301 real(8), intent(inout) :: w(ixI^S,1:nw)
302 real(8), intent(inout) :: gcak(ixO^S,1:3)
303
304 ! Local variables
305 real(8) :: a1, a2, a3, wyray, y, wpray, phiray, wtot, mustar, dvndn
306 real(8) :: costp, costp2, sintp, cospp, sinpp, cott0
307 real(8) :: vr(ixI^S), vt(ixI^S), vp(ixI^S)
308 real(8) :: vrr(ixI^S), vtr(ixI^S), vpr(ixI^S)
309 real(8) :: dvrdr(ixO^S), dvtdr(ixO^S), dvpdr(ixO^S)
310 real(8) :: dvrdt(ixO^S), dvtdt(ixO^S), dvpdt(ixO^S)
311 real(8) :: dvrdp(ixO^S), dvtdp(ixO^S), dvpdp(ixO^S)
312 integer :: ix^D, itray, ipray
313
314 ! Initialisation to have full velocity strain tensor expression at all times
315 vt(ixo^s) = 0.0d0; vtr(ixo^s) = 0.0d0
316 vp(ixo^s) = 0.0d0; vpr(ixo^s) = 0.0d0
317 cott0 = 0.0d0
318 dvrdr(ixo^s) = 0.0d0; dvtdr(ixo^s) = 0.0d0; dvpdr(ixo^s) = 0.0d0
319 dvrdt(ixo^s) = 0.0d0; dvtdt(ixo^s) = 0.0d0; dvpdt(ixo^s) = 0.0d0
320 dvrdp(ixo^s) = 0.0d0; dvtdp(ixo^s) = 0.0d0; dvpdp(ixo^s) = 0.0d0
321
322 ! Populate velocity field(s) depending on dimensions and directions
323 vr(ixi^s) = wct(ixi^s,iw_mom(1)) / wct(ixi^s,iw_rho)
324 vrr(ixi^s) = vr(ixi^s) / x(ixi^s,1)
325
326 {^nooned
327 vt(ixi^s) = wct(ixi^s,iw_mom(2)) / wct(ixi^s,iw_rho)
328 vtr(ixi^s) = vt(ixi^s) / x(ixi^s,1)
329
330 if (ndir > 2) then
331 vp(ixi^s) = wct(ixi^s,iw_mom(3)) / wct(ixi^s,iw_rho)
332 vpr(ixi^s) = vp(ixi^s) / x(ixi^s,1)
333 endif
334 }
335
336 ! Derivatives of velocity field in each coordinate direction (r=1,t=2,p=3)
337 call get_velocity_gradient(ixi^l,ixo^l,vr,x,1,dvrdr)
338
339 {^nooned
340 call get_velocity_gradient(ixi^l,ixo^l,vr,x,2,dvrdt)
341 call get_velocity_gradient(ixi^l,ixo^l,vt,x,1,dvtdr)
342 call get_velocity_gradient(ixi^l,ixo^l,vt,x,2,dvtdt)
343
344 if (ndir > 2) then
345 call get_velocity_gradient(ixi^l,ixo^l,vp,x,1,dvpdr)
346 call get_velocity_gradient(ixi^l,ixo^l,vp,x,2,dvpdt)
347 endif
348 }
349 {^ifthreed
350 call get_velocity_gradient(ixi^l,ixo^l,vr,x,3,dvrdp)
351 call get_velocity_gradient(ixi^l,ixo^l,vt,x,3,dvtdp)
352 call get_velocity_gradient(ixi^l,ixo^l,vp,x,3,dvpdp)
353 }
354
355 ! Get total acceleration from all rays at a certain grid point
356 {do ix^db=ixomin^db,ixomax^db\}
357 ! Loop over the rays; first theta then phi radiation angle
358 ! Get weights from current ray and their position
359 do itray = 1,nthetaray
360 wyray = wy(itray)
361 y = ay(itray)
362
363 do ipray = 1,nphiray
364 wpray = wphi(ipray)
365 phiray = aphi(ipray)
366
367 ! Redistribute the phi rays by a small offset
368 ! if (mod(itp,3) == 1) then
369 ! phip = phip + dphi/3.0d0
370 ! elseif (mod(itp,3) == 2) then
371 ! phip = phip - dphi/3.0d0
372 ! endif
373
374 ! === Geometrical factors ===
375 ! Make y quadrature linear in mu, not mu**2; better for gtheta,gphi
376 ! y -> mu quadrature is preserved; y=0 <=> mu=1; y=1 <=> mu=mustar
377 mustar = sqrt(max(1.0d0 - (drstar/x(ix^d,1))**2.0d0, 0.0d0))
378 costp = 1.0d0 - y*(1.0d0 - mustar)
379 costp2 = costp*costp
380 sintp = sqrt(max(1.0d0 - costp2, 0.0d0))
381 sinpp = sin(phiray)
382 cospp = cos(phiray)
383 {^nooned cott0 = cos(x(ix^d,2))/sin(x(ix^d,2))}
384
385 ! More weight close to star, less farther away
386 wtot = wyray * wpray * (1.0d0 - mustar)
387
388 ! Convenients a la Cranmer & Owocki (1995)
389 a1 = costp
390 a2 = sintp * cospp
391 a3 = sintp * sinpp
392
393 ! Get total velocity gradient for one ray with given (theta', phi')
394 dvndn = a1*a1 * dvrdr(ix^d) + a2*a2 * (dvtdt(ix^d) + vrr(ix^d)) &
395 + a3*a3 * (dvpdp(ix^d) + cott0 * vtr(ix^d) + vrr(ix^d)) &
396 + a1*a2 * (dvtdr(ix^d) + dvrdt(ix^d) - vtr(ix^d)) &
397 + a1*a3 * (dvpdr(ix^d) + dvrdp(ix^d) - vpr(ix^d)) &
398 + a2*a3 * (dvpdt(ix^d) + dvtdp(ix^d) - cott0 * vpr(ix^d))
399
400 ! No multiple resonances in CAK
401 dvndn = abs(dvndn)
402
403 ! Convert gradient back from wind coordinates (r',theta',phi') to
404 ! stellar coordinates (r,theta,phi)
405 gcak(ix^d,1) = gcak(ix^d,1) + (dvndn/wct(ix^d,iw_rho))**cak_alpha * a1 * wtot
406 gcak(ix^d,2) = gcak(ix^d,2) + (dvndn/wct(ix^d,iw_rho))**cak_alpha * a2 * wtot
407 gcak(ix^d,3) = gcak(ix^d,3) + (dvndn/wct(ix^d,iw_rho))**cak_alpha * a3 * wtot
408 enddo
409 enddo
410 {enddo\}
411
412 ! Normalisation for line force
413 ! NOTE: extra 1/pi factor comes from integration in radiation Phi angle
414 gcak(ixo^s,:) = (dke*gayley_qbar)**(1.0d0 - cak_alpha)/(1.0d0 - cak_alpha) &
415 * dlum/(4.0d0*dpi*drstar**2.0d0 * dclight**(1.0d0+cak_alpha)) &
416 * gcak(ixo^s,:)/dpi
417
418 if (fix_vector_force_1d) then
419 gcak(ixo^s,2) = 0.0d0
420 gcak(ixo^s,3) = 0.0d0
421 endif
422
423 ! Fill the nwextra slots for output
424 w(ixo^s,gcak1_) = gcak(ixo^s,1)
425 w(ixo^s,gcak2_) = gcak(ixo^s,2)
426 w(ixo^s,gcak3_) = gcak(ixo^s,3)
427
428 end subroutine get_cak_force_vector
429
430 !> Compute continuum radiation force from Thomson scattering
431 subroutine get_gelectron(ixI^L,ixO^L,w,x,ge)
433
434 integer, intent(in) :: ixI^L, ixO^L
435 real(8), intent(in) :: w(ixI^S,1:nw), x(ixI^S,1:ndim)
436 real(8), intent(out):: ge(ixO^S)
437
438 ge(ixo^s) = dke * dlum/(4.0d0*dpi * dclight * x(ixo^s,1)**2.0d0)
439
440 end subroutine get_gelectron
441
442 !> Check time step for total radiation contribution
443 subroutine cak_get_dt(w,ixI^L,ixO^L,dtnew,dx^D,x)
445
446 integer, intent(in) :: ixI^L, ixO^L
447 real(8), intent(in) :: dx^D, x(ixI^S,1:ndim)
448 real(8), intent(in) :: w(ixI^S,1:nw)
449 real(8), intent(inout) :: dtnew
450
451 ! Local variables
452 real(8) :: ge(ixO^S), max_gr, dt_cak
453
454 call get_gelectron(ixi^l,ixo^l,w,x,ge)
455
456 dtnew = bigdouble
457
458 ! Get dt from line force that is saved in the w-array in nwextra slot
459 max_gr = max( maxval(abs(ge(ixo^s) + w(ixo^s,gcak1_))), epsilon(1.0d0) )
460 dt_cak = minval( sqrt(block%dx(ixo^s,1)/max_gr) )
461 dtnew = min(dtnew, courantpar*dt_cak)
462
463 {^nooned
464 if (cak_vector_force) then
465 max_gr = max( maxval(abs(w(ixo^s,gcak2_))), epsilon(1.0d0) )
466 dt_cak = minval( sqrt(block%dx(ixo^s,1) * block%dx(ixo^s,2)/max_gr) )
467 dtnew = min(dtnew, courantpar*dt_cak)
468
469 {^ifthreed
470 max_gr = max( maxval(abs(w(ixo^s,gcak3_))), epsilon(1.0d0) )
471 dt_cak = minval( sqrt(block%dx(ixo^s,1) * sin(block%dx(ixo^s,3))/max_gr) )
472 dtnew = min(dtnew, courantpar*dt_cak)
473 }
474 endif
475 }
476
477 end subroutine cak_get_dt
478
479 !> Compute velocity gradient in direction 'idir' on a non-uniform grid
480 subroutine get_velocity_gradient(ixI^L,ixO^L,vfield,x,idir,grad_vn)
482
483 integer, intent(in) :: ixI^L, ixO^L, idir
484 real(8), intent(in) :: vfield(ixI^S), x(ixI^S,1:ndim)
485 real(8), intent(out) :: grad_vn(ixO^S)
486
487 ! Local variables
488 real(8) :: forw(ixO^S), backw(ixO^S), cent(ixO^S)
489 integer :: jrx^L, hrx^L{^NOONED,jtx^L, htx^L}{^IFTHREED,jpx^L, hpx^L}
490
491 ! Index +1 (j) and index -1 (h) in radial direction; kr(dir,dim)=1, dir=dim
492 jrx^l=ixo^l+kr(1,^d);
493 hrx^l=ixo^l-kr(1,^d);
494
495 {^nooned
496 ! Index +1 (j) and index -1 (h) in polar direction
497 jtx^l=ixo^l+kr(2,^d);
498 htx^l=ixo^l-kr(2,^d);
499 }
500
501 {^ifthreed
502 ! Index +1 (j) and index -1 (h) in azimuthal direction
503 jpx^l=ixo^l+kr(3,^d);
504 hpx^l=ixo^l-kr(3,^d);
505 }
506
507 ! grad(v.n) on non-uniform grid according to Sundqvist & Veronis (1970)
508 select case (idir)
509 case(1) ! Radial forward, backward, and central derivatives
510 forw(ixo^s) = (x(ixo^s,1) - x(hrx^s,1)) * vfield(jrx^s) &
511 / ((x(jrx^s,1) - x(ixo^s,1)) * (x(jrx^s,1) - x(hrx^s,1)))
512
513 backw(ixo^s) = -(x(jrx^s,1) - x(ixo^s,1)) * vfield(hrx^s) &
514 / ((x(ixo^s,1) - x(hrx^s,1)) * (x(jrx^s,1) - x(hrx^s,1)))
515
516 cent(ixo^s) = (x(jrx^s,1) + x(hrx^s,1) - 2.0d0*x(ixo^s,1)) * vfield(ixo^s) &
517 / ((x(ixo^s,1) - x(hrx^s,1)) * (x(jrx^s,1) - x(ixo^s,1)))
518 {^nooned
519 case(2) ! Polar forward, backward, and central derivatives
520 forw(ixo^s) = (x(ixo^s,2) - x(htx^s,2)) * vfield(jtx^s) &
521 / (x(ixo^s,1) * (x(jtx^s,2) - x(ixo^s,2)) * (x(jtx^s,2) - x(htx^s,2)))
522
523 backw(ixo^s) = -(x(jtx^s,2) - x(ixo^s,2)) * vfield(htx^s) &
524 / ( x(ixo^s,1) * (x(ixo^s,2) - x(htx^s,2)) * (x(jtx^s,2) - x(htx^s,2)))
525
526 cent(ixo^s) = (x(jtx^s,2) + x(htx^s,2) - 2.0d0*x(ixo^s,2)) * vfield(ixo^s) &
527 / ( x(ixo^s,1) * (x(ixo^s,2) - x(htx^s,2)) * (x(jtx^s,2) - x(ixo^s,2)))
528 }
529 {^ifthreed
530 case(3) ! Azimuthal forward, backward, and central derivatives
531 forw(ixo^s) = (x(ixo^s,3) - x(hpx^s,3)) * vfield(jpx^s) &
532 / ( 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)))
533
534 backw(ixo^s) = -(x(jpx^s,3) - x(ixo^s,3)) * vfield(hpx^s) &
535 / ( 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)))
536
537 cent(ixo^s) = (x(jpx^s,3) + x(hpx^s,3) - 2.0d0*x(ixo^s,3)) * vfield(ixo^s) &
538 / ( 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)))
539 }
540 end select
541
542 ! Total gradient for given velocity field
543 grad_vn(ixo^s) = backw(ixo^s) + cent(ixo^s) + forw(ixo^s)
544
545 end subroutine get_velocity_gradient
546
547 !> Initialise (theta',phi') radiation angles coming from stellar disc
548 subroutine rays_init(ntheta_point,nphi_point)
550
551 ! Subroutine arguments
552 integer, intent(in) :: ntheta_point, nphi_point
553
554 ! Local variables
555 real(8) :: ymin, ymax, phipmin, phipmax, adum
556 integer :: ii
557
558 ! Minimum and maximum range of theta and phi rays
559 ! NOTE: theta points are cast into y-space
560 ymin = 0.0d0
561 ymax = 1.0d0
562 phipmin = -dpi !0.0d0
563 phipmax = dpi !2.0d0*dpi
564 ! dphi = (phipmax - phipmin) / nphi_point
565
566 if (mype == 0) then
567 allocate(ay(ntheta_point))
568 allocate(wy(ntheta_point))
569 allocate(aphi(nphi_point))
570 allocate(wphi(nphi_point))
571
572 ! theta and phi ray positions and weights: Gauss-Legendre
573 call gauss_legendre_quadrature(ymin,ymax,ntheta_point,ay,wy)
574 call gauss_legendre_quadrature(phipmin,phipmax,nphi_point,aphi,wphi)
575
576 ! theta rays and weights: uniform
577 ! dth = 1.0d0 / nthetap
578 ! adum = ymin + 0.5d0*dth
579 ! do ip = 1,nthetap
580 ! ay(ip) = adum
581 ! wy(ip) = 1.0d0/nthetap
582 ! adum = adum + dth
583 ! !print*,'phipoints'
584 ! !print*,ip,aphi(ip),wphi(ip),dphi
585 ! enddo
586
587 ! phi ray position and weights: uniform
588 ! adum = phipmin + 0.5d0*dphi
589 ! do ii = 1,nphi_point
590 ! aphi(ii) = adum
591 ! wphi(ii) = 1.0d0/nphi_point
592 ! adum = adum + dphi
593 ! enddo
594
595 print*, '==========================='
596 print*, ' Radiation ray setup '
597 print*, '==========================='
598 print*, 'Theta ray points + weights '
599 do ii = 1,ntheta_point
600 print*,ii,ay(ii),wy(ii)
601 enddo
602 print*
603 print*, 'Phi ray points + weights '
604 do ii = 1,nphi_point
605 print*,ii,aphi(ii),wphi(ii)
606 enddo
607 print*
608 endif
609
610 call mpi_barrier(icomm,ierrmpi)
611
612 !===========================
613 ! Broadcast what mype=0 read
614 !===========================
615 if (npe > 1) then
616 call mpi_bcast(ntheta_point,1,mpi_integer,0,icomm,ierrmpi)
617 call mpi_bcast(nphi_point,1,mpi_integer,0,icomm,ierrmpi)
618
619 if (mype /= 0) then
620 allocate(ay(ntheta_point))
621 allocate(wy(ntheta_point))
622 allocate(aphi(nphi_point))
623 allocate(wphi(nphi_point))
624 endif
625
626 call mpi_bcast(ay,ntheta_point,mpi_double_precision,0,icomm,ierrmpi)
627 call mpi_bcast(wy,ntheta_point,mpi_double_precision,0,icomm,ierrmpi)
628 call mpi_bcast(aphi,nphi_point,mpi_double_precision,0,icomm,ierrmpi)
629 call mpi_bcast(wphi,nphi_point,mpi_double_precision,0,icomm,ierrmpi)
630 endif
631
632 end subroutine rays_init
633
634 !> Fast Gauss-Legendre N-point quadrature algorithm by G. Rybicki
635 subroutine gauss_legendre_quadrature(xlow,xhi,n,x,w)
636 ! Given the lower and upper limits of integration xlow and xhi, and given n,
637 ! this routine returns arrays x and w of length n, containing the abscissas
638 ! and weights of the Gauss-Legendre N-point quadrature
640
641 ! Subroutine arguments
642 real(8), intent(in) :: xlow, xhi
643 integer, intent(in) :: n
644 real(8), intent(out) :: x(n), w(n)
645
646 ! Local variables
647 real(8) :: p1, p2, p3, pp, xl, xm, z, z1
648 real(8), parameter :: error=3.0d-14
649 integer :: i, j, m
650
651 m = (n + 1)/2
652 xm = 0.5d0*(xhi + xlow)
653 xl = 0.5d0*(xhi - xlow)
654
655 do i = 1,m
656 z = cos( dpi * (i - 0.25d0)/(n + 0.5d0) )
657 z1 = 2.0d0 * z
658
659 do while (abs(z1 - z) > error)
660 p1 = 1.0d0
661 p2 = 0.0d0
662
663 do j = 1,n
664 p3 = p2
665 p2 = p1
666 p1 = ( (2.0d0*j - 1.0d0)*z*p2 - (j - 1.0d0)*p3 )/j
667 enddo
668
669 pp = n*(z*p1 - p2) / (z*z - 1.0d0)
670 z1 = z
671 z = z1 - p1/pp
672 enddo
673
674 x(i) = xm - xl*z
675 x(n+1-i) = xm + xl*z
676 w(i) = 2.0d0*xl / ((1.0d0 - z*z) * pp*pp)
677 w(n+1-i) = w(i)
678 enddo
679
680 end subroutine gauss_legendre_quadrature
681
682end module mod_cak_force
Module to include CAK radiation line force in (magneto)hydrodynamic models Computes both the force fr...
real(8), public gayley_qbar
subroutine cak_get_dt(w, ixil, ixol, dtnew, dxd, x)
Check time step for total radiation contribution.
real(8), public gayley_q0
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 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
subroutine, public set_cak_force_norm(rstar, twind)
Compute some (unitless) variables for CAK force normalisation.
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 get_velocity_gradient(ixil, ixol, vfield, x, idir, grad_vn)
Compute velocity gradient in direction 'idir' on a non-uniform grid.
integer cak_1d_opt
Switch to choose between the 1-D CAK line force options.
subroutine get_cak_force_radial(ixil, ixol, wct, w, x, gcak)
1-D CAK line force in the Gayley line-ensemble distribution parametrisation
subroutine get_gelectron(ixil, ixol, w, x, ge)
Compute continuum radiation force from Thomson scattering.
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.
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
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.
double precision, 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...
Definition mod_physics.t:4
procedure(sub_get_pthermal), pointer phys_get_pthermal
Definition mod_physics.t:74
character(len=name_len) physics_type
String describing the physics type of the simulation.
Definition mod_physics.t:52
Module with all the methods that users can customize in AMRVAC.