|
| 1 | +# ab09nd - model order reduction |
| 2 | + |
| 3 | +import numpy as np |
| 4 | +from slycot import ab09nd |
| 5 | + |
| 6 | +# SLICOT reference test; see SLICOT-Reference/examples/AB09ND.dat, AB09ND.res, TAB09ND.f |
| 7 | +def test_slicot_ref(): |
| 8 | + n = 7 |
| 9 | + m = 2 |
| 10 | + p = 3 |
| 11 | + nr = None # Slycot uses None for ordsel = 'A' |
| 12 | + alpha = -0.6 |
| 13 | + tol1 = 1e-1 |
| 14 | + tol2 = 1e-14 |
| 15 | + dico = 'C' |
| 16 | + job = 'N' |
| 17 | + equil = 'N' |
| 18 | + |
| 19 | + a = np.array([[-0.04165, 0.0000, 4.9200, -4.9200, 0.0000, 0.0000, 0.0000], |
| 20 | + [-5.2100, -12.500, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000], |
| 21 | + [0.0000, 3.3300, -3.3300, 0.0000, 0.0000, 0.0000, 0.0000], |
| 22 | + [0.5450, 0.0000, 0.0000, 0.0000, -0.5450, 0.0000, 0.0000], |
| 23 | + [0.0000, 0.0000, 0.0000, 4.9200, -0.04165, 0.0000, 4.9200], |
| 24 | + [0.0000, 0.0000, 0.0000, 0.0000, -5.2100, -12.500, 0.0000], |
| 25 | + [0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 3.3300, -3.3300]]) |
| 26 | + |
| 27 | + b = np.array([[0.0000, 0.0000], |
| 28 | + [12.500, 0.0000], |
| 29 | + [0.0000, 0.0000], |
| 30 | + [0.0000, 0.0000], |
| 31 | + [0.0000, 0.0000], |
| 32 | + [0.0000, 12.500], |
| 33 | + [0.0000, 0.0000]]) |
| 34 | + |
| 35 | + c = np.array([[1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000], |
| 36 | + [0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000], |
| 37 | + [0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000]]) |
| 38 | + |
| 39 | + d = np.zeros((3,2)) |
| 40 | + |
| 41 | + nr, ar, br, cr, dr, ns, hsv = \ |
| 42 | + ab09nd(dico, job, equil, n, m, p, a, b, c, d, alpha, nr, tol1, tol2) |
| 43 | + |
| 44 | + # reference values |
| 45 | + ref_nr = 5 |
| 46 | + ref_hsv = np.array([1.9178, 0.8621, 0.7666, 0.0336, 0.0246]) |
| 47 | + ref_ar = np.array([[-0.5181, -1.1084, 0.0000, 0.0000, 0.0000], |
| 48 | + [ 8.8157, -0.5181, 0.0000, 0.0000, 0.0000], |
| 49 | + [ 0.0000, 0.0000, 0.5847, 0.0000, 1.9230], |
| 50 | + [ 0.0000, 0.0000, 0.0000, -1.6606, 0.0000], |
| 51 | + [ 0.0000, 0.0000, -4.3823, 0.0000, -3.2922]]) |
| 52 | + |
| 53 | + ref_br = np.array([[-1.2837, 1.2837], |
| 54 | + [-0.7522, 0.7522], |
| 55 | + [-0.6379, -0.6379], |
| 56 | + [ 2.0656, -2.0656], |
| 57 | + [-3.9315, -3.9315]]) |
| 58 | + |
| 59 | + ref_cr = np.array([[-0.1380, -0.6445, -0.6416, -0.6293, 0.2526], |
| 60 | + [ 0.6246, 0.0196, 0.0000, 0.4107, 0.0000], |
| 61 | + [ 0.1380, 0.6445, -0.6416, 0.6293, 0.2526]]) |
| 62 | + |
| 63 | + ref_dr = np.array([[ 0.0582, -0.0090], |
| 64 | + [ 0.0015, -0.0015], |
| 65 | + [-0.0090, 0.0582]]) |
| 66 | + |
| 67 | + assert nr == ref_nr |
| 68 | + |
| 69 | + np.testing.assert_array_almost_equal(hsv[:nr], ref_hsv, decimal=4) |
| 70 | + np.testing.assert_array_almost_equal(ar, ref_ar, decimal=4) |
| 71 | + np.testing.assert_array_almost_equal(br, ref_br, decimal=4) |
| 72 | + np.testing.assert_array_almost_equal(cr, ref_cr, decimal=4) |
| 73 | + np.testing.assert_array_almost_equal(dr, ref_dr, decimal=4) |
| 74 | + |
| 75 | + |
| 76 | +# gh-242 regression test |
| 77 | +# iwork was incorrectly sized |
| 78 | +def test_gh242_regression(): |
| 79 | + n = 67 |
| 80 | + m = 1 |
| 81 | + p = 1 |
| 82 | + |
| 83 | + a = -np.eye(n) |
| 84 | + b = np.zeros((n, m)) |
| 85 | + c = np.zeros((p, n)) |
| 86 | + d = np.array([[42.24]]) |
| 87 | + |
| 88 | + nr, ar, br, cr, dr, ns, hsv = \ |
| 89 | + ab09nd(dico='C', job='B', equil='S', n=a.shape[0], |
| 90 | + m=b.shape[1], p=c.shape[0], A=a, B=b, C=c, D=d) |
| 91 | + |
| 92 | + assert nr == 0 |
| 93 | + np.testing.assert_equal(d, dr) |
0 commit comments