Volume of HexahedronElement with non-coplanar faces
Interestingly enough, if you convert the mesh to second order, the correct result comes up. So I made a mess in the 1st order symbolic code.
m2 = MeshOrderAlteration[mesh, 2];
m2["MeshElementMeasure"]
{{0.875`}}
This is fixed in version 12.0
Needs["NDSolve`FEM`"]
mesh = ToElementMesh[
"Coordinates" -> {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}, {0,
0, 0.5}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1}},
"MeshElements" -> {HexahedronElement[{{1, 2, 3, 4, 5, 6, 7,
8}}]}];
Total@Flatten@mesh["MeshElementMeasure"]
0.875`
The volume integral over the standard cube (to my surpise, it's Cuboid[{-1, -1, -1}, {1, 1, 1}]
) can be computed analytically like this:
pp = Table[Compile`GetElement[p, i, j], {i, 1, 8}, {j, 1, 3}];
f = {r, s, t} \[Function] Evaluate[
ElementShapeFunction[HexahedronElement, 1][r, s, t].pp
];
det = Det[D[f[r, s, t], {{r, s, t}, 1}]];
coeffrules = CoefficientRules[det, {r, s, t}];
vol = Values[coeffrules].Table[
Integrate[
FromCoefficientRules[{c -> 1}, {r, s, t}],
{r, -1, 1}, {s, -1, 1}, {t, -1, 1}
],
{c, Keys[coeffrules]}];
cvol = With[{code = vol}, Compile[{{p, _Real, 2}},
code,
CompilationTarget -> "C",
RuntimeAttributes -> {Listable},
Parallelization -> True
]];
Now let's try it:
hexdata = Partition[
mesh["Coordinates"][[Flatten[mesh["MeshElements"][[1, 1]]]]],
8
];
cvol[hexdata]
{0.875}