Access edge lengths and face areas

Hello!

I’ve been trying to build a code that would tell me, for each 3d element, the area of all of its faces and the length of all of its edges.

I know that the following can be used to compute the volume of a given element and have it saved on a list:

hvec = Integrate(1, mesh, VOL, element_wise=True)

But my question is, can I do something like that but that stores a specific quantity that depends on the edges/faces. For instace:

hmin_vec = # A vector that for each element saves it shortest edge

# I would make something like:

# hmin_vec = []
# for el in mesh.Elements:
#     hmin_vec.append(min(el.edges_length))

I’ve tried using the following code to access the edge lengths, but I haven’t been able to get the vertices of a given edge.

from ngsolve import *

geo = CSGeometry()
geo.Add(OrthoBrick(Pnt(0,0,0), Pnt(1,1,1)))
nmesh = geo.GenerateMesh(maxh=1)
mesh = Mesh(nmesh)

print(f"The mesh has:\n - {mesh.ne} elements,\n - {mesh.nface} faces,\n - {mesh.nedge} edges and,\n - {mesh.nv} vertices.")

hmin_vec = []
for el in mesh.Elements(VOL):
    # Find edges of each element
    el_edges = el.edges
    print(el_edges)

    # Find vertices of each edge
    for edge in el_edges: 
        pass

    # Compute length by l2 norm

I’m currently stuck since the for edge in el_edges cycle will cycle through NodeId objects and I can’t find a way to use them.

I’m also interested on the area of faces, but I think that issue is more complicated since I don’t want an aggregated quantity. In particular, I’m interested in the following:

If element K has faces F_{1},\dots,F_{4}, then I want to define a global function h_{\text{area}} as:

(h_{\text{area}}|_{K})|_{F} = |F|/|K|

i.e., on each element is defined only on each face as the area of its face. Its important (in this case) to have it defined element-wise since the argument depends on the element that’s being seen.

I hope you can help me with this and thanks beforehand on any insight you can give me.

Joaquín.

you can ask an edge for its vertices and a vertex for its point coordinates like:

for el in mesh.Elements(VOL):
  for eindex in el.edges:
    for vindex in mesh[eindex]:
      print(mesh[vindex].point)

Best