# Execute in FluentAGI after importing the supplied 0.01 s starter case.
# Continuation script: no mesh reload and no initialization.
# All simulation, adaptive refinement and native images run inside FluentAGI.
check=fluentagi.inspect_execution(directory='C:/Users/13977/AppData/Local/FluentAGI/data/runs/20261024-204040-c178d6')
print(check)
if abs(check['actual_state']['flow_time']-0.01)>0.00000001:
    raise RuntimeError('Expected 0.01 s starter state; inspect and resume from actual progress.')
co=solver.settings.results.graphics.contour['laser-temperature']
co.field='temperature'
co.surfaces_list=['top']
co.range_option.option='auto-range-off'
co.range_option.auto_range_off.minimum=300.0
co.range_option.auto_range_off.maximum=5000.0
solver.settings.results.graphics.views.restore_view(view_name='front')
pic=solver.settings.results.graphics.picture
pic.use_window_resolution=False
pic.x_resolution=1400
pic.y_resolution=900
adapt=solver.settings.mesh.adapt
adapt.manual_refinement_criteria='hot_zone'
adapt.set.maximum_refinement_level=1
calc=solver.settings.solution.run_calculation
calc.transient_controls.time_step_size=0.001
co.display()
pic.save_picture(file_name='L:/scan_001.png')
for frame in range(2,41):
    adapt.adapt_mesh()
    calc.dual_time_iterate(time_step_count=10,max_iter_per_step=40)
    co.display()
    pic.save_picture(file_name='L:/scan_%03d.png' % frame)
    temperatures=solver.fields.field_data.get_scalar_field_data('temperature',surfaces=['top'])['top']
    print('SCAN_FRAME',frame,'TIME_S',round(frame*0.01,3),'TMAX_K',float(max(temperatures)))
    if frame % 10 == 0:
        solver.settings.file.write_case_data(file_name='L:/checkpoint_%03d.cas.h5' % frame)
solver.settings.mesh.check()
solver.settings.file.write_case_data(file_name='L:/laser_final.cas.h5')
print('SCAN_COMPLETED',40,'frames',0.40,'seconds')
