84 class(*),
target,
intent(in) :: data
85 real(kind=
rp),
intent(in),
optional :: t
87 character(len=5) :: id_str
88 character(len=1024) :: fname
89 integer :: ierr, suffix_pos, optional_fields
90 type(
field_t),
pointer :: u, v, w, p, s
91 type(
field_t),
pointer :: abx1, abx2
92 type(
field_t),
pointer :: aby1, aby2
93 type(
field_t),
pointer :: abz1, abz2
94 type(
field_t),
pointer :: abs1, abs2
99 real(kind=
rp),
pointer :: dtlag(:), tlag(:)
100 type(
mesh_t),
pointer :: msh
101 type(mpi_status) :: status
103 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, byte_offset
104 integer(kind=i8) :: n_glb_dofs, dof_offset
105 logical :: write_lag, write_scalar, write_dtlag
106 logical :: write_scalarlag, write_abvel
118 if ( .not.
associated(data%u) .or. &
119 .not.
associated(data%v) .or. &
120 .not.
associated(data%w) .or. &
121 .not.
associated(data%p) )
then
133 if (
associated(data%ulag))
then
138 optional_fields = optional_fields + 1
143 if (
associated(data%s))
then
145 write_scalar = .true.
146 optional_fields = optional_fields + 2
148 write_scalar = .false.
151 if (
associated(data%tlag))
then
155 optional_fields = optional_fields + 4
157 write_dtlag = .false.
159 write_abvel = .false.
160 if (
associated(data%abx1))
then
167 optional_fields = optional_fields + 8
170 write_scalarlag = .false.
171 if (
associated(data%abs1))
then
175 optional_fields = optional_fields + 16
176 write_scalarlag = .true.
182 dof_offset = int(msh%offset_el,
i8) * int(u%Xh%lx * u%Xh%ly * u%Xh%lz,
i8)
183 n_glb_dofs = int(u%Xh%lx * u%Xh%ly * u%Xh%lz,
i8) * int(msh%glb_nelv,
i8)
186 if (.not. this%overwrite)
call this%increment_counter()
187 fname = trim(this%get_fname())
189 call mpi_file_open(
neko_comm, trim(fname), &
190 mpi_mode_wronly + mpi_mode_create, mpi_info_null, fh, ierr)
191 call mpi_file_write_all(fh, msh%glb_nelv, 1, mpi_integer, status, ierr)
192 call mpi_file_write_all(fh, msh%gdim, 1, mpi_integer, status, ierr)
193 call mpi_file_write_all(fh, u%Xh%lx, 1, mpi_integer, status, ierr)
194 call mpi_file_write_all(fh, optional_fields, 1, mpi_integer, status, ierr)
195 call mpi_file_write_all(fh, time, 1, mpi_double_precision, status, ierr)
204 byte_offset = byte_offset + &
206 call mpi_file_write_at_all(fh, byte_offset,u%x, u%dof%size(), &
210 mpi_offset = mpi_offset +&
213 byte_offset = mpi_offset + &
215 call mpi_file_write_at_all(fh, byte_offset, v%x, v%dof%size(), &
219 byte_offset = mpi_offset + &
221 call mpi_file_write_at_all(fh, byte_offset, w%x, w%dof%size(), &
225 byte_offset = mpi_offset + &
227 call mpi_file_write_at_all(fh, byte_offset, p%x, p%dof%size(), &
237 do i = 1, ulag%size()
238 byte_offset = mpi_offset + &
243 associate(x => ulag%lf(i)%x)
244 call mpi_file_write_at_all(fh, byte_offset, x, &
250 do i = 1, vlag%size()
251 byte_offset = mpi_offset + &
256 associate(x => vlag%lf(i)%x)
257 call mpi_file_write_at_all(fh, byte_offset, x, &
260 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
263 do i = 1, wlag%size()
264 byte_offset = mpi_offset + &
265 dof_offset * int(mpi_real_prec_size, i8)
269 associate(x => wlag%lf(i)%x)
270 call mpi_file_write_at_all(fh, byte_offset, x, &
271 wlag%lf(i)%dof%size(), mpi_real_precision, status, ierr)
273 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
278 if (write_scalar)
then
279 byte_offset = mpi_offset + &
280 dof_offset * int(mpi_real_prec_size, i8)
281 call mpi_file_write_at_all(fh, byte_offset, s%x, p%dof%size(), &
282 mpi_real_precision, status, ierr)
283 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
286 if (write_dtlag)
then
287 call mpi_file_write_at_all(fh, mpi_offset, tlag, 10, &
288 mpi_real_precision, status, ierr)
289 mpi_offset = mpi_offset + 10_i8 * int(mpi_real_prec_size, i8)
290 call mpi_file_write_at_all(fh, mpi_offset, dtlag, 10, &
291 mpi_real_precision, status, ierr)
292 mpi_offset = mpi_offset + 10_i8 * int(mpi_real_prec_size, i8)
295 if (write_abvel)
then
296 byte_offset = mpi_offset + &
297 dof_offset * int(mpi_real_prec_size, i8)
298 call mpi_file_write_at_all(fh, byte_offset, abx1%x, abx1%dof%size(), &
299 mpi_real_precision, status, ierr)
300 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
301 byte_offset = mpi_offset + &
302 dof_offset * int(mpi_real_prec_size, i8)
303 call mpi_file_write_at_all(fh, byte_offset, abx2%x, abx1%dof%size(), &
304 mpi_real_precision, status, ierr)
305 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
306 byte_offset = mpi_offset + &
307 dof_offset * int(mpi_real_prec_size, i8)
308 call mpi_file_write_at_all(fh, byte_offset, aby1%x, abx1%dof%size(), &
309 mpi_real_precision, status, ierr)
310 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
311 byte_offset = mpi_offset + &
312 dof_offset * int(mpi_real_prec_size, i8)
313 call mpi_file_write_at_all(fh, byte_offset, aby2%x, abx1%dof%size(), &
314 mpi_real_precision, status, ierr)
315 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
316 byte_offset = mpi_offset + &
317 dof_offset * int(mpi_real_prec_size, i8)
318 call mpi_file_write_at_all(fh, byte_offset, abz1%x, abx1%dof%size(), &
319 mpi_real_precision, status, ierr)
320 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
321 byte_offset = mpi_offset + &
322 dof_offset * int(mpi_real_prec_size, i8)
323 call mpi_file_write_at_all(fh, byte_offset, abz2%x, abx1%dof%size(), &
324 mpi_real_precision, status, ierr)
325 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
328 if (write_scalarlag)
then
329 do i = 1, slag%size()
330 byte_offset = mpi_offset + &
331 dof_offset * int(mpi_real_prec_size, i8)
335 associate(x => slag%lf(i)%x)
336 call mpi_file_write_at_all(fh, byte_offset, x, &
337 slag%lf(i)%dof%size(), mpi_real_precision, status, ierr)
339 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
342 byte_offset = mpi_offset + &
343 dof_offset * int(mpi_real_prec_size, i8)
344 call mpi_file_write_at_all(fh, byte_offset, abs1%x, abx1%dof%size(), &
345 mpi_real_precision, status, ierr)
346 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
347 byte_offset = mpi_offset + &
348 dof_offset * int(mpi_real_prec_size, i8)
349 call mpi_file_write_at_all(fh, byte_offset, abs2%x, abx1%dof%size(), &
350 mpi_real_precision, status, ierr)
351 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
354 call mpi_file_close(fh, ierr)
356 if (ierr .ne. mpi_success)
then
357 call neko_error(
'Error writing checkpoint file ' // trim(fname))
365 class(*),
target,
intent(inout) :: data
366 type(chkp_t),
pointer :: chkp
367 character(len=5) :: id_str
368 character(len=1024) :: fname
369 integer :: ierr, suffix_pos
370 type(field_t),
pointer :: u, v, w, p, s
371 type(field_series_t),
pointer :: ulag => null()
372 type(field_series_t),
pointer :: vlag => null()
373 type(field_series_t),
pointer :: wlag => null()
374 type(field_series_t),
pointer :: slag => null()
375 type(mesh_t),
pointer :: msh
376 type(mpi_status) :: status
378 type(field_t),
pointer :: abx1, abx2
379 type(field_t),
pointer :: aby1, aby2
380 type(field_t),
pointer :: abz1, abz2
381 type(field_t),
pointer :: abs1, abs2
382 real(kind=rp),
allocatable :: x_coord(:,:,:,:)
383 real(kind=rp),
allocatable :: y_coord(:,:,:,:)
384 real(kind=rp),
allocatable :: z_coord(:,:,:,:)
385 real(kind=rp),
pointer :: dtlag(:), tlag(:)
386 integer (kind=MPI_OFFSET_KIND) :: mpi_offset, byte_offset
387 integer(kind=i8) :: n_glb_dofs, dof_offset
388 integer :: glb_nelv, gdim, lx, have_lag, have_scalar, nel
389 integer :: optional_fields, have_dtlag
390 integer :: have_abvel, have_scalarlag
391 logical :: read_lag, read_scalar, read_dtlag, read_abvel, read_scalarlag
393 real(kind=rp) :: center_x, center_y, center_z
395 type(dofmap_t) :: dof
397 call this%check_exists()
402 if ( .not.
associated(data%u) .or. &
403 .not.
associated(data%v) .or. &
404 .not.
associated(data%w) .or. &
405 .not.
associated(data%p) )
then
406 call neko_error(
'Checkpoint not initialized')
413 this%chkp_Xh => data%previous_Xh
415 if (
allocated(data%previous_mesh%elements))
then
416 msh => data%previous_mesh
417 this%mesh2mesh = .true.
418 tol = data%mesh2mesh_tol
421 this%mesh2mesh = .false.
424 if (
associated(data%ulag))
then
433 if (
associated(data%s))
then
437 read_scalar = .false.
439 if (
associated(data%dtlag))
then
447 if (
associated(data%abx1))
then
456 read_scalarlag = .false.
457 if (
associated(data%abs1))
then
461 read_scalarlag = .true.
467 call neko_error(
'Invalid data')
470 fname = trim(this%get_fname())
471 call neko_log%message(
"Reading checkpoint from file: " // trim(fname), &
473 call mpi_file_open(neko_comm, trim(fname), &
474 mpi_mode_rdonly, mpi_info_null, fh, ierr)
475 call mpi_file_read_all(fh, glb_nelv, 1, mpi_integer, status, ierr)
476 call mpi_file_read_all(fh, gdim, 1, mpi_integer, status, ierr)
477 call mpi_file_read_all(fh, lx, 1, mpi_integer, status, ierr)
478 call mpi_file_read_all(fh, optional_fields, 1, mpi_integer, status, ierr)
479 call mpi_file_read_all(fh, chkp%t, 1, mpi_double_precision, status, ierr)
481 have_lag = mod(optional_fields,2)/1
482 have_scalar = mod(optional_fields,4)/2
483 have_dtlag = mod(optional_fields,8)/4
484 have_abvel = mod(optional_fields,16)/8
485 have_scalarlag = mod(optional_fields,32)/16
487 if ( ( glb_nelv .ne. msh%glb_nelv ) .or. &
488 ( gdim .ne. msh%gdim) .or. &
489 ( (have_lag .eq. 0) .and. (read_lag) ) .or. &
490 ( (have_scalar .eq. 0) .and. (read_scalar) ) )
then
491 call neko_error(
'Checkpoint does not match case')
495 if (gdim .eq. 3)
then
496 call this%chkp_Xh%init(gll, lx, lx, lx)
498 call this%chkp_Xh%init(gll, lx, lx)
500 if (this%mesh2mesh)
then
501 call dof%init(msh, this%chkp_Xh)
502 call this%global_interp%init(dof, neko_comm, tol = tol)
503 call this%global_interp%find_points(u%dof%x, u%dof%y, u%dof%z, &
506 call this%space_interp%init(this%sim_Xh, this%chkp_Xh)
508 dof_offset = int(msh%offset_el, i8) * int(this%chkp_Xh%lxyz, i8)
509 n_glb_dofs = int(this%chkp_Xh%lxyz, i8) * int(msh%glb_nelv, i8)
515 byte_offset = 4_i8 * int(mpi_integer_size, i8) + &
516 int(mpi_double_precision_size, i8)
517 byte_offset = byte_offset + &
518 dof_offset * int(mpi_real_prec_size, i8)
519 call this%read_field(fh, byte_offset, u%x, nel)
520 mpi_offset = 4_i8 * int(mpi_integer_size, i8) + &
521 int(mpi_double_precision_size, i8)
522 mpi_offset = mpi_offset +&
523 n_glb_dofs * int(mpi_real_prec_size, i8)
525 byte_offset = mpi_offset + &
526 dof_offset * int(mpi_real_prec_size, i8)
527 call this%read_field(fh, byte_offset, v%x, nel)
528 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
530 byte_offset = mpi_offset + &
531 dof_offset * int(mpi_real_prec_size, i8)
532 call this%read_field(fh, byte_offset, w%x, nel)
533 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
535 byte_offset = mpi_offset + &
536 dof_offset * int(mpi_real_prec_size, i8)
537 call this%read_field(fh, byte_offset, p%x, nel)
538 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
545 do i = 1, ulag%size()
546 byte_offset = mpi_offset + &
547 dof_offset * int(mpi_real_prec_size, i8)
548 call this%read_field(fh, byte_offset, ulag%lf(i)%x, nel)
549 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
552 do i = 1, vlag%size()
553 byte_offset = mpi_offset + &
554 dof_offset * int(mpi_real_prec_size, i8)
555 call this%read_field(fh, byte_offset, vlag%lf(i)%x, nel)
556 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
559 do i = 1, wlag%size()
560 byte_offset = mpi_offset + &
561 dof_offset * int(mpi_real_prec_size, i8)
562 call this%read_field(fh, byte_offset, wlag%lf(i)%x, nel)
563 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
567 if (read_scalar)
then
568 byte_offset = mpi_offset + &
569 dof_offset * int(mpi_real_prec_size, i8)
570 call this%read_field(fh, byte_offset, s%x, nel)
571 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
574 if (read_dtlag .and. have_dtlag .eq. 1)
then
575 call mpi_file_read_at_all(fh, mpi_offset, tlag, 10, &
576 mpi_real_precision, status, ierr)
577 mpi_offset = mpi_offset + 10_i8 * int(mpi_real_prec_size, i8)
578 call mpi_file_read_at_all(fh, mpi_offset, dtlag, 10, &
579 mpi_real_precision, status, ierr)
580 mpi_offset = mpi_offset + 10_i8 * int(mpi_real_prec_size, i8)
583 if (read_abvel .and. have_abvel .eq. 1)
then
584 byte_offset = mpi_offset + &
585 dof_offset * int(mpi_real_prec_size, i8)
586 call this%read_field(fh, byte_offset, abx1%x, nel)
587 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
588 byte_offset = mpi_offset + &
589 dof_offset * int(mpi_real_prec_size, i8)
590 call this%read_field(fh, byte_offset, abx2%x, nel)
591 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
592 byte_offset = mpi_offset + &
593 dof_offset * int(mpi_real_prec_size, i8)
594 call this%read_field(fh, byte_offset, aby1%x, nel)
595 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
596 byte_offset = mpi_offset + &
597 dof_offset * int(mpi_real_prec_size, i8)
598 call this%read_field(fh, byte_offset, aby2%x, nel)
599 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
600 byte_offset = mpi_offset + &
601 dof_offset * int(mpi_real_prec_size, i8)
602 call this%read_field(fh, byte_offset, abz1%x, nel)
603 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
604 byte_offset = mpi_offset + &
605 dof_offset * int(mpi_real_prec_size, i8)
606 call this%read_field(fh, byte_offset, abz2%x, nel)
607 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
609 if (read_scalarlag .and. have_scalarlag .eq. 1)
then
610 do i = 1, slag%size()
611 byte_offset = mpi_offset + &
612 dof_offset * int(mpi_real_prec_size, i8)
613 call this%read_field(fh, byte_offset, slag%lf(i)%x, nel)
614 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
616 byte_offset = mpi_offset + &
617 dof_offset * int(mpi_real_prec_size, i8)
618 call this%read_field(fh, byte_offset, abs1%x, nel)
619 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
620 byte_offset = mpi_offset + &
621 dof_offset * int(mpi_real_prec_size, i8)
622 call this%read_field(fh, byte_offset, abs2%x, nel)
623 mpi_offset = mpi_offset + n_glb_dofs * int(mpi_real_prec_size, i8)
626 call mpi_file_close(fh, ierr)
628 if (ierr .ne. mpi_success)
then
629 call neko_error(
'Error reading checkpoint file ' // trim(fname))
632 call this%global_interp%free()
633 call this%space_interp%free()