Skip to content

Modernize Elmer capacitance extraction - #781

Merged
nikosavola merged 16 commits into
mainfrom
elmer-capacitance
Sep 28, 2026
Merged

nikosavola merged 16 commits into
mainfrom
elmer-capacitance

Conversation

@nikosavola

@nikosavola nikosavola commented Sep 23, 2026 •

Copy link
Copy Markdown
Member
  • Modernize Elmer capacitance meshing, material handling, and solver output; reject terminal contacts with grounded conductors.
  • Return Maxwell capacitance matrices from both Elmer and Palace.
  • Add an Elmer extra and link CSC's Elmer Singularity recipe for container builds.
  • Execute the Elmer notebook in docs CI and parallelize independent setup steps.
  • Add focused Elmer and Palace tests; align xarray with tidy3d and refresh uv.lock.

@sourcery-ai

sourcery-ai Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Modernizes Elmer capacitance extraction around current meshwell and Elmer interfaces, including terminal-aware meshing, validated SIF/solver execution, Maxwell matrix results, and explicit layer-stack requirements, while adding packaging, CI, documentation, tests, and container support.

Sequence diagram for Elmer Maxwell capacitance extraction

sequenceDiagram
    participant Caller
    participant ElmerAPI as run_capacitive_simulation_elmer
    participant Meshwell
    participant ElmerGrid
    participant ElmerSolver
    participant Results

    Caller->>ElmerAPI: run_capacitive_simulation_elmer
    ElmerAPI->>ElmerAPI: _validate_solver_inputs
    ElmerAPI->>Meshwell: get_meshwell_prisms
    Meshwell-->>ElmerAPI: terminal-aware mesh
    ElmerAPI->>ElmerAPI: _sanitize_mesh_physical_names
    ElmerAPI->>ElmerAPI: _split_mesh_terminals
    ElmerAPI->>ElmerAPI: _generate_sif
    ElmerAPI->>ElmerGrid: _elmergrid
    ElmerGrid-->>ElmerAPI: mesh.names
    ElmerAPI->>ElmerSolver: _elmersolver
    ElmerSolver-->>ElmerAPI: lumped capacitance matrix
    ElmerAPI->>Results: _lumped_to_maxwell
    Results-->>Caller: ElectrostaticResults with Maxwell matrix
Loading

Flow diagram for lumped-to-Maxwell capacitance conversion

flowchart LR
    A[Elmer lumped capacitance matrix] --> B[_lumped_to_maxwell]
    B --> C[Negate off-diagonal terms]
    C --> D[Set diagonal to row sums]
    D --> E[_pair_capacitance_matrix]
    E --> F[Port-named Maxwell capacitance matrix]
Loading

File-Level Changes

Change Details Files
Reworked Elmer meshing, physical-group interpretation, material assignment, SIF generation, and solver execution for current meshwell/Elmer behavior.
  • Require an explicit layer stack and named background volume, with validation for materials, terminals, mesh groups, solver parameters, and unsupported mesh options.
  • Split and merge terminal geometry per component port, sanitize physical-group identifiers, resolve Elmer body/boundary indices, and generate updated SIF inputs.
  • Reuse supplied meshes, manage temporary and persistent result paths, and propagate missing executable, MPI, and nonzero solver failures.
gplugins/elmer/get_capacitance.py
gplugins/elmer/electrostatic.sif.j2
gplugins/elmer/tests/test_elmer.py
Changed Elmer result handling to expose a Maxwell capacitance matrix instead of Elmer's lumped matrix representation.
  • Convert lumped coefficients to charge-versus-voltage Maxwell coefficients with negative off-diagonals and row-sum diagonals.
  • Map matrix entries to component port-name pairs and validate the returned matrix shape and result filename.
gplugins/elmer/get_capacitance.py
gplugins/elmer/tests/test_elmer.py
Extended capacitance dispatch and packaging to support the modernized Elmer workflow.
  • Forward an optional layer stack through the shared capacitance wrapper while requiring it for Elmer.
  • Correct simulator aliases and add the Elmer optional dependency group.
gplugins/common/utils/get_capacitance.py
gplugins/common/utils/tests/test_get_capacitance.py
pyproject.toml
uv.lock
Integrated Elmer into automated testing, documentation execution, and containerized development.
  • Add Elmer to the plugin test matrix and execute the capacitance notebook as a required documentation build step.
  • Install Elmer from the CSC Ubuntu package in docs CI and add a Rocky 9.6 x86-64-v3 Apptainer recipe.
.github/workflows/test_code.yml
.github/workflows/pages.yml
Makefile
gplugins/elmer/containers/elmer-rocky9.def
notebooks/elmer_01_electrostatic.ipynb
Updated project metadata and dependency constraints for compatibility with the supported ecosystem.
  • Align xarray's version range with tidy3d and modernize authorship and license declarations.
pyproject.toml
uv.lock

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@nikosavola nikosavola self-assigned this Sep 23, 2026
@nikosavola nikosavola added enhancement New feature or request python Pull requests that update Python code simulations simulation plugins labels Sep 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical correctness issues remain in material and background-domain handling.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity

Open (2)
What changed in this PR

Modernizes Elmer capacitance extraction for current meshwell and Elmer workflows, including terminal-aware meshing and Maxwell capacitance matrices.

Changes:

  • Adds Elmer dependencies and a Rocky Linux container recipe.
  • Reworks mesh, SIF generation, validation, and solver handling.
  • Expands tests for matrix conversion and solver behavior.
File Description
pyproject.toml Adds the Elmer optional dependency extra.
gplugins/​elmer/​tests/​test_elmer.py Adds validation, failure, matrix, and smoke tests.
gplugins/​elmer/​get_capacitance.py Implements terminal-aware meshing, SIF generation, solver execution, and matrix conversion.
gplugins/​elmer/​electrostatic.sif.j2 Updates Elmer electrostatic configuration.
gplugins/​elmer/​containers/​elmer-rocky9.def Defines the Rocky Linux Elmer container build.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread gplugins/elmer/get_capacitance.py Outdated
Comment thread gplugins/elmer/get_capacitance.py

Copilot AI commented Sep 23, 2026

Copy link
Copy Markdown

One or more custom setup steps configured for this repository failed during this Copilot code review run:

Run {

Setup steps run before each review. If the review above is missing context, or no review was posted at all, the failing step above may be the cause. See the workflow run for failure details, fix your setup steps configuration, and re-request a review.

Note

You can configure setup steps for Copilot code review separately from Copilot cloud agent with a copilot-code-review.yml file. Read the docs for details.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical correctness and container-build issues, plus missing automated test coverage, remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 5 High severity · 2 Medium severity

Open (7)
Resolved since last review (2)

Comment thread gplugins/elmer/containers/elmer-rocky9.def Outdated
Comment thread gplugins/elmer/get_capacitance.py
Comment thread gplugins/elmer/get_capacitance.py Outdated
Comment thread gplugins/elmer/get_capacitance.py
Comment thread gplugins/elmer/get_capacitance.py
Comment thread gplugins/elmer/get_capacitance.py
Comment thread gplugins/elmer/tests/test_elmer.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved findings include incorrect SIF body mapping, a broken default wrapper call, missing mpiexec validation, and an incomplete test skip condition.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (7)

Comment thread gplugins/elmer/get_capacitance.py
Comment thread gplugins/elmer/get_capacitance.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Address non-finite result validation and make the partial-Elmer-installation test robust.

Review effort: Lite
Findings: None

Resolved since last review (2)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Reject non-finite values in Maxwell matrix results

gplugins/​elmer/​get_capacitance.py:480

The new result path validates only the matrix shape. If Elmer exits successfully but writes NaN/Inf (for example after an invalid or non-converged solve), _lumped_to_maxwell propagates those values and ElectrostaticResults returns them; the smoke test itself treats finiteness as part of the contract. Reject non-finite entries before returning the Maxwell matrix so callers cannot consume an invalid result.

Medium severity Handle partial Elmer installations in ElmerGrid test

gplugins/​elmer/​tests/​test_elmer.py:400

elmer_installed is true only when both ElmerGrid and ElmerSolver are present, but this test assumes ElmerGrid itself is absent. On a host with ElmerGrid installed and ElmerSolver missing, _elmergrid runs and the pytest.raises(..., match="ElmerGrid") assertion fails before testing layer-stack immutability. Force shutil.which to return None in this test, or skip based specifically on ElmerGrid, so partial installations do not make the suite fail.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Fix the invalid docs workflow structure and resolve the Elmer port-name parsing issue.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)

Comment thread .github/workflows/pages.yml
@nikosavola
nikosavola marked this pull request as ready for review September 23, 2026 21:54

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @nikosavola, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@nikosavola
nikosavola marked this pull request as draft September 23, 2026 22:09
auto-merge was automatically disabled September 23, 2026 22:09

Pull request was converted to draft

@nikosavola
nikosavola marked this pull request as ready for review September 23, 2026 22:26

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @nikosavola, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 10 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@nikosavola
nikosavola marked this pull request as draft September 23, 2026 22:28
auto-merge was automatically disabled September 23, 2026 22:28

Pull request was converted to draft

@nikosavola
nikosavola marked this pull request as ready for review September 23, 2026 23:11

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @nikosavola, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 9 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@nikosavola
nikosavola marked this pull request as draft September 24, 2026 20:36
auto-merge was automatically disabled September 24, 2026 20:36

Pull request was converted to draft

@nikosavola
nikosavola marked this pull request as ready for review September 25, 2026 12:37

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @nikosavola, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 20 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@nikosavola
nikosavola disabled auto-merge September 28, 2026 07:57
@nikosavola
nikosavola merged commit 0cfc6e6 into main Sep 28, 2026
29 checks passed
@nikosavola
nikosavola deleted the elmer-capacitance branch September 28, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request python Pull requests that update Python code simulations simulation plugins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants