def var_index(ti, vi, ci):
    """The flattened index corresponding to the tet index ti,
    local vertex index vi, and coordinate index ci.
    """
    if not isinstance(ci, range):
        ci = [ ci ]
    return [ ( 12 * ti + 3 * vi + i ) for i in ci ]