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 !> Indices of the magnetic field components
58 integer, allocatable, protected :: iw_mag(:)
59
60 !> Index of the cutoff temperature for the TRAC method
61 integer :: iw_tcoff = -1
62 integer :: iw_tweight= -1
63
64 !> number of species: each species has different characterictic speeds and should
65 !> be used accordingly in mod_finite_volume and mod_finite_difference
66 integer :: number_species = 1
67
68 !> index of the var
69 !> whose velocity appears in the induction eq.
70 integer :: index_v_mag = 1
71
72 !> the indices in 1:nwflux array are assumed consecutive for each species
73 !> this array should be of size number_species and contain the first index in the array of
74 !> the number_species
75 integer, allocatable :: start_indices(:)
76 !> the indices in 1:nwflux array are assumed consecutive for each species
77 !> this array should be of size number_species and contain the last index in the array of
78 !> the first number_species, the last index for the last one is nwflux
79 integer, allocatable :: stop_indices(:)
80
81 ! indices of equi for the species index_v_mag
82 ! these are needed for hlld solver, TODO: consider moving in a separate file
83 integer :: iw_equi_rho = -1
84 integer :: iw_equi_p = -1
85
86 !> Primitive variable names
87 character(len=name_len) :: prim_wnames(max_nw)
88
89 !> Conservative variable names
90 character(len=name_len) :: cons_wnames(max_nw)
91
92contains
93
94 !> Set generic flux variable
95 function var_set_fluxvar(name_cons, name_prim, ix, need_bc) result(iw)
96 character(len=*), intent(in) :: name_cons !< Conservative name
97 character(len=*), intent(in) :: name_prim !< Primitive name
98 integer, intent(in), optional :: ix !< Optional index (to make var1, var2, ...)
99 logical, intent(in), optional :: need_bc !< Require boundary condition (default: true)
100 integer :: iw
101 logical :: add_bc
102
103 nwflux = nwflux + 1
104 nw = nw + 1
105 iw = nwflux
106
107 add_bc = .true.
108 if (present(need_bc)) add_bc = need_bc
109 if (add_bc) nwfluxbc = nwfluxbc + 1
110
111 if (.not. present(ix)) then
112 cons_wnames(nwflux) = name_cons
113 prim_wnames(nwflux) = name_prim
114 else
115 write(cons_wnames(nwflux),"(A,I0)") name_cons, ix
116 write(prim_wnames(nwflux),"(A,I0)") name_prim, ix
117 end if
118 end function var_set_fluxvar
119
120 !> Set extra variable in w, which is not advected and has no boundary conditions.
121 !> This has to be done after defining flux variables and auxiliary variables.
122 function var_set_extravar(name_cons, name_prim, ix) result(iw)
123 character(len=*), intent(in) :: name_cons, name_prim
124 integer, intent(in), optional :: ix
125 integer :: iw
126
127 nwextra = nwextra + 1
128 nw = nw + 1
129 iw = nw
130
131 if (.not. present(ix)) then
132 prim_wnames(iw) = name_cons
133 cons_wnames(iw) = name_prim
134 else
135 write(cons_wnames(iw),"(A,I0)") name_cons, ix
136 write(prim_wnames(iw),"(A,I0)") name_prim, ix
137 end if
138 end function var_set_extravar
139
140 !> Set extra variable in wextra, which is not advected and has no boundary conditions and not output in dat.
141 !> This has to be done after defining flux variables and auxiliary variables.
142 function var_set_wextra() result(iw)
143 integer :: iw
144
145 nw_extra = nw_extra + 1
146 iw = nw_extra
147
148 end function var_set_wextra
149
150 !> Set auxiliary variable, which is not advected but has boundary conditions.
151 !> This has to be done after defining flux variables.
152 function var_set_auxvar(name_cons, name_prim, ix) result(iw)
153 character(len=*), intent(in) :: name_cons, name_prim
154 integer, intent(in), optional :: ix
155 integer :: iw
156
157 nwaux = nwaux + 1
158 nw = nw + 1
159 iw = nw
160
161 if (.not. present(ix)) then
162 prim_wnames(iw) = name_cons
163 cons_wnames(iw) = name_prim
164 else
165 write(cons_wnames(iw),"(A,I0)") name_cons, ix
166 write(prim_wnames(iw),"(A,I0)") name_prim, ix
167 end if
168 end function var_set_auxvar
169
170 !> Set density variable
171 function var_set_rho() result(iw)
172 integer :: iw
173
174 nwflux = nwflux + 1
175 nwfluxbc = nwfluxbc + 1
176 nw = nw + 1
177 iw_rho = nwflux
178 iw = nwflux
179 prim_wnames(nwflux) = 'rho'
180 cons_wnames(nwflux) = 'rho'
181 end function var_set_rho
182
183 !> Exit MPI-AMRVAC with an error message
184 subroutine errormsg(message)
185
186 character(len=*), intent(in) :: message !< The error message
187
188 write(*, *) "ERROR for processor"
189 write(*, *) trim(message)
190
191 end subroutine errormsg
192 !> Set momentum variables
193 function var_set_momentum(ndir) result(iw)
194 integer, intent(in) :: ndir
195 integer :: iw(ndir), idir
196
197 if (allocated(iw_mom)) &
198 call errormsg("Error: set_mom was already called")
199 allocate(iw_mom(ndir))
200
201 do idir = 1, ndir
202 nwflux = nwflux + 1
203 nwfluxbc = nwfluxbc + 1
204 nw = nw + 1
205 iw_mom(idir) = nwflux
206 iw(idir) = nwflux
207 write(cons_wnames(nwflux),"(A1,I1)") "m", idir
208 write(prim_wnames(nwflux),"(A1,I1)") "v", idir
209 end do
210 end function var_set_momentum
211
212 !> Set energy variable
213 function var_set_energy() result(iw)
214 integer :: iw
215
216 nwflux = nwflux + 1
217 nwfluxbc = nwfluxbc + 1
218 nw = nw + 1
219 iw_e = nwflux
220 iw = nwflux
221 cons_wnames(nwflux) = 'e'
222 prim_wnames(nwflux) = 'p'
223 end function var_set_energy
224
225 function var_set_radiation_energy() result(iw)
226 integer :: iw
227
228 nwflux = nwflux + 1
229 nwfluxbc = nwfluxbc + 1
230 nw = nw + 1
231 iw_r_e = nwflux
232 iw = nwflux
233 cons_wnames(nwflux) = 'r_e'
234 prim_wnames(nwflux) = 'r_e'
235 end function var_set_radiation_energy
236
237 !> Set magnetic field variables
238 function var_set_bfield(ndir) result(iw)
239 integer, intent(in) :: ndir
240 integer :: iw(ndir), idir
241
242 if (allocated(iw_mag)) &
243 call errormsg("Error: set_mag was already called")
244 allocate(iw_mag(ndir))
245
246 do idir = 1, ndir
247 nwflux = nwflux + 1
248 nwfluxbc = nwfluxbc + 1
249 nw = nw + 1
250 iw_mag(idir) = nwflux
251 iw(idir) = nwflux
252 write(cons_wnames(nwflux),"(A1,I1)") "b", idir
253 write(prim_wnames(nwflux),"(A1,I1)") "b", idir
254 end do
255 end function var_set_bfield
256
257end module mod_variables
Module with basic data types used in amrvac.
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 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 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 nw_extra
Number of extra variables in wextra seperated from w.
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 nwfluxbc
Number of flux variables which need user to specify boundary type.