The wave equation — 2C: co-energy and localized damping

  • file: examples/wave_coenergy.py

  • authors: Giuseppe Ferraro, Ghislain Haine

  • date: 22 nov. 2022

  • brief: wave equations in co-energy formulation, two sub-domains

examples.wave_coenergy.main()
examples.wave_coenergy.measure_coenergy(system)

Audit actual CN midpoint FE work, damping and boundary feedback.

Here the signed algebraic boundary power U*Y is a LOSS: because the coenergy Grad-Grad coupling imposes Y=-p (weakly), the original FE balance is dH/dt=-integral(U*Y)-D_r. The passive law is U=+kY. This is not the mixed-boundary 2A/2B sign convention.

The substituted resistive port has no independent flow unknown and Port.get_power() correctly cannot report its dissipative power. We assemble its true mixed FE dissipation in two mathematically equivalent ways: D_r=integral e_r**2/nu = -integral p*e_r. The pointwise nu*p**2 is ONLY a diagnostic because e_r is DG1 and nu*p is not generally in the same FE space.

examples.wave_coenergy.wave_coenergy_eq(*, mesh_size=0.2, final_time=0.08, time_step=0.008, factor_solver='mumps')

Solve the anisotropic 2D wave in genuine co-energy variables.

q=e_q (stress), p=e_p (velocity); Tinv=T**(-1), rho as in 2A/2B. Damping acts only on the inner disk, feedback only on the outer rim. The short fixed CN scenario is for native acceptance, NOT convergence.

Why this third tutorial?

Tutorial The wave equation — 2A: conservative anisotropic membrane introduces the anisotropic 2D membrane and mixed boundary ports (2A), then a separate resistive flow/effort pair (2B). This tutorial introduces a genuinely different construction: the co-energy states themselves, a concentric two-region domain, inner damping and an outer boundary feedback. It does not replace 2A or 2B or imply identical meshes.

The actual, executable code is examples/wave_coenergy.py. Fragments below are included from that file, rather than copied into the documentation. The short default example (h=0.2, dt=0.008, tf=0.08) is a qualified native MUMPS MPI1/2 acceptance pilot, not a resolved wave-propagation demonstration or a convergence study.

The true material inverse

The physical tension and density retain the definitions of 2A/2B:

\[\begin{split}T(x,y)=\begin{bmatrix}5+x&xy\\xy&2+y\end{bmatrix}, \qquad \rho(x)=3-x.\end{split}\]

However, the co-energy formulation needs the actual compliance, not the same numeric tensor renamed Tinv:

\[\begin{split}T^{-1}(x,y)=\frac{1}{(5+x)(2+y)-(xy)^2} \begin{bmatrix}2+y&-xy\\-xy&5+x\end{bmatrix}.\end{split}\]

On the unit disk the determinant is strictly positive. The GetFEM GWFL parameter Tinv below encodes this inverse; q.Tinv.q is a tensor contraction, not a Python transpose.

The co-energy unknowns are now stress q=T grad(w) and velocity p=dw/dt. The conjugate co-states have been substituted, so they do not introduce extra FE unknowns. The mechanical energy is

\[\mathcal H(q,p)=\frac12\int_\Omega \left(q\cdot T^{-1}q+\rho p^2\right)\,\mathrm dx.\]

Two regions and substituted ports

The geometry is a unit disk split into the inner disk Omega_1 (radius 0.6, region 1) and an annulus Omega_2 (region 2). Region 10 is their interface; region 20 is the external boundary. The damping port is present only on region 1 and the boundary port only on region 20.

    # Set the domain (using the built-in geometry `Concentric`)
    # Labels: Disk = 1, Annulus = 2, Interface = 10, Boundary = 20
    omega = S.Domain(
        "Concentric", {"R": 1.0, "r": 0.6, "h": mesh_size},
        mesh_output_dir=wave.get_output_path("mesh",create=True),
    )
    
    # And add it to the dphs
    wave.set_domain(omega)

    ## Define the variables
    states = [
        S.State("q", "Stress", "vector-field"),
        S.State("p", "Velocity", "scalar-field"),
    ]
    # Use of the `substituted=True` keyword to get the co-energy formulation
    costates = [
        S.CoState("e_q", "Stress", states[0], substituted=True),
        S.CoState("e_p", "Velocity", states[1], substituted=True),
    ]
    
    # Add them to the dphs
    for state in states:
        wave.add_state(state)
    for costate in costates:
        wave.add_costate(costate)
    
    # Define the dissipative port, only on the subdomain labelled 1 = the internal disk
    ports = [
        S.Port("Damping", "e_r", "e_r", "scalar-field", substituted=True, region=1),
    ]
    
    # Add it to the dphs
    for port in ports:
        wave.add_port(port)
    
    # Define the control port
    control_ports = [
        S.Control_Port(
            "Boundary control",
            "U",
            "Normal force",
            "Y",
            "Velocity trace",
            "scalar-field",
            region=20,
        ),
    ]

    # Add it to the dphs
    for ctrl_port in control_ports:
        wave.add_control_port(ctrl_port)
    
    # Define the Finite Elements Method of each port
    FEMs = [
        S.FEM(states[0].get_name(), 1, "DG"),
        S.FEM(states[1].get_name(), 2, "CG"),
        S.FEM(ports[0].get_name(), 1, "DG"),
        S.FEM(control_ports[0].get_name(), 1, "DG"),
    ]
    
    # Add them to the dphs
    for FEM in FEMs:
        wave.add_FEM(FEM)
    

In the internal disk, the resistive port is substituted: nu^{-1} e_r = -p in its finite-element weak form. Unlike a non-substituted port, it has no independent GetFEM flow variable. Consequently its power cannot be obtained through Port.get_power(). The native audit instead evaluates the original FE functions by independent GetFEM quadrature.

The legacy coefficient nu=10(0.36-r^2) vanished at the interface even though a brick integrates 1/nu. Here we deliberately use nu=0.2+10(0.36-r^2) on region 1 only. This is a strictly positive, bounded invertible coefficient on the disk and still has exactly zero damping on the outer annulus by region restriction. It is a documented change to the legacy scenario, not a numerical regularization hidden in SCRIMP.

    # Define physical parameters: care must be taken, 
    # in the co-energy formulation, some parameters are
    # inverted in comparison to the classical formulation
    parameters = [
        S.Parameter(
            "Tinv",
            "Anisotropic compliance T inverse",
            "tensor-field",
            TINV,
            "q",
        ),
        S.Parameter("rho", "Mass density", "scalar-field", "3-x", "p"),
        S.Parameter(
            "nu",
            "Viscosity",
            "scalar-field",
            # Strictly positive on region 1 for the 1/nu mass brick.
            # The damping port does not exist on region 2.
            "0.2+10*(0.36-(x*x+y*y))",
            ports[0].get_name(),
        ),
    ]

    # Add them to the dphs
    for parameter in parameters:
        wave.add_parameter(parameter)

The co-energy balance and feedback sign

The semidiscrete system is

\[T^{-1}\dot q=\nabla p,\qquad \rho\dot p=\operatorname{div}q+e_r \quad (e_r\text{ acts only on }\Omega_1),\]

with the signed Grad–Grad boundary observation Y=-p (in the boundary FE weak sense). The trace is not the Y=p used in an alternative boundary-port orientation. The algebraic signed port power reported by SCRIMP is P_b=integral UY, and the original co-energy Dirac bricks give

\[\frac{\mathrm d\mathcal H}{\mathrm dt} =-\int_{\partial\Omega} UY\,\mathrm ds -\int_{\Omega_1}\frac{e_r^2}{\nu}\,\mathrm dx.\]

Consequently the passive control is `U=+0.5Y`: P_b=+0.5*integral Y^2 >= 0, and this port power is subtracted from the Hamiltonian. A previous trial mistakenly used U=-0.5Y: the unqualified real MUMPS MPI1/2 archive v130-wave2d-coenergy-e1c5bc50-bRo68Qaf.zip proved that law injected energy. Its measured identity was H-H0+Li-Lb=0 to 1e-15, with the entire rejected energy defect equal to twice the signed boundary work. This is a physical sign correction, not an adjustment to energy tolerances or an arbitrary renaming of power.

For the two dissipative mechanisms, define

\[D_i=\int_{\Omega_1}\frac{e_r^2}{\nu}\,\mathrm dx =-\int_{\Omega_1}p e_r\,\mathrm dx\ge0, \qquad D_b=\int_{\partial\Omega} UY\,\mathrm ds =0.5\int_{\partial\Omega}Y^2\,\mathrm ds\ge0.\]

The equality for D_i holds in the FE weak projection. The pointwise integral integral nu*p^2 need not agree exactly, because e_r is DG1, and nu*p generally is not. We record it as a diagnostic, not a false exactness gate.

There is no independent boundary drive in this scenario; therefore the physical balance to validate is

\[\boxed{\mathcal H(t)-\mathcal H(0)+ \int_0^t (D_i(s)+D_b(s))\,\mathrm ds=0.}\]
    # Define the pHs via `Brick` == non-zero block matrices == variational terms
    # Since we use co-energy formulation, constitutive relations are already taken into
    # account in the mass matrices M_q and M_p
    bricks = [
        ## Define the Dirac structure
        # Define the mass matrices from the left-hand side: the `flow` part of the Dirac structure
        S.Brick("M_q", "q.Tinv.Test_q", [1, 2], dt=True, position="flow"),
        S.Brick("M_p", "p*rho*Test_p", [1, 2], dt=True, position="flow"),
        S.Brick("M_r", "e_r/nu*Test_e_r", [1], position="flow"),
        S.Brick("M_Y", "Y*Test_Y", [20], position="flow"),
        # Define the matrices from the right-hand side: the `effort` part of the Dirac structure
        S.Brick("D", "Grad(p).Test_q", [1, 2], position="effort"),
        S.Brick("-D^T", "-q.Grad(Test_p)", [1, 2], position="effort"),
        S.Brick("I_r", "e_r*Test_p", [1], position="effort"),
        S.Brick("B", "U*Test_p", [20], position="effort"),
        S.Brick("-I_r^T", "-p*Test_e_r", [1], position="effort"),
        S.Brick("-B^T", "-p*Test_Y", [20], position="effort"),
        ## Define the constitutive relations
        # Already taken into account in the Dirac Structure!
    ]
    
    # Add all these `Bricks` to the dphs
    for brick in bricks:
        wave.add_brick(brick)

A physically visible initial pulse

Two smooth initial velocity bumps excite the inner damping and outer feedback. The initial stress is zero. The time integrator is fixed Crank–Nicolson, ten accepted steps, with algebraic DAE initialization and default MUMPS LU. The short time interval proves the simulation and output pipeline works, but does not by itself establish long-time spatial quality.

    ## Initialize the problem
    # The controls expression
    # The Grad-Grad boundary output has Y=-p (weak trace):
    # its signed port power is U*Y and dH/dt=-U*Y-D_internal.
    # Thus U=+kY is passive: U*Y=+k*Y**2 and dH/dt<=0.
    # The previous U=-kY *injected* energy, as proved by native CN
    # H+L_internal-L_boundary=0 (e1c5bc50, MPI1/MPI2).
    expressions = [f"{FEEDBACK_GAIN}*Y"]
    
    # Add each expression to its control_port
    for control_port, expression in zip(control_ports, expressions):
        # Set the control functions (automatic construction of bricks such that -M_u u + f(t) = 0)
        wave.set_control(control_port.get_name(), expression)

    # Set the initial data
    wave.set_initial_value("q", "[0., 0.]")
    # Smooth two-part velocity pulse excites both internal damping and the
    # exterior feedback already at t=0, without prescribing a boundary trace.
    wave.set_initial_value(
        "p",
        "exp(-10*(x*x+y*y))+0.4*exp(-15*((x-0.8)*(x-0.8)+y*y))",
    )

    ## Solve in time
    # Define the time scheme ("cn" is Crank-Nicolson)
    options = {}
    if factor_solver is not None:
        options["pc_factor_mat_solver_type"] = factor_solver
    wave.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,
    )

    # Solve
    wave.solve()

    ## Post-processing
    ## Set Hamiltonian's name
    wave.hamiltonian.set_name("Mechanical energy")
    # Define each Hamiltonian Term
    terms = [
        S.Term("Potential energy", "0.5*q.Tinv.q", [1, 2]),
        S.Term("Kinetic energy", "0.5*p*p*rho", [1, 2]),
    ]
    # Add them to the Hamiltonian
    for term in terms:
        wave.hamiltonian.add_term(term)

    return wave


Native outputs and visualizations

The pilot below records the original full FE state history in NPZ, true GetFEM Hamiltonian and power histories, detailed JSON physical gates, two independent quadratures of inner resistance, and GetFEM/ParaView time series q, p, e_r (one PVD and eleven VTU per field and MPI case). It checks strict DAE, CN work/loss balance at every step, nontrivial passive feedback and damping, MPI replica/parity, and genuine nonempty VTK fields.

Once a native case passes, the same script renders from the original FE NPZ/VTK, not an invented analytic image:

  • visuals/energy_balance.png and .svg: mechanical energy vs work/losses, powers, balance defect;

  • visuals/field_snapshots.png and .svg: spatial snapshots of p, |q|, e_r;

  • visuals/p_evolution.gif: animated accepted p snapshots (pilot: 11 frames);

  • visuals/energy_and_ports.csv: actual energetic histories with explicit columns;

  • visuals/provenance.json: commit, image revision, number of frames and Float32 VTK warning.

Open mumps_mpi1/pv/p/p.pvd (or q/e_r) in ParaView to examine the whole native sequence. VTK Float32 is for visualisation; the acceptance audit uses full-precision original GetFEM FE values.

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-coenergy-pilot.sh

The same native visualization tool can be run on the already-qualified 2B archive, without any rerun of the solver:

python scripts/render-v130-wave2d-native.py \
  --input sandbox/outputs/v130-wave2d-dissipative-e582874f-9ni2cPYZ.zip \
  --case mumps_mpi1 \
  --output sandbox/outputs/wave2d-2b-visuals

The renderer also supports compatible archived 2A NPZ/PVD layouts. Use the case names in each archive. A separate long-time demonstration has now also passed its 100-step physical acceptance on MUMPS MPI1 (see below); those longer fields and animations should be considered for the public Sphinx gallery after labeling the inner damping region explicitly.

Qualification evidence — original GetFEM CN, MPI 1 and 2

PASS, 25 November 2026 on the original full-precision FE archive v130-wave2d-coenergy-eeae81f7-siWdW8ft.zip (commit eeae81f7099e61ed6edf62941c782e9d2ea56f2d, pinned native Docker image scrimp-mpi:v1.3.0-rc3). The short co-energy benchmark was run independently on MUMPS MPI1 and MPI2 with 2459 FE degrees of freedom, 10/10 accepted Crank–Nicolson steps, zero nonlinear failures, and exact-algebraic DAE initial projection. All ten physical acceptance gates passed in each case.

Original native physical evidence

Quantity

MPI 1

MPI 2

Maximum absolute energy defect per CN step

9.81e-16

4.39e-16

Maximum absolute cumulative energy defect

7.17e-16

2.60e-16

Cumulative internal dissipation Li(tf)

0.035508373984

0.035508373984

Cumulative boundary feedback dissipation Lb(tf)

0.001039372338

0.001039372338

VTK fields / saved frames

q,p,e_r / 11 each

q,p,e_r / 11 each

The first and last energies (MPI1) are H(0)=0.25557110317334153 and H(tf)=0.21902335685158436. The decline is 14.3%, about 97.2% from internal damping and 2.8% from boundary feedback. The maximum absolute difference in the full FE trajectory between MPI1 and MPI2 is 2.686556533e-11. The MPI2 ranks have identical full arrays and independently matching SHA256 digests.

The visual-output files were also generated and examined from the real native PVD/VTU, rather than synthetic or interpolated physics. The gallery field_snapshots.png shows the spatial stress magnitude, velocity and resistive effort at t=0,0.04,0.08; the animation p_evolution.gif uses all 11 accepted physical states. energy_balance.png superimposes measured H-H(0) and -Li-Lb and shows residuals at machine precision. The accompanying CSV makes the energy/power balance inspectable without ParaView. All files are included in the original pilot ZIP, under visuals/ and mumps_mpi*/pv/.

Long-time visualization — 100 accepted physical CN steps

PASS, 25 November 2026 on the authentic GetFEM archive v130-wave2d-2c-showcase-bc880100-9P5gcxWf.zip, commit bc880100f69f6f0dbbb5d31ee8fc229d0b32647d. The canonical example was executed at h=0.1, dt=0.01, tf=1.0, with 7905 DOFs, 100/100 accepted CN steps, zero nonlinear failures/rejections, and DAE initialization residual 9.86e-14. All 10 physics gates passed; the energy remained monotonically decreasing at every saved time.

Native long-run energy evidence (MUMPS MPI1)

Quantity

Measured value

Initial Hamiltonian H(0)

0.2556143692106721

Final Hamiltonian H(1)

0.10272364224930962

Total internal energy loss Li(1)

0.0882892889133343

Total boundary feedback energy loss Lb(1)

0.06460143804802765

Maximum CN per-step energy defect

1.32e-15

Maximum cumulative energy defect

1.62e-15

VTU data / animated frames

3 × 101 = 303 VTU / 101 GIF frames

The mechanical energy decreases by 59.81%: 57.75% of that loss is due to inner resistance and 42.25% to outer feedback. The original FE arrays were independently checked: H(t)-H(0)+Li(t)+Lb(t) is below 1.62e-15 and both dissipations increase monotonically. The export contains three authentic PVD time series (q, p, e_r), each with 101 GetFEM VTU files at precisely the saved CN times from 0 to 1. The renderer produced and archived all 101 GIF frames and the PNG/SVG field and energy figures from these real VTUs, plus the 101-row CSV.

Visualization note: the e_r port is restricted to the inner disk only. In the current generic visualizer, the annulus is shown with a zero-colored background; this is merely a plotting convenience, not a claim that e_r is physically defined there. The final pedagogical image should mark or mask the inner disk boundary to avoid confusion.

To reproduce this separate and now verified long-duration run:

cd ~/Simulations/scrimp
git pull --ff-only
SCRIMP_DOCKER_NO_SUDO=1 \
SCRIMP_V130_DAE_IMAGE=scrimp-mpi:v1.3.0-rc3 \
bash scripts/run-v130-wave2d-showcase.sh 2c

The short pilot qualifies the model in MUMPS MPI1/MPI2 at h=0.2 over 10 steps; the long showcase independently qualifies the 100-step physical balance and native visual outputs at h=0.1 in MUMPS MPI1 only. Neither campaign establishes mesh/time convergence or long-run MPI1/MPI2 equivalence. SuperLU_DIST and other solvers are not qualified for 2C. No automatic solver regularization was used.