MODFLOW 6 version 6.9.0.dev0
USGS Modular Hydrologic Model
Loading...
Searching...
No Matches
RunControl.f90
Go to the documentation of this file.
2 use kindmodule, only: i4b
9 implicit none
10 private
11
13
14 type, public :: runcontroltype
15 class(virtualdatamanagertype), pointer :: virtual_data_mgr !< syncs globally accessible data, timely, by
16 !! linking (local) or message passing (remote)
17 type(mappertype) :: mapper !< a 'mapper' for copying data between two memory addresses
18 contains
19 procedure :: start => ctrl_start
20 procedure :: at_stage => ctrl_at_stage
21 procedure :: finish => ctrl_finish
22 procedure :: after_con_cr => ctrl_after_con_cr
23
24 ! private
25 procedure, private :: init_handler
26 procedure, private :: before_con_df
27 procedure, private :: after_con_df
28 procedure, private :: destroy
29 end type runcontroltype
30
31contains
32
33 function create_seq_run_control() result(run_controller)
34 class(runcontroltype), pointer :: run_controller
35
36 allocate (run_controller)
37
38 end function create_seq_run_control
39
40 subroutine ctrl_start(this)
41 class(runcontroltype) :: this
42
43 allocate (this%virtual_data_mgr)
44
45 end subroutine ctrl_start
46
47 subroutine ctrl_finish(this)
48 use simvariablesmodule, only: iout
51 use timermodule, only: elapsed_time
52 use simmodule, only: final_message
53 class(runcontroltype) :: this
54
55 ! clean up
56 call this%destroy()
57
58 ! -- Write memory usage, elapsed time and terminate
60 call mem_da()
61 call mem_alias_da()
62
63 ! stop and print timings
64 call g_prof%stop(g_prof%tmr_finalize)
65 call g_prof%stop(g_prof%tmr_run)
66 call g_prof%print(iout)
67 call g_prof%destroy()
68
69 call elapsed_time(iout, 1)
70 call final_message()
71
72 end subroutine ctrl_finish
73
74 !> @brief This will call the handler for a particular stage
75 !< in the simulation run
76 subroutine ctrl_at_stage(this, stage)
77 class(runcontroltype) :: this
78 integer(I4B) :: stage
79
80 if (stage == stg_bfr_mdl_df) then
81 call this%init_handler()
82 else if (stage == stg_aft_con_cr) then
83 call this%after_con_cr()
84 else if (stage == stg_bfr_con_df) then
85 call this%before_con_df()
86 else if (stage == stg_aft_con_df) then
87 call this%after_con_df()
88 end if
89
90 call this%virtual_data_mgr%synchronize(stage)
91 call this%mapper%scatter(0, stage)
92
93 end subroutine ctrl_at_stage
94
95 subroutine init_handler(this)
97 class(runcontroltype), target :: this
98
99 call this%virtual_data_mgr%create(simulation_mode)
100 call this%virtual_data_mgr%init()
101 call this%mapper%init()
102
103 end subroutine init_handler
104
105 !> @brief Actions after connections have been created
106 !<
107 subroutine ctrl_after_con_cr(this)
108 class(runcontroltype) :: this
109
110 call this%virtual_data_mgr%activate_halo()
111
112 end subroutine ctrl_after_con_cr
113
114 !> @brief Actions before defining the connections
115 !!
116 !! Set up the virtual data manager:
117 !! The models and exchanges in the halo for this interface
118 !! have been determined. Add them to the virtual data manager
119 !! for synchronization. (After which the interface model
120 !< grids can be constructed)
121 subroutine before_con_df(this)
122 class(runcontroltype), target :: this
123 ! local
124 integer(I4B) :: i
125 class(*), pointer :: obj_ptr
126 class(numericalsolutiontype), pointer :: sol
127
128 ! Add (halo) models and exchanges to the virtual
129 ! solutions. Set the synchronization handler
130 ! in the numerical solution.
131 do i = 1, basesolutionlist%Count()
132 obj_ptr => basesolutionlist%GetItem(i)
133 select type (obj_ptr)
134 class is (numericalsolutiontype)
135 sol => obj_ptr
136 call this%virtual_data_mgr%add_solution(sol)
137 sol%synchronize => rc_solution_sync
138 sol%synchronize_ctx => this
139 end select
140 end do
141
142 ! The remote data fields in exchanges need to
143 ! be copied in from the virtual exchanges
144 call this%mapper%add_exchange_vars()
145
146 end subroutine before_con_df
147
148 !> @brief Actions after defining connections
149 !<
150 subroutine after_con_df(this)
151 class(runcontroltype) :: this
152
153 ! Reduce the halo
154 call this%virtual_data_mgr%compress_halo()
155
156 ! Add variables in interface models to the mapper
157 call this%mapper%add_interface_vars()
158
159 end subroutine after_con_df
160
161 !> @brief Synchronizes from within numerical solution (delegate)
162 !<
163 subroutine rc_solution_sync(num_sol, stage, ctx)
165 class(numericalsolutiontype) :: num_sol
166 integer(I4B) :: stage
167 class(*), pointer :: ctx
168
169 select type (ctx)
170 class is (runcontroltype)
171 call ctx%virtual_data_mgr%synchronize_sln(num_sol%id, stage)
172 call ctx%mapper%scatter(num_sol%id, stage)
173 end select
174
175 end subroutine rc_solution_sync
176
177 subroutine destroy(this)
178 class(runcontroltype) :: this
179
180 call this%virtual_data_mgr%destroy()
181 deallocate (this%virtual_data_mgr)
182
183 end subroutine destroy
184
185end module runcontrolmodule
This module defines variable data types.
Definition kind.f90:8
type(listtype), public basesolutionlist
Definition mf6lists.f90:19
subroutine destroy(this)
Definition Mapper.f90:360
Previous variable names checked in as deprecated aliases.
subroutine, public mem_alias_da()
Clear the recorded aliases.
subroutine, public mem_write_usage(iout)
Write memory manager memory usage based on the user-specified memory_print_option.
subroutine, public mem_da()
Deallocate memory in the memory manager.
type(profilertype), public g_prof
the global timer object (to reduce trivial lines of code)
Definition Profiler.f90:70
subroutine start(this, title, section_id)
Start section timing, add when not exist yet (i.e. when id < 1).
Definition Profiler.f90:177
subroutine rc_solution_sync(num_sol, stage, ctx)
Synchronizes from within numerical solution (delegate).
subroutine before_con_df(this)
Actions before defining the connections.
class(runcontroltype) function, pointer, public create_seq_run_control()
subroutine ctrl_at_stage(this, stage)
This will call the handler for a particular stage.
subroutine init_handler(this)
subroutine after_con_df(this)
Actions after defining connections.
subroutine ctrl_after_con_cr(this)
Actions after connections have been created.
subroutine ctrl_finish(this)
subroutine ctrl_start(this)
This module contains simulation methods.
Definition Sim.f90:10
subroutine, public final_message()
Create final message.
Definition Sim.f90:477
integer(i4b), parameter, public stg_aft_con_df
after connection define
Definition SimStages.f90:15
integer(i4b), parameter, public stg_bfr_mdl_df
before model define
Definition SimStages.f90:10
integer(i4b), parameter, public stg_aft_con_cr
after connection create
Definition SimStages.f90:13
integer(i4b), parameter, public stg_bfr_con_df
before connection define
Definition SimStages.f90:14
This module contains simulation variables.
character(len=linelength) simulation_mode
integer(i4b) iout
file unit number for simulation output
subroutine, public elapsed_time(iout, iprtim)
Get end time and calculate elapsed time.
Definition Timer.f90:36