MPI-AMRVAC  2.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code
mod_physics.t
Go to the documentation of this file.
1 !> This module defines the procedures of a physics module. It contains function
2 !> pointers for the various supported routines. An actual physics module has to
3 !> set these pointers to its implementation of these routines.
4 module mod_physics
5  use mod_global_parameters, only: name_len, max_nw
9 
10  implicit none
11  public
12 
13  !> String describing the physics type of the simulation
14  character(len=name_len) :: physics_type = ""
15 
16  !> To use wider stencils in flux calculations. A value of 1 will extend it by
17  !> one cell in both directions, in any dimension
18  integer :: phys_wider_stencil = 0
19 
20  !> Whether the physics routines require diagonal ghost cells, for example for
21  !> computing a curl.
22  logical :: phys_req_diagonal = .true.
23 
24  !> Array per direction per variable, which can be used to specify that certain
25  !> fluxes have to be treated differently
26  integer, allocatable :: flux_type(:, :)
27 
28  !> Indicates a normal flux
29  integer, parameter :: flux_default = 0
30  !> Indicates the flux should be treated with tvdlf
31  integer, parameter :: flux_tvdlf = 1
32  !> Indicates dissipation should be omitted
33  integer, parameter :: flux_no_dissipation = 2
34 
35  !> Type for special methods defined per variable
37  integer :: test
38  !> If this is set, use the routine as a capacity function when adding fluxes
39  procedure(sub_get_var), pointer, nopass :: inv_capacity => null()
40  end type iw_methods
41 
42  !> Special methods defined per variable
43  type(iw_methods) :: phys_iw_methods(max_nw)
44 
45  procedure(sub_check_params), pointer :: phys_check_params => null()
46  procedure(sub_convert), pointer :: phys_to_conserved => null()
47  procedure(sub_convert), pointer :: phys_to_primitive => null()
48  procedure(sub_modify_wlr), pointer :: phys_modify_wlr => null()
49  procedure(sub_get_cmax), pointer :: phys_get_cmax => null()
50  procedure(sub_get_cbounds), pointer :: phys_get_cbounds => null()
51  procedure(sub_get_flux), pointer :: phys_get_flux => null()
52  procedure(sub_get_v_idim), pointer :: phys_get_v_idim => null()
53  procedure(sub_get_dt), pointer :: phys_get_dt => null()
54  procedure(sub_add_source_geom), pointer :: phys_add_source_geom => null()
55  procedure(sub_add_source), pointer :: phys_add_source => null()
56  procedure(sub_global_source), pointer :: phys_global_source => null()
57  procedure(sub_get_aux), pointer :: phys_get_aux => null()
58  procedure(sub_check_w), pointer :: phys_check_w => null()
59  procedure(sub_get_pthermal), pointer :: phys_get_pthermal => null()
60  procedure(sub_boundary_adjust), pointer :: phys_boundary_adjust => null()
61  procedure(sub_write_info), pointer :: phys_write_info => null()
62  procedure(sub_angmomfix), pointer :: phys_angmomfix => null()
63  procedure(sub_small_values), pointer :: phys_handle_small_values => null()
64  procedure(sub_update_faces), pointer :: phys_update_faces => null()
65  procedure(sub_face_to_center), pointer :: phys_face_to_center => null()
66 
67  abstract interface
68 
69  subroutine sub_check_params
70  end subroutine sub_check_params
71 
74  end subroutine sub_boundary_adjust
75 
76  subroutine sub_convert(ixI^L, ixO^L, w, x)
78  integer, intent(in) :: ixI^L, ixO^L
79  double precision, intent(inout) :: w(ixi^s, nw)
80  double precision, intent(in) :: x(ixi^s, 1:^nd)
81  end subroutine sub_convert
82 
83  subroutine sub_modify_wlr(ixI^L, ixO^L, wLC, wRC, wLp, wRp, s, idir)
85  integer, intent(in) :: ixI^L, ixO^L, idir
86  double precision, intent(inout) :: wLC(ixi^s,1:nw), wRC(ixi^s,1:nw)
87  double precision, intent(inout) :: wLp(ixi^s,1:nw), wRp(ixi^s,1:nw)
88  type(state) :: s
89  end subroutine sub_modify_wlr
90 
91  subroutine sub_get_cmax(w, x, ixI^L, ixO^L, idim, cmax)
93  integer, intent(in) :: ixI^L, ixO^L, idim
94  double precision, intent(in) :: w(ixi^s, nw), x(ixi^s, 1:^nd)
95  double precision, intent(inout) :: cmax(ixi^s)
96  end subroutine sub_get_cmax
97 
98  subroutine sub_get_v_idim(w,x,ixI^L,ixO^L,idim,v)
100 
101  integer, intent(in) :: ixI^L, ixO^L, idim
102  double precision, intent(in) :: w(ixi^s,nw), x(ixi^s,1:^nd)
103  double precision, intent(out) :: v(ixi^s)
104 
105  end subroutine sub_get_v_idim
106 
107  subroutine sub_get_cbounds(wLC, wRC, wLp, wRp, x, ixI^L, ixO^L, idim, cmax, cmin)
109  integer, intent(in) :: ixI^L, ixO^L, idim
110  double precision, intent(in) :: wLC(ixi^s, nw), wRC(ixi^s, nw)
111  double precision, intent(in) :: wLp(ixi^s, nw), wRp(ixi^s, nw)
112  double precision, intent(in) :: x(ixi^s, 1:^nd)
113  double precision, intent(inout) :: cmax(ixi^s)
114  double precision, intent(inout), optional :: cmin(ixi^s)
115  end subroutine sub_get_cbounds
116 
117  subroutine sub_get_flux(wC, w, x, ixI^L, ixO^L, idim, f)
119  integer, intent(in) :: ixI^L, ixO^L, idim
120  double precision, intent(in) :: wC(ixi^s, 1:nw)
121  double precision, intent(in) :: w(ixi^s, 1:nw)
122  double precision, intent(in) :: x(ixi^s, 1:^nd)
123  double precision, intent(out) :: f(ixi^s, nwflux)
124  end subroutine sub_get_flux
125 
126  subroutine sub_add_source_geom(qdt, ixI^L, ixO^L, wCT, w, x)
128  integer, intent(in) :: ixI^L, ixO^L
129  double precision, intent(in) :: qdt, x(ixi^s, 1:^nd)
130  double precision, intent(inout) :: wCT(ixi^s, 1:nw), w(ixi^s, 1:nw)
131  end subroutine sub_add_source_geom
132 
133  subroutine sub_add_source(qdt, ixI^L, ixO^L, wCT, w, x, &
134  qsourcesplit, active)
136  integer, intent(in) :: ixI^L, ixO^L
137  double precision, intent(in) :: qdt
138  double precision, intent(in) :: wCT(ixi^s, 1:nw), x(ixi^s, 1:ndim)
139  double precision, intent(inout) :: w(ixi^s, 1:nw)
140  logical, intent(in) :: qsourcesplit
141  logical, intent(inout) :: active !< Needs to be set to true when active
142  end subroutine sub_add_source
143 
144  !> Add global source terms on complete domain (potentially implicit)
145  subroutine sub_global_source(qdt, qt, active)
146  double precision, intent(in) :: qdt !< Current time step
147  double precision, intent(in) :: qt !< Current time
148  logical, intent(inout) :: active !< Output if the source is active
149  end subroutine sub_global_source
150 
151  subroutine sub_get_dt(w, ixI^L, ixO^L, dtnew, dx^D, x)
153  integer, intent(in) :: ixI^L, ixO^L
154  double precision, intent(in) :: dx^D, x(ixi^s, 1:^nd)
155  double precision, intent(in) :: w(ixi^s, 1:nw)
156  double precision, intent(inout) :: dtnew
157  end subroutine sub_get_dt
158 
159  subroutine sub_get_aux(clipping,w,x,ixI^L,ixO^L,subname)
161  integer, intent(in) :: ixI^L, ixO^L
162  double precision, intent(in) :: x(ixi^s,1:ndim)
163  double precision, intent(inout) :: w(ixi^s,nw)
164  logical, intent(in) :: clipping
165  character(len=*) :: subname
166  end subroutine sub_get_aux
167 
168  subroutine sub_check_w(primitive, ixI^L, ixO^L, w, w_flag)
170  logical, intent(in) :: primitive
171  integer, intent(in) :: ixI^L, ixO^L
172  double precision, intent(in) :: w(ixi^s,nw)
173  integer, intent(inout) :: w_flag(ixg^t)
174  end subroutine sub_check_w
175 
176  subroutine sub_get_pthermal(w,x,ixI^L,ixO^L,pth)
178  integer, intent(in) :: ixI^L, ixO^L
179  double precision, intent(in) :: w(ixi^s,nw)
180  double precision, intent(in) :: x(ixi^s,1:ndim)
181  double precision, intent(out):: pth(ixi^s)
182  end subroutine sub_get_pthermal
183 
184  subroutine sub_write_info(file_handle)
185  integer, intent(in) :: file_handle
186  end subroutine sub_write_info
187 
188  subroutine sub_angmomfix(fC,x,wnew,ixI^L,ixO^L,idim)
190  integer, intent(in) :: ixI^L, ixO^L
191  double precision, intent(in) :: x(ixi^s,1:ndim)
192  double precision, intent(inout) :: fC(ixi^s,1:nwflux,1:ndim), wnew(ixi^s,1:nw)
193  integer, intent(in) :: idim
194  end subroutine sub_angmomfix
195 
196  subroutine sub_small_values(primitive, w, x, ixI^L, ixO^L, subname)
198  logical, intent(in) :: primitive
199  integer, intent(in) :: ixI^L,ixO^L
200  double precision, intent(inout) :: w(ixi^s,1:nw)
201  double precision, intent(in) :: x(ixi^s,1:ndim)
202  character(len=*), intent(in) :: subname
203  end subroutine sub_small_values
204 
205  subroutine sub_get_var(ixI^L, ixO^L, w, out)
207  integer, intent(in) :: ixI^L, ixO^L
208  double precision, intent(in) :: w(ixi^s, nw)
209  double precision, intent(out) :: out(ixo^s)
210  end subroutine sub_get_var
211 
212  subroutine sub_update_faces(ixI^L,ixO^L,qdt,wprim,fC,fE,sCT,s)
214  integer, intent(in) :: ixI^L, ixO^L
215  double precision, intent(in) :: qdt
216  ! cell-center primitive variables
217  double precision, intent(in) :: wprim(ixi^s,1:nw)
218  ! velocity structure
219  type(state) :: sCT, s
220  double precision, intent(in) :: fC(ixi^s,1:nwflux,1:ndim)
221  double precision, intent(inout) :: fE(ixi^s,7-2*ndim:3)
222  end subroutine sub_update_faces
223 
224  subroutine sub_face_to_center(ixO^L,s)
226  integer, intent(in) :: ixO^L
227  type(state) :: s
228  end subroutine sub_face_to_center
229 
230  end interface
231 
232 contains
233 
234  subroutine phys_check()
236 
240 
241  if (physics_type == "") call mpistop("Error: no physics module loaded")
242 
243  call phys_hllc_check()
244  call phys_roe_check()
245  call phys_ppm_check()
246 
247  ! Checks whether the required physics methods have been defined
248  if (.not. associated(phys_check_params)) &
250 
251  if (.not. associated(phys_to_conserved)) &
252  call mpistop("Error: phys_to_conserved not defined")
253 
254  if (.not. associated(phys_to_primitive)) &
255  call mpistop("Error: phys_to_primitive not defined")
256 
257  if (.not. associated(phys_modify_wlr)) &
259 
260  if (.not. associated(phys_get_cmax)) &
261  call mpistop("Error: no phys_get_cmax not defined")
262 
263  if (.not. associated(phys_get_cbounds)) &
264  call mpistop("Error: no phys_get_cbounds not defined")
265 
266  if (.not. associated(phys_get_flux)) &
267  call mpistop("Error: no phys_get_flux not defined")
268 
269  if (.not. associated(phys_get_dt)) &
270  call mpistop("Error: no phys_get_dt not defined")
271 
272  if (.not. associated(phys_add_source_geom)) &
274 
275  if (.not. associated(phys_add_source)) &
277 
278  if (.not. associated(phys_get_aux)) &
280 
281  if (.not. associated(phys_check_w)) &
283 
284  if (.not. associated(phys_get_pthermal)) &
286 
287  if (.not. associated(phys_boundary_adjust)) &
289 
290  if (.not. associated(phys_write_info)) &
292 
293  if (.not. associated(phys_angmomfix)) &
295 
296  if (.not. associated(phys_handle_small_values)) &
298 
299  if (.not. associated(phys_update_faces)) &
301 
302  if (.not. associated(phys_face_to_center)) &
304 
305  end subroutine phys_check
306 
307  subroutine dummy_init_params
308  end subroutine dummy_init_params
309 
310  subroutine dummy_check_params
311  end subroutine dummy_check_params
312 
313  subroutine dummy_modify_wlr(ixI^L, ixO^L, wLC, wRC, wLp, wRp, s, idir)
315  integer, intent(in) :: ixI^L, ixO^L, idir
316  double precision, intent(inout) :: wLC(ixi^s,1:nw), wRC(ixi^s,1:nw)
317  double precision, intent(inout) :: wLp(ixi^s,1:nw), wRp(ixi^s,1:nw)
318  type(state) :: s
319  end subroutine dummy_modify_wlr
320 
321  subroutine dummy_add_source_geom(qdt, ixI^L, ixO^L, wCT, w, x)
323  integer, intent(in) :: ixI^L, ixO^L
324  double precision, intent(in) :: qdt, x(ixi^s, 1:^nd)
325  double precision, intent(inout) :: wCT(ixi^s, 1:nw), w(ixi^s, 1:nw)
326  end subroutine dummy_add_source_geom
327 
328  subroutine dummy_add_source(qdt, ixI^L, ixO^L, wCT, w, x, &
329  qsourcesplit, active)
331  integer, intent(in) :: ixI^L, ixO^L
332  double precision, intent(in) :: qdt
333  double precision, intent(in) :: wCT(ixi^s, 1:nw), x(ixi^s, 1:ndim)
334  double precision, intent(inout) :: w(ixi^s, 1:nw)
335  logical, intent(in) :: qsourcesplit
336  logical, intent(inout) :: active
337  ! Don't have to set active, since it starts as .false.
338  end subroutine dummy_add_source
339 
340  subroutine dummy_get_aux(clipping,w,x,ixI^L,ixO^L,subname)
342  integer, intent(in) :: ixI^L, ixO^L
343  double precision, intent(in) :: x(ixi^s,1:ndim)
344  double precision, intent(inout) :: w(ixi^s,nw)
345  logical, intent(in) :: clipping
346  character(len=*) :: subname
347  end subroutine dummy_get_aux
348 
349  subroutine dummy_check_w(primitive, ixI^L, ixO^L, w, w_flag)
351  logical, intent(in) :: primitive
352  integer, intent(in) :: ixI^L, ixO^L
353  double precision, intent(in) :: w(ixi^s,nw)
354  integer, intent(inout) :: w_flag(ixg^t)
355 
356  w_flag(ixo^s) = 0 ! All okay
357  end subroutine dummy_check_w
358 
359  subroutine dummy_get_pthermal(w, x, ixI^L, ixO^L, pth)
361 
362  integer, intent(in) :: ixI^L, ixO^L
363  double precision, intent(in) :: w(ixi^s, nw)
364  double precision, intent(in) :: x(ixi^s, 1:ndim)
365  double precision, intent(out):: pth(ixi^s)
366 
367  call mpistop("No get_pthermal method specified")
368  end subroutine dummy_get_pthermal
369 
370  subroutine dummy_boundary_adjust
371  end subroutine dummy_boundary_adjust
372 
373  subroutine dummy_write_info(fh)
375  integer, intent(in) :: fh !< File handle
376  integer, dimension(MPI_STATUS_SIZE) :: st
377  integer :: er
378 
379  ! Number of physics parameters
380  integer, parameter :: n_par = 0
381 
382  call mpi_file_write(fh, n_par, 1, mpi_integer, st, er)
383  end subroutine dummy_write_info
384 
385  subroutine dummy_angmomfix(fC,x,wnew,ixI^L,ixO^L,idim)
387  double precision, intent(in) :: x(ixi^s,1:ndim)
388  double precision, intent(inout) :: fC(ixi^s,1:nwflux,1:ndim), wnew(ixi^s,1:nw)
389  integer, intent(in) :: ixI^L, ixO^L
390  integer, intent(in) :: idim
391  end subroutine dummy_angmomfix
392 
393  subroutine dummy_small_values(primitive, w, x, ixI^L, ixO^L, subname)
395  logical, intent(in) :: primitive
396  integer, intent(in) :: ixI^L,ixO^L
397  double precision, intent(inout) :: w(ixi^s,1:nw)
398  double precision, intent(in) :: x(ixi^s,1:ndim)
399  character(len=*), intent(in) :: subname
400  end subroutine dummy_small_values
401 
402  subroutine dummy_update_faces(ixI^L,ixO^L,qdt,wprim,fC,fE,sCT,s)
404  integer, intent(in) :: ixI^L, ixO^L
405  double precision, intent(in) :: qdt
406  ! cell-center primitive variables
407  double precision, intent(in) :: wprim(ixi^s,1:nw)
408  type(state) :: sCT, s
409  double precision, intent(in) :: fC(ixi^s,1:nwflux,1:ndim)
410  double precision, intent(inout) :: fE(ixi^s,7-2*ndim:3)
411  end subroutine dummy_update_faces
412 
413  subroutine dummy_face_to_center(ixO^L,s)
415  integer, intent(in) :: ixO^L
416  type(state) :: s
417  end subroutine dummy_face_to_center
418 
419 end module mod_physics
type(iw_methods), dimension(max_nw) phys_iw_methods
Special methods defined per variable.
Definition: mod_physics.t:43
This module contains definitions of global parameters and variables and some generic functions/subrou...
subroutine dummy_angmomfix(fC, x, wnew, ixIL, ixOL, idim)
Definition: mod_physics.t:386
subroutine phys_hllc_check
procedure(sub_global_source), pointer phys_global_source
Definition: mod_physics.t:56
subroutine dummy_modify_wlr(ixIL, ixOL, wLC, wRC, wLp, wRp, s, idir)
Definition: mod_physics.t:314
subroutine dummy_boundary_adjust
Definition: mod_physics.t:371
character(len=name_len) physics_type
String describing the physics type of the simulation.
Definition: mod_physics.t:14
subroutine dummy_init_params
Definition: mod_physics.t:308
Add global source terms on complete domain (potentially implicit)
Definition: mod_physics.t:145
subroutine dummy_write_info(fh)
Definition: mod_physics.t:374
Type for special methods defined per variable.
Definition: mod_physics.t:36
integer ndir
Number of spatial dimensions (components) for vector variables.
procedure(sub_check_w), pointer phys_check_w
Definition: mod_physics.t:58
procedure(sub_face_to_center), pointer phys_face_to_center
Definition: mod_physics.t:65
procedure(sub_small_values), pointer phys_handle_small_values
Definition: mod_physics.t:63
procedure(sub_boundary_adjust), pointer phys_boundary_adjust
Definition: mod_physics.t:60
logical phys_req_diagonal
Whether the physics routines require diagonal ghost cells, for example for computing a curl...
Definition: mod_physics.t:22
procedure(sub_update_faces), pointer phys_update_faces
Definition: mod_physics.t:64
subroutine dummy_update_faces(ixIL, ixOL, qdt, wprim, fC, fE, sCT, s)
Definition: mod_physics.t:403
procedure(sub_angmomfix), pointer phys_angmomfix
Definition: mod_physics.t:62
subroutine dummy_add_source_geom(qdt, ixIL, ixOL, wCT, w, x)
Definition: mod_physics.t:322
procedure(sub_convert), pointer phys_to_conserved
Definition: mod_physics.t:46
subroutine phys_check()
Definition: mod_physics.t:235
subroutine dummy_add_source(qdt, ixIL, ixOL, wCT, w, x, qsourcesplit, active)
Definition: mod_physics.t:330
integer, parameter flux_default
Indicates a normal flux.
Definition: mod_physics.t:29
procedure(sub_get_flux), pointer phys_get_flux
Definition: mod_physics.t:51
integer, parameter flux_no_dissipation
Indicates dissipation should be omitted.
Definition: mod_physics.t:33
procedure(sub_get_dt), pointer phys_get_dt
Definition: mod_physics.t:53
subroutine phys_roe_check()
procedure(sub_add_source_geom), pointer phys_add_source_geom
Definition: mod_physics.t:54
subroutine dummy_check_w(primitive, ixIL, ixOL, w, w_flag)
Definition: mod_physics.t:350
subroutine phys_ppm_check
subroutine mpistop(message)
Exit MPI-AMRVAC with an error message.
Definition: comm_lib.t:198
procedure(sub_check_params), pointer phys_check_params
Definition: mod_physics.t:45
subroutine dummy_face_to_center(ixOL, s)
Definition: mod_physics.t:414
subroutine dummy_check_params
Definition: mod_physics.t:311
integer, parameter ndim
Number of spatial dimensions for grid variables.
subroutine dummy_get_pthermal(w, x, ixIL, ixOL, pth)
Definition: mod_physics.t:360
integer phys_wider_stencil
To use wider stencils in flux calculations. A value of 1 will extend it by one cell in both direction...
Definition: mod_physics.t:18
procedure(sub_get_v_idim), pointer phys_get_v_idim
Definition: mod_physics.t:52
procedure(sub_get_cmax), pointer phys_get_cmax
Definition: mod_physics.t:49
This module defines the procedures of a physics module. It contains function pointers for the various...
Definition: mod_physics.t:4
procedure(sub_add_source), pointer phys_add_source
Definition: mod_physics.t:55
procedure(sub_convert), pointer phys_to_primitive
Definition: mod_physics.t:47
subroutine dummy_small_values(primitive, w, x, ixIL, ixOL, subname)
Definition: mod_physics.t:394
procedure(sub_get_aux), pointer phys_get_aux
Definition: mod_physics.t:57
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:26
procedure(sub_get_pthermal), pointer phys_get_pthermal
Definition: mod_physics.t:59
subroutine dummy_get_aux(clipping, w, x, ixIL, ixOL, subname)
Definition: mod_physics.t:341
procedure(sub_get_cbounds), pointer phys_get_cbounds
Definition: mod_physics.t:50
procedure(sub_modify_wlr), pointer phys_modify_wlr
Definition: mod_physics.t:48
procedure(sub_write_info), pointer phys_write_info
Definition: mod_physics.t:61
integer, parameter flux_tvdlf
Indicates the flux should be treated with tvdlf.
Definition: mod_physics.t:31