Commit d8302ae1 authored by Blais, Chris's avatar Blais, Chris
Browse files

Standardize figure names

parent 1483c16a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
%% Cell type:code id:c8f1b999 tags:

``` python
import sympy as sy
import pandas as pd
import os
import scipy as sp
import numpy as np
import math
import itertools
import sys
module_path = os.path.join(os.path.dirname(os.path.abspath('')))
if module_path not in sys.path:
    sys.path.insert(0, module_path)
else:
    print("path already in sys.path")

import matplotlib.pyplot as plt
from numerical_labelling.labelling import *
```

%% Output

    path already in sys.path

%% Cell type:markdown id:8e4f0a26 tags:

## Linear case
<img src="../fig/membrane_corrected.png" width="50%">
<img src="../fig/ccro_layout.png" width="50%">

%% Cell type:code id:a87b952f tags:

``` python
# generate constraints
def constr_mem_lin():
    """
    constraint equations for membrane example
    """

    m1, m2, m3, m4, m5, m6, m7, m8 = sy.symbols('m1 m2 m3 m4 m5 m6 m7 m8') # overall mass flow rates
    varbs = [
        m1, m2, m3, m4, m5, m6, m7, m8
        ]
    var_labels = [
        'M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8'
        ]

    # Create a dictionary to store all variables and their values
    var_dict = dict(zip(var_labels, varbs))

    constr = {}
    # mass balance
    constr[0] = m1 - m2
    constr[1] = m2 - m3 + m8
    constr[2] = m3 - m4 - m5
    constr[3] = m5 - m6 - m7
    constr[4] = m7 - m8

    return constr, var_dict
```

%% Cell type:code id:92ba160f tags:

``` python
constr_lin, varbs_lin = constr_mem_lin()
```

%% Cell type:code id:8f31dfa5 tags:

``` python
jac_lin = jacsym(constr_lin.values(), varbs_lin.values())
```

%% Cell type:code id:307d5feb tags:

``` python
jac_lin
```

%% Output

    $\displaystyle \left[\begin{matrix}1 & -1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & -1 & 0 & 0 & 0 & 0 & 1\\0 & 0 & 1 & -1 & -1 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 1 & -1 & -1 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 1 & -1\end{matrix}\right]$
    Matrix([
    [1, -1,  0,  0,  0,  0,  0,  0],
    [0,  1, -1,  0,  0,  0,  0,  1],
    [0,  0,  1, -1, -1,  0,  0,  0],
    [0,  0,  0,  0,  1, -1, -1,  0],
    [0,  0,  0,  0,  0,  0,  1, -1]])

%% Cell type:code id:7c92dbab tags:

``` python
layout = [True, True, True, False, False, False, False, False]
layout_inv = [not(i) for i in layout]
layout_inv
```

%% Output

    [False, False, False, True, True, True, True, True]

%% Cell type:code id:035143cd tags:

``` python
ju = jac_lin[:,layout_inv]
jm = jac_lin[:, layout]
```

%% Cell type:code id:50a64f26 tags:

``` python
ju.rref()[0]
```

%% Output

    $\displaystyle \left[\begin{matrix}1 & 0 & 1 & 0 & 0\\0 & 1 & -1 & 0 & 0\\0 & 0 & 0 & 1 & 0\\0 & 0 & 0 & 0 & 1\\0 & 0 & 0 & 0 & 0\end{matrix}\right]$
    Matrix([
    [1, 0,  1, 0, 0],
    [0, 1, -1, 0, 0],
    [0, 0,  0, 1, 0],
    [0, 0,  0, 0, 1],
    [0, 0,  0, 0, 0]])

%% Cell type:code id:1fad065b tags:

``` python
# transfer one measured over:
layout = [False, True, True, False, False, False, False, False]
layout_inv = [not(i) for i in layout]
ju = jac_lin[:,layout_inv]
jm = jac_lin[:, layout]
ju.rref()[0]
```

%% Output

    $\displaystyle \left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 1 & 0 & 0\\0 & 0 & 1 & -1 & 0 & 0\\0 & 0 & 0 & 0 & 1 & 0\\0 & 0 & 0 & 0 & 0 & 1\end{matrix}\right]$
    Matrix([
    [1, 0, 0,  0, 0, 0],
    [0, 1, 0,  1, 0, 0],
    [0, 0, 1, -1, 0, 0],
    [0, 0, 0,  0, 1, 0],
    [0, 0, 0,  0, 0, 1]])

%% Cell type:markdown id:21ed7f7f tags:

## bilinear case

%% Cell type:code id:e1d43176 tags:

``` python
import sympy as sy
import pandas as pd
import os
import scipy as sp
import numpy as np
import math
import itertools
import sys
module_path = os.path.join(os.path.dirname(os.path.abspath('')))
if module_path not in sys.path:
    sys.path.insert(0, module_path)
else:
    print("path already in sys.path")

import matplotlib.pyplot as plt
from numerical_labelling.labelling import *
from numerical_labelling.plot_layout import make_pretty_labels
```

%% Output

    path already in sys.path

%% Cell type:code id:a6ff637e tags:

``` python
def constr_spl():
    constr = {}
    m1, m2, m3 = sy.symbols("m1 m2 m3")
    x1, x2, x3 = sy.symbols("x1 x2 x3")
    varbs_sy = [m1, m2, m3, x1, x2, x3]

    constr[0] = m1 - m2 - m3
    constr[1] = x1 - x2
    constr[2] = x1 - x3

    varb_labels = [
        "m1", "m2", "m3",
        "x1", "x2", "x3",
        ]

    varbs = dict(zip(varb_labels,varbs_sy))

    return constr, varbs

def constr_spl_sup(simple_constr = False):
    "include superfluous constraint"
    constr = {}
    m1, m2, m3 = sy.symbols("m1 m2 m3")
    x1, x2, x3 = sy.symbols("x1 x2 x3")
    varbs_sy = [m1, m2, m3, x1, x2, x3]

    constr[0] = m1 - m2 - m3
    constr[1] = x1 - x2
    constr[2] = x1 - x3
    if simple_constr:
        constr[3] = m1 - m2 - m3
    else:
        constr[3] = m1*x1 - m2*x2 - m3*x3

    varb_labels = [
        "m1", "m2", "m3",
        "x1", "x2", "x3",
        ]

    varbs = dict(zip(varb_labels,varbs_sy))

    return constr, varbs
```

%% Cell type:code id:9a97895b tags:

``` python
constr_req, varbs_req = constr_spl()
constr_sup, varbs_sup = constr_spl_sup()
constr_sup_mb, varbs_sup_mb = constr_spl_sup(simple_constr=True)
jac_req = jacsym(constr_req.values(), varbs_req.values())
jac_sup = jacsym(constr_sup.values(), varbs_sup.values())
jac_sup_mb = jacsym(constr_sup_mb.values(), varbs_sup_mb.values())
```

%% Cell type:code id:2701d8e2 tags:

``` python
layout = [
    True, False, False,
    False, True, False
]

bool_measured = np.where(np.array(layout))[0]
bool_unmeasured = np.where(~np.array(layout))[0]
vb_all, vb_m, vb_um = make_pretty_labels(varbs_req, layout)
```

%% Cell type:code id:f55e7793 tags:

``` python
r1, r2, r3, r4 = sy.symbols("r1 r2 r3 r4")
rhs_syms = sy.Matrix([r1, r2, r3, r4])
```

%% Cell type:code id:4c3f3568 tags:

``` python
Ju_req = jac_req[:, list(bool_unmeasured)]
Ju_sup = jac_sup[:, list(bool_unmeasured)]
Ju_sup_mb = jac_sup_mb[:, list(bool_unmeasured)]
rref_req, rhs_req = Ju_req.rref_rhs(rhs_syms[:Ju_req.shape[0],:])
rref_sup, rhs_sup = Ju_sup.rref_rhs(rhs_syms[:Ju_sup.shape[0],:])
rref_sup_mb, rhs_sup_mb = Ju_sup_mb.rref_rhs(rhs_syms[:Ju_sup_mb.shape[0], :])
```

%% Cell type:code id:d4b906cd tags:

``` python
sy.Matrix.vstack(vb_um, rref_req)
```

%% Output

    $\displaystyle \left[\begin{matrix}m_{2} & m_{3} & x_{1} & x_{3}\\- & - & - & -\\1 & 1 & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right]$
    Matrix([
    [m2, m3, x1, x3],
    [ -,  -,  -,  -],
    [ 1,  1,  0,  0],
    [ 0,  0,  1,  0],
    [ 0,  0,  0,  1]])

%% Cell type:code id:aad07395 tags:

``` python
sy.Matrix.vstack(vb_um, rref_sup)
```

%% Output

    $\displaystyle \left[\begin{matrix}m_{2} & m_{3} & x_{1} & x_{3}\\- & - & - & -\\1 & 0 & 0 & 0\\0 & 1 & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\end{matrix}\right]$
    Matrix([
    [m2, m3, x1, x3],
    [ -,  -,  -,  -],
    [ 1,  0,  0,  0],
    [ 0,  1,  0,  0],
    [ 0,  0,  1,  0],
    [ 0,  0,  0,  1]])

%% Cell type:code id:07ba3528 tags:

``` python
sy.Matrix.vstack(vb_um, rref_sup_mb)
```

%% Output

    $\displaystyle \left[\begin{matrix}m_{2} & m_{3} & x_{1} & x_{3}\\- & - & - & -\\1 & 1 & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 0 & 1\\0 & 0 & 0 & 0\end{matrix}\right]$
    Matrix([
    [m2, m3, x1, x3],
    [ -,  -,  -,  -],
    [ 1,  1,  0,  0],
    [ 0,  0,  1,  0],
    [ 0,  0,  0,  1],
    [ 0,  0,  0,  0]])

%% Cell type:code id:20d2fb5a tags:

``` python
rhs_req
```

%% Output

    $\displaystyle \left[\begin{matrix}- r_{1}\\r_{2}\\r_{2} - r_{3}\end{matrix}\right]$
    Matrix([
    [    -r1],
    [     r2],
    [r2 - r3]])

%% Cell type:code id:3257c8d7 tags:

``` python
rhs_sup
```

%% Output

    $\displaystyle \left[\begin{matrix}\frac{m_{1} r_{2} - m_{3} r_{2} + m_{3} r_{3} + r_{1} x_{3} - r_{4}}{x_{2} - x_{3}}\\\frac{- m_{1} r_{2} + m_{3} r_{2} - m_{3} r_{3} - r_{1} x_{2} + r_{4}}{x_{2} - x_{3}}\\r_{2}\\r_{2} - r_{3}\end{matrix}\right]$
    Matrix([
    [ (m1*r2 - m3*r2 + m3*r3 + r1*x3 - r4)/(x2 - x3)],
    [(-m1*r2 + m3*r2 - m3*r3 - r1*x2 + r4)/(x2 - x3)],
    [                                             r2],
    [                                        r2 - r3]])

%% Cell type:code id:56de1575 tags:

``` python
rhs_sup_mb
```

%% Output

    $\displaystyle \left[\begin{matrix}- r_{4}\\r_{2}\\r_{2} - r_{3}\\r_{1} - r_{4}\end{matrix}\right]$
    Matrix([
    [    -r4],
    [     r2],
    [r2 - r3],
    [r1 - r4]])

%% Cell type:code id:e4b4c4d8 tags:

``` python
rref_subout, rhs_subout = Ju_sup.subs({'x2':varbs_req['x3']}).rref_rhs(rhs_syms[:4, :])
rhs_subout
```

%% Output

    $\displaystyle \left[\begin{matrix}\frac{m_{1} r_{2} - m_{3} r_{2} + m_{3} r_{3} - r_{4}}{x_{3}}\\r_{2}\\r_{2} - r_{3}\\\frac{m_{1} r_{2} - m_{3} r_{2} + m_{3} r_{3} + r_{1} x_{3} - r_{4}}{x_{3}}\end{matrix}\right]$
    Matrix([
    [        (m1*r2 - m3*r2 + m3*r3 - r4)/x3],
    [                                     r2],
    [                                r2 - r3],
    [(m1*r2 - m3*r2 + m3*r3 + r1*x3 - r4)/x3]])

%% Cell type:code id:224f51bb tags:

``` python
Ju_req
```

%% Output

    $\displaystyle \left[\begin{matrix}-1 & -1 & 0 & 0\\0 & 0 & 1 & 0\\0 & 0 & 1 & -1\end{matrix}\right]$
    Matrix([
    [-1, -1, 0,  0],
    [ 0,  0, 1,  0],
    [ 0,  0, 1, -1]])

%% Cell type:code id:f0f6e228 tags:

``` python
varbs_req['x2']
```

%% Output

    $\displaystyle x_{2}$
    x2

%% Cell type:markdown id:58024a89 tags:

## Bilinear failure: operating point selection

%% Cell type:markdown id:e4747f6d tags:
+2 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@
   "metadata": {},
   "source": [
    "## Linear case\n",
    "<img src=\"../fig/membrane_corrected.png\" width=\"50%\">"
    "<img src=\"../fig/ccro_layout.png\" width=\"50%\">"
   ]
  },
  {
@@ -1262,7 +1262,7 @@
   "metadata": {},
   "source": [
    "## QR factorization\n",
    "<img src=\"../fig/membrane_corrected.png\" width=\"50%\">"
    "<img src=\"../fig/ccro_layout.png\" width=\"50%\">"
   ]
  },
  {
(17.6 KiB)

File moved.

(13.1 KiB)

File moved.

fig/example_schematic.png

deleted100644 → 0
−10.8 KiB
Loading image diff...
Loading