(mol)= # Method-of-Lines Solution of Network Gas Flow *Author: [Ruizhi Yu](https://github.com/rzyu45)* Here we consider the transmission of gas in the following networks. ![11node](fig/11node.png) The squares are the sources producing gas while the circles are the consumers. The edges denote the pipes in which the gas is transferred. To get an insight into the state transfer of pressure and mass flow, we follow the derivations by Professor Gerd Steinebach[^paper1] which is based on the method-of-lines. ## Modelling ### Gas Pipes First, we have, for each pipe, the PDEs describing the isothermal gas transmission, with formulae ```{math} :label: pde_mol \pdv{p}{t}+\frac{c^2}{S}\pdv{q}{x}=&0,\\ \pdv{q}{t}+S\pdv{p}{x}+\frac{\lambda c^2q|q|}{2DSp}=&0 ``` where - $p$ is the spatial and temporal distribution of pressure - $q$ is the spatial and temporal distribution of mass flow - $c$ is the sound velocity - $S$ is the pipe cross-sectional area - $\lambda$ is the friction coefficient, - $D$ is the pipe diameter, and, suppose we have a pipe with length $L$, the initial conditions ```{math} p(x, 0)=p_0,\quad q(x,0)=q_0, ``` and the boundary conditions ```{math} p(0, t)=p_\text{b}(t),\quad q(L,t)=q_\text{b}(t). ``` ### Network Constraints Then there come the network constraints, that is, the continuity of mass flow ```{math} \sum_{i\in \mathbb{E}^\text{in}_k} q_i^\text{in}-\sum_{j\in \mathbb{E}^\text{out}_k} q_j^\text{out}=q_k, \quad k\in \mathbb{V} ``` where $q_i^\text{in/out}$ is the inlet/outlet mass flow of pipe $i$. $\mathbb{E}_k^\text{in/out}$ is the set of edges flowing into/out of node $k$. $q_k$ is the injection mass flow of node $k$, and the continuity of pressure ```{math} p_k=p^\text{out}_i=p^\text{in}_j,\quad i\in\mathbb{E}_k^\text{out},\ j\in\mathbb{E}_k^\text{in}, ``` where $p_k$ is the pressure of node $k$, $p_i^\text{in/out}$ is the inlet/outlet pressure of pipe $i$. ## Solution ### The Method of Lines The method of lines does the semidiscretization of PDEs for a system of ODEs. First, the PDE systems {eq}`pde_mol` are summarized by ```{math} \pdv{u}{t}+\pdv{f(u)}{x}=S(u), \quad x\in [0, L]. \label{hyperbolicpde} ``` with state vector $u$, flux function $f(u)$ and source term $S(u)$. The space interval is discretized into $0=x_0