omnibias.fields.weak
Structured scalar, vector, and tensor fields with derivative caches, calculus operators, and coordinate conventions.
import omnibias.fields.weakModule 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 module | Canonical reference |
|---|---|
TestFunctionSpace | omnibias.fields.TestFunctionSpace |
WeakForm | omnibias.fields.WeakForm |
boundary_bound | omnibias.fields.boundary_bound |
exact_moment | omnibias.fields.exact_moment |
eval_test
omnibias.fields.weak.eval_testSource ↗eval_test(space: TestFunctionSpace, index: int, x: float, *, deriv: int=0) -> floatv^{(deriv)}(x) for test function index.
Parameters
| Name | Type & default | Contract |
|---|---|---|
spacepositional-or-keyword | TestFunctionSpaceRequired | See the operation contract and implementation below. |
indexpositional-or-keyword | intRequired | See the operation contract and implementation below. |
xpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
derivkeyword-only | intDefault: 0 | See the operation contract and implementation below. |
floatExecuted 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_pathspython -m pytest "packages/omnibias-fields/tests/test_weak.py::test_path_recording_quadrature_for_callable_source" -qRegression 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 -qRead 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)poly_eval
omnibias.fields.weak.poly_evalSource ↗poly_eval(coeffs: tuple[float, ...], x: float) -> floatThe module contract describes the context for this operation. Its signature, explicit validation, return expressions, and implementation are recorded below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
coeffspositional-or-keyword | tuple[float, ...]Required | See the operation contract and implementation below. |
xpositional-or-keyword | floatRequired | See the operation contract and implementation below. |
floatRead 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