MPI-AMRVAC  2.2
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  integer :: nwx,idir
29 
31 
32  end subroutine gravity_init
33 
34  !> w[iw]=w[iw]+qdt*S[wCT,qtC,x] where S is the source based on wCT within ixO
35  subroutine gravity_add_source(qdt,ixI^L,ixO^L,wCT,w,x,&
36  energy,qsourcesplit,active)
38  use mod_usr_methods
39 
40  integer, intent(in) :: ixI^L, ixO^L
41  double precision, intent(in) :: qdt, x(ixi^s,1:ndim)
42  double precision, intent(in) :: wCT(ixi^s,1:nw)
43  double precision, intent(inout) :: w(ixi^s,1:nw)
44  logical, intent(in) :: energy,qsourcesplit
45  logical, intent(inout) :: active
46  integer :: idim
47 
48  double precision :: gravity_field(ixi^s,ndim)
49 
50  if(qsourcesplit .eqv. grav_split) then
51  active = .true.
52 
53  if (.not. associated(usr_gravity)) then
54  write(*,*) "mod_usr.t: please point usr_gravity to a subroutine"
55  write(*,*) "like the phys_gravity in mod_usr_methods.t"
56  call mpistop("gravity_add_source: usr_gravity not defined")
57  else
58  call usr_gravity(ixi^l,ixo^l,wct,x,gravity_field)
59  end if
60 
61  do idim = 1, ndim
62  w(ixo^s,iw_mom(idim)) = w(ixo^s,iw_mom(idim)) &
63  + qdt * gravity_field(ixo^s,idim) * wct(ixo^s,iw_rho)
64  if(energy .and. .not.block%e_is_internal) then
65  w(ixo^s,iw_e)=w(ixo^s,iw_e) &
66  + qdt * gravity_field(ixo^s,idim) * wct(ixo^s,iw_mom(idim))
67  end if
68  end do
69  end if
70 
71  end subroutine gravity_add_source
72 
73  subroutine gravity_get_dt(w,ixI^L,ixO^L,dtnew,dx^D,x)
75  use mod_usr_methods
76 
77  integer, intent(in) :: ixI^L, ixO^L
78  double precision, intent(in) :: dx^D, x(ixi^s,1:ndim), w(ixi^s,1:nw)
79  double precision, intent(inout) :: dtnew
80 
81  double precision :: dxinv(1:ndim), max_grav
82  integer :: idim
83 
84  double precision :: gravity_field(ixi^s,ndim)
85 
86  ^d&dxinv(^d)=one/dx^d;
87 
88  if(.not. associated(usr_gravity)) then
89  write(*,*) "mod_usr.t: please point usr_gravity to a subroutine"
90  write(*,*) "like the phys_gravity in mod_usr_methods.t"
91  call mpistop("gravity_get_dt: usr_gravity not defined")
92  else
93  call usr_gravity(ixi^l,ixo^l,w,x,gravity_field)
94  end if
95 
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 
102  end subroutine gravity_get_dt
103 
104 end module mod_gravity
This module contains definitions of global parameters and variables and some generic functions/subrou...
subroutine gravity_get_dt(w, ixIL, ixOL, dtnew, dxD, x)
Definition: mod_gravity.t:74
subroutine grav_params_read(files)
Read this module's parameters from a file.
Definition: mod_gravity.t:11
Module with all the methods that users can customize in AMRVAC.
procedure(phys_gravity), pointer usr_gravity
integer, parameter unitpar
subroutine gravity_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
Definition: mod_gravity.t:37
Module for including gravity in (magneto)hydrodynamics simulations.
Definition: mod_gravity.t:2
character(len=std_len), dimension(:), allocatable par_files
Which par files are used as input.
subroutine mpistop(message)
Exit MPI-AMRVAC with an error message.
Definition: comm_lib.t:198
integer, parameter ndim
Number of spatial dimensions for grid variables.
subroutine gravity_init()
Initialize the module.
Definition: mod_gravity.t:27
logical grav_split
source split or not
Definition: mod_gravity.t:6