DISPATCH
gpatch_mod.f90
1 !===============================================================================
2 !> The gpath_t layer now essentially only handles restarts
3 !===============================================================================
4 MODULE gpatch_mod
5  USE io_mod
6  USE os_mod
7  USE trace_mod
8  USE patch_mod
9  USE initial_mod
10  USE kinds_mod
11  USE mesh_mod
12  USE units_mod
13  USE timer_mod
14  USE omp_timer_mod
15  USE bits_mod
16  USE data_io_mod
17  USE guard_zones_mod
18  USE download_mod
19  USE data_hub_mod
20  USE validate_mod
21  USE list_mod
22  USE task_mod
23  implicit none
24  private
25  type, public, extends(patch_t):: gpatch_t
26  type(initial_t):: initial
27  type(data_hub_t):: data_hub
28  class(list_t), pointer:: task_list => null()
29  real(8):: d0
30  contains
31  procedure, nopass:: cast2gpatch
32  procedure:: init_task_list
33  procedure:: update
34  procedure:: input
35  procedure:: output
36  procedure:: init
37  procedure:: counter_update
38  procedure:: dnload
39  procedure:: courant_condition
40  !--- from void solver ---
41  procedure:: void_fun
42  procedure:: void_fun1
43  procedure:: void_fun3
44  procedure:: gas_pressure => void_fun
45  procedure:: compression_magnitude => void_sub
46  procedure:: vorticity_magnitude => void_sub
47  procedure:: gas_velocity_scalar => void_fun1
48  procedure:: gas_velocity_vector => void_fun3
49  generic:: gas_velocity => gas_velocity_scalar, gas_velocity_vector
50  end type
51  real(8), save :: restart_time = 0d0
52  logical, save :: detailed_timer=.false.
53  integer, save :: verbose=0
54  integer, save :: order=1
55  type(gpatch_t), public:: gpatch
56 CONTAINS
57 
58 !===============================================================================
59 !> Cast a generic task_t to patch_t
60 !===============================================================================
61 FUNCTION cast2gpatch (task) RESULT(gpatch)
62  class(task_t), pointer:: task
63  class(gpatch_t), pointer:: gpatch
64  !.............................................................................
65  select type (task)
66  class is (gpatch_t)
67  gpatch => task
68  class default
69  nullify(gpatch)
70  call io%abort ('gpatch_t%cast: failed to cast a task to patch_t')
71  end select
72 END FUNCTION cast2gpatch
73 
74 !===============================================================================
75 !> Make a copy of the task list pointer
76 !===============================================================================
77 SUBROUTINE init_task_list (self, task_list)
78  class(gpatch_t):: self
79  class(list_t), pointer:: task_list
80  !.............................................................................
81  call trace%begin ('gpatch_t%init_task_list')
82  self%task_list => task_list
83  call trace%end()
84 END SUBROUTINE init_task_list
85 
86 !===============================================================================
87 !> Interface allowing intercept
88 !===============================================================================
89 SUBROUTINE update (self)
90  class(gpatch_t):: self
91  !-----------------------------------------------------------------------------
92  call self%patch_t%update
93 END SUBROUTINE update
94 
95 !===============================================================================
96 !> Interface routine to the data_io input procedure, signalling if the patch
97 !> could be read, or not
98 !===============================================================================
99 SUBROUTINE input (self, ok)
100  class(gpatch_t):: self
101  logical:: ok
102  !-----------------------------------------------------------------------------
103  call data_io%input (self, ok)
104 END SUBROUTINE input
105 
106 !===============================================================================
107 !> Interface routine to the data_io output procedure
108 !===============================================================================
109 SUBROUTINE output (self)
110  class(gpatch_t):: self
111  !-----------------------------------------------------------------------------
112  call data_io%output (self)
113 END SUBROUTINE output
114 
115 !===============================================================================
116 !> Add restart functionality to patch initialization. This %init routine is
117 !> called for both internal and virtual patches, which both can be initialized
118 !> fully by the self%ininitial%condition() procedure. When instead calling the
119 !> self%input() procedure, we need to make a decision: Either we must make sure
120 !> that the data_io%input() routine can handle off-rank reading, or we need to
121 !> nevertheless return ok=.true., and instead rely on a negative time to force
122 !> any task that relies on the patch for guard zone values to wait until data
123 !> has been recieved with MPI from the owner rank.
124 !===============================================================================
125 SUBROUTINE init (self)
126  class(gpatch_t):: self
127  real(kind=KindScalarVar), pointer :: ff(:,:,:,:)
128  character(len=64) :: filename
129  logical :: ok
130  real(kind=KindScalarVar), pointer :: d(:,:,:)
131  !-----------------------------------------------------------------------------
132  if (self%is_set(bits%frozen)) &
133  return
134  call trace%begin ('gpatch_t%init')
135  call self%initial%init (self%kind, real(self%gamma))
136  call data_io%init (self)
137  call guard_zones%init
138  !-----------------------------------------------------------------------------
139  ! Try reading a restart snapshot.
140  !-----------------------------------------------------------------------------
141  call self%input (ok)
142  if (ok) then
143  restart_time = self%time
144  self%istep = 0
145  else
146  !---------------------------------------------------------------------------
147  ! Make sure the default time for patches with IC values is zero, to ensure
148  ! boundary tasks are not considered ready for updating until their virtual
149  ! task nbors have been updated, in evolved cases.
150  !---------------------------------------------------------------------------
151  restart_time = 0.0
152  self%mem = 0.0
153  ff => self%mem(:,:,:,:,1,1)
154  call self%initial%condition (self%mesh, ff, self%idx)
155  !---------------------------------------------------------------------------
156  ! patch_t%setup sets time = -1, to prevent downloading until nbors have been
157  ! initialized, and their time has been set to 0.0 here
158  !---------------------------------------------------------------------------
159  self%time = 0.0
160  self%t = 0.0
161  end if
162  !-----------------------------------------------------------------------------
163  ! If restart succeeded for some patch, use it to set time and output cadence.
164  ! FIXME: This may fail in some corner cases when running on multiple MPI ranks,
165  ! if one rank happens to handle only patches that do not exist yet.
166  !-----------------------------------------------------------------------------
167  if (restart_time > 0d0) then
168  call self%lock%set ('gpatch_t')
169  self%time = restart_time
170  self%t(self%it) = self%time
171  self%out_next = (int(self%time/io%out_time+1.0e-4)+1)*io%out_time ! add an `eps` to avoid round-off errors
172  self%iout = self%restart+1
173  !$omp master
174  write (filename,'(a,i5.5,"/")') trim(io%outputname), self%iout
175  if (io%iodir/=self%iout) call os%mkdir (trim(filename))
176  io%iodir = self%iout
177  !$omp end master
178  call self%lock%unset ('gpatch_t')
179  end if
180  call trace%end()
181 END SUBROUTINE init
182 
183 !===============================================================================
184 !> Increment the cell udpate counter. This may be overloaded in more complex
185 !> solvers, which prefer a different way of counting.
186 !===============================================================================
187 SUBROUTINE counter_update (self)
188  class(gpatch_t):: self
189  !-----------------------------------------------------------------------------
190  call trace%begin ('gpatch_t%counter_update')
191  !$omp atomic
192  timer%n_update = timer%n_update + product(self%n)
193  call trace%end()
194 END SUBROUTINE counter_update
195 
196 !===============================================================================
197 !> Add default guard zone download functionality. This may be overloaded in
198 !> experiment_mod, if more specialized guard zone loading is required.
199 !===============================================================================
200 SUBROUTINE dnload (self, only)
201  class(gpatch_t):: self
202  integer, optional:: only
203  !-----------------------------------------------------------------------------
204  call trace%begin ('gpatch_t%dnload')
205  if (self%is_clear (bits%frozen)) then
206  if (self%use_data_hub) then
207  call self%data_hub%update (self%link, only=only)
208  else
209  call download%download_link (self%link, only=only)
210  end if
211  end if
212  call trace%end()
213 END SUBROUTINE dnload
214 
215 !===============================================================================
216 !> Intercept to make validate%check call
217 !===============================================================================
218 SUBROUTINE courant_condition (self, detailed_timer)
219  class(gpatch_t):: self
220  logical, optional:: detailed_timer
221  !-----------------------------------------------------------------------------
222  call trace%begin ('gpatch_t%courant_condition')
223  call validate%check (self%link, self%u_max, 'courant')
224  call self%patch_t%courant_condition (detailed_timer)
225  call trace%end()
226 END SUBROUTINE courant_condition
227 
228 !===============================================================================
229 !> Voíd stub procedures
230 !===============================================================================
231 SUBROUTINE void_sub (self, w)
232  class(gpatch_t):: self
233  real, dimension(:,:,:):: w
234  !-----------------------------------------------------------------------------
235  w = self%mem(:,:,:,1,1,1)
236 END SUBROUTINE void_sub
237 
238 !===============================================================================
239 FUNCTION void_fun (self) RESULT (pg)
240  class(gpatch_t):: self
241  real, dimension(self%gn(1),self%gn(2),self%gn(3)):: pg
242  !-----------------------------------------------------------------------------
243  pg = self%mem(:,:,:,1,1,1)
244 END FUNCTION void_fun
245 
246 !===============================================================================
247 FUNCTION void_fun1 (self, idir) RESULT (v)
248  class(gpatch_t):: self
249  integer:: idir
250  real(4), dimension(self%gn(1),self%gn(2),self%gn(3)):: v
251  !-----------------------------------------------------------------------------
252  v = self%mem(:,:,:,1,1,1)
253 END FUNCTION void_fun1
254 
255 !===============================================================================
256 FUNCTION void_fun3 (self) RESULT (v)
257  class(gpatch_t):: self
258  real(4), dimension(self%gn(1),self%gn(2),self%gn(3),3):: v
259  !-----------------------------------------------------------------------------
260  v = self%mem(:,:,:,1,1:3,1)
261 END FUNCTION void_fun3
262 
263 END MODULE gpatch_mod
Each thread uses a private timer data type, with arrays for start time and total time for each regist...
Definition: timer_mod.f90:11
download_link: takes care of downloads to linktask same: called for patches on the same level differ:...
A communications hub between patches. Three methods are used: download_same, download_higher and down...
Definition: data_hub_mod.f90:5
The gpath_t layer now essentially only handles restarts.
Definition: gpatch_mod.f90:4
Support tic/toc timing, as in MATLAB, and accurate wallclock() function. The timing is generally much...
Generic validation module. The general idea is to be able to compare two runs at critical points in t...
Module with list handling for generic class task_t objects.
Definition: list_mod.f90:4
Interface from gpatch_mod to a choice of binary data I/O methods, controlled by the iomethod text str...
Definition: data_io_mod.f90:17
Template module for patches, which adds pointers to memory and mesh, and number of dimensions and var...
Definition: patch_mod.f90:6
Fundamental constants in CGS and SI units.
Definition: units_mod.f90:4
Template module for mesh.
Definition: mesh_mod.f90:4
Simple initical condition module for tests.
Definition: initial_mod.f90:7
Definition: io_mod.f90:4
Optimized restrict operations, intended for guard zones (not conservative)
Template module for tasks.
Definition: task_mod.f90:4