DISPATCH
extras_mod.f90
1 !===============================================================================
2 !> Template version of a module intended for adding extra features, at a level
3 !> between the basic task and patch layer, and the layer of solvers.
4 !>
5 !> To add extra features to the code, copy this file to experiments/your_dir/,
6 !> and add the extra dependencies to the Makefile (only) there.
7 !>
8 !> When doing to, the sketch of module dependencies below may be useful.
9 !> In particular, it shows that extras underlings, via gpatch_t, may use the
10 !> list_t data type (and hence they can access the copy of the task_list
11 !> pointer made available there).
12 !>
13 !> The sketch also illustrates that extras underlings can at most cast a task
14 !> pointer to a gpatch_t pointer, but not to an extras_t pointer (which is why
15 !> generic array data needs to be stored in data types below extras_t).
16 !>
17 !> task_list_t
18 !> / | |
19 !> experiment_t | |
20 !> solver_t | |
21 !> mhd_t | |
22 !> | refine_t |
23 !> | / |
24 !> extras_t |
25 !> / \ |
26 !> / \ |
27 !> extras_1_t extras_2_t |
28 !> | \ / |
29 !> | gpatch_t |
30 !> | | \ |
31 !> | | list_t
32 !> | | / |
33 !> | patch_t |
34 !> | / \ |
35 !> | / link_t
36 !> | / |
37 !> connect_t task_t
38 !>
39 !> The extra modules needed in an experiment should be chosen and coordinated
40 !> in this module, and the ones that are "below" (USEd by) this module should
41 !> generally refer to array memory in patch_t, and/or to local memory allocated
42 !> inside these extra modules. Only key physics effects, such as forcing,
43 !> cooling or heating, ionization, etc., should be added to the patch_t module,
44 !>
45 !> Modules that prepare input to the solvers should generally be called from the
46 !> pre_upate() procedure, while modules that rely on results from the solver
47 !> should be called from the post_update() procedure.
48 !>
49 !> This module should generally NOT use the h5_mod (HDF5) module itself. h5_mod
50 !> should instead be USEd from the actual extra modules that wish to use it to
51 !> save ad hoc results in a standardized format.
52 !===============================================================================
53 
54 MODULE extras_mod
55  !-----------------------------------------------------------------------------
56  ! Generic modules, which are always included in the code in any case
57  !-----------------------------------------------------------------------------
58  USE io_mod
59  USE trace_mod
60  USE gpatch_mod
61  USE patch_mod
62  USE connect_mod
63  USE list_mod
64  !-----------------------------------------------------------------------------
65  ! Optional modules start here.
66  !-----------------------------------------------------------------------------
67  !USE forces_mod ! forces
68  !USE trace_particles_mod ! tracep
69  !USE spitzer_mod ! spitzer
70  !USE gravity_mod ! gravity
71  !USE sink_patch_mod ! sinkp
72  !USE particle_solver_mod ! sinkp
73  !-----------------------------------------------------------------------------
74  implicit none
75  private
76  !-----------------------------------------------------------------------------
77  ! Note that modules that contain patch-private data, such as random number
78  ! states, must be accessed via a private instance in the extras_t data type
79  !-----------------------------------------------------------------------------
80  type, public, extends(gpatch_t):: extras_t
81  !type(forces_t):: forces ! forces
82  !type (spitzer_t):: spitzer ! spitzer
83  !type(gravity_t):: gravity ! gravity
84  !type(sinkparticles_t):: sinkparticles ! sinkp
85  !class(trace_particles_t), pointer:: trace_particles ! tracep
86  !real, dimension(:,:,:,:), pointer:: v ! tracep
87  contains
88  procedure, nopass:: cast2extras
89  procedure:: pre_init
90  procedure:: init
91  procedure:: dealloc
92  procedure:: init_task_list
93  procedure:: pre_update
94  procedure:: post_update
95  procedure:: output
96  procedure:: check_refine
97  end type
98  type(extras_t), public:: extras
99 CONTAINS
100 
101 !===============================================================================
102 !> Initialize the modules that are to be included and used
103 !===============================================================================
104 SUBROUTINE pre_init (self)
105  class(extras_t), target:: self
106  !.............................................................................
107  call trace%begin ('extras_t%pre_init')
108  call trace%end
109 END SUBROUTINE pre_init
110 
111 !===============================================================================
112 !> Initialize the modules that are to be included and used
113 !===============================================================================
114 SUBROUTINE init (self)
115  class(extras_t):: self
116  !.............................................................................
117  call trace%begin ('extras_t%init')
118  !call self%forces%init (self%link) ! forces
119  !-----------------------------------------------------------------------------
120  ! Allocate a trace_particles data type, connect a pointer, and initialize
121  !-----------------------------------------------------------------------------
122  !allocate (self%trace_particles) ! tracep
123  !self%connect%trace_particles => self%trace_particles ! tracep
124  !call self%trace_particles%add (self%link) ! tracep
125  !call self%spitzer%init(self%link) ! spitzer
126  !call self%gravity%init(self%link) ! gravity
127  !call sink_patch%init ! sinkp
128  call trace%end
129 END SUBROUTINE init
130 
131 !===============================================================================
132 !> Save a pointer to the task list, for use in underlings that need it
133 !===============================================================================
134 SUBROUTINE init_task_list (self, task_list)
135  class(extras_t):: self
136  class(list_t), pointer:: task_list
137  !.............................................................................
138  self%task_list => task_list
139 END SUBROUTINE init_task_list
140 
141 !===============================================================================
142 !> Deallocate allocated arrays
143 !===============================================================================
144 SUBROUTINE dealloc (self)
145  class(extras_t):: self
146  !.............................................................................
147  call trace%begin ('extras_t%dealloc')
148  !call self%forces%dealloc ! forces
149  !call trace_particles%dealloc ! sinkp
150  !deallocate (self%trace_particles) ! tracep
151  !call sink_patch%dealloc ! sinkp
152  call trace%end
153 END SUBROUTINE dealloc
154 
155 !===============================================================================
156 !> The pre_update hierarchy is called before the solver updates. To allow for
157 !> a general case, with several force data types adding their contributions,
158 !> the generic patch_t%arrays must (if allocated), be set to zero here, so each
159 !> force can be added separately, and to prevent these contributions to pile up.
160 !===============================================================================
161 SUBROUTINE pre_update (self)
162  class(extras_t), target:: self
163  !.............................................................................
164  !call self%forces%pre_update ! forces
165  !call self%trace_particles%update ! tracep
166  !call self%spitzer%pre_update() ! spitzer
167  !call self%gravity%pre_update() ! gravity
168  !call particle_solver%force_field (self) ! sinkp
169 END SUBROUTINE pre_update
170 
171 !===============================================================================
172 !> The post_update hierarchy is called after the solver updates
173 !===============================================================================
174 SUBROUTINE post_update (self)
175  class(extras_t):: self
176  !.............................................................................
177  !call self%forces%post_update ! forces
178  !call self%trace_particles%post_update (self) ! tracep
179  !call self%gravity%post_update ! gravity
180 END SUBROUTINE post_update
181 
182 !===============================================================================
183 !> Optionally call specific output modules for the extra features
184 !===============================================================================
185 SUBROUTINE output (self)
186  class(extras_t):: self
187  !.............................................................................
188  call self%gpatch_t%output ! keep
189 END SUBROUTINE output
190 
191 !===============================================================================
192 !> Interface to refinement
193 !===============================================================================
194 INTEGER function check_refine (self, patch)
195  class(extras_t):: self
196  class(extras_t), pointer:: patch
197  class(gpatch_t), pointer:: gpatch
198  !.............................................................................
199  gpatch => patch
200  check_refine = -1
201  !check_refine = max (check_refine, &
202  ! sinkparticles%check_refine (gpatch)) ! sinkp
203 END FUNCTION check_refine
204 
205 !===============================================================================
206 !> Cast a generic task_t to extras_t
207 !===============================================================================
208 FUNCTION cast2extras (task) RESULT(extras)
209  USE task_mod
210  class(task_t), pointer:: task
211  class(extras_t), pointer:: extras
212  !.............................................................................
213  select type (task)
214  class is (extras_t)
215  extras => task
216  class default
217  nullify(extras)
218  call io%abort ('extras_t%cast: failed to cast a task to extras_t')
219  end select
220 END FUNCTION cast2extras
221 
222 END MODULE extras_mod
Template version of a module intended for adding extra features, at a level between the basic task an...
Definition: extras_mod.f90:54
The gpath_t layer now essentially only handles restarts.
Definition: gpatch_mod.f90:4
Module with list handling for generic class task_t objects.
Definition: list_mod.f90:4
Template module for patches, which adds pointers to memory and mesh, and number of dimensions and var...
Definition: patch_mod.f90:6
Module holding anonymous pointers back to extras features.
Definition: connect_mod.f90:4
Definition: io_mod.f90:4
Template module for tasks.
Definition: task_mod.f90:4