MODFLOW 6  version 6.6.0.dev0
USGS Modular Hydrologic Model
RunControl.f90
Go to the documentation of this file.
2  use kindmodule, only: i4b
4  use virtualdatamanagermodule
5  use mappermodule
8  implicit none
9  private
10 
11  public :: create_seq_run_control
12 
13  type, public :: runcontroltype
14  class(virtualdatamanagertype), pointer :: virtual_data_mgr !< syncs globally accessible data, timely, by
15  !! linking (local) or message passing (remote)
16  type(mappertype) :: mapper !< a 'mapper' for copying data between two memory addresses
17  contains
18  procedure :: start => ctrl_start
19  procedure :: at_stage => ctrl_at_stage
20  procedure :: finish => ctrl_finish
21  procedure :: after_con_cr => ctrl_after_con_cr
22  ! private
23  procedure, private :: init_handler
24  procedure, private :: before_con_df
25  procedure, private :: after_con_df
26  procedure, private :: destroy
27  end type runcontroltype
28 
29 contains
30 
31  function create_seq_run_control() result(run_controller)
32  class(runcontroltype), pointer :: run_controller
33 
34  allocate (run_controller)
35 
36  end function create_seq_run_control
37 
38  subroutine ctrl_start(this)
39  class(runcontroltype) :: this
40 
41  allocate (this%virtual_data_mgr)
42 
43  end subroutine ctrl_start
44 
45  subroutine ctrl_finish(this)
46  use simvariablesmodule, only: iout
48  use timermodule, only: elapsed_time
49  use simmodule, only: final_message
50  class(runcontroltype) :: this
51 
52  ! clean up
53  call this%destroy()
54 
55  ! -- Write memory usage, elapsed time and terminate
56  call mem_write_usage(iout)
57  call mem_da()
58  call elapsed_time(iout, 1)
59  call final_message()
60 
61  end subroutine ctrl_finish
62 
63  !> @brief This will call the handler for a particular stage
64  !< in the simulation run
65  subroutine ctrl_at_stage(this, stage)
66  class(runcontroltype) :: this
67  integer(I4B) :: stage
68 
69  if (stage == stg_bfr_mdl_df) then
70  call this%init_handler()
71  else if (stage == stg_aft_con_cr) then
72  call this%after_con_cr()
73  else if (stage == stg_bfr_con_df) then
74  call this%before_con_df()
75  else if (stage == stg_aft_con_df) then
76  call this%after_con_df()
77  end if
78 
79  call this%virtual_data_mgr%synchronize(stage)
80  call this%mapper%scatter(0, stage)
81 
82  end subroutine ctrl_at_stage
83 
84  subroutine init_handler(this)
86  class(runcontroltype), target :: this
87 
88  call this%virtual_data_mgr%create(simulation_mode)
89  call this%virtual_data_mgr%init()
90  call this%mapper%init()
91 
92  end subroutine init_handler
93 
94  !> @brief Actions after connections have been created
95  !<
96  subroutine ctrl_after_con_cr(this)
97  class(runcontroltype) :: this
98 
99  call this%virtual_data_mgr%activate_halo()
100 
101  end subroutine ctrl_after_con_cr
102 
103  !> @brief Actions before defining the connections
104  !!
105  !! Set up the virtual data manager:
106  !! The models and exchanges in the halo for this interface
107  !! have been determined. Add them to the virtual data manager
108  !! for synchronization. (After which the interface model
109  !< grids can be constructed)
110  subroutine before_con_df(this)
111  class(runcontroltype), target :: this
112  ! local
113  integer(I4B) :: i
114  class(*), pointer :: obj_ptr
115  class(numericalsolutiontype), pointer :: sol
116 
117  ! Add (halo) models and exchanges to the virtual
118  ! solutions. Set the synchronization handler
119  ! in the numerical solution.
120  do i = 1, basesolutionlist%Count()
121  obj_ptr => basesolutionlist%GetItem(i)
122  select type (obj_ptr)
123  class is (numericalsolutiontype)
124  sol => obj_ptr
125  call this%virtual_data_mgr%add_solution(sol)
126  sol%synchronize => rc_solution_sync
127  sol%synchronize_ctx => this
128  end select
129  end do
130 
131  ! The remote data fields in exchanges need to
132  ! be copied in from the virtual exchanges
133  call this%mapper%add_exchange_vars()
134 
135  end subroutine before_con_df
136 
137  !> @brief Actions after defining connections
138  !<
139  subroutine after_con_df(this)
140  class(runcontroltype) :: this
141 
142  ! Reduce the halo
143  call this%virtual_data_mgr%compress_halo()
144 
145  ! Add variables in interface models to the mapper
146  call this%mapper%add_interface_vars()
147 
148  end subroutine after_con_df
149 
150  !> @brief Synchronizes from within numerical solution (delegate)
151  !<
152  subroutine rc_solution_sync(num_sol, stage, ctx)
154  class(numericalsolutiontype) :: num_sol
155  integer(I4B) :: stage
156  class(*), pointer :: ctx
157 
158  select type (ctx)
159  class is (runcontroltype)
160  call ctx%virtual_data_mgr%synchronize_sln(num_sol%id, stage)
161  call ctx%mapper%scatter(num_sol%id, stage)
162  end select
163 
164  end subroutine rc_solution_sync
165 
166  subroutine destroy(this)
167  class(runcontroltype) :: this
168 
169  call this%virtual_data_mgr%destroy()
170  deallocate (this%virtual_data_mgr)
171 
172  end subroutine destroy
173 
174 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.
subroutine rc_solution_sync(num_sol, stage, ctx)
Synchronizes from within numerical solution (delegate)
Definition: RunControl.f90:153
subroutine before_con_df(this)
Actions before defining the connections.
Definition: RunControl.f90:111
class(runcontroltype) function, pointer, public create_seq_run_control()
Definition: RunControl.f90:32
subroutine ctrl_at_stage(this, stage)
This will call the handler for a particular stage.
Definition: RunControl.f90:66
subroutine init_handler(this)
Definition: RunControl.f90:85
subroutine after_con_df(this)
Actions after defining connections.
Definition: RunControl.f90:140
subroutine ctrl_after_con_cr(this)
Actions after connections have been created.
Definition: RunControl.f90:97
subroutine ctrl_finish(this)
Definition: RunControl.f90:46
subroutine ctrl_start(this)
Definition: RunControl.f90:39
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