Skip to main content

omnibias.fields.weak

0.2.0rc1Release candidatePython >=3.10Apache-2.0

Structured scalar, vector, and tensor fields with derivative caches, calculus operators, and coordinate conventions.

import omnibias.fields.weak
Module contract & mathematical conventions

Weak-form VPINN test functions (theory 02-04, gated).

Import assembly kernels from omnibias.fields.weak.torch or omnibias.fields.weak.jax. Exact integrals only for polynomial coefficients on boxes; the boundary bound is on by default.

Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.

Imports & aliases​

These names share a definition with another public module. Follow a name for its full contract, parameters, and examples.

Import from this moduleCanonical reference
TestFunctionSpaceomnibias.fields.TestFunctionSpace
WeakFormomnibias.fields.WeakForm
boundary_boundomnibias.fields.boundary_bound
exact_momentomnibias.fields.exact_moment
FUNCTION

eval_test​

omnibias.fields.weak.eval_testSource ↗
eval_test(space: TestFunctionSpace, index: int, x: float, *, deriv: int=0) -> float

v^{(deriv)}(x) for test function index.

Parameters

NameType & defaultContract
spacepositional-or-keywordTestFunctionSpaceRequiredSee the operation contract and implementation below.
indexpositional-or-keywordintRequiredSee the operation contract and implementation below.
xpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
derivkeyword-onlyintDefault: 0See the operation contract and implementation below.
Returnsfloat
Executed regression · path recording quadrature for callable source

Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_path_recording_quadrature_for_callable_source() -> None:
    torch.set_default_dtype(torch.float64)
    space = _space()
    op = WeakForm(diffusion=(1.0,))
    quad = gauss_legendre(((0.0, 1.0),), 8)

    def source(x: torch.Tensor) -> torch.Tensor:
        return torch.sin(math.pi * x.reshape(-1)).reshape(x.shape)

    _res, terms = weak_residual(
        (0.0, 1.0, -1.0), space, operator=op, source=source, quadrature=quad
    )
    load_paths = {t.path for t in terms if t.name.startswith("load")}
    stiff_paths = {t.path for t in terms if t.name.startswith("stiffness")}
    assert "quadrature" in load_paths
    assert "exact" in stiff_paths
python -m pytest "packages/omnibias-fields/tests/test_weak.py::test_path_recording_quadrature_for_callable_source" -q
Regression example · g1 exact moment vs gauss

This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.

def test_g1_exact_moment_vs_gauss() -> None:
    space = TestFunctionSpace(
        BankSpec.uniform(0.3, 0.7, 3, scales=(2.0,)),
        orders=(2,),
        base="tanh",
        window=(0.0, 1.0),
    )
    exact = exact_moment(space, 0, 0)
    hi = gauss_legendre(((0.0, 1.0),), 48)
    lo = gauss_legendre(((0.0, 1.0),), 2)
    v_hi = np.array([eval_test(space, 0, float(x), deriv=0) for x in hi.nodes[:, 0]])
    v_lo = np.array([eval_test(space, 0, float(x), deriv=0) for x in lo.nodes[:, 0]])
    g_hi = float(np.dot(hi.weights, v_hi))
    g_lo = float(np.dot(lo.weights, v_lo))
    rel = abs(exact - g_hi) / max(abs(g_hi), 1e-16)
    assert rel <= 1e-13
    assert abs(g_lo - exact) > abs(g_hi - exact)
python -m pytest packages/omnibias-fields/tests/test_weak.py -k test_g1_exact_moment_vs_gauss -q
Read the implementation
def eval_test(space: TestFunctionSpace, index: int, x: float, *, deriv: int = 0) -> float:
    """``v^{(deriv)}(x)`` for test function ``index``."""
    n = space.order_at(index) + int(deriv)
    alpha = space.scale_at(index)
    mu = space.offset_at(index)
    z = alpha * (x - mu)
    return (alpha ** deriv) * _sigma_n(space.base, z, n)
FUNCTION

poly_eval​

omnibias.fields.weak.poly_evalSource ↗
poly_eval(coeffs: tuple[float, ...], x: float) -> float

The module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.

Parameters

NameType & defaultContract
coeffspositional-or-keywordtuple[float, ...]RequiredSee the operation contract and implementation below.
xpositional-or-keywordfloatRequiredSee the operation contract and implementation below.
Returnsfloat
Read the implementation
def poly_eval(coeffs: tuple[float, ...], x: float) -> float:
    acc = 0.0
    for c in reversed(coeffs):
        acc = acc * x + c
    return acc