Global subroutine to import fields from fld files (gfldr)#2325
Global subroutine to import fields from fld files (gfldr)#2325
Conversation
|
Nice! |
|
Awesome stuff!! Only glanced through the code. But dont call it global, this is a totally normal subroutine living in a module. The word global scares people :-). |
|
For the future, would be very nice if one can also support hdf5 files ;) |
I have been working a bit with HDF5 now, and it should be quite simple to extend, atleast to be functional. But we would need to decide on some standardized path naming, Which should probably be informed by however a vtkhdf5 neko export would look like. |
|
Regarding the name, I would just call it |
|
@adperezm replying to your PR #2327 about vector lists here:
Yea I think this would be definitely great for an hdf5 interface. For the fld files my opinion is that we shouldn't spend more time on extending And sorry I don't understand what you mean about the searches traversing the lists, for |
No problem :), The part about the search was not specific to this PR. Just in general, when we search for something by name in a list, we traverse, so there is a bunch of implicit nested loops there. But this does not affect this PR at all. The reason I was thinking about extending this function you provided here, was because in my mind, something like this would be nice (highjacking your example): ! Case 5. "field0.f00001" contains temperature, s01, s02.
! Define a list with sources
character(:), allocatable :: names(:)
names = [ character(:) :: "t", "s1", "s2" ]
! Define a list with outputs (potentially also replace with field_arrays_t that also initialize the data)
call my_field_list%init(3)
call my_field_list%assign(1, my_custom_field)
call my_field_list%assign(2, s1)
call my_field_list%assign(3, s2)
! Do the import
call import_fields("field0.f00001", output=my_field_list, from=names)And that would be doable if one has names for the vectors, even if it is hard-coded. I think it would nicely change things inside the current code from: ! Evaluate all the fields
if (present(u)) call global_interp%evaluate(u%x(:,1,1,1), this%u%x, &
on_host=.false.)
if (present(v)) call global_interp%evaluate(v%x(:,1,1,1), this%v%x, &
on_host=.false.)
if (present(w)) call global_interp%evaluate(w%x(:,1,1,1), this%w%x, &
on_host=.false.)
if (present(p)) call global_interp%evaluate(p%x(:,1,1,1), this%p%x, &
on_host=.false.)
if (present(t)) call global_interp%evaluate(t%x(:,1,1,1), this%t%x, &
on_host=.false.)
if (present(s_target_list)) then
! If the index list exists, use it as a "mask"
if (present(s_index_list)) then
do i = 1, size(s_index_list)
! Take care that if we set i=0 we want temperature
if (s_index_list(i) .eq. 0) then
call global_interp%evaluate(s_target_list%x(i), &
this%t%x, on_host=.false.)
else
call global_interp%evaluate(s_target_list%x(i), &
this%s(s_index_list(i))%x, on_host=.false.)
end if
end doTo something like (not really proper fortran): ! Evaluate all the fields
do i = 1, n
call global_interp%evaluate(output_field_list%get_by_index(i)%x(:,1,1,1), &
this%vector_list%get_by_name(names(i))%x, &
on_host=.false.)
end doIf one then uses this This is basically what I do in pysemtools with the function I have found very useful to use the same simple interface for any type of file I want to read. But in the end, I did not say we should change this :). It does come to preferences. I would like to always output a list of fields and input a list of keys, then I do not need to play around with optional arguments in the subroutine, but this does not mean everyone else likes that. |
oooh I see now. Didn't think that far, sorry.
Yea definitely agree, once this moves further to accept hdf5 it will for sure be needed |
src/fluid/flow_ic.f90
Outdated
| use neko_config, only : NEKO_BCKND_DEVICE | ||
| use flow_profile, only : blasius_profile, blasius_linear, blasius_cubic, & | ||
| blasius_quadratic, blasius_quartic, blasius_sin, blasius_tanh | ||
| use import_field_utils, only: import_fields |
There was a problem hiding this comment.
Another alternative could be load_fields. I like it more than read_ since we potentially do extra stuff. But import_ is also not that bad!
There was a problem hiding this comment.
I do like import_fields as well.. but let's finalize this in the dev meeting tomorrow so this can move forward to merging!
There was a problem hiding this comment.
Unless there are strong opinions I then suggest we jsut go ahead with that name. I wrote that the name was up for discussion in case it was divisive but it doesn't look that way :)
Added vector list with the same characteristics as field_list_t. @timfelle , if you already had this somewhere, then of course ignore :). I think it would be nice to add names to the vectors. The particular use-case I was thinking about was to further extend #2325 once it is merged. I would like that functionality to accept a list of keys to read, and since `fld_file_data_t` uses `vector_t`, it would be nice if one could search a vector by name. This would also help to have a unique interface with hdf5, I believe. I do not like that these searches need to always traverse the list. But I suppose that having hashtables with these types is overkill, considering that we never have crazy many entries. --------- Co-authored-by: Tim Felle Olsen <timfelle@hotmail.com>
timofeymukha
left a comment
There was a problem hiding this comment.
All good, just some tiny stuff.
Co-authored-by: Timofey Mukha <timofey.mukha@protonmail.com>
As the title says. Introduces a global subroutine to handle reading + interpolation of fld files, similar in essence to the Nek5000
gfldr, but on steroids.Fixes #2284 and #2268
The
globalsubroutine is namedimport_fields. Below are some examples of how the function can be used.pynekread/pynekwritefunctions from pySEMTools!import_fieldsis very much open for discussion, but I would suggest to keep it short, as you can see the argument list can grow quickly. Same goes for the dummy argumentss_target_listands_index_list.target_index(maybe should besource_index) to the scalar initial condition, that allows the user to bypass the naming conventions and select which scalar/temperature array they want to import their data from.target_index = 0load the temperature array in the fld file. So you effectively don't need your field to be namedtemperaturein the registry to load the data from the temperature array.More details
import_fieldsis implemented in its own file because it was a mess with all different imports: file, fld_file_data, global_interpolation, etc. But I guess that's a choice that can be discussedimport_fieldsis a basically fancy wrapper ("one-call wonder") that takes care of all the machinery of file names, input arguments, data movement (memcpy) etc. The interpolation operations are offloaded to the newfld_file_data_import_fieldssubroutine.About
fld_file_data_import_fieldscopyof fld arrays to fields.import_fields.One thing that was bugging me is if, and where data movement should be done. When an fld file is read and all the data is loaded into the
fld_file_dataobject, there is no device memcpy. Since the interpolation is done on GPUs, a memcpy would be required after an fld_file read:So, should
fld_file_data_import_fieldstake care of data movement for you? Well thankfully we have a note about data movement in our documentation:Therefore this routine is kept lightweight and focuses only on interpolation capabilities. Instead, the data movement aspect is taken care of by the
globalimport_fieldssubroutine. Because it takes the file name as input, there is no access to the fld_file_data object and no possibility to handle the memcpy manually anyways.Compiling
Testing