Skip to content

Refactor hyperelasticity demo into reusable functions - #4683

Open
wangguanyao4-netizen wants to merge 1 commit into
FEniCS:mainfrom
wangguanyao4-netizen:work/restructure-demos
Open

wangguanyao4-netizen wants to merge 1 commit into
FEniCS:mainfrom
wangguanyao4-netizen:work/restructure-demos

Conversation

@wangguanyao4-netizen

@wangguanyao4-netizen wangguanyao4-netizen commented Oct 25, 2026 •

Copy link
Copy Markdown

This refactors the C++ hyperelasticity demo into a small set of reusable functions while preserving the numerical formulation and output.

Changes

  • isolate mesh construction;
  • isolate finite-element space construction;
  • isolate the prescribed rotation field;
  • isolate the two Dirichlet boundary conditions; and
  • keep main responsible only for PETSc/logging lifecycle while solve_hyperelasticity owns the simulation.

The generated UFL forms and solver callbacks are unchanged. The resulting layout gives users a concrete pattern for separating setup, boundary data, solving, and output in a larger nonlinear mechanics program.

Validation

  • clang-format --dry-run --Werror cpp/demo/hyperelasticity/main.cpp
  • git diff --check

A full demo build/run was not run because this environment does not have CMake or the PETSc/DOLFINx build dependencies installed.

@schnellerhase schnellerhase 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.

Check your git config and rewrite the commit.

Comment thread cpp/demo/hyperelasticity/main.cpp Resolved
Comment thread cpp/demo/hyperelasticity/main.cpp Resolved
Comment thread cpp/demo/hyperelasticity/main.cpp Resolved

@schnellerhase schnellerhase 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.

Thanks, this reads way better.

This does not resolve #3076 (please remove the autoclose statement from the PR description).

If approved by others this could be extended in a similar manner to other demos (in future PRs), i.e. breaking out mesh generation, definition of functions and/or BCs, and post processing.

@schnellerhase schnellerhase added the demo New demo or demo enhancements/improvements label Nov 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

demo New demo or demo enhancements/improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants