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%user_init_modules(c%time%t, c%fluid_adj%u_adj, &
81 c%fluid_adj%v_adj, c%fluid_adj%w_adj, &
82 c%fluid_adj%p_adj, c%fluid_adj%c_Xh, c%case%params)
83 call neko_log%end_section()
84 call neko_log%newline()
89 subroutine simulation_adjoint_finalize(C)
91 logical :: output_at_end
94 call json_get_or_default(c%case%params,
'case.output_at_end', &
95 output_at_end, .true.)
96 call c%output_controller%execute(c%time, output_at_end)
98 if (.not. (output_at_end) .and. c%time%t .lt. c%time%end_time)
then
99 call simulation_adjoint_joblimit_chkp(c, c%time%t)
103 call c%case%user%user_finalize_modules(c%time%t, c%case%params)
105 call neko_log%end_section(
'Normal end.')
110 subroutine simulation_adjoint_step(C, dt_controller, cfl, tstep_loop_start_time)
112 real(kind=rp),
intent(inout) :: cfl
113 type(time_step_controller_t),
intent(inout) :: dt_controller
114 real(kind=dp),
intent(in) :: tstep_loop_start_time
115 real(kind=dp) :: start_time, end_time, tstep_start_time
116 character(len=LOG_SIZE) :: log_buf
119 call profiler_start_region(
'Time-Step Adjoint')
120 c%time%tstep = c%time%tstep + 1
121 start_time = mpi_wtime()
122 tstep_start_time = start_time
127 cfl = c%fluid_adj%compute_cfl(c%time%dt)
128 call dt_controller%set_dt(c%time, cfl)
129 if (dt_controller%is_variable_dt) cfl = c%fluid_adj%compute_cfl(c%time%dt)
135 call simulation_settime(c%time, c%fluid_adj%ext_bdf)
137 call neko_log%begin()
139 write(log_buf,
'(A,E15.7,1x,A,E15.7)')
'CFL:', cfl,
'dt:', c%time%dt
140 call neko_log%message(log_buf)
144 if (
allocated(c%adjoint_scalars))
then
145 start_time = mpi_wtime()
146 call neko_log%section(
'Adjoint scalar')
147 call c%adjoint_scalars%step(c%time, &
148 c%case%fluid%ext_bdf, dt_controller)
149 end_time = mpi_wtime()
150 write(log_buf,
'(A,E15.7)') &
151 'Scalar step time: ', end_time-start_time
152 call neko_log%end_section(log_buf)
156 call neko_log%section(
'Adjoint fluid')
157 call c%fluid_adj%step(c%time, dt_controller)
158 end_time = mpi_wtime()
159 write(log_buf,
'(A,E15.7)') &
160 'Fluid step time (s): ', end_time-start_time
161 call neko_log%end_section(log_buf)
164 call neko_log%section(
'Postprocessing')
167 call c%output_controller%execute(c%time)
169 call neko_log%end_section()
172 end_time = mpi_wtime()
173 call neko_log%section(
'Step summary')
174 write(log_buf,
'(A,I8,A,E15.7)') &
175 'Total time for step ', c%time%tstep,
' (s): ', end_time-tstep_start_time
176 call neko_log%message(log_buf)
177 write(log_buf,
'(A,E15.7)') &
178 'Total elapsed time (s): ', end_time-tstep_loop_start_time
179 call neko_log%message(log_buf)
181 call neko_log%end_section()
183 call profiler_end_region
213 subroutine simulation_adjoint_restart(C)
216 type(file_t) :: chkpf, previous_meshf
217 character(len=LOG_SIZE) :: log_buf
218 character(len=:),
allocatable :: restart_file
219 character(len=:),
allocatable :: restart_mesh_file
223 call c%case%params%get(
'case.restart_file', restart_file, found)
224 call c%case%params%get(
'case.restart_mesh_file', restart_mesh_file, found)
227 call previous_meshf%init(trim(restart_mesh_file))
228 call previous_meshf%read(c%fluid_adj%chkp%previous_mesh)
231 call c%case%params%get(
'case.mesh2mesh_tolerance', tol, found)
233 if (found) c%case%fluid%chkp%mesh2mesh_tol = tol
235 call chkpf%init(trim(restart_file))
236 call chkpf%read(c%fluid_adj%chkp)
237 c%time%dtlag = c%fluid_adj%chkp%dtlag
238 c%time%tlag = c%fluid_adj%chkp%tlag
241 do i = 1,
size(c%time%dtlag)
242 call c%case%fluid%ext_bdf%set_coeffs(c%time%dtlag)
245 call c%fluid_adj%restart(c%case%chkp)
246 call c%case%fluid%chkp%previous_mesh%free()
247 if (
allocated(c%adjoint_scalars))
then
248 call c%adjoint_scalars%restart(c%case%chkp)
251 c%time%t = c%case%fluid%chkp%restart_time()
252 call neko_log%section(
'Restarting from checkpoint')
253 write(log_buf,
'(A,A)')
'File : ', trim(restart_file)
254 call neko_log%message(log_buf)
255 write(log_buf,
'(A,E15.7)')
'Time : ', c%time%t
256 call neko_log%message(log_buf)
257 call neko_log%end_section()
259 call c%output_controller%set_counter(c%time)