1 Introduction

As computational power increases and the desire for ever more complex models grows, the need to have an energy-conserving mathematical framework for multiphysics, multidomain problems is becoming apparent. Many fields require complex couplings between continuum and lumped parameter models (LPMs) including physiology, aerospace, vehicle dynamics, robotics, and many more. The coupling of these models is typically done in an iterative manner, which has multiple disadvantages. Two major downsides are the failure of iterative couplings to conserve energy [35] and the difficulty in finding a stable combination of timesteps for the coupled models [45]. Another equally large disadvantage of the iterative approach is the difficulty of implementing control algorithms without a monolithic state-space matrix. A fully coupled, monolithic approach that conserves the structural properties of the lumped parameter and continuum models is desirable.

In this paper we discuss the energy conservation of a continuum system described by a partial differential equation (PDE) coupled with a LPM. Specifically, a model is derived for the linear 2D wave equation with an electromechanical (EM) linear actuator driving one of the boundaries. This example also shows that the port-Hamiltonian (PH) formalism can be used to interconnect various types of models while conserving energy flow through ports/boundaries. PH is a proven method for the modelling and control of complex multiphysics systems. Over the last 20 years, a significant amount of work has been done on infinite-dimensional PH methods for the modelling of continuum systems [17, 42]. Some PDEs that have been modelled using the PH framework are transmission line equations, shallow water equations and Timoshenko beam equations [14]. More recently, both 2D and 3D models have been implemented using the PH framework [38, 41, 44].

In Sect. 2 the spatial discretisation is proven to conserve the Hamiltonian in the same manner as the exact equations. Section 3 formulates the discretisation of the temporal domain with well known symplectic integrators: the symplectic Euler (SE) method, the symplectic (implicit) midpoint (SM) method and the Störmer-Verlet (SV) (leapfrog) method. A symplectic method conserves volume in phase space, which results in bounded conservation of the Hamiltonian [20]. The combined spatial-temporal discretisation, therefore, conserves the Hamiltonian structure of the governing equations. A similar class of methods that conserves the Hamiltonian structure is the class of multi-symplectic methods. Multiple groups have applied multi-symplectic methods to both the linear and non-linear wave equations. Reich used Runge-Kutta finite difference schemes in both space and time [34], McLachlin compared multiple methods, including spectral methods [28], and Brugnano used a Hamilton Boundary Value Method [5]. McDonald shows that multi-symplecticity preserves the travelling waves of hyperbolic equations [27]. The Partitioned Finite Element Method (PFEM) in the paper by Cardoso-Ribeiro et al. [11] combines a finite element spatial discretisation with an SV time integration scheme in a way that conserves energy but requires Lagrange multipliers to implement mixed boundary conditions [21]. Brugnoli et al. successfully apply this approach to Mindlin and Kirchhoff plate models [7, 8]. Brugnoli et al. [9] have also introduced another method for applying mixed boundary conditions to PFEM. Their method requires discretisation of the spatial domain into separate sections, each section having one type of boundary condition. The Stokes-Dirac structure [43] and interconnection property of PH methods is then used to combine the multiple sections, creating a full system with mixed boundary conditions. Similar to our method, Kotyczka uses a finite element discretisation and symplectic time integration in a way that conserves the Hamiltonian structure and allows for mixed boundary conditions [22], however, user-defined parameters in the method must be tuned for accurate results. The method introduced in this paper combines desirable attributes of Cardoso-Ribeiro’s, Brugnoli’s, and Kotyczka’s methods and provides a Hamiltonian-conserving, symplectic method that allows for easily implemented mixed boundary conditions, port-based boundary coupling, and does not require tuning of user-defined parameters.

To ensure conservation of energy flow through the boundaries, a weak boundary condition implementation is used for the Dirichlet conditions, similar to the way Neumann conditions are typically implemented in finite element methods. Weak boundary conditions are implemented in the variational form and provide many benefits for a finite element formulation. One of these benefits is that it simplifies the implementation by not having to directly prescribe the degrees of freedom (DOFs) at the boundary. This can have benefits in applying multiple types of boundary conditions, including no-slip conditions for the Navier-Stokes equations [3]. Also, no manipulation of the solution matrix is required to prescribe the DOFs. The ability to have mixed boundary conditions is also extended to allow mixed causality interconnections with other PH models. By showing that our spatial discretisation is equivalent to a coupling of canonical PH models with either Neumann or Dirichlet boundaries and by following the interconnection methods of Brugnoli [6], we calculate the causal boundary connections with a LPM. The ability to use the canonical forms to calculate the power conserving interconnection allows mixed causality boundary interconnection between other PH models.

Continuous Galerkin and hybridizable discontinuous Galerkin methods couple well with PH methods due to the ease of ensuring structural properties of the models and the simplicity of coupling different models at the boundary. Brezzi and Fortin give a good overview of Galerkin methods [4]. Cockburn developed a unifying framework for Galerkin methods [12] that multiple authors have extended. McLachlan extends Cockburn’s discontinuous Galerkin (DG) methods into a formulation that allows proof of multi-symplecticity for elliptic equations [29]. Sanchez uses a hybridizable discontinuous Galerkin approach to obtain a wave equation discretisation similar to our method, that is proven to be Hamiltonian-conserving and symplectic in time [36]. We prove the same qualities for our method, a continuous Galerkin approach that has the important added novelty of being able to be coupled with arbitrary PH LPMs. The conservativity and modular approach of this method is thus ideal for a wide range of real-world problems.

Energy conservation in the Galerkin method is extremely important for real-world applications that require long-time simulations, such as in geophysical fluid dynamics. Bauer uses a Poisson bracket approach to prove conservation of energy for a Galerkin discretisation of the rotating shallow water equations [2]. Extending on Bauer’s work, Eldred uses the Galerkin method coupled with a Poisson time integrator to conserve energy when modelling the thermal shallow water equations [15]. Both of these models take advantage of Hamiltonian-conservation to give good long-time prediction for geophysical fluid dynamics applications.

Modelling of wave propagation also has applications in multiple biological fields. In this paper, the wave equation models homogeneous, linear-elastic media. For extensions with heterogeneous materials, typical of most biological materials, see the paper by Serhani [38]. Elastography [31] is an interesting application that requires a type of inverse modelling to identify the elasticity of heart tissue. A coupled LPM-continuum model could improve the current elastography methods. There has also been work done on non-linear models for wave propagation through biological tissue [13].

The model in this paper is implemented with the software FEniCS [1], which is a tool for automated scientific computing that focuses on solving PDEs. FEniCS allows for a very efficient implementation of finite element methods specified in a weak form. Another strong attribute of FEniCS is its automatic differentiation, which is valuable for inverse problems and for control.

The section outline of the paper is as follows. Section 2 details the PH form of the wave equation, proves that the discretisation conserves energy, and proves that the discretisation retains the Stokes-Dirac structure. The FEniCS implementation and the results showing energy conservation are shown in Sect. 3. Section 4 validates the wave equation against an analytical solution by showing spatial, temporal, and eigenvalue convergence. An EM model is introduced in Sect. 5. In Sect. 6 the wave equation is coupled with the EM model in a monolithic approach that conserves the canonical PH structure. Finally, in Sect. 7, the results of the combined model are shown and the energy conservation of the model is discussed. Appendices A and C detail the Python code for Sects. 3 and 6, respectively.

2 The Wave Equation

This section details the weak form PH discretisation of the wave equation with constant propagation speed, the conservation of energy proof, and the proof that the discretisation ensures a Stokes-Dirac structure. The 2D wave equation in Cartesian coordinates is used throughout this paper, however, all results in this section naturally extend to the 3D wave equation. The basic linear wave equation is

$$ \partial _{t}^{2} w (\boldsymbol{x}, t) = c^{2} \Delta w(\boldsymbol{x}, t)\,, $$
(1)

where \(w\) is the wave amplitude, \(\boldsymbol{x}\) denotes the spatial coordinates, and \(t\) is the time. To model the simplified wave propagation in an elastic membrane we define \(c^{2} = k_{w} / \rho _{w}\) as the wave speed squared, which is a constant function of the material density (\(\rho _{w}\)) and stiffness (\(k_{w}\)). To transform Equation (1) into PH form, state variables, \(\tilde{p}\), the momentum, and \(\tilde{\boldsymbol{q}}\), the strain, are chosen as

$$ \tilde{p} = -\rho _{w} \partial _{t} w \,, \qquad \tilde{\boldsymbol{q}} = \nabla w \,. $$
(2)

This transforms the second-order equation into a system of (\(n+1\)) first-order equations, where \(n\) is the number of spatial dimensions. Note that the tilde overscript is used to denote exact variables, to distinguish them from the approximate functions used in subsequent sections. Using the PH notation of flow and effort variables, the time derivative of the state variables, \(\tilde{f}_{p}\) and \(\tilde{\boldsymbol{f_{q}}}\), are defined as flows

$$ \tilde{f}_{p} = -\partial _{t} \tilde{p} \,, \qquad \tilde{\boldsymbol{f_{q}}} = - \partial _{t} \tilde{\boldsymbol{q}} \,. $$
(3)

The Hamiltonian functional and the Hamiltonian density are respectively given by

$$\begin{aligned} H(\tilde{p}, \tilde{\boldsymbol{q}}) & = \int _{\Omega } \mathcal{H}(\tilde{p}, \tilde{\boldsymbol{q}}) dV \,, \end{aligned}$$
(4)
$$\begin{aligned} \mathcal{H}(\tilde{p},\tilde{\boldsymbol{q}}) &= \frac{1}{2 \rho _{w}} \tilde{p}^{2} + \frac{1}{2} k_{w} \tilde{\boldsymbol{q}} \cdot \tilde{\boldsymbol{q}} \,, \end{aligned}$$
(5)

where \(\Omega \) is an open, bounded spatial domain with a Lipschitz-continuous boundary, \(\partial \Omega \). The effort variables \(\tilde{e}_{p}\), the velocity, and \(\tilde{\boldsymbol{e}}_{\boldsymbol{q}}\), the stress, are defined as the variational derivatives of the Hamiltonian density,

$$ \tilde{e}_{p} = \partial _{\tilde{p}} \mathcal{H} = \frac{\tilde{p}}{\rho _{w}} \,, \qquad \tilde{\boldsymbol{e}}_{\boldsymbol{q}} = \partial _{\tilde{\boldsymbol{q}}} \mathcal{H} = k_{w} \tilde{\boldsymbol{q}}\,. $$
(6)

For a functional that only depends on its states, not on their spatial derivatives, the variational derivatives are equal to the partial derivatives of the integrand. Transforming Equations (1) and (3) to (6) into a PH structure gives

$$ \begin{bmatrix} \tilde{f}_{p} \\ \tilde{\boldsymbol{f}}_{\boldsymbol{q}} \\ \end{bmatrix} = \begin{bmatrix} 0 & \mathrm{{div} }\\ \mathrm{{grad} }& \boldsymbol{0} \\ \end{bmatrix} \begin{bmatrix} \tilde{e}_{p} \\ \tilde{\boldsymbol{e}}_{\boldsymbol{q}} \\ \end{bmatrix} = \boldsymbol{J} \begin{bmatrix} \tilde{e}_{p} \\ \tilde{\boldsymbol{e}}_{\boldsymbol{q}} \\ \end{bmatrix} \,, $$
(7)

where the \(\mathrm{{div}}\) and \(\mathrm{{grad}}\) operators make up the formally skew-adjoint \(\boldsymbol{J}\) operator. For a proof of the skew-adjointness of \(\boldsymbol{J}\) see the work by Trenchant et al. [40].

Theorem 2.0.1

Equation (7) is energy-conserving. i.e., the rate of change of the Hamiltonian is equal to the energy flow through the domain boundary.

Proof

$$\begin{aligned} \dot{H} & = \int _{\Omega } \bigg( \frac{\partial H}{\partial \tilde{p}} \frac{\partial \tilde{p}}{\partial t} + \frac{\partial H}{\partial \tilde{\boldsymbol{q}}} \cdot \frac{\partial \tilde{\boldsymbol{q}}}{\partial t} \bigg) dV \\ & = -\int _{\Omega } \bigg( \tilde{e}_{p} \tilde{f}_{p} + \tilde{\boldsymbol{e}}_{\boldsymbol{q}} \cdot \tilde{\boldsymbol{f}}_{\boldsymbol{q}} \bigg) dV \,. \end{aligned}$$
(8)

Equation (8) satisfies the well known bond-graph and PH condition, that the product of the effort and flow variables equals the power [42]. Substituting Equation (7) into Equation (8) and using integration by parts gives

$$ \begin{aligned} \dot{H} & = -\int _{\Omega } \bigg( \tilde{e}_{p} ( \nabla \cdot \tilde{\boldsymbol{e}}_{\boldsymbol{q}}) + \tilde{\boldsymbol{e}}_{\boldsymbol{q}} \cdot \nabla \tilde{e}_{p} \bigg) dV \\ & = - \int _{\Omega } \bigg( \tilde{e}_{p} (\nabla \cdot \tilde{\boldsymbol{e}}_{\boldsymbol{q}}) - (\nabla \cdot \tilde{\boldsymbol{e}}_{\boldsymbol{q}}) \tilde{e}_{p} \bigg) dV - \int _{\partial \Omega } (\tilde{\boldsymbol{e}}_{ \boldsymbol{q}} \cdot \boldsymbol{n})\tilde{e}_{p} ds \\ & = -\int _{\partial \Omega } (\tilde{\boldsymbol{e}}_{\boldsymbol{q}} \cdot \boldsymbol{n}) \tilde{e}_{p} ds \,. \end{aligned} $$

 □

Therefore, the rate of change of the Hamiltonian is only dependent on the boundary terms and thus the Hamiltonian is conserved within the internal domain.

Corollary 2.0.2

The canonical inputs and outputs of the system are either

$$ \tilde{u}_{\boldsymbol{q}} = -(\tilde{\boldsymbol{e}}_{\boldsymbol{q}} \cdot \boldsymbol{n}) \rvert _{ \partial \Omega } = -k_{w} (\tilde{\boldsymbol{q}} \cdot \boldsymbol{n}) \rvert _{ \partial \Omega } \,, \qquad \tilde{y}_{p} = \tilde{e}_{p} \rvert _{ \partial \Omega } = \frac{\tilde{p}}{\rho _{w}} \bigg\rvert _{ \partial \Omega } \,, $$
(9)

respectively, or for the opposite causality the inputs and outputs are respectively,

$$ \tilde{y}_{q} = (\tilde{\boldsymbol{e}}_{\boldsymbol{q}} \cdot \boldsymbol{n}) \rvert _{ \partial \Omega } = k_{w} (\tilde{\boldsymbol{q}} \cdot \boldsymbol{n}) \rvert _{ \partial \Omega } \,, \qquad \tilde{u}_{p} = -\tilde{e}_{p} \rvert _{ \partial \Omega } = -\frac{\tilde{p}}{\rho _{w}} \bigg\rvert _{ \partial \Omega } \,. $$
(10)

2.1 Weak Form

In this section, the discretised weak form of the wave equation is derived. First, we define the \(L^{2}\) inner product over the domain, \(\Omega \), and the boundary, \(\partial \Omega \), as

$$ \langle \boldsymbol{a} | \boldsymbol{b} \rangle _{\Omega } = \int _{\Omega } \boldsymbol{a} \cdot \boldsymbol{b} dV \,, \qquad \langle \boldsymbol{a} | \boldsymbol{b} \rangle _{ \partial \Omega } = \int _{\partial \Omega } \boldsymbol{a} \cdot \boldsymbol{b} ds \,. $$
(11)

Using the same function spaces as in Cardoso-Ribeiro’s work [11], approximate flow and effort functions are introduced,

$$ \begin{aligned} & f_{p}, e_{p} \in H^{1}(\Omega ) \,, \\ & \boldsymbol{f_{q}}, \boldsymbol{e_{q}} \in H^{\mathrm{{div}}}(\Omega ) \,. \end{aligned} $$
(12)

In the succeeding sections, we show that this choice of function spaces allows us to combine important features of Cardoso-Ribeiro’s and Kotyczka’s [22] methods. Cardoso-Ribeiro’s methods ease of implementation is combined with Kotyczka’s methods ability to implement mixed boundary conditions without Lagrange multipliers. Substituting these approximate functions for the exact flows and efforts in Equation (7) and taking the inner product with the test functions (\(v_{p}\), \(\boldsymbol{v_{q}}\)) gives

$$\begin{aligned} \langle v_{p} | f_{p} \rangle _{\Omega } & = \langle v_{p} | \nabla \cdot \boldsymbol{e_{q}} \rangle _{\Omega } \,, \end{aligned}$$
(13a)
$$\begin{aligned} \langle \boldsymbol{v_{q}} | \boldsymbol{f_{q}} \rangle _{\Omega } & = \langle \boldsymbol{v_{q}} | \nabla e_{p} \rangle _{\Omega } \,. \end{aligned}$$
(13b)

The right-hand side of Equations (13a) and (13b) are then integrated by parts to give

$$\begin{aligned} \langle v_{p} | f_{p} \rangle _{\Omega } & = -\langle \nabla v_{p} | \boldsymbol{e_{q}} \rangle _{\Omega } + \langle v_{p} | (\boldsymbol{e_{q}} \cdot \boldsymbol{n}) \rangle _{\partial \Omega } \,, \end{aligned}$$
(14a)
$$\begin{aligned} \langle \boldsymbol{v_{q}} | \boldsymbol{f_{q}} \rangle _{\Omega } & = -\langle ( \nabla \cdot \boldsymbol{v_{q}}) | e_{p} \rangle _{\Omega } + \langle ( \boldsymbol{v_{q}} \cdot \boldsymbol{n}) | e_{p} \rangle _{\partial \Omega } \,. \end{aligned}$$
(14b)

These equations are now in a form where the Galerkin method can be applied. To do this, the approximate flow and effort functions in Equation (12) are defined from the discrete flow (\(\boldsymbol{\hat{f}}_{p} \in \mathbb{R}^{N_{p}}\), \(\boldsymbol{\hat{f}}_{\boldsymbol{q}} \in \mathbb{R}^{N_{\boldsymbol{q}}}\)) and effort (\(\boldsymbol{\hat{e}}_{p} \in \mathbb{R}^{N_{p}}\), \(\boldsymbol{\hat{e}}_{\boldsymbol{q}} \in \mathbb{R}^{N_{\boldsymbol{q}}}\)) vectors and the vectors of globally defined basis functions (\(\boldsymbol{\varphi }_{p}\), \(\boldsymbol{\varphi _{q}}\)) as shown here,

$$ \begin{alignedat}{3} & f_{p} (\boldsymbol{x}) &&= \sum _{i=1}^{N_{p}} \hat{f}_{pi} \varphi _{pi} ( \boldsymbol{x}) &&= \langle \boldsymbol{\hat{f}}_{p} , \boldsymbol{\varphi }_{p} (\boldsymbol{x}) \rangle \,, \\ & \boldsymbol{f}_{\boldsymbol{q}} (\boldsymbol{x}) &&= \sum _{j=1}^{N_{\boldsymbol{q}}} \hat{f}_{ \boldsymbol{q}j} \boldsymbol{\varphi }_{\boldsymbol{q}j} (\boldsymbol{x}) &&= (\boldsymbol{\varphi _{q}} ( \boldsymbol{x}))^{T} \boldsymbol{\hat{f}}_{\boldsymbol{q}} \,, \end{alignedat} $$
(15)
$$ \begin{alignedat}{3} & e_{p} (\boldsymbol{x}) &&= \sum _{i=1}^{N_{p}} \hat{e}_{pi} \varphi _{pi} ( \boldsymbol{x}) &&= \langle \boldsymbol{\hat{e}}_{p} , \boldsymbol{\varphi }_{p} (\boldsymbol{x}) \rangle \,, \\ & \boldsymbol{e}_{\boldsymbol{q}} (\boldsymbol{x}) &&= \sum _{j=1}^{N_{\boldsymbol{q}}} \hat{e}_{ \boldsymbol{q}_{j}} \boldsymbol{\varphi }_{\boldsymbol{q}j} (\boldsymbol{x}) &&= (\boldsymbol{\varphi _{q}} ( \boldsymbol{x}))^{T} \boldsymbol{\hat{e}}_{\boldsymbol{q}} \,, \end{alignedat} $$
(16)

where \(N_{p}\) and \(N_{\boldsymbol{q}}\) are the number of DOFs stored by the discrete vectors. A hat over a variable is used to denote the vector of discrete values, i.e., \(\boldsymbol{\hat{e}}_{p}\) is the column vector of discrete DOF values for the scalar field \(e_{p}\). To make the method Galerkin, \(v_{p}\) and \(\boldsymbol{v_{q}}\) are discretised with the same basis functions as \(f_{p}\) and \(\boldsymbol{f_{q}}\), respectively. The basis function families that we use are Lagrange for \(\boldsymbol{\varphi }_{p}\) and Raviart-Thomas [33] for \(\boldsymbol{\varphi _{q}}\), however, any basis functions that satisfy the function spaces in Equation (12) are suitable. In Equations (15) and (16), the sizes of \(\boldsymbol{\varphi }_{p}\) and \(\boldsymbol{\varphi _{q}}\) are \(N_{p} \times 1\) and \(N_{q} \times 2\), respectively. The notation, \(\langle \cdot , \cdot \rangle \) is used for the standard inner product on ℝ, as opposed to \(\langle \cdot | \cdot \rangle _{\Omega }\), the \(L^{2}\) inner product. For the lowest order Lagrange and Raviart-Thomas elements, \(\boldsymbol{\hat{e}}_{p}\) and \(\boldsymbol{\hat{f}}_{p}\) are stored at nodes and \(\boldsymbol{\hat{e}_{q}}\) and \(\boldsymbol{\hat{f}_{q}}\) are stored at edges. For details on higher order elements see the FEniCS book [26].

Substituting the approximate functions from Equations (15) and (16) as well as the corresponding test functions into Equation (14a) gives

v p | f p Ω = v p | e q Ω + v p | ( e q n ) Ω , v ˆ p T φ p | φ p Ω f ˆ p = v ˆ p T φ p | φ q Ω e ˆ q + v ˆ p T ψ p | ψ q Ω e ˆ q , v ˆ p T M p f ˆ p = v ˆ p T K p e ˆ q + v ˆ p T L p e ˆ q ,
(17)

where \(\boldsymbol{\psi }_{p} = \boldsymbol{\varphi }_{p} \vert _{\partial \Omega }\) represents \(\boldsymbol{\varphi }_{p}\) evaluated at the boundary and \(\boldsymbol{\psi _{q}} = \boldsymbol{\varphi }_{\boldsymbol{q}} \cdot \boldsymbol{n}\vert _{\partial \Omega }\) represents \(\boldsymbol{\varphi }_{\boldsymbol{q}}\) evaluated in the normal direction at the boundary. More clearly, the basis functions for the boundary terms satisfy the following relations,

$$ e_{p} |_{\partial \Omega } = \langle \boldsymbol{\hat{e}}_{p} , \boldsymbol{\psi }_{p} \rangle \,, \qquad \boldsymbol{e_{q}} \cdot \boldsymbol{n} |_{\partial \Omega } = \langle \boldsymbol{\hat{e}}_{\boldsymbol{q}} , \boldsymbol{\psi _{q}} \rangle \,. $$
(18)

Substituting the approximate functions from Equations (15), (16) and (18), as well as the corresponding test functions into Equation (14b) gives

v q | f q Ω = ( v q ) | e p Ω + ( v q n ) | e p Ω , v ˆ q T φ q | φ q Ω f ˆ q = v ˆ q T ( φ q ) | φ p Ω e ˆ p + v ˆ q T ψ q | ψ p Ω e ˆ p , v ˆ q T M q f ˆ q = v ˆ q T K q e ˆ p + v ˆ q T L q e ˆ p .
(19)

The matrices in Equations (17) and (19) are given as

$$ \begin{aligned} \boldsymbol{M}_{p} &= \langle \boldsymbol{\varphi }_{p} | \boldsymbol{\varphi }_{p} \rangle _{\Omega } \,, \\ \boldsymbol{M_{q}} &= \langle \boldsymbol{\varphi _{q}} | \boldsymbol{\varphi _{q}} \rangle _{ \Omega } \,, \\ \boldsymbol{K}_{p} &= -\langle \nabla \boldsymbol{\varphi }_{p} | \boldsymbol{\varphi _{q}} \rangle _{\Omega } \,, \\ \boldsymbol{K_{q}} &= -\langle \nabla \cdot \boldsymbol{\varphi }_{\boldsymbol{q}} | \boldsymbol{\varphi }_{p} \rangle _{\Omega } \,, \\ \boldsymbol{L}_{p} &= \langle \boldsymbol{\psi }_{p} | \boldsymbol{\psi _{q}} \rangle _{ \partial \Omega } \,, \\ \boldsymbol{L_{q}} &= \langle \boldsymbol{\psi _{q}} | \boldsymbol{\psi }_{p} \rangle _{ \partial \Omega } \,, \end{aligned} $$
(20)

where the inner product acts elementwise for the matrix as

$$ \langle \boldsymbol{a} | \boldsymbol{b} \rangle _{\Omega }^{ij} = \langle \boldsymbol{a}^{i} | \boldsymbol{b}^{j} \rangle _{\Omega } \,. $$
(21)

Applying a typical weak form approach, Equations (17) and (19) must hold for any \(\boldsymbol{\hat{v}}_{p} \in \mathbb{R}^{N_{p}}\) and \(\boldsymbol{\hat{v}_{q}} \in \mathbb{R}^{N_{\boldsymbol{q}}}\). Therefore, according to the fundamental theorem of variational calculus, the following matrix system of equations holds,

$$ \begin{aligned} \boldsymbol{M}_{p} \boldsymbol{\hat{f}}_{p} &= \boldsymbol{K}_{p} \boldsymbol{\hat{e}_{q}} + \boldsymbol{L}_{p} \boldsymbol{\hat{e}_{q}} \,, \\ \boldsymbol{M_{q}} \boldsymbol{\hat{f}_{q}} &= \boldsymbol{K_{q}} \boldsymbol{\hat{e}}_{p} + \boldsymbol{L_{q}} \boldsymbol{\hat{e}}_{p} \,. \end{aligned} $$
(22)

When implementing Equation (22), it is essential to include the discrete dynamic and constitutive laws which coincide with Equations (3) and (6), respectively. The dynamic and constitutive laws are respectively,

$$ \frac{\partial }{\partial t} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \end{bmatrix} = \begin{bmatrix} - \boldsymbol{\hat{f}}_{p} \\ - \boldsymbol{\hat{f}_{q}} \\ \end{bmatrix} \,, $$
(23)
$$ \begin{bmatrix} \boldsymbol{\hat{e}}_{p} \\ \boldsymbol{\hat{e}}_{\boldsymbol{q}} \\ \end{bmatrix} = \begin{bmatrix} \frac{1}{\rho _{w}} \boldsymbol{I} & \boldsymbol{0} \\ \boldsymbol{0} & k_{w}\boldsymbol{I} \\ \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \end{bmatrix} = \boldsymbol{Q} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \end{bmatrix} \,, $$
(24)

where \(\boldsymbol{I}\) is the identity matrix. Also, \(\boldsymbol{\hat{p}}\) and \(\boldsymbol{\hat{q}}\) are the discrete vectors of momentum DOFs and strain DOFs, respectively. This formulation assumes constant material properties and therefore a constant \(\boldsymbol{Q}\) matrix. Finally, substituting Equations (23) and (24) into Equation (22) we get the matrix system of equations,

$$ \begin{bmatrix} -\boldsymbol{M}_{p} & \boldsymbol{0} \\ \boldsymbol{0} & -\boldsymbol{M_{q}} \\ \end{bmatrix} \frac{\partial }{\partial t} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \end{bmatrix} = \begin{bmatrix} \boldsymbol{0} & \boldsymbol{K}_{p} + \boldsymbol{L}_{p} \\ \boldsymbol{K_{q}} + \boldsymbol{L_{q}} & \boldsymbol{0} \\ \end{bmatrix} \begin{bmatrix} \frac{1}{\rho _{w}} \boldsymbol{I} & \boldsymbol{0} \\ \boldsymbol{0} & k_{w}\boldsymbol{I} \\ \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \end{bmatrix} \,. $$
(25)

In Sect. 2.3 we prove that Equation (25) can be written in two different (one for Dirichlet and one for Neumann boundary conditions) canonical PH forms and that it represents a non-degenerate Stokes-Dirac structure.

2.2 Discrete Conservation of Power Proof

To proceed with a conservation of power proof we first define the approximate Hamiltonian, \(\hat{H}\), and Hamiltonian density, \(\hat{\mathcal{H}}\) in the same way as the exact functions that were defined in Equations (4) and (5),

$$ \hat{H}(p, \boldsymbol{q}) = \int _{\Omega } \hat{\mathcal{H}}(p, \boldsymbol{q})dV = \int _{\Omega } \bigg(\frac{1}{2\rho _{w}} p^{2} + \frac{1}{2}k_{w} \boldsymbol{q} \cdot \boldsymbol{q}\bigg) dV \,. $$
(26)

The variables \(p\) and \(\boldsymbol{q}\) have the same basis functions as \(e_{p}\) and \(\boldsymbol{e}_{\boldsymbol{q}}\) respectively. Substituting in the discrete vectors, \(\boldsymbol{\hat{p}}\) and \(\boldsymbol{\hat{q}}\) and their corresponding basis functions gives

$$\begin{aligned} \hat{H}(\hat{p}, \boldsymbol{\hat{q}}) & = \int _{\Omega } \bigg( \frac{1}{2\rho _{w}} \boldsymbol{\hat{p}}^{T} \boldsymbol{\varphi }_{p} \boldsymbol{\varphi }_{p}^{T} \boldsymbol{\hat{p}} + \frac{1}{2}k_{w} \boldsymbol{\hat{q}}^{T} \boldsymbol{\varphi }_{\boldsymbol{q}} \boldsymbol{\varphi }_{\boldsymbol{q}}^{T} \boldsymbol{\hat{q}} \bigg) dV \\ & = \frac{1}{2\rho _{w}} \boldsymbol{\hat{p}}^{T} \boldsymbol{M}_{p} \boldsymbol{\hat{p}} + \frac{1}{2}k_{w} \boldsymbol{\hat{q}}^{T} \boldsymbol{M}_{q} \boldsymbol{\hat{q}} \,. \end{aligned}$$
(27)

The relationship between the approximate state variable functions and the approximate effort functions from Equation (16) can be found by taking the partial derivative of \(\hat{\mathcal{H}}(p, \boldsymbol{q})\) with respect to \(p\) and \(\boldsymbol{q}\).

$$ e_{p} = \partial _{p} \hat{\mathcal{H}} = \frac{p}{\rho _{w}} \,, \qquad \boldsymbol{e}_{\boldsymbol{q}} = \partial _{\boldsymbol{q}} \hat{\mathcal{H}} = k_{w} \boldsymbol{q} \,. $$
(28)

The corresponding relation between discrete effort variables and state vectors is

$$ \boldsymbol{\hat{e}}_{p} = \frac{\boldsymbol{\hat{p}}}{\rho _{w}} \,, \qquad \boldsymbol{\hat{e}}_{\boldsymbol{q}} = k_{w} \boldsymbol{\hat{q}}\,. $$
(29)

To retain the structure of the continuous system, the discretised equations must have the same energy-conserving structure as the continuous equations. Therefore, the rate of change of the Hamiltonian must only depend on the boundary variables, as in Theorem 2.0.1. The following conservation of energy proof is influenced by the thesis of Kotyczka [22] and the paper by Cardoso-Ribeiro [11].

Theorem 2.2.1

The rate of change of the Hamiltonian for the discrete system (\(\dot{\hat{H}}\)) is a dual product of the boundary efforts (\(\boldsymbol{\hat{e}}_{pb}\), \(\boldsymbol{\hat{e}}_{\boldsymbol{q}b}\)) and boundary flows (\(\boldsymbol{\hat{f}}_{pb}\), \(\boldsymbol{\hat{f}}_{\boldsymbol{q}b}\)) in either \(p\) or \(\boldsymbol{q}\). Put more simply, the change of energy in the domain equals the energy flow through the domain boundary.

$$ \dot{\hat{H}} = -\boldsymbol{\hat{e}}_{pb}^{T} \boldsymbol{\hat{f}}_{pb} = - \boldsymbol{\hat{e}}_{\boldsymbol{q}b}^{T} \boldsymbol{\hat{f}}_{\boldsymbol{q}b} \,. $$

To prove Theorem 2.2.1 a mapping between general variables and boundary variables must be formulated. Following the work of [22], we decompose \(\boldsymbol{L}_{p}\) into \(\boldsymbol{T}_{p}\), \(\boldsymbol{S_{q}}\) and \(\boldsymbol{L_{q}}\) into \(\boldsymbol{T_{q}}\), \(\boldsymbol{S}_{p}\), as shown,

$$ \boldsymbol{L}_{p} = \boldsymbol{T}_{p}^{T} \boldsymbol{S_{q}} \,, \qquad \boldsymbol{L_{q}} = \boldsymbol{T_{q}}^{T} \boldsymbol{S}_{p} \,. $$
(30)

The matrix \(\boldsymbol{T}_{p}\) is simply a mapping from all \(\boldsymbol{\hat{e}}_{p}\) DOFs of the mesh to the DOFs that have \(\boldsymbol{\hat{e}}_{p}\) defined at the boundary. Similarly, \(\boldsymbol{T_{q}}\) is a mapping from all \(\boldsymbol{\hat{e}}_{\boldsymbol{q}}\) DOFs of the mesh to the DOFs that have \(\boldsymbol{\hat{e}_{q}}\) defined at the boundary. Both \(\boldsymbol{T}_{p}\) and \(\boldsymbol{T_{q}}\) are made of zeroes and ones and are semi-orthogonal, therefore \(\boldsymbol{T}_{p} \boldsymbol{T}_{p}^{T} = \boldsymbol{I}_{Np}\) and \(\boldsymbol{T_{q}} \boldsymbol{T_{q}}^{T} = \boldsymbol{I}_{Nq}\). For first order Lagrange and Raviart-Thomas elements, the identity matrix \(\boldsymbol{I}_{Np}\) has a number of rows and columns equal to the number of nodes (\(N_{p}\)) and \(\boldsymbol{I}_{Nq}\) has a number of rows and columns equal to the number of edges (\(N_{\boldsymbol{q}}\)). Calculation of \(\boldsymbol{S}_{p}\) and \(\boldsymbol{S_{q}}\) is done trivially by using the semi-orthogonality of \(\boldsymbol{T}_{p/\boldsymbol{q}}\) and Equation (30), giving \(\boldsymbol{S_{q}} = \boldsymbol{T}_{p} \boldsymbol{L}_{p}\) and \(\boldsymbol{S}_{p} = \boldsymbol{T_{q}} \boldsymbol{L_{q}}\). The matrix \(\boldsymbol{S}_{p}\) is a mapping from momentum efforts \(\boldsymbol{\hat{e}}_{p}\) to boundary strain flows \(\boldsymbol{\hat{f}}_{\boldsymbol{q}b}\). Similarly, \(\boldsymbol{S_{q}}\) is a mapping from stress efforts \(\boldsymbol{\hat{e}_{q}}\) to boundary velocity flows \(\boldsymbol{\hat{f}}_{pb}\). The matrix mappings of \(\boldsymbol{T}_{p/\boldsymbol{q}}\) and \(\boldsymbol{S}_{p/\boldsymbol{q}}\) are summarised as

$$ \begin{aligned} & \boldsymbol{\hat{e}}_{pb} = \boldsymbol{T}_{p} \boldsymbol{\hat{e}}_{p} \,, \qquad \boldsymbol{\hat{e}}_{\boldsymbol{q}b} = \boldsymbol{T_{q}} \boldsymbol{\hat{e}_{q}} \,, \\ & \boldsymbol{\hat{f}}_{pb} = \boldsymbol{S_{q}} \boldsymbol{\hat{e}_{q}} \,, \qquad \boldsymbol{\hat{f}}_{\boldsymbol{q}b} = \boldsymbol{S}_{p} \boldsymbol{\hat{e}}_{p} \,. \end{aligned} $$
(31)

To prove Theorem 2.2.1 we need a small lemma.

Lemma 2.2.2

Lemma 1 [24]

$$ (\boldsymbol{K}_{p} + \boldsymbol{L}_{p}) + (\boldsymbol{K_{q}} + \boldsymbol{L_{q}})^{T} = \boldsymbol{L}_{p} \,. $$

Proof

$$ \begin{aligned} & (\boldsymbol{K_{q}} + \boldsymbol{L_{q}})^{T} = \bigg( -\langle \nabla \cdot \boldsymbol{\varphi }_{\boldsymbol{q}} | \boldsymbol{\varphi }_{p} \rangle _{ \Omega } + \langle \boldsymbol{\psi _{q}} | \boldsymbol{\psi }_{p} \rangle _{\partial \Omega } \bigg)^{T} \,, \\ & (\boldsymbol{K_{q}} + \boldsymbol{L_{q}})^{T} = \bigg( -\langle \nabla \cdot \boldsymbol{\varphi }_{\boldsymbol{q}} | \boldsymbol{\varphi }_{p} \rangle _{\Omega } + \langle ( \boldsymbol{\varphi _{q}} \cdot \boldsymbol{n}) | \boldsymbol{\psi }_{p} \rangle _{\partial \Omega } \bigg)^{T} \,. \end{aligned} $$

Applying integration by parts in reverse then gives

$$ \begin{aligned} (\boldsymbol{K_{q}} + \boldsymbol{L_{q}})^{T} & = \bigg( \langle \boldsymbol{\varphi }_{\boldsymbol{q}} | \nabla \boldsymbol{\varphi }_{p} \rangle _{\Omega } \bigg)^{T} \\ & = \langle \nabla \boldsymbol{\varphi }_{p} | \boldsymbol{\varphi }_{\boldsymbol{q}} \rangle _{ \Omega } \\ & = -\boldsymbol{K}_{p} \,, \end{aligned} $$
(32)

therefore,

$$ (\boldsymbol{K}_{p} + \boldsymbol{L}_{p}) + (\boldsymbol{K_{q}} + \boldsymbol{L_{q}})^{T} = (\boldsymbol{K}_{p} + \boldsymbol{L}_{p}) - \boldsymbol{K}_{p} = \boldsymbol{L}_{p} \,. $$

 □

Proof of Theorem 2.2.1

We start by taking the time differential of the Hamiltonian in the usual way.

$$ \begin{aligned} \dot{H} & = \int _{\Omega } \bigg( \frac{\partial H}{\partial p} \frac{\partial p}{\partial t} + \frac{\partial H}{\partial \boldsymbol{q}} \cdot \frac{\partial \boldsymbol{q}}{\partial t} \bigg) dV \\ & = - \langle e_{p} | f_{p} \rangle _{\Omega } - \langle \boldsymbol{e_{q}} | \boldsymbol{f_{q}} \rangle _{\Omega } \,. \end{aligned} $$

The approximate efforts and flows from Equations (15) and (16) are then substituted for the effort and flow functions to give the discrete Hamiltonian rate of change

$$ \begin{aligned} \dot{\hat{H}} & = -\boldsymbol{\hat{e}}_{p}^{T} \langle \boldsymbol{\varphi }_{p} | \boldsymbol{\varphi }_{p} \rangle _{\Omega } \boldsymbol{\hat{f}}_{p} - \boldsymbol{\hat{e}_{q}}^{T} \langle \boldsymbol{\varphi _{q}} | \boldsymbol{\varphi _{q}} \rangle _{\Omega } \boldsymbol{\hat{f}_{q}} \\ & = -\boldsymbol{\hat{e}}_{p}^{T} \boldsymbol{M}_{p} \boldsymbol{\hat{f}}_{p} - \boldsymbol{\hat{e}_{q}}^{T} \boldsymbol{M_{q}} \boldsymbol{\hat{f}_{q}} \,. \end{aligned} $$

Equation (22) is then used to give

$$ \begin{aligned} \dot{\hat{H}} & = - \boldsymbol{\hat{e}}_{p}^{T} (\boldsymbol{K}_{p} + \boldsymbol{L}_{p}) \boldsymbol{\hat{e}_{q}} - \boldsymbol{\hat{e}_{q}}^{T} (\boldsymbol{K_{q}} + \boldsymbol{L_{q}}) \boldsymbol{\hat{e}}_{p} \\ & = -\boldsymbol{\hat{e}}_{p}^{T} (\boldsymbol{K}_{p} + \boldsymbol{L}_{p}) \boldsymbol{\hat{e}_{q}} - \boldsymbol{\hat{e}}_{p}^{T} (\boldsymbol{K_{q}} + \boldsymbol{L_{q}})^{T} \boldsymbol{\hat{e}_{q}} \,. \end{aligned} $$

Lemma 2.2.2 can now be used. Following that, the definitions of the boundary flows and efforts in Equation (31) can be used to complete the first half of the proof,

$$\begin{aligned} \dot{\hat{H}} & = -\boldsymbol{\hat{e}}_{p}^{T} \boldsymbol{L}_{p} \boldsymbol{\hat{e}_{q}} \\ & = -\boldsymbol{\hat{e}}_{p}^{T} \boldsymbol{T}_{p}^{T} \boldsymbol{S_{q}} \boldsymbol{\hat{e}_{q}} \\ & = -(\boldsymbol{T}_{p} \boldsymbol{\hat{e}}_{p})^{T} (\boldsymbol{S_{q}} \boldsymbol{\hat{e}_{q}}) \\ & = -\boldsymbol{\hat{e}}_{pb}^{T} \boldsymbol{\hat{f}}_{pb} \,, \end{aligned}$$
(33)

and identically for the second half of the proof,

$$ \begin{aligned} \dot{\hat{H}} & = -\boldsymbol{\hat{e}}_{p}^{T} \boldsymbol{L}_{p} \boldsymbol{\hat{e}_{q}} \\ & = -\boldsymbol{\hat{e}}_{p}^{T} \boldsymbol{L_{q}}^{T} \boldsymbol{\hat{e}_{q}} \\ & = -\boldsymbol{\hat{e}_{q}}^{T} \boldsymbol{L_{q}} \boldsymbol{\hat{e}}_{p} \\ & = -\boldsymbol{\hat{e}_{q}}^{T} \boldsymbol{T_{q}}^{T} \boldsymbol{S}_{p} \boldsymbol{\hat{e}}_{p} \\ & = -(\boldsymbol{T_{q}} \boldsymbol{\hat{e}_{q}})^{T} (\boldsymbol{S}_{p} \boldsymbol{\hat{e}}_{p}) \\ & = -\boldsymbol{\hat{e}}_{\boldsymbol{q}b}^{T} \boldsymbol{\hat{f}}_{\boldsymbol{q}b} \,. \end{aligned} $$

 □

Corollary 2.2.3

The rate of change of the Hamiltonian of the discrete system conserves energy in the same way as in Theorem 2.0.1, for the continuous system.

Proof

Beginning with Equation (33) and substituting in \(\boldsymbol{L}_{p}\) from Equation (20) gives

$$\begin{aligned} \dot{\hat{H}} & = - \boldsymbol{\hat{e}}_{p}^{T} \boldsymbol{L}_{p} \boldsymbol{\hat{e}_{q}} \\ & = - \int _{\partial \Omega } \boldsymbol{\hat{e}}_{p}^{T} \boldsymbol{\psi }_{p} \boldsymbol{\psi }_{\boldsymbol{q}}^{T} \boldsymbol{\hat{e}_{q}} ds \end{aligned}$$

Substituting Equation (18) gives

$$ \dot{\hat{H}} = - \int _{\partial \Omega } e_{p} (\boldsymbol{e}_{\boldsymbol{q}} \cdot \boldsymbol{n})ds \,, $$

which confirms that the rate of change of the discrete system Hamiltonian is a function of the efforts at the boundary. This correctly coincides with Theorem 2.0.1. □

The approximate system inputs and outputs are thus defined in the same way as Equations (9) and (10), either

$$ u_{\boldsymbol{q}} = -\boldsymbol{e}_{\boldsymbol{q}} \cdot \boldsymbol{n} |_{\partial \Omega }\,, \qquad y_{p} = e_{p} |_{\partial \Omega } \,, $$
(34)

or

$$ y_{\boldsymbol{q}} = \boldsymbol{e}_{\boldsymbol{q}} \cdot \boldsymbol{n} |_{\partial \Omega } \,, \qquad u_{p} = - e_{p} |_{\partial \Omega } \,. $$
(35)

2.3 Stokes-Dirac Structure and the Canonical Port-Hamiltonian Form

In Equation (22) we introduce the model in a non-canonical PH form, however, in this section we prove that Equation (22) is equivalent to a structure-preserving coupling of canonical Port-Hamiltonian forms. This also proves that the discretisation ensures a Stokes-Dirac structure [43], therefore, conserving the structure of the continuous equations, Equation (7). To formulate the system in an input-state-output PH form, we first define the input and output functions at the boundary corresponding to Equations (34) and (35) in terms of their discrete vectors (\(\boldsymbol{\hat{u}}_{\boldsymbol{q}}\), \(\boldsymbol{\hat{y}}_{p}\), \(\boldsymbol{\hat{u}}_{p}\), \(\boldsymbol{\hat{y}}_{\boldsymbol{q}}\)) and basis functions (\(\boldsymbol{\theta }_{\boldsymbol{q}}\), \(\boldsymbol{\theta }_{p}\)).

$$ \begin{alignedat}{3} & u_{\boldsymbol{q}} &&= \langle \boldsymbol{\hat{e}}_{\boldsymbol{q}} , \boldsymbol{\psi }_{\boldsymbol{q}} \rangle &&= \langle \boldsymbol{\hat{u}}_{\boldsymbol{q}} , \boldsymbol{\theta }_{\boldsymbol{q}} \rangle \,, \\ & y_{p} &&= \langle \boldsymbol{\hat{e}}_{p} , \boldsymbol{\psi }_{p} \rangle &&= \langle \boldsymbol{\hat{y}}_{p} , \boldsymbol{\theta }_{p} \rangle \,, \end{alignedat} $$
(36)
$$ \begin{alignedat}{3} & u_{p} &&= \langle \boldsymbol{\hat{e}}_{p} , \boldsymbol{\psi }_{p} \rangle &&= \langle \boldsymbol{\hat{u}}_{p} , \boldsymbol{\theta }_{p} \rangle \,, \\ & y_{\boldsymbol{q}} &&= \langle \boldsymbol{\hat{e}}_{\boldsymbol{q}} , \boldsymbol{\psi }_{\boldsymbol{q}} \rangle &&= \langle \boldsymbol{\hat{y}}_{\boldsymbol{q}} , \boldsymbol{\theta _{q}} \rangle \,, \end{alignedat} $$
(37)

where \(\boldsymbol{\theta }_{p}\) and \(\boldsymbol{\theta }_{\boldsymbol{q}}\) contain the entries of \(\boldsymbol{\psi }_{p}\) and \(\boldsymbol{\psi }_{\boldsymbol{q}}\) corresponding to the boundary DOFs. The first canonical PH form for Neumann boundary conditions can be set up by using

$$ (\boldsymbol{K_{q}} + \boldsymbol{L_{q}})^{T} = -\boldsymbol{K}_{p} \,, $$
(38)

which was formulated in Equation (32). Inserting the transpose of Equation (38) into Equation (22) gives

$$ \begin{bmatrix} \boldsymbol{M}_{p} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{M_{q}} \\ \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{f}}_{p} \\ \boldsymbol{\hat{f}}_{\boldsymbol{q}} \\ \end{bmatrix} = \begin{bmatrix} \boldsymbol{0} & \boldsymbol{K}_{p} + \boldsymbol{L}_{p} \\ -\boldsymbol{K_{p}}^{T} & \boldsymbol{0} \\ \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{e}}_{p} \\ \boldsymbol{\hat{e}}_{\boldsymbol{q}} \\ \end{bmatrix} \,. $$
(39)

We then multiply the output equation in Equation (34) by the \(v_{yq} = \langle \boldsymbol{\hat{v}}_{y\boldsymbol{q}} | \boldsymbol{\theta }_{\boldsymbol{q}} \rangle _{\partial \Omega _{N}}\) trial function, where a subscript \(N\) denotes a Neumann boundary. Following this, we integrate over the boundary then use the fundamental theorem of variational calculus to get,

v ˆ y q Ω N θ q y p d s N = v ˆ y q Ω N θ q e p | Ω N d s N v ˆ y q Ω N θ q θ p T y ˆ p d s N = v ˆ y q Ω N θ q ψ p T e ˆ p d s N M y p y ˆ p = B q b T e ˆ p
(40)

where \(\boldsymbol{M}_{yp} = \langle \boldsymbol{\theta _{q}} | \boldsymbol{\theta }_{p} \rangle _{ \partial \Omega _{N}}\). Also, \(\boldsymbol{B}_{\boldsymbol{q}b}\) is defined as,

$$ \boldsymbol{B}_{\boldsymbol{q}b} \boldsymbol{\hat{u}}_{\boldsymbol{q}} = -\boldsymbol{L}_{p} \boldsymbol{\hat{e}}_{ \boldsymbol{q}} \,, \qquad \boldsymbol{B}_{\boldsymbol{q}b} = \langle \boldsymbol{\psi }_{p} | \boldsymbol{\theta }_{\boldsymbol{q}} \rangle _{\partial \Omega _{N}} \,. $$
(41)

Combining Equations (39) to (41) gives the PH canonical form,

$$ \renewcommand{\arraystretch}{1.2} \begin{bmatrix} \boldsymbol{M}_{p} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{M_{q}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{M}_{yp} \\ \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{f}}_{p} \\ \boldsymbol{\hat{f}}_{\boldsymbol{q}} \\ \boldsymbol{\hat{y}}_{p} \\ \end{bmatrix} = \begin{bmatrix} \boldsymbol{0} & \boldsymbol{K}_{p} & -\boldsymbol{B}_{\boldsymbol{q}b} \\ -\boldsymbol{K}_{p}^{T} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{B}_{\boldsymbol{q}b}^{T} & \boldsymbol{0} & \boldsymbol{0} \\ \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{e}}_{p} \\ \boldsymbol{\hat{e}}_{\boldsymbol{q}} \\ \boldsymbol{\hat{u}}_{\boldsymbol{q}} \end{bmatrix} \,. $$
(42)

Including the dynamic and constitutive laws from Equations (23) and (24) gives the input-state-output PH form,

$$ \renewcommand{\arraystretch}{1.2} \begin{bmatrix} -\boldsymbol{M}_{p} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{0} & -\boldsymbol{M_{q}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{M}_{yp} \\ \end{bmatrix} \begin{bmatrix} \partial _{t} \boldsymbol{\hat{p}} \\ \partial _{t} \boldsymbol{\hat{q}} \\ \boldsymbol{\hat{y}}_{p} \\ \end{bmatrix} = \begin{bmatrix} \boldsymbol{0} & \boldsymbol{K}_{p} & -\boldsymbol{B}_{\boldsymbol{q}b} \\ -\boldsymbol{K}_{p}^{T} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{B}_{\boldsymbol{q}b}^{T} & \boldsymbol{0} & \boldsymbol{0} \\ \end{bmatrix} \begin{bmatrix} \frac{1}{\rho _{w}} \boldsymbol{I} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{0} & k_{w}\boldsymbol{I} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{I} \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \boldsymbol{\hat{u}}_{\boldsymbol{q}} \end{bmatrix} \,, $$
$$ \renewcommand{\arraystretch}{1.2} \boldsymbol{M}_{\boldsymbol{q}b} \begin{bmatrix} \partial _{t} \boldsymbol{\hat{p}} \\ \partial _{t} \boldsymbol{\hat{q}} \\ \boldsymbol{\hat{y}}_{p} \\ \end{bmatrix} = \boldsymbol{J}_{\boldsymbol{q}b} \boldsymbol{Q}_{\boldsymbol{q}b} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \boldsymbol{\hat{u}}_{\boldsymbol{q}} \end{bmatrix} \,, $$
(43)

where \(\boldsymbol{M}_{\boldsymbol{q}b}\) is the mass matrix, \(\boldsymbol{J}_{\boldsymbol{q}b}\) is the skew-symmetric matrix, and \(\boldsymbol{Q}_{\boldsymbol{q}b}\) is the constitutive law matrix. The infinite-dimensional canonical form corresponding to the discretised canonical form in Equation (42) is

$$ \renewcommand{\arraystretch}{1.2} \boldsymbol{\mathcal{M}}_{\boldsymbol{q}b} \begin{bmatrix} f_{p} \\ \boldsymbol{f}_{\boldsymbol{q}} \\ y_{p} \\ \end{bmatrix} = \boldsymbol{\mathcal{J}}_{\boldsymbol{q}b} \begin{bmatrix} e_{p} \\ \boldsymbol{e}_{\boldsymbol{q}} \\ u_{\boldsymbol{q}} \end{bmatrix} \,, $$
(44)

where, \(\boldsymbol{\mathcal{M}}_{\boldsymbol{q}b}\) is the mass operator and \(\boldsymbol{\mathcal{J}}_{\boldsymbol{q}b}\) is the skew-symmetric operator.

Technically, Equations (43) and (44) are canonical forms for domains with Neumann conditions only. In the following we formulate the canonical form for Dirichlet conditions. We take the transpose of Equation (38) and use the fact that \(\boldsymbol{L_{q}} = \boldsymbol{L}_{p}^{T}\) to give

$$ (\boldsymbol{K}_{p} + \boldsymbol{L}_{p})^{T} = -\boldsymbol{K}_{q} \,. $$
(45)

Equation (45) can be substituted into Equation (22) and the discretisation of \(y_{\boldsymbol{q}}\) can be done in the same way as for \(y_{p}\) in Equation (40) to give the Dirichlet boundary condition equivalent of Equation (42). This discrete canonical form is

$$ \renewcommand{\arraystretch}{1.2} \begin{bmatrix} \boldsymbol{M}_{p} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{M_{q}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{M}_{y\boldsymbol{q}} \\ \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{f}}_{p} \\ \boldsymbol{\hat{f}}_{\boldsymbol{q}} \\ \boldsymbol{\hat{y}}_{\boldsymbol{q}} \\ \end{bmatrix} = \begin{bmatrix} \boldsymbol{0} & -\boldsymbol{K}_{\boldsymbol{q}}^{T} & \boldsymbol{0} \\ \boldsymbol{K_{q}} & \boldsymbol{0} & -\boldsymbol{B}_{pb} \\ \boldsymbol{0} & \boldsymbol{B}_{pb}^{T} & \boldsymbol{0} \\ \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{e}}_{p} \\ \boldsymbol{\hat{e}}_{\boldsymbol{q}} \\ \boldsymbol{\hat{u}}_{p} \end{bmatrix} \,, $$
(46)

and the input-state-output PH form is

$$ \renewcommand{\arraystretch}{1.2} \begin{bmatrix} -\boldsymbol{M}_{p} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{0} & -\boldsymbol{M_{q}} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{M}_{y\boldsymbol{q}} \\ \end{bmatrix} \begin{bmatrix} \partial _{t} \boldsymbol{\hat{p}} \\ \partial _{t} \boldsymbol{\hat{q}} \\ \boldsymbol{\hat{y}}_{\boldsymbol{q}} \\ \end{bmatrix} = \begin{bmatrix} \boldsymbol{0} & -\boldsymbol{K}_{\boldsymbol{q}}^{T} & \boldsymbol{0} \\ \boldsymbol{K_{q}} & \boldsymbol{0} & -\boldsymbol{B}_{pb} \\ \boldsymbol{0} & \boldsymbol{B}_{pb}^{T} & \boldsymbol{0} \\ \end{bmatrix} \begin{bmatrix} \frac{1}{\rho _{w}} \boldsymbol{I} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{0} & k_{w} \boldsymbol{I} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{I} \end{bmatrix} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \boldsymbol{\hat{u}}_{p} \end{bmatrix} \,, $$
$$ \renewcommand{\arraystretch}{1.2} \boldsymbol{M}_{pb} \begin{bmatrix} \partial _{t} \boldsymbol{\hat{p}} \\ \partial _{t} \boldsymbol{\hat{q}} \\ \boldsymbol{\hat{y}}_{\boldsymbol{q}} \\ \end{bmatrix} = \boldsymbol{J}_{pb} \boldsymbol{Q}_{pb} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \boldsymbol{\hat{u}}_{p} \end{bmatrix} \,, $$
(47)

where \(\boldsymbol{M}_{y\boldsymbol{q}} = \langle \boldsymbol{\theta }_{p} | \boldsymbol{\theta }_{\boldsymbol{q}} \rangle _{\partial \Omega _{D}}\) and a subscript \(D\) denotes a Dirichlet boundary. The canonical PH form in Equation (47) has a mass matrix, \(\boldsymbol{M}_{pb}\), a skew-symmetric matrix, \(\boldsymbol{J}_{pb}\), and a constitutive law matrix, \(\boldsymbol{Q}_{pb}\). The interconnection matrix, \(\boldsymbol{B}_{pb}\) is defined as

$$ \boldsymbol{B}_{pb} \boldsymbol{\hat{u}}_{p} = - \boldsymbol{L}_{q} \boldsymbol{\hat{e}}_{p} \,, \qquad \boldsymbol{B}_{pb} = \langle \boldsymbol{\psi }_{\boldsymbol{q}} | \boldsymbol{\theta }_{p} \rangle _{\partial \Omega _{D}} \,. $$
(48)

The infinite-dimensional canonical form corresponding to Equation (46) is

$$ \renewcommand{\arraystretch}{1.2} \boldsymbol{\mathcal{M}}_{pb} \begin{bmatrix} f_{p} \\ \boldsymbol{f}_{\boldsymbol{q}} \\ y_{\boldsymbol{q}} \\ \end{bmatrix} = \boldsymbol{\mathcal{J}}_{pb} \begin{bmatrix} e_{p} \\ \boldsymbol{e}_{\boldsymbol{q}} \\ u_{p} \end{bmatrix} \,, $$
(49)

where, \(\boldsymbol{\mathcal{M}}_{pb}\) is the mass operator and \(\boldsymbol{\mathcal{J}}_{pb}\) is the skew-symmetric operator.

Equations (47) and (49) are only canonical PH forms for boundaries with Dirichlet conditions. For a domain with mixed boundaries, our system in Equation (25) needs to be equivalent to a canonical PH system, or in our case a combination of canonical PH systems. Any closed domain with mixed Neumann and Dirichlet boundary conditions can be subdivided into subdomains with only Neumann or only Dirichlet boundary conditions. This idea has been taken advantage of in Brugnoli et al.’s work [9], where the authors numerically segment the domain and apply PFEM to each section. Here the idea is only used conceptually to prove that our system in Equation (25) is equivalent to a combination of canonical input-state-output PH formulations and therefore, by the compositionality property, retains the Stokes-Dirac structure of the analytic equations, Equation (7). This means that mixed boundary conditions can be implemented in the weak form, as detailed in Sect. 3, and that the resulting system is a Stokes-Dirac structure. It is also important to note that our formulation is non-degenerate, due to \(\boldsymbol{M}_{p}\) and \(\boldsymbol{M}_{q}\) being full rank. The matrices turn out to be full rank because we use the same basis functions for effort and flow functions. Proposition 1 of Kotyczka’s paper [24], uses a similar compositionality argument to allow mixed boundary conditions and mixed causality at the boundaries. However, in Kotyczka’s work, the non-full-rank \(\boldsymbol{M}_{p}\) and \(\boldsymbol{M}_{q}\) matrices cause the requirement of user-defined parameters in-order to form a non-degenerate Stokes-Dirac structure.

Theorem 2.3.1

Equation (25) over any connected domain with Neumann and Dirichlet boundaries is equivalent to a structure-preserving combination of canonical PH systems in the form of Equations (44) and (49). (Kotyczka makes the same statement in Proposition. 1 of [24] for a different set of function spaces.)

Proof

First we subdivide the domain so that each connected Neumann boundary is in a domain denoted \(\Omega _{Ni}\) that does not connect or overlap with any \(\Omega _{Nj}\) \((j \neq i)\) and is not connected to any other external boundaries. A simple example of a subdivision is shown in Fig. 1. Each of the \(i\) subdomains has inputs and outputs split up into \(u_{\boldsymbol{q}i}\), \(y_{pi}\) at the external boundary, and \(u_{\boldsymbol{q}i}^{\mathit{int}}\), \(y_{pi}^{\mathit{int}}\) at the internal boundary. The remainder of the domain is therefore connected and only has Dirichlet boundary conditions, we denote this subdomain \(\Omega _{D}\).

Fig. 1
figure 1

Example of the subdivision of a domain with Neumann boundaries, \(\partial \Omega _{N}\), and Dirichlet boundaries, \(\partial \Omega _{D}\), showing boundary and interconnection inputs/outputs

The inputs and outputs of \(\Omega _{D}\) are split up into \(u_{pk}\), \(y_{\boldsymbol{q}k}\) at the external boundaries and \(u_{pi}^{\mathit{int}}\), \(y_{\boldsymbol{q}i}^{\mathit{int}}\) at the internal boundaries that border \(\Omega _{Ni}\). The canonical form of Equation (44) is used in the \(\Omega _{Ni}\) domains and Equation (49) is used in the \(\Omega _{D}\) domain. Note that the canonical forms are modified accordingly, to split the inputs and outputs into internal and external parts. The causal interconnection relations [6, 24] at each internal boundary can then be written as

$$ u_{pi}^{\mathit{int}} = -y_{pi}^{\mathit{int}} \,, \qquad u_{\boldsymbol{q}i}^{\mathit{int}} = y_{\boldsymbol{q}i}^{\mathit{int}} \,. $$
(50)

This ensures conservation of energy flow between the subdomains due to the power conserving inner product,

$$ \langle u_{pi}^{\mathit{int}} | y_{\boldsymbol{q}i}^{\mathit{int}} \rangle _{\partial \Omega _{i}^{\mathit{int}}} + \langle u_{\boldsymbol{q}i}^{\mathit{int}} | y_{pi}^{\mathit{int}} \rangle _{\partial \Omega _{i}^{\mathit{int}}} = 0\,. $$
(51)

Therefore, since each subdomain has a PH Stokes-Dirac structure, the power conserving interconnection ensures the total system is also a Stokes-Dirac structure by compositionality. Also, each subdomain has the correct canonical form for its Neumann or Dirichlet boundary conditions. Lastly, any connected domain is equivalent to a decomposition in the way we have described. The combination of these results proves that Equation (25) is equivalent to a structure-preserving combination of canonical PH forms for any connected domain with mixed boundary conditions. □

As will be seen in Sect. 6 the infinite-dimensional canonical form in Equation (49) can be used to determine the power conserving interconnection between other canonical PH systems, where the interconnection enforces a Dirichlet condition on the wave domain boundary. Similarly, the infinite-dimensional canonical form of Equation (44) can be used to find the power conserving interconnection for connections that assign a Neumann condition on the wave domain boundary. Due to the conclusion of Theorem 2.3.1, that any domain is equivalent to a subdivision of subdomains with either the canonical form of Equation (49) or Equation (44), both Dirichlet and Neumann interconnections can be implemented on a domain. This means that the system developed in this paper can have mixed boundary conditions as well as mixed causality interconnections between other PH systems.

3 Wave Equation FEniCS Implementation

In this section, the FEniCS implementation of Equations (14a) and (14b) on a rectangle domain is detailed. Appendix A supplements this section by detailing the Python code for the implementation. A schematic of the wave domain is shown in Fig. 2.

Fig. 2
figure 2

Rectangle wave domain diagram

An unstructured, triangular mesh was created over the domain with FEniCS meshing software. The boundary conditions on the domain are set as

p L =p(0,y,t)= { 10 sin ( 8 π t ) t < 0.25 0 t 0.25 ,
(52a)
p R =p( L x ,y,t)=0,
(52b)
q M =(q(x,0,t)n)=(q(x, L y ,t)n)=0,
(52c)

where the inputs in Equations (34) and (35) for the left, right, and middle boundaries are defined respectively as

$$ u_{pL} = -\frac{p_{L}}{\rho _{w}} \,, \quad u_{pR} = - \frac{p_{R}}{\rho _{w}} \,, \quad u_{\boldsymbol{q}M} = -k_{w} q_{M} \,. $$
(53)

Dirichlet conditions are applied to both the left and the right boundaries. The left boundary is set as an input condition whereas the right boundary is given a fixed zero value. The top and bottom boundaries have a zero-flux Neumann condition applied. Separating the boundary terms in Equations (14a) and (14b) for each boundary condition and reverting to integral rather than inner product notation gives

Ω v p f p dV= Ω v p e q dV+ Ω L v p ( e q n)d s L
(54a)
+ Ω R v p ( e q n ) d s R + Ω M v p ( e q n ) d s M , Ω v q f q d V = Ω ( v q ) e p d V + Ω L ( v q n ) e p d s L + Ω R ( v q n ) e p d s R + Ω M ( v q n ) e p d s M .
(54b)

In Equations (54a) and (54b), the terms inside the boundary integrals are evaluated at their respective boundary. Substituting the state variables \(f_{p} = -\dot{p}\), \(\boldsymbol{f_{q}} = -\dot{\boldsymbol{q}}\), \(e_{p} = p/\rho _{w} \), \(\boldsymbol{e_{q}} = k_{w} \boldsymbol{q}\) and the boundary terms from Equations (52a)–(52c) gives

Ω v p p ˙ dV= k w Ω v p qdV+ k w Ω L v p (qn)d s L
(55a)
+ k w Ω R v p ( q n ) d s R + k w Ω M v p q M d s M , Ω v q q ˙ d V = 1 ρ w Ω ( v q ) p d V + 1 ρ w Ω L ( v q n ) p L d s L + 1 ρ w Ω R ( v q n ) p R d s R + 1 ρ w Ω M ( v q n ) p d s M .
(55b)

These equations can be implemented in FEniCS, which automatically generates a matrix system of equations in the form of Equation (25). However, to solve these equations the system must also be discretised in time. Symplectic time integration schemes conserve the symplectic structure of the continuous equations and approximately conserve the Hamiltonian, therefore, they are the natural choice for the temporal discretisation. The symplectic Euler (SE) time integration scheme is applied to Equations (55a) and (55b) to give

Ω v p p p m Δ t dV= k w Ω v p q m dV+ k w Ω L v p ( q m n)d s L
(56a)
+ k w Ω R v p ( q m n ) d s R + k w Ω M v p q M d s M , Ω v q q q m Δ t d V = 1 ρ w Ω ( v q ) p d V + 1 ρ w Ω L ( v q n ) p L d s L + 1 ρ w Ω R ( v q n ) p R d s R + 1 ρ w Ω M ( v q n ) p d s M ,
(56b)

where the \(m\) superscript denotes the variable at the previous time step. The \(L\), \(R\), and \(M\) subscripts denote variables at the left, right, and middle boundaries, respectively. The SE scheme combines an explicit step for Equation (56a) and an implicit step for Equation (56b). When the Hamiltonian is separable the SE scheme is semi-explicit, meaning Equation (56b) could be solved explicitly after the solution of Equation (56a). However, due to the ease of implementation in FEniCS, the equations are solved in one implicit step. By Theorem 2.2.1, Equations (55a) and (55b) conserve the Hamiltonian. Combining this with SE integration gives a discrete system that retains the Hamiltonian structure of the continuum equations and conserves energy for large times, as further discussed in Sect. 3.1.

The energy bound on symplectic methods is, in general, proportional to \(\mathcal{O}((\Delta t)^{r})\), where \(r\) is the order of the time integration scheme [20]. To compare the energy bound between different order methods, a second-order symplectic scheme, the Störmer-Verlet (SV) method [19] is also implemented,

Ω v q q 1 / 2 q m 0.5 Δ t dV= 1 ρ w Ω ( v q ) p m dV+ 1 ρ w Ω L ( v q n) p L m d s L
(57a)
+ 1 ρ w Ω R ( v q n ) p R m d s R + 1 ρ w Ω M ( v q n ) p m d s M , Ω v p p p m Δ t d V = k w Ω v p q 1 / 2 d V + k w Ω L v p ( q 1 / 2 n ) d s L
(57b)
+ k w Ω R v p ( q 1 / 2 n ) d s R + k w Ω M v p q M 1 / 2 d s M , Ω v q q q 1 / 2 0.5 Δ t d V = 1 ρ w Ω ( v q ) p d V + 1 ρ w Ω L ( v q n ) p L d s L + 1 ρ w Ω R ( v q n ) p R d s R + 1 ρ w Ω M ( v q n ) p d s M .
(57c)

Solving Equations (57a)–(57c) requires two system of equation solves per time step, Equation (57a) is solved to get \(\boldsymbol{q}^{1/2}\) then Equations (57b) and (57c) are solved for \(\boldsymbol{q}\) and \(p\). Although in the general case the energy residual is bounded for symplectic methods, since the example we are modelling is linear we can improve this result and get exact energy conservation. We do this with the symplectic midpoint (SM) method, which conserves all quadratic invariants for linear systems [20]. The variational form of the SM scheme is

Ω v p p p m Δ t dV= k w Ω v p ( q m + q ) 2 dV+ k w Ω L v p ( ( q m + q ) 2 n)d s L
(58a)
+ k w Ω R v p ( ( q m + q ) 2 n ) d s R + k w Ω M v p ( q M m + q M ) 2 d s M , Ω v q q q m Δ t d V = 1 ρ w Ω ( v q ) ( p m + p ) 2 d V + 1 ρ w Ω L ( v q n ) ( p L m + p L ) 2 d s L + 1 ρ w Ω R ( v q n ) ( p R m + p R ) 2 d s R + 1 ρ w Ω M ( v q n ) ( p m + p ) 2 d s M .
(58b)

3.1 Wave Results

In this section, the model that is detailed in Sect. 3 and proven to conserve energy by Theorem 2.2.1 has been implemented with a range of different time integration schemes. Our method, which has a weak Dirichlet boundary condition implementation is compared to an implementation with Dirichlet boundary conditions implemented in the typical strong form. This is done to show that the naive setting of boundary conditions in a strong manner is detrimental to energy conservation. The strong Dirichlet implementation modifies the matrix system of equations generated by FEniCS to directly enforce the boundary condition values. This differs from our weak boundary Dirichlet implementation, where we apply the boundary conditions by specifying the boundary integral terms in Equations (55a) and (55b). A detailed example of the different boundary condition implementations in FEniCS is shown in Appendix A.

For the wave equation in PH form, setting \(p\) at the boundary is a Dirichlet condition, equivalent to setting \(\rho _{w} e_{p}\), and setting (\(\boldsymbol{q} \cdot \boldsymbol{n}\)) is a Neumann condition, equivalent to setting \(\frac{1}{k_{w}} (\boldsymbol{e}_{\boldsymbol{q}} \cdot \boldsymbol{n})\). The reason that we can implement Dirichlet and Neumann conditions in the weak form is because we integrate both Equations (13a) and (13b) by parts, giving boundary terms for Dirichlet and Neumann conditions in Equations (55a) and (55b). This approach differs from the PFEM of Cardoso-Ribeiro [10], where integration by parts is only used on a subset of the governing equations. Our approach thus has the advantage of allowing mixed boundary conditions without the need for Lagrange multipliers. Therefore, our method results in a matrix system of equations that can be solved as an ordinary differential equation (ODE), rather than a differential algebraic equation (DAE), which is easier to solve in general. All methods in this section use a time step of \(\Delta t = 5\times 10^{-4}\). Figure 3 shows the resulting Hamiltonian, \(\hat{H}\), for the input in Equations (52a)–(52c). The Hamiltonian is expected to be constant after \(0.25\, s\), because the input boundary condition is set to zero, therefore, no energy flows into or out of the domain.

Fig. 3
figure 3

(a) Hamiltonian for different time integration schemes and for strong and weak boundary condition implementations. (b) Zoomed in view. IE=Implicit Euler, EE=Explicit Euler, SE=Symplectic Euler, EH=Explicit Heun, SV=Störmer-Verlet, SM=Symplectic (Implicit) Midpoint

In Fig. 3(a) we show that the implicit Euler (IE) scheme incorrectly dissipates energy and the explicit Euler (EE) scheme has a fictitious increase in energy, resulting in instability. At \(t \approx 0.9\, s\) the SE integration schemes for strong and weak boundary conditions show an undesirable non-constant Hamiltonian. A zoomed-in image of the non-constant behaviour is also shown in Fig. 3(b). The bump at \(t \approx 0.9\, s\) is likely due to there being high-order dynamics when the wavefront approaches the right boundary that are not accounted for in the first-order SE scheme. To remedy this situation, three second-order integration schemes are implemented, Explicit Heun’s (EH) (also called improved Euler [39]), SV and SM. All of these methods drastically decrease the bump at \(t \approx 0.9\, s\). It should be noted that decreasing the time step of the first-order methods also has the same effect of decreasing the bump (not shown). Interestingly, EH removes the bump completely, however, SV does not. SM also removes the bump completely because the SM scheme conserves quadratic invariants exactly for linear systems [20].

Figure 3(b) shows that for SE and SV the Hamiltonian oscillates about a conserved average Hamiltonian. This plot also shows that SV has an approximately constant Hamiltonian (apart from the aforementioned bump at \(t \approx 0.9\, s\)), whereas EH has a gradually increasing Hamiltonian, indicating that energy is not conserved for long times. For SV, however, the Hamiltonian oscillates about a conserved value and therefore, is conserved for long times. The bound on the oscillations also converges towards the conserved value as the time step is decreased [20]. The energy bound for SE and SV is likely higher at the bump due to the reflecting boundary. This would hint that the non-perfect energy conservation of SE and SV is heavily influenced by the boundary and not so much by the internal domain. The SM scheme has a perfectly flat Hamiltonian after \(0.25\, s\), which is the expected result, again due to the conservation of quadratic invariants.

One problem of the first-order SE weak method in Fig. 3 is its oscillatory behaviour. These oscillations may be due to applying an essential boundary condition (EBC) weakly, without a penalty method. Typically EBC’s are applied with a penalty method such as Nitsche [25, 30], however, according to Scovazzi, penalty methods are not required due to the hyperbolic nature of the wave equation [37]. This could mean that the oscillations may simply be the expected oscillations of low order symplectic time integration schemes. As anticipated by the proof of boundedness in [18], the oscillations are reduced when the time step is decreased (not shown) or the order of the symplectic method is increased, as seen with the SV method.

To compare the energy conservation of weak and strong boundary condition implementations, we define the energy residual at time \(t_{f}\) as

$$\begin{aligned} E_{res} & = \hat{H} + \int _{t_{0}}^{t_{f}} \int _{\partial \Omega _{L}} (\boldsymbol{e_{q}}^{\star }\cdot \boldsymbol{n})e_{p}^{\star }ds_{L}dt \\ & = \hat{H} + c^{2} \int _{t_{0}}^{t_{f}} \int _{\partial \Omega _{L}} (\boldsymbol{q}^{\star }\cdot \boldsymbol{n})p_{L}^{\star }ds_{L}dt \,, \end{aligned}$$
(59)

where \(\hat{H}\), which is equal to the internal energy in the domain at time \(t_{f}\), is calculated from Equation (27) with \(\boldsymbol{\hat{q}}\) and \(\boldsymbol{\hat{p}}\) variables at time \(t_{f}\). Kotyczka et al. [23] shows that implicit Gauss-Legendre schemes such as SM conserve the discrete energy exactly for linear PH systems. However, for schemes such as SV and SE that do not conserve energy perfectly, we expect an energy error from both the non-conservativity within the domain and a non-exact energy transferred through the boundary. Therefore, the second term in Equation (59) is simply the energy that we expect to have transferred through the left boundary out of the domain (the term is negative for flow into the domain) between the initial time \(t_{0}\) and time \(t_{f}\). Since we want to calculate the numerical energy flow out of the boundary, care must be taken to evaluate the output energy calculation in the same way as the numerical time integration scheme. This ensures that there is no discrepancy between the accuracy in which the two terms in Equation (59) are calculated. To ensure this consistent numerical accuracy, variables with a ⋆ overscript are the effort or state variables evaluated at time steps that correspond with the chosen time integration scheme. For example, the expected energy contribution of the SV scheme at the boundary can be calculated by decomposing the SV method, as shown in a concise form here,

$$\begin{aligned} \frac{\boldsymbol{q}^{1/2} - \boldsymbol{q}^{m}}{0.5 \Delta t} & = \mathcal{F}(p^{m}) \,, \end{aligned}$$
(60a)
$$\begin{aligned} \frac{p - p^{m}}{\Delta t} & = \mathcal{F}(\boldsymbol{q}^{1/2}) \,, \end{aligned}$$
(60b)
$$\begin{aligned} \frac{\boldsymbol{q} - \boldsymbol{q}^{1/2}}{0.5 \Delta t} & = \mathcal{F}(p) \,, \end{aligned}$$
(60c)

into two adjoint SE method steps with half timestep each [20], this gives

q 1 / 2 q m 0.5 Δ t =F( p m ), p 1 / 2 p m 0.5 Δ t =F( q 1 / 2 ),
(61a)
q q 1 / 2 0.5 Δ t =F(p), p p 1 / 2 0.5 Δ t =F( q 1 / 2 ),
(61b)

where \(\mathcal{F}()\) denotes a function of the entries in the bracket. Then, by knowing that the superscripts of \(\boldsymbol{q}^{\star }\) and \(p_{L}^{\star }\) are the same as the superscripts of \(\boldsymbol{q}\) and \(p\) in Equation (61a) for the first half time step, and the same as in Equation (61b) for the second half time step. We can calculate the residual in two half time steps, as follows from Equation (59),

$$\begin{aligned} & E_{res} = H^{\star } + c^{2} \sum _{\mathit{numSteps}} \bigg( \int _{t^{m}}^{t} \int _{\partial \Omega _{L}} (\boldsymbol{q}^{\star }\cdot \boldsymbol{n})p_{L}^{\star }ds_{L}dt \bigg) \,, \\ & E_{res} = H^{\star } + c^{2} \sum _{\mathit{numSteps}} \bigg( \int _{t^{m}}^{t^{1/2}} \int _{\partial \Omega _{L}} (\boldsymbol{q}^{1/2} \cdot \boldsymbol{n})p_{L}^{m} ds_{L}dt + \int _{t^{1/2}}^{t} \int _{\partial \Omega _{L}} (\boldsymbol{q}^{1/2} \cdot \boldsymbol{n})p_{L} ds_{L}dt \bigg) \,, \\ & E_{res} = H^{\star } + c^{2} \sum _{\mathit{numSteps}} \bigg( 0.5\Delta t \int _{\partial \Omega _{L}} (\boldsymbol{q}^{1/2} \cdot \boldsymbol{n})p^{m}_{L} ds_{L} + 0.5\Delta t \int _{\partial \Omega _{L}} (\boldsymbol{q}^{1/2} \cdot \boldsymbol{n})p_{L} ds_{L} \bigg) \,. \end{aligned}$$
(62)

The energy residual in Equation (59) is plotted for multiple time integration schemes in Fig. 4.

Fig. 4
figure 4

(a) Energy residual for different time integration schemes and for strong and weak boundary condition implementations. (b) Zoomed-in view. IE=Implicit Euler, EE=Explicit Euler, SE=Symplectic Euler, EH=Explicit Heun, SV=Störmer-Verlet, SM=Symplectic (Implicit) Midpoint

It is clear from the bounded energy residual of the SE and SV schemes and the exactly conserved energy of the SM scheme in Fig. 4 that the weak boundary condition implementation conserves energy for long times. This agrees with our proof of Theorem 2.2.1 and the expected bounded energy residual of symplectic time integrations schemes. Again, for the SE and SV schemes, the energy is conserved in an average sense and oscillations about the conserved energy do occur. As expected, the SM scheme conserves energy exactly, with an energy residual of \(<10^{-12}\), which is round-off error. The strong implementation of the input Dirichlet boundary condition does not conserve energy. More exactly, the strong implementation’s energy residual is dependent on the refinement of the spatial mesh. To display this effect, the energy residual of the wave equation with SV time integration is analysed for varying element characteristic length (\(\sqrt{\mathit{Mean}\, \mathit{Element}\, \mathit{Area}}\)) and is shown in Fig. 5. A quadratic trend is plotted to show that the energy residual when using a strong boundary condition implementation has a quadratic dependence on the element characteristic length. This differs from the weak boundary condition implementation, which conserves energy independently of the mesh refinement. This agrees with our proof of Theorem 2.2.1, i.e., that our spatial discretisation is perfectly energy-conserving. Since the energy error is bounded for symplectic time integration schemes [19], the energy error for the weak boundary implementation is only dependent on the step size of the symplectic time integration scheme.

Fig. 5
figure 5

Energy residual vs characteristic element length for strong and weak boundary condition implementations with an SV integration scheme. A quadratic trend of \(y=100x^{2}\) is plotted for comparison. SV=Störmer-Verlet

Temporal integration schemes cannot, in general, conserve both the exact energy and the symplectic structure of the system [20]. However, a general result that applies to non-linear systems, as well as our linear system, is that conserving the symplectic structure results in a bounded energy error which decreases as the time step is reduced. In subsequent chapters, we focus on the results of the SV scheme rather than the SM scheme to show energy conservation results that resemble what we expect for general non-linear problems.

4 Wave Equation Comparison with Analytical Solution

In this section, our numerical model with a weak boundary condition implementation is compared against an analytical solution to ensure stable spatial and temporal convergence as well as good long-time behaviour and accurate eigenvalues. The analytic solution of the linear 2D wave equation was derived from one of the particular solutions in Sect. 7.1.1 of Polyanin and Nazaikinskii’s book [32]. The initial and boundary conditions are given as

$$\begin{aligned} &p(x,y,0) = \rho c \sqrt{\frac{\pi ^{2}}{4L_{x}^{2}} + \frac{4\pi ^{2}}{L_{y}^{2}}} \sin \bigg(\frac{\pi x}{2 L_{x}} + \frac{\pi }{2} \bigg) \sin \bigg(\frac{2 \pi y}{L_{y}} + \frac{\pi }{2} \bigg) \,, \end{aligned}$$
(63a)
$$\begin{aligned} &p(0,y,t) = \rho c \sqrt{\frac{\pi ^{2}}{4L_{x}^{2}} + \frac{4\pi ^{2}}{L_{y}^{2}}} \sin \bigg(\frac{2\pi y}{L_{y}} + \frac{\pi }{2}\bigg) \cos \bigg(t c \sqrt{\frac{\pi ^{2}}{4L_{x}^{2}} + \frac{4\pi ^{2}}{L_{y}^{2}}}\bigg) \,, \end{aligned}$$
(63b)
$$\begin{aligned} &p(L_{x},y,t) = 0 \,, \end{aligned}$$
(63c)
$$\begin{aligned} &\boldsymbol{q}(x,0,t) \cdot \boldsymbol{n} = 0 \,, \end{aligned}$$
(63d)
$$\begin{aligned} &\boldsymbol{q}(x,L_{y},t) \cdot \boldsymbol{n} = 0 \,. \end{aligned}$$
(63e)

The analytical solution is then given by

$$ p^{a}(x,y,t) = \rho c \sqrt{\frac{\pi ^{2}}{4L_{x}^{2}} + \frac{4\pi ^{2}}{L_{y}^{2}}} \sin \bigg(\frac{\pi x}{2 L_{x}} + \frac{\pi }{2} \bigg) \sin \bigg(\frac{2\pi y}{L_{y}} + \frac{\pi }{2} \bigg) \cos \bigg(t c \sqrt{\frac{\pi ^{2}}{4L_{x}^{2}} + \frac{4\pi ^{2}}{L_{y}^{2}}}\bigg) \,, $$
(64)

where all constants are given in Appendix D.

4.1 Spatial Convergence

The error between the numerical model and the analytic solution for a range of characteristic element lengths is evaluated to show the spatial convergence of the model. A table of the number of elements, with corresponding error and convergence details for each refinement level, is shown in Appendix E. The SV time integration scheme was used with a time step of \(5\times 10^{-4}~\mathrm{s}\). The \(L^{2}\) error norm for each step \(n\) is defined as

$$ E^{n} = \sqrt{ \int _{\Omega } (p^{n} - p^{a}(t_{n}))^{2})dV} \,, $$
(65)

where \(p^{a}(t_{n})\) is the exact solution evaluated at the step \(n\). This error is calculated accurately with the ‘errornorm’ function in FEniCS. The maximum \(L^{2}\) error norm over \(1.5~\mathrm{s}\) of simulation is plotted in Fig. 6 for each characteristic element length. In the figure legend, the numbers following P and RT denote the order of the Lagrange and Raviart-Thomas elements, respectively, i.e., P1RT2 uses first order Lagrange elements and second order Raviart-Thomas elements. As can be seen, the \(L^{2}\) error norm for all element order combinations shows standard convergence against characteristic element length. Here we define standard spatial convergence as convergence of order \(\mathcal{O}((\Delta x_{c})^{k+1})\), where \(k\) is the order of the methods lowest order basis function and \(\Delta x_{c}\) is the characteristic element length.

Fig. 6
figure 6

Log-log plot of the maximum \(L^{2}\) error norm of the numerical method for a \(1.5~\mathrm{s}\) simulation of the wave equation for varied characteristic element length and element order. SV=Störmer-Verlet

4.2 Modal Analysis

To ensure the correct handling of mixed boundary conditions, the eigenvalues of the model were verified to be accurate by performing a modal analysis. The analytic eigenvalues were calculated by separation of variables of Equation (1) into

$$ w(x, y, t) = T(t)X(x)Y(y) \,. $$
(66)

This method can simply be shown to give the following three first order eigenvalue problems,

$$\begin{aligned} \partial _{t}^{2} T + c^{2}(\mu + \lambda ) T &= 0 \,, \end{aligned}$$
(67a)
$$\begin{aligned} \partial _{x}^{2} X + \lambda X &= 0 \,, \end{aligned}$$
(67b)
$$\begin{aligned} \partial _{y}^{2} Y + \mu Y &= 0 \,, \end{aligned}$$
(67c)

where \(\lambda \) and \(\mu \) are eigenvalues of the first order spatial systems and \(\omega ^{2} = c^{2} (\mu + \lambda )\) is the eigenvalue or the squared eigenfrequency that we want to predict. For the boundary conditions in Equations (63a)–(63e), the real components of the eigenvalues in Equations (67b) and (67c) are zero and the complex components are

$$ \lambda = \bigg(\frac{n \pi }{L_{x}}\bigg)^{2} \,, \quad \forall n \in \mathbb{N}^{+} \,, \qquad \mu = \bigg(\frac{m \pi }{L_{y}}\bigg)^{2} \,, \quad \forall m \in \mathbb{N}^{0} \,. $$
(68)

Therefore, from Equation (67a), the analytic eigenfrequencies we wish to find are given by

$$ \omega = c \sqrt{\bigg(\frac{n \pi }{L_{x}}\bigg)^{2} + \bigg( \frac{m \pi }{L_{y}}\bigg)^{2}} \,, \quad \forall n,m \quad s.t. \quad n \in \mathbb{N}^{+}\,, m \in \mathbb{N}^{0} \,. $$
(69)

To predict the eigenfrequencies of our model, Equations (55a) and (55b) were discretised in FEniCS, creating the following system of equations,

$$\begin{aligned} & \boldsymbol{M}_{e} \frac{\partial }{\partial t} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \end{bmatrix} = \boldsymbol{K}_{e} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \end{bmatrix} + \boldsymbol{L}_{e} \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ \end{bmatrix} \,, \end{aligned}$$
(70a)
$$\begin{aligned} \boldsymbol{M}_{e} = \begin{bmatrix} -\boldsymbol{M}_{p} & \boldsymbol{0} \\ \boldsymbol{0} & -\boldsymbol{M_{q}} \\ \end{bmatrix} \,, & \qquad \boldsymbol{K}_{e} = \begin{bmatrix} \boldsymbol{0} & k_{w} \boldsymbol{K}_{p} \\ \frac{1}{\rho _{w}} \boldsymbol{K_{q}} & \boldsymbol{0} \\ \end{bmatrix} \,, \qquad \boldsymbol{L}_{e} = \begin{bmatrix} \boldsymbol{0} & k_{w} \boldsymbol{L}_{p} \\ \frac{1}{\rho _{w}} \boldsymbol{L_{q}} & \boldsymbol{0} \\ \end{bmatrix} \,, \end{aligned}$$
(70b)

where, \(\boldsymbol{M}_{e}\), \(\boldsymbol{K}_{e}\), and \(\boldsymbol{L}_{e}\) are the mass, stiffness, and boundary matrices which determine the eigenfrequencies of the system. The \(\boldsymbol{M}_{e}^{-1}(\boldsymbol{K}_{e} + \boldsymbol{L}_{e})\) matrix was then input into NumPy’s eigensolver to calculate the eigenfrequencies of the system. A plot of the complex part of the first 50 analytic and modelled eigenfrequency pairs for a mesh with 1322 elements is shown in Fig. 7. The real parts of all eigenfrequencies equal zero, as expected for the wave equation with no damping.

Fig. 7
figure 7

Comparison of the complex part of the first 50 model and analytic eigenfrequencies

As shown in Fig. 7, the eigenfrequencies are predicted accurately with no spurious modes. A plot of the convergence of the eigenfrequencies with respect to the characteristic element length is shown in Fig. 8. This shows standard quadratic convergence for first order Lagrange and Raviart-Thomas elements.

Fig. 8
figure 8

Log-log plot of the first eigenfrequency percentage error when compared to the analytic eigenfrequency

4.3 Time Convergence

The numerical error for this model is heavily dominated by the spatial discretisation. Therefore, to show time convergence, third order Lagrange and Raviart-Thomas elements are used. This ensures that the initial spatial error is small, therefore, the error that propagates through the domain is due to the temporal discretisation. A convergence study is done for a \(1.5~\mathrm{s}\) simulation and an error growth study is assessed for long-times \((t=10~\mathrm{s})\). The long-time analysis shows the rate at which the error grows through time and displays our models effectiveness for long-time simulations. Although the rate of error growth for different symplectic schemes is well known [18], this section importantly shows that our spatial discretisation does not deteriorate the expected error growth rate.

The SE and SV time integration schemes have been implemented to show the temporal convergence of our method. Linear and quadratic convergence is shown for the SE and SV schemes, respectively in Fig. 9, where the maximum \(L^{2}\) error over the \(1.5~\mathrm{s}\) simulation is plotted for a range of time steps. This shows that our method gives standard temporal convergence, where we define standard temporal convergence as convergence of order \(\mathcal{O}((\Delta t)^{r})\), where \(r\) is the order of the time integration scheme. These simulations were performed on a spatial discretisation with 9358 elements.

Fig. 9
figure 9

Log-log plot of the maximum \(L^{2}\) error norm of the numerical method for a \(1.5~\mathrm{s}\) simulation of the wave equation for varied time step and 9358 elements. SE=Symplectic Euler, SV=Störmer-Verlet

The order at which the state variable error of a method grows is a common metric for the accuracy of symplectic and multi-symplectic methods, as assessed extensively in Hairer’s book [20]. Hairer shows that symplectic methods have state variable error growth of order \(\mathcal{O}(t(\Delta t)^{r})\), where \(r\) is the order of the time integration scheme. The time step convergence in Fig. 9 for fixed final time \(t=1.5~\mathrm{s}\) confirms that the error converges with order \(\mathcal{O}((\Delta t)^{r})\) Therefore, observing an error growth proportional to \(t\) when simulated for long times is sufficient to show the correct order of error growth, \(\mathcal{O}(t(\Delta t)^{r})\). The \(L^{2}\) error norm for a \(10~\mathrm{s}\) simulation of the wave equation is shown in Fig. 10 for various time integration schemes. To give a fair comparison, the schemes have time steps that result in the same number of function evaluations, \(0.00025~\mathrm{s}\) for IE and SM and \(0.0005~\mathrm{s}\) for SV. To display a result that does not blow up immediately, the time step for EH is decreased even further to \(0.000125~\mathrm{s}\).

Fig. 10
figure 10

\(L^{2}\) error norm over a \(10~\mathrm{s}\) simulation for various time integration schemes. EH=Explicit Heun, IE=Implicit Euler, SV=Störmer-Verlet, SM=Symplectic (Implicit) Midpoint

In Fig. 10 the EH method blows up with exponential error growth because it does not have a bounded energy residual. This behaviour is typical of fully explicit methods, which can be unstable for long times [19]. The IE method has large error growth due to its inherent energy dissipation. This error increase tapers off (not shown) due to the complete loss of energy in the numerical model, this results in \(p^{n}\) approaching a constant zero throughout the domain. The symplectic methods both show an error that is linearly dependent on time, as required to validate that the error growth is proportional to \(\mathcal{O}(t(\Delta t)^{r})\). The high-frequency oscillations of the \(L^{2}\) error norm in Fig. 10 are due to \(p^{n}\) varying from being zero throughout the domain to having a maximum, as shown in Fig. 11. Therefore, the oscillation frequency is the frequency that \(p\) oscillates from maximum/minimum to zero.

Fig. 11
figure 11

\(p\) variable in wave domain after \(0.5~\mathrm{s}\), for the model used to compare with the analytic solution, using Störmer-Verlet time integration

5 Electromechanical Lumped Parameter Model

This section details a simple LPM for a linear actuated electric motor. The system diagram and bond-graph schematic are shown in Fig. 12, with constants defined in Appendix D. The current of the electrical system is \(i\) and the displacement of the linear motor is \(s\). The bond-graph methodology is a modular approach for LPMs that ensure conservation of energy within and between models, for a review see the work by Gawthrop [16]. The PH framework extends from bond-graphs to also allow continuum models that conserve energy.

Fig. 12
figure 12

(a) System diagram and (b) bond-graph diagram for an electromechanical system, where Se, R, I, C, and GY denote effort sources, dissipative components, inductive/mass storage components, capacitive/spring storage components, and gyrator components respectively

The Hamiltonian for this system is

$$ H_{\mathit{EM}} = \frac{h_{E}^{2}}{2L_{E}} + \frac{h_{M}^{2}}{2m} + \frac{K_{m} s^{2}}{2} \,, $$
(71)

where the canonical momentum for the mechanical subsystem is given by \(h_{M} = m \dot{s}\) and the electrical system equivalent of the canonical momentum is the magnetic flux linkage, denoted by \(h_{E} = L_{E} i\). The canonical PH form for this system is

$$ \renewcommand{\arraystretch}{1.2} \begin{aligned} \frac{\partial }{\partial t} \begin{bmatrix} h_{E} \\ h_{M} \\ s \\ \end{bmatrix} & = \left ( \begin{bmatrix} 0 & B_{l} & 0 \\ -B_{l} & 0 & -1 \\ 0 & 1 & 0 \\ \end{bmatrix} - \begin{bmatrix} R_{E} & 0 & 0 \\ 0 & R_{M} & 0 \\ 0 & 0 & 0 \\ \end{bmatrix} \right ) \begin{bmatrix} \frac{\partial H_{\mathit{EM}}}{\partial h_{E}} \\ \frac{\partial H_{\mathit{EM}}}{\partial h_{M}} \\ \frac{\partial H_{\mathit{EM}}}{\partial s} \\ \end{bmatrix} + \boldsymbol{B}_{u} u + \boldsymbol{B}_{F} F_{b} \,, \\ y_{u} & = \boldsymbol{B}_{u}^{T} \begin{bmatrix} \frac{\partial H_{\mathit{EM}}}{\partial h_{E}} \\ \frac{\partial H_{\mathit{EM}}}{\partial h_{M}} \\ \frac{\partial H_{\mathit{EM}}}{\partial s} \\ \end{bmatrix} \,, \qquad y_{F} = \boldsymbol{B}_{F}^{T} \begin{bmatrix} \frac{\partial H_{\mathit{EM}}}{\partial h_{E}} \\ \frac{\partial H_{\mathit{EM}}}{\partial h_{M}} \\ \frac{\partial H_{\mathit{EM}}}{\partial s} \\ \end{bmatrix} \,, \qquad \end{aligned} $$
(72)

where \(\boldsymbol{B}_{u}\) is the input control matrix with corresponding input, \(u\) and output, \(y_{u}\). Also, \(\boldsymbol{B}_{F}\) is the boundary port matrix with corresponding boundary force \(F_{b}\) and boundary output \(y_{F}\). Including the constitutive laws and evaluating the \(\boldsymbol{B}_{u}\) and \(\boldsymbol{B}_{F}\) matrices gives

$$ \renewcommand{\arraystretch}{1.2} \begin{aligned} \frac{\partial }{\partial t} \begin{bmatrix} h_{E} \\ h_{M} \\ s \\ \end{bmatrix} &\! = \!\left ( \begin{bmatrix} 0 & B_{l} & 0 \\ -B_{l} & 0 & -1 \\ 0 & 1 & 0 \\ \end{bmatrix} {-} \begin{bmatrix} R_{E} & 0 & 0 \\ 0 & R_{M} & 0 \\ 0 & 0 & 0 \\ \end{bmatrix} \right )\! \begin{bmatrix} \frac{1}{L_{E}} & 0 & 0 \\ 0 & \frac{1}{m} & 0 \\ 0 & 0 & K_{M} \\ \end{bmatrix}\! \begin{bmatrix} h_{E} \\ h_{M} \\ s \\ \end{bmatrix} {+} \begin{bmatrix} u \\ F_{b} \\ 0 \\ \end{bmatrix} , \\ y_{u} & = \frac{h_{E}}{L_{E}} \,, \qquad y_{F} = \frac{h_{M}}{m} \,. \end{aligned} $$
(73)

In this paper, the resistances, \(R_{E}\) and \(R_{M}\), are set to zero, as a non-dissipative system is required to display a conserved Hamiltonian. The values of all constants used in the simulations are given in Appendix D. From Sect. 6 onwards \(F_{b}\) will be the reaction force from the coupled wave equation. The first part of Equation (73) can be written as a typical linear system of ODE’s with a state vector \(\boldsymbol{y} = [h_{E}, h_{M}, s]^{T}\) and a control/interconnection vector \(\boldsymbol{u} = [u, F_{b}, 0]^{T}\), as

$$ \dot{\boldsymbol{y}} = \boldsymbol{A} \boldsymbol{y} + \boldsymbol{u} \,, $$
(74)
$$ \boldsymbol{A} = \left ( \begin{bmatrix} 0 & B_{l} & 0 \\ -B_{l} & 0 & -1 \\ 0 & 1 & 0 \\ \end{bmatrix} - \begin{bmatrix} R_{E} & 0 & 0 \\ 0 & R_{M} & 0 \\ 0 & 0 & 0 \\ \end{bmatrix} \right ) \begin{bmatrix} \frac{1}{L_{E}} & 0 & 0 \\ 0 & \frac{1}{m} & 0 \\ 0 & 0 & K_{M} \\ \end{bmatrix} \,. $$

To create a monolithic coupling of this LPM with the wave equation from Sect. 3 the LPM needs to be implemented in FEniCS. The ODE in Equation (74) can be implemented in FEniCS by using the ‘real function space’, which assumes a function has one value over a domain, i.e., it has no spatial dependence. This makes the domain that the equations are implemented on irrelevant to the ODE. Equation (74) can then be implemented by multiplying by a trial function, \(\boldsymbol{v_{y}}\), and taking the trace against the border of an arbitrary domain. To allow easier coupling in the following section the trace is taken against the left boundary of the wave domain. The remainder of this section details the implementation of the LPM in FEniCS. Although in the following sections we use an SV time integration scheme, the SE scheme is detailed here to provide easier understanding to the reader. For the implementation of the SV method see the GitHub repo.

https://github.com/FinbarArgus/portHamiltonian_FEM.git

For the SE scheme, the ODE can be implemented by solving the matrix systems of equations generated by

$$ \int _{\partial \Omega _{L}} \boldsymbol{v}_{y} \cdot \frac{\boldsymbol{y}-\boldsymbol{y}^{m}}{\Delta t} ds_{L} = \int _{\partial \Omega _{L}} \boldsymbol{v}_{y} \cdot ( \boldsymbol{A} \boldsymbol{y}^{a} + \boldsymbol{u} ) ds_{L} \,, $$
(75)

at each time step. This method of implementing a LPM by assigning the variables as real functions over the whole domain is not optimally efficient and thus, future work should look at developing a method specifically for LPMs that is compatible with FEniCS. \(\boldsymbol{y}^{m}\) is a vector of state variables at the previous time step and \(\boldsymbol{y}^{a}\) is a vector of state variables at a combination of current and previous time steps, as shown here,

$$ \boldsymbol{y}^{m} = \begin{bmatrix} h^{m}_{E} \\ h^{m}_{M} \\ s^{m} \\ \end{bmatrix}, \quad \boldsymbol{y}^{a} = \begin{bmatrix} h_{E} \\ h_{M} \\ s^{m} \\ \end{bmatrix}, \quad \boldsymbol{y} = \begin{bmatrix} h_{E} \\ h_{M} \\ s \\ \end{bmatrix} \,. $$
(76)

Once real function spaces are created and the vectors in Equation (76) are formed, the variational form in Equation (75) can be expressed and solved with the Python code in Appendix B.

6 Coupling with the Electromechanical Model

In this section, the wave equation from Sect. 3 is coupled with the EM PH model from Sect. 5. A schematic of the combined model is shown in Fig. 13 for a rectangle wave domain.

Fig. 13
figure 13

System diagram for the coupled wave-electromechanical system

Following the previous sections, the boundaries denoted \(\partial \Omega _{M}\) and \(\partial \Omega _{R}\) have zero Neumann and zero Dirichlet conditions, respectively. The \(\partial \Omega _{L}\) boundary is the Dirichlet boundary connection with the LPM model. All boundary conditions are implemented in a weak manner. Since the only boundary connection is a Dirichlet boundary, the canonical form of Equation (49) can be used to set up the interconnection with Equation (73). The relationship between inputs and outputs of the wave domain and EM domain can be written as

$$ u_{p} = -\mathcal{W} y_{F} \,, \qquad F_{b} = \mathcal{W}^{*} y_{ \boldsymbol{q}} \,, $$
(77)

where \(\mathcal{W}\) is a compact operator and \(\mathcal{W}^{*}\) is its adjoint operator. The duality pairings for the inputs and outputs are

$$ \langle u_{p} | y_{\boldsymbol{q}} \rangle _{\partial \Omega } \,, \quad \langle F_{b} , y_{F} \rangle \,, $$
(78)

where the \(\langle \cdot | \cdot \rangle _{\partial \Omega _{L}}\) duality product is an \(L^{2}\) inner product that acts over the connection boundary and the \(\langle \cdot , \cdot \rangle \) inner product is the standard inner product in ℝ. We know that the velocity of the left wave boundary is directly set by the output velocity of the EM system, therefore,

$$ u_{p} = -\mathcal{W} y_{F} = -w y_{F} \,, $$
(79)

where \(w\) transforms a scalar into a constant function over the boundary, with the value of \(y_{F}\). Substituting the boundary output relation from Equation (73) gives

$$ u_{p} = -w\frac{h_{M}}{m} \,, $$
(80)

In practice, to turn the scalar value into a function it must be turned into a constant vector and then the vector must be dot producted with a vector of basis functions. Knowing that \(u_{p} = \boldsymbol{\theta }_{p}^{T} \boldsymbol{\hat{u}}_{p}\) we get,

$$ \theta _{p}^{T} \boldsymbol{\hat{u}}_{p} = -w \frac{h_{M}}{m} \,, $$
(81)

Now, we enforce that every point on the left boundary of the wave domain has the same vertical velocity (\(\boldsymbol{\hat{e}}_{p} |_{\partial \Omega _{L}}\)) as the vertical velocity of the output motor (\(\frac{h_{M}}{m}\)). Therefore, \(\boldsymbol{\hat{u}}_{p} = -\boldsymbol{\hat{e}}_{p} |_{\partial \Omega _{L}}\) has the value of \(-\frac{h_{M}}{m}\) for each of its DOFs, which gives

$$ -\boldsymbol{\theta }_{p}^{T} \boldsymbol{1} \frac{h_{M}}{m} = -w \frac{h_{M}}{m} \,, $$
(82)

where \(\boldsymbol{1}\) is a column vector of size equal to the number of boundary \(\boldsymbol{\hat{u}}_{p}\) DOFs that transforms the scalar \(\frac{h_{M}}{m}\) into a vector with value \(\frac{h_{M}}{m}\) for each DOF on \(\partial \Omega _{L}\). Equating both sides of Equation (82) gives

$$ w = \boldsymbol{\theta }_{p}^{T} \boldsymbol{1} $$
(83)

The following energy conserving relation between the \(L^{2}\) and ℝ inner products in Equation (78) can be used to determine \(\mathcal{W}^{*}\),

$$ \langle \mathcal{W} y_{F}| y_{\boldsymbol{q}} \rangle _{\partial \Omega _{L}} = \langle \mathcal{W}^{*} y_{\boldsymbol{q}}, y_{F} \rangle \,. $$
(84)

Evaluating the left-hand side of Equation (84) gives

$$ \begin{aligned} \langle \mathcal{W} y_{F}| y_{\boldsymbol{q}} \rangle _{ \partial \Omega _{L}} & = \int _{\partial \Omega _{L}} (w y_{F})^{T} y_{ \boldsymbol{q}} ds_{L} \\ & = y_{F} \int _{\partial \Omega _{L}} w^{T} y_{\boldsymbol{q}} ds_{L} \,. \end{aligned} $$
(85)

Equating to the right-hand side of Equation (84) gives

$$ \begin{aligned} y_{F} \int _{\partial \Omega _{L}} w y_{\boldsymbol{q}} ds_{L} & = \langle \mathcal{W}^{*} y_{\boldsymbol{q}}, y_{F} \rangle \\ & = y_{F} \mathcal{W}^{*} y_{\boldsymbol{q}} \,, \end{aligned} $$
(86)

which results in

$$ F_{b} = \mathcal{W}^{*} y_{\boldsymbol{q}} = \int _{\partial \Omega _{L}} w y_{ \boldsymbol{q}} ds_{L} \,. $$
(87)

Substituting \(y_{\boldsymbol{q}}\) from Equation (35) and \(\boldsymbol{e}_{\boldsymbol{q}} = k_{w} \boldsymbol{q}\) gives

$$ F_{b} = k_{w} \int _{\partial \Omega _{L}} w (\boldsymbol{q} \cdot \boldsymbol{n}) ds_{L} \,. $$
(88)

Therefore, Equations (80) and (88) are the energy conserving interconnection relations between the two domains. The total Hamiltonian of the combined system is given by

$$ H_{\mathit{total}} = \hat{H} + H_{\mathit{EM}} = \int _{\Omega } \bigg( \frac{1}{2\rho _{w}} p^{2} + \frac{1}{2} k_{w} \boldsymbol{q} \cdot \boldsymbol{q} \bigg)dV + \frac{h_{E}^{2}}{2L_{E}} + \frac{h_{M}^{2}}{2m} + \frac{K_{M} s^{2}}{2} $$
(89)

Finally, the canonical forms of Equations (47) and (73) can be combined to give the input-state-output PH form of the interconnected system,

$$ \begin{aligned} & \begin{bmatrix} -\boldsymbol{M}_{p} & \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{0} & -\boldsymbol{M_{q}} & \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0} & 1 & 0 & 0 \\ \boldsymbol{0} & \boldsymbol{0} & 0 & 1 & 0 \\ \boldsymbol{0} & \boldsymbol{0} & 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} \partial _{t} \boldsymbol{\hat{p}} \\ \partial _{t} \boldsymbol{\hat{q}} \\ \partial _{t} h_{E} \\ \partial _{t} h_{M} \\ \partial _{t} s \\ \end{bmatrix} \\ &\quad = \begin{bmatrix} \boldsymbol{0} & -\boldsymbol{K}_{\boldsymbol{q}}^{T} & \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{0} \\ \boldsymbol{K_{q}} & \boldsymbol{0} & \boldsymbol{0} & \boldsymbol{D}_{p} & \boldsymbol{0} \\ \boldsymbol{0} & \boldsymbol{0} & 0 & B_{l} & 0 \\ \boldsymbol{0} & \boldsymbol{D}_{p}^{0} & -B_{l} & 0 & -1 \\ \boldsymbol{0} & \boldsymbol{0} & 0 & 1 & 0 \end{bmatrix}\! \begin{bmatrix} \rho _{w} \boldsymbol{I} & \boldsymbol{0} & 0 & 0 & 0 \\ \boldsymbol{0} & k_{w} \boldsymbol{I} & 0 & 0 & 0 \\ \boldsymbol{0} & \boldsymbol{0} & \frac{1}{L_{E}} & 0 & 0 \\ \boldsymbol{0} & \boldsymbol{0} & 0 & \frac{1}{m} & 0 \\ \boldsymbol{0} & \boldsymbol{0} & 0 & 0 & K_{M} \\ \end{bmatrix}\! \begin{bmatrix} \boldsymbol{\hat{p}} \\ \boldsymbol{\hat{q}} \\ h_{E} \\ h_{M} \\ s \end{bmatrix}\, +\, \begin{bmatrix} 0 \\ 0 \\ 1 \\ 0 \\ 0 \\ \end{bmatrix} u \,, \\ &y_{u} = \frac{h_{E}}{L_{E}} \,, \end{aligned} $$
(90)

where \(D_{p}\) and \(D_{p}^{0}\) are the interconnection matrices of the skew symmetric system matrix. For skew-symmetry of the system matrix to hold the following must be true

$$ D_{p}^{0} = -D_{p}^{T} \,. $$
(91)

To verify that this skew symmetry holds we calculate \(D_{p}\) and \(D_{p}^{0}\) by discretising Equations (80) and (88). Firstly, Equation (80) is discretised by multiplying on the left by the trial basis function, \(\boldsymbol{\psi _{q}}\), and integrating over the boundary, as was done in the formulation of the boundary term in Equation (19),

$$\begin{aligned} \int _{\partial \Omega _{L}} \boldsymbol{\psi _{q}} u_{p} ds_{L} & = -\bigg( \int _{\partial \Omega _{L}} \boldsymbol{\psi _{q}} \boldsymbol{\theta }_{p}^{T} ds_{L} \bigg) \boldsymbol{1} \frac{h_{M}}{m} \end{aligned}$$
(92)
$$\begin{aligned} & = -\boldsymbol{B}_{pb} \boldsymbol{1}\frac{h_{M}}{m} \,, \end{aligned}$$
(93)

where the final step comes from the definition of \(\boldsymbol{B}_{pb}\) in Equation (48). Equating this with the boundary term in the second row of Equation (90) gives

$$\begin{aligned} \boldsymbol{D}_{p} \frac{h_{M}}{m} &= -\boldsymbol{B}_{pb} \boldsymbol{1} \frac{h_{M}}{m} \,, \\ \rightarrow \quad \boldsymbol{D}_{p} &= -\boldsymbol{B}_{pb} \boldsymbol{1} \,. \end{aligned}$$
(94)

To discretise Equation (88), we first substitute Equation (83) and apply \(w = w^{T}\), because \(w\) is a constant function,

$$\begin{aligned} F_{b} = k_{w} \int _{\partial \Omega _{L}} (\boldsymbol{\theta }_{p}^{T} \boldsymbol{1})^{T} (\boldsymbol{q} \cdot \boldsymbol{n}) ds_{L} \,. \end{aligned}$$
(95)

Discretising \(\boldsymbol{q} \cdot \boldsymbol{n}\) in the same way as \(\boldsymbol{e}_{q} \cdot \boldsymbol{n}\) was discretised in Equation (18) gives,

$$\begin{aligned} F_{b} &= \boldsymbol{1}^{T} k_{w} \bigg( \int _{\partial \Omega _{L}} \boldsymbol{\theta }_{p} \boldsymbol{\psi _{q}}^{T} ds_{L} \bigg) \boldsymbol{\hat{q}} \\ & = \boldsymbol{1}^{T} k_{w} \boldsymbol{B}_{pb}^{T} \boldsymbol{\hat{q}} \,, \end{aligned}$$
(96)

where \(\boldsymbol{1}^{T}\) simply adds up the force contribution from each boundary DOF to calculate \(F_{b}\). Equating the boundary term in the fourth row of Equation (90) with the boundary term in the second row of Equation (73) gives

$$\begin{aligned} k_{w} \boldsymbol{D}_{p}^{0} \boldsymbol{\hat{q}} &= F_{b} \\ k_{w} \boldsymbol{D}_{p}^{0} \boldsymbol{\hat{q}} &= k_{w} \boldsymbol{1}^{T} \boldsymbol{B}_{pb}^{T} \boldsymbol{\hat{q}} \,. \\ \boldsymbol{D}_{p}^{0} &= \boldsymbol{1}^{T} \boldsymbol{B}_{pb}^{T} \\ \rightarrow \quad \boldsymbol{D}_{p}^{0} &= -\boldsymbol{D}_{p}^{T} \,. \end{aligned}$$
(97)

Therefore, the discrete interconnected system retains a skew symmetric matrix, as required for a port Hamiltonian system. Equation (90) encompasses the canonical form, the dynamic equations and the constitutive law equations of the interconnected system.

It is important to note that if the right-side boundary condition, \(p_{R}\), was non-zero then there would be an extra boundary input and output in the canonical form of Equation (90). Also, if the top and bottom Neumann boundaries were non-zero conditions, the canonical form of Equation (90) would have interconnection inputs \(u_{p}^{\mathit{int}}\) and outputs \(y_{\boldsymbol{q}}^{\mathit{int}}\) with the same definitions as the discrete version of Equation (35). A canonical form for the Neumann conditions would also have to be created with inputs/outputs for the boundary \(u_{\boldsymbol{q}}\), \(y_{p}\) and for the interconnection \(u_{\boldsymbol{q}}^{\mathit{int}}\), \(y_{p}^{\mathit{int}}\) with the same definitions as the discrete version of Equation (34). The two canonical forms could then be connected with Equation (50). Although the formulation of the interconnected canonical form seems complicated, it is not necessary for implementation. The full system canonical form is only discussed to reassure the reader that the total system is equivalent to a combination of canonical forms and therefore is a Stokes-Dirac structure and can have mixed causality boundary connections. The usefulness of the canonical forms, Equations (47) and (73), is that they allow calculation of the interconnection relations, which can then be implemented in FEniCS, as shown in Appendix C.

7 Interconnection Model Results

This section displays the results for the coupled wave-EM model for a sinusoidal input voltage. The time step for the simulations is \(5\times 10^{-4}~\mathrm{s}\), using an SV time integration scheme. The problem is solved on both a simple rectangle domain with 21110 elements and a square domain with central input and 13067 elements.

7.1 Rectangle Domain

The input voltage condition for the rectangle domain is given by

$$ u = \textstyle\begin{cases} 5 \sin (8 \pi t)\ [\mathrm{V}] & t < 0.25\ [\mathrm{s}] \\ 0\ [\mathrm{V}] & t \geq 0.25\ [\mathrm{s}] \end{cases}\displaystyle \,. $$
(98)

The \(p\) variable of the wave equation is displayed after \(0.3~\mathrm{s}\) and \(1.1~\mathrm{s}\) in Figs. 14 and 15, respectively. The initial large sinusoidal wave, which is due to the input over the first \(0.25~\mathrm{s}\), flows through the domain as expected. This wave is followed by smaller repeating waves caused by the lingering oscillations of the EM system.

Fig. 14
figure 14

\(p\) variable in the wave domain after \(0.3~\mathrm{s}\) of a wave-EM simulation, using Störmer-Verlet time integration

Fig. 15
figure 15

\(p\) variable in the wave domain after \(1.1~\mathrm{s}\) of a wave-EM simulation, using Störmer-Verlet time integration

To confirm that the energy error of the model is bounded, the energy residual of each domain and the total energy residual is plotted in Fig. 16. The residual for each domain is the difference between the accumulated energy that has entered the domain and the internal energy in the domain.

Fig. 16
figure 16

Energy residual vs time for the interconnected wave-EM simulation, using Störmer-Verlet time integration. Total Residual is the sum of the energy residuals from the wave and EM domains. Wave residual is the difference between the energy in the wave domain and the accumulated energy that has entered the wave domain through its boundaries. EM residual is the difference between the energy in the EM domain and the accumulated energy that has entered the EM domain through its boundaries

As shown, the energy residual is bounded for increasing times, as expected for a symplectic time integration scheme. For a second-order symplectic method such as SV, the energy residual bound should be quadratically dependent on the time step, this relationship is proven in [18] and expressed more generally as

$$ H(q(t), p(t)) = H(q(0), p(0)) + \mathcal{O}((\Delta t)^{r}) \,. $$
(99)

To ensure that the bounded energy residual is indeed quadratically dependent on the time step, the energy residual maximum over a \(20~\mathrm{s}\) simulation is plotted against the step size in Fig. 17. As discussed in Sect. 4 The SM scheme can also be used to conserve quadratic invariants exactly. As shown in Fig. 17 we achieve an energy residual of \(<10^{-11}\) for a \(20~\mathrm{s}\) simulation with SM, confirming that our model, with an SM scheme, conserves energy exactly for linear, coupled LPM-continuum systems.

Fig. 17
figure 17

Maximum energy residual for the interconnection model with a varied time step size. SV=Störmer-Verlet, SM=Symplectic (Implicit) Midpoint

7.2 Square Domain with Central Input Boundary

A diagram for the domain of this section is shown in Fig. 18 and the input voltage is the same as Equation (98). Following the notation of the previous sections, the boundaries denoted \(\partial \Omega _{M}\) and \(\partial \Omega _{R}\) have zero Neumann conditions and zero Dirichlet conditions, respectively. Again, the \(\partial \Omega _{L}\) boundary is the connection boundary with the LPM model and all boundary conditions are implemented in the weak form.

Fig. 18
figure 18

System diagram for the coupled wave-electromechanical system with a square domain and a central input

The \(p\) variable of the wave equation is displayed after \(0.4~\mathrm{s}\) and \(0.6~\mathrm{s}\) in Figs. 19 and 20, respectively. As can be seen, this example shows realistic 2D dispersion of a wave entering a square domain.

Fig. 19
figure 19

\(p\) variable in a square wave domain after \(0.4~\mathrm{s}\) of the wave-EM simulation, using Störmer-Verlet time integration

Fig. 20
figure 20

\(p\) variable in a square wave domain after \(0.6~\mathrm{s}\) of the wave-EM simulation, using Störmer-Verlet time integration

At long times the uniform circular wave structure breaks down due to waves rebounding off the walls. However, the wave behaviour should still retain some structure, for example, there should be symmetry about the midline parallel to the \(x\) axis. Figure 21 shows \(p^{n}\) after \(8~\mathrm{s}\) of simulation, once the uniform wavefronts have completely broken down. As can be seen, there is still symmetry about the midline parallel to the \(x\) axis, further showing this methods ability to accurately model the physical structure of the system.

Fig. 21
figure 21

\(p\) variable in a square wave domain after \(8~\mathrm{s}\) of the wave-EM simulation, using Störmer-Verlet time integration

The energy residual for an \(8~\mathrm{s}\) simulation with the SV scheme is shown in Fig. 22. As in previous sections, the energy residual is oscillatory and bounded, as expected. Also, as in the previous sections, when using the SM method the energy residual is \(<10^{-12}\), therefore, exactly conserved to within round-off error.

Fig. 22
figure 22

Energy residual vs time for the interconnected wave-EM simulation with a square domain, using Störmer-Verlet time integration. Total Residual is the sum of the energy residuals from the wave and EM domains. Wave residual is the difference between the energy in the wave domain and the accumulated energy that has entered the wave domain through its boundaries. EM residual is the difference between the energy in the EM domain and the accumulated energy that has entered the EM domain through its boundaries

8 Conclusion

For the modelling of continuum systems, a port-Hamiltonian, Galerkin finite element method has been developed that, in general, has a bounded energy residual and linear long-time error growth for the state variables. This method allows mixed boundary conditions without the need for Lagrange multipliers or user-defined parameters. The discretisation is shown to be equivalent to a coupling of canonical port-Hamiltonian forms that allows mixed interconnections with other canonical port-Hamiltonian models. The discretisation is also shown to be symplectic in both time and space. For our specific 2D linear wave equation system we also show exact energy conservation with a symplectic (implicit) midpoint method that guarantees conservation of quadratic first integrals. We also compare against an analytical solution and show standard order of convergence for the state variables with respect to the temporal and spatial discretisation. A modal analysis is performed and the eigenvalues are verified to be accurate. The boundary conditions are implemented in variational form, in a weak manner, without the need for penalty methods. In addition to this, the method is capable of monolithic coupling with arbitrary LPMs. The coupled model is shown to also have a bounded energy residual with a standard temporal order of convergence for the SV time integration scheme and exact energy conservation for the SM time integration scheme. The example model of a 2D linear wave equation coupled with an EM linear actuator is a good proof of concept for more advanced couplings between Hamiltonian PDEs and LPMs. Future work will be done on implementing control algorithms for coupled models, in order to improve control of multiphysics, multidomain, and non-linear problems.