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 implicit none
38 private
39
49 real(kind=rp) :: frequency = 0
51 real(kind=rp) :: time_interval = 0
53 integer :: nsteps = 0
55 real(kind=rp) :: end_time = 0
57 integer :: nexecutions = 0
59 real(kind=rp) :: start_time
61 logical :: never = .false.
64 character(len=:), allocatable :: control_mode
66 real(kind=rp) :: control_value
67
68 contains
70 procedure, pass(this) :: init => time_based_controller_init
72 procedure, pass(this) :: check => time_based_controller_check
74 procedure, pass(this) :: register_execution => &
77 procedure, pass(this) :: set_counter => &
79
81
82 interface assignment(=)
84 end interface assignment(=)
85
86contains
87
93 subroutine time_based_controller_init(this, end_time, control_mode, &
94 control_value, start_time)
95 class(time_based_controller_t), intent(inout) :: this
96 real(kind=rp), intent(in) :: end_time
97 character(len=*), intent(in) :: control_mode
98 real(kind=rp), intent(in) :: control_value
99 real(kind=rp), intent(in), optional :: start_time
100
101 this%end_time = end_time
102 this%control_mode = control_mode
103 this%control_value = control_value
104 if (present(start_time)) then
105 this%start_time = start_time
106 else
107 this%start_time = 0.0_rp
108 end if
109
110 if (trim(control_mode) .eq. 'simulationtime') then
111 this%time_interval = control_value
112 this%frequency = 1/this%time_interval
113 this%nsteps = 0
114 else if (trim(control_mode) .eq. 'nsamples') then
115 if (control_value .le. 0) then
116 call neko_error("nsamples must be positive")
117 end if
118
119 this%frequency = control_value / end_time
120 this%time_interval = 1.0_rp / this%frequency
121 this%nsteps = 0
122 else if (trim(control_mode) .eq. 'tsteps') then
123 this%nsteps = control_value
124 ! if the timestep will be variable, we cannot compute these.
125 this%frequency = 0
126 this%time_interval = 0
127 else if (trim(control_mode) .eq. 'never') then
128 this%never = .true.
129 else
130 call neko_error("The control parameter must be simulationtime, nsamples&
131 & tsteps, or never, but received "//trim(control_mode))
132 end if
133 end subroutine time_based_controller_init
134
142 function time_based_controller_check(this, t, tstep, force) result(check)
143 class(time_based_controller_t), intent(inout) :: this
144 real(kind=rp), intent(in) :: t
145 integer, intent(in) :: tstep
146 logical, intent(in), optional :: force
147 logical :: check
148 logical :: ifforce
149
150 if (present(force)) then
151 ifforce = force
152 else
153 ifforce = .false.
154 end if
155
156 check = .false.
157 if (ifforce) then
158 check = .true.
159 else if (this%never) then
160 check = .false.
161 else if (t .lt. this%start_time) then
162 check = .false.
163 else if ( (this%nsteps .eq. 0) .and. &
164 (t .ge. this%nexecutions * this%time_interval) ) then
165 check = .true.
166 else if (this%nsteps .gt. 0) then
167 if (mod(tstep, this%nsteps) .eq. 0) then
168 check = .true.
169 end if
170 end if
171 end function time_based_controller_check
172
176 subroutine time_based_controller_assignment(ctrl1, ctrl2)
177 type(time_based_controller_t), intent(inout) :: ctrl1
178 type(time_based_controller_t), intent(in) :: ctrl2
179
180 ctrl1%end_time = ctrl2%end_time
181 ctrl1%frequency = ctrl2%frequency
182 ctrl1%nsteps = ctrl2%nsteps
183 ctrl1%time_interval = ctrl2%time_interval
184 ctrl1%nexecutions = ctrl2%nexecutions
185
187
190 class(time_based_controller_t), intent(inout) :: this
191
192 this%nexecutions = this%nexecutions + 1
193
195
199 class(time_based_controller_t), intent(inout) :: this
200 real(kind=rp), intent(in) :: t
201
202 if (this%nsteps .eq. 0) then
203 this%nexecutions = int(t / this%time_interval) + 1
204 end if
205
207
208
209end 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_assignment(ctrl1, ctrl2)
Assignment operator. Simply copies attribute values.
subroutine time_based_controller_set_counter(this, t)
Set the counter based on a time (for restarts)
subroutine time_based_controller_register_execution(this)
Increment nexectutions.
subroutine time_based_controller_init(this, end_time, control_mode, control_value, start_time)
Constructor.
logical function time_based_controller_check(this, t, tstep, force)
Check if the execution should be performed.
Utilities.
Definition utils.f90:35
A utility type for determening whether an action should be executed based on the current time value....