MPI-AMRVAC  3.1
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
mod_rho_phys.t
Go to the documentation of this file.
1 !> Module containing the physics routines for scalar advection
3 
4  implicit none
5  private
6 
7  integer, protected, public :: rho_ = 1
8 
9  !> Whether particles module is added
10  logical, public, protected :: rho_particles = .false.
11 
12  double precision, protected, public :: rho_v(^nd) = 1.0d0
13 
14  ! Public methods
15  public :: rho_phys_init
16  public :: rho_get_v
17 
18 contains
19 
20  subroutine rho_params_read(files)
22  character(len=*), intent(in) :: files(:)
23  integer :: n
24 
25  namelist /rho_list/ rho_v, rho_particles
26 
27  do n = 1, size(files)
28  open(unitpar, file=trim(files(n)), status='old')
29  read(unitpar, rho_list, end=111)
30 111 close(unitpar)
31  end do
32 
33  end subroutine rho_params_read
34 
35  !> Write this module's parameters to a snapsoht
36  subroutine rho_write_info(fh)
38  integer, intent(in) :: fh
39  integer, parameter :: n_par = ^nd
40  double precision :: values(n_par)
41  character(len=name_len) :: names(n_par)
42  integer, dimension(MPI_STATUS_SIZE) :: st
43  integer :: er
44  integer :: idim
45 
46  call mpi_file_write(fh, n_par, 1, mpi_integer, st, er)
47 
48  do idim=1,ndim
49  write(names(idim),'(a,i1)') "v",idim
50  values(idim) = rho_v(idim)
51  end do
52  call mpi_file_write(fh, values, n_par, mpi_double_precision, st, er)
53  call mpi_file_write(fh, names, n_par * name_len, mpi_character, st, er)
54  end subroutine rho_write_info
55 
56  subroutine rho_phys_init()
58  use mod_physics
59  use mod_particles, only: particles_init
60 
61  call rho_params_read(par_files)
62 
63  physics_type = "rho"
64  phys_energy = .false.
65  phys_req_diagonal = .false.
67 
68  allocate(start_indices(number_species),stop_indices(number_species))
69  ! set the index of the first flux variable for species 1
70  start_indices(1)=1
71  rho_ = var_set_rho()
72 
73  ! set number of variables which need update ghostcells
74  nwgc=nwflux
75 
76  ! set the index of the last flux variable for species 1
77  stop_indices(1)=nwflux
78 
79  ! Number of variables need reconstruction in w
80  nw_recon=nwflux
81 
82  ! Check whether custom flux types have been defined
83  if (.not. allocated(flux_type)) then
84  allocate(flux_type(ndir, nw))
86  else if (any(shape(flux_type) /= [ndir, nw])) then
87  call mpistop("phys_check error: flux_type has wrong shape")
88  end if
89 
98 
99  ! Initialize particles module
100  if (rho_particles) then
101  call particles_init()
102  phys_req_diagonal = .true.
103  end if
104 
105  end subroutine rho_phys_init
106 
107  subroutine rho_to_conserved(ixI^L, ixO^L, w, x)
109  integer, intent(in) :: ixI^L, ixO^L
110  double precision, intent(inout) :: w(ixI^S, nw)
111  double precision, intent(in) :: x(ixI^S, 1:^ND)
112 
113  ! Do nothing (primitive and conservative are equal for rho module)
114  end subroutine rho_to_conserved
115 
116  subroutine rho_to_primitive(ixI^L, ixO^L, w, x)
118  integer, intent(in) :: ixI^L, ixO^L
119  double precision, intent(inout) :: w(ixI^S, nw)
120  double precision, intent(in) :: x(ixI^S, 1:^ND)
121 
122  ! Do nothing (primitive and conservative are equal for rho module)
123  end subroutine rho_to_primitive
124 
125  subroutine rho_get_v(w, x, ixI^L, ixO^L, idim, v, centered)
127  use mod_geometry
128  logical, intent(in) :: centered
129  integer, intent(in) :: ixi^l, ixo^l, idim
130  double precision, intent(in) :: w(ixi^s, nw), x(ixi^s, 1:^nd)
131  double precision, intent(out) :: v(ixi^s)
132 
133  double precision :: dtheta, dphi, halfdtheta, halfdphi, invdtheta, invdphi
134  {^ifthreed
135  double precision :: appcosphi(ixi^s), appsinphi(ixi^s), &
136  appcosthe(ixi^s), appsinthe(ixi^s)
137  }
138 
139  select case (coordinate)
140  case (cylindrical)
141  {^ifoned
142  call mpistop("advection in 1D cylindrical not available")
143  }
144  {^iftwod
145  ! advection in 2D cylindrical: polar grid: to v_R, v_varphi
146  if(centered)then
147  select case (idim)
148  case (1) ! radial velocity
149  v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2))+rho_v(2)*dsin(x(ixo^s,2))
150  case (2) ! v_varphi
151  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,2))+rho_v(2)*dcos(x(ixo^s,2))
152  end select
153  else
154  ! assumed uniform in varphi=theta
155  dtheta=x(ixomin1,ixomin2+1,2)-x(ixomin1,ixomin2,2)
156  halfdtheta=0.5d0*dtheta
157  invdtheta=1.0d0/dtheta
158  select case (idim)
159  case (1) ! radial velocity
160  v(ixo^s) =( rho_v(1)*( dsin(x(ixo^s,2)+halfdtheta) &
161  -dsin(x(ixo^s,2)-halfdtheta)) &
162  +rho_v(2)*(-dcos(x(ixo^s,2)+halfdtheta) &
163  +dcos(x(ixo^s,2)-halfdtheta)))*invdtheta
164  case (2) ! v_varphi
165  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,2)+halfdtheta) &
166  +rho_v(2)*dcos(x(ixo^s,2)+halfdtheta)
167  end select
168  endif
169  }
170  {^ifthreed
171  ! advection in 3D cylindrical: convert to v_R, v_Z, v_varphi
172  if(centered)then
173  select case (idim)
174  case (1) ! v_R velocity
175  v(ixo^s) = rho_v(1)*dcos(x(ixo^s,3))+rho_v(2)*dsin(x(ixo^s,3))
176  case (2) ! v_Z velocity
177  v(ixo^s) = rho_v(3)
178  case (3) ! v_varphi velocity
179  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3))+rho_v(2)*dcos(x(ixo^s,3))
180  end select
181  else
182  ! assumed uniform in varphi=theta
183  dtheta=x(ixomin1,ixomin2,ixomin3+1,3)-x(ixomin1,ixomin2,ixomin3,3)
184  halfdtheta=0.5d0*dtheta
185  invdtheta=1.0d0/dtheta
186  select case (idim)
187  case (1) ! radial velocity
188  v(ixo^s) =( rho_v(1)*( dsin(x(ixo^s,3)+halfdtheta) &
189  -dsin(x(ixo^s,3)-halfdtheta)) &
190  +rho_v(2)*(-dcos(x(ixo^s,3)+halfdtheta) &
191  +dcos(x(ixo^s,3)-halfdtheta)))*invdtheta
192  case (2) ! v_Z velocity
193  v(ixo^s) = rho_v(3)
194  case (3) ! v_varphi
195  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)+halfdtheta) &
196  +rho_v(2)*dcos(x(ixo^s,3)+halfdtheta)
197  end select
198  endif
199  }
200  case (spherical)
201  {^ifoned
202  call mpistop("advection in 1D spherical not available")
203  }
204  {^iftwod
205  call mpistop("advection in 2D spherical not available")
206  }
207  {^ifthreed
208  ! advection in 3D spherical: convert to v_r, v_theta, v_phi
209  if(centered)then
210  select case (idim)
211  case (1) ! radial velocity
212  v(ixo^s) = rho_v(1)*dsin(x(ixo^s,2))*dcos(x(ixo^s,3)) &
213  +rho_v(2)*dsin(x(ixo^s,2))*dsin(x(ixo^s,3)) &
214  +rho_v(3)*dcos(x(ixo^s,2))
215  case (2) ! theta velocity
216  v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2))*dcos(x(ixo^s,3)) &
217  +rho_v(2)*dcos(x(ixo^s,2))*dsin(x(ixo^s,3)) &
218  -rho_v(3)*dsin(x(ixo^s,2))
219  case (3) ! phi velocity
220  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)) &
221  +rho_v(2)*dcos(x(ixo^s,3))
222  end select
223  else
224  ! assumed uniform in theta and phi
225  dtheta=x(ixomin1,ixomin2+1,ixomin3,2)-x(ixomin1,ixomin2,ixomin3,2)
226  dphi=x(ixomin1,ixomin2,ixomin3+1,3)-x(ixomin1,ixomin2,ixomin3,3)
227  halfdtheta=0.5d0*dtheta
228  halfdphi=0.5d0*dphi
229  invdtheta=1.0d0/dtheta
230  invdphi=1.0d0/dphi
231  select case (idim)
232  case (1) ! radial velocity
233  appcosphi(ixo^s)=( dsin(x(ixo^s,3)+halfdphi) &
234  -dsin(x(ixo^s,3)-halfdphi))*invdphi
235  appsinphi(ixo^s)=(-dcos(x(ixo^s,3)+halfdphi) &
236  +dcos(x(ixo^s,3)-halfdphi))*invdphi
237  appcosthe(ixo^s)=(dsin(x(ixo^s,2)+halfdtheta)**2 &
238  -dsin(x(ixo^s,2)-halfdtheta)**2) &
239  /(4.0d0*dabs(dsin(x(ixo^s,2)))*dsin(halfdtheta))
240  appsinthe(ixo^s)= &
241  (-dsin(x(ixo^s,2)+halfdtheta)*dcos(x(ixo^s,2)+halfdtheta) &
242  +dsin(x(ixo^s,2)-halfdtheta)*dcos(x(ixo^s,2)-halfdtheta) &
243  +dtheta)/(4.0d0*dabs(dsin(x(ixo^s,2)))*dsin(halfdtheta))
244  v(ixo^s) = rho_v(1)*appsinthe(ixo^s)*appcosphi(ixo^s) &
245  +rho_v(2)*appsinthe(ixo^s)*appsinphi(ixo^s) &
246  +rho_v(3)*appcosthe(ixo^s)
247  case (2) ! theta velocity
248  appcosphi(ixo^s)=( dsin(x(ixo^s,3)+halfdphi) &
249  -dsin(x(ixo^s,3)-halfdphi))*invdphi
250  appsinphi(ixo^s)=(-dcos(x(ixo^s,3)+halfdphi) &
251  +dcos(x(ixo^s,3)-halfdphi))*invdphi
252  v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2)+halfdtheta)*appcosphi(ixo^s) &
253  +rho_v(2)*dcos(x(ixo^s,2)+halfdtheta)*appsinphi(ixo^s) &
254  -rho_v(3)*dsin(x(ixo^s,2)+halfdtheta)
255  case (3) ! phi velocity
256  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)+halfdphi) &
257  +rho_v(2)*dcos(x(ixo^s,3)+halfdphi)
258  end select
259  endif
260  }
261  case default
262  v(ixo^s) = rho_v(idim)
263  end select
264  end subroutine rho_get_v
265 
266  !> Calculate simple v component
267  subroutine rho_get_v_idim(w,x,ixI^L,ixO^L,idim,v)
269 
270  integer, intent(in) :: ixI^L, ixO^L, idim
271  double precision, intent(in) :: w(ixI^S,nw), x(ixI^S,1:ndim)
272  double precision, intent(out) :: v(ixI^S)
273 
274  v(ixo^s) = rho_v(idim)
275 
276  end subroutine rho_get_v_idim
277 
278  subroutine rho_get_cmax(w, x, ixI^L, ixO^L, idim, cmax)
280  integer, intent(in) :: ixI^L, ixO^L, idim
281  double precision, intent(in) :: w(ixI^S, nw), x(ixI^S, 1:^ND)
282  double precision, intent(inout) :: cmax(ixI^S)
283 
284  call rho_get_v(w, x, ixi^l, ixo^l, idim, cmax, .true.)
285 
286  cmax(ixo^s) = abs(cmax(ixo^s))
287 
288  end subroutine rho_get_cmax
289 
290  subroutine rho_get_cbounds(wLC, wRC, wLp, wRp, x, ixI^L, ixO^L, idim,Hspeed, cmax, cmin)
292  use mod_variables
293  integer, intent(in) :: ixI^L, ixO^L, idim
294  double precision, intent(in) :: wLC(ixI^S, nw), wRC(ixI^S,nw)
295  double precision, intent(in) :: wLp(ixI^S, nw), wRp(ixI^S,nw)
296  double precision, intent(in) :: x(ixI^S, 1:^ND)
297  double precision, intent(inout) :: cmax(ixI^S,1:number_species)
298  double precision, intent(inout), optional :: cmin(ixI^S,1:number_species)
299  double precision, intent(in) :: Hspeed(ixI^S,1:number_species)
300 
301  ! If get_v depends on w, the first argument should be some average over the
302  ! left and right state
303  call rho_get_v(wlc, x, ixi^l, ixo^l, idim, cmax(ixi^s,1), .false.)
304 
305  if (present(cmin)) then
306  cmin(ixo^s,1) = min(cmax(ixo^s,1), zero)
307  cmax(ixo^s,1) = max(cmax(ixo^s,1), zero)
308  else
309  cmax(ixo^s,1) = maxval(abs(cmax(ixo^s,1)))
310  end if
311 
312  end subroutine rho_get_cbounds
313 
314  subroutine rho_get_dt(w, ixI^L, ixO^L, dtnew, dx^D, x)
316  integer, intent(in) :: ixI^L, ixO^L
317  double precision, intent(in) :: dx^D, x(ixI^S, 1:^ND)
318  double precision, intent(in) :: w(ixI^S, 1:nw)
319  double precision, intent(inout) :: dtnew
320 
321  dtnew = bigdouble
322  end subroutine rho_get_dt
323 
324  ! There is nothing to add to the transport flux in the transport equation
325  subroutine rho_get_flux(wC, w, x, ixI^L, ixO^L, idim, f)
327  integer, intent(in) :: ixI^L, ixO^L, idim
328  double precision, intent(in) :: wC(ixI^S, 1:nw)
329  double precision, intent(in) :: w(ixI^S, 1:nw)
330  double precision, intent(in) :: x(ixI^S, 1:^ND)
331  double precision, intent(out) :: f(ixI^S, nwflux)
332  double precision :: v(ixI^S)
333 
334  call rho_get_v(wc, x, ixi^l, ixo^l, idim, v, .false.)
335 
336  f(ixo^s, rho_) = w(ixo^s, rho_) * v(ixo^s)
337  end subroutine rho_get_flux
338 
339  subroutine rho_add_source_geom(qdt, dtfactor, ixI^L, ixO^L, wCT,wprim, w, x)
340 
341  ! Add geometrical source terms to w
342  ! There are no geometrical source terms in the transport equation
343 
345 
346  integer, intent(in) :: ixI^L, ixO^L
347  double precision, intent(in) :: qdt, dtfactor, x(ixI^S, 1:^ND)
348  double precision, intent(inout) :: wCT(ixI^S, 1:nw),wprim(ixI^S,1:nw), w(ixI^S, 1:nw)
349 
350  end subroutine rho_add_source_geom
351 
352 end module mod_rho_phys
Module with geometry-related routines (e.g., divergence, curl)
Definition: mod_geometry.t:2
integer coordinate
Definition: mod_geometry.t:7
integer, parameter spherical
Definition: mod_geometry.t:11
integer, parameter cylindrical
Definition: mod_geometry.t:10
This module contains definitions of global parameters and variables and some generic functions/subrou...
integer, parameter unitpar
file handle for IO
integer, parameter ndim
Number of spatial dimensions for grid variables.
logical use_particles
Use particles module or not.
character(len=std_len), dimension(:), allocatable par_files
Which par files are used as input.
integer ndir
Number of spatial dimensions (components) for vector variables.
Module containing all the particle routines.
Definition: mod_particles.t:2
subroutine particles_init()
Initialize particle data and parameters.
Definition: mod_particles.t:15
This module defines the procedures of a physics module. It contains function pointers for the various...
Definition: mod_physics.t:4
procedure(sub_convert), pointer phys_to_primitive
Definition: mod_physics.t:59
procedure(sub_write_info), pointer phys_write_info
Definition: mod_physics.t:81
procedure(sub_get_flux), pointer phys_get_flux
Definition: mod_physics.t:68
logical phys_req_diagonal
Whether the physics routines require diagonal ghost cells, for example for computing a curl.
Definition: mod_physics.t:36
procedure(sub_get_cbounds), pointer phys_get_cbounds
Definition: mod_physics.t:67
procedure(sub_get_dt), pointer phys_get_dt
Definition: mod_physics.t:71
procedure(sub_add_source_geom), pointer phys_add_source_geom
Definition: mod_physics.t:72
integer, parameter flux_default
Indicates a normal flux.
Definition: mod_physics.t:24
integer, dimension(:, :), allocatable flux_type
Array per direction per variable, which can be used to specify that certain fluxes have to be treated...
Definition: mod_physics.t:21
procedure(sub_convert), pointer phys_to_conserved
Definition: mod_physics.t:58
character(len=name_len) physics_type
String describing the physics type of the simulation.
Definition: mod_physics.t:54
procedure(sub_get_cmax), pointer phys_get_cmax
Definition: mod_physics.t:61
logical phys_energy
Solve energy equation or not.
Definition: mod_physics.t:39
Module containing the physics routines for scalar advection.
Definition: mod_rho_phys.t:2
subroutine, public rho_get_v(w, x, ixIL, ixOL, idim, v, centered)
Definition: mod_rho_phys.t:126
subroutine rho_to_conserved(ixIL, ixOL, w, x)
Definition: mod_rho_phys.t:108
subroutine rho_add_source_geom(qdt, dtfactor, ixIL, ixOL, wCT, wprim, w, x)
Definition: mod_rho_phys.t:340
subroutine rho_get_dt(w, ixIL, ixOL, dtnew, dxD, x)
Definition: mod_rho_phys.t:315
subroutine rho_to_primitive(ixIL, ixOL, w, x)
Definition: mod_rho_phys.t:117
double precision, dimension(^nd), public, protected rho_v
Definition: mod_rho_phys.t:12
subroutine rho_get_v_idim(w, x, ixIL, ixOL, idim, v)
Calculate simple v component.
Definition: mod_rho_phys.t:268
subroutine rho_write_info(fh)
Write this module's parameters to a snapsoht.
Definition: mod_rho_phys.t:37
subroutine rho_get_flux(wC, w, x, ixIL, ixOL, idim, f)
Definition: mod_rho_phys.t:326
subroutine, public rho_phys_init()
Definition: mod_rho_phys.t:57
subroutine rho_get_cbounds(wLC, wRC, wLp, wRp, x, ixIL, ixOL, idim, Hspeed, cmax, cmin)
Definition: mod_rho_phys.t:291
subroutine rho_get_cmax(w, x, ixIL, ixOL, idim, cmax)
Definition: mod_rho_phys.t:279
logical, public, protected rho_particles
Whether particles module is added.
Definition: mod_rho_phys.t:10
integer, public, protected rho_
Definition: mod_rho_phys.t:7