# Question about "MeshCoordinates()" in legacy FEniCS

Hello
It’s been a while since I’ve posted a question

Recently, while exploring the legacy DOLFIN code, I came across the MeshCoordinates() function.
From posts ref1 and ref2, I thought it was a way to express the coordinate position of a declared mesh.
I ran a simple code with my Jupyter notebook,

from dolfin import * # version: 2019.1.0

lx, ly = 1.0, 1.0
elx, ely = 5, 5
msh = RectangleMesh(Point(0, 0), Point(lx, ly), elx, ely, diagonal="crossed")

x0, x1 = MeshCoordinates(msh)
print("x[0]: ", x0)
print("x[1]: ", x1)


the output was

x0:  f_3[0]
x1:  f_3[1]


The properties for the variables x0, x1 were as follows,

x0: Indexed(Coefficient(FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 0), VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2)), 3), MultiIndex((FixedIndex(0),)))
x1: Indexed(Coefficient(FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 0), VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2)), 3), MultiIndex((FixedIndex(1),)))


but it was hard to visually figure out what values they represented, hence the posting question.

My questions are:
a) What should I understand about the output of this function?
(MeshCoordinate(msh) seems to hold a lot of information.)

b) And in dolfinx, what is the function that does the same thing as MeshCoordinates()?
(Does this do the same thing as the tabulate_dof_coordinates() function? )

MeshCoordinates gives you a symbolic expression for getting the vertices of the current cell, as stated in Bitbucket

It is unclear to me what the use-case of it is, as there are very few use-cases of it.

What do you want to use it for?

To me it feels like something created before ufl.SpatialCoordinate came around.

1 Like

Thanks for the quick reply , @dokken!
The purpose of my exploration of the MeshCoordinates() was to convert the legacy DOLFIN code to dolfinx, which does the formula calculation for subdomains for a given mesh.

The code I was working on was similar to the code(conditional equation form) mentioned below,

and I wanted to convert this type of code to dolfinx.

You mentioned that MeshCoordinates() was a function that used before SpatialCoordinate(), and after reading that post, I googled clue1(Form compilation) and clue2(conditional.py github), and based on that,

# In dolfinx env. Assuming imported the ufl library beforehand
x0, x1 = SpatialCoordinate(mesh)
p_Ex = conditional(ge(0, x0-x1), -2*(exp(x0-x1)-1)/(exp(x0-x1)-1), -(x0-x1))


I was able to get the desired result when I ran the code in the form below.

An additional question I have is,
are MeshCoordinates() and SpatialCoordinate() the same function?
If SpatialCoordinate() came later, it seems like there would be some differences, then what differences have be…?

SpatialCoordinate gives you the physical coordinates of the quadrature points, which I assume is what you are after in your assembly routines.

Like this is giving you the expression

u(x0,x1)=\begin{cases} -2(e^{x0-x1}-1)/(e^{x0-x1}-1)=-2 \text{ if } 0>=x0-x1\\ -(x0-x1) \text{ otherwise } \end{cases}

Is that what you wanted?

Yep! @dokken, it’s similar to the form of equation my working with.
(I’m not sure about =2, though… )

By any chance, is it possible to make a declaration with additional conditions? In dolfinx environment.
(If possible, it would be helpful to have some code to compare to legacy DOLFIN to better understand.)
For example,

u(x0, x1)=\begin{cases} \frac{-2(e^{x0-x1}-1)}{e^{x0-x1}-1} & \text{if 0 $\gt$ $(x0-x1)$} \\ 0 & \text{if 0 $=$ $(x0-x1)$} \\ -(x0-x1) & \text{otherwise} \end{cases}

(I tweaked the equation a bit to add the term.)

As writing replies, I’m sure there are more questions I could ask. I apologize if I’ve bothered you

You can nest conditionals. There are several examples on the forum of this.

Thanks for the answer, it helped a lot!