48 use json_module,
only : json_file, json_value, json_core
62 use,
intrinsic :: iso_c_binding
66 use mpi_f08,
only : mpi_allreduce, mpi_integer, mpi_sum, &
67 mpi_double_precision, mpi_gatherv, mpi_gather, mpi_exscan
73 real(kind=
rp) :: start_time
75 integer :: n_fields = 0
78 integer :: n_global_probes
80 integer :: n_probes_offset
82 real(kind=
rp),
allocatable :: xyz(:,:)
84 real(kind=
rp),
allocatable :: out_values(:,:)
85 type(c_ptr),
allocatable :: out_values_d(:)
86 real(kind=
rp),
allocatable :: out_vals_trsp(:,:)
88 integer :: n_local_probes
91 character(len=NEKO_VARNAME_LEN),
allocatable :: which_fields(:)
93 integer,
allocatable :: n_local_probes_tot_offset(:)
94 integer,
allocatable :: n_local_probes_tot(:)
97 real(kind=
rp),
allocatable :: global_output_values(:,:)
105 logical :: append_out = .true.
107 logical :: output_file_open = .false.
109 integer :: n_samples = 0
114 procedure, pass(this) :: init_from_components => &
149 class(
probes_t),
intent(inout),
target :: this
150 type(json_file),
intent(inout) :: json
151 class(
case_t),
intent(inout),
target :: case
152 character(len=:),
allocatable :: output_file
153 character(len=:),
allocatable :: input_file
157 character(len=:),
allocatable :: point_type
158 type(json_value),
pointer :: json_point_list
159 type(json_file) :: json_point
160 type(json_core) :: core
161 integer :: idx, n_point_children
163 character(len=:),
allocatable :: name
169 call this%init_base(json,
case)
173 if (this%output_controller%control_mode == &
174 this%compute_controller%control_mode .and. &
175 this%output_controller%control_value == &
176 this%compute_controller%control_value)
then
177 this%output_controller%never = .true.
178 this%output_controller%control_mode =
'never'
179 call json%add(
'output_control',
'never')
183 call json%info(
'fields', n_children = this%n_fields)
184 call json_get(json,
'fields', this%which_fields)
185 call json_get(json,
'output_file', output_file)
190 call this%sampled_fields%init(this%n_fields)
191 do i = 1, this%n_fields
193 call this%sampled_fields%assign(i, &
198 this%n_local_probes = 0
199 this%n_global_probes = 0
202 if (json%valid_path(
'points_file'))
then
205 call json_get(json,
'points_file', input_file)
210 this%n_global_probes, input_file)
213 if (json%valid_path(
'points'))
then
216 call json%get(
'points', json_point_list)
217 call json%info(
'points', n_children = n_point_children)
219 do idx = 1, n_point_children
223 select case (point_type)
226 call this%read_file(json_point)
228 call this%read_point(json_point)
230 call this%read_line(json_point)
232 call neko_error(
'Plane probes not implemented yet.')
234 call this%read_circle(json_point)
236 call this%read_point_zone(json_point,
case%fluid%dm_Xh)
238 call json_point%print()
241 call neko_error(
'Unknown region type ' // point_type)
247 call mpi_allreduce(this%n_local_probes, this%n_global_probes, 1, &
254 type(json_file) :: interp_subdict
256 call this%global_interp%init(
case%fluid%dm_Xh, &
257 params_subdict = interp_subdict)
259 call this%init_common(
case%fluid%dm_Xh, output_file, name)
273 class(
probes_t),
intent(inout) :: this
274 type(dofmap_t),
intent(in) :: dof
275 character(len=:),
allocatable,
intent(inout) :: output_file
276 character(len=*),
intent(in) :: name
277 real(kind=dp),
intent(in),
optional :: tolerance, padding
279 character(len=1024) :: header_line
280 real(kind=rp),
allocatable :: global_output_coords(:,:)
282 type(matrix_t) :: mat_coords
284 call this%global_interp%init(dof, tol = tolerance, pad = padding)
286 call this%init_common(dof, output_file, name)
298 class(
probes_t),
intent(inout) :: this
299 type(json_file),
intent(inout) :: json
300 character(len=:),
allocatable :: input_file
301 real(kind=rp),
dimension(:,:),
allocatable :: point_list
303 integer :: n_local, n_global
305 if (pe_rank .ne. 0)
return
307 call json_get(json,
'file_name', input_file)
311 call this%add_points(point_list)
319 class(
probes_t),
intent(inout) :: this
320 type(json_file),
intent(inout) :: json
322 real(kind=rp),
dimension(:,:),
allocatable :: point_list
323 real(kind=rp),
dimension(:),
allocatable :: rp_list_reader
326 if (pe_rank .ne. 0)
return
327 call json_get_or_lookup(json,
'coordinates', rp_list_reader)
329 if (mod(
size(rp_list_reader), 3) /= 0)
then
330 call neko_error(
'Invalid number of coordinates.')
334 allocate(point_list(3,
size(rp_list_reader)/3))
335 point_list = reshape(rp_list_reader, [3,
size(rp_list_reader)/3])
337 call this%add_points(point_list)
344 class(
probes_t),
intent(inout) :: this
345 type(json_file),
intent(inout) :: json
347 real(kind=rp),
dimension(:,:),
allocatable :: point_list
348 real(kind=rp),
dimension(:),
allocatable :: start,
end
349 real(kind=rp),
dimension(3) :: direction
352 integer :: n_points, i
355 if (pe_rank .ne. 0)
return
356 call json_get_or_lookup(json,
"start", start)
357 call json_get_or_lookup(json,
"end",
end)
358 call json_get_or_lookup(json,
"amount", n_points)
361 if (
size(start) /= 3 .or.
size(
end) /= 3) then
362 call neko_error(
'Invalid start or end coordinates.')
366 allocate(point_list(3, n_points))
369 direction =
end - start
371 t =
real(i - 1, kind = rp) /
real(n_points - 1, kind = rp)
372 point_list(:, i) = start + direction * t
375 call this%add_points(point_list)
388 class(
probes_t),
intent(inout) :: this
389 type(json_file),
intent(inout) :: json
391 real(kind=rp),
dimension(:,:),
allocatable :: point_list
392 real(kind=rp),
dimension(:),
allocatable :: center, normal
393 real(kind=rp) :: radius
394 real(kind=rp) :: angle
395 integer :: n_points, i
396 character(len=:),
allocatable :: axis
398 real(kind=rp),
dimension(3) :: zero_line, cross_line, temp
402 if (pe_rank .ne. 0)
return
403 call json_get_or_lookup(json,
"center", center)
404 call json_get_or_lookup(json,
"normal", normal)
405 call json_get_or_lookup(json,
"radius", radius)
406 call json_get_or_lookup(json,
"amount", n_points)
407 call json_get(json,
"axis", axis)
410 if (
size(center) /= 3 .or.
size(normal) /= 3)
then
411 call neko_error(
'Invalid center or normal coordinates.')
413 if (axis /=
'x' .and. axis /=
'y' .and. axis /=
'z')
then
414 call neko_error(
'Invalid axis.')
416 if (radius <= 0)
then
417 call neko_error(
'Invalid radius.')
419 if (n_points <= 0)
then
420 call neko_error(
'Invalid number of points.')
424 normal = normal / norm2(normal)
427 if (axis .eq.
'x') zero_line = [1.0, 0.0, 0.0]
428 if (axis .eq.
'y') zero_line = [0.0, 1.0, 0.0]
429 if (axis .eq.
'z') zero_line = [0.0, 0.0, 1.0]
431 if (1.0_rp - dot_product(zero_line, normal) .le. 1e-6)
then
432 call neko_error(
'Invalid axis and normal.')
435 zero_line = zero_line - dot_product(zero_line, normal) * normal
436 zero_line = zero_line / norm2(zero_line)
438 cross_line(1) = normal(2) * zero_line(3) - normal(3) * zero_line(2)
439 cross_line(2) = normal(3) * zero_line(1) - normal(1) * zero_line(3)
440 cross_line(3) = normal(1) * zero_line(2) - normal(2) * zero_line(1)
443 allocate(point_list(3, n_points))
445 pi = 4.0_rp * atan(1.0_rp)
449 angle = 2.0_rp * pi *
real(i - 1, kind = rp) /
real(n_points, kind = rp)
450 temp = cos(angle) * zero_line + sin(angle) * cross_line
452 point_list(:, i) = center + radius * temp
455 call this%add_points(point_list)
464 class(
probes_t),
intent(inout) :: this
465 type(json_file),
intent(inout) :: json
466 type(dofmap_t),
intent(in) :: dof
468 real(kind=rp),
dimension(:,:),
allocatable :: point_list
469 character(len=:),
allocatable :: point_zone_name
470 class(point_zone_t),
pointer :: zone
471 integer :: i, idx, lx, nlindex(4)
472 real(kind=rp) :: x, y, z
475 if (pe_rank .ne. 0)
return
477 call json_get(json,
"name", point_zone_name)
478 zone => neko_point_zone_registry%get_point_zone(point_zone_name)
481 allocate(point_list(3, zone%size))
485 idx = zone%mask%get(i)
488 x = dof%x%x(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
489 y = dof%y%x(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
490 z = dof%z%x(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
492 point_list(:, i) = [x, y, z]
495 call this%add_points(point_list)
505 class(
probes_t),
intent(inout) :: this
506 real(kind=rp),
dimension(:,:),
intent(in) :: new_points
508 real(kind=rp),
dimension(:,:),
allocatable :: temp
509 integer :: n_old, n_new
512 n_old = this%n_local_probes
513 n_new =
size(new_points, 2)
516 if (
allocated(this%xyz))
then
517 call move_alloc(this%xyz, temp)
521 allocate(this%xyz(3, n_old + n_new))
522 if (
allocated(temp))
then
523 this%xyz(:, 1:n_old) = temp
525 this%xyz(:, n_old+1:n_old+n_new) = new_points
527 this%n_local_probes = this%n_local_probes + n_new
538 class(
probes_t),
intent(inout) :: this
539 type(dofmap_t),
intent(in) :: dof
540 character(len=:),
allocatable,
intent(inout) :: output_file
541 character(len=*),
intent(in) :: name
543 character(len=1024) :: header_line
544 real(kind=rp),
allocatable :: global_output_coords(:,:)
546 type(matrix_t) :: mat_coords
551 call this%global_interp%find_points_and_redist(this%xyz, &
555 allocate(this%out_values(this%n_local_probes, this%n_fields))
556 allocate(this%out_values_d(this%n_fields))
557 allocate(this%out_vals_trsp(this%n_fields, this%n_local_probes))
559 if (neko_bcknd_device .eq. 1)
then
560 do i = 1, this%n_fields
561 this%out_values_d(i) = c_null_ptr
562 call device_map(this%out_values(:,i), this%out_values_d(i), &
568 call this%fout%init(this%case%output_directory // trim(output_file))
570 select type (ft => this%fout%file_type)
576 write(header_line,
'(I0, A, I0)') this%n_global_probes, achar(44), &
578 do i = 1, this%n_fields
579 header_line = trim(header_line) // achar(44) // &
580 trim(this%which_fields(i))
582 call this%fout%set_header(header_line)
587 allocate(this%n_local_probes_tot(pe_size))
588 allocate(this%n_local_probes_tot_offset(pe_size))
589 call this%setup_offset()
590 if (pe_rank .eq. 0)
then
591 allocate(global_output_coords(3, this%n_global_probes))
592 call this%mat_out%init(this%n_global_probes, this%n_fields)
593 allocate(this%global_output_values(this%n_fields, &
594 this%n_global_probes))
595 call mat_coords%init(this%n_global_probes,3)
597 call mpi_gatherv(this%xyz, 3*this%n_local_probes, &
598 mpi_real_precision, global_output_coords, &
599 3*this%n_local_probes_tot, &
600 3*this%n_local_probes_tot_offset, &
601 mpi_real_precision, 0, neko_comm, ierr)
602 if (pe_rank .eq. 0)
then
603 call trsp(mat_coords%x, this%n_global_probes, &
604 global_output_coords, 3)
606 call this%fout%write(mat_coords)
607 call mat_coords%free()
609 class is (hdf5_file_t)
612 call this%probe_layout%init(this%n_local_probes)
615 this%seq_io = .false.
616 if (this%append_out)
then
618 if (pe_rank == 0)
then
619 call this%time_out%init(1)
621 call this%time_out%init(0)
623 call this%time_layout%init(this%time_out%size())
625 call this%open_output()
628 call neko_error(
"Invalid data. Expected csv_file_t or hdf5_file_t.")
635 class(
probes_t),
intent(inout) :: this
636 type(matrix_t) :: mat_coords
638 select type (ft => this%fout%file_type)
639 type is (hdf5_file_t)
640 call ft%set_overwrite(.not. this%append_out)
642 call ft%set_active_group(
"probes")
643 this%output_file_open = .true.
646 call mat_coords%init(3, this%n_local_probes,
"coordinates")
647 call copy(mat_coords%x, this%xyz, 3*this%n_local_probes)
648 call ft%write_dataset(mat_coords, layout = this%probe_layout)
649 call ft%write_attribute(
"NProbes", this%n_global_probes)
650 call ft%write_attribute(
"NSteps", this%n_samples)
651 call mat_coords%free()
657 class(
probes_t),
intent(inout) :: this
662 if (this%output_file_open)
then
663 select type (ft => this%fout%file_type)
664 class is (hdf5_file_t)
667 this%output_file_open = .false.
670 call this%fout%free()
672 if (
allocated(this%xyz))
then
676 if (
allocated(this%out_vals_trsp))
then
677 deallocate(this%out_vals_trsp)
680 call this%sampled_fields%free()
682 if (
allocated(this%n_local_probes_tot))
then
683 deallocate(this%n_local_probes_tot)
686 if (
allocated(this%n_local_probes_tot_offset))
then
687 deallocate(this%n_local_probes_tot_offset)
690 if (
allocated(this%global_output_values))
then
691 deallocate(this%global_output_values)
694 if (
allocated(this%which_fields))
then
695 deallocate(this%which_fields)
698 if (
allocated(this%out_values))
then
699 if (neko_bcknd_device .eq. 1)
then
700 do i = 1, this%n_fields
701 call device_unmap(this%out_values(:,i), this%out_values_d(i))
704 if (
allocated(this%out_values_d))
deallocate(this%out_values_d)
705 deallocate(this%out_values)
708 call this%global_interp%free()
709 call this%mat_out%free()
710 call this%time_out%free()
717 character(len=LOG_SIZE) :: log_buf
721 call neko_log%section(
'Probes')
722 write(log_buf,
'(A,I6)')
"Number of probes: ", this%n_global_probes
723 call neko_log%message(log_buf)
725 call neko_log%message(
"xyz-coordinates:", lvl = neko_log_debug)
726 do i = 1, this%n_local_probes
727 write(log_buf,
'("(",F10.6,",",F10.6,",",F10.6,")")') this%xyz(:,i)
728 call neko_log%message(log_buf, lvl = neko_log_debug)
732 write(log_buf,
'(A,I6)')
"Number of fields: ", this%n_fields
733 call neko_log%message(log_buf)
734 do i = 1, this%n_fields
735 write(log_buf,
'(A,I6,A,A)') &
736 "Field: ", i,
" ", trim(this%which_fields(i))
737 call neko_log%message(log_buf, lvl = neko_log_debug)
739 call neko_log%end_section()
740 call neko_log%newline()
748 character(len=LOG_SIZE) :: log_buf
751 do i = 1, this%n_local_probes
752 write (log_buf, *) pe_rank,
"/", this%global_interp%pe_owner(i), &
753 "/" , this%global_interp%el_owner0(i)
754 call neko_log%message(log_buf)
755 write(log_buf,
'(A5, "(", F10.6, ",", F10.6, ",", F10.6, ")")') &
756 "rst: ", this%global_interp%rst(:, i)
757 call neko_log%message(log_buf)
765 this%n_local_probes_tot = 0
766 this%n_local_probes_tot_offset = 0
767 this%n_probes_offset = 0
768 call mpi_gather(this%n_local_probes, 1, mpi_integer, &
769 this%n_local_probes_tot, 1, mpi_integer, &
772 call mpi_exscan(this%n_local_probes, this%n_probes_offset, 1, &
773 mpi_integer, mpi_sum, neko_comm, ierr)
774 call mpi_gather(this%n_probes_offset, 1, mpi_integer, &
775 this%n_local_probes_tot_offset, 1, mpi_integer, &
787 class(
probes_t),
intent(inout) :: this
788 type(time_state_t),
intent(in) :: time
790 logical :: do_interp_on_host = .false.
791 character(len=1000) :: group_name
792 real(kind=rp) :: time_
796 if (time%t .lt. this%start_time)
return
799 do i = 1, this%n_fields
800 call this%global_interp%evaluate(this%out_values(:,i), &
801 this%sampled_fields%items(i)%ptr%x, &
805 if (neko_bcknd_device .eq. 1)
then
806 do i = 1, this%n_fields
807 call device_memcpy(this%out_values(:,i), this%out_values_d(i), &
808 this%n_local_probes, device_to_host, sync = .true.)
812 select type (ft => this%fout%file_type)
816 if (this%seq_io)
then
817 call trsp(this%out_vals_trsp, this%n_fields, &
818 this%out_values, this%n_local_probes)
819 call mpi_gatherv(this%out_vals_trsp, &
820 this%n_fields*this%n_local_probes, &
821 mpi_real_precision, this%global_output_values, &
822 this%n_fields*this%n_local_probes_tot, &
823 this%n_fields*this%n_local_probes_tot_offset, &
824 mpi_real_precision, 0, neko_comm, ierr)
825 if (pe_rank .eq. 0)
then
826 call trsp(this%mat_out%x, this%n_global_probes, &
827 this%global_output_values, this%n_fields)
828 call this%fout%write(this%mat_out, time%t)
831 call neko_error(
"CSV outputs only works sequentially")
833 call this%output_controller%register_execution(time)
835 type is (hdf5_file_t)
837 if (this%seq_io)
then
838 call neko_error(
"HDF5 outputs only works in parallel currently.")
842 this%n_samples = this%n_samples + 1
845 if (this%append_out)
then
849 out_int = this%n_samples
850 call ft%write_attribute(
"NSteps", out_int)
852 do i = 1, this%n_fields
855 call ft%write_array(this%out_values(:,i), &
856 trim(this%which_fields(i)), this%probe_layout)
859 if (pe_rank == 0) this%time_out%x(1) = time%t
860 call ft%write_dataset(this%time_out, name =
"time", &
861 layout = this%time_layout)
866 out_int = this%n_samples
868 write(group_name,
'(A,I0)')
"probes/Step_", out_int
869 call ft%set_active_group(
"probes")
871 call ft%write_attribute(
"NSteps", out_int)
873 call ft%set_active_group(trim(group_name))
874 do i = 1, this%n_fields
877 call ft%write_array(this%out_values(:,i), &
878 trim(this%which_fields(i)), this%probe_layout)
882 call ft%write_attribute(
"time", time_)
888 if (this%output_controller%check(time))
then
890 this%output_file_open = .false.
891 call this%open_output()
892 call this%output_controller%register_execution(time)
895 call neko_error(
"Invalid data. Expected csv_file_t or hdf5_file_t.")
904 class(
probes_t),
intent(inout) :: this
905 character(len=:),
allocatable :: points_file
906 real(kind=rp),
allocatable :: xyz(:,:)
907 integer,
intent(inout) :: n_local_probes, n_global_probes
908 type(matrix_t) :: mat_in
912 type(file_t) :: file_in
914 call file_in%init(trim(points_file))
916 select type (ft => file_in%file_type)
920 type is (hdf5_file_t)
922 call ft%read_dataset(
"xyz", mat_in,
"rank_0")
926 n_local_probes = mat_in%get_ncols()
927 call mpi_allreduce(n_local_probes, n_global_probes, 1, mpi_integer, &
928 mpi_sum, neko_comm, ierr)
930 allocate(xyz(3, n_local_probes))
931 call copy(xyz, mat_in%x, 3*n_local_probes)
934 call neko_error(
"Invalid data. Expected csv_file_t.")
938 call file_free(file_in)
948 type(csv_file_t),
intent(inout) :: f
949 real(kind=rp),
allocatable :: xyz(:,:)
950 integer,
intent(inout) :: n_local_probes, n_global_probes
951 type(matrix_t) :: mat_in, mat_in2
954 n_lines = f%count_lines()
957 n_global_probes = n_lines
960 if (pe_rank .eq. 0)
then
961 n_local_probes = n_global_probes
962 allocate(xyz(3, n_local_probes))
963 call mat_in%init(n_global_probes,3)
964 call mat_in2%init(3, n_global_probes)
966 call trsp(xyz, 3, mat_in%x, n_global_probes)
971 allocate(xyz(3, n_local_probes))
__inline__ __device__ void nonlinear_index(const int idx, const int lx, int *index)
Map a Fortran array to a device (allocate and associate).
Copy data between host and device (or device and device).
Unmap a Fortran array from a device (deassociate and free).
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Defines a simulation case.
type(mpi_datatype), public mpi_real_precision
MPI type for working precision of REAL types.
integer, public pe_size
MPI size of communicator.
integer, public pe_rank
MPI rank.
type(mpi_comm), public neko_comm
MPI communicator.
File format for .csv files, used for any read/write operations involving floating point data.
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
Device abstraction, common interface for various accelerators.
integer, parameter, public device_to_host
Defines a mapping of the degrees of freedom.
Module for file I/O operations.
subroutine file_free(this)
File operation destructor.
Implements global_interpolation given a dofmap.
Module containing host-only array type.
Utilities for retrieving parameters from the case files.
subroutine, public json_get_subdict_or_empty(json, key, output)
Extract a sub-object from a json object and returns an empty object if the key is missing.
integer, parameter, public neko_log_debug
Debug.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
subroutine, public copy(a, b, n)
Copy a vector .
integer, parameter neko_bcknd_device
integer, parameter, public dp
integer, parameter, public rp
Global precision used in computations.
type(point_zone_registry_t), target, public neko_point_zone_registry
Global point_zone registry.
subroutine read_point_zone(this, json, dof)
Construct a list of points from a point zone.
subroutine read_circle(this, json)
Construct a list of points from a circle.
subroutine probes_init_from_components(this, dof, output_file, name, tolerance, padding)
Initialize based on individual parameters.
subroutine add_points(this, new_points)
Append a new list of points to the exsiting list.
subroutine probes_init_common(this, dof, output_file, name)
Common constructor.
subroutine probes_evaluate_and_write(this, time)
Interpolate each probe from its r,s,t coordinates.
subroutine read_line(this, json)
Construct a list of points from a line.
subroutine read_probe_locations(this, xyz, n_local_probes, n_global_probes, points_file)
Initialize the physical coordinates from a csv input file.
subroutine read_point(this, json)
Read a list of points from the json file.
subroutine probes_show(this)
Print current probe status, with number of probes and coordinates.
subroutine probes_free(this)
Destructor.
subroutine probes_debug(this)
Show the status of processor/element owner and error code for each point.
subroutine probes_setup_offset(this)
Setup offset for rank 0.
subroutine probes_open_output(this)
Open a new numbered file and initialize its probe metadata.
subroutine read_file(this, json)
Read a list of points from a csv file.
subroutine read_xyz_from_csv(xyz, n_local_probes, n_global_probes, f)
Read and initialize the number of probes from a csv input file.
subroutine probes_init_from_json(this, json, case)
Constructor from json.
Defines a registry for storing solution fields.
type(registry_t), target, public neko_registry
Global field registry.
Simulation components are objects that encapsulate functionality that can be fit to a particular comp...
subroutine compute_(this, time)
Dummy compute function.
subroutine, public trsp(a, lda, b, ldb)
Transpose of a rectangular tensor .
Module with things related to the simulation time.
integer, parameter, public neko_varname_len
pure integer function, dimension(4), public nonlinear_index(linear_index, lx, ly, lz)
Compute (i,j,k,l) array given linear index with sizes (1:lx, 1:ly, 1:lz, :).
field_list_t, To be able to group fields together
A wrapper around a polymorphic generic_file_t that handles its init. This is essentially a factory fo...
Implements global interpolation for arbitrary points in the domain.
Interface for HDF5 files.
Reusable distribution of a rank-ordered host array over NEKO_COMM. Counts are vector elements or matr...
Host-only temporary array.
Base abstract type for point zones.
Base abstract class for simulation components.
A struct that contains all info about the time, expand as needed.