MPI-AMRVAC  3.1
The MPI - Adaptive Mesh Refinement - Versatile Advection Code
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  ! Check whether custom flux types have been defined
80  if (.not. allocated(flux_type)) then
81  allocate(flux_type(ndir, nw))
83  else if (any(shape(flux_type) /= [ndir, nw])) then
84  call mpistop("phys_check error: flux_type has wrong shape")
85  end if
86 
95 
96  ! Initialize particles module
97  if (rho_particles) then
98  call particles_init()
99  phys_req_diagonal = .true.
100  end if
101 
102  end subroutine rho_phys_init
103 
104  subroutine rho_to_conserved(ixI^L, ixO^L, w, x)
106  integer, intent(in) :: ixI^L, ixO^L
107  double precision, intent(inout) :: w(ixI^S, nw)
108  double precision, intent(in) :: x(ixI^S, 1:^ND)
109 
110  ! Do nothing (primitive and conservative are equal for rho module)
111  end subroutine rho_to_conserved
112 
113  subroutine rho_to_primitive(ixI^L, ixO^L, w, x)
115  integer, intent(in) :: ixI^L, ixO^L
116  double precision, intent(inout) :: w(ixI^S, nw)
117  double precision, intent(in) :: x(ixI^S, 1:^ND)
118 
119  ! Do nothing (primitive and conservative are equal for rho module)
120  end subroutine rho_to_primitive
121 
122  subroutine rho_get_v(w, x, ixI^L, ixO^L, idim, v, centered)
124  use mod_geometry
125  logical, intent(in) :: centered
126  integer, intent(in) :: ixi^l, ixo^l, idim
127  double precision, intent(in) :: w(ixi^s, nw), x(ixi^s, 1:^nd)
128  double precision, intent(out) :: v(ixi^s)
129 
130  double precision :: dtheta, dphi, halfdtheta, halfdphi, invdtheta, invdphi
131  {^ifthreed
132  double precision :: appcosphi(ixi^s), appsinphi(ixi^s), &
133  appcosthe(ixi^s), appsinthe(ixi^s)
134  }
135 
136  select case (coordinate)
137  case (cylindrical)
138  {^ifoned
139  call mpistop("advection in 1D cylindrical not available")
140  }
141  {^iftwod
142  ! advection in 2D cylindrical: polar grid: to v_R, v_varphi
143  if(centered)then
144  select case (idim)
145  case (1) ! radial velocity
146  v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2))+rho_v(2)*dsin(x(ixo^s,2))
147  case (2) ! v_varphi
148  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,2))+rho_v(2)*dcos(x(ixo^s,2))
149  end select
150  else
151  ! assumed uniform in varphi=theta
152  dtheta=x(ixomin1,ixomin2+1,2)-x(ixomin1,ixomin2,2)
153  halfdtheta=0.5d0*dtheta
154  invdtheta=1.0d0/dtheta
155  select case (idim)
156  case (1) ! radial velocity
157  v(ixo^s) =( rho_v(1)*( dsin(x(ixo^s,2)+halfdtheta) &
158  -dsin(x(ixo^s,2)-halfdtheta)) &
159  +rho_v(2)*(-dcos(x(ixo^s,2)+halfdtheta) &
160  +dcos(x(ixo^s,2)-halfdtheta)))*invdtheta
161  case (2) ! v_varphi
162  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,2)+halfdtheta) &
163  +rho_v(2)*dcos(x(ixo^s,2)+halfdtheta)
164  end select
165  endif
166  }
167  {^ifthreed
168  ! advection in 3D cylindrical: convert to v_R, v_Z, v_varphi
169  if(centered)then
170  select case (idim)
171  case (1) ! v_R velocity
172  v(ixo^s) = rho_v(1)*dcos(x(ixo^s,3))+rho_v(2)*dsin(x(ixo^s,3))
173  case (2) ! v_Z velocity
174  v(ixo^s) = rho_v(3)
175  case (3) ! v_varphi velocity
176  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3))+rho_v(2)*dcos(x(ixo^s,3))
177  end select
178  else
179  ! assumed uniform in varphi=theta
180  dtheta=x(ixomin1,ixomin2,ixomin3+1,3)-x(ixomin1,ixomin2,ixomin3,3)
181  halfdtheta=0.5d0*dtheta
182  invdtheta=1.0d0/dtheta
183  select case (idim)
184  case (1) ! radial velocity
185  v(ixo^s) =( rho_v(1)*( dsin(x(ixo^s,3)+halfdtheta) &
186  -dsin(x(ixo^s,3)-halfdtheta)) &
187  +rho_v(2)*(-dcos(x(ixo^s,3)+halfdtheta) &
188  +dcos(x(ixo^s,3)-halfdtheta)))*invdtheta
189  case (2) ! v_Z velocity
190  v(ixo^s) = rho_v(3)
191  case (3) ! v_varphi
192  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)+halfdtheta) &
193  +rho_v(2)*dcos(x(ixo^s,3)+halfdtheta)
194  end select
195  endif
196  }
197  case (spherical)
198  {^ifoned
199  call mpistop("advection in 1D spherical not available")
200  }
201  {^iftwod
202  call mpistop("advection in 2D spherical not available")
203  }
204  {^ifthreed
205  ! advection in 3D spherical: convert to v_r, v_theta, v_phi
206  if(centered)then
207  select case (idim)
208  case (1) ! radial velocity
209  v(ixo^s) = rho_v(1)*dsin(x(ixo^s,2))*dcos(x(ixo^s,3)) &
210  +rho_v(2)*dsin(x(ixo^s,2))*dsin(x(ixo^s,3)) &
211  +rho_v(3)*dcos(x(ixo^s,2))
212  case (2) ! theta velocity
213  v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2))*dcos(x(ixo^s,3)) &
214  +rho_v(2)*dcos(x(ixo^s,2))*dsin(x(ixo^s,3)) &
215  -rho_v(3)*dsin(x(ixo^s,2))
216  case (3) ! phi velocity
217  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)) &
218  +rho_v(2)*dcos(x(ixo^s,3))
219  end select
220  else
221  ! assumed uniform in theta and phi
222  dtheta=x(ixomin1,ixomin2+1,ixomin3,2)-x(ixomin1,ixomin2,ixomin3,2)
223  dphi=x(ixomin1,ixomin2,ixomin3+1,3)-x(ixomin1,ixomin2,ixomin3,3)
224  halfdtheta=0.5d0*dtheta
225  halfdphi=0.5d0*dphi
226  invdtheta=1.0d0/dtheta
227  invdphi=1.0d0/dphi
228  select case (idim)
229  case (1) ! radial velocity
230  appcosphi(ixo^s)=( dsin(x(ixo^s,3)+halfdphi) &
231  -dsin(x(ixo^s,3)-halfdphi))*invdphi
232  appsinphi(ixo^s)=(-dcos(x(ixo^s,3)+halfdphi) &
233  +dcos(x(ixo^s,3)-halfdphi))*invdphi
234  appcosthe(ixo^s)=(dsin(x(ixo^s,2)+halfdtheta)**2 &
235  -dsin(x(ixo^s,2)-halfdtheta)**2) &
236  /(4.0d0*dabs(dsin(x(ixo^s,2)))*dsin(halfdtheta))
237  appsinthe(ixo^s)= &
238  (-dsin(x(ixo^s,2)+halfdtheta)*dcos(x(ixo^s,2)+halfdtheta) &
239  +dsin(x(ixo^s,2)-halfdtheta)*dcos(x(ixo^s,2)-halfdtheta) &
240  +dtheta)/(4.0d0*dabs(dsin(x(ixo^s,2)))*dsin(halfdtheta))
241  v(ixo^s) = rho_v(1)*appsinthe(ixo^s)*appcosphi(ixo^s) &
242  +rho_v(2)*appsinthe(ixo^s)*appsinphi(ixo^s) &
243  +rho_v(3)*appcosthe(ixo^s)
244  case (2) ! theta velocity
245  appcosphi(ixo^s)=( dsin(x(ixo^s,3)+halfdphi) &
246  -dsin(x(ixo^s,3)-halfdphi))*invdphi
247  appsinphi(ixo^s)=(-dcos(x(ixo^s,3)+halfdphi) &
248  +dcos(x(ixo^s,3)-halfdphi))*invdphi
249  v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2)+halfdtheta)*appcosphi(ixo^s) &
250  +rho_v(2)*dcos(x(ixo^s,2)+halfdtheta)*appsinphi(ixo^s) &
251  -rho_v(3)*dsin(x(ixo^s,2)+halfdtheta)
252  case (3) ! phi velocity
253  v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)+halfdphi) &
254  +rho_v(2)*dcos(x(ixo^s,3)+halfdphi)
255  end select
256  endif
257  }
258  case default
259  v(ixo^s) = rho_v(idim)
260  end select
261  end subroutine rho_get_v
262 
263  !> Calculate simple v component
264  subroutine rho_get_v_idim(w,x,ixI^L,ixO^L,idim,v)
266 
267  integer, intent(in) :: ixI^L, ixO^L, idim
268  double precision, intent(in) :: w(ixI^S,nw), x(ixI^S,1:ndim)
269  double precision, intent(out) :: v(ixI^S)
270 
271  v(ixo^s) = rho_v(idim)
272 
273  end subroutine rho_get_v_idim
274 
275  subroutine rho_get_cmax(w, x, ixI^L, ixO^L, idim, cmax)
277  integer, intent(in) :: ixI^L, ixO^L, idim
278  double precision, intent(in) :: w(ixI^S, nw), x(ixI^S, 1:^ND)
279  double precision, intent(inout) :: cmax(ixI^S)
280 
281  call rho_get_v(w, x, ixi^l, ixo^l, idim, cmax, .true.)
282 
283  cmax(ixo^s) = abs(cmax(ixo^s))
284 
285  end subroutine rho_get_cmax
286 
287  subroutine rho_get_cbounds(wLC, wRC, wLp, wRp, x, ixI^L, ixO^L, idim,Hspeed, cmax, cmin)
289  use mod_variables
290  integer, intent(in) :: ixI^L, ixO^L, idim
291  double precision, intent(in) :: wLC(ixI^S, nw), wRC(ixI^S,nw)
292  double precision, intent(in) :: wLp(ixI^S, nw), wRp(ixI^S,nw)
293  double precision, intent(in) :: x(ixI^S, 1:^ND)
294  double precision, intent(inout) :: cmax(ixI^S,1:number_species)
295  double precision, intent(inout), optional :: cmin(ixI^S,1:number_species)
296  double precision, intent(in) :: Hspeed(ixI^S,1:number_species)
297 
298  ! If get_v depends on w, the first argument should be some average over the
299  ! left and right state
300  call rho_get_v(wlc, x, ixi^l, ixo^l, idim, cmax(ixi^s,1), .false.)
301 
302  if (present(cmin)) then
303  cmin(ixo^s,1) = min(cmax(ixo^s,1), zero)
304  cmax(ixo^s,1) = max(cmax(ixo^s,1), zero)
305  else
306  cmax(ixo^s,1) = maxval(abs(cmax(ixo^s,1)))
307  end if
308 
309  end subroutine rho_get_cbounds
310 
311  subroutine rho_get_dt(w, ixI^L, ixO^L, dtnew, dx^D, x)
313  integer, intent(in) :: ixI^L, ixO^L
314  double precision, intent(in) :: dx^D, x(ixI^S, 1:^ND)
315  double precision, intent(in) :: w(ixI^S, 1:nw)
316  double precision, intent(inout) :: dtnew
317 
318  dtnew = bigdouble
319  end subroutine rho_get_dt
320 
321  ! There is nothing to add to the transport flux in the transport equation
322  subroutine rho_get_flux(wC, w, x, ixI^L, ixO^L, idim, f)
324  integer, intent(in) :: ixI^L, ixO^L, idim
325  double precision, intent(in) :: wC(ixI^S, 1:nw)
326  double precision, intent(in) :: w(ixI^S, 1:nw)
327  double precision, intent(in) :: x(ixI^S, 1:^ND)
328  double precision, intent(out) :: f(ixI^S, nwflux)
329  double precision :: v(ixI^S)
330 
331  call rho_get_v(wc, x, ixi^l, ixo^l, idim, v, .false.)
332 
333  f(ixo^s, rho_) = w(ixo^s, rho_) * v(ixo^s)
334  end subroutine rho_get_flux
335 
336  subroutine rho_add_source_geom(qdt, dtfactor, ixI^L, ixO^L, wCT, w, x)
337 
338  ! Add geometrical source terms to w
339  ! There are no geometrical source terms in the transport equation
340 
342 
343  integer, intent(in) :: ixI^L, ixO^L
344  double precision, intent(in) :: qdt, dtfactor, x(ixI^S, 1:^ND)
345  double precision, intent(inout) :: wCT(ixI^S, 1:nw), w(ixI^S, 1:nw)
346 
347  end subroutine rho_add_source_geom
348 
349 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:79
procedure(sub_get_flux), pointer phys_get_flux
Definition: mod_physics.t:67
logical phys_req_diagonal
Whether the physics routines require diagonal ghost cells, for example for computing a curl.
Definition: mod_physics.t:24
procedure(sub_get_cbounds), pointer phys_get_cbounds
Definition: mod_physics.t:66
procedure(sub_get_dt), pointer phys_get_dt
Definition: mod_physics.t:69
procedure(sub_add_source_geom), pointer phys_add_source_geom
Definition: mod_physics.t:70
integer, parameter flux_default
Indicates a normal flux.
Definition: mod_physics.t:46
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:43
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:16
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:27
Module containing the physics routines for scalar advection.
Definition: mod_rho_phys.t:2
subroutine rho_add_source_geom(qdt, dtfactor, ixIL, ixOL, wCT, w, x)
Definition: mod_rho_phys.t:337
subroutine, public rho_get_v(w, x, ixIL, ixOL, idim, v, centered)
Definition: mod_rho_phys.t:123
subroutine rho_to_conserved(ixIL, ixOL, w, x)
Definition: mod_rho_phys.t:105
subroutine rho_get_dt(w, ixIL, ixOL, dtnew, dxD, x)
Definition: mod_rho_phys.t:312
subroutine rho_to_primitive(ixIL, ixOL, w, x)
Definition: mod_rho_phys.t:114
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:265
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:323
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:288
subroutine rho_get_cmax(w, x, ixIL, ixOL, idim, cmax)
Definition: mod_rho_phys.t:276
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