MPI-AMRVAC  3.1
The MPI - Adaptive Mesh Refinement - Versatile Advection Code
mod_gravity.t
Go to the documentation of this file.
1 !> Module for including gravity in (magneto)hydrodynamics simulations
2 module mod_gravity
3  implicit none
4 
5  !> source split or not
6  logical :: grav_split= .false.
7 
8 contains
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)
20 111 close(unitpar)
21  end do
22 
23  end subroutine grav_params_read
24 
25  !> Initialize the module
26  subroutine gravity_init()
28  use mod_usr_methods
29  use mod_comm_lib, only: mpistop
30  integer :: nwx,idir
31 
32  if (.not. associated(usr_gravity)) then
33  write(*,*) "mod_usr.t: please define usr_gravity before (m)hd activate"
34  write(*,*) "like the phys_gravity in mod_usr_methods.t"
35  call mpistop("usr_gravity not defined or pointed")
36  end if
38  if(grav_split) any_source_split=.true.
39 
40  end subroutine gravity_init
41 
42  !> w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
43  subroutine gravity_add_source(qdt,ixI^L,ixO^L,wCT,wCTprim,w,x,&
44  energy,rhov,qsourcesplit,active)
46  use mod_usr_methods
47 
48  integer, intent(in) :: ixI^L, ixO^L
49  double precision, intent(in) :: qdt, x(ixI^S,1:ndim)
50  double precision, intent(in) :: wCT(ixI^S,1:nw),wCTprim(ixI^S,1:nw)
51  double precision, intent(inout) :: w(ixI^S,1:nw)
52  logical, intent(in) :: energy,rhov,qsourcesplit
53  logical, intent(inout) :: active
54  integer :: idim
55 
56  double precision :: gravity_field(ixI^S,ndim)
57 
58  if(qsourcesplit .eqv. grav_split) then
59  active = .true.
60 
61  call usr_gravity(ixi^l,ixo^l,wct,x,gravity_field)
62 
63  do idim = 1, ndim
64  w(ixo^s,iw_mom(idim)) = w(ixo^s,iw_mom(idim)) &
65  + qdt * gravity_field(ixo^s,idim) * wct(ixo^s,iw_rho)
66  if(energy) then
67  if(rhov) then
68  w(ixo^s,iw_e)=w(ixo^s,iw_e) &
69  +qdt*gravity_field(ixo^s,idim)*wctprim(ixo^s,iw_mom(idim))*wctprim(ixo^s,iw_rho)
70  else
71  w(ixo^s,iw_e)=w(ixo^s,iw_e) &
72  + qdt * gravity_field(ixo^s,idim) * wct(ixo^s,iw_mom(idim))
73  end if
74  end if
75  end do
76  end if
77 
78  end subroutine gravity_add_source
79 
80  subroutine gravity_get_dt(w,ixI^L,ixO^L,dtnew,dx^D,x)
82  use mod_usr_methods
83 
84  integer, intent(in) :: ixI^L, ixO^L
85  double precision, intent(in) :: dx^D, x(ixI^S,1:ndim), w(ixI^S,1:nw)
86  double precision, intent(inout) :: dtnew
87 
88  double precision :: dxinv(1:ndim), max_grav
89  integer :: idim
90 
91  double precision :: gravity_field(ixI^S,ndim)
92 
93  ^d&dxinv(^d)=one/dx^d;
94 
95  call usr_gravity(ixi^l,ixo^l,w,x,gravity_field)
96 
97  do idim = 1, ndim
98  max_grav = maxval(abs(gravity_field(ixo^s,idim)))
99  max_grav = max(max_grav, epsilon(1.0d0))
100  dtnew = min(dtnew, 1.0d0 / sqrt(max_grav * dxinv(idim)))
101  end do
102 
103  end subroutine gravity_get_dt
104 
105 end module mod_gravity
subroutine, public mpistop(message)
Exit MPI-AMRVAC with an error message.
Definition: mod_comm_lib.t:208
This module contains definitions of global parameters and variables and some generic functions/subrou...
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.
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 gravity_add_source(qdt, ixIL, ixOL, wCT, wCTprim, w, x, energy, rhov, 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:45
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:27
Module with all the methods that users can customize in AMRVAC.
procedure(phys_gravity), pointer usr_gravity