def affine_weights(dim):
    """Compute coefficents for mapping from reference to physical element"""
    if dim == 1:
        return lambda X: (1.0 - X[0], X[0])
    elif dim == 2:
        return lambda X: (1.0 - X[0] - X[1], X[0], X[1])
    elif dim == 3:
        return lambda X: (1.0 - X[0] - X[1] - X[2], X[0], X[1], X[2])
