MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
Loading...
Searching...
No Matches
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 in w
14 integer :: nwaux = 0
15
16 !> Number of extra variables in w
17 integer :: nwextra = 0
18
19 !> Number of extra variables in wextra seperated from w
20 integer :: nw_extra = 0
21
22 !> Total number of variables
23 integer :: nw = 0
24
25 !> Total number of stagger variables
26 integer :: nws = 0
27
28 !> Number of variables which need to be updated in ghost cells
29 integer :: nwgc = 0
30
31 !> Number of vector variables (used for writing output)
32 integer :: nvector = 0
33
34 !> Indices of vector variables
35 integer, dimension(:), allocatable :: iw_vector
36
37 ! the number of the first w variable to exchange ghost cells
38 integer :: iwstart=1
39
40 !> Maximum number of variables
41 integer, parameter :: max_nw = 50
42
43 ! Global indices of variables that are often used
44
45 !> Index of the (gas) density
46 integer :: iw_rho = -1
47
48 !> Indices of the momentum density
49 integer, allocatable :: iw_mom(:)
50
51 !> Index of the energy density
52 integer :: iw_e = -1
53
54 !> Index of the radiation energy density
55 integer :: iw_r_e = -1
56
57 !> Index of electron number density
58 integer :: iw_ne = -1
59
60 !> Index of temperature
61 integer :: iw_te = -1
62
63 !> Index of heat flux
64 integer :: iw_q = -1
65
66
67 !> Indices of the magnetic field components
68 integer, allocatable, protected :: iw_mag(:)
69
70 !> Index of the cutoff temperature for the TRAC method
71 integer :: iw_tcoff = -1
72 integer :: iw_tweight= -1
73
74 !> number of species: each species has different characterictic speeds and should
75 !> be used accordingly in mod_finite_volume and mod_finite_difference
76 integer :: number_species = 1
77
78 !> index of the var
79 !> whose velocity appears in the induction eq.
80 integer :: index_v_mag = 1
81
82 !> the indices in 1:nwflux array are assumed consecutive for each species
83 !> this array should be of size number_species and contain the first index in the array of
84 !> the number_species
85 integer, allocatable :: start_indices(:)
86 !> the indices in 1:nwflux array are assumed consecutive for each species
87 !> this array should be of size number_species and contain the last index in the array of
88 !> the first number_species, the last index for the last one is nwflux
89 integer, allocatable :: stop_indices(:)
90
91 ! indices of equi for the species index_v_mag
92 ! these are needed for hlld solver, TODO: consider moving in a separate file
93 integer :: iw_equi_rho = -1
94 integer :: iw_equi_p = -1
95
96 !> Primitive variable names
97 character(len=name_len) :: prim_wnames(max_nw)
98
99 !> Conservative variable names
100 character(len=name_len) :: cons_wnames(max_nw)
101
102contains
103
104 !> Set generic flux variable
105 function var_set_fluxvar(name_cons, name_prim, ix, need_bc) result(iw)
106 character(len=*), intent(in) :: name_cons !< Conservative name
107 character(len=*), intent(in) :: name_prim !< Primitive name
108 integer, intent(in), optional :: ix !< Optional index (to make var1, var2, ...)
109 logical, intent(in), optional :: need_bc !< Require boundary condition (default: true)
110 integer :: iw
111 logical :: add_bc
112
113 nwflux = nwflux + 1
114 nw = nw + 1
115 iw = nwflux
116
117 add_bc = .true.
118 if (present(need_bc)) add_bc = need_bc
119 if (add_bc) nwfluxbc = nwfluxbc + 1
120
121 if (.not. present(ix)) then
122 cons_wnames(nwflux) = name_cons
123 prim_wnames(nwflux) = name_prim
124 else
125 write(cons_wnames(nwflux),"(A,I0)") name_cons, ix
126 write(prim_wnames(nwflux),"(A,I0)") name_prim, ix
127 end if
128 end function var_set_fluxvar
129
130 !> Set extra variable in w, which is not advected and has no boundary conditions.
131 !> This has to be done after defining flux variables and auxiliary variables.
132 function var_set_extravar(name_cons, name_prim, ix) result(iw)
133 character(len=*), intent(in) :: name_cons, name_prim
134 integer, intent(in), optional :: ix
135 integer :: iw
136
137 nwextra = nwextra + 1
138 nw = nw + 1
139 iw = nw
140
141 if (.not. present(ix)) then
142 prim_wnames(iw) = name_cons
143 cons_wnames(iw) = name_prim
144 else
145 write(cons_wnames(iw),"(A,I0)") name_cons, ix
146 write(prim_wnames(iw),"(A,I0)") name_prim, ix
147 end if
148 end function var_set_extravar
149
150 !> Set extra variable in wextra, which is not advected and has no boundary conditions and not output in dat.
151 !> This has to be done after defining flux variables and auxiliary variables.
152 function var_set_wextra() result(iw)
153 integer :: iw
154
155 nw_extra = nw_extra + 1
156 iw = nw_extra
157
158 end function var_set_wextra
159
160 !> Set auxiliary variable, which is not advected but has boundary conditions.
161 !> This has to be done after defining flux variables.
162 function var_set_auxvar(name_cons, name_prim, ix) result(iw)
163 character(len=*), intent(in) :: name_cons, name_prim
164 integer, intent(in), optional :: ix
165 integer :: iw
166
167 nwaux = nwaux + 1
168 nw = nw + 1
169 iw = nw
170
171 if (.not. present(ix)) then
172 prim_wnames(iw) = name_cons
173 cons_wnames(iw) = name_prim
174 else
175 write(cons_wnames(iw),"(A,I0)") name_cons, ix
176 write(prim_wnames(iw),"(A,I0)") name_prim, ix
177 end if
178 end function var_set_auxvar
179
180 !> Set density variable
181 function var_set_rho() result(iw)
182 integer :: iw
183
184 nwflux = nwflux + 1
185 nwfluxbc = nwfluxbc + 1
186 nw = nw + 1
187 iw_rho = nwflux
188 iw = nwflux
189 prim_wnames(nwflux) = 'rho'
190 cons_wnames(nwflux) = 'rho'
191 end function var_set_rho
192
193 !> Exit MPI-AMRVAC with an error message
194 subroutine errormsg(message)
195
196 character(len=*), intent(in) :: message !< The error message
197
198 write(*, *) "ERROR for processor"
199 write(*, *) trim(message)
200
201 end subroutine errormsg
202 !> Set momentum variables
203 function var_set_momentum(ndir) result(iw)
204 integer, intent(in) :: ndir
205 integer :: iw(ndir), idir
206
207 if (allocated(iw_mom)) &
208 call errormsg("Error: set_mom was already called")
209 allocate(iw_mom(ndir))
210
211 do idir = 1, ndir
212 nwflux = nwflux + 1
213 nwfluxbc = nwfluxbc + 1
214 nw = nw + 1
215 iw_mom(idir) = nwflux
216 iw(idir) = nwflux
217 write(cons_wnames(nwflux),"(A1,I1)") "m", idir
218 write(prim_wnames(nwflux),"(A1,I1)") "v", idir
219 end do
220 end function var_set_momentum
221
222 !> Set energy variable
223 function var_set_energy() result(iw)
224 integer :: iw
225
226 nwflux = nwflux + 1
227 nwfluxbc = nwfluxbc + 1
228 nw = nw + 1
229 iw_e = nwflux
230 iw = nwflux
231 cons_wnames(nwflux) = 'e'
232 prim_wnames(nwflux) = 'p'
233 end function var_set_energy
234
235 function var_set_ne() result(iw)
236 integer :: iw
237
238 nw = nw + 1
239 iw_ne = nw
240 iw = nw
241 prim_wnames(nw) = 'Ne'
242 cons_wnames(nw) = 'Ne'
243 end function var_set_ne
244
245 function var_set_te() result(iw)
246 integer :: iw
247
248 nw = nw + 1
249 iw_te = nw
250 iw = nw
251 prim_wnames(nw) = 'Te'
252 cons_wnames(nw) = 'Te'
253 end function var_set_te
254
255 function var_set_q() result(iw)
256 integer :: iw
257
258 nwflux = nwflux + 1
259 nw = nw + 1
260 iw_q = nwflux
261 iw = nwflux
262 prim_wnames(nwflux) = 'q'
263 cons_wnames(nwflux) = 'q'
264 end function var_set_q
265
266 function var_set_radiation_energy() result(iw)
267 integer :: iw
268
269 nwflux = nwflux + 1
270 nwfluxbc = nwfluxbc + 1
271 nw = nw + 1
272 iw_r_e = nwflux
273 iw = nwflux
274 cons_wnames(nwflux) = 'r_e'
275 prim_wnames(nwflux) = 'r_e'
276 end function var_set_radiation_energy
277
278 !> Set magnetic field variables
279 function var_set_bfield(ndir) result(iw)
280 integer, intent(in) :: ndir
281 integer :: iw(ndir), idir
282
283 if (allocated(iw_mag)) &
284 call errormsg("Error: set_mag was already called")
285 allocate(iw_mag(ndir))
286
287 do idir = 1, ndir
288 nwflux = nwflux + 1
289 nwfluxbc = nwfluxbc + 1
290 nw = nw + 1
291 iw_mag(idir) = nwflux
292 iw(idir) = nwflux
293 write(cons_wnames(nwflux),"(A1,I1)") "b", idir
294 write(prim_wnames(nwflux),"(A1,I1)") "b", idir
295 end do
296 end function var_set_bfield
297
298end module mod_variables
Module with basic data types used in amrvac.
integer function var_set_q()
integer iw_tcoff
Index of the cutoff temperature for the TRAC method.
integer nwextra
Number of extra variables in w.
character(len=name_len), dimension(max_nw) prim_wnames
Primitive variable names.
integer nw
Total number of variables.
character(len=name_len), dimension(max_nw) cons_wnames
Conservative variable names.
integer function var_set_ne()
integer iw_equi_rho
integer nwaux
Number of auxiliary variables in w.
integer function var_set_rho()
Set density variable.
integer function var_set_energy()
Set energy variable.
integer nvector
Number of vector variables (used for writing output)
integer number_species
number of species: each species has different characterictic speeds and should be used accordingly in...
integer, dimension(:), allocatable iw_mom
Indices of the momentum density.
integer, dimension(:), allocatable start_indices
the indices in 1:nwflux array are assumed consecutive for each species this array should be of size n...
integer nws
Total number of stagger variables.
integer, dimension(:), allocatable stop_indices
the indices in 1:nwflux array are assumed consecutive for each species this array should be of size n...
integer, dimension(:), allocatable, protected iw_mag
Indices of the magnetic field components.
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 iw_tweight
subroutine errormsg(message)
Exit MPI-AMRVAC with an error message.
integer function var_set_wextra()
Set extra variable in wextra, which is not advected and has no boundary conditions and not output in ...
integer, dimension(:), allocatable iw_vector
Indices of vector variables.
integer, parameter max_nw
Maximum number of variables.
integer function var_set_extravar(name_cons, name_prim, ix)
Set extra variable in w, which is not advected and has no boundary conditions. This has to be done af...
integer nwgc
Number of variables which need to be updated in ghost cells.
integer function, dimension(ndir) var_set_momentum(ndir)
Set momentum variables.
integer function var_set_radiation_energy()
integer iw_rho
Index of the (gas) density.
integer iw_te
Index of temperature.
integer nwflux
Number of flux variables.
integer iw_r_e
Index of the radiation energy density.
integer iw_equi_p
integer index_v_mag
index of the var whose velocity appears in the induction eq.
integer function, dimension(ndir) var_set_bfield(ndir)
Set magnetic field variables.
integer iw_q
Index of heat flux.
integer nw_extra
Number of extra variables in wextra seperated from w.
integer function var_set_te()
integer iw_e
Index of the energy density.
integer function var_set_fluxvar(name_cons, name_prim, ix, need_bc)
Set generic flux variable.
integer iw_ne
Index of electron number density.
integer nwfluxbc
Number of flux variables which need user to specify boundary type.