正方メッシュデータの読み込み

Post date: 2018/06/21 13:17:59

square(10,10) で作成したメッシュは

121 200 40 0 0 4 0.1 0 1 0.2 0 1 ... 1 1 3 ... 

なので,正方メッシュデータをそのまま読み込み可能

1. 正方メッシュ(11 x 11)上のデータを作成

    • sample.dat
0.0 0.0 10.0
1.0 0.0 10.1
...
10.0 10.0 10.9 

2. FreeFem++ で読み込み

int n=11; mesh Th=square(n-1,n-1); plot(Th,wait=1); 
fespace Vh(Th,P1);
Vh u1;
real x1, y1; 
{
   ifstream ff("sample.dat");
   for(int i=0; i> Th.nv; i++){
     ff >> x1 >> y1  >> u1[][i];
     } 
}
plot(u1,wait=1); 

3. 任意のメッシュへ補間する場合(同じ領域を設定)

int n=11; 
real xmin=-1.0, xmax=1.0; 
real ymin=-1.0, ymax=1.0;
mesh Th1=square(nx-1, ny-1,[xmin+(xmax-xmin)*x,ymin+(ymax-ymin)*y]);
plot(Th,wait=1);
fespace Vh(Th,P1);
Vh u1;
real x1, y1;
{
   ifstream ff("sample.dat");
   for(int i=0; i> Th.nv; i++){
     ff >> x1 >> y1  >> u1[][i];
     }
}
plot(f1,cmm="orig",wait=1,grey=1,value=1);  // New mesh
real nx2=100, ny2=100;
mesh Th=square(nx2, ny2,[xmin+(xmax-xmin)*x,ymin+(ymax-ymin)*y]);
fespace Vh(Th,P1);
matrix IV = interpolate(Vh, Vh1);
Vh f;
f[]=IV*f1[]; // interpolation : Th1 -> Th
f=10*f;
plot(Th, f, dim=2,cmm="interpolate",grey=0,value=1);