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  !> Index of the internal energy density
51  integer, protected :: iw_eaux = -1
52 
53  !> Indices of the magnetic field components
54  integer, allocatable, protected :: iw_mag(:)
55 
56 contains
57 
58  !> Set generic flux variable
59  function var_set_fluxvar(name_cons, name_prim, ix, need_bc) result(iw)
60  character(len=*), intent(in) :: name_cons !< Conservative name
61  character(len=*), intent(in) :: name_prim !< Primitive name
62  integer, intent(in), optional :: ix !< Optional index (to make var1, var2, ...)
63  logical, intent(in), optional :: need_bc !< Require boundary condition (default: true)
64  integer :: iw
65  logical :: add_bc
66 
67  nwflux = nwflux + 1
68  nw = nw + 1
69  iw = nwflux
70 
71  add_bc = .true.
72  if (present(need_bc)) add_bc = need_bc
73  if (add_bc) nwfluxbc = nwfluxbc + 1
74 
75  if (.not. present(ix)) then
76  prim_wnames(nwflux) = name_cons
77  cons_wnames(nwflux) = name_prim
78  else
79  write(cons_wnames(nwflux),"(A,I0)") name_cons, ix
80  write(prim_wnames(nwflux),"(A,I0)") name_prim, ix
81  end if
82  end function var_set_fluxvar
83 
84  !> Set extra variable, which is not advected and has no boundary conditions.
85  !> This has to be done after defining flux variables and auxiliary variables.
86  function var_set_extravar(name_cons, name_prim, ix) result(iw)
87  character(len=*), intent(in) :: name_cons, name_prim
88  integer, intent(in), optional :: ix
89  integer :: iw
90 
91  nwextra = nwextra + 1
92  nw = nw + 1
93  iw = nw
94 
95  if (.not. present(ix)) then
96  prim_wnames(iw) = name_cons
97  cons_wnames(iw) = name_prim
98  else
99  write(cons_wnames(iw),"(A,I0)") name_cons, ix
100  write(prim_wnames(iw),"(A,I0)") name_prim, ix
101  end if
102  end function var_set_extravar
103 
104  !> Set auxiliary variable, which is not advected but has boundary conditions.
105  !> This has to be done after defining flux variables.
106  function var_set_auxvar(name_cons, name_prim, ix) result(iw)
107  character(len=*), intent(in) :: name_cons, name_prim
108  integer, intent(in), optional :: ix
109  integer :: iw
110 
111  nwaux = nwaux + 1
112  nw = nw + 1
113  iw = nw
114 
115  if (.not. present(ix)) then
116  prim_wnames(iw) = name_cons
117  cons_wnames(iw) = name_prim
118  else
119  write(cons_wnames(iw),"(A,I0)") name_cons, ix
120  write(prim_wnames(iw),"(A,I0)") name_prim, ix
121  end if
122  end function var_set_auxvar
123 
124  !> Set density variable
125  function var_set_rho() result(iw)
126  integer :: iw
127 
128  nwflux = nwflux + 1
129  nwfluxbc = nwfluxbc + 1
130  nw = nw + 1
131  iw_rho = nwflux
132  iw = nwflux
133  prim_wnames(nwflux) = 'rho'
134  cons_wnames(nwflux) = 'rho'
135  end function var_set_rho
136 
137  !> Set momentum variables
138  function var_set_momentum(ndir) result(iw)
139  integer, intent(in) :: ndir
140  integer :: iw(ndir), idir
141 
142  if (allocated(iw_mom)) &
143  call mpistop("Error: set_mom was already called")
144  allocate(iw_mom(ndir))
145 
146  do idir = 1, ndir
147  nwflux = nwflux + 1
148  nwfluxbc = nwfluxbc + 1
149  nw = nw + 1
150  iw_mom(idir) = nwflux
151  iw(idir) = nwflux
152  write(cons_wnames(nwflux),"(A1,I1)") "m", idir
153  write(prim_wnames(nwflux),"(A1,I1)") "v", idir
154  end do
155  end function var_set_momentum
156 
157  !> Set energy variable
158  function var_set_energy() result(iw)
159  integer :: iw
160 
161  nwflux = nwflux + 1
162  nwfluxbc = nwfluxbc + 1
163  nw = nw + 1
164  iw_e = nwflux
165  iw = nwflux
166  cons_wnames(nwflux) = 'e'
167  prim_wnames(nwflux) = 'p'
168  end function var_set_energy
169 
170  !> Set magnetic field variables
171  function var_set_bfield(ndir) result(iw)
172  integer, intent(in) :: ndir
173  integer :: iw(ndir), idir
174 
175  if (allocated(iw_mag)) &
176  call mpistop("Error: set_mag was already called")
177  allocate(iw_mag(ndir))
178 
179  do idir = 1, ndir
180  nwflux = nwflux + 1
181  nwfluxbc = nwfluxbc + 1
182  nw = nw + 1
183  iw_mag(idir) = nwflux
184  iw(idir) = nwflux
185  write(cons_wnames(nwflux),"(A1,I1)") "b", idir
186  write(prim_wnames(nwflux),"(A1,I1)") "b", idir
187  end do
188  end function var_set_bfield
189 
190  !> Set internal energy variable
191  function var_set_internal_energy() result(iw)
192  integer :: iw
193 
194  nwflux = nwflux + 1
195  nw = nw + 1
196  iw_eaux = nwflux
197  iw = nwflux
198  cons_wnames(nwflux) = 'eaux'
199  prim_wnames(nwflux) = 'paux'
200  end function var_set_internal_energy
201 
202 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, protected iw_eaux
Index of the internal energy density.
Definition: mod_variables.t:51
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:60
integer, dimension(:), allocatable, protected iw_mag
Indices of the magnetic field components.
Definition: mod_variables.t:54
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:87
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 function var_set_internal_energy()
Set internal energy variable.
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