load "gmsh"
load "iovtk"
load "medit"
//verbosity = 1;

// example gmsh

mesh3 Th = gmshload3("cube.msh");
//medit("gmsh3d",Th,wait=1);

// example iovtk

border Gamma(t=0,2*pi){x=cos(t);y=sin(t);label=3;}
border Gamma1(t=0,2*pi){x=2*cos(t);y=2*sin(t);label=5;}
mesh Th2 = buildmesh( Gamma(10)+Gamma1(20) ); 

fespace Vh(Th2,P1);     // P1 FE space
func gg=x;
Vh uh,vh,u;   
Vh ggg=gg;
solve laplacep(uh,vh,solver=CG,tgv=1e5) =      //  definion of  the problem 
    int2d(Th2)( dx(uh)*dx(vh) + dy(uh)*dy(vh) )   //  bilinear form
       + on(3,uh=1)+ on(5,uh=2) ;                        //  boundary condition form

cout << "vtk information" << endl;
int[int] fforder=[0,0,1,0,1];
savevtk("disque.vtk",Th2,uh,ggg,uh,[uh,ggg],[uh,ggg],dataname="kkdjd jyqql bidule45 vector nnn nn44233T",order=fforder,bin=1);


mesh3 Th3;
try {
Th3=readmesh3("spherewithahole.mesh"); // This .mesh file is obtaing with tetgenholeregion.edp
}
catch (...) {
  // FFCS - path to example scripts are changed, so this needs to be in the local directory to be common to FF and FFCS
  //  trick to extract Th3finhole from "tetgenholeregion_rugby.edp"
  //  warning Th3 mesh3 exist in "tetgenholeregion_rugby.edp"
  mesh3 Thedp;// mesh3 variable  out the block 
  {
  include "tetgenholeregion_rugby.edp"
  Thedp=Th3finhole;// save de correcte mesh 
  }
  Th3=Thedp;// set coorect variable ...
}
fespace Vh3(Th3,P1);     // P1 FE space
func gg2=x+y;
int[int] fforder2=[1,1,1,1];
if(verbosity) verbosity=2;
savevtk("bidule.vtu",Th3,gg2,[gg2,gg2,gg2],gg2,[gg2,gg2,gg2],order=fforder2,dataname="kkdjd jyqql bidule45",bin=1); // The fourth solution Have no name. This name is vector4 (4 ==> fourth solution and vector ==> vector solution).
savevtk("bidule.vtk",Th3,gg2,[gg2,gg2,gg2],gg2,[gg2,gg2,gg2],order=fforder2,dataname="kkdjd jyqql bidule45",bin=1);
if(0) { // restore mesh and data, does not work on Windows
real[int][int] data;	

mesh3 Th=vtkload3("bidule.vtk",fields=data);//  work only with order =1 and vgk file
cout << " " << data.n << " == 4 "<< endl;
}

savegmsh(Th3,"Th3");
