44submodule(simulation_checkpoint) checkpoint_linear
45 use simulation,
only: simulation_step, simulation_restart
46 use file,
only: file_t, file_free
47 use time_step_controller,
only: time_step_controller_t
54 module subroutine checkpoint_save_linear(this, neko_case)
55 class(simulation_checkpoint_t),
intent(inout) :: this
56 class(case_t),
intent(inout) :: neko_case
57 integer :: index, tstep, counter
60 time = neko_case%time%t
61 tstep = neko_case%time%tstep
64 index = modulo(tstep, this%n_saves_memory)
67 if (index .eq. 0 .or. tstep .le. this%first_valid_timestep)
then
68 this%loaded_checkpoint = tstep
70 counter = determine_counter(tstep, this%n_saves_memory, &
71 this%first_valid_timestep)
73 call this%chkp_output%set_counter(counter)
74 call this%chkp_output%sample(time)
75 this%n_saves_disc = this%n_saves_disc + 1
78 call this%save_data(index + 1)
79 end subroutine checkpoint_save_linear
85 module subroutine checkpoint_restore_linear(this, neko_case, tstep)
86 class(simulation_checkpoint_t),
intent(inout) :: this
87 class(case_t),
target,
intent(inout) :: neko_case
88 integer,
intent(in) :: tstep
89 type(time_step_controller_t) :: dt_controller
90 real(kind=dp) :: loop_start
91 integer :: k, previous_save, next_save, local_idx, counter
92 type(field_t),
pointer :: u, v, w, p, s
94 loop_start = mpi_wtime()
96 u => neko_case%fluid%u
97 v => neko_case%fluid%v
98 w => neko_case%fluid%w
99 p => neko_case%fluid%p
103 previous_save = tstep - modulo(tstep, this%n_saves_memory)
104 next_save = previous_save + this%n_saves_memory
108 if (tstep .lt. this%first_valid_timestep)
then
109 previous_save = tstep
110 next_save = previous_save + 1
111 else if (previous_save .lt. this%first_valid_timestep)
then
112 previous_save = this%first_valid_timestep
116 if (this%loaded_checkpoint .ne. previous_save)
then
119 counter = determine_counter(previous_save, this%n_saves_memory, &
120 this%first_valid_timestep)
121 call this%chkp_output%set_counter(counter)
122 call this%chkp_output%file_%read(neko_case%chkp)
123 call simulation_restart(neko_case, neko_case%chkp)
126 call dt_controller%init(neko_case%params)
127 neko_case%time%tstep = previous_save
128 this%loaded_checkpoint = neko_case%time%tstep
131 do k = previous_save, min(next_save - 1, this%n_timesteps)
134 if (k .ne. previous_save)
then
135 if (neko_case%time%t .ge. neko_case%time%end_time)
exit
136 call simulation_step(neko_case, dt_controller, loop_start)
140 local_idx = modulo(k, this%n_saves_memory) + 1
141 call this%save_data(local_idx)
146 local_idx = modulo(tstep, this%n_saves_memory) + 1
147 call this%load_data(local_idx)
148 end subroutine checkpoint_restore_linear
150 pure function determine_counter(tstep, n_memory, first)
result(counter)
151 integer,
intent(in) :: tstep, n_memory, first
154 if (tstep .le. first)
then
157 counter = first + tstep / n_memory
160 end function determine_counter
162end submodule checkpoint_linear