56 subroutine solve_adjoint(this)
59 real(kind=rp) :: t_adj
60 real(kind=dp) :: start_time_org, start_time, end_time
61 character(len=LOG_SIZE) :: log_buf
63 logical :: output_at_end
64 type(time_step_controller_t) :: dt_controller
77 call neko_log%section(
'Starting adjoint')
78 write(log_buf,
'(A,E15.7,A,E15.7,A)')
'T : [', 0d0,
', ', &
79 this%case%time%end_time,
')'
80 call neko_log%message(log_buf)
81 call dt_controller%init(this%case%params)
82 if (.not. dt_controller%if_variable_dt)
then
83 write(log_buf,
'(A, E15.7)')
'dt : ', this%case%time%dt
84 call neko_log%message(log_buf)
86 write(log_buf,
'(A, E15.7)')
'CFL : ', dt_controller%set_cfl
87 call neko_log%message(log_buf)
91 call neko_log%section(
'Postprocessing')
93 call this%output_controller%execute(this%case%time)
98 call this%case%usr%user_init_modules(t_adj, this%fluid_adj%u_adj, &
99 this%fluid_adj%v_adj, this%fluid_adj%w_adj,&
100 this%fluid_adj%p_adj, this%fluid_adj%c_Xh, this%case%params)
101 call neko_log%end_section()
102 call neko_log%newline()
105 start_time_org = mpi_wtime()
107 do while (t_adj .lt. this%case%time%end_time .and. &
108 (.not. jobctrl_time_limit()))
109 call profiler_start_region(
'Time-Step')
110 tstep_adj = tstep_adj + 1
111 start_time = mpi_wtime()
113 call this%case%time%status()
114 call neko_log%message(log_buf)
115 call neko_log%begin()
119 call neko_log%message(log_buf)
120 call simulation_settime(t_adj, this%case%time%dt, &
121 this%case%fluid%ext_bdf, this%case%time%tlag, &
122 this%case%time%dtlag, tstep_adj)
127 if (
allocated(this%scalar_adj))
then
128 start_time = mpi_wtime()
129 call neko_log%section(
' Adjoint scalar')
130 call this%scalar_adj%step(t_adj, tstep_adj, this%case%time%dt, &
131 this%case%fluid%ext_bdf, dt_controller)
132 end_time = mpi_wtime()
133 write(log_buf,
'(A,E15.7,A,E15.7)') &
134 'Elapsed time (s):', end_time-start_time_org,
' Step time:', &
136 call neko_log%end_section(log_buf)
139 call neko_log%section(
'Adjoint fluid')
140 call this%fluid_adj%step(t_adj, tstep_adj, this%case%time%dt, &
141 this%case%fluid%ext_bdf, dt_controller)
142 end_time = mpi_wtime()
143 write(log_buf,
'(A,E15.7,A,E15.7)') &
144 'Elapsed time (s):', end_time-start_time_org,
' Step time:', &
146 call neko_log%end_section(log_buf)
149 call neko_log%section(
'Postprocessing')
152 call this%output_controller%execute(this%case%time)
154 call neko_log%end_section()
157 call profiler_end_region
161 call json_get_or_default(this%case%params,
'case.output_at_end',&
162 output_at_end, .true.)
163 call this%output_controller%execute(this%case%time, output_at_end)
165 if (.not. (output_at_end) .and. t_adj .lt. this%case%time%end_time)
then
166 call simulation_joblimit_chkp(this%case, t_adj)
169 call this%case%usr%user_finalize_modules(t_adj, this%case%params)
171 call neko_log%end_section(
'Normal end.')
175 subroutine simulation_settime(t, dt, ext_bdf, tlag, dtlag, step)
204 subroutine simulation_restart(C, t)
205 type(case_t),
intent(inout) :: c
206 real(kind=rp),
intent(inout) :: t
208 type(file_t) :: chkpf, previous_meshf
209 character(len=LOG_SIZE) :: log_buf
210 character(len=:),
allocatable :: restart_file
211 character(len=:),
allocatable :: restart_mesh_file
215 call c%params%get(
'case.restart_file', restart_file, found)
216 call c%params%get(
'case.restart_mesh_file', restart_mesh_file, found)
219 previous_meshf = file_t(trim(restart_mesh_file))
220 call previous_meshf%read(c%fluid%chkp%previous_mesh)
223 call c%params%get(
'case.mesh2mesh_tolerance', tol,&
226 if (found) c%fluid%chkp%mesh2mesh_tol = tol
228 chkpf = file_t(trim(restart_file))
229 call chkpf%read(c%fluid%chkp)
230 c%time%dtlag = c%fluid%chkp%dtlag
231 c%time%tlag = c%fluid%chkp%tlag
234 call c%fluid%chkp%previous_mesh%free()
235 do i = 1,
size(c%time%dtlag)
236 call c%fluid%ext_bdf%set_coeffs(c%time%dtlag)
239 call c%fluid%restart(c%chkp)
240 if (
allocated(c%scalar))
call c%scalar%restart(c%chkp)
242 t = c%fluid%chkp%restart_time()
243 call neko_log%section(
'Restarting from checkpoint')
244 write(log_buf,
'(A,A)')
'File : ', trim(restart_file)
245 call neko_log%message(log_buf)
246 write(log_buf,
'(A,E15.7)')
'Time : ', t
247 call neko_log%message(log_buf)
248 call neko_log%end_section()
250 call c%output_controller%set_counter(c%time)