How to get array of minimum edge lengths for each cell

12 months ago by
I want to get an array of floats whose length is equal to the number of cells, and gives the minimum edge length of each cell. Does the following give what I want ? Is there a more direct way to get this information ?
mesh = UnitSquareMesh(5,10)
V = FunctionSpace(mesh, 'DG', 0)
v = TestFunction(V)
a = assemble(MinCellEdgeLength(mesh)*v*dx)
b = assemble(v*dx)
h = a.array() / b.array()
print h​
Community: FEniCS Project

1 Answer

12 months ago by
Maybe you can iterate over cells and then find the shortest edges (?). Something like this:

import numpy as np

l = np.zeros(mesh.num_cells())
for c in cells(mesh):
  edges = c.entities(1)
  l[c.index()] = min([Edge(mesh, edges[0]).length(), \
                      Edge(mesh, edges[1]).length(), \
                      Edge(mesh, edges[2]).length()])​
Is this a bit more slick?

l = [min(edge.length() for edge in edges(cell)) for cell in cells(mesh)]

written 12 months ago by Nate  
yes, that looks nice!
written 12 months ago by Hernán Mella  
This is nice. Can you make it into an answer. Thanks.
written 12 months ago by Praveen C  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »