# Save Boundary Condition

**URL:** <https://community.freefem.org/t/save-boundary-condition/2246>\
**Category:** General Discussion\
**Created:** [January 25, 2023, 1:39pm UTC](https://community.freefem.org/t/save-boundary-condition/2246 "2023-01-25T13:39:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![galfras](https://avatars.discourse-cdn.com/v4/letter/g/898d66/32.png) [@galfras](https://community.freefem.org/u/galfras)\
**Post date:** [January 25, 2023, 1:39pm UTC](https://community.freefem.org/t/save-boundary-condition/2246/1 "2023-01-25T13:39:36Z")

</div>

Hello!  
I’m working with several files, and the solution I obtain in one of them I need to use ir as the boundary condtion in the other. Is there a way to save and read the boundary condition in a .txt? I know I can save the whole solution, but I don’t need most of that data and that creares big files.  
Thanks!

---

<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:** [January 26, 2023, 9:00pm UTC](https://community.freefem.org/t/save-boundary-condition/2246/2 "2023-01-26T21:00:28Z")

</div>

The idea is to save the interpolation of the boundary condition.

an ideas:

[save-bc.edp](https://community.freefem.org/uploads/short-url/32k2tEaonvJOpgYyzWPqzLmz2yq.edp) (423 Bytes)

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [January 26, 2023, 10:37pm UTC](https://community.freefem.org/t/save-boundary-condition/2246/3 "2023-01-26T22:37:04Z")

</div>

You can evaluate the solution anywhere with automatic interpolation. I just output on  
a regular grid which includes the boundaries I seem to recall however something in libmesh  
about some way of handling these or related problems but I dont remember the  
name. - there may be a function to do this. Anyway, for example I just looked at this  
in R and it seems to work,

```auto
int onmesh=0;
{
ofstream ff("peri.txt");
if (onmesh==1)
{
for (int ii = 0; ii < Th.nv; ii++)
//for (int ii = 0; ii < Th.nt; ii++)
{
// I guess these are verticies? 
real x=Th[ii][0].x;
real y=Th[ii][0].y;
real z=Th[ii][0].z;
real uhi=uh(x,y,z);
//if (Th[ii].region==888) hx[ii]=volume/1.4; 
//if (Th[ii].region==999) hx[ii]=volume;
//cout<<" point "<< x<<" "<<y<<" "<<z <<" "<< Th[ii].region << " "<<uhi << endl;
ff<<" point "<< x<<" "<<y<<" "<<z <<" "<< Th[ii].region << " "<<uhi << endl;
} 
} // onmesh
else
{
int npts=1e2;
int px=npts^3;
int px2=npts^2;
int ip=0,iq=0,ir=0;
real delc=2*dim/npts; 
for (int ii = 0; ii < px; ii++)
{
++ip; if (ip==npts) { ip=0; ++iq;
if (iq==npts) { iq=0; ++ir; } }
real x=x0+delc*ip;;
real y=x0+delc*iq;;
real z=x0+delc*ir;;
real uhi=uh(x,y,z);
ff<<" point "<< x<<" "<<y<<" "<<z <<" "<<uhi << endl;

} // ii 

} // !onmesh 
} // scope

```

---

<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:** [January 27, 2023, 9:02am UTC](https://community.freefem.org/t/save-boundary-condition/2246/4 "2023-01-27T09:02:42Z")

</div>

Be careful with the previous comment, this ok for P1 Finite element ; not for all finite element because the interpolation operator is not only the value a vertices.

use varf with on like

varf vonPb(u,v) = on(1,2,3,4,u=g);  
Vh g=vonPb(0,Vh,tgv=1);// tgv=1 is important because other without you get the value multiply by tgv value (1e30)

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [January 27, 2023, 9:24am UTC](https://community.freefem.org/t/save-boundary-condition/2246/5 "2023-01-27T09:24:16Z")

</div>

Interpolating the solution will pick up the tgv to enforce the diriclet bc?  
In any case, it looks like you can just iterate over the  
boundary just as you would any other component. Thbounds is part of the overall  
mesh and AFAICT this generates the right result. This is the example I happen  
to have, there is no BC enforced although it is using periodic BC  
on this surface.

```auto
meshS Thbounds = mycube(x0,x1,yy0,yy1,z0,z1,-1,1);
real vol=volumetet;
meshS Thsrc=Thx0;
//nx=8; ny=8; nz=8;
meshS Thdense = mycube(x0+sx,x1-sx,yy0+sx,yy1-sx,z0+sx,z1-sx,-1,100);
meshS Thtotal= Thdense+Thbounds;

```

```auto
for (int ii = 0; ii < Thbounds.nv; ii++)
//for (int ii = 0; ii < Th.nt; ii++)
{
// I guess these are verticies? 
real x=Thbounds[ii][0].x;
real y=Thbounds[ii][0].y;
real z=Thbounds[ii][0].z;
real uhi=uh(x,y,z);
//if (Th[ii].region==888) hx[ii]=volume/1.4; 
//if (Th[ii].region==999) hx[ii]=volume;
//cout<<" point "<< x<<" "<<y<<" "<<z <<" "<< Th[ii].region << " "<<uhi << endl;
ff<<" point "<< x<<" "<<y<<" "<<z <<" "<< Thbounds[ii].region << " "<<uhi << endl;

```
