[petsc-users] HDF5 time step count

Matthew Knepley knepley at gmail.com
Wed May 8 10:00:12 CDT 2024


On Wed, May 1, 2024 at 11:03 PM Adrian Croucher <a.croucher at auckland.ac.nz>
wrote:

> hi Matt & all,
>
> I just had a query from one of my users which prompted me to see if any
> progress had been made on the issue below - using PETSc to get the number
> of time steps in an HDF5 file.
>
> I can't see anything new in PETSc on this - I did try using
> PetscViewerHDF5ReadSizes() to see if that would do it, but it seems it
> doesn't. If I use that on the "time" dataset it just returns 1.
>
> Sorry about the delay. I had lost track of this. Can you look at branch

  knepley/feature-hdf5-seq-len

I have not made a test yet, but if this works for you, I will make a test
and merge it in.

  Thanks!

     Matt

> Regards, Adrian
> On 11/10/21 2:08 pm, Adrian Croucher wrote:
>
> On 10/11/21 11:59 AM, Matthew Knepley wrote:
>
> On Sun, Oct 10, 2021 at 6:51 PM Adrian Croucher <a.croucher at auckland.ac.nz>
> wrote:
>
>> hi
>>
>> Is there any way to query the PETSc HDF5 viewer to find the number of
>> time steps in the file?
>>
>> A common use case I have is that an HDF5 file from a previous simulation
>> is used to get initial conditions for a subsequent run. The most common
>> thing you want to do is restart from the last set of results in the
>> previous output. To do that you need to know how many time steps there
>> are, so you can set the output index to be the last one.
>>
>> I thought maybe I could just query the size of the "time" dataset, but I
>> can't even see any obvious way to do that using the viewer functions.
>>
>
> There is nothing in there that does it right now. Do you know how to do it
> in HDF5?
> If so, I can put it in. Otherwise, I will have to learn more HDF5 :)
>
>
> I haven't actually tried this myself but it looks like what you do is:
>
> 1) get the dataspace for the dataset (in our case the "time" dataset):
>
> hid_t dspace = H5Dget_space(dset);
>
> 2) Get the dimensions of the dataspace:
>
> const int ndims = 1;
>
> hsize_t dims[ndims];
> H5Sget_simple_extent_dims(dspace, dims, NULL);
>
> The first element of dims should be the number of time steps. Here I've
> assumed the number of dimensions of the time dataset is 1. In general you
> can instead query the rank of the dataspace using
> H5Sget_simple_extent_ndims() to get the rank ndims.
>
> Regards, Adrian
>
> --
> Dr Adrian Croucher
> Senior Research Fellow
> Department of Engineering Science
> Waipapa Taumata Rau / University of Auckland, New Zealand
> email: a.croucher at auckland.ac.nz
> tel: +64 (0)9 923 4611
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eWw8ZyC03JCY81KS4nuvF6OwPoyRvldIwdZsw_6BlM1OLpJ4cucgOSJ6wetJu-YCCDUSYq0ZI_4rgu343kFn$  <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!eWw8ZyC03JCY81KS4nuvF6OwPoyRvldIwdZsw_6BlM1OLpJ4cucgOSJ6wetJu-YCCDUSYq0ZI_4rgriZqJYl$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240508/92bf1b14/attachment.html>


More information about the petsc-users mailing list