# Saving P2 element solution

**URL:** <https://community.freefem.org/t/saving-p2-element-solution/2554>\
**Category:** General Discussion\
**Created:** [June 22, 2023, 7:27am UTC](https://community.freefem.org/t/saving-p2-element-solution/2554 "2023-06-22T07:27:45Z")\
**Posts on this page:** 7\
**Page:** 1

<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 22, 2023, 7:27am UTC](https://community.freefem.org/t/saving-p2-element-solution/2554/1 "2023-06-22T07:27:45Z")

</div>

I was working on a project where for the initial part, we were working on P1 element freespace, and saving the solution of our equation with

```auto
savesol("c1.sol",Th,c,order=1);

```

But later we had to shift to P2 elements, so naturally i changed the code by changing P1 to P2 everywhere in the code and changing order = 2 , while using savesol.  
But in this approach, there is no output being saved in the sol file.  
Do anyone have any idea on where i am making a mistake and how do i fix it to save the solution file

---

<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 23, 2023, 3:56am UTC](https://community.freefem.org/t/saving-p2-element-solution/2554/2 "2023-06-23T03:56:18Z")

</div>

The simple way is one save the mesh with save mesh instruction and sane the array of dof in a file “Toto” as an array

After to reread in freefem

Read the mesh file with readmesh instruction  
Then def the finite element space Vh

> 

VH U;  
Ifstream fin(“Toto”);  
fin \>\> U;

---

<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 23, 2023, 1:56pm UTC](https://community.freefem.org/t/saving-p2-element-solution/2554/3 "2023-06-23T13:56:51Z")

</div>

I am new to this software, how does saving the mesh play any role in saving the solution ( with P2 elements) to the equation and how do I implement saving the array of dof part

![Screenshot 2023-06-23 at 7.26.14 PM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/e74204a7f1e2cd3f5ff3cc57a6bb587cd663f3c1.png)

---

<div class="post-metadata">

**Author:** ![jbl](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jbl](https://community.freefem.org/u/jbl)\
**Post date:** [June 23, 2023, 2:09pm UTC](https://community.freefem.org/t/saving-p2-element-solution/2554/4 "2023-06-23T14:09:01Z")

</div>

Hello,

Have you looked at this [Savesol readsol for P2 FE fields? - #3 by plouraboue](https://community.freefem.org/t/savesol-readsol-for-p2-fe-fields/2337/3)?

Admittedly, there’s no use of savesol, but it does allow you to save a solution and then read it later.

---

<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:** [June 23, 2023, 2:50pm UTC](https://community.freefem.org/t/saving-p2-element-solution/2554/5 "2023-06-23T14:50:39Z")

</div>

Yes I did. savesol can not handle P2 FE fields. Only P1. For P2 you have to write manually as suggested by Frederic. Chears, Franck

---

<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 25, 2023, 6:16pm UTC](https://community.freefem.org/t/saving-p2-element-solution/2554/6 "2023-06-25T18:16:57Z")

</div>

Thank you, I will try implementing this and share the updates

---

<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:47pm UTC](https://community.freefem.org/t/saving-p2-element-solution/2554/7 "2023-06-26T18:47:26Z")

</div>

![Read File](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/ef4efaa6e2ccd47ebac1a5181ddc6115027fb418.png)

Hi , i tried this, my read code is plotting the mesh ( saved in mesh.msh) instead of the solution that my i saved in the save.txt

or am i doing something wrong in saving

 ![Save File](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/0/060847398b123b2c1f994ae37508f75e3ebb6999.png)
