46 use json_module,
only : json_file
56 use,
intrinsic :: iso_c_binding
62 integer :: n_fields = 0
65 integer :: n_global_probes
67 integer :: n_probes_offset
69 real(kind=
rp),
allocatable :: xyz(:,:)
71 real(kind=
rp),
allocatable :: out_values(:,:)
72 type(c_ptr),
allocatable :: out_values_d(:)
73 real(kind=
rp),
allocatable :: out_vals_trsp(:,:)
75 integer :: n_local_probes
78 character(len=20),
allocatable :: which_fields(:)
80 integer,
allocatable :: n_local_probes_tot_offset(:)
81 integer,
allocatable :: n_local_probes_tot(:)
84 real(kind=
rp),
allocatable :: global_output_values(:,:)
92 procedure, pass(this) :: init_from_attributes => &
107 class(
probes_t),
intent(inout) :: this
108 type(json_file),
intent(inout) :: json
109 class(
case_t),
intent(inout),
target :: case
110 real(kind=
rp),
allocatable :: xyz(:,:)
111 character(len=:),
allocatable :: output_file
112 character(len=:),
allocatable :: points_file
113 integer :: i, n_local_probes, n_global_probes
116 call this%init_base(json,
case)
119 call json%info(
'fields', n_children=this%n_fields)
120 call json_get(json,
'fields', this%which_fields)
123 call json_get(json,
'points_file', points_file)
124 call json_get(json,
'output_file', output_file)
126 allocate(this%sampled_fields%fields(this%n_fields))
127 do i = 1, this%n_fields
129 trim(this%which_fields(i)))
135 this%n_global_probes, points_file)
137 call this%init_from_attributes(
case%fluid%dm_Xh, output_file)
138 if(
allocated(xyz))
deallocate(xyz)
147 class(
probes_t),
intent(inout) :: this
149 character(len=:),
allocatable,
intent(inout) :: output_file
150 character(len=1024) :: header_line
151 real(kind=
rp),
allocatable :: global_output_coords(:,:)
158 call this%global_interp%init(dof)
161 call this%global_interp%find_points_and_redist(this%xyz, this%n_local_probes)
164 allocate(this%out_values(this%n_local_probes,this%n_fields))
165 allocate(this%out_values_d(this%n_fields))
166 allocate(this%out_vals_trsp(this%n_fields,this%n_local_probes))
168 if (neko_bcknd_device .eq. 1)
then
169 do i = 1, this%n_fields
170 this%out_values_d(i) = c_null_ptr
171 call device_map(this%out_values(:,i), this%out_values_d(i),&
179 this%fout =
file_t(trim(output_file))
181 select type(ft => this%fout%file_type)
185 write(header_line,
'(I0,A,I0)') this%n_global_probes,
",", this%n_fields
186 do i = 1, this%n_fields
187 header_line = trim(header_line) //
"," // trim(this%which_fields(i))
189 call this%fout%set_header(header_line)
194 allocate(this%n_local_probes_tot(
pe_size))
195 allocate(this%n_local_probes_tot_offset(
pe_size))
196 call this%setup_offset()
198 allocate(global_output_coords(3,&
199 this%n_global_probes))
200 call this%mat_out%init(this%n_global_probes, this%n_fields)
201 allocate(this%global_output_values(this%n_fields,&
202 this%n_global_probes))
203 call mat_coords%init(this%n_global_probes,3)
205 call mpi_gatherv(this%xyz, 3*this%n_local_probes,&
206 mpi_double_precision, global_output_coords,&
207 3*this%n_local_probes_tot,&
208 3*this%n_local_probes_tot_offset,&
209 mpi_double_precision, 0,
neko_comm, ierr)
211 call trsp(mat_coords%x, this%n_global_probes,&
212 global_output_coords, 3)
214 call this%fout%write(mat_coords)
217 call neko_error(
"Invalid data. Expected csv_file_t.")
224 class(
probes_t),
intent(inout) :: this
226 if (
allocated(this%xyz))
then
230 if (
allocated(this%out_values))
then
231 deallocate(this%out_values)
234 if (
allocated(this%out_vals_trsp))
then
235 deallocate(this%out_vals_trsp)
238 if (
allocated(this%sampled_fields%fields))
then
239 deallocate(this%sampled_fields%fields)
242 if (
allocated(this%n_local_probes_tot))
then
243 deallocate(this%n_local_probes_tot)
246 if (
allocated(this%n_local_probes_tot_offset))
then
247 deallocate(this%n_local_probes_tot_offset)
250 if (
allocated(this%global_output_values))
then
251 deallocate(this%global_output_values)
254 call this%global_interp%free()
261 character(len=LOG_SIZE) :: log_buf
266 write(log_buf,
'(A,I6)')
"Number of probes: ", this%n_global_probes
268 call neko_log%message(
"xyz-coordinates:")
269 do i=1,this%n_local_probes
270 write(log_buf,
'("(",F10.6,",",F10.6,",",F10.6,")")') this%xyz(:,i)
274 write(log_buf,
'(A,I6)')
"Number of fields: ", this%n_fields
277 write(log_buf,
'(A,I6, A ,A)')
"Field: ", i,
" ", trim(this%which_fields(i))
289 character(len=LOG_SIZE) :: log_buf
292 do i = 1, this%n_local_probes
293 write (log_buf, *)
pe_rank,
"/", this%global_interp%proc_owner(i),
"/" ,&
294 this%global_interp%el_owner(i),
"/",this%global_interp%error_code(i)
296 write(log_buf,
'(A5,"(",F10.6,",",F10.6,",",F10.6,")")')
"rst: ", this%global_interp%rst(:,i)
305 this%n_local_probes_tot = 0
306 this%n_local_probes_tot_offset = 0
307 this%n_probes_offset = 0
308 call mpi_gather(this%n_local_probes, 1, mpi_integer,&
309 this%n_local_probes_tot, 1, mpi_integer,&
312 call mpi_exscan(this%n_local_probes, this%n_probes_offset, 1, &
314 call mpi_gather(this%n_probes_offset, 1, mpi_integer,&
315 this%n_local_probes_tot_offset, 1, mpi_integer,&
327 class(
probes_t),
intent(inout) :: this
328 real(kind=
rp),
intent(in) :: t
329 integer,
intent(in) :: tstep
330 real(kind=
rp),
allocatable :: tmp(:,:)
331 integer :: i, ierr, lx
332 integer :: size_outfields
337 do i = 1,this%n_fields
338 call this%global_interp%evaluate(this%out_values(:,i), &
339 this%sampled_fields%fields(i)%f%x)
342 if (neko_bcknd_device .eq. 1)
then
343 do i = 1, this%n_fields
344 call device_memcpy(this%out_values(:,i),this%out_values_d(i),&
349 if (this%output_controller%check(t, tstep))
then
352 if (this%seq_io)
then
353 call trsp(this%out_vals_trsp, this%n_fields, &
354 this%out_values,this%n_local_probes)
355 call mpi_gatherv(this%out_vals_trsp, this%n_fields*this%n_local_probes,&
356 mpi_double_precision, this%global_output_values,&
357 this%n_fields*this%n_local_probes_tot,&
358 this%n_fields*this%n_local_probes_tot_offset,&
359 mpi_double_precision, 0,
neko_comm, ierr)
361 call trsp(this%mat_out%x, this%n_global_probes, &
362 this%global_output_values, this%n_fields)
363 call this%fout%write(this%mat_out, t)
366 call neko_error(
'probes sim comp, parallel io need implementation')
370 call this%output_controller%register_execution()
378 class(
probes_t),
intent(inout) :: this
379 character(len=:),
allocatable :: points_file
380 real(kind=
rp),
allocatable :: xyz(:,:)
381 integer,
intent(inout) :: n_local_probes, n_global_probes
385 integer :: ierr, file_unit, n_lines
387 file_in =
file_t(trim(points_file))
389 select type(ft => file_in%file_type)
394 call neko_error(
"Invalid data. Expected csv_file_t.")
408 class(
probes_t),
intent(inout) :: this
410 real(kind=
rp),
allocatable :: xyz(:,:)
411 integer,
intent(inout) :: n_local_probes, n_global_probes
413 integer :: ierr, file_unit, n_lines
415 if (
pe_rank .eq. 0) n_lines = f%count_lines()
416 call mpi_bcast(n_lines, 1, mpi_integer, 0,
neko_comm, ierr)
419 n_global_probes = n_lines
420 this%n_global_probes = n_lines
424 this%n_local_probes = this%n_global_probes
425 n_local_probes = n_global_probes
426 allocate(xyz(3,this%n_local_probes))
427 call mat_in%init(this%n_global_probes,3)
428 call mat_in2%init(3,this%n_global_probes)
430 call trsp(xyz, 3, mat_in%x, this%n_global_probes)
433 this%n_local_probes = 0
434 allocate(xyz(3,this%n_local_probes))
Map a Fortran array to a device (allocate and associate)
Copy data between host and device (or device and device)
Retrieves a parameter by name or throws an error.
Defines a simulation case.
type(mpi_comm) neko_comm
MPI communicator.
integer pe_size
MPI size of communicator.
File format for .csv files, used for any read/write operations involving floating point data.
Device abstraction, common interface for various accelerators.
integer, parameter, public device_to_host
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.
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.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
integer, parameter, public rp
Global precision used in computations.
subroutine read_xyz_from_csv(this, xyz, n_local_probes, n_global_probes, f)
Read and initialize the number of probes from a csv input file.
subroutine probes_init_from_attributes(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 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_evaluate_and_write(this, t, tstep)
Interpolate each probe from its r,s,t coordinates.
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, public trsp(a, lda, b, ldb)
Transpose of a rectangular tensor .
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 class for simulation components.