export B767FlutterCondition

"""
    B767FlutterCondition

"""
struct B767FlutterCondition <: ControlBenchmarkProblem end

@addbenchmark B767FlutterCondition "ifac06" "Boeing 767" "Boeing 767 at flutter condition" Set([:linear, :unstable, :continuous, :aerospace, :nonnormal, :nonminimum_phase, :ifac])


"""
    controlbenchmark(::B767FlutterCondition) -> sys
"""
function controlbenchmark( ::B767FlutterCondition )

    # The state transition matrix
    #           R    C        Value
    Aparts = [   1    1       0.1015;
                 2    1        19.77;
                 1    2       -19.77;
                 2    2       0.1015;
                 3    3    -0.023202;
                 4    3     0.092543;
                 3    4    -0.092543;
                 4    4    -0.023202;
                 5    5      -0.3165;
                 6    5        14.33;
                 5    6       -14.33;
                 6    6      -0.3165;
                 7    7      -0.3892;
                 8    7        22.29;
                 7    8       -22.29;
                 8    8      -0.3892;
                 9    9      -0.9883;
                10    9        36.16;
                 9   10       -36.16;
                10   10      -0.9883;
                11   11       -1.342;
                12   11        2.457;
                11   12       -2.547;
                12   12       -1.342;
                13   13       -2.312;
                14   13        21.51;
                13   14       -21.51;
                14   14       -2.312;
                15   15       -2.792;
                16   15        26.71;
                15   16       -26.71;
                16   16       -2.792;
                17   17       -2.796;
                18   17        63.79;
                17   18       -63.79;
                18   18       -2.796;
                19   19       -3.332;
                20   19        56.37;
                19   20       -56.37;
                20   20       -3.332;
                21   21       -3.418;
                22   21        88.67;
                21   22       -88.67;
                22   22       -3.418;
                23   23       -4.441;
                24   23        69.45;
                23   24       -69.45;
                24   24       -4.441;
                25   25       -5.108;
                26   25        53.39;
                25   26       -53.39;
                26   26       -5.108;
                27   27       -5.199;
                28   27        50.64;
                27   28       -50.64;
                28   28       -5.199;
                29   29       -5.301;
                30   30        -5.67;
                31   30        92.96;
                30   31       -92.96;
                31   31        -5.67;
                32   32       -6.197;
                33   32         40.0;
                32   33        -40.0;
                33   33       -6.197;
                34   34       -8.177;
                35   34        16.61;
                34   35       -16.61;
                35   35       -8.177;
                36   36       -8.221;
                37   36        139.1;
                36   37       -139.1;
                37   37       -8.221;
                38   38       -10.35;
                39   38        163.0;
                38   39       -163.0;
                39   39       -10.35;
                40   40       -11.72;
                41   40        109.3;
                40   41       -109.3;
                41   41       -11.72;
                42   42       -11.79;
                43   42        304.6;
                42   43       -304.6;
                43   43       -11.79;
                44   44       -33.27;
                45   45       -221.2;
                 1   46      -1970.0;
                 2   46      -2665.0;
                 3   46        586.9;
                 4   46       -501.1;
                 5   46        134.5;
                 6   46       -164.5;
                 7   46        608.5;
                 8   46       -77.54;
                 9   46      -1117.0;
                10   46       1790.0;
                11   46     -13858.0;
                12   46      15010.0;
                13   46     -21697.0;
                14   46      19966.0;
                15   46      -2861.0;
                16   46       6583.0;
                17   46      -2212.0;
                18   46       6321.0;
                19   46      13964.0;
                20   46       2382.0;
                21   46       -303.7;
                22   46        542.8;
                23   46       -527.1;
                24   46       2658.0;
                25   46        25341;
                26   46       6538.0;
                27   46      42048.0;
                28   46        210.6;
                30   46        994.2;
                31   46        769.2;
                32   46      42702.0;
                33   46     -76982.0;
                34   46       -288.8;
                35   46      -2237.0;
                36   46     -16942.0;
                37   46     -12513.0;
                38   46       5748.0;
                39   46     -14657.0;
                40   46      -4089.0;
                41   46       7940.0;
                42   46       9582.0;
                43   46       9474.0;
                48   46    -800000.0;
                 1   47        6.796;
                 2   47        7.196;
                 3   47    0.0017334;
                 4   47    0.0041488;
                 5   47       -0.269;
                 6   47       0.4627;
                 7   47       -1.835;
                 8   47       0.1595;
                 9   47        4.615;
                10   47       -3.752;
                11   47        0.555;
                12   47       -3.138;
                13   47        61.46;
                14   47       -53.56;
                15   47        13.14;
                16   47       -19.32;
                17   47       -12.28;
                18   47       -27.17;
                19   47       -17.24;
                20   47       -20.08;
                21   47        2.624;
                22   47       0.5789;
                23   47       -36.01;
                24   47        3.812;
                25   47       -36.45;
                26   47       -28.56;
                27   47       -59.43;
                28   47       -39.51;
                30   47        13.57;
                31   47         10.6;
                32   47       -120.7;
                33   47        140.6;
                34   47      -0.9428;
                35   47        8.455;
                36   47        94.43;
                37   47        68.02;
                38   47       -35.78;
                39   47        216.8;
                40   47       -258.1;
                41   47        309.0;
                42   47         37.3;
                43   47         41.4;
                46   47          1.0;
                48   47     -60800.0;
                 1   48      -0.1334;
                 2   48      -0.1568;
                 3   48  -4.3119e-05;
                 4   48  -8.0848e-05;
                 5   48    0.0049694;
                 6   48    -0.008432;
                 7   48     0.036978;
                 8   48   -0.0020525;
                 9   48    -0.084286;
                10   48     0.071871;
                11   48    -0.012727;
                12   48     0.065016;
                13   48       -1.286;
                14   48        1.121;
                15   48      -0.2426;
                16   48       0.3841;
                17   48       0.1229;
                18   48       0.2049;
                19   48     0.035851;
                20   48       0.3605;
                21   48      -0.1208;
                22   48       0.1194;
                23   48       0.3072;
                24   48    -0.037101;
                25   48       0.4514;
                26   48       0.3244;
                27   48       0.7558;
                28   48       0.5076;
                30   48    -0.021971;
                31   48    -0.092043;
                32   48         1.94;
                33   48       -2.796;
                34   48     0.023831;
                35   48      -0.1565;
                36   48       -1.144;
                37   48      -0.6821;
                38   48       0.2067;
                39   48      -0.6615;
                40   48       -1.059;
                41   48        1.175;
                42   48    -0.031126;
                43   48    -0.050827;
                47   48          1.0;
                48   48      -1060.0;
                 1   49      -1429.0;
                 2   49      -2222.0;
                 3   49        119.0;
                 4   49       -105.9;
                 5   49       -146.8;
                 6   49        196.0;
                 7   49        175.1;
                 8   49        9.616;
                 9   49       -34.14;
                10   49       -222.7;
                11   49      -2014.0;
                12   49       2668.0;
                13   49      -3652.0;
                14   49       2881.0;
                15   49      -1080.0;
                16   49      -3883.0;
                17   49      -1647.0;
                18   49      -1045.0;
                19   49        562.0;
                20   49        902.6;
                21   49       1129.0;
                22   49      -1258.0;
                23   49      -1267.0;
                24   49       -49.11;
                25   49       4360.0;
                26   49       3790.0;
                27   49       2501.0;
                28   49       -470.4;
                30   49        828.4;
                31   49        810.0;
                32   49      -3077.0;
                33   49       -348.3;
                34   49      -1499.0;
                35   49      -6578.0;
                36   49       -60.89;
                37   49       -29.37;
                38   49       -39.31;
                39   49        123.4;
                40   49        33.03;
                41   49        61.04;
                42   49        140.9;
                43   49        156.3;
                51   49    -800000.0;
                 1   50        18.03;
                 2   50       -2.684;
                 3   50   0.00048611;
                 4   50    0.0010274;
                 5   50      -0.7097;
                 6   50        1.345;
                 7   50       -1.082;
                 8   50        0.637;
                 9   50        6.425;
                10   50        1.899;
                11   50    -0.050439;
                12   50        -1.06;
                13   50        5.074;
                14   50       -26.77;
                15   50        48.49;
                16   50       -12.93;
                17   50        -5.13;
                18   50       -15.59;
                19   50       -25.48;
                20   50       -1.623;
                21   50        4.399;
                22   50       -6.993;
                23   50        7.583;
                24   50       -4.347;
                25   50       -131.3;
                26   50        90.71;
                27   50       -17.39;
                28   50       -18.75;
                30   50         12.9;
                31   50        19.07;
                32   50         35.9;
                33   50       -38.56;
                34   50       0.9758;
                35   50         49.5;
                36   50       0.2221;
                37   50       0.4639;
                38   50       -0.683;
                39   50        9.043;
                40   50        -2.04;
                41   50        2.311;
                42   50        2.627;
                43   50        3.098;
                49   50          1.0;
                51   50     -60800.0;
                 1   51      -0.1517;
                 2   51    -0.050292;
                 3   51  -7.4279e-06;
                 4   51  -1.1816e-05;
                 5   51    0.0012317;
                 6   51   -0.0039645;
                 7   51     0.011391;
                 8   51   -0.0028823;
                 9   51    -0.049071;
                10   51    -0.015192;
                11   51    0.0010263;
                12   51     0.011647;
                13   51      -0.1277;
                14   51        0.254;
                15   51      -0.3712;
                16   51     0.010825;
                17   51     0.020187;
                18   51     0.064588;
                19   51       0.1072;
                20   51     0.077575;
                21   51     -0.02724;
                22   51     0.029297;
                23   51   -0.0065626;
                24   51   -0.0084969;
                25   51       0.8394;
                26   51      -0.3495;
                27   51       0.1113;
                28   51       0.1395;
                30   51    -0.036967;
                31   51    -0.081012;
                32   51      -0.2467;
                33   51       0.1981;
                34   51    -0.041943;
                35   51       -0.498;
                36   51    -0.011955;
                37   51   -0.0099611;
                38   51    0.0078189;
                39   51    -0.087434;
                40   51     0.023536;
                41   51    -0.028729;
                42   51    -0.018542;
                43   51    -0.022171;
                50   51          1.0;
                51   51      -1060.0;
                53   52          1.0;
                 1   53       -3.158;
                 2   53        1.779;
                 3   53    0.0053132;
                 4   53    0.0080111;
                 5   53       0.1066;
                 6   53      -0.4078;
                 7   53       0.1001;
                 8   53      -0.1571;
                 9   53        -1.06;
                10   53       0.4854;
                11   53       -2.733;
                12   53        2.067;
                13   53        3.001;
                14   53        3.544;
                15   53       -7.199;
                16   53        7.207;
                17   53       0.6186;
                18   53        1.076;
                19   53        2.821;
                20   53      -0.7866;
                21   53      -0.1111;
                22   53        1.509;
                23   53      -0.3659;
                24   53       0.8635;
                25   53        7.433;
                26   53       -15.36;
                27   53         4.57;
                28   53      -0.2771;
                29   53       -1.251;
                30   53      -0.5031;
                31   53      -0.4524;
                32   53       -1.592;
                33   53        1.956;
                34   53       -5.981;
                35   53       -10.88;
                36   53       -1.121;
                37   53       0.1532;
                38   53      -0.4254;
                39   53      -0.7886;
                40   53      -0.1053;
                41   53       -2.007;
                42   53       0.1886;
                43   53    0.0092049;
                44   53       -17.07;
                45   53       -37.83;
                52   53      -0.2668;
                53   53       -1.033;
                48   54  -16000000.0;
                54   54        -20.0;
                51   55  -16000000.0;
                55   55        -20.0 ]

    A = sparse( Aparts[:, 1], Aparts[:, 2], Aparts[:, 3], 55, 55 )

    # The disturbance input mapping matrix
    #           R    C        Value
    B1parts = [ 52   1         0.3713;
                53   1          1.245;
                48   2       800000.0;
                54   2            1.0;
                51   3       800000.0;
                55   3            1.0 ]

    B1 = sparse( B1parts[:, 1], B1parts[:, 2], B1parts[:, 3], 55, 3 )

    # The control input mapping matrix
    #           R    C        Value
    B2parts = [ 48   1       800000.0;
                51   2       800000.0 ]

    B2 = sparse( B2parts[:, 1], B2parts[:, 2], B2parts[:, 3], 55, 2 )


    # The output measurement matrix
    #           R    C        Value
    C1parts = [  1   1     4.4247e-05;
                 2   1          35.92;
                 1   2     4.3403e-05;
                 2   2         -12.46;
                 1   3     4.9713e-05;
                 2   3        -0.5332;
                 1   4     4.5556e-05;
                 2   4        -0.5659;
                 1   5    -4.1311e-06;
                 2   5        -0.9664;
                 1   6     7.9201e-06;
                 2   6          12.75;
                 1   7     7.2496e-06;
                 2   7         -21.45;
                 1   8    -6.7385e-05;
                 2   8          6.822;
                 1   9    -0.00018236;
                 2   9          33.88;
                 1   10    2.0657e-05;
                 2   10            17;
                 1   11    0.00013194;
                 2   11        -0.138;
                 1   12   -0.00015849;
                 2   12       -0.8803;
                 1   13   -6.7655e-05;
                 2   13         5.465;
                 1   14   -8.7358e-06;
                 2   14        -1.614;
                 1   15   -9.8119e-05;
                 2   15         55.18;
                 1   16    3.1119e-05;
                 2   16          30.1;
                 1   17   -5.7479e-05;
                 2   17        -4.878;
                 1   18      0.000316;
                 2   18         14.36;
                 1   19    -0.0005775;
                 2   19         62.54;
                 1   20       0.00071;
                 2   20         55.18;
                 1   21   -9.6843e-05;
                 2   21        -138.8;
                 1   22    2.9934e-05;
                 2   22        -104.4;
                 1   23    0.00054014;
                 2   23         6.831;
                 1   24    -0.0004762;
                 2   24        -11.78;
                 1   25    -4.163e-06;
                 2   25        -55.04;
                 1   26   -0.00021609;
                 2   26        -30.66;
                 1   27   -0.00010541;
                 2   27         1.402;
                 1   28   -3.1883e-05;
                 2   28        -30.33;
                 1   29   -0.00015062;
                 2   29         4.869;
                 1   30   -0.00027714;
                 2   30        -74.28;
                 1   31   -0.00024361;
                 2   31         74.14;
                 1   32     2.799e-05;
                 2   32          16.3;
                 1   33   -0.00016592;
                 2   33         3.118;
                 1   34    1.2748e-05;
                 2   34         8.728;
                 1   35   -2.0762e-05;
                 2   35        -74.53;
                 1   36   -0.00012546;
                 2   36          1.46;
                 1   37    -4.436e-05;
                 2   37        -3.334;
                 1   38   -1.0147e-05;
                 2   38        -7.367;
                 1   39    0.00015343;
                 2   39        -1.032;
                 1   40    2.1956e-05;
                 2   40         2.867;
                 1   41   -2.9386e-05;
                 2   41         6.583;
                 1   42    6.5513e-05;
                 2   42        -1.361;
                 1   43    6.1813e-05;
                 2   43          1.35;
                 1   44    1.9995e-05;
                 2   44         10.71;
                 1   45    8.9674e-06;
                 2   45        -25.91;
                 2   46         48.52;
                 2   47        -7.932;
                 2   48      0.079915;
                 2   49        -25618;
                 2   50        -167.4;
                 2   51        0.2213;
                 2   53          1.88 ]

    C1 = sparse( C1parts[:, 1], C1parts[:, 2], C1parts[:, 3], 2, 55 )

    # The output performance matrix (regulated)
    #           R    C        Value
    C2parts = [  1   1      -0.00196156517750494;
                 2   1       -0.0129504190712116;
                 3   1      -0.00576793734796071;
                 1   2      -0.00178666088824936;
                 2   2      -0.00659743772384401;
                 3   2       0.00212717146699555;
                 1   3       0.00383083053052468;
                 2   3         0.000520641604177;
                 3   3      0.000855251280034119;
                 1   4       0.00417773050112139;
                 2   4      0.000964484966186617;
                 3   4      0.000948383511296986;
                 1   5       0.00271334336979307;
                 2   5       0.00603316894923389;
                 3   5      0.000112181294363187;
                 1   6       0.00343099389588498;
                 2   6       0.00288047491396818;
                 3   6      -0.00240891603216052;
                 1   7     -0.000578619067781213;
                 2   7        0.0125202768040487;
                 3   7       0.00399138133983713;
                 1   8     -0.000744991440487741;
                 2   8       0.00414241786038058;
                 3   8     -0.000938835501033062;
                 1   9      -0.00335052241025187;
                 2   9        0.0012720384899837;
                 3   9        0.0032244100235547;
                 1  10      0.000254794053305802;
                 2  10       0.00330629051960048;
                 3  10       0.00282214139440248;
                 1  11       0.00638400655782871;
                 2  11       0.00138777668592609;
                 3  11       0.00123153679928778;
                 1  12       0.00655735958952992;
                 2  12       0.00137912336286498;
                 3  12       0.00142672317304374;
                 1  13     -0.000209807584228979;
                 2  13      -0.00121471022470382;
                 3  13      -0.00140825325154959;
                 1  14      0.000596458529656505;
                 2  14      -0.00375806609441612;
                 3  14      -0.00084585979452862;
                 1  15       -0.0075373665495052;
                 2  15      -0.00171696351737595;
                 3  15      -0.00223360830272454;
                 1  16      -0.00707644914866206;
                 2  16      -0.00037245344675543;
                 3  16      -0.00256700603816976;
                 1  17      -0.00136471883345984;
                 2  17     -3.18478344161734e-07;
                 3  17      -0.00108487310064357;
                 1  18       0.00216827024662518;
                 2  18       0.00166540413413682;
                 3  18       0.00532966802437075;
                 1  19       0.00155164536876182;
                 2  19       0.00124319407977998;
                 3  19       0.00306005902720846;
                 1  20       0.00200693946097036;
                 2  20      0.000469803331192958;
                 3  20      0.000830833417719822;
                 1  21       -0.0111834035238652;
                 2  21      -0.00587272191747575;
                 3  21      -0.00193934175688557;
                 1  22       -0.0113474490102401;
                 2  22      0.000330773274011066;
                 3  22       -0.0026781386166515;
                 1  23      -0.00187663382640301;
                 2  23      -0.00235081943160252;
                 3  23      -0.00835372635714146;
                 1  24      -0.00340733721818079;
                 2  24      -0.00159365366375508;
                 3  24      -0.00927409193668038;
                 1  25     -0.000802000155610957;
                 2  25        0.0050308256946549;
                 3  25        0.0121838871958009;
                 1  26       -9.559624678825e-05;
                 2  26       0.00394267031971987;
                 3  26       0.00977027542088758;
                 1  27      2.96096285690989e-05;
                 2  27      -0.00467676055940434;
                 3  27        -0.013112079013261;
                 1  28     -0.000463632101563298;
                 2  28      0.000816657363892594;
                 3  28      -0.00333397735445219;
                 1  29       -0.0104723458423793;
                 2  29      -0.00241463768917823;
                 3  29       -0.0032118880428807;
                 1  30       0.00272730468778243;
                 2  30       -0.0239635754421163;
                 3  30        0.0131856456497208;
                 1  31      -0.00352988656497627;
                 2  31        0.0215622782926573;
                 3  31       -0.0125736338442791;
                 1  32      -0.00081809445273758;
                 2  32      -0.00171227630071785;
                 3  32      0.000249813514446276;
                 1  33     -0.000313547933177688;
                 2  33      -0.00127095682460106;
                 3  33       -0.0015855958028451;
                 1  34       0.00815476705614575;
                 2  34      -0.00221669292415526;
                 3  34      -0.00684639293350886;
                 1  35       0.00651722080031051;
                 2  35       0.00897421712462987;
                 3  35        0.0152032497858188;
                 1  36      1.85821264294483e-05;
                 2  36      4.96123855503845e-05;
                 3  36     -6.51769094081639e-05;
                 1  37     -0.000102828985135515;
                 2  37     -0.000575085428436506;
                 3  37     -1.22026701668119e-05;
                 1  38     -8.21972596623513e-05;
                 2  38     -0.000689381403868715;
                 3  38      3.14771289192645e-05;
                 1  39     -1.56037119250517e-05;
                 2  39     -7.34090239684468e-05;
                 3  39      3.93503242680413e-05;
                 1  40      0.000112563126289207;
                 2  40      0.000877230625320389;
                 3  40      8.89843251646041e-05;
                 1  41      0.000129413661473586;
                 2  41       0.00112997976973041;
                 3  41     -0.000317588734844295;
                 1  42     -3.99254913056809e-06;
                 2  42     -6.15107047594157e-05;
                 3  42      2.52474435339501e-06;
                 1  43      5.50696431802495e-06;
                 2  43      7.29763578153911e-05;
                 3  43      2.33691464328503e-06;
                 1  44      -0.00630528023694427;
                 2  44      -0.00523489989684617;
                 3  44       -0.0116673554929984;
                 1  45     -0.000260805176328999;
                 2  45     -0.000249215704160071;
                 3  45     -0.000737544661698531 ]

    C2 = sparse( C2parts[:, 1], C2parts[:, 2], C2parts[:, 3], 5, 55 )

    # Feedforward term for the disturbance to the regulated output
    D11 = spzeros( 5, 3 )

    # Feedforward term for the control inputs to the regulated output
    D12 = spzeros( 5, 2 )

    # Feedforward term for the disturbance to the measurments
    D21 = spzeros( 2, 3 )

    # Feedforward term for the control inputs to the measurments
    D22 = spzeros( 2, 2 )

    return (; :sys => HeteroStateSpace( A, B2, C1, D22, Continuous() ) )
end
