Skip to content

Add example that illustrates how to use submeshes with DOLFINx-adjoint - #80

Merged
jorgensd merged 15 commits into
mainfrom
dokken/emi
Sep 2, 2026
Merged

Add example that illustrates how to use submeshes with DOLFINx-adjoint#80
jorgensd merged 15 commits into
mainfrom
dokken/emi

Conversation

@jorgensd

@jorgensd jorgensd commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

Bug-fixes/minor improvements

  • Add naming to constant function constuctor (as it becomes a function).
  • Minor fix for none-blocks in pad blocks by parts
  • In assemble_scalar only add dependencies for OverloadedType. Note added in current demo regarding this behavior.

The demo is generated with the help of Claude, using the aforementioned sources as input (the fenics-in-the-wild, dolfinx-adjoint, dolfinx-adjoint-knowledge and scifem repos).
The bug-fixes is my own work, no AI involved.

Things to consider:

In the demo it states:

# This BC value is deliberately a plain `dolfinx.fem.Constant`, not a
# `dolfinx_adjoint.Constant`, unlike the physical parameters above: tracking it (via
# `dolfinx_adjoint.dirichletbc`) breaks the adjoint gradient for this particular
# entity_maps + blocked LinearProblem combination -- confirmed with a Taylor test, whose
# rate drops from the correct ~1.0 to ~-1.4 as soon as the BC value is annotated. Since
# the BC is fixed data, not a control, leaving it untracked is also the right modelling
# choice, not just a workaround; the discrepancy is worth a closer look/report upstream.

which hopefully should be resolved with #83.

…uctor (as it becomes a function). Minor fix for none-blocks in pad blocks by parts
@jorgensd
jorgensd requested a review from finsberg September 1, 2026 15:39
Comment thread demos/emi_membrane_current_control.py Outdated
@jorgensd jorgensd changed the title Submesh support Add example that illustrates how to use submeshes with DOLFINx-adjoint Sep 2, 2026
@jorgensd
jorgensd merged commit bf40ec6 into main Sep 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants