forked from MODFLOW-ORG/modflow6
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunControl.f90
More file actions
183 lines (142 loc) · 5.14 KB
/
RunControl.f90
File metadata and controls
183 lines (142 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
module RunControlModule
use KindModule, only: I4B
use SimStagesModule
use VirtualDataManagerModule
use MapperModule
use ListsModule, only: basesolutionlist
use NumericalSolutionModule, only: NumericalSolutionType
use ProfilerModule
implicit none
private
public :: create_seq_run_control
type, public :: RunControlType
class(VirtualDataManagerType), pointer :: virtual_data_mgr !< syncs globally accessible data, timely, by
!! linking (local) or message passing (remote)
type(MapperType) :: mapper !< a 'mapper' for copying data between two memory addresses
contains
procedure :: start => ctrl_start
procedure :: at_stage => ctrl_at_stage
procedure :: finish => ctrl_finish
procedure :: after_con_cr => ctrl_after_con_cr
! private
procedure, private :: init_handler
procedure, private :: before_con_df
procedure, private :: after_con_df
procedure, private :: destroy
end type RunControlType
contains
function create_seq_run_control() result(run_controller)
class(RunControlType), pointer :: run_controller
allocate (run_controller)
end function create_seq_run_control
subroutine ctrl_start(this)
class(RunControlType) :: this
allocate (this%virtual_data_mgr)
end subroutine ctrl_start
subroutine ctrl_finish(this)
use SimVariablesModule, only: iout
use MemoryManagerModule, only: mem_write_usage, mem_da
use TimerModule, only: elapsed_time
use SimModule, only: final_message
class(RunControlType) :: this
! clean up
call this%destroy()
! -- Write memory usage, elapsed time and terminate
call mem_write_usage(iout)
call mem_da()
! stop and print timings
call g_prof%stop(g_prof%tmr_finalize)
call g_prof%stop(g_prof%tmr_run)
call g_prof%print(iout)
call g_prof%destroy()
call elapsed_time(iout, 1)
call final_message()
end subroutine ctrl_finish
!> @brief This will call the handler for a particular stage
!< in the simulation run
subroutine ctrl_at_stage(this, stage)
class(RunControlType) :: this
integer(I4B) :: stage
if (stage == STG_BFR_MDL_DF) then
call this%init_handler()
else if (stage == STG_AFT_CON_CR) then
call this%after_con_cr()
else if (stage == STG_BFR_CON_DF) then
call this%before_con_df()
else if (stage == STG_AFT_CON_DF) then
call this%after_con_df()
end if
call this%virtual_data_mgr%synchronize(stage)
call this%mapper%scatter(0, stage)
end subroutine ctrl_at_stage
subroutine init_handler(this)
use SimVariablesModule, only: simulation_mode
class(RunControlType), target :: this
call this%virtual_data_mgr%create(simulation_mode)
call this%virtual_data_mgr%init()
call this%mapper%init()
end subroutine init_handler
!> @brief Actions after connections have been created
!<
subroutine ctrl_after_con_cr(this)
class(RunControlType) :: this
call this%virtual_data_mgr%activate_halo()
end subroutine ctrl_after_con_cr
!> @brief Actions before defining the connections
!!
!! Set up the virtual data manager:
!! The models and exchanges in the halo for this interface
!! have been determined. Add them to the virtual data manager
!! for synchronization. (After which the interface model
!< grids can be constructed)
subroutine before_con_df(this)
class(RunControlType), target :: this
! local
integer(I4B) :: i
class(*), pointer :: obj_ptr
class(NumericalSolutionType), pointer :: sol
! Add (halo) models and exchanges to the virtual
! solutions. Set the synchronization handler
! in the numerical solution.
do i = 1, basesolutionlist%Count()
obj_ptr => basesolutionlist%GetItem(i)
select type (obj_ptr)
class is (NumericalSolutionType)
sol => obj_ptr
call this%virtual_data_mgr%add_solution(sol)
sol%synchronize => rc_solution_sync
sol%synchronize_ctx => this
end select
end do
! The remote data fields in exchanges need to
! be copied in from the virtual exchanges
call this%mapper%add_exchange_vars()
end subroutine before_con_df
!> @brief Actions after defining connections
!<
subroutine after_con_df(this)
class(RunControlType) :: this
! Reduce the halo
call this%virtual_data_mgr%compress_halo()
! Add variables in interface models to the mapper
call this%mapper%add_interface_vars()
end subroutine after_con_df
!> @brief Synchronizes from within numerical solution (delegate)
!<
subroutine rc_solution_sync(num_sol, stage, ctx)
use NumericalSolutionModule, only: NumericalSolutionType
class(NumericalSolutionType) :: num_sol
integer(I4B) :: stage
class(*), pointer :: ctx
select type (ctx)
class is (RunControlType)
call ctx%virtual_data_mgr%synchronize_sln(num_sol%id, stage)
call ctx%mapper%scatter(num_sol%id, stage)
end select
end subroutine rc_solution_sync
subroutine destroy(this)
class(RunControlType) :: this
call this%virtual_data_mgr%destroy()
deallocate (this%virtual_data_mgr)
end subroutine destroy
end module RunControlModule