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

**URL:** <https://community.freefem.org/t/is-there-anyway-to-substrcipt-the-elements-of-an-fespace/2258>\
**Category:** General Discussion\
**Created:** [February 1, 2023, 10:44pm UTC](https://community.freefem.org/t/is-there-anyway-to-substrcipt-the-elements-of-an-fespace/2258 "2023-02-01T22:44:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [February 1, 2023, 10:44pm UTC](https://community.freefem.org/t/is-there-anyway-to-substrcipt-the-elements-of-an-fespace/2258/1 "2023-02-01T22:44:28Z")

</div>

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](https://community.freefem.org/uploads/short-url/vg4XTkzJSJqSSVq4SAGOj5bwSo6.edp) (1.4 KB)

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)\
**Post date:** [February 2, 2023, 9:49am UTC](https://community.freefem.org/t/is-there-anyway-to-substrcipt-the-elements-of-an-fespace/2258/2 "2023-02-02T09:49:02Z")

</div>

Maybe the following could work:

```auto
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.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [February 2, 2023, 11:03am UTC](https://community.freefem.org/t/is-there-anyway-to-substrcipt-the-elements-of-an-fespace/2258/3 "2023-02-02T11:03:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)\
**Post date:** [February 2, 2023, 1:49pm UTC](https://community.freefem.org/t/is-there-anyway-to-substrcipt-the-elements-of-an-fespace/2258/4 "2023-02-02T13:49:03Z")

</div>

I think you can find basically all the mesh related commands here: [Mesh Generation](https://doc.freefem.org/documentation/mesh-generation.html#mesh-connectivity-and-data)

One thing is that the vertices correspond to the DOF only to in the case of P1 elements, see [Finite element](https://doc.freefem.org/documentation/finite-element.html#lagrangian-finite-elements). I am not sure whether this causes the confusion or not.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [February 2, 2023, 8:47pm UTC](https://community.freefem.org/t/is-there-anyway-to-substrcipt-the-elements-of-an-fespace/2258/5 "2023-02-02T20:47:54Z")

</div>

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,

```auto
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

```
