[petsc-users] Error loading data coming from a .hdf5 file into a DMSwarm

Matthew Knepley knepley at gmail.com
Mon Apr 1 11:32:06 CDT 2024


On Mon, Apr 1, 2024 at 11:13 AM MIGUEL MOLINOS PEREZ <mmolinos at us.es> wrote:

> Dear Matthew,
>
> Thank you for your suggestion. I tried to update the vector with the
> information coming from the hdf5 file inside the main function. Then I
> print the vector two times (see the lines below), the first time it has the
> correct data. However, the second time, it has the same values like I never
> updated it with VecLoad.
>
> It is an alternative way of initialise a vector coming from DMSWarm with
> previously stored information (keeping the parallel structure)?
>

Oh, you cannot use the Swarm vectors for VecLoad(). They are just a view
into the particle data, and that view is destroyed on restore. Swarm data
is stored in a particle-like data structure, not in Vecs. If you want to
load this Vec, you have to duplicate exactly as you did. This interface is
likely to change in the next year to make this problem go away.

  Thanks,

    Matt


> Miguel
>
> //! Load Hdf5 viewer
> PetscViewer viewer_hdf5;
> REQUIRE_NOTHROW(PetscViewerHDF5Open(MPI_COMM_WORLD, Output_hdf5_file,
> FILE_MODE_READ, &viewer_hdf5));
> REQUIRE_NOTHROW(PetscViewerHDF5PushTimestepping(viewer_hdf5));
>
> //! Load the vector and fill it with the information from the .hdf5 file
> Vec stdv_q;
> REQUIRE_NOTHROW(DMSwarmCreateGlobalVectorFromField(
> Simulation.atomistic_data, "stdv-q", &stdv_q));
>
> REQUIRE_NOTHROW(PetscViewerHDF5PushGroup(viewer_hdf5, "/particle_fields"
> ));
> REQUIRE_NOTHROW(VecLoad(stdv_q, viewer_hdf5));
> REQUIRE_NOTHROW(VecView(stdv_q, PETSC_VIEWER_STDOUT_WORLD));
> REQUIRE_NOTHROW(PetscViewerHDF5PopGroup(viewer_hdf5));
>
> REQUIRE_NOTHROW(DMSwarmDestroyGlobalVectorFromField(
> Simulation.atomistic_data, "stdv-q", &stdv_q));
>
> //! Destoy HDF5 context
> REQUIRE_NOTHROW(PetscViewerDestroy(&viewer_hdf5));
>
> //! Load the vector again and print
> REQUIRE_NOTHROW(DMSwarmCreateGlobalVectorFromField(
> Simulation.atomistic_data, "stdv-q", &stdv_q));
>
> REQUIRE_NOTHROW(VecView(stdv_q, PETSC_VIEWER_STDOUT_WORLD));
>
> REQUIRE_NOTHROW(DMSwarmDestroyGlobalVectorFromField(
> Simulation.atomistic_data, "stdv-q", &stdv_q));
>
> Best,
> Miguel
>
> Miguel Molinos
> Investigador postdoctoral
> Juan de la Cierva
> Dpto. Mecánica de Medios Continuos y Teoría de Estructuras - ETSI
> Universidad de Sevilla
> Camino de los descubrimientos, s/n
> 41092 Sevilla
>
>
> [image: us_logo.jpg]
>
>
>
>
> https://urldefense.us/v3/__http://www.us.es__;!!G_uCfscf7eWS!YcVqv_PA_UdFsx4fZHfzMMaZZ7auMp-poE49ThdEDk0fT7DAXF6-0fOpeWMEOJcrVL5grSHp-QCF8PdvRl51$ 
> Este correo electrónico y, en su caso, cualquier fichero anexo al
> mismo, contiene información de carácter confidencial exclusivamente
> dirigida a su destinatario o destinatarios. Si no es UD. el
> destinatario del mensaje, le ruego lo destruya sin hacer copia digital o
> física, comunicando al emisor por esta misma vía la recepción del presente
> mensaje. Gracias
>
>
>
>
> On 1 Apr 2024, at 16:28, Matthew Knepley <knepley at gmail.com> wrote:
>
> From the description, my guess is that this is pointer confusion. The
> vector inside the function is different from the vector outside the
> function.
>
>
>

-- 
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!YcVqv_PA_UdFsx4fZHfzMMaZZ7auMp-poE49ThdEDk0fT7DAXF6-0fOpeWMEOJcrVL5grSHp-QCF8EnZVeTC$  <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!YcVqv_PA_UdFsx4fZHfzMMaZZ7auMp-poE49ThdEDk0fT7DAXF6-0fOpeWMEOJcrVL5grSHp-QCF8AYgu-dB$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240401/7e7aa99c/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: us_logo.jpg
Type: image/jpeg
Size: 21155 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240401/7e7aa99c/attachment-0001.jpg>


More information about the petsc-users mailing list