Boost serialization

77 views
Skip to first unread message

Najwa Alshehri

unread,
Dec 2, 2024, 8:34:44 AM12/2/24
to deal.II User Group
Dear All,

Thank you for your always support.

I am trying to serialize a Stokes solution in 2d ( dim for velocity +1 for pressure) to use it as a reference solution. Please stop me here if there is a better way to do this.

Unofortunatly, for some reason that I do not know, the saved_solution is all zeros or code breaks. 

To give more details I am solving using :
, fe(FE_Q<dim>(degree + 1), dim, FE_Q<dim>(degree), 1)
with BlockVector solution. This solution is not zeros ( I checked that).

Then I open a file and save in order the following:
<<triangulation
<<fe
<<dof_handler
<<solution
using 
boost::archive::text_iarchive
This finishes with no issues.  I even checked if the file is unreadable or empty, it is not.

When I deserialize to check the saved solution is matching my computed solution, I use same fe 
FESystem<dim> saved_fe(FE_Q<dim>(degree + 1), dim, FE_Q<dim>(degree), 1);
and deserialize in the following order
>>saved_triangulation
>>safe_fe
reint and distribute_dofe for the saved_dof_handler using the saved triangulation and fe.
>>saved_dof_handler
>>saved solution


After a deep investigation, it seems like " >>saved_dof_handler" is where the code beaks with error 
"----------------------------------------------------
Exception on processing:
input stream error
Aborting!
---------------------------------------------------- "
which means that saved_dof_handler cannot be read form the saved file. However,  I checked after distributing dofs and  "saved_dof_handler" has the correct n_dofs().

In this code I was just checking, so dof_handler is not really needed here, but in the real code it is need to write a function out of the solution. For the sake of debugging, I removed  " >>saved_dof_handler". Removing it gives all zeros solution vector.  This is suspicious, is it connected to the saved_dof_handler?? 

I think I have checked many other things to find the source of the issue with no success. Conclusion, saved triangulation and saved fe seems to be correct.

Any one knows what is happening here? I would appreciate any guidance one what could be a source for the issue.

Best,
Najwa

Wolfgang Bangerth

unread,
Dec 2, 2024, 3:42:10 PM12/2/24
to dea...@googlegroups.com

Najwa:
I assume you have taken a look at step-83, the tutorial program that
demonstrates serialization?
https://dealii.org/developer/doxygen/deal.II/step_83.html

Separately, the way to debug these sorts of problems is to create as
small a program as possible that still shows the issue. It doesn't have
to do anything useful, for example you can replace assemble_system() and
solve() by just setting the vector to ones. Can you come up with such a
minimal program?

Best
W.


On 12/2/24 06:34, Najwa Alshehri wrote:
> *** Caution: EXTERNAL Sender ***
> --
> The deal.II project is located at http://www.dealii.org/ <https://
> nam10.safelinks.protection.outlook.com/?
> url=http%3A%2F%2Fwww.dealii.org%2F&data=05%7C02%7CWolfgang.Bangerth%40colostate.edu%7Cd23d2bd47fb74e7a13d008dd12d617b6%7Cafb58802ff7a4bb1ab21367ff2ecfc8b%7C0%7C0%7C638687432905944661%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=aL1SluRAwCThs3i1ORCDkJqgy6G5yYqZIzrus4R1hTk%3D&reserved=0>
> For mailing list/forum options, see https://groups.google.com/d/forum/
> dealii?hl=en <https://nam10.safelinks.protection.outlook.com/?
> url=https%3A%2F%2Fgroups.google.com%2Fd%2Fforum%2Fdealii%3Fhl%3Den&data=05%7C02%7CWolfgang.Bangerth%40colostate.edu%7Cd23d2bd47fb74e7a13d008dd12d617b6%7Cafb58802ff7a4bb1ab21367ff2ecfc8b%7C0%7C0%7C638687432905970544%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=2qVckhsHD78WJek30A49bAR3RHjH4Zt1JpXJchZe8es%3D&reserved=0>
> ---
> You received this message because you are subscribed to the Google
> Groups "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to dealii+un...@googlegroups.com
> <mailto:dealii+un...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/dealii/
> b2e37661-b458-4dbb-a849-52c6f1744ec2n%40googlegroups.com <https://
> nam10.safelinks.protection.outlook.com/?
> url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fdealii%2Fb2e37661-
> b458-4dbb-
> a849-52c6f1744ec2n%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C02%7CWolfgang.Bangerth%40colostate.edu%7Cd23d2bd47fb74e7a13d008dd12d617b6%7Cafb58802ff7a4bb1ab21367ff2ecfc8b%7C0%7C0%7C638687432905991612%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=bgq9j1DMj%2BiUfEMR5WCYiQKw0IYC9OkrnVjtLUdS3GU%3D&reserved=0>.

Message has been deleted

Najwa Alshehri

unread,
Dec 3, 2024, 8:19:49 AM12/3/24
to deal.II User Group

Dear Prof. Wolfgang,

I appreciate your answer. 

The exact same steps I used for elliptic problem with FE_Q and solution that is written in vector. It was working perfectly. 

New things here, we are using fe system and block vector, others should be the same.

Best,
Najwa
Message has been deleted

Wolfgang Bangerth

unread,
Dec 3, 2024, 11:57:59 PM12/3/24
to dea...@googlegroups.com
On 12/3/24 02:32, Najwa Alshehri wrote:
>
> The exact same steps I used for elliptic problem with FE_Q and solution that
> is written in vector. It was working perfectly.
>
> New things here, we are using fe system and block vector, others should be the
> same.

Najwa:
This does not trigger any "oh, I know what Najwa's problem is" reaction in me.
As I mentioned, create a minimal test case that illustrates the problem and
nothing else -- then we can look at it.

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/


Najwa Alshehri

unread,
Dec 4, 2024, 12:37:04 AM12/4/24
to deal.II User Group
Thank you for your response. 

For those who might face something similar, I found that the saved file does not have the solution saved and the last thing that was saved is the dof_handler (assuming that I can read the saved file :) ).  It looks like (<< solution; ) was not doing the job.

It turned out that if I saved the solution block after the other, it worked. "Worked" in the sense that I could see the solution in the saved file. ( << solution.block(0); << solution.block(1); ). The solution in the saved file matches the solution I wanted to save.

I am not sure if this is the correct way to do it, but it seems like it is because when I deserialize, I get a saved_solution with the correct size and number of blocks. 

Unfortunately, I still have saved_solution, which is all zeros when I deserialize, but I am working on it and will update you for the benefit of others if I find a solution to it.

Best,
Najwa

Najwa Alshehri

unread,
Dec 4, 2024, 1:42:12 AM12/4/24
to deal.II User Group
Dear all,

Thank you for your ongoing support. It's quite amusing that every time I post a question here, I end up solving it myself—perhaps writing it out helps me think more clearly.

In any case, I've successfully managed to serialize and deserialize solutions. I serialized the block vector one block at a time using `<< solution.block(i);` for each block, and deserialized in the same manner with `>> saved_solution.block(i);` for each block.

It is time now to use it and see how it goes. 

Feel free to reach out if you have any questions on this.

Best regards,
Najwa

Reply all
Reply to author
Forward
0 new messages