Skip to content

Pydantic-ify DiffusionConfig and GridGeometry #53

@jc-macdonald

Description

@jc-macdonald

Summary

Convert DiffusionConfig (L84) and GridGeometry (L76) in matrix_ops.py from frozen dataclasses to Pydantic BaseModel.

Motivation

  • DiffusionConfigbc field accepts any string but only "neumann" and "absorbing" are valid. Validation currently happens downstream in build_laplacian_tridiag(). Pydantic Literal["neumann", "absorbing"] catches invalid values at construction.
  • GridGeometryn and dx have implicit constraints (n > 0, dx > 0) that are never checked. Pydantic Field(gt=0) adds guardrails.
  • coeff in DiffusionConfig should likely be ge=0 (non-negative diffusion coefficient).

Scope

  • Convert 2 dataclasses → Pydantic BaseModel with frozen=True
  • Add field constraints and bc as Literal type
  • Remove downstream bc validation in build_laplacian_tridiag()
  • Update tests

Constraints

  • Must pass ruff check --preview and mypy --strict

Related

Metadata

Metadata

Assignees

Labels

architectureStructural or design-level changesrefactorCode reorganization without behavior change

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions