MODFLOW 6  version 6.7.0.dev1
USGS Modular Hydrologic Model
RunControl.f90
Go to the documentation of this file.
2  use kindmodule, only: i4b
4  use virtualdatamanagermodule
5  use mappermodule
9  implicit none
10  private
11 
12  public :: create_seq_run_control
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 
31 contains
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
50  use timermodule, only: elapsed_time
51  use simmodule, only: final_message
52  class(runcontroltype) :: this
53 
54  ! clean up
55  call this%destroy()
56 
57  ! -- Write memory usage, elapsed time and terminate
58  call mem_write_usage(iout)
59  call mem_da()
60 
61  ! stop and print timings
62  call g_prof%stop(g_prof%tmr_finalize)
63  call g_prof%stop(g_prof%tmr_run)
64  call g_prof%print(iout)
65  call g_prof%destroy()
66 
67  call elapsed_time(iout, 1)
68  call final_message()
69 
70  end subroutine ctrl_finish
71 
72  !> @brief This will call the handler for a particular stage
73  !< in the simulation run
74  subroutine ctrl_at_stage(this, stage)
75  class(runcontroltype) :: this
76  integer(I4B) :: stage
77 
78  if (stage == stg_bfr_mdl_df) then
79  call this%init_handler()
80  else if (stage == stg_aft_con_cr) then
81  call this%after_con_cr()
82  else if (stage == stg_bfr_con_df) then
83  call this%before_con_df()
84  else if (stage == stg_aft_con_df) then
85  call this%after_con_df()
86  end if
87 
88  call this%virtual_data_mgr%synchronize(stage)
89  call this%mapper%scatter(0, stage)
90 
91  end subroutine ctrl_at_stage
92 
93  subroutine init_handler(this)
95  class(runcontroltype), target :: this
96 
97  call this%virtual_data_mgr%create(simulation_mode)
98  call this%virtual_data_mgr%init()
99  call this%mapper%init()
100 
101  end subroutine init_handler
102 
103  !> @brief Actions after connections have been created
104  !<
105  subroutine ctrl_after_con_cr(this)
106  class(runcontroltype) :: this
107 
108  call this%virtual_data_mgr%activate_halo()
109 
110  end subroutine ctrl_after_con_cr
111 
112  !> @brief Actions before defining the connections
113  !!
114  !! Set up the virtual data manager:
115  !! The models and exchanges in the halo for this interface
116  !! have been determined. Add them to the virtual data manager
117  !! for synchronization. (After which the interface model
118  !< grids can be constructed)
119  subroutine before_con_df(this)
120  class(runcontroltype), target :: this
121  ! local
122  integer(I4B) :: i
123  class(*), pointer :: obj_ptr
124  class(numericalsolutiontype), pointer :: sol
125 
126  ! Add (halo) models and exchanges to the virtual
127  ! solutions. Set the synchronization handler
128  ! in the numerical solution.
129  do i = 1, basesolutionlist%Count()
130  obj_ptr => basesolutionlist%GetItem(i)
131  select type (obj_ptr)
132  class is (numericalsolutiontype)
133  sol => obj_ptr
134  call this%virtual_data_mgr%add_solution(sol)
135  sol%synchronize => rc_solution_sync
136  sol%synchronize_ctx => this
137  end select
138  end do
139 
140  ! The remote data fields in exchanges need to
141  ! be copied in from the virtual exchanges
142  call this%mapper%add_exchange_vars()
143 
144  end subroutine before_con_df
145 
146  !> @brief Actions after defining connections
147  !<
148  subroutine after_con_df(this)
149  class(runcontroltype) :: this
150 
151  ! Reduce the halo
152  call this%virtual_data_mgr%compress_halo()
153 
154  ! Add variables in interface models to the mapper
155  call this%mapper%add_interface_vars()
156 
157  end subroutine after_con_df
158 
159  !> @brief Synchronizes from within numerical solution (delegate)
160  !<
161  subroutine rc_solution_sync(num_sol, stage, ctx)
163  class(numericalsolutiontype) :: num_sol
164  integer(I4B) :: stage
165  class(*), pointer :: ctx
166 
167  select type (ctx)
168  class is (runcontroltype)
169  call ctx%virtual_data_mgr%synchronize_sln(num_sol%id, stage)
170  call ctx%mapper%scatter(num_sol%id, stage)
171  end select
172 
173  end subroutine rc_solution_sync
174 
175  subroutine destroy(this)
176  class(runcontroltype) :: this
177 
178  call this%virtual_data_mgr%destroy()
179  deallocate (this%virtual_data_mgr)
180 
181  end subroutine destroy
182 
183 end 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:340
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:65
subroutine start(this, title, section_id)
Start section timing, add when not exist yet (i.e. when id < 1)
Definition: Profiler.f90:144
subroutine rc_solution_sync(num_sol, stage, ctx)
Synchronizes from within numerical solution (delegate)
Definition: RunControl.f90:162
subroutine before_con_df(this)
Actions before defining the connections.
Definition: RunControl.f90:120
class(runcontroltype) function, pointer, public create_seq_run_control()
Definition: RunControl.f90:34
subroutine ctrl_at_stage(this, stage)
This will call the handler for a particular stage.
Definition: RunControl.f90:75
subroutine init_handler(this)
Definition: RunControl.f90:94
subroutine after_con_df(this)
Actions after defining connections.
Definition: RunControl.f90:149
subroutine ctrl_after_con_cr(this)
Actions after connections have been created.
Definition: RunControl.f90:106
subroutine ctrl_finish(this)
Definition: RunControl.f90:48
subroutine ctrl_start(this)
Definition: RunControl.f90:41
This module contains simulation methods.
Definition: Sim.f90:10
subroutine, public final_message()
Create final message.
Definition: Sim.f90:472
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.
Definition: SimVariables.f90:9
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