# Is There anyway to substrcipt the elements of an fespace?

I the attached file, I’m trying to set the value of “d” or “dodo” such that
it has one value above and another below y=.95 . Actually what I want is for any
vertex closest to the top to have one value different from the bulk . I can find
documentation on indexing the mesh but there is no obvious way to extent
that to the dof’s. It looks like the function method shown for “dodo” works
but how do you do this stepping through verticies?
Thanks. All this time I thought I had some obscure math problem lol.
wtf.edp (1.4 KB)

``````mesh Th = square(10,10);
fespace Vt(Th,P2);
Vt d;
for (int ii = 0; ii < Th.nv; ii++)
{
d[][ii]=1; // /(1+fb[i][9]*dfb+fbc[ii][0]*dfbc);
// d[][Th[ii][0]]=1e12; // /(1+fb[i][9]*dfb+fbc[ii][0]*dfbc);
//if (Th[ii][0].y>(.95)) d[][ii]=0;
if (Th(ii).x>(.95)) d[][ii]=2;
//if (Th[0][ii].y>(.95)) d[][ii]=0;
//else  Do[][Th[ii]]=1e12; // /(1+fb[i][9]*dfb+fbc[ii][0]*dfbc);
}
func real ff(real x, real y)
{
if (y>.85) return 2;
return 1;
}
Vt dodo = ff(x,y);

plot(d,cmm="d",wait=true);
plot(dodo,cmm="d",wait=true);

``````

Maybe the following could work:

``````Vt xx = x;
Vt yy = y;
Vt dodo;
for(int i=0; i<dodo[].n; i++) {
if(yy[][i]>0.85)
dodo[][i]=1;
}
``````

This way, you can loop through the points where the function values are stored, and also access their coordinates.

Thanks but isn’t it kind of a kluge to make an fespace to store
x and y? I have nothing against using that but I’m just surprised
there is no easy way to loop over the mesh- elements or verticies,
and get the corresponding dof’s.
I have a lot of cases where I try to loop from zero to mesh.nv
assuming I’m getting all the verticies. Sometimes this looks like it
works other times it clearly fails. I guess I don’t understand why there is not
some subscript that points to the vertex in the mesh and to the coresponding
dof in the femspace arrays. Depending on the vertex coord I can set the
value of dodo.

For now I converted my code to use functions but I still want to
get dof variables vertex by vertex.

Thanks.

I think you can find basically all the mesh related commands here: Mesh Generation

One thing is that the vertices correspond to the DOF only to in the case of P1 elements, see Finite element. I am not sure whether this causes the confusion or not.

Thanks, on a quick test this appears to work where Th is being updated
to Th2 and last values are interpolated and put onto new mesh,

``````macro RESAMPLE( B,Th2,A,Th,E) {
fespace Ah(Th,E); fespace Bh(Th2,E);
Bh xx=x; Bh yy=y;
for(int i=0; i<xx.n; ++i) {real xp=xx[][i]; real yp=yy[][i];
B[][i]=A(xp,yp); }
} // EOM

``````