The wave equation — 2A: conservative anisotropic membrane
Conservative 2D anisotropic membrane with mixed boundary ports.
2D mixed-boundary anisotropic membrane, energy variables q=grad w, p=rho*w_t, coenergy e_q=T q and e_p=p/rho. This preserves the original model’s four boundary ports and its actual GetFEM GWFL Hamiltonian 0.5*q.T.q, where T is the full tensor parameter.
Physical outward-normal traction: u_N=n.e_q at bottom/right/top; observation y_N=e_p. Left side prescribes u_D=e_p (velocity) and observes y_D=n.e_q (traction). The pH energy balance is
H(t)-H(0) = integral (u_N*y_N + u_D*y_D) dt.
The negative flow-side algebraic rows impose Y_N=e_p and U_D=e_p: this is the same physical sign convention as qualified wave_1d.py. The physical sign of the measured work is audited independently against the original GetFEM Hamiltonian; no success is inferred solely from these formulae.
This tutorial starts from EXACTLY zero, compatible with zero initial Dirichlet velocity and initial normal stress, and uses a left-boundary velocity that is zero at t=0 but nontrivial soon after. The original model, before promotion, passed real MUMPS MPI1/2 10-step TSCN physical and shared-ParaView tests at cf42089d; other LU backends require independent native acceptance.
Scientific context: Haine, Matignon, Serhani (2023), anisotropic heterogeneous wave PFEM, DOI 10.4208/ijnam2023-1005; and Brugnoli, Haine, Matignon (2022) on mixed boundary control.
- examples.wave.main()
- examples.wave.measure_wave_2d(system)
Measure ORIGINAL GetFEM energy and all four signed port powers.
- examples.wave.wave_eq(*, mesh_size=0.2, final_time=0.08, time_step=0.008, factor_solver=None)
Build and integrate the conservative mixed-boundary 2D pH wave.
The time/mesh defaults are intentionally for native installation acceptance, not for a convergence order or published benchmark.
Why this example?
The first tutorial showed a one-dimensional string and its two boundary ports. Our next model is genuinely two-dimensional, heterogeneous and anisotropic, with mixed boundary control: three boundary segments prescribe an outward normal traction, while the fourth prescribes a velocity. We will keep exactly the same materials, mesh and boundary convention when we add an internal dissipative port in example 2B. We will then study the complementary co-energy formulation in example 2C (The wave equation — 2C: co-energy and localized damping).
This page describes the actual code in examples/wave.py.
Its snippets are included directly from that file, avoiding
manual discrepancies between the tutorial and the program.
The validated source is the same for all PETSc solver backends.
The physical model
Let \(\Omega=(0,2)\times(0,1)\) and let \(w(t,x,y)\) denote the transverse displacement of a membrane. We consider
where the in-plane tension tensor and areal mass density are
Here \(T\) is not a scalar Young modulus. It is a symmetric, positive-definite anisotropic tensor; both \(T\) and \(\rho\) vary spatially. The lower, right and upper boundaries are \(\Gamma_N\) (GetFEM regions 10, 11 and 12). The left boundary is \(\Gamma_D\) (region 13). Writing \(n\) for the outward unit normal, the controls are
The second condition prescribes velocity, not displacement. This is sometimes called a velocity-Dirichlet port in the port-Hamiltonian literature.
Energy variables, co-energy variables and power
We choose the energy states
and their conjugate co-energies
Thus \(q\) and \(e_q\) are vectors, whereas \(p\) and \(e_p\) are scalars. The first-order port-Hamiltonian dynamics are
The physical Hamiltonian is
In the GetFEM Generic Weak Form Language (GWFL),
q.T.q denotes \(q\cdot Tq\): T is the
tensor parameter’s identifier, not the transpose
operator from Python/NumPy. The actual code therefore
correctly uses "0.5*q.T.q".
With our boundary orientation, the collocated outputs are
The energy exchanged with the environment is
Our short demonstration uses zero Neumann tractions, with a nontrivial prescribed left velocity. Thus the left-hand boundary supplies the entire mechanical work; the right, top and bottom boundary powers are zero.
From the strong equation to PFEM
Integrating \(\partial_t p=\operatorname{div}e_q\) against a test function \(\varphi_p\) gives
The first equation is tested without integration by parts:
These two choices yield the partitioned finite-element
discretization (PFEM): DG1 for vector strain
\(q\), CG2 for scalar momentum \(p\),
and DG1 boundary traces. The exact finite-element
spaces and material definitions are shown below.
In SCRIMP’s assembly convention, the flow-side algebraic variables for the Neumann velocity observations are ``-Y_B``, ``-Y_R``, ``-Y_T``, and the velocity input on the left appears as ``-U_L``. The corresponding effort-side test terms are negative velocity traces. The signs make the measured powers consistent with (2). They have been checked by native GetFEM/PETSc simulations, not merely assumed from the matrix layout.
Build the real SCRIMP model
To reproduce the snippets in a notebook, begin with these imports and the same tested defaults (the command-line entry point accepts other values):
import numpy as np
import scrimp as S
mesh_size = 0.2
final_time = 0.08
time_step = 0.008
factor_solver = None # Production default: MUMPS
The four boundary identifiers are taken directly from the Python module, too:
BOUNDARIES = (
("bottom", 10, "B"),
("right", 11, "R"),
("top", 12, "T"),
("left", 13, "L"),
)
The following seven sections are taken literally from
examples/wave.py:wave_eq(); no duplicate hand-written
Python excerpts are maintained in Sphinx. The boundary
index tuple BOUNDARIES is defined at module level.
1. Instantiate the DPHS, domain, states and co-states.
system = S.DPHS("real")
system.set_output_name("wave_2d")
system.set_domain(S.Domain("Rectangle", {
"L": 2., "l": 1., "h": mesh_size,
}, mesh_output_dir=system.get_output_path("mesh",create=True)))
q = S.State("q", "Strain", "vector-field")
p = S.State("p", "Linear momentum", "scalar-field")
system.add_state(q)
system.add_state(p)
system.add_costate(S.CoState("e_q", "Stress", q))
system.add_costate(S.CoState("e_p", "Velocity", p))
2. Define the four mixed boundary ports. Only the left port
uses position="flow", since it imposes the velocity
instead of the normal traction.
for side, region, suffix in BOUNDARIES:
# Only the LEFT boundary is velocity-controlled (flow port).
is_left = side == "left"
system.add_control_port(S.Control_Port(
f"Boundary control ({side})",
f"U_{suffix}",
"Velocity" if is_left else "Outward normal traction",
f"Y_{suffix}",
"Outward normal traction" if is_left else "Velocity",
"scalar-field",
region=region,
position="flow" if is_left else "effort",
))
3. Choose the PFEM spaces and material coefficients. GetFEM’s nested GWFL matrix definition is symmetric and represents the actual inhomogeneous tensor \(T\).
for fem in (
S.FEM("q", 1, "DG"),
S.FEM("p", 2, "CG"),
*(S.FEM(f"Boundary control ({side})", 1, "DG")
for side, _, _ in BOUNDARIES),
):
system.add_FEM(fem)
# This T is symmetric positive definite throughout [0,2] x [0,1].
# GWFL nested matrices list COLUMNS; it is symmetric here.
system.add_parameter(S.Parameter(
"T", "Anisotropic membrane tension", "tensor-field",
"[[5+x,x*y],[x*y,2+y]]", "q",
))
system.add_parameter(S.Parameter(
"rho", "Areal mass density", "scalar-field",
"3-x", "p",
))
4. Assemble the Dirac structure and constitutive laws.
The rows with dt=True represent the differential
part of the port-Hamiltonian DAE. Boundary observations and
constraints are algebraic; the signs are visible here.
bricks = [
S.Brick("M_q", "q.Test_q", [1], dt=True, position="flow"),
S.Brick("M_p", "p*Test_p", [1], dt=True, position="flow"),
# Signed algebraic observation in *flow*:
# -Y_N = -e_p -> Y_N=e_p (Neumann outputs).
S.Brick("-M_Y_B", "-Y_B*Test_Y_B", [10], position="flow"),
S.Brick("-M_Y_R", "-Y_R*Test_Y_R", [11], position="flow"),
S.Brick("-M_Y_T", "-Y_T*Test_Y_T", [12], position="flow"),
# Mixed left velocity input: -U_L=-e_p -> U_L=e_p.
S.Brick("-M_U_L", "-U_L*Test_Y_L", [13], position="flow"),
S.Brick("D", "Grad(e_p).Test_q", [1], position="effort"),
S.Brick("-D^T", "-e_q.Grad(Test_p)", [1], position="effort"),
S.Brick("B_B", "U_B*Test_p", [10], position="effort"),
S.Brick("B_R", "U_R*Test_p", [11], position="effort"),
S.Brick("B_T", "U_T*Test_p", [12], position="effort"),
S.Brick("B_L", "Y_L*Test_p", [13], position="effort"),
S.Brick("-B_B^T", "-e_p*Test_Y_B", [10], position="effort"),
S.Brick("-B_R^T", "-e_p*Test_Y_R", [11], position="effort"),
S.Brick("-B_T^T", "-e_p*Test_Y_T", [12], position="effort"),
S.Brick("-B_L^T", "-e_p*Test_Y_L", [13], position="effort"),
S.Brick("-M_e_q", "-e_q.Test_e_q", [1]),
S.Brick("CR_q", "q.T.Test_e_q", [1]),
S.Brick("-M_e_p", "-e_p*Test_e_p", [1]),
S.Brick("CR_p", "p/rho*Test_e_p", [1]),
]
for brick in bricks:
system.add_brick(brick)
5. Prescribe compatible initial data and controls. We set \(q_0=p_0=0\), so \(e_q=e_p=0\) at the initial instant, and apply
This input also vanishes at \(t=0\) and at the corners of the left boundary. It is already nonzero during the ten-step installation smoke.
# Exactly compatible at t=0 (zero stress and zero velocity).
# The left boundary injects energy immediately after t=0.
for side, _, _ in BOUNDARIES:
value = (
"0.2*sin(4*pi*t)*sin(pi*y)"
if side == "left" else "0."
)
system.set_control(f"Boundary control ({side})", value)
system.set_initial_value("q", "[0., 0.]")
system.set_initial_value("p", "0.")
6. Solve the actual DAE. The algebraic initial
projection is strict and preserves the prescribed
differential data. For the quick installation check
we use fixed Crank–Nicolson,
\(t_f=0.08\), \(\Delta t=0.008\),
and ten accepted time steps, not a five-second
publication reproduction.
options = {}
if factor_solver is not None:
options["pc_factor_mat_solver_type"] = factor_solver
system.set_time_scheme(
init_step_ts_type="algebraic", init_step=True,
ts_type="cn", ts_adapt_type="none",
ts_exact_final_time="matchstep",
ksp_type="gmres", pc_type="lu",
t_0=0., t_f=final_time,
dt=time_step, dt_save=time_step,
**options,
)
system.solve()
7. Register the real anisotropic Hamiltonian. The two integrals are evaluated by GetFEM on the actual finite-element fields.
system.hamiltonian.set_name(
"Anisotropic membrane mechanical energy (mixed boundary control)"
)
system.hamiltonian.add_term(S.Term(
"Potential energy (q dot T q)", "0.5*q.T.q", [1],
))
system.hamiltonian.add_term(S.Term(
"Kinetic energy", "0.5*p*p/rho", [1],
))
To reproduce the complete program, use the canonical
entry point, which encapsulates the steps above
(and defines BOUNDARIES):
python -m examples.wave --solver mumps --check --export --output outputs/my_wave_2d
Installation and genuine scientific checks
The result must be a real GetFEM/PETSc solve, not an LU
factorization smoke. The common measure_wave_2d()
function checks convergence, the strict initial DAE
projection, nonzero left power and the mechanical
energy/work equality at every accepted CN step:
The port powers \(P_{\ast,k}\) are the genuine
cn_step GetFEM integrals sampled on the mean FE
state of the accepted step, not instantaneous endpoint
powers. Never trapezoid-integrate the P[0] sample.
The initial MUMPS native pilot passed in MPI 1
and MPI 2, with 2,230 DOFs, ten accepted steps and
numerical energy/power defects below
\(3\times10^{-18}\). Both ranks had identical
full trajectories; the MPI 1/MPI 2 state difference
was below \(4.2\times10^{-14}\). All four
fields (q, p, e_q, e_p)
were exported as valid, root-only shared VTU/PVD,
with 11 time frames per field. This is a
qualified MUMPS MPI1/2 result only, not yet
a five-backend installation acceptance.
The complete installation acceptance requires: MUMPS (MPI 1/2), sequential SuperLU (MPI 1), and SuperLU_DIST (MPI 1/2). The three backends must reproduce the same state, Hamiltonian, physical powers, and ParaView outputs. SuperLU standard is serial-only.
To save the four original GetFEM variable series,
open outputs/my_wave_2d/pv/q/q.pvd,
pv/p/p.pvd, pv/e_q/e_q.pvd or
pv/e_p/e_p.pvd in ParaView and play the
11 frames. The vector fields q and
e_q may be displayed with arrows; the
velocity is e_p (not momentum p).
Longer native showcase: 100-step energy and wave propagation
PASS, 25 November 2026, on the complete original
GetFEM/PETSc MUMPS MPI1 archive
v130-wave2d-2a-showcase-bd6f5468-teEK1Ejz.zip
(source bd6f5468e3a167f2b2a3b9e1b72bcc54e1948d45,
native Docker image scrimp-mpi:v1.3.0-rc3).
This longer visual run used h=0.1, dt=0.01
and tf=1, with 8,138 DOFs, 100/100
accepted fixed Crank–Nicolson steps, zero
rejections, exact DAE initialization, and
7/7 original physical acceptance gates passed.
The open conservative boundary-work balance
H(t)-H(0)=W_boundary(t) holds at each
accepted CN step (maximum absolute defect
2.07e-16) and cumulatively (maximum
1.25e-16). The left imposed-velocity
port supplies the energy; all three other
Neumann boundaries carry exactly zero power.
The original rank0.npz is accompanied by
four PVD series and 404 authentic GetFEM VTU
files, for q, p, e_q and e_p,
each at 101 times from 0 to 1.
The renderer generated from the actual FE data:
visuals/field_snapshots.{png,svg},
visuals/energy_balance.{png,svg},
visuals/p_evolution.gif (101 frames),
visuals/energy_and_ports.csv, plus a
machine-readable provenance JSON. The animation
shows a boundary-generated disturbance
propagating through the anisotropic rectangle.
Interpretation of fields matters:
q=Grad(w) is the displacement gradient
(not stress), while p=rho*dt(w) is momentum
(not velocity). The velocity is e_p=p/rho,
and the stress-like energy co-variable is
e_q=T*q. The generic maps and GIF currently
display p and |q|; they must not be
labeled velocity or stress. The original
e_p and e_q VTK series permit these
physical quantities to be visualized separately.
To reproduce the independently qualified long MUMPS MPI1 visual run:
cd ~/Simulations/scrimp
git pull --ff-only
conda activate scrimp
SCRIMP_DOCKER_NO_SUDO=1 \
SCRIMP_V130_DAE_IMAGE=scrimp-mpi:v1.3.0-rc3 \
bash scripts/run-v130-wave2d-showcase.sh 2a
This long-run result is not an MPI1/MPI2 parity
test or a mesh/time convergence study. The short
MUMPS MPI1/2 and other solver installation
acceptance remains a separate experiment.
The displacement w is not an independent
state of this energy-based DAE; any animation
of it must identify its reconstruction
method and gauge.
Scientific references
This introductory 2D example illustrates the PFEM framework analyzed by Haine, Matignon and Serhani (2023), Numerical Analysis of a Structure-Preserving Space-Discretization for an Anisotropic and Heterogeneous Boundary Controlled N-Dimensional Wave Equation As a Port-Hamiltonian System, DOI 10.4208/ijnam2023-1005, and the mixed-boundary-control work of Brugnoli, Haine and Matignon (2022). The tutorial is not a numerical reproduction of either paper.
The next section introduces a physically distinct
resistive port in examples/wave_dissipative.py
while keeping the same material, domain and
conventions. The later The wave equation — 2C: co-energy and localized damping
chapter changes the state variables and adds
spatially localized damping.
2B — Adding a resistive port: heterogeneous damping
Dissipative 2D anisotropic membrane with mixed boundary ports.
2D mixed-boundary anisotropic membrane, energy variables q=grad w, p=rho*w_t, coenergy e_q=T q and e_p=p/rho. This preserves the original model’s four boundary ports and its actual GetFEM GWFL Hamiltonian 0.5*q.T.q, where T is the full tensor parameter.
Physical outward-normal traction: u_N=n.e_q at bottom/right/top; observation y_N=e_p. Left side prescribes u_D=e_p (velocity) and observes y_D=n.e_q (traction). The physical pH energy balance is
H(t)-H(0) = W_boundary(t) - integral_0^t D(s) ds.
The signed algebraic boundary rows impose Y_N=e_p and U_D=e_p. The additional port obeys f_r=-e_p, e_r=nu*f_r with nu>=0. Thus its positive dissipated power is e_r*f_r=nu*f_r*f_r and dH/dt = signed_boundary_work_rate - integral_Omega(nu*f_r*f_r). The physical sign of the measured work is audited independently against the original GetFEM Hamiltonian; no success is inferred solely from these formulae.
As in qualified 2A, the initial strain and momentum are exactly zero, the left velocity input starts at zero, and the tensor, density, boundary mesh and 10-step CN discretization are unchanged. The only new physics is nu(x)=damping_strength*0.5*(2-x)>=0.
Scientific context: Haine, Matignon, Serhani (2023), anisotropic heterogeneous wave PFEM, DOI 10.4208/ijnam2023-1005; and Brugnoli, Haine, Matignon (2022) on mixed boundary control.
- examples.wave_dissipative.main()
- examples.wave_dissipative.measure_wave_2d(system)
Measure original GetFEM H, boundary work and independent resistive loss.
- examples.wave_dissipative.wave_eq(*, mesh_size=0.2, final_time=0.08, time_step=0.008, damping_strength=1.0, factor_solver=None)
Build and integrate the dissipative mixed-boundary 2D pH wave.
The time/mesh defaults are intentionally for native installation acceptance, not for a convergence order or published benchmark.
What changes relative to 2A?
This second example introduces one new physical feature: distributed viscous damping of the 2D anisotropic membrane. The independent, executable source is examples/wave_dissipative.py. Its rectangle, material tensor, density, normal directions, four boundary control ports, finite-element spaces for q and p, initial conditions and fixed Crank–Nicolson scheme are identical to those of The wave equation — 2A: conservative anisotropic membrane.
On \(\Omega=(0,2)\times(0,1)\), the equation now reads
with the same symmetric positive-definite tension and mass as example 2A and the additional nonnegative, spatially varying damping coefficient
The damping is nonzero throughout the interior except on the right boundary. We may choose a nonnegative strength multiplier in the executable; the default is damping_strength=1.0. Damping does not change the Hamiltonian:
Why add a separate resistive port?
We retain the skew-adjoint interconnection of 2A and expose the dissipation as a new scalar algebraic port (f_r,e_r). The state and co-energy variables are still
The additional constitutive and coupling equations are
Indeed, e_r=-nu e_p and partial_t p=operatorname{div}e_q-nu e_p. The discrete resistive port introduces two algebraic fields f_r and e_r (both CG2), while preserving the mechanical variables and boundary ports from example 2A.
The dissipation power is positive:
Consequently, for the same boundary work \(W_\partial(t)\) as 2A,
A dissipative system can still gain mechanical energy if its boundary ports inject more power than it dissipates. The correct identity is therefore \(\Delta H=W_\partial-L_\nu\), not the unconditional monotonicity of \(H\).
Build the actual GetFEM/PETSc model
The following code fragments are read directly from examples/wave_dissipative.py; they are not second, manually maintained versions of the solver.
1. Construct the same 2D physical and co-energy states:
system = S.DPHS("real")
system.set_output_name("wave_dissipative")
system.set_domain(S.Domain("Rectangle", {
"L": 2., "l": 1., "h": mesh_size,
}, mesh_output_dir=system.get_output_path("mesh",create=True)))
q = S.State("q", "Strain", "vector-field")
p = S.State("p", "Linear momentum", "scalar-field")
system.add_state(q)
system.add_state(p)
system.add_costate(S.CoState("e_q", "Stress", q))
system.add_costate(S.CoState("e_p", "Velocity", p))
2. Reuse the exact 2A mixed boundary control:
for side, region, suffix in BOUNDARIES:
# Only the LEFT boundary is velocity-controlled (flow port).
is_left = side == "left"
system.add_control_port(S.Control_Port(
f"Boundary control ({side})",
f"U_{suffix}",
"Velocity" if is_left else "Outward normal traction",
f"Y_{suffix}",
"Outward normal traction" if is_left else "Velocity",
"scalar-field",
region=region,
position="flow" if is_left else "effort",
))
3. Add precisely one scalar dissipative port:
system.add_port(S.Port(
"Damping", "f_r", "e_r", "scalar-field",
dissipative=True, region=1,
))
4. Reuse DG1/CG2 and add CG2 for damping, with the same tensor and density:
for fem in (
S.FEM("q", 1, "DG"),
S.FEM("p", 2, "CG"),
*(S.FEM(f"Boundary control ({side})", 1, "DG")
for side, _, _ in BOUNDARIES),
S.FEM("Damping", 2, "CG"),
):
system.add_FEM(fem)
# This T is symmetric positive definite throughout [0,2] x [0,1].
# GWFL nested matrices list COLUMNS; it is symmetric here.
system.add_parameter(S.Parameter(
"T", "Anisotropic membrane tension", "tensor-field",
"[[5+x,x*y],[x*y,2+y]]", "q",
))
system.add_parameter(S.Parameter(
"rho", "Areal mass density", "scalar-field",
"3-x", "p",
))
system.add_parameter(S.Parameter(
"nu", "Nonnegative heterogeneous viscous damping", "scalar-field",
f"{damping_strength}*0.5*(2.0-x)", "Damping",
))
5. Keep all 20 original 2A weak-form bricks and add exactly five resistive ones.
bricks = [
S.Brick("M_q", "q.Test_q", [1], dt=True, position="flow"),
S.Brick("M_p", "p*Test_p", [1], dt=True, position="flow"),
# Signed algebraic observation in *flow*:
# -Y_N = -e_p -> Y_N=e_p (Neumann outputs).
S.Brick("-M_Y_B", "-Y_B*Test_Y_B", [10], position="flow"),
S.Brick("-M_Y_R", "-Y_R*Test_Y_R", [11], position="flow"),
S.Brick("-M_Y_T", "-Y_T*Test_Y_T", [12], position="flow"),
# Mixed left velocity input: -U_L=-e_p -> U_L=e_p.
S.Brick("-M_U_L", "-U_L*Test_Y_L", [13], position="flow"),
# f_r=-e_p, algebraic resistive flow.
S.Brick("M_r", "f_r*Test_f_r", [1], position="flow"),
S.Brick("D", "Grad(e_p).Test_q", [1], position="effort"),
S.Brick("-D^T", "-e_q.Grad(Test_p)", [1], position="effort"),
S.Brick("B_B", "U_B*Test_p", [10], position="effort"),
S.Brick("B_R", "U_R*Test_p", [11], position="effort"),
S.Brick("B_T", "U_T*Test_p", [12], position="effort"),
S.Brick("B_L", "Y_L*Test_p", [13], position="effort"),
# e_r=-nu*e_p enters momentum equation.
S.Brick("I_r", "e_r*Test_p", [1], position="effort"),
S.Brick("-I_r^T", "-e_p*Test_f_r", [1], position="effort"),
S.Brick("-B_B^T", "-e_p*Test_Y_B", [10], position="effort"),
S.Brick("-B_R^T", "-e_p*Test_Y_R", [11], position="effort"),
S.Brick("-B_T^T", "-e_p*Test_Y_T", [12], position="effort"),
S.Brick("-B_L^T", "-e_p*Test_Y_L", [13], position="effort"),
S.Brick("-M_e_q", "-e_q.Test_e_q", [1]),
S.Brick("CR_q", "q.T.Test_e_q", [1]),
S.Brick("-M_e_p", "-e_p*Test_e_p", [1]),
S.Brick("CR_p", "p/rho*Test_e_p", [1]),
# Resistive constitutive law e_r=nu*f_r.
S.Brick("-M_e_r", "-e_r*Test_e_r", [1]),
S.Brick("CR_r", "nu*f_r*Test_e_r", [1]),
]
for brick in bricks:
system.add_brick(brick)
The extra bricks are M_r, I_r, -I_r^T, -M_e_r and CR_r. Their orientations implement f_r=-e_p and e_r=nu f_r. In particular, adding a negative e_r term by hand to the Hamiltonian would be wrong: the port itself carries the positive dissipated power in (3).
6. Start with the same compatible states and control pulse:
# Exactly compatible at t=0 (zero stress and zero velocity).
# The left boundary injects energy immediately after t=0.
for side, _, _ in BOUNDARIES:
value = (
"0.2*sin(4*pi*t)*sin(pi*y)"
if side == "left" else "0."
)
system.set_control(f"Boundary control ({side})", value)
system.set_initial_value("q", "[0., 0.]")
system.set_initial_value("p", "0.")
7. Apply the same strict algebraic DAE initialization and fixed CN step, without pseudo-time relaxation:
options = {}
if factor_solver is not None:
options["pc_factor_mat_solver_type"] = factor_solver
system.set_time_scheme(
init_step_ts_type="algebraic", init_step=True,
ts_type="cn", ts_adapt_type="none",
ts_exact_final_time="matchstep",
ksp_type="gmres", pc_type="lu",
t_0=0., t_f=final_time,
dt=time_step, dt_save=time_step,
**options,
)
system.solve()
8. Compute the unchanged physical Hamiltonian:
system.hamiltonian.set_name(
"Anisotropic membrane mechanical energy (mixed boundary control)"
)
system.hamiltonian.add_term(S.Term(
"Potential energy (q dot T q)", "0.5*q.T.q", [1],
))
system.hamiltonian.add_term(S.Term(
"Kinetic energy", "0.5*p*p/rho", [1],
))
Physical qualification: original boundary work minus dissipation
For each accepted CN step, the program measures the original GetFEM Hamiltonian and all four port powers on the mean finite-element state. The resistive power is computed by SCRIMP’s native Port.compute(), and checked independently by a second GetFEM volume quadrature of nu*f_r*f_r. The intended stepwise residual is
The script also verifies the cumulative (4), the nonnegativity of the actual dissipated power, the resistive flow equation, and the consistency of the 11-snapshot accepted FE history. Because nu f_r has higher polynomial degree than the CG2 space of e_r, the constitutive relationship is discrete weak projection; a pointwise zero L^2 error is not an appropriate acceptance criterion.
Run a short, real GetFEM/PETSc check (not a standalone LU smoke):
python -m examples.wave_dissipative --solver mumps \
--mesh-size 0.2 --final-time 0.08 --time-step 0.008 \
--damping-strength 1 --check --export \
--output outputs/my_wave_2d_dissipative
The native qualification runner below checks MUMPS MPI1/2 and all six finite-element exports (q, p, e_q, e_p, f_r, e_r). Its physical results must be inspected before declaring this example qualified:
SCRIMP_DOCKER_NO_SUDO=1 \
SCRIMP_V130_DAE_IMAGE=scrimp-mpi:v1.3.0-rc3 \
bash scripts/run-v130-wave2d-dissipative-pilot.sh
Long native dissipative showcase — 100 CN steps
PASS, 25 November 2026, on the authentic
GetFEM/PETSc archive
v130-wave2d-2b-showcase-dbdc49cf-G1CKQAVG.zip
(source dbdc49cfcac47d4daa1706b3fc2fa4b53646b0a2,
pinned Docker scrimp-mpi:v1.3.0-rc3).
The actual executable examples/wave_dissipative.py
ran with h=0.1, dt=0.01, tf=1 and
damping_strength=1.0, on MUMPS MPI1:
10,204 DOFs, 100/100 fixed CN steps,
zero rejected steps or nonlinear failures,
and PASS on exact-algebraic DAE initialisation
(the algebraic residual is zero). All
10 native physical gates passed.
Quantity |
Measured value |
|---|---|
Hamiltonian at |
|
Hamiltonian at |
|
Injected signed boundary work |
|
Cumulative viscous loss |
|
Maximum absolute defect per CN step |
|
Maximum absolute cumulative defect |
|
Native time series |
6 × 101 = 606 VTU, six PVD |
The original FE arrays satisfy the open
dissipative balance H-H0=W_boundary-L,
not unconditional monotonicity of H.
The three non-driven Neumann boundaries
carry exactly zero power. The integral
D=integral f_r*e_r is positive and agrees
with an independently assembled GetFEM
volume integral integral nu*f_r*f_r.
The flow equation f_r=-e_p is satisfied
to machine precision in its FE test.
The archive includes true 101-frame VTK/PVD
series for all six fields, plus energy CSV,
PNG/SVG figures and a 101-frame animation
p_evolution.gif. All 101 VTK timestamps
were verified against the original CN states.
2A versus 2B — same physical inputs, different dissipation
The independently inspected 2A and 2B long
archives have the same rectangle, anisotropic
tensor, density, velocity boundary drive,
mesh size and CN time grid. The VTK mesh
coordinates and cell connectivity for the
field p coincide exactly at t=0,
t=0.5, t=1. Adding two algebraic
resistive fields increases the model DOFs
from 8,138 (2A) to 10,204 (2B).
Quantity |
Conservative 2A |
Dissipative 2B |
|---|---|---|
Injected work |
|
|
Dissipated energy |
|
|
Remaining mechanical energy |
|
|
2B has 13.528% less mechanical energy
than 2A at t=1. The applied control is
identical, but the work delivered need not
be: it depends on the dynamical response.
Consequently the difference in stored energy
is not exactly the dissipated energy.
The exact comparison identity is
which matches the real GetFEM values to
2.08e-17. This distinction matters when
illustrating dissipation in an open
port-Hamiltonian system.
A separate comparison figure of the native
fields p at t=0.5 and t=1 uses the
same color scale for both simulations.
It depicts momentum p, not velocity
e_p; the original e_p VTK series
is available for a velocity-specific figure.
The resulting pointwise visual differences
are moderate on this time interval; the
energy deficit is the clearer diagnostic.
To reproduce the long 2B showcase:
cd ~/Simulations/scrimp
git pull --ff-only
conda activate scrimp
SCRIMP_DOCKER_NO_SUDO=1 \
SCRIMP_V130_DAE_IMAGE=scrimp-mpi:v1.3.0-rc3 \
bash scripts/run-v130-wave2d-showcase.sh 2b
Scope: MUMPS MPI1 only at the long showcase resolution. The short native MUMPS MPI1/MPI2 2B pilot passed separately; this archive does not establish mesh/time convergence, long-run MPI1/2 parity or SuperLU_DIST qualification for 2B.
The progressive example 2C, The wave equation — 2C: co-energy and localized damping, will then introduce an explicitly different co-energy formulation, instead of merely renaming these variables.