11 integer,
parameter :: fastRW_ = 3,fastlw_=4,slowrw_=5,slowlw_=6
12 integer,
parameter :: entroW_ = 8,diverw_=7,alfvrw_=1,alfvlw_=2
32 case(fastrw_,fastlw_,slowrw_,slowlw_)
49 subroutine mhd_average(wL,wR,x,ix^L,idim,wroe,workroe)
52 integer,
intent(in) :: ix^
l, idim
53 double precision,
intent(in) :: wl(ixg^t, nw), wr(ixg^t, nw)
54 double precision,
intent(inout) :: wroe(ixg^t, nw)
55 double precision,
intent(inout) :: workroe(ixg^t,
nworkroe)
56 double precision,
intent(in) :: x(ixg^t, 1:^nd)
58 call average2(wl,wr,x,ix^
l,idim,wroe,workroe(ixg^t,1),workroe(ixg^t,2), &
59 workroe(ixg^t,3),workroe(ixg^t,4),workroe(ixg^t,5),workroe(ixg^t,6), &
60 workroe(ixg^t,7),workroe(ixg^t,8))
62 end subroutine mhd_average
70 subroutine average2(wL,wR,x,ix^L,idim,wroe,cfast,cslow,afast,aslow,csound2,dp, &
75 integer :: ix^
l,idim,idir,jdir,iw
76 double precision,
dimension(ixG^T,nw) :: wl,wr,wroe
77 double precision,
intent(in) :: x(ixg^t,1:
ndim)
78 double precision,
dimension(ixG^T) :: cfast,cslow,afast,aslow,csound2,dp, &
81 if (
ndir==1)
call mpistop(
"MHD with d=11 is the same as HD")
86 wroe(ix^s,
mom(idir))=half*(wl(ix^s,
mom(idir))/wl(ix^s,
rho_)+wr(ix^s,
mom(idir))/wr(ix^s,
rho_))
87 wroe(ix^s,
mag(idir))=half*(wl(ix^s,
mag(idir))+wr(ix^s,
mag(idir)))
90 call eos%get_thermal_pressure(wl,x,ixg^
ll,ix^
l,afast)
91 call eos%get_thermal_pressure(wr,x,ixg^
ll,ix^
l,aslow)
94 wroe(ix^s,
e_)=half*(afast(ix^s)+aslow(ix^s))
96 dp(ix^s)=aslow(ix^s)-afast(ix^s)
98 dp(ix^s)=aslow(ix^s)-afast(ix^s)
102 rhodv(ix^s)=wr(ix^s,
mom(idim))-wl(ix^s,
mom(idim))-&
109 call eos%get_csound2(wroe, x, ixg^
ll, ix^
l, csound2)
111 csound2(ix^s)=eos%gamma*
mhd_adiab*wroe(ix^s,
rho_)**(eos%gamma-one)
115 cfast(ix^s)=sum(wroe(ix^s,
mag(:))**2,dim=
ndim+1)/wroe(ix^s,
rho_)+csound2(ix^s)
118 cslow(ix^s)=half*(cfast(ix^s)-dsqrt(cfast(ix^s)**2-&
119 4d0*csound2(ix^s)*wroe(ix^s,
mag(idim))**2/wroe(ix^s,
rho_)))
122 cfast(ix^s)=cfast(ix^s)-cslow(ix^s)
125 afast(ix^s)=(csound2(ix^s)-cslow(ix^s))/(cfast(ix^s)-cslow(ix^s))
126 afast(ix^s)=min(one,max(afast(ix^s),zero))
129 aslow(ix^s)=dsqrt(one-afast(ix^s))
132 afast(ix^s)=dsqrt(afast(ix^s))
135 cfast(ix^s)=dsqrt(cfast(ix^s))
138 cslow(ix^s)=dsqrt(cslow(ix^s))
142 wroe(ix^s,
rho_)=dsqrt(wroe(ix^s,
rho_))
145 where(dabs(wroe(ix^s,
mag(idim)))<smalldouble)&
146 wroe(ix^s,
mag(idim))=smalldouble
150 where(wroe(ix^s,
mag(idir))>=zero)
151 wroe(ix^s,
mag(idir))=one
153 wroe(ix^s,
mag(idir))=-one
158 tmp(ix^s)=dsqrt(wroe(ix^s,
mag(idir))**2+wroe(ix^s,
mag(jdir))**2)
159 where(tmp(ix^s)>smalldouble)
160 wroe(ix^s,
mag(idir))=wroe(ix^s,
mag(idir))/tmp(ix^s)
161 wroe(ix^s,
mag(jdir))=wroe(ix^s,
mag(jdir))/tmp(ix^s)
163 wroe(ix^s,
mag(idir))=dsqrt(half)
164 wroe(ix^s,
mag(jdir))=dsqrt(half)
168 end subroutine average2
180 subroutine mhd_get_eigenjump(wL,wR,wroe,x,ix^L,il,idim,smalla,a,jump,workroe)
183 integer,
intent(in) :: ix^
l,il,idim
184 double precision,
dimension(ixG^T,nw) :: wl,wr,wroe
185 double precision,
intent(in) :: x(ixg^t,1:
ndim)
186 double precision,
dimension(ixG^T) :: smalla,a,jump
187 double precision,
dimension(ixG^T,nworkroe) :: workroe
189 call geteigenjump2(wl,wr,wroe,x,ix^
l,il,idim,smalla,a,jump, &
190 workroe(ixg^t,1),workroe(ixg^t,2), &
191 workroe(ixg^t,3),workroe(ixg^t,4),workroe(ixg^t,5),workroe(ixg^t,6), &
192 workroe(ixg^t,7),workroe(ixg^t,8),workroe(ixg^t,9),workroe(ixg^t,10), &
193 workroe(ixg^t,11),workroe(ixg^t,12),workroe(ixg^t,13))
195 end subroutine mhd_get_eigenjump
207 subroutine geteigenjump2(wL,wR,wroe,x,ix^L,il,idim,smalla,a,jump, &
208 cfast,cslow,afast,aslow,csound2,dp,rhodv,bdv,bdb,cs2L,cs2R,cs2ca2L,cs2ca2R)
212 integer :: ix^
l,il,idim,idir,jdir
213 double precision,
dimension(ixG^T,nw) :: wl,wr,wroe
214 double precision,
intent(in) :: x(ixg^t,1:
ndim)
215 double precision,
dimension(ixG^T) :: smalla,a,jump
216 double precision,
dimension(ixG^T) :: cfast,cslow,afast,aslow,csound2,dp,rhodv
217 double precision,
dimension(ixG^T) :: bdv,bdb
218 double precision,
dimension(ixG^T) :: al,ar,cs2l,cs2r,cs2ca2l,cs2ca2r
226 bdv(ix^s)=wroe(ix^s,
mag(idir))* &
227 (wr(ix^s,
mom(idir))/wr(ix^s,
rho_)-wl(ix^s,
mom(idir))/wl(ix^s,
rho_))
228 if(
ndir==3)bdv(ix^s)=bdv(ix^s)+wroe(ix^s,
mag(jdir))* &
229 (wr(ix^s,
mom(jdir))/wr(ix^s,
rho_)-wl(ix^s,
mom(jdir))/wl(ix^s,
rho_))
230 bdv(ix^s)=bdv(ix^s)*sign(wroe(ix^s,
rho_)**2,wroe(ix^s,
mag(idim)))
232 bdb(ix^s)=wroe(ix^s,
mag(idir))*(wr(ix^s,
mag(idir))-wl(ix^s,
mag(idir)))
233 if(
ndir==3)bdb(ix^s)=bdb(ix^s)+&
234 wroe(ix^s,
mag(jdir))*(wr(ix^s,
mag(jdir))-wl(ix^s,
mag(jdir)))
235 bdb(ix^s)=bdb(ix^s)*dsqrt(csound2(ix^s))*wroe(ix^s,
rho_)
241 bdv(ix^s)=wroe(ix^s,
mag(jdir))* &
242 (wr(ix^s,
mom(idir))/wr(ix^s,
rho_)-wl(ix^s,
mom(idir))/wl(ix^s,
rho_)) &
243 -wroe(ix^s,
mag(idir))* &
244 (wr(ix^s,
mom(jdir))/wr(ix^s,
rho_)-wl(ix^s,
mom(jdir))/wl(ix^s,
rho_))
245 bdb(ix^s)=wroe(ix^s,
mag(jdir))*(wr(ix^s,
mag(idir))-wl(ix^s,
mag(idir))) &
246 -wroe(ix^s,
mag(idir))*(wr(ix^s,
mag(jdir))-wl(ix^s,
mag(jdir)))
247 bdv(ix^s)=bdv(ix^s)*half*wroe(ix^s,
rho_)**2
248 bdb(ix^s)=bdb(ix^s)*half*sign(wroe(ix^s,
rho_),wroe(ix^s,
mag(idim)))
253 a(ix^s)=wroe(ix^s,
mom(idim))+cfast(ix^s)
254 jump(ix^s)=half/csound2(ix^s)*(&
255 afast(ix^s)*(+cfast(ix^s)*rhodv(ix^s)+dp(ix^s))&
256 +aslow(ix^s)*(-cslow(ix^s)*bdv(ix^s)+bdb(ix^s)))
258 a(ix^s)=wroe(ix^s,
mom(idim))-cfast(ix^s)
259 jump(ix^s)=half/csound2(ix^s)*(&
260 afast(ix^s)*(-cfast(ix^s)*rhodv(ix^s)+dp(ix^s))&
261 +aslow(ix^s)*(+cslow(ix^s)*bdv(ix^s)+bdb(ix^s)))
263 a(ix^s)=wroe(ix^s,
mom(idim))+cslow(ix^s)
264 jump(ix^s)=half/csound2(ix^s)*(&
265 aslow(ix^s)*(+cslow(ix^s)*rhodv(ix^s)+dp(ix^s))&
266 +afast(ix^s)*(+cfast(ix^s)*bdv(ix^s)-bdb(ix^s)))
268 a(ix^s)=wroe(ix^s,
mom(idim))-cslow(ix^s)
269 jump(ix^s)=half/csound2(ix^s)*(&
270 aslow(ix^s)*(-cslow(ix^s)*rhodv(ix^s)+dp(ix^s))&
271 +afast(ix^s)*(-cfast(ix^s)*bdv(ix^s)-bdb(ix^s)))
273 a(ix^s)=wroe(ix^s,
mom(idim))
274 jump(ix^s)=wr(ix^s,
rho_)-wl(ix^s,
rho_)-dp(ix^s)/csound2(ix^s)
277 a(ix^s)=wroe(ix^s,
mom(idim))
278 jump(ix^s)=wr(ix^s,
mag(idim))-wl(ix^s,
mag(idim))
284 a(ix^s)=wroe(ix^s,
mom(idim))+dabs(wroe(ix^s,
mag(idim)))/wroe(ix^s,
rho_)
285 jump(ix^s)=+bdv(ix^s)-bdb(ix^s)
287 a(ix^s)=wroe(ix^s,
mom(idim))-dabs(wroe(ix^s,
mag(idim)))/wroe(ix^s,
rho_)
288 jump(ix^s)=-bdv(ix^s)-bdb(ix^s)
297 case(
'harten',
'powell',
'ratio')
300 al(ix^s)= wl(ix^s,
mom(idim))/wl(ix^s,
rho_)
301 ar(ix^s)= wr(ix^s,
mom(idim))/wr(ix^s,
rho_)
307 call eos%get_thermal_pressure(wl,x,ixg^
ll,ix^
l,cs2l)
308 cs2l(ix^s)=eos%gamma*cs2l(ix^s)/wl(ix^s,
rho_)
309 call eos%get_thermal_pressure(wr,x,ixg^
ll,ix^
l,cs2r)
310 cs2r(ix^s)=eos%gamma*cs2r(ix^s)/wr(ix^s,
rho_)
311 cs2ca2l(ix^s)=cs2l(ix^s)+sum(wl(ix^s,
mag(:))**2,dim=
ndim+1)/wl(ix^s,
rho_)
312 cs2ca2r(ix^s)=cs2r(ix^s)+sum(wr(ix^s,
mag(:))**2,dim=
ndim+1)/wr(ix^s,
rho_)
315 dsqrt(cs2ca2l(ix^s)**2-4d0*cs2l(ix^s)*wl(ix^s,
mag(idim))**2/wl(ix^s,
rho_))
317 dsqrt(cs2ca2r(ix^s)**2-4d0*cs2r(ix^s)*wr(ix^s,
mag(idim))**2/wr(ix^s,
rho_))
320 al(ix^s)=al(ix^s) + dsqrt(half*(cs2ca2l(ix^s) + cs2l(ix^s)))
321 ar(ix^s)=ar(ix^s) + dsqrt(half*(cs2ca2r(ix^s) + cs2r(ix^s)))
323 al(ix^s)=al(ix^s) - dsqrt(half*(cs2ca2l(ix^s) + cs2l(ix^s)))
324 ar(ix^s)=ar(ix^s) - dsqrt(half*(cs2ca2r(ix^s) + cs2r(ix^s)))
326 al(ix^s)=al(ix^s) + dsqrt(half*(cs2ca2l(ix^s) - cs2l(ix^s)))
327 ar(ix^s)=ar(ix^s) + dsqrt(half*(cs2ca2r(ix^s) - cs2r(ix^s)))
329 al(ix^s)=al(ix^s) - dsqrt(half*(cs2ca2l(ix^s) - cs2l(ix^s)))
330 ar(ix^s)=ar(ix^s) - dsqrt(half*(cs2ca2r(ix^s) - cs2r(ix^s)))
331 case(entrow_,diverw_)
335 cs2ca2l(ix^s)=dabs(wl(ix^s,
mag(idim)))/dsqrt(wl(ix^s,
rho_))
336 cs2ca2r(ix^s)=dabs(wr(ix^s,
mag(idim)))/dsqrt(wr(ix^s,
rho_))
338 al(ix^s)=al(ix^s) + cs2ca2l(ix^s)
339 ar(ix^s)=ar(ix^s) + cs2ca2r(ix^s)
341 al(ix^s)=al(ix^s) - cs2ca2l(ix^s)
342 ar(ix^s)=ar(ix^s) - cs2ca2r(ix^s)
348 end subroutine geteigenjump2
351 subroutine mhd_rtimes(q,w,ix^L,iw,il,idim,rq,workroe)
354 integer,
intent(in) :: ix^
l, iw, il, idim
355 double precision,
intent(in) :: w(ixg^t, nw), q(ixg^t)
356 double precision,
intent(inout) :: rq(ixg^t)
357 double precision,
intent(inout) :: workroe(ixg^t,
nworkroe)
359 call rtimes2(q,w,ix^
l,iw,il,idim,rq,&
360 workroe(ixg^t,1),workroe(ixg^t,2), &
361 workroe(ixg^t,3),workroe(ixg^t,4),workroe(ixg^t,5),workroe(ixg^t,6), &
362 workroe(ixg^t,7),workroe(ixg^t,14),workroe(ixg^t,15))
364 end subroutine mhd_rtimes
367 subroutine rtimes2(q,wroe,ix^L,iw,il,idim,rq, &
368 cfast,cslow,afast,aslow,csound2,dp,rhodv,bv,v2a2)
371 integer :: ix^
l,iw,il,idim,idir,jdir
372 double precision :: wroe(ixg^t,nw)
373 double precision,
dimension(ixG^T) :: q,rq
374 double precision,
dimension(ixG^T) :: cfast,cslow,afast,aslow,csound2,dp,rhodv
375 double precision,
dimension(ixG^T) :: bv,v2a2
382 case(fastrw_,fastlw_)
383 rq(ix^s)=q(ix^s)*afast(ix^s)
384 case(slowrw_,slowlw_)
385 rq(ix^s)=q(ix^s)*aslow(ix^s)
388 case(diverw_,alfvrw_,alfvlw_)
391 else if(iw ==
e_)
then
394 v2a2(ix^s)=half*sum(wroe(ix^s,
mom(:))**2,dim=
ndim+1)+ &
395 (two-eos%gamma)/(eos%gamma-one)*csound2(ix^s)
397 bv(ix^s)=wroe(ix^s,
mag(idir))*wroe(ix^s,
mom(idir))
398 if(
ndir==3)bv(ix^s)=bv(ix^s)+wroe(ix^s,
mag(jdir))*wroe(ix^s,
mom(jdir))
399 bv(ix^s)=bv(ix^s)*sign(one,wroe(ix^s,
mag(idim)))
400 else if(il==alfvrw_)
then
402 bv(ix^s)=(wroe(ix^s,
mag(jdir))*wroe(ix^s,
mom(idir))-&
403 wroe(ix^s,
mag(idir))*wroe(ix^s,
mom(jdir)))
408 rq(ix^s)=q(ix^s)*(-aslow(ix^s)*cslow(ix^s)*bv(ix^s)+afast(ix^s)*&
409 (v2a2(ix^s)+cfast(ix^s)*(cfast(ix^s)+wroe(ix^s,
mom(idim)))))
411 rq(ix^s)=q(ix^s)*(+aslow(ix^s)*cslow(ix^s)*bv(ix^s)+afast(ix^s)*&
412 (v2a2(ix^s)+cfast(ix^s)*(cfast(ix^s)-wroe(ix^s,
mom(idim)))))
414 rq(ix^s)=q(ix^s)*(+afast(ix^s)*cfast(ix^s)*bv(ix^s)+aslow(ix^s)*&
415 (v2a2(ix^s)+cslow(ix^s)*(cslow(ix^s)+wroe(ix^s,
mom(idim)))))
417 rq(ix^s)=q(ix^s)*(-afast(ix^s)*cfast(ix^s)*bv(ix^s)+aslow(ix^s)*&
418 (v2a2(ix^s)+cslow(ix^s)*(cslow(ix^s)-wroe(ix^s,
mom(idim)))))
420 rq(ix^s)= q(ix^s)*half*sum(wroe(ix^s,
mom(:))**2,dim=
ndim+1)
423 rq(ix^s)= q(ix^s)*wroe(ix^s,
mag(idim))
428 rq(ix^s)=+q(ix^s)*bv(ix^s)
430 rq(ix^s)=-q(ix^s)*bv(ix^s)
432 else if(any(
mom(:)==iw))
then
433 if(iw==
mom(idim))
then
436 rq(ix^s)=q(ix^s)*afast(ix^s)*(wroe(ix^s,iw)+cfast(ix^s))
438 rq(ix^s)=q(ix^s)*afast(ix^s)*(wroe(ix^s,iw)-cfast(ix^s))
440 rq(ix^s)=q(ix^s)*aslow(ix^s)*(wroe(ix^s,iw)+cslow(ix^s))
442 rq(ix^s)=q(ix^s)*aslow(ix^s)*(wroe(ix^s,iw)-cslow(ix^s))
444 rq(ix^s)=q(ix^s)*wroe(ix^s,iw)
445 case(diverw_,alfvlw_,alfvrw_)
451 rq(ix^s)=q(ix^s)*(afast(ix^s)*wroe(ix^s,iw)-aslow(ix^s)*&
452 cslow(ix^s)*wroe(ix^s,
mag(1)-
mom(1)+iw)*sign(one,wroe(ix^s,
mag(idim))))
454 rq(ix^s)=q(ix^s)*(afast(ix^s)*wroe(ix^s,iw)+aslow(ix^s)*&
455 cslow(ix^s)*wroe(ix^s,
mag(1)-
mom(1)+iw)*sign(one,wroe(ix^s,
mag(idim))))
457 rq(ix^s)=q(ix^s)*(aslow(ix^s)*wroe(ix^s,iw)+afast(ix^s)*&
458 cfast(ix^s)*wroe(ix^s,
mag(1)-
mom(1)+iw)*sign(one,wroe(ix^s,
mag(idim))))
460 rq(ix^s)=q(ix^s)*(aslow(ix^s)*wroe(ix^s,iw)-afast(ix^s)*&
461 cfast(ix^s)*wroe(ix^s,
mag(1)-
mom(1)+iw)*sign(one,wroe(ix^s,
mag(idim))))
463 rq(ix^s)=q(ix^s)*wroe(ix^s,iw)
467 if(iw==
mom(idir))
then
468 rq(ix^s)=+q(ix^s)*wroe(ix^s,
mag(jdir))
470 rq(ix^s)=-q(ix^s)*wroe(ix^s,
mag(idir))
473 if(iw==
mom(idir))
then
474 rq(ix^s)=-q(ix^s)*wroe(ix^s,
mag(jdir))
476 rq(ix^s)=+q(ix^s)*wroe(ix^s,
mag(idir))
480 else if(any(
mag(:)==iw))
then
481 if(iw==
mag(idim))
then
489 case(fastrw_,fastlw_)
490 rq(ix^s)=+q(ix^s)*aslow(ix^s)*dsqrt(csound2(ix^s))*wroe(ix^s,iw)&
492 case(slowrw_,slowlw_)
493 rq(ix^s)=-q(ix^s)*afast(ix^s)*dsqrt(csound2(ix^s))*wroe(ix^s,iw)&
495 case(entrow_,diverw_)
497 case(alfvrw_,alfvlw_)
498 if(iw==
mag(idir))
then
499 rq(ix^s)=-q(ix^s)*wroe(ix^s,
mag(jdir))&
500 /sign(wroe(ix^s,
rho_),wroe(ix^s,
mag(idim)))
502 rq(ix^s)=+q(ix^s)*wroe(ix^s,
mag(idir))&
503 /sign(wroe(ix^s,
rho_),wroe(ix^s,
mag(idim)))
509 end subroutine rtimes2
Equation of state for AMRVAC, handled through a single eos_container object.
integer, dimension(:), allocatable, public mag
Indices of the magnetic field.
This module contains definitions of global parameters and variables and some generic functions/subrou...
character(len=std_len), dimension(:), allocatable typeentropy
Which type of entropy fix to use with Riemann-type solvers.
integer, parameter ndim
Number of spatial dimensions for grid variables.
integer ndir
Number of spatial dimensions (components) for vector variables.
double precision, dimension(:), allocatable entropycoef
Magneto-hydrodynamics module.
integer, dimension(:), allocatable, public, protected mom
Indices of the momentum density.
double precision, public mhd_adiab
The adiabatic constant.
logical, public, protected mhd_energy
Whether an energy equation is used.
logical, public divbwave
Add divB wave in Roe solver.
integer, public, protected rho_
Index of the density (in the w array)
integer, public, protected e_
Index of the energy density (-1 if not present)
Subroutines for Roe-type Riemann solver for MHD.
subroutine, public mhd_roe_init()
procedure(sub_rtimes), pointer phys_rtimes
procedure(sub_get_eigenjump), pointer phys_get_eigenjump
procedure(sub_average), pointer phys_average
Subroutines for TVD-MUSCL schemes.
subroutine, public entropyfix(ixl, il, al, ar, a, smalla)
integer nw
Total number of variables.