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

MIGUEL MOLINOS PEREZ mmolinos at us.es
Mon Apr 1 11:38:52 CDT 2024


I see. Thank you for the feedback Matthew!

Thanks,
Miguel

On 1 Apr 2024, at 18:32, Matthew Knepley <knepley at gmail.com> wrote:

On Mon, Apr 1, 2024 at 11:13 AM MIGUEL MOLINOS PEREZ <mmolinos at us.es<mailto: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


<us_logo.jpg>




https://urldefense.us/v3/__http://www.us.es__;!!G_uCfscf7eWS!Z_MoZ7Bj4eyIXKal80C357h4aO105lFAgZwG6a6xZwNKsKVTzZ4HfUspESkt1TKg2MOv5bbWwmDB8Gsd-nJ2ng$ <https://urldefense.us/v3/__http://www.us.es/__;!!G_uCfscf7eWS!Z_MoZ7Bj4eyIXKal80C357h4aO105lFAgZwG6a6xZwNKsKVTzZ4HfUspESkt1TKg2MOv5bbWwmDB8GvROZc7vQ$ >
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<mailto: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!Z_MoZ7Bj4eyIXKal80C357h4aO105lFAgZwG6a6xZwNKsKVTzZ4HfUspESkt1TKg2MOv5bbWwmDB8Gs0StP1_g$ <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!Z_MoZ7Bj4eyIXKal80C357h4aO105lFAgZwG6a6xZwNKsKVTzZ4HfUspESkt1TKg2MOv5bbWwmDB8Gt75UYM5Q$ >

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20240401/1b07ade9/attachment.html>


More information about the petsc-users mailing list