59 subroutine simulation_adjoint_init(C, dt_controller)
61 type(time_step_controller_t),
intent(inout) :: dt_controller
62 character(len=LOG_SIZE) :: log_buf
65 call neko_log%section(
'Adjoint Starting simulation')
66 write(log_buf,
'(A, E15.7,A,E15.7,A)') &
67 'T : [', c%time%t,
',', c%time%end_time,
']'
68 call neko_log%message(log_buf)
69 if (.not. dt_controller%is_variable_dt)
then
70 write(log_buf,
'(A, E15.7)')
'dt : ', c%time%dt
72 write(log_buf,
'(A, E15.7)')
'CFL : ', dt_controller%cfl_trg
74 call neko_log%message(log_buf)
77 call neko_log%section(
'Postprocessing')
78 call c%output_controller%execute(c%time)
80 call c%case%user%initialize(c%time)
81 call neko_log%end_section()
82 call neko_log%newline()
87 subroutine simulation_adjoint_finalize(C)
89 logical :: output_at_end
92 call json_get_or_default(c%case%params,
'case.output_at_end', &
93 output_at_end, .true.)
94 call c%output_controller%execute(c%time, output_at_end)
96 if (.not. (output_at_end) .and. c%time%t .lt. c%time%end_time)
then
97 call simulation_adjoint_joblimit_chkp(c, c%time%t)
101 call c%case%user%finalize(c%time)
103 call neko_log%end_section(
'Normal end.')
108 subroutine simulation_adjoint_step(C, dt_controller, cfl, tstep_loop_start_time)
110 real(kind=rp),
intent(inout) :: cfl
111 type(time_step_controller_t),
intent(inout) :: dt_controller
112 real(kind=dp),
intent(in) :: tstep_loop_start_time
113 real(kind=dp) :: start_time, end_time, tstep_start_time
114 character(len=LOG_SIZE) :: log_buf
117 call profiler_start_region(
'Time-Step Adjoint')
118 c%time%tstep = c%time%tstep + 1
119 start_time = mpi_wtime()
120 tstep_start_time = start_time
125 cfl = c%fluid_adj%compute_cfl(c%time%dt)
126 call dt_controller%set_dt(c%time, cfl)
127 if (dt_controller%is_variable_dt) cfl = c%fluid_adj%compute_cfl(c%time%dt)
133 call simulation_settime(c%time, c%fluid_adj%ext_bdf)
135 call neko_log%begin()
137 write(log_buf,
'(A,E15.7,1x,A,E15.7)')
'CFL:', cfl,
'dt:', c%time%dt
138 call neko_log%message(log_buf)
142 if (
allocated(c%adjoint_scalars))
then
143 start_time = mpi_wtime()
144 call neko_log%section(
'Adjoint scalar')
145 call c%adjoint_scalars%step(c%time, &
146 c%case%fluid%ext_bdf, dt_controller)
147 end_time = mpi_wtime()
148 write(log_buf,
'(A,E15.7)') &
149 'Scalar step time: ', end_time-start_time
150 call neko_log%end_section(log_buf)
154 call neko_log%section(
'Adjoint fluid')
155 call c%fluid_adj%step(c%time, dt_controller)
156 end_time = mpi_wtime()
157 write(log_buf,
'(A,E15.7)') &
158 'Fluid step time (s): ', end_time-start_time
159 call neko_log%end_section(log_buf)
162 call neko_log%section(
'Postprocessing')
165 call c%output_controller%execute(c%time)
167 call neko_log%end_section()
170 end_time = mpi_wtime()
171 call neko_log%section(
'Step summary')
172 write(log_buf,
'(A,I8,A,E15.7)') &
173 'Total time for step ', c%time%tstep,
' (s): ', end_time-tstep_start_time
174 call neko_log%message(log_buf)
175 write(log_buf,
'(A,E15.7)') &
176 'Total elapsed time (s): ', end_time-tstep_loop_start_time
177 call neko_log%message(log_buf)
179 call neko_log%end_section()
181 call profiler_end_region
211 subroutine simulation_adjoint_restart(C)
214 type(file_t) :: chkpf, previous_meshf
215 character(len=LOG_SIZE) :: log_buf
216 character(len=:),
allocatable :: restart_file
217 character(len=:),
allocatable :: restart_mesh_file
221 call c%case%params%get(
'case.restart_file', restart_file, found)
222 call c%case%params%get(
'case.restart_mesh_file', restart_mesh_file, found)
225 call previous_meshf%init(trim(restart_mesh_file))
226 call previous_meshf%read(c%fluid_adj%chkp%previous_mesh)
229 call c%case%params%get(
'case.mesh2mesh_tolerance', tol, found)
231 if (found) c%case%fluid%chkp%mesh2mesh_tol = tol
233 call chkpf%init(trim(restart_file))
234 call chkpf%read(c%fluid_adj%chkp)
235 c%time%dtlag = c%fluid_adj%chkp%dtlag
236 c%time%tlag = c%fluid_adj%chkp%tlag
239 do i = 1,
size(c%time%dtlag)
240 call c%case%fluid%ext_bdf%set_coeffs(c%time%dtlag)
243 call c%fluid_adj%restart(c%case%chkp)
244 call c%case%fluid%chkp%previous_mesh%free()
245 if (
allocated(c%adjoint_scalars))
then
246 call c%adjoint_scalars%restart(c%case%chkp)
249 c%time%t = real(c%case%fluid%chkp%restart_time(), kind=rp)
250 call neko_log%section(
'Restarting from checkpoint')
251 write(log_buf,
'(A,A)')
'File : ', trim(restart_file)
252 call neko_log%message(log_buf)
253 write(log_buf,
'(A,E15.7)')
'Time : ', c%time%t
254 call neko_log%message(log_buf)
255 call neko_log%end_section()
257 call c%output_controller%set_counter(c%time)