47 use json_module,
only : json_file, json_value, json_core
58 use,
intrinsic :: iso_c_binding
67 integer :: n_global_probes
69 integer :: n_probes_offset
71 real(kind=
rp),
allocatable :: xyz(:,:)
73 real(kind=
rp),
allocatable :: out_values(:,:)
74 type(c_ptr),
allocatable :: out_values_d(:)
75 real(kind=
rp),
allocatable :: out_vals_trsp(:,:)
77 integer :: n_local_probes
80 character(len=20),
allocatable :: which_fields(:)
82 integer,
allocatable :: n_local_probes_tot_offset(:)
83 integer,
allocatable :: n_local_probes_tot(:)
86 real(kind=
rp),
allocatable :: global_output_values(:,:)
94 procedure, pass(this) :: init_from_components => &
125 class(
probes_t),
intent(inout) :: this
126 type(json_file),
intent(inout) :: json
127 class(
case_t),
intent(inout),
target :: case
128 character(len=:),
allocatable :: output_file
129 character(len=:),
allocatable :: input_file
133 character(len=:),
allocatable :: point_type
134 type(json_value),
pointer :: json_point_list
135 type(json_file) :: json_point
136 type(json_core) :: core
137 integer :: idx, n_point_children
141 call this%init_base(json,
case)
144 call json%info(
'fields', n_children = this%n_fields)
145 call json_get(json,
'fields', this%which_fields)
146 call json_get(json,
'output_file', output_file)
148 call this%sampled_fields%init(this%n_fields)
149 do i = 1, this%n_fields
151 call this%sampled_fields%assign(i, &
156 this%n_local_probes = 0
157 this%n_global_probes = 0
160 if (json%valid_path(
'points_file'))
then
163 call json_get(json,
'points_file', input_file)
168 this%n_global_probes, input_file)
172 call json%get(
'points', json_point_list)
173 call json%info(
'points', n_children = n_point_children)
175 do idx = 1, n_point_children
179 select case (point_type)
182 call this%read_file(json_point)
184 call this%read_point(json_point)
186 call this%read_line(json_point)
188 call neko_error(
'Plane probes not implemented yet.')
190 call this%read_circle(json_point)
192 call this%read_point_zone(json_point,
case%fluid%dm_Xh)
194 call json_point%print()
197 call neko_error(
'Unknown region type ' // point_type)
201 call mpi_allreduce(this%n_local_probes, this%n_global_probes, 1, &
205 call this%init_from_components(
case%fluid%dm_Xh, output_file)
217 class(
probes_t),
intent(inout) :: this
218 type(json_file),
intent(inout) :: json
219 character(len=:),
allocatable :: input_file
220 real(kind=
rp),
dimension(:,:),
allocatable :: point_list
222 integer :: n_local, n_global
226 call json_get(json,
'file_name', input_file)
230 call this%add_points(point_list)
238 class(
probes_t),
intent(inout) :: this
239 type(json_file),
intent(inout) :: json
241 real(kind=
rp),
dimension(:,:),
allocatable :: point_list
242 real(kind=
rp),
dimension(:),
allocatable :: rp_list_reader
246 call json_get(json,
'coordinates', rp_list_reader)
248 if (mod(
size(rp_list_reader), 3) /= 0)
then
249 call neko_error(
'Invalid number of coordinates.')
253 allocate(point_list(3,
size(rp_list_reader)/3))
254 point_list = reshape(rp_list_reader, [3,
size(rp_list_reader)/3])
256 call this%add_points(point_list)
263 class(
probes_t),
intent(inout) :: this
264 type(json_file),
intent(inout) :: json
266 real(kind=
rp),
dimension(:,:),
allocatable :: point_list
267 real(kind=
rp),
dimension(:),
allocatable :: start,
end
268 real(kind=
rp),
dimension(3) :: direction
271 integer :: n_points, i
277 call json_get(json,
"amount", n_points)
280 if (
size(start) /= 3 .or.
size(
end) /= 3) then
281 call neko_error(
'Invalid start or end coordinates.')
285 allocate(point_list(3, n_points))
288 direction =
end - start
290 t =
real(i - 1, kind = rp) /
real(n_points - 1, kind = rp)
291 point_list(:, i) = start + direction * t
294 call this%add_points(point_list)
307 class(
probes_t),
intent(inout) :: this
308 type(json_file),
intent(inout) :: json
310 real(kind=rp),
dimension(:,:),
allocatable :: point_list
311 real(kind=rp),
dimension(:),
allocatable :: center, normal
312 real(kind=rp) :: radius
313 real(kind=rp) :: angle
314 integer :: n_points, i
315 character(len=:),
allocatable :: axis
317 real(kind=rp),
dimension(3) :: zero_line, cross_line, temp
321 if (pe_rank .ne. 0)
return
322 call json_get(json,
"center", center)
323 call json_get(json,
"normal", normal)
324 call json_get(json,
"radius", radius)
325 call json_get(json,
"amount", n_points)
326 call json_get(json,
"axis", axis)
329 if (
size(center) /= 3 .or.
size(normal) /= 3)
then
330 call neko_error(
'Invalid center or normal coordinates.')
332 if (axis /=
'x' .and. axis /=
'y' .and. axis /=
'z')
then
333 call neko_error(
'Invalid axis.')
335 if (radius <= 0)
then
336 call neko_error(
'Invalid radius.')
338 if (n_points <= 0)
then
339 call neko_error(
'Invalid number of points.')
343 normal = normal / norm2(normal)
346 if (axis .eq.
'x') zero_line = [1.0, 0.0, 0.0]
347 if (axis .eq.
'y') zero_line = [0.0, 1.0, 0.0]
348 if (axis .eq.
'z') zero_line = [0.0, 0.0, 1.0]
350 if (1.0_rp - dot_product(zero_line, normal) .le. 1e-6)
then
351 call neko_error(
'Invalid axis and normal.')
354 zero_line = zero_line - dot_product(zero_line, normal) * normal
355 zero_line = zero_line / norm2(zero_line)
357 cross_line(1) = normal(2) * zero_line(3) - normal(3) * zero_line(2)
358 cross_line(2) = normal(3) * zero_line(1) - normal(1) * zero_line(3)
359 cross_line(3) = normal(1) * zero_line(2) - normal(2) * zero_line(1)
362 allocate(point_list(3, n_points))
364 pi = 4.0_rp * atan(1.0_rp)
368 angle = 2.0_rp * pi *
real(i - 1, kind = rp) /
real(n_points, kind = rp)
369 temp = cos(angle) * zero_line + sin(angle) * cross_line
371 point_list(:, i) = center + radius * temp
374 call this%add_points(point_list)
383 class(
probes_t),
intent(inout) :: this
384 type(json_file),
intent(inout) :: json
385 type(dofmap_t),
intent(in) :: dof
387 real(kind=rp),
dimension(:,:),
allocatable :: point_list
388 character(len=:),
allocatable :: point_zone_name
389 class(point_zone_t),
pointer :: zone
390 integer :: i, idx, lx, nlindex(4)
391 real(kind=rp) :: x, y, z
394 if (pe_rank .ne. 0)
return
396 call json_get(json,
"name", point_zone_name)
397 zone => neko_point_zone_registry%get_point_zone(point_zone_name)
400 allocate(point_list(3, zone%size))
407 x = dof%x(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
408 y = dof%y(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
409 z = dof%z(nlindex(1), nlindex(2), nlindex(3), nlindex(4))
411 point_list(:, i) = [x, y, z]
414 call this%add_points(point_list)
424 class(
probes_t),
intent(inout) :: this
425 real(kind=rp),
dimension(:,:),
intent(in) :: new_points
427 real(kind=rp),
dimension(:,:),
allocatable :: temp
428 integer :: n_old, n_new
431 n_old = this%n_local_probes
432 n_new =
size(new_points, 2)
435 if (
allocated(this%xyz))
then
436 call move_alloc(this%xyz, temp)
440 allocate(this%xyz(3, n_old + n_new))
441 if (
allocated(temp))
then
442 this%xyz(:, 1:n_old) = temp
444 this%xyz(:, n_old+1:n_old+n_new) = new_points
446 this%n_local_probes = this%n_local_probes + n_new
456 class(
probes_t),
intent(inout) :: this
457 type(dofmap_t),
intent(in) :: dof
458 character(len=:),
allocatable,
intent(inout) :: output_file
459 character(len=1024) :: header_line
460 real(kind=rp),
allocatable :: global_output_coords(:,:)
462 type(matrix_t) :: mat_coords
465 call this%global_interp%init(dof)
468 call this%global_interp%find_points_and_redist(this%xyz, &
472 allocate(this%out_values(this%n_local_probes, this%n_fields))
473 allocate(this%out_values_d(this%n_fields))
474 allocate(this%out_vals_trsp(this%n_fields, this%n_local_probes))
476 if (neko_bcknd_device .eq. 1)
then
477 do i = 1, this%n_fields
478 this%out_values_d(i) = c_null_ptr
479 call device_map(this%out_values(:,i), this%out_values_d(i), &
485 this%fout = file_t(trim(output_file))
487 select type (ft => this%fout%file_type)
493 write(header_line,
'(I0,A,I0)') this%n_global_probes,
",", this%n_fields
494 do i = 1, this%n_fields
495 header_line = trim(header_line) //
"," // trim(this%which_fields(i))
497 call this%fout%set_header(header_line)
502 allocate(this%n_local_probes_tot(pe_size))
503 allocate(this%n_local_probes_tot_offset(pe_size))
504 call this%setup_offset()
505 if (pe_rank .eq. 0)
then
506 allocate(global_output_coords(3, this%n_global_probes))
507 call this%mat_out%init(this%n_global_probes, this%n_fields)
508 allocate(this%global_output_values(this%n_fields, &
509 this%n_global_probes))
510 call mat_coords%init(this%n_global_probes,3)
512 call mpi_gatherv(this%xyz, 3*this%n_local_probes, &
513 mpi_double_precision, global_output_coords, &
514 3*this%n_local_probes_tot, &
515 3*this%n_local_probes_tot_offset, &
516 mpi_double_precision, 0, neko_comm, ierr)
517 if (pe_rank .eq. 0)
then
518 call trsp(mat_coords%x, this%n_global_probes, &
519 global_output_coords, 3)
521 call this%fout%write(mat_coords)
524 call neko_error(
"Invalid data. Expected csv_file_t.")
531 class(
probes_t),
intent(inout) :: this
533 if (
allocated(this%xyz))
then
537 if (
allocated(this%out_values))
then
538 deallocate(this%out_values)
541 if (
allocated(this%out_vals_trsp))
then
542 deallocate(this%out_vals_trsp)
545 call this%sampled_fields%free()
547 if (
allocated(this%n_local_probes_tot))
then
548 deallocate(this%n_local_probes_tot)
551 if (
allocated(this%n_local_probes_tot_offset))
then
552 deallocate(this%n_local_probes_tot_offset)
555 if (
allocated(this%global_output_values))
then
556 deallocate(this%global_output_values)
559 call this%global_interp%free()
566 character(len=LOG_SIZE) :: log_buf
570 call neko_log%section(
'Probes')
571 write(log_buf,
'(A,I6)')
"Number of probes: ", this%n_global_probes
572 call neko_log%message(log_buf)
574 call neko_log%message(
"xyz-coordinates:", lvl = neko_log_debug)
575 do i = 1, this%n_local_probes
576 write(log_buf,
'("(",F10.6,",",F10.6,",",F10.6,")")') this%xyz(:,i)
577 call neko_log%message(log_buf, lvl = neko_log_debug)
581 write(log_buf,
'(A,I6)')
"Number of fields: ", this%n_fields
582 call neko_log%message(log_buf)
583 do i = 1, this%n_fields
584 write(log_buf,
'(A,I6,A,A)') &
585 "Field: ", i,
" ", trim(this%which_fields(i))
586 call neko_log%message(log_buf, lvl = neko_log_debug)
588 call neko_log%end_section()
589 call neko_log%newline()
597 character(len=LOG_SIZE) :: log_buf
600 do i = 1, this%n_local_probes
601 write (log_buf, *) pe_rank,
"/", this%global_interp%proc_owner(i), &
602 "/" , this%global_interp%el_owner(i), &
603 "/", this%global_interp%error_code(i)
604 call neko_log%message(log_buf)
605 write(log_buf,
'(A5,"(",F10.6,",",F10.6,",",F10.6,")")') &
606 "rst: ", this%global_interp%rst(:,i)
607 call neko_log%message(log_buf)
615 this%n_local_probes_tot = 0
616 this%n_local_probes_tot_offset = 0
617 this%n_probes_offset = 0
618 call mpi_gather(this%n_local_probes, 1, mpi_integer, &
619 this%n_local_probes_tot, 1, mpi_integer, &
622 call mpi_exscan(this%n_local_probes, this%n_probes_offset, 1, &
623 mpi_integer, mpi_sum, neko_comm, ierr)
624 call mpi_gather(this%n_probes_offset, 1, mpi_integer, &
625 this%n_local_probes_tot_offset, 1, mpi_integer, &
637 class(
probes_t),
intent(inout) :: this
638 type(time_state_t),
intent(in) :: time
642 do i = 1, this%n_fields
643 call this%global_interp%evaluate(this%out_values(:,i), &
644 this%sampled_fields%items(i)%ptr%x)
647 if (neko_bcknd_device .eq. 1)
then
648 do i = 1, this%n_fields
649 call device_memcpy(this%out_values(:,i), this%out_values_d(i), &
650 this%n_local_probes, device_to_host, sync = .true.)
654 if (this%output_controller%check(time))
then
657 if (this%seq_io)
then
658 call trsp(this%out_vals_trsp, this%n_fields, &
659 this%out_values, this%n_local_probes)
660 call mpi_gatherv(this%out_vals_trsp, &
661 this%n_fields*this%n_local_probes, &
662 mpi_double_precision, this%global_output_values, &
663 this%n_fields*this%n_local_probes_tot, &
664 this%n_fields*this%n_local_probes_tot_offset, &
665 mpi_double_precision, 0, neko_comm, ierr)
666 if (pe_rank .eq. 0)
then
667 call trsp(this%mat_out%x, this%n_global_probes, &
668 this%global_output_values, this%n_fields)
669 call this%fout%write(this%mat_out, time%t)
672 call neko_error(
'probes sim comp, parallel io need implementation')
676 call this%output_controller%register_execution()
685 class(
probes_t),
intent(inout) :: this
686 character(len=:),
allocatable :: points_file
687 real(kind=rp),
allocatable :: xyz(:,:)
688 integer,
intent(inout) :: n_local_probes, n_global_probes
691 type(file_t) :: file_in
693 file_in = file_t(trim(points_file))
695 select type (ft => file_in%file_type)
700 call neko_error(
"Invalid data. Expected csv_file_t.")
704 call file_free(file_in)
714 type(csv_file_t),
intent(inout) :: f
715 real(kind=rp),
allocatable :: xyz(:,:)
716 integer,
intent(inout) :: n_local_probes, n_global_probes
717 type(matrix_t) :: mat_in, mat_in2
720 n_lines = f%count_lines()
723 n_global_probes = n_lines
726 if (pe_rank .eq. 0)
then
727 n_local_probes = n_global_probes
728 allocate(xyz(3, n_local_probes))
729 call mat_in%init(n_global_probes,3)
730 call mat_in2%init(3, n_global_probes)
732 call trsp(xyz, 3, mat_in%x, n_global_probes)
735 allocate(xyz(3, n_local_probes))
__device__ void nonlinear_index(const int idx, const int lx, int *index)
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_comm) neko_comm
MPI communicator.
File format for .csv files, used for any read/write operations involving floating point data.
Device abstraction, common interface for various accelerators.
Defines a mapping of the degrees of freedom.
Defines a registry for storing solution fields.
type(field_registry_t), target, public neko_field_registry
Global field registry.
pure integer function n_fields(this)
Get the number of fields stored in the registry.
Module for file I/O operations.
subroutine file_free(this)
File operation destructor.
Implements global_interpolation given a dofmap.
Utilities for retrieving parameters from the case files.
integer, parameter, public neko_log_debug
Debug log level.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
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 add_points(this, new_points)
Append a new list of points to the exsiting list.
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 probes_init_from_components(this, dof, output_file)
Initialize without json things.
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 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.
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.
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.
Base abstract type for point zones.
Base abstract class for simulation components.
A struct that contains all info about the time, expand as needed.