# Save results in Mixed FEM

**URL:** <https://community.freefem.org/t/save-results-in-mixed-fem/284>\
**Category:** General Discussion\
**Created:** [March 2, 2020, 5:06am UTC](https://community.freefem.org/t/save-results-in-mixed-fem/284 "2020-03-02T05:06:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emma87](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@Emma87](https://community.freefem.org/u/Emma87)\
**Post date:** [March 2, 2020, 5:06am UTC](https://community.freefem.org/t/save-results-in-mixed-fem/284/1 "2020-03-02T05:06:57Z")

</div>

Dear Friends,  
I want to know how I can save values of a primal variable from a mixed fem formulation, for example:

mesh Th=square(3,3);  
fespace Vh(Th, [P1,P1]);  
Vh [u, v];

func real initialize() {  
real value1 = 1.0, value2 = -1.0;  
if( x\>=0.25 && x\<=0.75 && y\>=0.25 && y\<=0.75 ) return value1;  
else return value2;  
}  
[u, v] = [initialize(), 0.5];

/\* Print results \*/  
for(int i=0; i\<Vh.ndof; ++i)  
cout \<\< " u = "\<\< u[][i] \<\< endl;

Result:  
Square mesh : nb vertices =16 , nb triangles = 18 , nb boundary edges 12  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
u = 1  
u = 0.5  
u = 1  
u = 0.5  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
u = 1  
u = 0.5  
u = 1  
u = 0.5  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
u = -1  
u = 0.5  
times: compile 0.026953s, execution 0.003083s, mpirank:0  
CodeAlloc : nb ptr 3463, size :466120 mpirank: 0  
Ok: Normal End

The result shows the output of the two variables, but how can I save only the variable of interest “u”

---

<div class="post-metadata">

**Author:** ![BeniaminBogosel](https://avatars.discourse-cdn.com/v4/letter/b/3ec8ea/32.png) [@BeniaminBogosel](https://community.freefem.org/u/BeniaminBogosel)\
**Post date:** [March 4, 2020, 10:08pm UTC](https://community.freefem.org/t/save-results-in-mixed-fem/284/2 "2020-03-04T22:08:19Z")

</div>

Just make a scalar P1 finite element space and save the component of interest as a scalar function.

You can note that the values for u are stored on even indices in u[] while those for v on odd indices in u[].

* * *

mesh Th=square(20,20);

fespace Vh2(Th,[P1,P1]);  
fespace Vh(Th,P1);

Vh2 [u,v];  
Vh w;  
[u,v]= [sqrt(x^2+y^2),sqrt((x-0.5)^2)];  
plot(u,fill=1,cmm=“u”,wait=1);

w = u;  
plot(w,fill=1,cmm=“w”,wait=1);  
w = v;  
plot(w,fill=1,cmm=“w”,wait=1);

// or notice how the variables are stored in u[]  
[u,v] = [0,1];

for(int i=0;i\<Vh2.ndof;i++){  
cout \<\< u[][i] \<\< endl;  
}

---

<div class="post-metadata">

**Author:** ![Emma87](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@Emma87](https://community.freefem.org/u/Emma87)\
**Post date:** [March 5, 2020, 9:20am UTC](https://community.freefem.org/t/save-results-in-mixed-fem/284/3 "2020-03-05T09:20:17Z")

</div>

Thanks Beniamin, this works for the tests I want to perform.

Best regards,
