MeshEditor(): editor.open error

Hello everyone.

I’m trying to solve a fluid dynamic problem. For benchmark, I want to compute the difference of pressure in points p(0.15,0.2) - p(0.25,0.2).

I’m using a rectangular channel and a specific number of cells, i.g.:

domain = Rectangle(Point(0, 0), Point(2.2, 0.41))
n_cells = 44
mesh = generate_mesh(domain, n_cells)

The problem is that in some refinement cases I don’t have a specific vertex in these coordinates.

To solve that, I’m trying to use MeshEditor() to add those specific vertexes.

editor = MeshEditor()
gdim = mesh.geometry().dim()
tdim = mesh.topology().dim()
editor.open(mesh, tdim, gdim)

But when I use the editor.open I get the following error:

TypeError: open(): incompatible function arguments. The following argument types are supported:
1. (self: dolfin.cpp.mesh.MeshEditor, mesh: dolfin.cpp.mesh.Mesh, type: str, tdim: int, gdim: int, degree: int=1) → None

Invoked with: <dolfin.cpp.mesh.MeshEditor object at 0x7fc8ee0f0f80>, <dolfin.cpp.mesh.Mesh object at 0x7fc8edac3f10>, 2, 2

Does anyone have an idea how can I solve this problem? It is not necessary using MeshEditor(), I just want help to compute those values in a specific coordinate

Thank you and have a nice day

I am not sure if this is what you are looking for but I guess you want to find the difference of the values of your unknown (Pressure value in your case) in 2 specific coordinate. If I got it right, you can simply do it by :

#Lets say u is your unknown pressure
#(x_coordinate1 , y_coordinate1) and (x_coordinate2 , y_coordinate2) are 2 arbitrary coordinates
u(x_coordinate1 , y_coordinate1) - u(x_coordinate2 , y_coordinate2)

Look at this example (Poisson Demo)

from dolfin import *

# Create mesh and define function space
mesh = UnitSquareMesh(5, 5)
V = FunctionSpace(mesh, "Lagrange", 1)

# Define Dirichlet boundary (x = 0 or x = 1)
def boundary(x):
    return x[0] < DOLFIN_EPS or x[0] > 1.0 - DOLFIN_EPS

# Define boundary condition
u0 = Constant(0.0)
bc = DirichletBC(V, u0, boundary)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)",degree=1)
g = Expression("sin(5*x[0])",degree=1)
a = inner(grad(u), grad(v))*dx
L = f*v*dx + g*v*ds

# Compute solution
u = Function(V)
solve(a == L, u, bc)

# Save solution in VTK format
file = File("poisson.pvd")
file << u
#Difference of u in two arbitrary coordinates
print ( u(0.31,0.78) - u(0.47,0.52) )
1 Like

Thanks Leo.

However, for more complex geometry, depending how refined is my mesh, I don’t have a vertex in that exactly coordinate, so I’m trying to add a vertex if don’t already exist one.

I found this MeshEditor() function, but I’m not been able to use.

Hi Evandro
You want to calculate your unknown in a certain coordinate. Am I right or I got you wrong? If yes, you do not need to have a vertex at that certain coordinate to be able to extract the unknown value at that point. For example in the example that I provided above I do not have a vertex at the coordinates (0.31,0.78) or (0.47,0.52) but it returns the value of the unknown (u) at those coordinates.

1 Like

base) hemanth@CMS:~/Documents/tension_fenics$ python3 Tension.py
Traceback (most recent call last):
File “Tension.py”, line 19, in
editor.open(mesh, 2, 2)
TypeError: open(): incompatible function arguments. The following argument types are supported:
1. (self: dolfin.cpp.mesh.MeshEditor, mesh: dolfin.cpp.mesh.Mesh, type: str, tdim: int, gdim: int, degree: int = 1) -> None

Invoked with: <dolfin.cpp.mesh.MeshEditor object at 0x7fce85d02e30>, <dolfin.cpp.mesh.Mesh object at 0x7fce9b1c61d0>, 2, 2

i am getting above mentioned error for mesh editor opition

Hi,
I am trying to use dolfin MeshEditor function to edit my mesh but I am the same error. Anyone can tell me how to fix it?

Hi everyone,

I hope this is still useful. The problem you are having with the .open() function is due to the arguments you are passing to it.
As described in the error message, you need to pass the following arguments to open():
(mesh object, type, tdim, gdim, degree).
You can skip the degree argument as I believe it is set by default to 1.
The ‘type’ argument pertains to the type of cell you are using, which also depends on the dimensions of your mesh. In 1-D, it will be ‘interval’, in 2D likely ‘triangle’ , in 3D probably ‘tetrahedron’ and so on.
If you add that argument, as a string, it should work.
For venkat201, you would have to rewrite:
editor.open(mesh, ‘cell_type’, 2, 2)
where ‘cell_type’ will be one of the element types I described above, depending on the dimensions of your mesh.
Hope this helps!