MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
mod_gravity.t
Go to the documentation of this file.
1!> Module for including gravity in (magneto)hydrodynamics simulations
3 implicit none
4
5 !> source split or not
6 logical :: grav_split= .false.
7
8contains
9 !> Read this module's parameters from a file
10 subroutine grav_params_read(files)
12 character(len=*), intent(in) :: files(:)
13 integer :: n
14
15 namelist /grav_list/ grav_split
16
17 do n = 1, size(files)
18 open(unitpar, file=trim(files(n)), status="old")
19 read(unitpar, grav_list, end=111)
20111 close(unitpar)
21 end do
22 end subroutine grav_params_read
23
24 !> Initialize the module
25 subroutine gravity_init()
28 use mod_comm_lib, only: mpistop
29 integer :: nwx,idir
30
31 if (.not. associated(usr_gravity)) then
32 write(*,*) "mod_usr.t: please define usr_gravity before (m)hd activate"
33 write(*,*) "like the phys_gravity in mod_usr_methods.t"
34 call mpistop("usr_gravity not defined or pointed")
35 end if
38 end subroutine gravity_init
39
40 !> w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
41 subroutine gravity_add_source(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x,&
42 energy,qsourcesplit,active)
45 use mod_comm_lib, only: mpistop
46 integer, intent(in) :: ixI^L, ixO^L
47 double precision, intent(in) :: qdt, x(ixI^S,1:ndim)
48 double precision, intent(in) :: wCT(ixI^S,1:nw),wCTprim(ixI^S,1:nw)
49 double precision, intent(inout) :: w(ixI^S,1:nw)
50 logical, intent(in) :: energy,qsourcesplit
51 logical, intent(inout) :: active
52
53 double precision :: gravity_field(ixI^S,ndim)
54 integer :: ix^D
55
56 if(qsourcesplit .eqv. grav_split) then
57 active = .true.
58 call usr_gravity(ixi^l,ixo^l,wct,x,gravity_field)
59 if(size(iw_mom)<ndim) then
60 {do ix^db=ixomin^db,ixomax^db\}
61 w(ix^d,iw_mom(1)) = w(ix^d,iw_mom(1)) &
62 + qdt*wct(ix^d,iw_rho)*(^d&gravity_field({ix^d},^d)*block%B0({ix^d},^d,0)+)
63 if(energy) then
64 w(ix^d,iw_e)=w(ix^d,iw_e) &
65 +qdt*wct(ix^d,iw_mom(1))*(^d&gravity_field({ix^d},^d)*block%B0({ix^d},^d,0)+)
66 end if
67 {end do\}
68 else
69 {do ix^db=ixomin^db,ixomax^db\}
70 ^d&w({ix^d},iw_mom(^d))=w({ix^d},iw_mom(^d))+qdt*gravity_field({ix^d},^d)*wct({ix^d},iw_rho)\
71 if(energy) then
72 w(ix^d,iw_e)=w(ix^d,iw_e) &
73 +qdt*wctprim(ix^d,iw_rho)*(^d&gravity_field({ix^d},^d)*wctprim({ix^d},iw_mom(^d))+)
74 end if
75 {end do\}
76 end if
77 end if
78 end subroutine gravity_add_source
79
80 subroutine gravity_get_dt(w,ixI^L,ixO^L,dtnew,dx^D,x)
83 use mod_geometry
84
85 integer, intent(in) :: ixI^L, ixO^L
86 double precision, intent(in) :: dx^D, x(ixI^S,1:ndim), w(ixI^S,1:nw)
87 double precision, intent(inout) :: dtnew
88
89 double precision :: dxinv(1:ndim), max_grav
90 double precision :: gravity_field(ixI^S,ndim)
91 integer :: idim
92
93 call usr_gravity(ixi^l,ixo^l,w,x,gravity_field)
94 if(slab_uniform) then
95 ^d&dxinv(^d)=one/dx^d;
96 do idim = 1, ndim
97 max_grav = maxval(abs(gravity_field(ixo^s,idim)))
98 max_grav = max(max_grav, epsilon(1.0d0))
99 dtnew = min(dtnew, 1.0d0 / sqrt(max_grav * dxinv(idim)))
100 end do
101 else
102 do idim = 1, ndim
103 max_grav = maxval(abs(gravity_field(ixo^s,idim))/block%ds(ixo^s,idim))
104 max_grav = max(max_grav, epsilon(1.0d0))
105 dtnew = min(dtnew, 1.0d0 / sqrt(max_grav))
106 end do
107 endif
108 end subroutine gravity_get_dt
109end module mod_gravity
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
Module with geometry-related routines (e.g., divergence, curl)
Definition mod_geometry.t:2
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.
integer, parameter unitpar
file handle for IO
logical any_source_split
if any normal source term is added in split fasion
character(len=std_len), dimension(:), allocatable par_files
Which par files are used as input.
logical slab_uniform
uniform Cartesian geometry or not (stretched Cartesian)
Module for including gravity in (magneto)hydrodynamics simulations.
Definition mod_gravity.t:2
logical grav_split
source split or not
Definition mod_gravity.t:6
subroutine gravity_get_dt(w, ixil, ixol, dtnew, dxd, x)
Definition mod_gravity.t:81
subroutine grav_params_read(files)
Read this module's parameters from a file.
Definition mod_gravity.t:11
subroutine gravity_init()
Initialize the module.
Definition mod_gravity.t:26
subroutine gravity_add_source(qdt, ixil, ixol, wct, wctprim, w, x, energy, qsourcesplit, active)
w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
Definition mod_gravity.t:43
Module with all the methods that users can customize in AMRVAC.
procedure(phys_gravity), pointer usr_gravity