# Savesol readsol for P2 FE fields?

**URL:** <https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337>\
**Category:** General Discussion\
**Created:** [March 15, 2023, 10:03pm UTC](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337 "2023-03-15T22:03:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![plouraboue](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/plouraboue/32/1584_2.png) [@plouraboue](https://community.freefem.org/u/plouraboue)\
**Post date:** [March 15, 2023, 10:03pm UTC](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337/1 "2023-03-15T22:03:38Z")

</div>

Hi to all,  
I guess this is a question to Frédéric Hetch or close collaborators :

The documentation only describe order=0 and order=1 options for saving a field with savesol and all examples I have seen only do it for P1 FE fields. I have tested savesol readsol for P1 fields and it works fine. However, for P2 fields, even if the option order=2 is accepted there is a MISSING DATA warning when executing and readsol does not work properly.

Is there some project to extend savesol readsol funcitons for P2 FE fields ?

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [March 19, 2023, 8:54am UTC](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337/2 "2023-03-19T08:54:37Z")

</div>

Dear User,

The savsol, is make to do graphic, not really to save the solution.

The best way to save the solution is

1. save the mesh ( do not rebuild because if you change of machin the risk to get a different mesh is important)
2. save the array of dof

when

1. read les mesh
2. def. the finite element space ( Generally you know it, but it is impossible to make a generic code)
3. read the solution

remark, if you want the know the dof numbing, you can save the numbering by element

---

<div class="post-metadata">

**Author:** ![plouraboue](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/plouraboue/32/1584_2.png) [@plouraboue](https://community.freefem.org/u/plouraboue)\
**Post date:** [April 5, 2023, 8:08pm UTC](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337/3 "2023-04-05T20:08:21Z")

</div>

Many thanks Frédéric. It works indeed. Here are some line codes for people interested :

fespace Vh(Th, P2);  
Vh c, ctest;  
// copy the data c into a vector  
ctest= c;  
// save the P2 FE field  
{ofstream ff(“csol.txt”); ff \<\< ctest\<\< endl;  
}  
read the P2 FE field  
{ifstream gg(“csol.txt”); gg \>\> ctest3;  
}  
// plot the read data  
plot(ctest3, Th, value=true, wait=true);

---

<div class="post-metadata">

**Author:** ![niks9k](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@niks9k](https://community.freefem.org/u/niks9k)\
**Post date:** [June 26, 2023, 6:42pm UTC](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337/4 "2023-06-26T18:42:12Z")

</div>

![Screenshot 2023-06-27 at 12.08.00 AM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/ef4efaa6e2ccd47ebac1a5181ddc6115027fb418.png)  
Hi , i tried this, my code is plotting the mesh instead of the solution that my i saved in the save.txt

or am i doing something wrong in saving

 ![Screenshot 2023-06-27 at 12.11.55 AM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/d/d822cc941f6cc35e5a04c13a50ac98580c1ed604.png)

---

<div class="post-metadata">

**Author:** ![niks9k](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@niks9k](https://community.freefem.org/u/niks9k)\
**Post date:** [June 26, 2023, 7:14pm UTC](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337/5 "2023-06-26T19:14:46Z")

</div>

Tried with the first example in learning by examples. So, what could be the possible reason of not receiving the plot of u. Attaching the save-read code and result

 ![Save File](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/5a037bda34fdb59be3d5921aebd283ccc70cf972.png)  
 ![Read File](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/8/89b825f49a0d6da54ad9799c39aff642cc6472ff.png)  
 ![Read File Plot](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/2/25d75682413e4cd92911598810a6e67df851cdb4.png)

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 26, 2023, 8:24pm UTC](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337/6 "2023-06-26T20:24:11Z")

</div>

Because you the mesh after with fill=1 so you don not see the solution so change the order

---

<div class="post-metadata">

**Author:** ![niks9k](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@niks9k](https://community.freefem.org/u/niks9k)\
**Post date:** [July 1, 2023, 7:50am UTC](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337/7 "2023-07-01T07:50:12Z")

</div>

thank you very much, it works now
