Skip to content

Forward coefficient functions to solveAsync, add varying-coefficient regression tests - #91

Merged
nikoscham merged 2 commits into
FEAScript:feature/spatially-varying-coefficientsfrom
Ed6003:feature/spatially-varying-coefficients
Aug 19, 2026
Merged

Forward coefficient functions to solveAsync, add varying-coefficient regression tests#91
nikoscham merged 2 commits into
FEAScript:feature/spatially-varying-coefficientsfrom
Ed6003:feature/spatially-varying-coefficients

Conversation

@Ed6003

@Ed6003 Ed6003 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Follows up on #82, on the branch you suggested.

solveAsync coefficient forwardingsolve() passes this.coefficientFunctions to assembleHeatConductionMat; solveAsync() did not, so any model with spatially varying coefficients silently fell back to k = 1, Q = 0 on the async path. One-line fix, matching the call site in solve().

Regression tests — closed-form solutions rather than stored reference values, with each case chosen so the finite element solution is exact at the nodes, allowing a tolerance of 1e-10. 1D covers a uniform source against T = x(1-x)/2, the manufactured solution T = x under k = 1+x, Q = -1 for both element orders, the frontal assembler against the matrix assembler, and the solveAsync forwarding above. 2D covers T = x and its rotation T = y.

Mutations tested against the new tests. Each was applied to src/, the suite run, then reverted. Every one is caught, and every one passes the existing HeatConduction1DWall test, which supplies no coefficientFunctions:

Mutation Sites 1D 2D Existing Wall test
(control — unmutated) pass pass pass
Drop the heat source term 4 fail fail pass
Flip the heat source sign 4 fail fail pass
Ignore k, always use 1 4 fail fail pass
Sample k at a fixed x, not the Gauss point 2 fail pass pass
2D: swap x and y 4 pass fail pass
2D: pass x as the y argument 4 pass fail pass
Frontal: stop forwarding coefficients 1 fail pass pass
solveAsync: no forwarding 1 fail pass pass

Two notes, both pre-existing on main and out of scope here:

  • npm test runs node --test tests, which fails on Node 22+ (the path is treated as a file). node --test works — 7 files, 7 pass.
  • This branch is 3 commits behind main (12c053e, 50e8345, c88ed35). No source conflicts; only the committed dist/ bundles collide.

Ed6003 added 2 commits August 18, 2026 13:02
`solve()` passes `this.coefficientFunctions` to `assembleHeatConductionMat`,
but `solveAsync()` called the same assembler with only the mesh and the
boundary conditions. Any model configured with spatially varying
coefficients silently fell back to a uniform conductivity of 1 and a heat
source of 0 when solved through the asynchronous path.

Pass the coefficients at that call site as well, so both paths assemble the
same system.

Refs FEAScript#82
The existing regression tests pass no `coefficientFunctions`, so the
coefficients resolve to a uniform conductivity of 1 and a heat source of 0.
Both are then invisible to the result: multiplying by 1 and adding 0 leaves
the assembled system identical to one that never read them. Nothing in the
suite could distinguish correct coefficient handling from none at all.

These two tests assert closed-form solutions rather than stored reference
values, which for a new feature would only record whatever the code produced
when the test was written. Each case is chosen so the finite element solution
is exact at the nodes, giving a tolerance of 1e-10 instead of 1e-4 and
expected values that never need re-deriving when the mesh or element order
changes.

1D covers a uniform source against T = x(1 - x)/2, whose exact solution lies
outside the finite element space and so pins the quadrature of the source
term; the manufactured solution T = x under k = 1 + x and Q = -1 for both
element orders, which pins the Gauss point as the evaluation point; the
frontal assembler against the matrix assembler; and the coefficient
forwarding in `solveAsync`. 2D covers T = x and its rotation T = y, since the
2D assembler is a separate implementation and the 1D path calls the
coefficients with x alone.

Confirmed to have teeth by mutation: swapping x and y in the 2D assembler
moves both 2D cases from 1e-15 to 1e-1, and dropping the coefficients from
the `solveAsync` call site fails the 1D suite.

Refs FEAScript#82
@nikoscham nikoscham self-assigned this Aug 19, 2026
@nikoscham nikoscham added the enhancement New feature or request label Aug 19, 2026
@nikoscham nikoscham linked an issue Aug 19, 2026 that may be closed by this pull request
@nikoscham nikoscham added this to the 0.3.0 milestone Aug 19, 2026
@nikoscham
nikoscham marked this pull request as ready for review August 19, 2026 09:39
@nikoscham
nikoscham merged commit 6602f6d into FEAScript:feature/spatially-varying-coefficients Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spatially varying heat transfer coefficient and heat source

2 participants