Loading [MathJax]/extensions/tex2jax.js
Neko 0.9.99
A portable framework for high-order spectral element flow simulations
All Classes Namespaces Files Functions Variables Typedefs Enumerator Macros Pages
time_based_controller.f90
Go to the documentation of this file.
1! Copyright (c) 2023, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
35 use num_types, only : rp
36 use utils, only : neko_error
37 use time_state, only : time_state_t
38 implicit none
39 private
40
50 real(kind=rp) :: frequency = 0
52 real(kind=rp) :: time_interval = 0
54 integer :: nsteps = 0
56 real(kind=rp) :: end_time = 0
58 integer :: nexecutions = 0
60 logical :: never = .false.
63 character(len=:), allocatable :: control_mode
65 real(kind=rp) :: control_value
66
67 contains
69 procedure, pass(this) :: init => time_based_controller_init
71 procedure, pass(this) :: check => time_based_controller_check
73 procedure, pass(this) :: register_execution => &
76 procedure, pass(this) :: set_counter => &
78
80
81 interface assignment(=)
83 end interface assignment(=)
84
85contains
86
91 subroutine time_based_controller_init(this, end_time, control_mode, &
92 control_value)
93 class(time_based_controller_t), intent(inout) :: this
94 real(kind=rp), intent(in) :: end_time
95 character(len=*), intent(in) :: control_mode
96 real(kind=rp), intent(in) :: control_value
97
98 this%end_time = end_time
99 this%control_mode = control_mode
100 this%control_value = control_value
101
102 if (trim(control_mode) .eq. 'simulationtime') then
103 this%time_interval = control_value
104 this%frequency = 1/this%time_interval
105 this%nsteps = 0
106 else if (trim(control_mode) .eq. 'nsamples') then
107 if (control_value .le. 0) then
108 call neko_error("nsamples must be positive")
109 end if
110
111 this%frequency = control_value / end_time
112 this%time_interval = 1.0_rp / this%frequency
113 this%nsteps = 0
114 else if (trim(control_mode) .eq. 'tsteps') then
115 this%nsteps = control_value
116 ! if the timestep will be variable, we cannot compute these.
117 this%frequency = 0
118 this%time_interval = 0
119 else if (trim(control_mode) .eq. 'never') then
120 this%never = .true.
121 else
122 call neko_error("The control parameter must be simulationtime, nsamples&
123 & tsteps, or never, but received "//trim(control_mode))
124 end if
125 end subroutine time_based_controller_init
126
136 function time_based_controller_check(this, time, force) result(check)
137 class(time_based_controller_t), intent(inout) :: this
138 type(time_state_t), intent(in) :: time
139 logical, intent(in), optional :: force
140 real(kind=rp) :: t
141 integer :: tstep
142 real(kind=rp) :: dt
143 logical :: check
144 logical :: ifforce
145
146 t = time%t
147 dt = time%dt
148 tstep = time%tstep
149
150
151 if (present(force)) then
152 ifforce = force
153 else
154 ifforce = .false.
155 end if
156
157 check = .false.
158 if (ifforce) then
159 check = .true.
160 else if (this%never) then
161 check = .false.
162 else if ( (this%nsteps .eq. 0) .and. &
163 (t .ge. this%nexecutions * this%time_interval - 0.1 * dt) ) then
164 check = .true.
165 else if (this%nsteps .gt. 0) then
166 if (mod(tstep, this%nsteps) .eq. 0) then
167 check = .true.
168 end if
169 end if
170 end function time_based_controller_check
171
175 subroutine time_based_controller_assignment(ctrl1, ctrl2)
176 type(time_based_controller_t), intent(inout) :: ctrl1
177 type(time_based_controller_t), intent(in) :: ctrl2
178
179 ctrl1%end_time = ctrl2%end_time
180 ctrl1%frequency = ctrl2%frequency
181 ctrl1%nsteps = ctrl2%nsteps
182 ctrl1%time_interval = ctrl2%time_interval
183 ctrl1%nexecutions = ctrl2%nexecutions
184
186
189 class(time_based_controller_t), intent(inout) :: this
190
191 this%nexecutions = this%nexecutions + 1
192
194
198 class(time_based_controller_t), intent(inout) :: this
199 type(time_state_t) :: time
200
201 if (this%nsteps .eq. 0) then
202 this%nexecutions = int((time%t+0.1_rp*time%dt) / this%time_interval) + 1
203 end if
204
206
207
208end module time_based_controller
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Contains the time_based_controller_t type.
subroutine time_based_controller_set_counter(this, time)
Set the counter based on a time (for restarts)
subroutine time_based_controller_init(this, end_time, control_mode, control_value)
Constructor.
subroutine time_based_controller_assignment(ctrl1, ctrl2)
Assignment operator. Simply copies attribute values.
logical function time_based_controller_check(this, time, force)
Check if the execution should be performed.
subroutine time_based_controller_register_execution(this)
Increment nexectutions.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
A utility type for determining whether an action should be executed based on the current time value....
A struct that contains all info about the time, expand as needed.