Possible bug: volume quality measure for pyramid element
Dear gmsh team,
when using the method gmsh.model.mesh.getElementQualities()
i ran into a possible bug. The volume calculated by gmsh for an equilateral pyramid is 1.33 times as large as i calculated by hand. I prepared a minimal example to demonstrate the problem. If i just messed up the calculation myself i also look forward to being corrected :-)
I am using gmsh 4.12.1.
import numpy as np
import gmsh
gmsh.initialize()
a = 1. # pyramid edge length
h = a/np.sqrt(2) # pyramid height
# node tags and coordinates for equilateral 5-node pyramid
node_tags = [1,2,3,4,5]
node_coords = np.array([[-a/2, -a/2, 0],
[ a/2, -a/2, 0],
[ a/2, a/2, 0],
[-a/2, a/2, 0],
[ 0, 0, h]])
# add nodes and 1 pyramid element to a discrete volume
vtag = gmsh.model.addDiscreteEntity(3)
gmsh.model.mesh.addNodes(3, vtag, node_tags, node_coords.flatten())
gmsh.model.mesh.addElementsByType(vtag, 7, [1], node_tags)
# analytical expression for the pyramid volume:
# pyramid base area A=a^2, pyramid height H=a/sqrt(2), pyramid volume V=A*H/3
expected_volume = a**3/3./np.sqrt(2)
# get the min and max edge length to make sure the pyramid really is equilateral
min_edge = gmsh.model.mesh.getElementQualities([1], qualityName="minEdge")[0]
max_edge = gmsh.model.mesh.getElementQualities([1], qualityName="maxEdge")[0]
# get the volume
vol = gmsh.model.mesh.getElementQualities([1], qualityName="volume")[0]
print(f"Min, max edge length: {min_edge}, {max_edge}")
print(f"Volume calculated, expected: {vol}, {expected_volume}")
print(f"Calculated volume is too large by factor {vol/expected_volume}")
gmsh.finalize()