1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
border floor(t=0,1){ x=t; y=0; label=1;}; // the unit square
border right(t=0,1){ x=1; y=t; label=5;};
border ceiling(t=1,0){ x=t; y=1; label=5;};
border left(t=1,0){ x=0; y=t; label=5;};
int n=10;
mesh th= buildmesh(floor(n)+right(n)+ceiling(n)+left(n));
savemesh(th,"toto.am_fmt");// format "formated Marrocco"
savemesh(th,"toto.Th");//format database "bamg"
savemesh(th,"toto.dbg");//format debug
savemesh(th,"toto.msh"); //format freefem
mesh th2 = readmesh("toto.msh");
fespace femp1(th,P1);
femp1 f = sin(x)*cos(y),g;
int where;
real xx;
{
ofstream file("f.txt",binary);// for windows add binary version 3.30
file.precision(16);
file << f[] << endl;
where=file.tellp();
file << 0.1 ;
// file << " " << 0.2 ;
cout << " where in file " << where << endl;
file << " # comment bla bla ... 0.3 \n";
file << 0.2 << endl;
file.flush; // to flush the io buffer of file
}
// Idea to skip comment in a file ... start with # too EOL
func ifstream skipcomment(ifstream &ff)
{
while(1)
{
int where = ff.tellg(); // store file position
string comment;
ff >> comment;
if ( ! ff.good() ) break;
if( comment(0:0)=="#") {
getline(ff,comment);
cout << " -- #" << comment << endl;
}
else {
ff.seekg(where); //restore file position
break;
}
}
return ff;
}
{
ifstream file("f.txt",binary); // for windows (pb CRNL EOL translation )
cout << " where " << file.seekg << endl;
file.seekg(where);
file >> xx;
cout << " xx = " << xx << " good ? " << file.good() << endl;
assert(xx==0.1);
skipcomment(file) >> xx;
assert(xx==0.2);
file.seekg(0);
cout << " where " << file.tellg() << " " << file.good() << endl;
file >> g[] ;
}
fespace Vh2(th2,P1);
Vh2 u,v;
plot(g);
solve pb(u,v) =
int2d(th2)( u*v -dx(u)*dx(v)-dy(u)*dy(v) )
+ int2d(th2)(-g*v)
+ int1d(th2,5)( -g*v)
+ on(1,u=0) ;
plot (th2,u);
cout << " (u[],u[]) = " << (u[]'*u[]) << endl;
{
ofstream file("u.txt");
file << u[] << endl;
file.seekp(100);
file.flush;
file << "xxx "<< endl;
}
|