MPI-AMRVAC  2.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code
mod_variables.t
Go to the documentation of this file.
3 
4  implicit none
5  public
6 
7  !> Number of flux variables
8  integer :: nwflux = 0
9 
10  !> Number of flux variables which need user to specify boundary type
11  integer :: nwfluxbc = 0
12 
13  !> Number of auxiliary variables
14  integer :: nwaux = 0
15 
16  !> Number of extra variables
17  integer :: nwextra = 0
18 
19  !> Total number of variables
20  integer :: nw = 0
21 
22  !> Total number of stagger variables
23  integer :: nws = 0
24 
25  !> Number of vector variables (used for writing output)
26  integer :: nvector = 0
27 
28  !> Indices of vector variables
29  integer, dimension(:), allocatable :: iw_vector
30 
31  !> Maximum number of variables
32  integer, parameter :: max_nw = 50
33 
34  !> Primitive variable names
35  character(len=name_len) :: prim_wnames(max_nw)
36 
37  !> Conservative variable names
38  character(len=name_len) :: cons_wnames(max_nw)
39 
40  ! Global indices of variables that are often used
41 
42  !> Index of the (gas) density
43  integer, protected :: iw_rho = -1
44 
45  !> Indices of the momentum density
46  integer, allocatable, protected :: iw_mom(:)
47 
48  !> Index of the energy density
49  integer, protected :: iw_e = -1
50 
51  !> Indices of the magnetic field components
52  integer, allocatable, protected :: iw_mag(:)
53 
54 contains
55 
56  !> Set generic flux variable
57  function var_set_fluxvar(name_cons, name_prim, ix, need_bc) result(iw)
58  character(len=*), intent(in) :: name_cons !< Conservative name
59  character(len=*), intent(in) :: name_prim !< Primitive name
60  integer, intent(in), optional :: ix !< Optional index (to make var1, var2, ...)
61  logical, intent(in), optional :: need_bc !< Require boundary condition (default: true)
62  integer :: iw
63  logical :: add_bc
64 
65  nwflux = nwflux + 1
66  nw = nw + 1
67  iw = nwflux
68 
69  add_bc = .true.
70  if (present(need_bc)) add_bc = need_bc
71  if (add_bc) nwfluxbc = nwfluxbc + 1
72 
73  if (.not. present(ix)) then
74  prim_wnames(nwflux) = name_cons
75  cons_wnames(nwflux) = name_prim
76  else
77  write(cons_wnames(nwflux),"(A,I0)") name_cons, ix
78  write(prim_wnames(nwflux),"(A,I0)") name_prim, ix
79  end if
80  end function var_set_fluxvar
81 
82  !> Set extra variable, which is not advected and has no boundary conditions.
83  !> This has to be done after defining flux variables and auxiliary variables.
84  function var_set_extravar(name_cons, name_prim, ix) result(iw)
85  character(len=*), intent(in) :: name_cons, name_prim
86  integer, intent(in), optional :: ix
87  integer :: iw
88 
89  nwextra = nwextra + 1
90  nw = nw + 1
91  iw = nw
92 
93  if (.not. present(ix)) then
94  prim_wnames(iw) = name_cons
95  cons_wnames(iw) = name_prim
96  else
97  write(cons_wnames(iw),"(A,I0)") name_cons, ix
98  write(prim_wnames(iw),"(A,I0)") name_prim, ix
99  end if
100  end function var_set_extravar
101 
102  !> Set auxiliary variable, which is not advected but has boundary conditions.
103  !> This has to be done after defining flux variables.
104  function var_set_auxvar(name_cons, name_prim, ix) result(iw)
105  character(len=*), intent(in) :: name_cons, name_prim
106  integer, intent(in), optional :: ix
107  integer :: iw
108 
109  nwaux = nwaux + 1
110  nw = nw + 1
111  iw = nw
112 
113  if (.not. present(ix)) then
114  prim_wnames(iw) = name_cons
115  cons_wnames(iw) = name_prim
116  else
117  write(cons_wnames(iw),"(A,I0)") name_cons, ix
118  write(prim_wnames(iw),"(A,I0)") name_prim, ix
119  end if
120  end function var_set_auxvar
121 
122  !> Set density variable
123  function var_set_rho() result(iw)
124  integer :: iw
125 
126  nwflux = nwflux + 1
127  nwfluxbc = nwfluxbc + 1
128  nw = nw + 1
129  iw_rho = nwflux
130  iw = nwflux
131  prim_wnames(nwflux) = 'rho'
132  cons_wnames(nwflux) = 'rho'
133  end function var_set_rho
134 
135  !> Set momentum variables
136  function var_set_momentum(ndir) result(iw)
137  integer, intent(in) :: ndir
138  integer :: iw(ndir), idir
139 
140  if (allocated(iw_mom)) &
141  call mpistop("Error: set_mom was already called")
142  allocate(iw_mom(ndir))
143 
144  do idir = 1, ndir
145  nwflux = nwflux + 1
146  nwfluxbc = nwfluxbc + 1
147  nw = nw + 1
148  iw_mom(idir) = nwflux
149  iw(idir) = nwflux
150  write(cons_wnames(nwflux),"(A1,I1)") "m", idir
151  write(prim_wnames(nwflux),"(A1,I1)") "v", idir
152  end do
153  end function var_set_momentum
154 
155  !> Set energy variable
156  function var_set_energy() result(iw)
157  integer :: iw
158 
159  nwflux = nwflux + 1
160  nwfluxbc = nwfluxbc + 1
161  nw = nw + 1
162  iw_e = nwflux
163  iw = nwflux
164  cons_wnames(nwflux) = 'e'
165  prim_wnames(nwflux) = 'p'
166  end function var_set_energy
167 
168  !> Set magnetic field variables
169  function var_set_bfield(ndir) result(iw)
170  integer, intent(in) :: ndir
171  integer :: iw(ndir), idir
172 
173  if (allocated(iw_mag)) &
174  call mpistop("Error: set_mag was already called")
175  allocate(iw_mag(ndir))
176 
177  do idir = 1, ndir
178  nwflux = nwflux + 1
179  nwfluxbc = nwfluxbc + 1
180  nw = nw + 1
181  iw_mag(idir) = nwflux
182  iw(idir) = nwflux
183  write(cons_wnames(nwflux),"(A1,I1)") "b", idir
184  write(prim_wnames(nwflux),"(A1,I1)") "b", idir
185  end do
186  end function var_set_bfield
187 
188 end module mod_variables
integer, dimension(:), allocatable, protected iw_mom
Indices of the momentum density.
Definition: mod_variables.t:46
integer nwaux
Number of auxiliary variables.
Definition: mod_variables.t:14
integer nwflux
Number of flux variables.
Definition: mod_variables.t:8
integer nwextra
Number of extra variables.
Definition: mod_variables.t:17
integer, dimension(:), allocatable iw_vector
Indices of vector variables.
Definition: mod_variables.t:29
character(len=name_len), dimension(max_nw) cons_wnames
Conservative variable names.
Definition: mod_variables.t:38
integer nvector
Number of vector variables (used for writing output)
Definition: mod_variables.t:26
Module with basic data types used in amrvac.
character(len=name_len), dimension(max_nw) prim_wnames
Primitive variable names.
Definition: mod_variables.t:35
integer function var_set_auxvar(name_cons, name_prim, ix)
Set auxiliary variable, which is not advected but has boundary conditions. This has to be done after ...
integer nwfluxbc
Number of flux variables which need user to specify boundary type.
Definition: mod_variables.t:11
integer function var_set_fluxvar(name_cons, name_prim, ix, need_bc)
Set generic flux variable.
Definition: mod_variables.t:58
integer, dimension(:), allocatable, protected iw_mag
Indices of the magnetic field components.
Definition: mod_variables.t:52
integer function var_set_rho()
Set density variable.
subroutine mpistop(message)
Exit MPI-AMRVAC with an error message.
Definition: comm_lib.t:198
integer function var_set_extravar(name_cons, name_prim, ix)
Set extra variable, which is not advected and has no boundary conditions. This has to be done after d...
Definition: mod_variables.t:85
integer nw
Total number of variables.
Definition: mod_variables.t:20
integer, parameter max_nw
Maximum number of variables.
Definition: mod_variables.t:32
integer, protected iw_e
Index of the energy density.
Definition: mod_variables.t:49
integer function, dimension(ndir) var_set_bfield(ndir)
Set magnetic field variables.
integer, protected iw_rho
Index of the (gas) density.
Definition: mod_variables.t:43
integer function, dimension(ndir) var_set_momentum(ndir)
Set momentum variables.
integer function var_set_energy()
Set energy variable.
integer nws
Total number of stagger variables.
Definition: mod_variables.t:23