Hi,
Let’s say I have a 2D array stored in a file:
import matplotlib.pyplot as plt
import numpy as np
a = np.loadtxt(“w_map.txt”)
a = np.reshape(a,(624,304))
plt.imshow(a)
plt.show()
Then I want to use this 2D function in FreeFem++:
// READ THE MAP
ifstream wmap(“w_map.txt”);
real[int, int] w(624, 304);
for(int i=0; i<624; i++){
for(int j=0; j<304; j++){
string comment;
if ( !wmap.good() )
break;
getline(wmap, comment);
w(i,j) =atof(comment);
}
}
// CREATE THE FESPACE (just a rectangle)
border a(t=0, dims[0]){x=t; y=0; label=1;};
border b(t=0, dims[1]){x=624; y=t; label=2;};
border f(t=0, dims[0]){x=624-t; y=304; label=3;};
border d(t=0, dims[1]){x=0; y=304-t; label=4;};
int n=240;
mesh fm = buildmesh(a(n) + b(n) + f(n) + d(n));
fespace Vh(fm, P1);
Vh whh = w;
plot(whh, wait=true);
It looks like the projection of my 2D function onto the fespace is wrong but I dont know why.
Do you have any idea where the problem comes from ?
PS: Do you know how to do the Tab cause it’s really annoying to have non indented code in my posts.