MPI-AMRVAC 3.1
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
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
18contains
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)
30111 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
60
61 call rho_params_read(par_files)
62
63 physics_type = "rho"
64 phys_energy = .false.
66
67 allocate(start_indices(number_species),stop_indices(number_species))
68 ! set the index of the first flux variable for species 1
69 start_indices(1)=1
70 rho_ = var_set_rho()
71
72 ! set number of variables which need update ghostcells
73 nwgc=nwflux
74
75 ! set the index of the last flux variable for species 1
76 stop_indices(1)=nwflux
77
78 ! Number of variables need reconstruction in w
79 nw_recon=nwflux
80
81 ! Check whether custom flux types have been defined
82 if (.not. allocated(flux_type)) then
83 allocate(flux_type(ndir, nw))
85 else if (any(shape(flux_type) /= [ndir, nw])) then
86 call mpistop("phys_check error: flux_type has wrong shape")
87 end if
88
89 phys_get_cmax => rho_get_cmax
90 phys_get_cbounds => rho_get_cbounds
91 phys_get_flux => rho_get_flux
92 phys_add_source_geom => rho_add_source_geom
93 phys_to_conserved => rho_to_conserved
94 phys_to_primitive => rho_to_primitive
95 phys_get_dt => rho_get_dt
96 phys_write_info => rho_write_info
97
98 ! Initialize particles module
99 if (rho_particles) then
100 call particles_init()
101 end if
102
103 end subroutine rho_phys_init
104
105 subroutine rho_to_conserved(ixI^L, ixO^L, w, x)
107 integer, intent(in) :: ixi^l, ixo^l
108 double precision, intent(inout) :: w(ixi^s, nw)
109 double precision, intent(in) :: x(ixi^s, 1:^nd)
110
111 ! Do nothing (primitive and conservative are equal for rho module)
112 end subroutine rho_to_conserved
113
114 subroutine rho_to_primitive(ixI^L, ixO^L, w, x)
116 integer, intent(in) :: ixi^l, ixo^l
117 double precision, intent(inout) :: w(ixi^s, nw)
118 double precision, intent(in) :: x(ixi^s, 1:^nd)
119
120 ! Do nothing (primitive and conservative are equal for rho module)
121 end subroutine rho_to_primitive
122
123 subroutine rho_get_v(w, x, ixI^L, ixO^L, idim, v, centered)
125 use mod_geometry
126 logical, intent(in) :: centered
127 integer, intent(in) :: ixi^l, ixo^l, idim
128 double precision, intent(in) :: w(ixi^s, nw), x(ixi^s, 1:^nd)
129 double precision, intent(out) :: v(ixi^s)
130
131 double precision :: dtheta, dphi, halfdtheta, halfdphi, invdtheta, invdphi
132 {^ifthreed
133 double precision :: appcosphi(ixi^s), appsinphi(ixi^s), &
134 appcosthe(ixi^s), appsinthe(ixi^s)
135 }
136
137 select case (coordinate)
138 case (cylindrical)
139 {^ifoned
140 call mpistop("advection in 1D cylindrical not available")
141 }
142 {^iftwod
143 ! advection in 2D cylindrical: polar grid: to v_R, v_varphi
144 if(centered)then
145 select case (idim)
146 case (1) ! radial velocity
147 v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2))+rho_v(2)*dsin(x(ixo^s,2))
148 case (2) ! v_varphi
149 v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,2))+rho_v(2)*dcos(x(ixo^s,2))
150 end select
151 else
152 ! assumed uniform in varphi=theta
153 dtheta=x(ixomin1,ixomin2+1,2)-x(ixomin1,ixomin2,2)
154 halfdtheta=0.5d0*dtheta
155 invdtheta=1.0d0/dtheta
156 select case (idim)
157 case (1) ! radial velocity
158 v(ixo^s) =( rho_v(1)*( dsin(x(ixo^s,2)+halfdtheta) &
159 -dsin(x(ixo^s,2)-halfdtheta)) &
160 +rho_v(2)*(-dcos(x(ixo^s,2)+halfdtheta) &
161 +dcos(x(ixo^s,2)-halfdtheta)))*invdtheta
162 case (2) ! v_varphi
163 v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,2)+halfdtheta) &
164 +rho_v(2)*dcos(x(ixo^s,2)+halfdtheta)
165 end select
166 endif
167 }
168 {^ifthreed
169 ! advection in 3D cylindrical: convert to v_R, v_Z, v_varphi
170 if(centered)then
171 select case (idim)
172 case (1) ! v_R velocity
173 v(ixo^s) = rho_v(1)*dcos(x(ixo^s,3))+rho_v(2)*dsin(x(ixo^s,3))
174 case (2) ! v_Z velocity
175 v(ixo^s) = rho_v(3)
176 case (3) ! v_varphi velocity
177 v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3))+rho_v(2)*dcos(x(ixo^s,3))
178 end select
179 else
180 ! assumed uniform in varphi=theta
181 dtheta=x(ixomin1,ixomin2,ixomin3+1,3)-x(ixomin1,ixomin2,ixomin3,3)
182 halfdtheta=0.5d0*dtheta
183 invdtheta=1.0d0/dtheta
184 select case (idim)
185 case (1) ! radial velocity
186 v(ixo^s) =( rho_v(1)*( dsin(x(ixo^s,3)+halfdtheta) &
187 -dsin(x(ixo^s,3)-halfdtheta)) &
188 +rho_v(2)*(-dcos(x(ixo^s,3)+halfdtheta) &
189 +dcos(x(ixo^s,3)-halfdtheta)))*invdtheta
190 case (2) ! v_Z velocity
191 v(ixo^s) = rho_v(3)
192 case (3) ! v_varphi
193 v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)+halfdtheta) &
194 +rho_v(2)*dcos(x(ixo^s,3)+halfdtheta)
195 end select
196 endif
197 }
198 case (spherical)
199 {^ifoned
200 call mpistop("advection in 1D spherical not available")
201 }
202 {^iftwod
203 call mpistop("advection in 2D spherical not available")
204 }
205 {^ifthreed
206 ! advection in 3D spherical: convert to v_r, v_theta, v_phi
207 if(centered)then
208 select case (idim)
209 case (1) ! radial velocity
210 v(ixo^s) = rho_v(1)*dsin(x(ixo^s,2))*dcos(x(ixo^s,3)) &
211 +rho_v(2)*dsin(x(ixo^s,2))*dsin(x(ixo^s,3)) &
212 +rho_v(3)*dcos(x(ixo^s,2))
213 case (2) ! theta velocity
214 v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2))*dcos(x(ixo^s,3)) &
215 +rho_v(2)*dcos(x(ixo^s,2))*dsin(x(ixo^s,3)) &
216 -rho_v(3)*dsin(x(ixo^s,2))
217 case (3) ! phi velocity
218 v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)) &
219 +rho_v(2)*dcos(x(ixo^s,3))
220 end select
221 else
222 ! assumed uniform in theta and phi
223 dtheta=x(ixomin1,ixomin2+1,ixomin3,2)-x(ixomin1,ixomin2,ixomin3,2)
224 dphi=x(ixomin1,ixomin2,ixomin3+1,3)-x(ixomin1,ixomin2,ixomin3,3)
225 halfdtheta=0.5d0*dtheta
226 halfdphi=0.5d0*dphi
227 invdtheta=1.0d0/dtheta
228 invdphi=1.0d0/dphi
229 select case (idim)
230 case (1) ! radial velocity
231 appcosphi(ixo^s)=( dsin(x(ixo^s,3)+halfdphi) &
232 -dsin(x(ixo^s,3)-halfdphi))*invdphi
233 appsinphi(ixo^s)=(-dcos(x(ixo^s,3)+halfdphi) &
234 +dcos(x(ixo^s,3)-halfdphi))*invdphi
235 appcosthe(ixo^s)=(dsin(x(ixo^s,2)+halfdtheta)**2 &
236 -dsin(x(ixo^s,2)-halfdtheta)**2) &
237 /(4.0d0*dabs(dsin(x(ixo^s,2)))*dsin(halfdtheta))
238 appsinthe(ixo^s)= &
239 (-dsin(x(ixo^s,2)+halfdtheta)*dcos(x(ixo^s,2)+halfdtheta) &
240 +dsin(x(ixo^s,2)-halfdtheta)*dcos(x(ixo^s,2)-halfdtheta) &
241 +dtheta)/(4.0d0*dabs(dsin(x(ixo^s,2)))*dsin(halfdtheta))
242 v(ixo^s) = rho_v(1)*appsinthe(ixo^s)*appcosphi(ixo^s) &
243 +rho_v(2)*appsinthe(ixo^s)*appsinphi(ixo^s) &
244 +rho_v(3)*appcosthe(ixo^s)
245 case (2) ! theta velocity
246 appcosphi(ixo^s)=( dsin(x(ixo^s,3)+halfdphi) &
247 -dsin(x(ixo^s,3)-halfdphi))*invdphi
248 appsinphi(ixo^s)=(-dcos(x(ixo^s,3)+halfdphi) &
249 +dcos(x(ixo^s,3)-halfdphi))*invdphi
250 v(ixo^s) = rho_v(1)*dcos(x(ixo^s,2)+halfdtheta)*appcosphi(ixo^s) &
251 +rho_v(2)*dcos(x(ixo^s,2)+halfdtheta)*appsinphi(ixo^s) &
252 -rho_v(3)*dsin(x(ixo^s,2)+halfdtheta)
253 case (3) ! phi velocity
254 v(ixo^s) =-rho_v(1)*dsin(x(ixo^s,3)+halfdphi) &
255 +rho_v(2)*dcos(x(ixo^s,3)+halfdphi)
256 end select
257 endif
258 }
259 case default
260 v(ixo^s) = rho_v(idim)
261 end select
262 end subroutine rho_get_v
263
264 !> Calculate simple v component
265 subroutine rho_get_v_idim(w,x,ixI^L,ixO^L,idim,v)
267
268 integer, intent(in) :: ixi^l, ixo^l, idim
269 double precision, intent(in) :: w(ixi^s,nw), x(ixi^s,1:ndim)
270 double precision, intent(out) :: v(ixi^s)
271
272 v(ixo^s) = rho_v(idim)
273
274 end subroutine rho_get_v_idim
275
276 subroutine rho_get_cmax(w, x, ixI^L, ixO^L, idim, cmax)
278 integer, intent(in) :: ixi^l, ixo^l, idim
279 double precision, intent(in) :: w(ixi^s, nw), x(ixi^s, 1:^nd)
280 double precision, intent(inout) :: cmax(ixi^s)
281
282 call rho_get_v(w, x, ixi^l, ixo^l, idim, cmax, .true.)
283
284 cmax(ixo^s) = abs(cmax(ixo^s))
285
286 end subroutine rho_get_cmax
287
288 subroutine rho_get_cbounds(wLC, wRC, wLp, wRp, x, ixI^L, ixO^L, idim,Hspeed, cmax, cmin)
290 use mod_variables
291 integer, intent(in) :: ixi^l, ixo^l, idim
292 double precision, intent(in) :: wlc(ixi^s, nw), wrc(ixi^s,nw)
293 double precision, intent(in) :: wlp(ixi^s, nw), wrp(ixi^s,nw)
294 double precision, intent(in) :: x(ixi^s, 1:^nd)
295 double precision, intent(inout) :: cmax(ixi^s,1:number_species)
296 double precision, intent(inout), optional :: cmin(ixi^s,1:number_species)
297 double precision, intent(in) :: hspeed(ixi^s,1:number_species)
298
299 ! If get_v depends on w, the first argument should be some average over the
300 ! left and right state
301 call rho_get_v(wlc, x, ixi^l, ixo^l, idim, cmax(ixi^s,1), .false.)
302
303 if (present(cmin)) then
304 cmin(ixo^s,1) = min(cmax(ixo^s,1), zero)
305 cmax(ixo^s,1) = max(cmax(ixo^s,1), zero)
306 else
307 cmax(ixo^s,1) = maxval(abs(cmax(ixo^s,1)))
308 end if
309
310 end subroutine rho_get_cbounds
311
312 subroutine rho_get_dt(w, ixI^L, ixO^L, dtnew, dx^D, x)
314 integer, intent(in) :: ixi^l, ixo^l
315 double precision, intent(in) :: dx^d, x(ixi^s, 1:^nd)
316 double precision, intent(in) :: w(ixi^s, 1:nw)
317 double precision, intent(inout) :: dtnew
318
319 dtnew = bigdouble
320 end subroutine rho_get_dt
321
322 ! There is nothing to add to the transport flux in the transport equation
323 subroutine rho_get_flux(wC, w, x, ixI^L, ixO^L, idim, f)
325 integer, intent(in) :: ixi^l, ixo^l, idim
326 double precision, intent(in) :: wc(ixi^s, 1:nw)
327 double precision, intent(in) :: w(ixi^s, 1:nw)
328 double precision, intent(in) :: x(ixi^s, 1:^nd)
329 double precision, intent(out) :: f(ixi^s, nwflux)
330 double precision :: v(ixi^s)
331
332 call rho_get_v(wc, x, ixi^l, ixo^l, idim, v, .false.)
333
334 f(ixo^s, rho_) = w(ixo^s, rho_) * v(ixo^s)
335 end subroutine rho_get_flux
336
337 subroutine rho_add_source_geom(qdt, dtfactor, ixI^L, ixO^L, wCT,wprim, w, x)
338
339 ! Add geometrical source terms to w
340 ! There are no geometrical source terms in the transport equation
341
343
344 integer, intent(in) :: ixi^l, ixo^l
345 double precision, intent(in) :: qdt, dtfactor, x(ixi^s, 1:^nd)
346 double precision, intent(inout) :: wct(ixi^s, 1:nw),wprim(ixi^s,1:nw), w(ixi^s, 1:nw)
347
348 end subroutine rho_add_source_geom
349
350end 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
integer, parameter cylindrical
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.
double precision, dimension(:), allocatable, parameter d
integer ndir
Number of spatial dimensions (components) for vector variables.
double precision, dimension(:,:), allocatable dx
Module containing all the particle routines.
subroutine particles_init()
Initialize particle data and parameters.
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:55
procedure(sub_write_info), pointer phys_write_info
Definition mod_physics.t:77
procedure(sub_get_flux), pointer phys_get_flux
Definition mod_physics.t:64
procedure(sub_get_cbounds), pointer phys_get_cbounds
Definition mod_physics.t:63
procedure(sub_get_dt), pointer phys_get_dt
Definition mod_physics.t:67
procedure(sub_add_source_geom), pointer phys_add_source_geom
Definition mod_physics.t:68
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:54
character(len=name_len) physics_type
String describing the physics type of the simulation.
Definition mod_physics.t:50
procedure(sub_get_cmax), pointer phys_get_cmax
Definition mod_physics.t:57
logical phys_energy
Solve energy equation or not.
Definition mod_physics.t:35
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)
double precision, dimension(^nd), public, protected rho_v
subroutine, public rho_phys_init()
logical, public, protected rho_particles
Whether particles module is added.
integer, public, protected rho_
Definition mod_rho_phys.t:7
integer nw
Total number of variables.
integer number_species
number of species: each species has different characterictic speeds and should be used accordingly in...