A Novel Mixed Finite/Infinite Dimensional Port–Hamiltonian Model of a Mechanical Ventilator

: Mechanical ventilation is a life-saving treatment for critically ill patients who are struggling to breathe independently due to injury or disease. Globally, per year, there has always been a large number of individuals who have required mechanical ventilation. The COVID-19 pandemic brought to light the significance of mechanical ventilation, which played a significant role in sustaining COVID-19-infected critically ill patients who could not breathe on their own. The pandemic drew the attention of the world to the shortage of ventilators globally. Some of the challenges to providing an adequate number of ventilators include: increased demand for ventilators, supply chain disruptions, manufacturing constraints, distribution inequalities, financial constraints, maintenance and logistics difficulties, training and expertise shortages, and the lack of design and development of affordable mechanical ventilators that satisfy the stipulated requirements. This research work presents the formulation of a detailed Port–Hamiltonian model of a mechanical ventilator integrated with the human respiratory system. The interconnection and coupling conditions for the various subsystems within the mechanical ventilator and the coupling between the mechanical ventilator and the human respiratory system are also presented. Structure-preserving discretization is provided alongside numerical simulations and results. The obtained results are found to be comparable to results presented in the literature. Future work will include the design of suitable controllers for the system.


Introduction
The World Health Organization (WHO) has "access to oxygen" on its model list as one of the essentials required by an individual, especially when they are in a critical condition health-wise and are unable to breathe on their own.Oxygen is the only listed medicine that does not have a substitute.Access to oxygen even after the worldwide pandemic is still a major dilemma in middle-and low-income countries [1].A mechanical ventilator is a medical device that is employed to assist patients in cases where their respiratory system is not functioning well and, thus, the patient has challenges with breathing or has shortness of breath.A mechanical ventilator can also be used in cases where a patient has been sedated and is undergoing surgery.
The basic operation of a mechanical ventilator is to control a high-pressure region during the inspiration stage.In the inspiration stage, the mechanical ventilator is paused.During expiration, air flows out due to the lung's natural recoil, which creates higher pressure in the alveoli.Due to the high demand for mechanical ventilators both in the past and at present, it is imperative that efficient and affordable mechanical ventilators be researched, modelled, designed and implemented.To ensure that robust mechanical ventilators are designed, it is important to formulate new models that can be used in the research and testing stages of mechanical ventilators.

Mathematical Models of the Respiratory System
Sound mathematical formulations of the underlying physics of the respiratory system are very important for understanding the anatomy and physiology of the organs.Classical modelling methodologies that employ a physiological or clinical perspective have been previously used mainly for data-fitting for single-compartment model parameters: for example, [2].Human lungs are usually mathematically viewed to be made up of intricate branching networks of compliant tubes spanning a broad range of scales and flow regimes.The flow may be a highly pulsatile flow or an almost laminar diffusion-dominated process.Flow enters a sponge-like microstructure of lung tissue from the terminal branches of the airway.The lung tissue material's behaviour is very nonlinear, and for efficient gaseous exchange, the topology is optimized with small embedded blood vessels.Current research developments in the mechanical and mathematical modelling of the lungs have mainly focused on studying isolated effects that are difficult to understand and assess in vivo.These studies seek to advance medical imaging and functional diagnostics and assist with patient-specific treatment planning and optimization.Bates [3] used a system identification approach to provide a mathematical description of lung mechanics, with evolving intricacies in the mathematical formulations.This ranged from single linear compartments to generalized multi-compartmental models.Maury [4] further developed the concept proposed by Bates [3] and described the lung as a resistive tree.Various levels of description have been proposed, including lumped models with a small number of parameters described by ordinary differential equations (ODEs) up to infinite-dimensional models based on partial differential equations (PDEs).Resistive networks and how they can be used to investigate the dependence of the lung's resistance on geometrical characteristics have also been presented.Analyses of the various models from a theoretical perspective have been provided.The approximate solution techniques that have been provided have shown good correlation with experimental measurements.Other researchers that have proposed similar works are Burrowes et al. [5], Tawhai et al. [6], and Berger et al. [7].Research has also been conducted by Roth et al. [8] using Navier-Stokes equations for fluid flow from a very mathematical perspective.This research work also provides comprehensive and computationally fully resolved fluid representations of human respiratory models or parts thereof.Solutions of the three-dimensional Navier-Stokes equations on rigid geometries have also been formulated.Information from medical imaging alongside the fluid domain have been used to formulate real fluid-structure interaction effects [8].As an approach for replicating real fluid-structure effects, techniques have been developed and published that demonstrate this concept in the fluid domain by the application of data from medical imaging information.To quantify particle deposition or drug delivery in the lower and upper airways and for investigation of patterns in the lungs such as jets or vortices, a fully resolved fluid model may be used.Such models are very complex, and in most cases, only parts of the human respiratory system are investigated, thus eliminating the important impact of the entire organ.A holistic human respiratory system model requires a consistent, physiologically realistic representation of the respiratory mechanics in addition to the purely mechanical or structural aspects because the basic physics of respiratory mechanics are governed by the interaction of the fluid with the anatomy.The normal functioning of the lung is possible due to the deformation of the associated muscles, airway tree and lung tissue.Indeed, tissue properties have an influence on airflow and the processes that occur during air transportation: for instance, during gaseous exchange or aerosol transportation.

Related Works
Tran et al. [9] conducted research work with the main goal of designing, controlling, modelling, and simulating a mechanical ventilator that is lightweight, portable, and suitable for use at home.Tran et al. [9] modelled a mechanical ventilator as a voltage source.El-Hadj et al. [10] applied the fluid-structure interaction (FSI) to couple the computational fluid dynamics used for fluid flow with finite element analysis for the solid domain.This facilitated the investigation of fluid behaviour, structural behaviour, and interactions.Two designs were proposed for the mechanical ventilator.The first design was reported to be uncontrollable, and the second design considers computational fluid dynamics (CDF) with a moving boundary applied to a piston-cylinder-based ventilator.Tharton et al. [11] designed and developed a ventilator prototype to be used by professionals in medical emergencies and in any other context where the regular ventilator is not available.A mechanical ventilator was modelled using a crank rocker mechanism in order to meet specific requirements for mechanical ventilator design.Pivk et al. [12] developed an empirical model for a low-cost mechanical ventilator by observing the response of each of the ventilator subsystems.The current progress made globally in the development of affordable and effective designs is important.However, research in mechanical ventilator development lacks model development.The Port-Hamiltonian approach applied in this research work acts as a modelling template for future energy-based mechanical ventilator modelling and design.Lagrangian modelling and Kane's approach do not emphasize energy routing in the system through a Dirac structure.Kane's method is also limited with regard to modelling of the fluid interaction of the mechanical ventilator-human respiratory system.It is important to develop designs that rest on a solid understanding of a significant aspect of the design.Naggar [13] developed a piecewise model of a mechanical ventilator that describes the artificial behaviour of a mechanical ventilator.A pressure-controlled ventilator was created and simulated.The mechanical ventilator was modelled using a periodic function with inequalities to control the beginning of the inspiration and expiration periods.Shi et al. [14] developed a mathematical model of volume-controlled mechanical ventilation.The model is viewed as a pneumatic system wherein the ventilator is regarded as an air compressor.The exhalation valve is considered a throttle.The compressor and the container represent the ventilator.Naggar et al. [15] proposed an integrated mathematical model of the mechanical ventilator and the lung.Linear quadratic and exponential equations were used to model the system.The integrated model was used to simulate volume-controlled artificial ventilation.Giri et al. [16] proposed a simplified design of a mechanical ventilator to reduce cost and automate the mechanical ventilation process.The proposed design was simulated on the MATLAB platform.Hannon et al. [17] reviewed the progress in mathematical modelling and simulation of human anatomy, physiology, and pathophysiology using computers in the context of mechanical ventilation.This study emphasized the clinical applications of computer simulations in various disease states.The research work further discussed the present constraints and the possibility of in silico modelling.There are currently no existing Port-Hamiltonian models of mechanical ventilators.

Applications of Integrated Mechanical Ventilator-Human Lung System Models
Integrated mechanical ventilator-human lung system models can be used to simulate the behaviour of the respiratory system and to study the effects of mechanical ventilation on lung function.These models have several applications in research, education, and clinical practice.Overall, integrated mechanical ventilator-human lung system models provide a valuable tool for understanding the behaviour of the respiratory system under mechanical ventilation and for developing improved strategies for the diagnosis and treatment of respiratory disorders.The subsections to follow provide examples of applications of integrated models of the mechanical ventilator-respiratory system.In Mehedi et al. [18], the respiratory system was modelled as a combination of the blower-hose patient system with nonlinear lung compliance.There are currently very few studies that have conducted simulations during expiration since the availability of storage for the inhaled volume is required during expiration.

Motivation of the Port-Hamiltonian Approach
Both the mechanical ventilator and the human respiratory system are multi-physical in nature (they contain components from various domains in physics).As such, a more apt approach to understand the manner in which these systems work, the coupling between them, etc., and, furthermore, to improve the efficiency of mechanical ventilation, is to make use of models that better represent these systems.Thus, a more representative modelling approach would be to account for the multi-physical nature of these systems [19,20].The Port-Hamiltonian approach for modelling integrated systems has several benefits, including [19,20]: The Port-Hamiltonian approach is modular and is based on the topology of the mechanical ventilator and the human respiratory system.Thus, various types of mechanical ventilators and human respiratory systems with different structure/topologies can be simulated/tested numerically under various operating conditions to analyse performance, etc. [19,20].

2.
The modular nature of the Port-Hamiltonian method, together with its basis in graph theory, means that one can proceed to develop software to automate the modelling of various types of mechanical ventilator/human respiratory system topologies [19,20].

3.
Properties such as the passivity of the integrated mechanical ventilator-human respiratory system can be shown and studied [19,20].
Currently, there are no energy-based models of MV-patient systems that can be used in systems that have dissipation of energy from the ports.Complex dynamical systems can be modelled and controlled in the Port-Hamiltonian framework because the framework provides a powerful tool for the analysis, modelling and control of such systems.The key attributes of the Port-Hamiltonian (pH) framework are: Firstly, it is established on the multi-domain bond-graph modelling method, which connects various physical elements via ports.The interconnection in the Port-Hamiltonian method is such that there is power conservation.Secondly, there is significance assigned to the energy variables as well as the total energy stored, which is also known as the Hamiltonian and is the foundation for multi-physics system modelling.The Port-Hamiltonian approach provides the basis for understanding energy transfer in the various physical domains that govern the respiratory system.Sampled data can be obtained when the Port-Hamiltonian structure is exploited and preserved in discretization.This research work applies the Port-Hamiltonian system approach to model the MV-human respiratory system.The resulting model explicitly shows the energy storage, energy dissipation and the interconnection underlying the system.The obtained Port-Hamiltonian model has numerous applications: for instance, it may be applied in the design of various medical devices and for respiratory disease diagnostics.
The main contribution in this research work is the development of an integrated Port-Hamiltonian model representation of a mechanical ventilator-human respiratory system.The model consists of electromechanical and electromagnetic components modelled in a finite-dimensional representation and interconnected with fluid components in an infinite-dimensional representation.As a result, this Port-Hamiltonian model is of a mixed finite/infinite dimensional nature.The remainder of this paper is structured as follows: The materials and methods are outlined in Section 2, Sections 3 and 4 present the detailed Port-Hamiltonian model of a mechanical ventilator and the solenoid valve subsystem.Sections 5 and 6 give the model network topology and model interconnection with coupling conditions.Sections 7 and 8 show the structure-preserving discretization, results and discussion.Finally, the conclusion and recommendations are presented in Section 9.

Materials and Method
This section presents the mathematical preliminaries of the Port-Hamiltonian approach that are followed in later sections.These definitions are standard definitions from the literature and are mostly derived from the following references: [21][22][23].

Definition 1. (Dirac structure):
A Dirac structure (DS) is a pair of elements, f ∈ R n and e ∈ R n , that satisfies the set: The DS is a subset D ⊂ F × E, where F and E represent the flows and efforts, respectively.
The DS in electric circuits can be represented as:

Definition 3. (Port-Hamiltonian (pH) system):
The set (D, L, R) defines a pH system where: The elements of the sets: are known as flows and efforts; are known as resistive flows and efforts; • F P ∈ R n P and E P ∈ R n P are known as external flows and efforts, respectively.
where n L , n R and n P ∈ N 0 .The dynamics of the pH system are given by the differential inclusion: where (x(t), e L (t)) ∈ L, ( f R (t), e R (t)) ∈ R, and ( f P (t), e P (t)) ∈ P.

Definition 4. (Interconnection of n pH systems):
Let (D i , L i , R i ) denote the space of the ith pH system in a set of n pH systems that are to be interconnected.The space of flows is divided into an external part and a part to be linked and is given by Similarly, the space of efforts is divided into an external part and a part to be linked and is expressed as: The interconnection of two pH systems (D 1 , L 1 , R 1 ) and (D 2 , L 2 , R 2 ) with respect to the link (F Plink , E Plink ) results in a new interconnected pH system: (D, L, R).This interconnected system is given by the expression:
V is a set of vertices; 2.
E is a set of edges; 3.
l ∶ E → V maps each edge, e, to an initial vertex; 4.
r ∶ E → V maps each edge, e, to a terminal vertex.

Definition 6. (Loop-free directed graph):
If G is a directed graph, then G is said to be loop-free if for all e ∈ E, l(e) ≠ r(e).

Definition 7. (Subgraphs).
Given the graphs G ∶= (V, E, l, r) and A subgraph is said to be spanning if V ′ = V; 3.
A subgraph is said to be a proper subgraph if E ′ ≠ E; 4.
If both V and E are finite, then G is said to be finite.

2.
A path from υ to υ is called a cycle.

3.
Two vertices, υ and ϖ are said to be connected if there exists a path from υ to ϖ.

4.
The existence of paths from vertices gives an equivalence relation on the set of vertices.

5.
A subgraph is a component of the graph.6.
A graph with only one component is said to be connected.

Definition 9. (Incidence matrix):
Let G = (V, E, l, r) be a directed graph that is finite and loop-free such that E = e 1 , . . ., e m and V = υ 1 , . . ., υ n .Then the jth row and kth column of the incidence matrix A 0 ∈ R n×m of G is given by If rank(A 0 ) = n − k, then graph G has k ∈ N components, such that k rows can be removed from A 0 , resulting in a matrix with the same rank.
Definition 10. (Kirchhoff-Dirac structure, Kirchhoff-Lagrange submanifold): The Kirchhoff-Dirac structure of G can thus be defined by the set where i and u are the currents and voltages, respectively, at the edges of the graph, whereas q and ϕ are the charges and potentials, respectively, at the vertices of the graph, respectively.
Assuming that S = {v 1 , . . ., v |S| }, the Kirchhoff-Lagrange submanifold of G with respect to S is defined as where Is finite; 2.
Has an incidence matrix can be constructed by deleting the rows corresponding to the vertices S from A 0 ∈ R n×m .Remark 1.According to Proposition 1, Equations ( 1) and ( 2 Definition 10 caters to an introduction of a pH system (D S K (G), L S K (G), {0}) with dynamics: where (q(t), ϕ(t)) ∈ L S K (G).Using the equivalence of (q(t), ϕ(t)) ∈ L S K (G) to q(t) = 0 and ϕ(t) ∈ R n−|S| , we see that Equation (3) holds if and only if this condition holds: e l ∈ C j with orientations that coincide, −1 e l ∈ C j with orientations that do not coincide, 0 otherwise.
On this basis, one can define a DS and an LS Together, they form a pH system defined by the set

Dirac Structure
A key feature of a Dirac structure is the fact that the standard composition of two Dirac structures is again a Dirac structure.The implication of this statement is that any power-conserving interconnection of a Port-Hamiltonian system is also a Port-Hamiltonian system itself.This constitutes the foundational feature of the Port-Hamiltonian approach to modelling, simulation and control of complex physical systems.The intricate Dirac structure is the guide to the algebraic constraints of the interconnected system as well as its Casimir functions [23].The Casimir functions are significant for the set-point regulation of Port-Hamiltonian systems.The framework of the Port-Hamiltonian approach allows for port-based modelling.Port-based modelling means that we are interconnecting many different elements through ports.Dirac structures are the tools used to connect multiple elements.These various elements are energy-storing elements, energy-dissipating elements and external elements that can supply energy.A diagram to demonstrate the connection structure is given in Figure 1 [23].

Description of the System
The overall mechanical ventilator system diagram is provided in Figure 2. The entire system consists of various subsystems.In this research work, the main subsystem that contributes to the flow of air and, consequently, the air pressure are discussed.Therefore, the following main subsystems will be discussed: the DC motor subsystem, the turbine pump/blower subsystem, the pump-shaft/impeller subsystem and the solenoid valve subsystem.

Blower Model
In this section, the dynamical system model equations for the blower model are presented in the Port-Hamiltonian framework.The blower model comprises three sub-systems: namely, a DC motor that drives the blower-shaft/impeller, a blower-shaft/impeller that couples the DC motor to the fluid by using the rotational motion of the motor to accelerate the fluid, and finally, the fluid being driven.
From the Port-Hamiltonian perspective, the state vector X b ∈ R 4 is given by: where p m ∈ R 1 and ϕ m ∈ R 1 are the angular momentum and magnetic flux of the DC motor, respectively, while P b ∈ R 1 and Q b ∈ R 1 are the pressure and flow rate of the blower, respectively.The total energy of the blower is given by the Hamiltonian: where and I b ∈ R 1 + are the hydraulic capacitance and inertance of the air in the blower, respectively.Thus, the Port-Hamiltonian model of a blower is given by Ẋb where where + is the armature resistance, and + is the motor's angular momentum/pressure coupling constant.The inputs to the system are the DC motor voltage, the input volumetric flow rate and the pressure, which are given by V ∈ R 1 , Q in ∈ R 1 and P in ∈ R 1 , respectively.One can easily show that J m = −J ⊺ m and R m = R ⊺ m ⪰ 0. Taking the time derivative of the Hamiltonian gives This system has power and resistive ports.

Solenoid Valve Subsystem
Figure 3 shows a solenoid valve in the open and closed positions.It is assumed that the air gaps are sufficiently small such that the effect of fringing of the magnetic flux is negligible.Consider a solenoid in which the permeability of the core and the length of the part of the magnetic circuit inside the core are denoted by µ c ∈ R 1 + and l c ∈ R 1 + , respectively.The equivalent length of the solenoid's magnetic circuit l eq [⋅] ∶ R → R is dependent on the displacement of the spool q s ∈ R and can be written as: where µ 0 ∈ R 1 + is the permeability of air, and q s tot ∈ R 1 + is the total air gap.The solenoid coordinate system is represented in Figure 4. Thus, the inductance of the solenoid varies with displacement of the spool and, hence, can be expressed by the function L s [⋅] ∶ R → R given by: where N ∈ R 1 + is the number of turns in the coil of the solenoid, and A e ∈ R 1 + is the effective cross-sectional area of the path of the magnetic flux.The magnetic and mechanical subsystems in the solenoid valve are therefore coupled magnetically due to the dependence of the inductance on the displacement of the spool.The total energy of the solenoid is given by the Hamiltonian H s [⋅] ∶ R 3 → R, which is a function of the state vector X s = [ϕ s , p s , q s ] ⊺ ∈ R 3 and is expressed as the sum of the magnetic, kinetic and potential energies, which are denoted by given a magnetic flux ϕ s ∈ R. Assuming that the pretension of the spring is set to q 0 ∈ R, the Hamiltonian is where p s ∈ R is the momentum of the spool, m s ∈ R 1 + is the mass of the spool, k s ∈ R 1 + is the spring stiffness, and g ∈ R 1 + is the acceleration due to gravity.Hence, the solenoid's state and output dynamics are expressed in Port-Hamiltonian form in Equations ( 13) and ( 14), respectively: where + is the resistance of the coil, b s ∈ R 1 + is the viscous damping acting on the spool, and ∇ is the gradient operator.A s 1 , A s 2 ∈ R 1 + are the various cross-sectional areas of the surfaces of the spool, and the input vector u s ∈ R 2 consists of the input voltage V s ∈ R 1 and the supply pressure p s ∈ R 1 .It can be seen that Taking the time derivative of the Hamiltonian gives: This system has power and resistive ports.

Pipe Model
In this section, a Port-Hamiltonian model of a single pipe segment is developed.The basis of these developments is the Navier-Stokes equations for one-dimensional nonstationary flow of gas in a pipe.The following assumptions are taken for the sake of model simplification [24,25]: The pipe is taken as rigid (the cross-section does not expand as a result of fluid flow).

2.
Frictional and gravitational effects are neglected (this will be relaxed in future works in this research area).

3.
The model parameters of the gas remain constant along the pipe cross-section but vary in time along the pipe length.Thus, they can be averaged about the cross-section, and thus, the gas flow is one-dimensional.

4.
The temperatures of the pipe walls are assumed to be constant and equal to the ambient room temperature.Hence, temperature effects are ignored.
Taking into account these assumptions, the coordinate system attached to a segment of pipe is illustrated in Figure 5. Thus, for a given time interval t s ≤ t < t f with start time t s and finish time t f , the length-normalized one-dimensional Euler equations for gas with a density ρ(t, z) ∶ (t s , t f ] × (0, ℓ) → R 1 flowing at a velocity ν(t, z) ∶ (t s , t f ] × (0, ℓ) → R 1 through a pipe of length ℓ ∈ R 1 + and cross-sectional area A p ∈ R 1 + are given by: where p(t, z) ∶ (t s , t f ] × (0, ℓ) → R 1 is the pressure, and ∂ i ∶= ∂/∂ i is the partial derivative with respect to the temporal and spatial variables given by the subscripts i ∈ {t, z}.

Port-Hamiltonian Formulation of Pipe-Flow Model
The fluid dynamics can be written in terms of mass per unit length, i.e., ϱ ∶= ρA p , as well as the fluid momentum, m ∶= ϱν.Thus, Equations ( 16) and ( 17) can be expressed as Defining the state vector of the gas flow through a pipe segment as χ p ∶= [ ϱ m ], the energy of the gas can be expressed in the form of a Hamiltonian H p [χ p ] ∶ R 2 → R 1 given by where is the internal energy of the gas, which, in the case of an isentropic fluid, can be expressed as a function of density.The Port-Hamiltonian dynamics take the following form: where J [χ p ], which is the formally skew-symmetric operator, and δ χ p H[χ p ], which is the variational derivative of the Hamiltonian density, are expressed as where h is the enthalpy, and J [χ p ] is a formally skew-symmetric operator.
The rate of change of the Hamiltonian can be found as where with components given by , and Expanding u p and y p gives Thus, the rate of change of the Hamiltonian is

Electric Circuit Model of the Lung
The Port-Hamiltonian formulation for nonlinear electric circuits is presented in this section.Since the main focus of this article is a mechanical ventilator model, the lung model is simplified by considering an electric circuit analogy.The model under consideration is that of a fully sedated patient who relies completely on the mechanical ventilator to breathe.The circuit model is shown in Figure 6.The circuit can be represented in the form of a network graph using graph theory.The graph of the circuit given in Figure 6 is given in Figure 7.The model has n = |V| = 7 vertices.The complete graph of the circuit, A 0 , is The ventilator input voltage is represented as a source S = (D S , L S , R S ).The set of sources is S = {v 7 }, and the dimension of the source is |S| = 1.The circuit also consists of m C = 5 capacitors (storage elements) that are represented as where the ith index used to distinguish between the components is i Furthermore there are m R = 4 resistors (dissipative elements) that are represented as where the ith index is given by i = {R ML , R IT , R TB , R BA }.
Selecting node 7 as the ground, the reduced incidence matrix, A, is given by where the dimensions of the components of The total energy of the circuit is given by the Hamiltonian where q C i ∈ R 1 is the charge of the ith capacitor for i = {C L , C T , C B , C A , C CW }.Thus, where I and O are appropriately sized identity and zero matrices, respectively, q = 0, and ϕ is the node potential.Expanding Equation (30) gives The Dirac structure is given by the set with the following attributes for (D, L, R):

Model Network Topology
Definition 11. (Directed graph) [27]: A directed graph G denotes the pair (V, A), where V(D) and A(D) denote the set of vertices and arcs, respectively.An arc is a distinct ordered-pair of vertices.
The directed graph of a mechanical ventilator model is composed of the disjoint union of the vertices associated with the patient as well as the inspiratory and expiratory limbs of the ventilator, which are given by v O , V I and V E , respectively.Similarly, the patient, inspiratory and expiratory arcs are given by a O , A I and A E , respectively.Each arc and vertex can further be subdivided into those associated with the blowers, valves, pipes and electric circuits present in the mechanical ventilator.Thus, the totality of vertices and arcs is given by and respectively, where the subscripts i ∈ {O, p, b, v, p, e} are used to indicate the patient, blowers, valves, pipes and electric circuit components, respectively.
A simplified graph of the mechanical ventilator shown in Figure 2 is given in Figure 8.This simplified graph indicates the elements belonging to the patient, as well as the inspiratory arcs and vertices belonging to the mechanical ventilator.The arcs belonging to the patient are denoted by A O 21 ∈ A O , while the vertices are denoted by The elements of the inspiratory and expiratory arcs and vertices, given by V I , V E and A IO , A OE , respectively.A more detailed representation of the graph of the mechanical ventilator in Figure 8 is given in Figure 9.
Figure 9 shows a detailed graph of the mechanical ventilator given in Figure 2 that indicates the patient vertex V O and the arcs and vertices along the inspiratory path, given by respectively, as well as the arcs and vertices along the expiratory path, given by respectively.

Model Interconnection/Coupling Conditions
In this section, the coupling conditions of the Port-Hamiltonian network model of the mechanical ventilator are given.The types of interconnections occurring in this model are given below: 1.
Pump-to-pipe interconnection: The pressure and flow rate of the fluid exiting the pump, P b and Q b , respectively, are equal to the pressure and flow rate at the inlet of the pipe, given by p(0) and m(0), respectively.Thus,

2.
Pipe-to-valve interconnection: The pressure and flow rate of the fluid entering/exiting a valve, P v and Q v , respectively, are equal to the pressure and flow rate at the inlet/outlet of the pipe, given by p(0) and m(0) for the inlet and p(ℓ) and m(ℓ) for the outlet.Thus, at the inlet, and at the outlet.

3.
Pipe-to-circuit interconnection: The pressure and fluid flow rate at the outlet of a pipe can act as inputs to a circuit model; thus, On the other hand, the output voltage and current of a circuit can be interconnected with a fluid pipe at the inlet of the pipe.In this case, the output voltage and or current of the circuit should be equal to the inlet pressure and inlet flow rate, respectively.This relation can expressed mathematically as: v c out = p(0) and i c out = m(0) at the inlet.
The Hamiltonian of the complete system is given by the sum of the Hamiltonian's of the individual systems: The rate of change of the energy of the complete system is The terms F p , M p , F v in , M v in , F v out and M v out are the external pressures and flow rates acting on the system.They should be equal to zero to complete the interconnection.

Structure-Preserving Discretization
The Port-Hamiltonian model of the pipe is a partial differential equation that is continuous in space.As such, it is difficult to simulate the dynamics of a pipe section.In order to do this, it is necessary to approximate the model with a discrete model: in this case, a finite difference model that is an approximation of the original system.Within the context of Port-Hamiltonian systems, an additional requirement is the need to ensure that the discrete approximation maintains the structural properties of the original system: e.g., skew symmetry, etc.
Each system state can be replaced with a discrete approximation consisting of a total on n elements, as can be seen in Figure 10.As such, ϱ ≈ ϱ d = [ϱ 1 , ϱ 2 , ⋯, ϱ n ] ∈ R n×1 , and m ≈ m d = [m 1 , m 2 , ⋯, m n ] ∈ R n×1 .As such, state vector χ p can be replaced by a discrete approximation where ∆ is the fixed discrete step size between points, and i = 1, 2, ⋯, n.In addition, the efforts at the boundaries are given by δ χ 0 H 0 and δ χ n H n .Thus, the Hamiltonian given in Equation ( 20) can be approximated by a discrete approximation such that H p [χ p ] ≈ ∆H d [χ d ] so that the discrete system effort is now δ χ d (H d ).A finite difference approximation of the spatial derivatives at the ith point is The central difference approximation at the ith point is In matrix form, this is and which can be re-written as where The skew-symmetric operator is clear from Equation (43).

Results and Discussion
The pipe and solenoid valve model parameters used in this work are given in Table 1 and Table 2, respectively.The Lung circuit model parameters are given in Table 3.

Model Validation
The model was validated using parameters obtained from the literature.The simulation results provided in the results and discussion section were found to be comparable to those in the existing literature.

Simulation Environment
Simulations were conducted using MATLAB Version: 9.13.0.2193358 (R2022b) Update 5 on an Intel Core i5 CPU with four cores and 8 GB of RAM.Figures 11 and 12 show ventilation curves for a lung under two conditions: a partially damaged lung with a compliance and resistance of 20 mL/cmH 2 O and 20 cmH 2 O-s/L, respectively, and a lung with complete damage, which is represented by a lung compliance and resistance of 10 mL/cmH 2 O and 50 cmH 2 O-s/L, respectively.The ventilation curves maintain the same sinusoidal behaviour.For the damaged lung case study, minimum ventilation values of flow over time and air volume are achieved.In the damaged lung, the compliance and resistance of the lung increase the pressure.

Conclusions and Recommendations
In this research work, we formulate a detailed mechanical ventilator in the Port-Hamiltonian framework.This is followed by a Port-Hamiltonian model of the respiratory system, and thereafter, these two systems are integrated.The conducted work demonstrates that the Port-Hamiltonian approach is a valid method for the modelling of an integrated mechanical ventilator-human respiratory system.The Port-Hamiltonian framework is modular in nature.Furthermore, the complete model structure is based on the underlying graph of the mechanical ventilator and human respiratory system.Future research directions include: • Developing a software framework for the automatic generation of the Port-Hamiltonian dynamics for various mechanical ventilator and human respiratory system configurations as well as their associated integrated models [19]; • Development of various reduced-order models; • Development of an integrated framework for the modelling of mechanical ventilator/human respiratory systems to enable control and system optimization [19,20]; • Taking advantage of the modular and graph theoretic nature of the Port-Hamiltonian approach to incorporate machine learning and artificial intelligence [19]; • Investigation of the most appropriate structure-preserving discretizations and modelorder reductions for various data-driven applications and control system designs.

Figure 2 .
Figure 2. Schematic diagram of a mechanical ventilator

Figure 3 .
Figure 3. Diagram of a solenoid valve in (i) the open position, which allows fluid flow, and (ii) the closed position, which stops fluid flow.

Figure 6 .
Figure 6. Circuit diagram of an electric model of a lung of a fully sedated patient [26].

Figure 7 .
Figure 7.The graph associated with the circuit diagram given in Figure 6.

Figure 8 .
Figure 8. Simplified graph of the mechanical ventilator given in Figure 2 indicating the elements belonging to the patient, given by the arcs A O 21 ∈ A O and vertices {V O 1 , V O 2 } ∈ V O , as well as elements of the inspiratory and expiratory arcs and vertices, given by V I , V E and A IO , A OE , respectively.

Figure 9 .
Figure 9. Detailed graph of the mechanical ventilator given in Figure 8 indicating the patient vertex V O as well as the arcs and vertices along the inspiratory and expiratory paths.

Figure 10 .
Figure 10.Staggered grid discretization of the one-dimensional Port-Hamiltonian pipe dynamic model.

Figure 11 .
Figure 11.Graph of air pressure versus time.

Figure 12 .
Figure 12.Graph of volume flow versus time.

Table 1 .
Pipe model parameter values.