# Solution Store for dG set up

**URL:** <https://community.freefem.org/t/solution-store-for-dg-set-up/3850>\
**Category:** General Discussion\
**Created:** [April 10, 2025, 6:05am UTC](https://community.freefem.org/t/solution-store-for-dg-set-up/3850 "2025-04-10T06:05:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ravi](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ravi/32/2468_2.png) [@Ravi](https://community.freefem.org/u/Ravi)\
**Post date:** [April 10, 2025, 6:05am UTC](https://community.freefem.org/t/solution-store-for-dg-set-up/3850/1 "2025-04-10T06:05:14Z")

</div>

For discontinuous space set up how to store the solution with x and y values in a text file?  
I tried

> {  
> ofstream ff(“phi.txt”);  
> ff \<\< phi ;  
> }  
> savemesh(Th,“Th.msh”);

and

> {  
> ofstream ff(“graph.txt”);  
> for (int i = 0; i \< Th.nt; i++)  
> {  
> for (int j = 0; j \< 3; j++)  
> ff \<\< Th[i][j].x \<\< " "\<\< Th[i][j].y \<\< " " \<\< phi[Vh(i,j)] \<\< endl;  
> ff \<\< Th[i][0].x \<\< " " \<\< Th[i][0].y \<\< " " \<\< phi[Vh(i,0)] \<\< “\n\n\n”  
> }  
> }

But it did not work.

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [April 10, 2025, 11:10am UTC](https://community.freefem.org/t/solution-store-for-dg-set-up/3850/2 "2025-04-10T11:10:50Z")

</div>

Your syntax is correct for P1dc `fespace Vh(Th,P1dc)`.  
Your first try stores the coordinates in the basis of the fespace.  
It can be used for loading later in FF++.  
Your second try solves the location of dof and the value of the function.  
You simply miss `{}` for the content of the j loop:

```auto
{
ofstream ff("graph.txt");
for (int i = 0; i < Th.nt; i++)
{
for (int j = 0; j < 3; j++){
ff << Th[i][j].x << " "<< Th[i][j].y << " " << phi[][Vh(i,j)] << endl;
}
}
}

```

---

<div class="post-metadata">

**Author:** ![Ravi](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ravi/32/2468_2.png) [@Ravi](https://community.freefem.org/u/Ravi)\
**Post date:** [April 10, 2025, 6:57pm UTC](https://community.freefem.org/t/solution-store-for-dg-set-up/3850/3 "2025-04-10T18:57:13Z")

</div>

Do I need to change anything for _P2dc fespace Vh(Th, P2dc)_?

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [April 11, 2025, 8:49am UTC](https://community.freefem.org/t/solution-store-for-dg-set-up/3850/4 "2025-04-11T08:49:23Z")

</div>

for `fespace Vh(Th,P2dc)` you can do as

```auto
{
ofstream ff("graph.txt");
real[int] mix(3),miy(3);
for (int i = 0; i < Th.nt; i++)
{
mix(0)=(Th[i][1].x+Th[i][2].x)/2.;//coordinates of the middle of the edges
miy(0)=(Th[i][1].y+Th[i][2].y)/2.;
mix(1)=(Th[i][0].x+Th[i][2].x)/2.;
miy(1)=(Th[i][0].y+Th[i][2].y)/2.;
mix(2)=(Th[i][0].x+Th[i][1].x)/2.;
miy(2)=(Th[i][0].y+Th[i][1].y)/2.;
for (int j = 0; j < 3; j++){
ff << Th[i][j].x << " "<< Th[i][j].y << " " << phi[][Vh(i,j)] << endl;
ff << mix(j) << " "<< miy(j) << " " << phi[][Vh(i,j+3)] << endl;
}
}
}

```
