Skip to content

Add Ferrite.jl code examples - #574

Merged
mscroggs merged 1 commit into
DefElement:mainfrom
fredrikekre:fe/ferrite
Aug 6, 2026
Merged

Add Ferrite.jl code examples#574
mscroggs merged 1 commit into
DefElement:mainfrom
fredrikekre:fe/ferrite

Conversation

@fredrikekre

Copy link
Copy Markdown
Contributor

Add Ferrite.jl (https://github.com/Ferrite-FEM/Ferrite.jl) to the list of implementations, with Julia code snippets for creating each supported interpolation.

New implementation class (defelement/implementations/ferrite.py):

  • Snippets construct interpolations as Name{RefShape, order}(), with DefElement cell names mapped to Ferrite reference shapes (e.g. interval -> RefLine). Vectorized interpolations use the ^vdim syntax via a vdim parameter in the .def files.
  • Since Ferrite is not on PyPI, version() resolves the latest release from the Versions.toml registry file of Julia's General registry.

Julia language support:

  • New Julia entry in defelement/languages.py. webtools has no Julia highlighter and the snippets are short, so a minimal local formatter highlights comments only (same color webtools uses).
  • Use "#" as the comment prefix for Julia example headers in defelement/implementations/core.py.

Elements covered (all interpolations in Ferrite v1.6.0), with DEGREES restrictions matching the orders implemented in Ferrite:

  • Lagrange and discontinuous Lagrange (equispaced variant) on all seven reference cells
  • Crouzeix-Raviart (CrouzeixRaviart on simplices, RannacherTurek on quadrilateral/hexahedron)
  • bubble enriched Lagrange (triangle)
  • serendipity (Serendipity, degree 2 on quadrilateral/hexahedron)
  • Raviart-Thomas and Nedelec first kind (Lagrange variant, with DEGREEMAP=k+1 since Ferrite's lowest order is 1 where DefElement's degree is 0)
  • Brezzi-Douglas-Marini (Lagrange variant, triangle degree 1)
  • vector Lagrange, vector Q and vector bubble enriched Lagrange via VectorizedInterpolation (ip^vdim)

Note on serendipity: Ferrite uses point evaluations at edge midpoints (classical Q8/Q20) where DefElement defines the edge DOFs as integral moments, giving a different basis for the same space. This is flagged with an implementation note on the element page.

Generated by 🤖 and reviewed by me.

Add Ferrite.jl (https://github.com/Ferrite-FEM/Ferrite.jl) to the list of
implementations, with Julia code snippets for creating each supported
interpolation.

New implementation class (defelement/implementations/ferrite.py):
 - Snippets construct interpolations as `Name{RefShape, order}()`, with
   DefElement cell names mapped to Ferrite reference shapes (e.g.
   interval -> RefLine). Vectorized interpolations use the `^vdim` syntax
   via a `vdim` parameter in the .def files.
 - Since Ferrite is not on PyPI, version() resolves the latest release
   from the Versions.toml registry file of Julia's General registry.

Julia language support:
 - New Julia entry in defelement/languages.py. webtools has no Julia
   highlighter and the snippets are short, so a minimal local formatter
   highlights comments only (same color webtools uses).
 - Use "#" as the comment prefix for Julia example headers in
   defelement/implementations/core.py.

Elements covered (all interpolations in Ferrite v1.6.0), with DEGREES
restrictions matching the orders implemented in Ferrite:
 - Lagrange and discontinuous Lagrange (equispaced variant) on all seven
   reference cells
 - Crouzeix-Raviart (CrouzeixRaviart on simplices, RannacherTurek on
   quadrilateral/hexahedron)
 - bubble enriched Lagrange (triangle)
 - serendipity (Serendipity, degree 2 on quadrilateral/hexahedron)
 - Raviart-Thomas and Nedelec first kind (Lagrange variant, with
   DEGREEMAP=k+1 since Ferrite's lowest order is 1 where DefElement's
   degree is 0)
 - Brezzi-Douglas-Marini (Lagrange variant, triangle degree 1)
 - vector Lagrange, vector Q and vector bubble enriched Lagrange via
   VectorizedInterpolation (`ip^vdim`)

Note on serendipity: Ferrite uses point evaluations at edge midpoints
(classical Q8/Q20) where DefElement defines the edge DOFs as integral
moments, giving a different basis for the same space. This is flagged
with an implementation note on the element page.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread defelement/languages.py
Comment on lines +11 to +30
def julia_highlight(code: str) -> str:
"""Highlight comments in a Julia snippet and convert it to HTML.

webtools does not provide a Julia highlighter. The snippets are short enough that
keyword highlighting adds little, so only comments are highlighted, using the same
color that webtools uses.

Args:
code: Julia snippet

Returns:
Snippet with comments highlighted
"""
out = []
for line in code.replace(" ", "&nbsp;").split("\n"):
if "#" in line:
line, comment = line.split("#", 1)
line += f"<span style='color:#FF8800'>#{comment}</span>"
out.append(line)
return "<br />".join(out)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should at some point be moved to webtools, but that can be done after this is merged. Issue for this: DefElement/website-build-tools#41

@mscroggs
mscroggs merged commit 99bd810 into DefElement:main Aug 6, 2026
7 checks passed
@fredrikekre
fredrikekre deleted the fe/ferrite branch August 6, 2026 17:29
@fredrikekre

Copy link
Copy Markdown
Contributor Author

Thanks! Looks like CI choked on main (GitHub issue most likely) so this never deployed (https://github.com/DefElement/DefElement/actions/runs/31116625753/job/92668950854).

@mscroggs

mscroggs commented Aug 7, 2026

Copy link
Copy Markdown
Member

GitHub issue most likely

Definitely a GitHub issue as different jobs failed on my first rerun. Hopefully enough time has passed now that the current rerun will succeed

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