# Periodic Boundary Conditions for Mixed Finite Element Spaces

**URL:** <https://community.freefem.org/t/periodic-boundary-conditions-for-mixed-finite-element-spaces/4289>\
**Category:** General Discussion\
**Created:** [May 29, 2026, 9:59am UTC](https://community.freefem.org/t/periodic-boundary-conditions-for-mixed-finite-element-spaces/4289 "2026-05-29T09:59:53Z")\
**Posts on this page:** 1\
**Showing post:** 11

<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:** [June 1, 2026, 9:45am UTC](https://community.freefem.org/t/periodic-boundary-conditions-for-mixed-finite-element-spaces/4289/11 "2026-06-01T09:45:30Z")

</div>

In order to save a reference solution computed on a fine mesh, and later compare it to another run of your code on a rough mesh, you can follow the following sketch

```auto
// assumed known mesh Th, fespace Vh, approximate solution u in Vh

// save the mesh to a file "mesh.msh"
savemesh(Th,"mesh.msh");
// save the solution to a file "uref.d"
{
 ofstream fileref("uref.d");
 fileref << u[] << endl;
}

//-------------------------------

//recover a previously saved solution "uref.d" and its mesh "mesh.msh"
mesh Ths=readmesh("mesh.msh");
fespace Vs(Ths,....);//define the fespace exactly as it was defined when the reference solution was saved to a file
Vs us;
{
 ifstream filereadref("uref.d");
 filereadref >> us[] ;
}

// compute the error between u and the reference solution us
// the error is computed on the rough mesh Th (computation on Ths is also possible)
Vh usinterp=us;//interpolate the reference solution us defined on Ths to a function usinterp on Th
real error = sqrt(int2d(Th)((u-usinterp)^2));

```

---

_[View the full topic](https://community.freefem.org/t/periodic-boundary-conditions-for-mixed-finite-element-spaces/4289)._
