volume_integral.py

back to table · edit · history · where entries came from · files · download

1249 bytes, as of the version from 2026-11-27 09:27 (current). Recorded here, not run.

"""Schlaefli integral from Klein edge lengths; independent of Kellerhals.

Reusable component rerun for the density build. Numerical quadrature is
heuristic. Endpoint logarithm is removed analytically.
"""
import pathlib
import mpmath as mp
DATA={'tetrahedron':(3,3,24,6,6,7),'cube':(3,4,48,12,6,7),
      'octahedron':(4,3,48,12,4,5)}
ROOT=pathlib.Path(__file__).resolve().parent

def independent_volume(cell,p,dps):
    with mp.workdps(dps):
        q,r,M,E,p0,minimum=DATA[cell];a0=mp.pi/p0;a=mp.pi/p;D=a0-a
        clausen=mp.sqrt(3)/72*(mp.zeta(2,mp.mpf(1)/6)+mp.zeta(2,mp.mpf(2)/6)
                     -mp.zeta(2,mp.mpf(4)/6)-mp.zeta(2,mp.mpf(5)/6))
        catalan=(mp.zeta(2,mp.mpf(1)/4)-mp.zeta(2,mp.mpf(3)/4))/16
        anchor={'tetrahedron':clausen,'cube':5*clausen,'octahedron':4*catalan}[cell]
        def regular(s):
            t=a0-s;c=mp.cos(2*t)
            if cell=='octahedron':
                A=1+c;B=2*mp.sin(2*s);ratio=4*mp.sinc(2*s)
            else:
                A=c if cell=='tetrahedron' else mp.mpf(1)
                ratio=4*mp.sin(a0+t)*mp.sinc(s);B=s*ratio
            return mp.log((A+mp.sqrt(A*A-B*B))/ratio)
        integral=(mp.quad(regular,[0,D/2,D])-D*mp.log(D)+D)/2
        return + (anchor+2*E*integral)