Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
time_state.f90
Go to the documentation of this file.
1! Copyright (c) 2025, 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
37 use json_module, only : json_file
40 implicit none
41 private
42
44 type, public :: time_state_t
45 real(kind=rp), dimension(10) :: tlag = 0.0_rp
46 real(kind=rp), dimension(10) :: dtlag = 0.0_rp
47 real(kind=rp) :: t = 0.0_rp
48 real(kind=rp) :: dt = 0.0_rp
49 real(kind=rp) :: start_time = 0.0_rp
50 real(kind=rp) :: end_time = 0.0_rp
51 integer :: tstep = 0
52
53 contains
54 generic :: init => init_from_components, init_from_json
55 procedure, pass(this) :: init_from_components => &
57 procedure, pass(this) :: init_from_json => time_state_init_from_json
58 procedure, pass(this) :: reset => time_state_reset
59 procedure, pass(this) :: status => time_state_status
60 procedure, pass(this) :: is_done => time_state_is_done
61 end type time_state_t
62
63contains
64
66 subroutine time_state_init_from_json(this, params)
67 class(time_state_t), intent(inout) :: this
68 type(json_file), intent(inout) :: params
69
70 real(kind=rp) :: time_step
71 real(kind=rp) :: start_time
72 real(kind=rp) :: end_time
73 logical :: is_variable
74
75 call json_get_or_lookup_or_default(params, 'start_time', start_time, 0.0_rp)
76 call json_get_or_lookup(params, 'end_time', end_time)
77 call json_get_or_default(params, 'variable_timestep', is_variable, .false.)
78 if (.not. is_variable) then
79 call json_get_or_lookup(params, 'timestep', time_step)
80 else
81 ! randomly set an initial dt to get cfl when dt is variable
82 time_step = 1.0_rp
83 end if
84
85 call this%init_from_components(start_time, end_time, time_step)
86
87 end subroutine time_state_init_from_json
88
90 subroutine time_state_init_from_components(this, start_time, end_time, dt)
91 class(time_state_t), intent(inout) :: this
92 real(kind=rp), intent(in) :: start_time
93 real(kind=rp), intent(in) :: end_time
94 real(kind=rp), intent(in) :: dt
95
96 if (dt .gt. 0.0_rp .and. start_time .gt. end_time .or. &
97 dt .lt. 0.0_rp .and. start_time .lt. end_time) then
98 call neko_log%error('Time step size must match direction of time.')
99 end if
100
101 this%start_time = start_time
102 this%end_time = end_time
103 this%dt = dt
104
105 this%t = start_time
106 this%tstep = 0
107 this%tlag = start_time
108 this%dtlag = dt
109
111
113 subroutine time_state_reset(this)
114 class(time_state_t), intent(inout) :: this
115
116 this%t = this%start_time
117 this%tstep = 0
118 this%tlag = this%start_time
119 this%dtlag = this%dt
120
121 end subroutine time_state_reset
122
124 subroutine time_state_status(this)
125 class(time_state_t), intent(in) :: this
126 character(len=LOG_SIZE) :: log_buf
127 character(len=64) :: log_fmt
128 real(kind=rp) :: t_prog
129 integer :: time_digits, time_width, pad_width
130
131 t_prog = 100.0_rp * (this%t - this%start_time) / &
132 (this%end_time - this%start_time)
133
134 time_digits = precision(this%t)
135 time_width = time_digits + 8
136 pad_width = max(1, log_size - (34 + time_width) - 1)
137
138 write(log_fmt, '(A,I0,A,I0,A,I0,A,I0,A)') &
139 '(A7,1X,I10,1X,A4,ES', time_width, '.', time_digits, ',', &
140 pad_width, 'X,A2,F6.2,A3)'
141 write(log_buf, log_fmt) 'Step = ', this%tstep, 't = ', this%t, &
142 '[ ', t_prog, '% ]'
143
144 call neko_log%message(repeat('-', log_size - 1))
145 call neko_log%message(log_buf, neko_log_quiet)
146 call neko_log%message(repeat('-', log_size - 1))
147
148 end subroutine time_state_status
149
151 pure function time_state_is_done(this) result(is_done)
152 class(time_state_t), intent(in) :: this
153 logical :: is_done
154
155 is_done = this%t - this%start_time .ge. this%end_time - this%start_time &
156 .and. this%tstep .gt. 0
157
158 end function time_state_is_done
159
160end module time_state
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Utilities for retrieving parameters from the case files.
Logging routines.
Definition log.f90:34
integer, parameter, public neko_log_quiet
Always logged.
Definition log.f90:82
type(log_t), public neko_log
Global log stream.
Definition log.f90:80
integer, parameter, public log_size
Definition log.f90:46
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Module with things related to the simulation time.
subroutine time_state_status(this)
Write status banner.
subroutine time_state_init_from_json(this, params)
Initialize time state from JSON.
pure logical function time_state_is_done(this)
Check if the simulation is done.
subroutine time_state_init_from_components(this, start_time, end_time, dt)
Initialize time state.
subroutine time_state_reset(this)
Reset time state.
A struct that contains all info about the time, expand as needed.
#define max(a, b)
Definition tensor.cu:40