Average Node Distance

Hi, is there a quick way to check the average distance between nodes in the mesh? Thanks, Ondrej.

Hi Ondrej,

You can use the edge quality metric. Issue the command

quality edge all length global

and it will print out results showing the average edge length, the standard deviation and the minimum and maximum edge lengths.

 Edge quality, 1204 elements:
------------------------------------
   Function Name    Average      Std Dev      Minimum   (id)    Maximum   (id) 
 ---------------    ---------    ---------    --------------    ---------------
          Length    3.820e-01    3.334e-02    2.232e-01 (48)    5.151e-01 (175)
------------------------------------

This command is accessible in the Command Panels from Mesh/Edge/Quality/Quality Metrics.

Thanks,
Karl

I did just realize that there is a caveat to this. By default, Cubit uses a reduced data structure to store elements. Edge elements only exist on the surface for visualization surfaces. If you are doing a 3D mesh, this will not include any mesh edges internal to the volume.

There is a work-around for hex meshes. Prior to meshing the volumes, you can issue the command

set fullhex on

This will create a complete data structure for the hexahedral element including the edges. This will use significantly more memory and degrade the overall performance of Cubit. I would not recommend doing this for a large model.

There is no corresponding method for tetrahedral elements. At that point we would have to resort to python code to extract all the edges and edge lengths.

Thanks,
Karl

Thank you, Karl, for the explanation. I actually intended to use python code, but I couldn’t figure out how. Is it somehow possible with “cubit.parse_cubit_list”?

Hi Ondrej,

Since there are no internal edges, you will have to get the elements and the element connectivity. Then calculate the distance between each connected node pair in the element.

You could do something like this. This is untested code off the top of my head. It does give a reasonable value. Use it for what it is. It does point to some useful methods.

Karl

import numpy as np

average = 0
tet_edges = { (0,1), (1,2), (2,0), (0,3), (1,3), (2,3) }
tet_list = cubit.parse_cubit_list("tet", "all")
for tet_id in tet_list:
    conn = cubit.get_connectivity("tet", tet_id)
    edge_lengths = 0
    for edge in tet_edges:
        coord1 = np.array(cubit.get_nodal_coordinates(conn[edge[0]]))
        coord2 = np.array(cubit.get_nodal_coordinates(conn[edge[1]]))
        edge_lengths +=  np.linalg.norm(coord1 - coord2)
    average += edge_lengths/6.0     
average = average / len(tet_list)
print(f"Average edge length: {average}")

Thank you, Karl. I’ll play with this.