DISPATCH
index_mod.f90
1 !===============================================================================
2 !> This index file has slot indices for all solver, all initially equal to zero
3 !> It is the responsibility of the solver to set all values it needs to use.
4 !> NOTE: The only reference to indices in tasks should be via task%idx, never to
5 !> a temporary instance of index_t.
6 !===============================================================================
7 MODULE index_mod
8  USE io_mod
9  USE trace_mod
10  implicit none
11  private
12  type, public:: index_t
13  integer:: d=0, e=0, px=0, py=0, pz=0, bx=0, by=0, bz=0, phi=0, tt=0, s=0, &
14  et=0, dphi=0, qr=0, ex=0, ey=0, ez=0
15  integer:: dtr=0
16  contains
17  procedure:: init
18  procedure:: copy
19  procedure:: request_index
20  procedure:: output
21  end type
22  type(index_t), public:: idx
23 CONTAINS
24 
25 !===============================================================================
26 !> Initialize the indices to default values, possibly to be modified by solvers
27 !===============================================================================
28 SUBROUTINE init (self, ie, mhd)
29  class(index_t):: self
30  integer:: ie
31  logical:: mhd
32  !-----------------------------------------------------------------------------
33  call trace%begin ('index_t%init')
34  if (ie==2) then
35  self%d = 1
36  self%e = 2
37  self%s = 2
38  self%px = 3
39  self%py = 4
40  self%pz = 5
41  else
42  self%d = 1
43  self%px = 2
44  self%py = 3
45  self%pz = 4
46  self%e = 5
47  self%s = 5
48  end if
49  if (mhd) then
50  self%bx = 6
51  self%by = 7
52  self%bz = 8
53  else
54  self%bx = -1
55  self%by = -1
56  self%bz = -1
57  end if
58  call self%copy
59  call trace%end ()
60 END SUBROUTINE init
61 
62 !===============================================================================
63 !> Request a new, unique index
64 !> idx should be index itself, nv is patch%nv.
65 !===============================================================================
66 SUBROUTINE request_index (self, idx, nv, success)
67  class(index_t):: self
68  integer :: idx, nv
69  logical, optional :: success
70  !-----------------------------------------------------------------------------
71  if (present(success)) success = .false.
72  if (idx <= 0) then
73  !$omp critical (index_cr)
74  nv = nv+1
75  idx = nv
76  if (present(success)) success = .true.
77  !$omp end critical (index_cr)
78  call self%copy
79  end if
80 END SUBROUTINE request_index
81 
82 !===============================================================================
83 !> Initialize the indices to default values, possibly to be modified by solvers
84 !===============================================================================
85 SUBROUTINE copy (self)
86  class(index_t):: self
87  !-----------------------------------------------------------------------------
88  ! Ugly fix, necessary because there are a large number of places that refer to
89  ! a local instance of index_t, which is assumed to be authentative. In cases
90  ! where the default values have been modified by the server, this may lead to
91  ! inconsistencies. As a fall back, such places may instead refer to this one
92  ! pubclic instance.
93  !-----------------------------------------------------------------------------
94  !$omp critical (index_cr)
95  select type(self)
96  type is (index_t)
97  idx = self
98  end select
99  !$omp end critical (index_cr)
100 END SUBROUTINE copy
101 
102 !===============================================================================
103 !> Write out index value namelist, for python/dispatch/
104 !===============================================================================
105 SUBROUTINE output (self, unit)
106  class(index_t):: self
107  integer:: unit
108  !.............................................................................
109  integer:: &
110  d, e, et, s, px, py, pz, bx, by, bz, qr, tt, phi, p1, p2, p3, b1, b2, b3
111  namelist /idx_nml/ &
112  d, e, et, s, px, py, pz, bx, by, bz, qr, tt, phi, p1, p2, p3, b1, b2, b3
113  !-----------------------------------------------------------------------------
114  if (io%time_derivs>0) then
115  call output_time_derivs (self, unit)
116  else
117  d = self%d - 1
118  e = self%e - 1
119  s = self%s - 1
120  et = self%et - 1
121  qr = self%qr - 1
122  px = self%px - 1
123  py = self%py - 1
124  pz = self%pz - 1
125  bx = self%bx - 1
126  by = self%by - 1
127  bz = self%bz - 1
128  p1 = self%px - 1
129  p2 = self%py - 1
130  p3 = self%pz - 1
131  b1 = self%bx - 1
132  b2 = self%by - 1
133  b3 = self%bz - 1
134  qr = self%qr - 1
135  tt = self%tt - 1
136  phi = self%phi - 1
137  write (unit, idx_nml)
138  end if
139 END SUBROUTINE output
140 
141 !===============================================================================
142 !> Write out time derivative index value namelist, for python/dispatch/
143 !===============================================================================
144 SUBROUTINE output_time_derivs (self, unit)
145  class(index_t):: self
146  integer:: unit
147  !.............................................................................
148  integer:: &
149  d, e, et, s, px, py, pz, bx, by, bz, qr, tt, phi, p1, p2, p3, b1, b2, b3, &
150  dpxdt, dpydt, dpzdt, dbxdt, dbydt, dbzdt, dphidt, dddt, dedt, dsdt, &
151  dp1dt, dp2dt, dp3dt, db1dt, db2dt, db3dt
152  namelist /idx_nml/ &
153  d, e, et, s, px, py, pz, bx, by, bz, qr, tt, phi, p1, p2, p3, b1, b2, b3, &
154  dpxdt, dpydt, dpzdt, dbxdt, dbydt, dbzdt, dphidt, dddt, dedt, dsdt, &
155  dp1dt, dp2dt, dp3dt, db1dt, db2dt, db3dt
156  d = self%d - 1
157  e = self%e - 1
158  s = self%s - 1
159  et = self%et - 1
160  qr = self%qr - 1
161  tt = self%tt - 1
162  px = self%px - 1
163  py = self%py - 1
164  pz = self%pz - 1
165  bx = self%bx - 1
166  by = self%by - 1
167  bz = self%bz - 1
168  p1 = self%px - 1
169  p2 = self%py - 1
170  p3 = self%pz - 1
171  b1 = self%bx - 1
172  b2 = self%by - 1
173  b3 = self%bz - 1
174  phi = self%phi - 1
175  !-----------------------------------------------------------------------------
176  ! These values are preliminary, and are reassigned in python/dispatch/, based
177  ! on knowledge of the mhd and selfgravity swwitches (not available here)
178  !-----------------------------------------------------------------------------
179  dddt = d + io%nv
180  dedt = e + io%nv
181  dsdt = s + io%nv
182  dpxdt = px + io%nv
183  dpydt = py + io%nv
184  dpzdt = pz + io%nv
185  dphidt = phi + io%nv
186  dp1dt = dpxdt
187  dp2dt = dpydt
188  dp3dt = dpzdt
189  if (bx > 0) then
190  dbxdt = bx + io%nv
191  dbydt = by + io%nv
192  dbzdt = bz + io%nv
193  else
194  dbxdt = -1
195  dbydt = -1
196  dbzdt = -1
197  end if
198  db1dt = dbxdt
199  db2dt = dbydt
200  db3dt = dbzdt
201  write (unit, idx_nml)
202 END SUBROUTINE output_time_derivs
203 
204 END MODULE index_mod
This index file has slot indices for all solver, all initially equal to zero It is the responsibility...
Definition: index_mod.f90:7
Definition: io_mod.f90:4