load "distance"
load "medit"
mesh3 Th=cube(10,10,10);
fespace Vh(Th,P1);
Vh u = z;//-0.501; 
func fxy=max(abs(x-y),abs(-1.+x+y));
func fxz=max(abs(x-z),abs(-1.+x+z));
func fyz=max(abs(y-z),abs(-1.+y+z));
func fxyz = max(max(fxy,fxz),fyz);
func ff=max(max(abs(x-0.5),abs(y-0.5)),abs(z-0.5));
u = 0.25-ff;
real[int] v0 = [0.001];
plot(u, dim=3, value=1,viso=v0,wait=1); 
Vh v=0,zz=z;
verbosity=3; 
//cout << v[] << endl; 

distance(Th,u,v[],distmax=1);


plot(u,wait=1,viso=v0);
plot(v,wait=1,cmm="distance",nbiso=10);
cout << " vmin/ vmax  " << v[].min << " "<< v[].max << endl;
verbosity=0;
/*
for( int k=0; k< Th.nt; ++k)
for( int j=0; j< 4; ++j)
{
	int i= Vh(k,j);
if(abs(v[][i]-zz[][i]) > 0.001)
cout << " i "<< i << " k = "<< k << " " << j << endl;
}
//medit("Th-v",Th,v);
*/
