# A small puzzle about the length of vector valued fespace

**URL:** <https://community.freefem.org/t/a-small-puzzle-about-the-length-of-vector-valued-fespace/2610>\
**Category:** General Discussion\
**Created:** [July 17, 2023, 1:23pm UTC](https://community.freefem.org/t/a-small-puzzle-about-the-length-of-vector-valued-fespace/2610 "2023-07-17T13:23:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)\
**Post date:** [July 17, 2023, 1:23pm UTC](https://community.freefem.org/t/a-small-puzzle-about-the-length-of-vector-valued-fespace/2610/1 "2023-07-17T13:23:47Z")

</div>

Dear all  
if we create two fespace Vh(Th,[P2 P2 P1]) and Mh(Th,P1) on the same mesh, then we define Vh [ux,uy,up] and Mh [vp], I find that the length of vp (vp.n) doesn’t equal to the length of up.  
I think the length of up should equal to the number of points, because it is defined as P1 in the Vh(Th,[P2 P2 P1]). But it doesn’t. I just don’t know why.  
Thanks a lot!

---

<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:** [July 17, 2023, 5:48pm UTC](https://community.freefem.org/t/a-small-puzzle-about-the-length-of-vector-valued-fespace/2610/2 "2023-07-17T17:48:48Z")

</div>

I think ux, uy, up all just return the vector that corresponds to the full vectorial finite element space. This is just how it is as far as I know.

If you want to access only `up` as a vector, you could set up a problem with three FE spaces ux (P2), uy (P2), up (P1), and assemble the problem you are solving using block matrices.

Or maybe use indices and go through the vector with something like this (I did not test the code)  
Vh fieldInd [f1,f2,f3] = [1,2,3];  
Mh mp;  
int ip = 0;  
for [i, fi: f1] (fi==3 ? mp[ip++] = fi : 0);

---

<div class="post-metadata">

**Author:** ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)\
**Post date:** [July 18, 2023, 4:35am UTC](https://community.freefem.org/t/a-small-puzzle-about-the-length-of-vector-valued-fespace/2610/3 "2023-07-18T04:35:19Z")

</div>

Thanks very much~ I have found the problem that some of the data is stored according to the mesh connectivity（ the length of data vp [p1] equals to the 3\*n\_triangle), while some of the data up [p1] is stored in the point of the mesh , so its length equals to the n\_points. It’s my fault to make such a mistake…

---

<div class="post-metadata">

**Author:** ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)\
**Post date:** [July 18, 2023, 7:28am UTC](https://community.freefem.org/t/a-small-puzzle-about-the-length-of-vector-valued-fespace/2610/4 "2023-07-18T07:28:54Z")

</div>

Besides, there also exits a tool in matlab (ffvectorget.m) which could get ux from the vectorized fespace (ux,uy,up). However, the ux is stored according to the mesh connectivity, so the length of ux equals to 6\*n\_triangle instead of the degree of freedom about P2 on the Th.
