# SpatialCoordinate of submesh

**URL:** <https://fenicsproject.discourse.group/t/spatialcoordinate-of-submesh/16396>\
**Category:** dolfinx\
**Tags:** mesh\
**Created:** [November 26, 2024, 10:06pm UTC](https://fenicsproject.discourse.group/t/spatialcoordinate-of-submesh/16396 "2024-11-26T22:06:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![torhans](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/torhans/32/3976_2.png) [@torhans](https://fenicsproject.discourse.group/u/torhans)\
**Post date:** [November 26, 2024, 10:06pm UTC](https://fenicsproject.discourse.group/t/spatialcoordinate-of-submesh/16396/1 "2024-11-26T22:06:46Z")

</div>

Is this difference in coordinates in dofs and geometry intended?

```auto
import gmsh
from dolfinx.io import gmshio
from mpi4py import MPI

gmsh.initialize()
r1=gmsh.model.occ.addRectangle(0, 0, 0, 1, 1)
r2=gmsh.model.occ.addRectangle(1, 0, 0, 1, 1)
r3=gmsh.model.occ.addRectangle(2, 0, 0, 1, 1)
gmsh.model.occ.synchronize()
v,v0=gmsh.model.occ.fragment([(2,r1),(2,r2),(2,r3)],[],removeObject=True)
gmsh.model.occ.synchronize()

for i,ee in enumerate(v):
    gmsh.model.addPhysicalGroup(2, [ee[1]],i+1)

facets=gmsh.model.getBoundary(v)
left=[]
right=[]
for f in facets:
    p1,p2=gmsh.model.getBoundary([f])
    if (gmsh.model.getValue(*p1,[])[0]==0) & (gmsh.model.getValue(*p2,[])[0]==0):
        left.append(f[1])
    if (gmsh.model.getValue(*p1,[])[0]==3) & (gmsh.model.getValue(*p2,[])[0]==3):
        right.append(f[1])
gmsh.model.addPhysicalGroup(1, left,2)    
gmsh.model.addPhysicalGroup(1, right,3)    

gmsh.option.setNumber("Mesh.MeshSizeMin", 5)
gmsh.option.setNumber("Mesh.MeshSizeMax", 30)

gmsh.model.mesh.generate(2)

comm=MPI.COMM_WORLD
domain,st,ft=gmshio.model_to_mesh(gmsh.model,comm,0)
gmsh.finalize()

import numpy as np
import dolfinx
import ufl
cells0,cells1=[np.concatenate([st.find(mi) for mi in grp]) for grp in [[1,2],[3]]]
mesh0,ent_mesh0_main,_,_=dolfinx.mesh.create_submesh(domain,domain.topology.dim,cells0)
V0=dolfinx.fem.functionspace(mesh0,("CG", 1))
f=dolfinx.fem.Function(V0)
x=ufl.SpatialCoordinate(mesh0)
def xx(x):
    return(x[0])
def yy(x):
    return(x[1])
with np.printoptions(precision=2,linewidth=200,suppress=1e-4,floatmode='fixed',sign=' '):
    print(mesh0.geometry.x[:,0])
    print(mesh0.geometry.x[:,1])
    print()
    f.interpolate(xx)
    print(f.x.array)
    f.interpolate(yy)
    print(f.x.array) 

```

> [2.00 2.00 1.50 1.00 1.00 0.50 0.00 0.00]  
> [0.00 1.00 0.50 0.00 1.00 0.50 0.00 1.00]
> 
> [2.00 1.50 2.00 1.00 1.00 0.50 0.00 -0.00]  
> [1.00 0.50 0.00 0.00 1.00 0.50 0.00 1.00]

1st, 2nd and 3rd coordinate has been rotated.

How do I plot a function on submesh using pyvista?

```auto
topology, cell_types, geometry = plot.vtk_mesh(mesh0, tdim)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)

```

does not work correctly

Thanks

---

<div class="post-metadata">

**Author:** ![torhans](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/torhans/32/3976_2.png) [@torhans](https://fenicsproject.discourse.group/u/torhans)\
**Post date:** [November 26, 2024, 10:20pm UTC](https://fenicsproject.discourse.group/t/spatialcoordinate-of-submesh/16396/2 "2024-11-26T22:20:33Z")

</div>

Sorry, maybe I should read the docs first

```auto
topology, cell_types, geometry = plot.vtk_mesh(V0)
grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)

```

does it correctly.

---

<div class="post-metadata">

**Author:** ![nate](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/nate/32/17_2.png) [@nate](https://fenicsproject.discourse.group/u/nate)\
**Post date:** [November 27, 2024, 12:11am UTC](https://fenicsproject.discourse.group/t/spatialcoordinate-of-submesh/16396/3 "2024-11-27T00:11:56Z")

</div>

I have some examples [here](https://github.com/nate-sime/febug/blob/main/febug/plot.py) which may help also.
