public void MeasurePool()
        {
            Info("Measuring memory pool performance");
            Info("---------------------------------");
            ILArray <int>    Lengths = ILMath.toint32(ILMath.vector(1000000, 1000, 1000000));
            ILArray <int>    PoolSizes = ILMath.toint32(ILMath.vector(00, 10, 250));
            ILArray <double> result = ILMath.zeros(Lengths.Length, PoolSizes.Length);
            ILArray <double> dataA = ILMath.ones(1000, 1000);
            ILArray <double> dataB = ILMath.ones(1000, 1000);
            int counter = 1, countAll = Lengths.Length * PoolSizes.Length;

            for (int p = 0; p < PoolSizes.Length; p++)
            {
                for (int s = 0; s < Lengths.Length; s++)
                {
                    result[s, p] = MeasurePoolParameter((int)Lengths[s], (int)PoolSizes[p], 100, dataA, dataB);
                    Console.Out.Write(String.Format("\r... step {0} of {1} completed", counter++, countAll));
                }
            }
            result.Name = "results";
            ILMatFile mf = new ILMatFile();

            mf["results"]   = result;
            mf["lengths"]   = Lengths;
            mf["poolSizes"] = PoolSizes;
            mf.Write(new FileStream("memoryPoolTestPerf.mat", FileMode.Create));
        }
示例#2
0
        public Bars AddBars(ILArray <double> barStart, ILArray <double> barEnd, ILArray <double> barPosition, ILArray <double> barThickness, BarType barType)
        {
            int n = barStart.Dimensions[0];

            if (barThickness.IsScalar)
            {
                barThickness = ILMath.ones(n) * barThickness;
            }
            Bars bars = new Bars(this, barStart, barEnd, barPosition, barThickness, barType);

            barsList.Add(bars);
            foreach (Path rectangle in bars.Paths)
            {
                canvas.Children.Add(rectangle);
                IBoundableFromChild.Add((object)(rectangle), bars);
            }
            if (graphToCanvas.Matrix.M11 != 0)
            {
                ViewedRegion = GetCanvasChildrenBounds();
            }
            else
            {
                ViewedRegion = bars.Bounds;
            }
            return(bars);
        }
示例#3
0
        public void Test_LDA_Performance2000_var(int rep)
        {
            int errorCode = 0;

            try {
                LDA lda                 = new LDA();
                ILArray <double> X      = ILMath.horzcat(ILMath.randn(2, 2000) * 2.0, ILMath.randn(2, 2000) * -2.0);
                ILLogicalArray   labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1, 2000), ILMath.zeros(1, 2000)));
                labels = labels.Concat(ILMath.tological(ILMath.zeros(1, 2000).Concat(ILMath.ones(1, 2000), 1)), 0);
                ILPerformer    timer = new ILPerformer();
                LDA.Hyperplane C;
                int            oldRefMin = ILNumerics.Settings.ILSettings.MinimumRefDimensions;
                ILNumerics.Settings.ILSettings.MinimumRefDimensions = 2;
                timer.Tic();
                for (int i = 0; i < rep; i++)
                {
                    C = lda.TrainLDA(X, labels, 0.4);
                }
                timer.Toc();
                Info("Test_LDA_Performance: with reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms");
                ILNumerics.Settings.ILSettings.MinimumRefDimensions = 3;
                timer.Tic();
                for (int i = 0; i < rep; i++)
                {
                    C = lda.TrainLDA(X, labels, 0.4);
                }
                timer.Toc();
                ILNumerics.Settings.ILSettings.MinimumRefDimensions = oldRefMin;
                Info("Test_LDA_Performance: without reference - data: 2x2000 run " + rep.ToString() + " times in: " + timer.Duration + "ms");
                Success();
            }catch (Exception e) {
                Error(errorCode, e.Message);
            }
        }
示例#4
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;
            // empty
            ILArray <double> tmp;

            ret[count++] = ILArray <double> .empty(0, 0);

            ret[count++] = ILArray <double> .empty(1, 0);

            ret[count++] = ILArray <double> .empty(0, 1, 0);

            // scalar
            ret[count++] = (ILArray <double>) 1.0;
            ret[count++] = (ILArray <double>) double.NaN;
            ret[count++] = (ILArray <double>) double.PositiveInfinity;
            ret[count++] = (ILArray <double>) double.NegativeInfinity;
            ret[count++] = (ILArray <double>) 0.0;
            ret[count++] = (ILArray <double>)(-30.0);
            // vector
            ret[count++] = ILMath.zeros(1, 10);
            ret[count++] = ILMath.ones(1, 10);
            ret[count++] = ILMath.zeros(10, 1);
            ret[count++] = ILMath.ones(10, 1);
            ret[count++] = ILMath.vector(0.0, 10.0);
            ret[count++] = ILMath.vector(-5.0, 4.0);

            tmp          = ILMath.vector(-5.0, 4.0);
            tmp[0]       = double.NegativeInfinity;
            tmp["end"]   = double.PositiveInfinity;
            tmp[3]       = double.NaN;
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILMath.zeros(3, 2);
            ret[count++] = ILMath.rand(2, 4);
            ret[count++] = ILMath.ones(2, 3) * double.NaN;
            ret[count++] = ILMath.ones(3, 2) / 0.0; // inf
            tmp          = ILMath.ones(3, 2);
            tmp[0]       = double.NaN;
            ret[count++] = tmp;
            tmp[1]       = double.PositiveInfinity;
            ret[count++] = tmp;
            tmp[3]       = double.NegativeInfinity;
            ret[count++] = tmp;
            // 3d array
            ret[count++] = ILMath.zeros(4, 3, 2);
            ret[count++] = ILMath.ones(4, 3, 2);
            ret[count++] = 0.0 / ILMath.zeros(4, 3, 2);
            ret[count++] = ILMath.ones(4, 3, 2) * double.NaN;
            ret[count++] = ILMath.ones(4, 3, 2) * double.NegativeInfinity;
            ret[count++] = ILMath.rand(4, 3, 2);
            // 4d array
            ret[count++] = ILMath.rand(30, 2, 3, 20);

            return(ret);
        }
示例#5
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;
            // empty
            ILArray <ulong> tmp;

            ret[count++] = ILArray <ulong> .empty(0, 0);

            ret[count++] = ILArray <ulong> .empty(1, 0);

            ret[count++] = ILArray <ulong> .empty(0, 1, 0);

            // scalar
            ret[count++] = (ILArray <ulong>)(ulong) 1;
            ret[count++] = (ILArray <ulong>)(ulong) uint.MaxValue;
            ret[count++] = (ILArray <ulong>)(ulong) uint.MinValue;
            ret[count++] = (ILArray <ulong>)(ulong) 0;
            ret[count++] = (ILArray <ulong>)(ulong)(30);
            // vector
            ret[count++] = ILMath.touint64(ILMath.zeros(1, 10));
            ret[count++] = ILMath.touint64(ILMath.ones(1, 10));
            ret[count++] = ILMath.touint64(ILMath.zeros(10, 1));
            ret[count++] = ILMath.touint64(ILMath.ones(10, 1));
            ret[count++] = ILMath.touint64(ILMath.vector(0.0, 10.0));
            ret[count++] = ILMath.touint64(ILMath.vector(0.0, 14.0));

            tmp          = ILMath.touint64(ILMath.vector(0, 14.0));
            tmp[0]       = uint.MinValue;
            tmp["end"]   = uint.MaxValue;
            tmp[3]       = 0;
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILMath.touint64(ILMath.zeros(3, 2));
            ret[count++] = ILMath.touint64(ILMath.rand(2, 4));
            ret[count++] = ILMath.touint64(ILMath.ones(2, 3) * double.NaN);
            ret[count++] = ILMath.touint64(ILMath.ones(3, 2) / 0.0); // inf
            // 3d array
            ret[count++] = ILMath.touint64(ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.touint64(ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.touint64(0.0 / ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.touint64(ILMath.ones(4, 3, 2) * uint.MinValue);
            ret[count++] = ILMath.touint64(ILMath.rand(4, 3, 2) * uint.MaxValue);
            // 4d array
            ret[count++] = ILMath.touint64(ILMath.rand(30, 2, 3, 20) * uint.MaxValue);
            return(ret);
        }
示例#6
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;
            // empty
            ILArray <long> tmp;

            ret[count++] = ILArray <long> .empty(0, 0);

            ret[count++] = ILArray <long> .empty(1, 0);

            ret[count++] = ILArray <long> .empty(0, 1, 0);

            // scalar
            ret[count++] = (ILArray <long>)(long) 1;
            ret[count++] = (ILArray <long>)(long) int.MaxValue;
            ret[count++] = (ILArray <long>)(long) int.MinValue;
            ret[count++] = (ILArray <long>)(long) 0;
            ret[count++] = (ILArray <long>)(long)(-30);
            // vector
            ret[count++] = ILMath.toint64(ILMath.zeros(1, 10));
            ret[count++] = ILMath.toint64(ILMath.ones(1, 10));
            ret[count++] = ILMath.toint64(ILMath.zeros(10, 1));
            ret[count++] = ILMath.toint64(ILMath.ones(10, 1));
            ret[count++] = ILMath.toint64(ILMath.vector(0.0, 10.0));
            ret[count++] = ILMath.toint64(ILMath.vector(-5.0, 4.0));

            tmp          = ILMath.toint64(ILMath.vector(-5.0, 4.0));
            tmp[0]       = int.MinValue;
            tmp["end"]   = int.MaxValue;
            tmp[3]       = 0;
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILMath.toint64(ILMath.zeros(3, 2));
            ret[count++] = ILMath.toint64(ILMath.rand(2, 4));
            ret[count++] = ILMath.toint64(ILMath.ones(2, 3));
            ret[count++] = ILMath.toint64(ILMath.ones(3, 2));
            // 3d array
            ret[count++] = ILMath.toint64(ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.toint64(ILMath.toint32(0.0 / (ILMath.randn(4, 3, 2))));
            ret[count++] = ILMath.toint64(ILMath.ones(4, 3, 2) * int.MinValue);
            ret[count++] = ILMath.toint64(ILMath.rand(4, 3, 2) * int.MaxValue);
            // 4d array
            ret[count++] = ILMath.toint64(ILMath.rand(30, 2, 3, 20) * int.MaxValue);
            return(ret);
        }
示例#7
0
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;
            // empty
            ILArray <short> tmp;

            ret[count++] = ILArray <short> .empty(0, 0);

            ret[count++] = ILArray <short> .empty(1, 0);

            ret[count++] = ILArray <short> .empty(0, 1, 0);

            // scalar
            ret[count++] = (ILArray <short>)(short) 1;
            ret[count++] = (ILArray <short>) short.MaxValue;
            ret[count++] = (ILArray <short>) short.MinValue;
            ret[count++] = (ILArray <short>)(short) 0;
            ret[count++] = (ILArray <short>)(short)(-30);
            // vector
            ret[count++] = ILMath.toint16(ILMath.zeros(1, 10));
            ret[count++] = ILMath.toint16(ILMath.ones(1, 10));
            ret[count++] = ILMath.toint16(ILMath.zeros(10, 1));
            ret[count++] = ILMath.toint16(ILMath.ones(10, 1));
            ret[count++] = ILMath.toint16(ILMath.vector(0.0, 10.0));
            ret[count++] = ILMath.toint16(ILMath.vector(-5.0, 4.0));

            tmp          = ILMath.toint16(ILMath.vector(-5.0, 4.0));
            tmp[0]       = short.MinValue;
            tmp["end"]   = short.MaxValue;
            tmp[3]       = 0;
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILMath.toint16(ILMath.zeros(3, 2));
            ret[count++] = ILMath.toint16(ILMath.rand(2, 4));
            ret[count++] = ILMath.toint16(ILMath.ones(2, 3) * double.NaN);
            ret[count++] = ILMath.toint16(ILMath.ones(3, 2) / 0.0); // inf
            // 3d array
            ret[count++] = ILMath.toint16(ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.toint16(ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.toint16(0.0 / ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.toint16(ILMath.ones(4, 3, 2) * short.MinValue);
            ret[count++] = ILMath.toint16(ILMath.rand(4, 3, 2) * short.MaxValue - (short.MaxValue / 2.0));
            // 4d array
            ret[count++] = ILMath.toint16(ILMath.rand(30, 2, 3, 20) * short.MaxValue - (short.MaxValue / 2.0));
            return(ret);
        }
示例#8
0
        public void Test_LDA_Performance200k_10()
        {
            int errorCode = 0;

            try {
                LDA lda                 = new LDA();
                ILArray <double> X      = ILMath.horzcat(ILMath.randn(2, 200000) * 2.0, ILMath.randn(2, 200000) * -2.0);
                ILLogicalArray   labels = ILMath.tological(ILMath.horzcat(ILMath.ones(1, 100000), ILMath.zeros(1, 100000)));
                labels = labels.Concat(ILMath.tological(ILMath.zeros(1, 100000).Concat(ILMath.ones(1, 100000), 1)), 0);
                ILPerformer timer = new ILPerformer();
                timer.Tic();  LDA.Hyperplane C;
                for (int i = 0; i < 10; i++)
                {
                    C = lda.TrainLDA(X, labels, 0.4);
                }
                timer.Toc();
                Info("Test_LDA_Performance2: data: 2x200000 run 10 times in: " + timer.Duration + "ms");
                Success();
            }catch (Exception e) {
                Error(errorCode, e.Message);
            }
        }
示例#9
0
 protected static ILArray <double> ones(int size1, int size2)
 {
     return(ILMath.ones(size1, size2));
 }
        public override ILCell GenerateTestArrays()
        {
            ILCell ret   = new ILCell();
            int    count = 0;

            complex[] elements = new complex[] {
                new complex(0.0, 0.0),
                new complex(1.0, 0.0),
                new complex(1.0, 1.0),
                new complex(0.0, 1.0),
                new complex(-1.0, 0.0),
                new complex(-1.0, -1.0),
                new complex(0.0, -1.0),
                new complex(double.NaN, 0.0),
                new complex(double.NaN, 1.0),
                new complex(0.0, double.NaN),
                new complex(1.0, double.NaN),
                new complex(double.NaN, double.NaN),        // 11
                new complex(double.PositiveInfinity, 0.0),
                new complex(double.PositiveInfinity, 1.0),
                new complex(0.0, double.PositiveInfinity),
                new complex(1.0, double.PositiveInfinity),
                new complex(double.PositiveInfinity, double.PositiveInfinity),
                new complex(double.NegativeInfinity, 0.0),
                new complex(double.NegativeInfinity, 1.0),
                new complex(0.0, double.NegativeInfinity),
                new complex(1.0, double.NegativeInfinity),
                new complex(double.NegativeInfinity, double.NegativeInfinity),
                // mixed
                new complex(double.NaN, double.NegativeInfinity),
                new complex(double.NaN, double.PositiveInfinity),
                new complex(double.PositiveInfinity, double.NegativeInfinity),
                new complex(double.NegativeInfinity, double.PositiveInfinity),
                new complex(double.NaN, double.PositiveInfinity),
                new complex(double.NegativeInfinity, double.NaN),
                new complex(double.PositiveInfinity, double.NaN),
                new complex(double.MaxValue, double.NaN),
                new complex(double.MinValue, double.NaN),
                new complex(double.MaxValue, double.MinValue),
                new complex(double.NaN, double.MaxValue),
                new complex(double.NaN, double.MinValue),
                new complex(double.MaxValue, double.MinValue)
            };

            // empty
            ILArray <complex> tmp;

            ret[count++] = ILArray <complex> .empty(0, 0);

            ret[count++] = ILArray <complex> .empty(1, 0);

            ret[count++] = ILArray <complex> .empty(0, 1, 0);

            // scalar
            foreach (complex elem in elements)
            {
                ret[count++] = (ILArray <complex>)elem;
            }
            // vector
            ret[count++] = ILArray <complex> .zeros(1, 10);

            ret[count++] = ILArray <complex> .zeros(1, 10) + elements[2];

            ret[count++] = ILArray <complex> .zeros(10, 1);

            ret[count++] = ILArray <complex> .zeros(10, 1) + elements[2];

            ret[count++] = ILMath.ccomplex(ILMath.vector(0.0, 10.0), ILMath.vector(0.0, 10.0));
            ret[count++] = ILMath.ccomplex(ILMath.vector(-5.0, 4.0), -ILMath.vector(-5.0, 4.0));

            tmp          = ILMath.ccomplex(ILMath.vector(-5.0, 4.0), -ILMath.vector(-5.0, 4.0));
            tmp[0]       = elements[22];
            tmp["end"]   = elements[25];
            tmp[3]       = elements[26];
            ret[count++] = tmp;
            // matrix
            ret[count++] = ILArray <complex> .zeros(3, 2);

            ret[count++] = ILMath.ccomplex(ILMath.rand(3, 4), ILMath.rand(3, 4));
            ret[count++] = ILMath.ccomplex(ILMath.ones(2, 3) * double.NaN, ILMath.ones(2, 3) * double.NaN);
            ret[count++] = ILMath.ccomplex(ILMath.ones(3, 2) / 0.0, ILMath.ones(3, 2) / 0.0); // inf
            tmp          = ILArray <complex> .zeros(3, 2) + elements[2];

            tmp[0]       = elements[11]; // nans
            ret[count++] = tmp;
            tmp[1]       = elements[15];
            ret[count++] = tmp;
            tmp[3]       = elements[20]; // neg inf
            ret[count++] = tmp;
            // 3d array
            ret[count++] = ILMath.ccomplex(ILMath.zeros(4, 3, 2), ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2), ILMath.ones(4, 3, 2));
            ret[count++] = ILMath.ccomplex(0.0 / ILMath.zeros(4, 3, 2), 0.0 / ILMath.zeros(4, 3, 2));
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NaN, ILMath.ones(4, 3, 2) * float.NaN);
            ret[count++] = ILMath.ccomplex(ILMath.ones(4, 3, 2) * float.NegativeInfinity, ILMath.ones(4, 3, 2) * float.NegativeInfinity);
            ret[count++] = ILMath.ccomplex(ILMath.rand(4, 3, 2), ILMath.rand(4, 3, 2));
            // 4d array
            ret[count++] = ILMath.ccomplex(ILMath.rand(15, 12, 3, 10), ILMath.rand(15, 12, 3, 10));

            return(ret);
        }
示例#11
0
        //% The main file for running the wind farm controll and wake simulation.
        // It is not completely done yet. Further updates will come
        // Currently there are only 4 turbines, for test purposes. But is should be
        // easily updated to a larger number of turbines.
        // Similarly there is a lot of room for speed optimizations, even though it
        // now runs slowly with only 4 turbines
        // 19/07-13 MS

        public static double[][] Simulation(WakeFarmControlConfig config)
        {
            var parm = new WindTurbineParameters();

            ILMatFile env;
            ILMatFile wt;

            ILArray <int>    idx;
            ILArray <double> ee;

            double           Ki;
            double           Kp;
            int              PC_MaxPit;
            int              PC_MinPit;
            double           VS_CtInSp;
            double           VS_RtGnSp;
            double           VS_Rgn2K;
            double           omega0;
            double           beta0;
            double           power0;
            ILArray <double> x;
            ILArray <double> u0;
            ILArray <double> u;
            ILArray <double> Mg_old;
            ILArray <double> P_ref;
            ILArray <double> Pa;
            ILArray <double> Power;
            ILArray <double> Ct;
            ILArray <double> P_ref_new;
            ILArray <double> v_nac;
            double           alpha;
            double           Mg_max_rate;
            ILArray <double> e;
            ILArray <double> Mg;
            ILArray <double> beta;
            ILArray <double> Cp;
            ILArray <double> Omega;
            ILArray <double> out_;

            if (config.NTurbines == 0)
            {
                return(null);
            }

            // Wind farm properties
            //turbine properties
            env             = wt = new ILMatFile(config.NREL5MW_MatFile);                                             //Load parameters from the NREL 5MW turbine
            parm.N          = config.NTurbines;                                                                       // number of turbines in farm
            parm.rho        = (double)env.GetArray <double>("env_rho");                                               //air density
            parm.radius     = ((double)(wt.GetArray <double>("wt_rotor_radius"))) * ILMath.ones(1, config.NTurbines); // rotor radius (NREL5MW)
            parm.rated      = 5e6 * ILMath.ones(1, config.NTurbines);                                                 //rated power (NREL5MW)
            parm.ratedSpeed = (double)wt.GetArray <double>("wt_rotor_ratedspeed");                                    //rated rotor speed

            idx = ILMath.empty <int>();
            ILMath.max(wt.GetArray <double>("wt_cp_table")[ILMath.full], idx);                                        //Find index for max Cp;
            parm.Cp = ILMath.ones(1, config.NTurbines) * wt.GetArray <double>("wt_cp_table").GetValue(idx.ToArray()); //Set power coefficent to maximum value in the cp table
            parm.Ct = ILMath.ones(1, config.NTurbines) * wt.GetArray <double>("wt_ct_table").GetValue(idx.ToArray()); //Set power coefficent to maximum value in the ct table

            // NOTE: controller parameters should be imported from the wt....struct in
            //Pitch control

            ee = 0;                                 //blade pitch integrator
            Ki = 0.008068634 * 360 / 2 / ILMath.pi; // integral gain (NREL5MW)
            Kp = 0.01882681 * 360 / 2 / ILMath.pi;  // proportional gain (NREL5MW)

            PC_MaxPit = 90;
            PC_MinPit = 0;

            //region control NREL
            VS_CtInSp = 70.16224;
            VS_RtGnSp = 121.6805;
            VS_Rgn2K  = 2.332287;


            // load initial wind data
            var wind = new ILMatFile(config.Wind_MatFile);

            //% Set initial conditions
            omega0 = 1.267; //Rotation speed
            beta0  = 0;     //Pitch

            var timeLine = (int)config.TimeLine();

            power0 = parm.rated.GetValue(0); //Power production
            x      = (omega0 * ILMath.ones(parm.N, 1)).Concat((wind.GetArray <double>("wind").GetValue(0, 1) * ILMath.ones(parm.N, 1)), 1);
            u0     = (beta0 * ILMath.ones(parm.N, 1)).Concat((power0 * ILMath.ones(parm.N, 1)), 1);
            u      = u0.C;
            Mg_old = u[ILMath.full, 1];
            P_ref  = ILMath.zeros(parm.N, (int)config.TimeLine()); //Initialize matrix to save the power production history for each turbine
            Pa     = P_ref.C;                                      //Initialize available power matrix
            Power  = P_ref.C;
            Ct     = parm.Ct.C;                                    //Initialize Ct - is this correct?
            Ct[timeLine - 1, ILMath.full] = Ct[0, ILMath.full];
            P_ref_new = power0 * ILMath.ones(config.NTurbines, 1);

            v_nac = ILMath.zeros(Ct.Size[1], timeLine);
            Mg    = ILMath.zeros(u.Size[0], timeLine);
            beta  = ILMath.zeros(u.Size[0], timeLine);
            Omega = ILMath.zeros(Ct.Size[1], timeLine);
            Cp    = ILMath.zeros(timeLine, parm.Cp.Size[1]);

            var turbineModel = new TurbineDrivetrainModel();

            //% Simulate wind farm operation
            //var timeLine = (int) config.TimeLine();
            for (var i = 2; i <= timeLine; i++) //At each sample time(DT) from Tstart to Tend
            {
                //Calculate the wake using the current Ct values
                {
                    ILArray <double> out_v_nac;
                    WakeCalculation.Calculate((Ct[i - 1 - 1, ILMath.full]), i, wind, out out_v_nac);
                    v_nac[ILMath.full, i - 1] = out_v_nac;
                }
                x[ILMath.full, 1] = v_nac[ILMath.full, i - 1];


                //Farm control
                //Calculate the power distribution references for each turbine
                if (config.EnablePowerDistribution)
                {
                    ILArray <double> out_Pa;
                    PowerDistributionControl.DistributePower(v_nac[ILMath.full, i - 1], config.Pdemand, Power[ILMath.full, i - 1 - 1], parm, out P_ref_new, out out_Pa);
                    Pa[ILMath.full, i - 1] = out_Pa;
                }

                //Hold  the demand for some seconds
                if (ILMath.mod(i, ILMath.round(config.PRefSampleTime / config.DT)) == 2) //???
                {
                    P_ref[ILMath.full, i - 1] = P_ref_new;
                }
                else
                {
                    if (config.PowerRefInterpolation)
                    {
                        alpha = 0.01;
                        P_ref[ILMath.full, i - 1] = (1 - alpha) * P_ref[ILMath.full, i - 1 - 1] + (alpha) * P_ref_new;
                    }
                    else
                    {
                        P_ref[ILMath.full, i - 1] = P_ref_new;
                    }
                }


                //Calculate control for each individual turbine - should be moved to the
                //turbine (drivetrain) model.

                //Torque controller
                for (var j = 1; j <= parm.N; j++)
                {
                    if ((x.GetValue(j - 1, 0) * 97 >= VS_RtGnSp) || (u.GetValue(j - 1, 0) >= 1))   // We are in region 3 - power is constant
                    {
                        u.SetValue(P_ref.GetValue(j - 1, i - 1) / x.GetValue(j - 1, 0), j - 1, 1);
                    }
                    else if (x.GetValue(j - 1, 0) * 97 <= VS_CtInSp)                            //! We are in region 1 - torque is zero
                    {
                        u.SetValue(0.0, j - 1, 1);
                    }
                    else                                                         //! We are in region 2 - optimal torque is proportional to the square of the generator speed
                    {
                        u.SetValue(97 * VS_Rgn2K * x.GetValue(j - 1, 0) * x.GetValue(j - 1, 0) * Math.Pow(97, 2), j - 1, 1);
                    }
                }

                //Rate limit torque change
                //  u(:,2) - Mg_old;
                Mg_max_rate       = 1e6 * config.DT;
                u[ILMath.full, 1] = ILMath.sign(u[ILMath.full, 1] - Mg_old) * ILMath.min(ILMath.abs(u[ILMath.full, 1] - Mg_old), Mg_max_rate) + Mg_old;

                //Pitch controller
                e  = 97 * (omega0 * ILMath.ones(parm.N, 1) - x[ILMath.full, 0]);
                ee = ee - config.DT * e;
                ee = ILMath.min(ILMath.max(ee, PC_MinPit / Ki), PC_MaxPit / Ki);

                u[ILMath.full, 0] = -Kp * config.DT * e + Ki * ee;
                for (var j = 1; j <= parm.N; j++)
                {
                    u.SetValue(Math.Min(Math.Max(u.GetValue(j - 1, 0), PC_MinPit), PC_MaxPit), j - 1, 0);
                }

                if (!config.EnableTurbineDynamics)
                {
                    u = u0;
                }

                Mg[ILMath.full, i - 1] = u[ILMath.full, 1];
                Mg_old = Mg[ILMath.full, i - 1];
                beta[ILMath.full, i - 1] = u[ILMath.full, 0]; //Set pitch


                //Turbine dynamics - can be simplified
                if (config.EnableTurbineDynamics)
                {
                    for (var j = 1; j <= parm.N; j++)
                    {
                        double out_x;
                        double out_Ct;
                        double out_Cp;
                        turbineModel.Model(x[j - 1, ILMath.full], u[j - 1, ILMath.full], wt, env, config.DT, out out_x, out out_Ct, out out_Cp);
                        x.SetValue(out_x, j - 1, 0);
                        Ct.SetValue(out_Ct, i - 1, j - 1);
                        Cp.SetValue(out_Cp, i - 1, j - 1);
                    }
                }
                else
                {
                    Ct[i - 1, ILMath.full] = parm.Ct;
                    Cp[i - 1, ILMath.full] = parm.Cp;
                    x[ILMath.full, 0]      = parm.ratedSpeed;//Rotational speed
                }

                Omega[ILMath.full, i - 1] = x[ILMath.full, 0];
                Power[ILMath.full, i - 1] = Omega[ILMath.full, i - 1] * Mg[ILMath.full, i - 1];
            }

            //% Save output data
            out_ = (config.DT * (ILMath.counter(0, 1, config.TimeLine())));
            out_ = out_.Concat(v_nac.T, 1);
            out_ = out_.Concat(Omega.T, 1);
            out_ = out_.Concat(beta.T, 1);
            out_ = out_.Concat(P_ref.T, 1);
            out_ = out_.Concat(Ct, 1);
            out_ = out_.Concat(Cp, 1);
            out_ = out_.Concat(Pa.T, 1);
            out_ = out_.Concat(Mg.T, 1);
            out_ = out_.Concat(Power.T, 1);

            //Ttotal power demand
            var l = config.NTurbines * 3 + 1;
            var r = l + config.NTurbines - 1;

            out_ = out_.Concat(ILMath.sum(out_[ILMath.full, ILMath.r(l, r)], 1) / 1e6, 1);    // P_ref sum

            l = config.NTurbines * 6 + 1;
            r = l + config.NTurbines - 1;

            out_ = out_.Concat(ILMath.sum(out_[ILMath.full, ILMath.r(l, r)], 1) / 1e6, 1);    // Pa sum. 'Power Demand'
            out_ = out_.Concat(ILMath.sum(Power).T / 1e6, 1);                                 // 'Actual Production'

            //Ttotal power demand
            out_ = out_.Concat(ILMath.sum(P_ref.T, 1), 1);              // 'Demand'
            out_ = out_.Concat(ILMath.sum(Pa.T, 1), 1);                 // 'Available'
            out_ = out_.Concat(ILMath.sum(Mg * Omega).T, 1);            // 'Actual'

            //Total power produced
            out_ = out_.Concat((Mg * Omega).T, 1);

            var out_doubleArray = new double[out_.Size[0]][];

            for (int i = 0; i <= out_doubleArray.GetLength(0) - 1; i++)
            {
                out_doubleArray[i] = new double[out_.Size[1]];
                for (int j = 0; j <= out_doubleArray[i].GetLength(0) - 1; j++)
                {
                    out_doubleArray[i][j] = out_.GetValue(i, j);
                }
            }
            return(out_doubleArray);
        }
示例#12
0
        /// <summary>
        /// run all tests for ILMatFile
        /// </summary>
        public override void Run()
        {
            // tests: creation
            // =================
            Header();
            Test_TestMatlab();
            Test_StreamMatlab("testarray1.mat", ILMath.empty());
            Test_StreamMatlab("testarray1.mat", ILMath.ones(1, 1));
            Test_StreamMatlab("testarray1.mat", ILMath.rand(10, 1));
            Test_StreamMatlab("testarray1.mat", ILMath.rand(1, 10));
            Test_StreamMatlab("testarray1.mat", ILMath.rand(0, 1));
            Test_StreamMatlab("testarray1.mat", ILMath.rand(10, 100, 4));

            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.ones(1, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(10, 100, 4)));

            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.ones(1, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(10, 100, 4)));

            Test_StreamMatlab("testarray1.mat", new ILArray <complex>(new complex[] { new complex(1.0, 2.0) }));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(10, 100, 4)));

            Test_StreamMatlab("testarray1.mat", new ILArray <fcomplex>(new fcomplex[] { new fcomplex(1.0f, 2.0f) }));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(10, 100, 4)));

            Test_StreamMatlab("testarray1.mat", new ILArray <char>(new char[] { 'A', 'B', 'F' }));
            Test_StreamMatlab("testarray1.mat", new ILArray <char>(new char[] { 'A', 'B', 'F' }).T);
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(10, 1) * 250));
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(1, 10) * 250));
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(0, 1) * 250));
            Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(10, 100, 4) * 250));

            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.ones(1, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(1, 10) * 255));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(0, 1) * 255));
            Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(10, 100, 4) * 255));

            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.ones(1, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.empty()) * 16000);
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(10, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(1, 10) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(0, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(10, 100, 4) * 16000));

            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.ones(1, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.empty() * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(10, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(1, 10) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(0, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(10, 100, 4) * 16000));

            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.ones(1, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.empty() * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(10, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(1, 10) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(0, 1) * 16000));
            Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(10, 100, 4) * 16000));

            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.ones(1, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.empty()));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(10, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(1, 10)));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(0, 1)));
            Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(10, 100, 4)));
            Test_ImportMatlab2();
            Test_ImportMatlab();
            Test_NameRestrictions();
            // summary
            Footer();
        }
示例#13
0
        public void Test_Addressing()
        {
            int errorCode = 0;

            try {
                ILBaseArray[] data = new ILBaseArray[60];
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = new ILArray <Int16>(new Int16[1] {
                        (Int16)i
                    });
                }
                ILCell A = new ILCell(data, 20, 3);
                A.Name    = "A";
                errorCode = 1;
                A[1, 1]   = ILMath.vector(10, 100);
                A[2, 1]   = ILMath.vector(-10, -1, -100);
                errorCode = 2;
                // test subarray access: single
                ILBaseArray ret = A[23];
                ret.Name  = "ret";
                errorCode = 3;
                // single element returned should be inner ILBaseArray
                if (!(ret is ILArray <Int16>))
                {
                    throw new Exception("ILCell: single element returned should be of ILArray<double> type");
                }
                ILArray <Int16> a23 = (ILArray <Int16>)ret;
                a23.Name = "a23";
                if (!a23.IsScalar || a23 != 23.0)
                {
                    throw new Exception("ILCell: returned element value mismatch! Expected: 23, found:" + a23.GetValue(0));
                }
                errorCode = 4;
                // test subarray access: multiple via vector (sequential)
                // - put Cell into cell
                ILArray <double> element1 = ILMath.vector(10, 2, 20);
                element1.Name = "element1";
                ILArray <double> element2 = ILMath.vector(20, 2, 30);
                element2.Name = "element2";
                ILCell innerCell = new ILCell(new ILBaseArray[] { element1, element2 }, 2, 1);
                A[3, 1] = innerCell;
                ILArray <double> ind = new ILArray <double>(new double[] { 20.0, 21.0, 22.0, 23.0, 24.0 });
                ind.Name = "ind";
                ILCell cellresult_vect = (ILCell)A[ind];
                cellresult_vect.Name = "cellresult_vect";
                if (!cellresult_vect.IsRowVector || cellresult_vect.Dimensions[0] != 1 ||
                    cellresult_vect.Dimensions[1] != 5)
                {
                    throw new Exception("ILCell: index access dimension mismatch: should be ILCell 1x5! ");
                }
                if (!(cellresult_vect[0, 0] is ILArray <short>) || !(cellresult_vect[0, 1] is ILArray <double>) ||
                    !(cellresult_vect[0, 2] is ILArray <double>) || !(cellresult_vect[0, 3] is ILCell) ||
                    !(cellresult_vect[0, 4] is ILArray <short>))
                {
                    throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices.");
                }
                errorCode = 5;
                // test if elements returned are properly referenced (detached from original)
                ILArray <short> tmps = (ILArray <short>)cellresult_vect[0, 0];
                tmps.Name = "tmps";
                if (!tmps.IsScalar || (tmps != 20.0))
                {
                    throw new Exception("ILCell: invalid value returned: expected:20, found:" + tmps.GetValue(0));
                }
                ILArray <double> tmp = (ILArray <double>)cellresult_vect[1];
                tmp.Name = "tmp";
                if (!tmp.IsVector || (bool)(tmp.Length != 91) || (bool)(tmp[0] != 10) || (bool)(tmp["end"] != 100))
                {
                    throw new Exception("ILCell: invalid value returned: expected double vector 10:2:20");
                }
                tmp = (ILArray <double>)cellresult_vect[2];
                if (!tmp.IsVector || (bool)(tmp.Length != 91) || (bool)(tmp[0] != -10) || (bool)(tmp["end"] != -100))
                {
                    throw new Exception("ILCell: invalid value returned: expected vector 20:2:30");
                }
                tmps = (ILArray <short>)cellresult_vect[4];
                if (!tmps.IsScalar || (bool)(tmps["end"] != 24.0))
                {
                    throw new Exception("ILCell: invalid value returned: expected short 24, found: " + tmps.GetValue(0));
                }
                cellresult_vect[0, 3, 1, 0, 1] = -111.0;
                if ((ILArray <double>)cellresult_vect[0, 3, 1, 0, 1] != -111.0)
                {
                    throw new Exception("ILCell: invalid result of inner element index access: expected: -111.0, found: " + ((ILArray <double>)cellresult_vect[0, 3, 1, 0, 1]).GetValue(0));
                }
                errorCode = 6;
                // test if original still intact
                if (!A[3, 1, 1, 0, 1].IsScalar || (ILArray <double>)A[3, 1, 1, 0, 1] != 22.0)
                {
                    throw new Exception("ILCell: original should not be altered if reference was altered! A[3,1,1,0,1] = " + ((ILArray <double>)A[3, 1, 1, 0, 1]).GetValue(0));
                }
                // test subarray access: matrix (sequential)   **********************************************
                errorCode = 7;
                ind       = new ILArray <double>(new double[6] {
                    20.0, 21.0, 22.0, 23.0, 24.0, 25.0
                }, 3, 2);
                ind.Name             = "ind";
                cellresult_vect      = (ILCell)A[ind];
                cellresult_vect.Name = "cellresult_vect";
                if (!cellresult_vect.IsMatrix || cellresult_vect.Dimensions[0] != 3 ||
                    cellresult_vect.Dimensions[1] != 2)
                {
                    throw new Exception("ILCell: index access dimension mismatch: should be ILCell 3x2! ");
                }
                if (!(cellresult_vect[0, 0] is ILArray <short>) || !(cellresult_vect[1, 0] is ILArray <double>) ||
                    !(cellresult_vect[2, 0] is ILArray <double>) || !(cellresult_vect[0, 1] is ILCell) ||
                    !(cellresult_vect[1, 1] is ILArray <short>) || !(cellresult_vect[2, 1] is ILArray <short>))
                {
                    throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices.");
                }
                if (!(cellresult_vect[0] is ILArray <short>) || !(cellresult_vect[1] is ILArray <double>) ||
                    !(cellresult_vect[2] is ILArray <double>) || !(cellresult_vect[3] is ILCell) ||
                    !(cellresult_vect[4] is ILArray <short>) || !(cellresult_vect[5] is ILArray <short>))
                {
                    throw new Exception("ILCell: index access failed. Inner element mismatch for vector indices.");
                }
                errorCode = 8;
                // test if elements returned are properly referenced (detached from original)
                tmps      = (ILArray <short>)cellresult_vect[0, 0];
                tmps.Name = "tmps";
                if (!tmps.IsScalar || (byte)tmps != 20.0)
                {
                    throw new Exception("ILCell: invalid value returned: expected:20, found:" + tmps.GetValue(0));
                }
                tmp      = (ILArray <double>)cellresult_vect[1];
                tmp.Name = "tmp";
                if (!tmp.IsVector || tmp.Length != 91 || tmp[0] != 10.0 || tmp["end"] != 100.0)
                {
                    throw new Exception("ILCell: invalid value returned: expected double vector 10:2:20");
                }
                tmp = (ILArray <double>)cellresult_vect[2];
                if (!tmp.IsVector || tmp.Length != 91 || tmp[0] != -10.0 || tmp["end"] != -100.0)
                {
                    throw new Exception("ILCell: invalid value returned: expected vector 20:2:30");
                }
                tmps = (ILArray <short>)cellresult_vect[4];
                if (!tmps.IsScalar || (byte)tmps["end"] != 24.0)
                {
                    throw new Exception("ILCell: invalid value returned: expected short 24, found: " + tmps.GetValue(0));
                }
                cellresult_vect[0, 1, 1, 0, 1] = -111.0;
                if ((double)(ILArray <double>)cellresult_vect[0, 1, 1, 0, 1] != -111.0)
                {
                    throw new Exception("ILCell: invalid result of inner element index access: expected: -111.0, found: " + ((ILArray <double>)cellresult_vect[0, 3, 1, 0, 1]).GetValue(0));
                }
                errorCode = 9;
                // test if original still untouched
                if ((ILArray <double>)A[3, 1, 1, 0, 1] != 22.0)
                {
                    throw new Exception("ILCell: original should not be altered if reference was altered! A[3,1,1,0,1] = " + ((ILArray <double>)A[3, 1, 1, 0, 1]).GetValue(0));
                }
                // test sequential index array set acces
                innerCell    = new ILCell(4, 3, 2);
                innerCell[0] = ILMath.vector(20, -3, -100);
                innerCell[1] = ((ILArray <double>)innerCell[0] < 0.0);
                ILCell rangedsource = new ILCell(new ILBaseArray [] {
                    new ILArray <int>(3333),
                    new ILLogicalArray(1),
                    ILMath.vector(1000, 2000),
                    innerCell
                }, 2, 2);
                ILArray <double> range = new ILArray <double>(new double[] { 0, 51, 52, 59 });
                A[range] = rangedsource;
                if (!(A[0] is ILArray <int>))
                {
                    throw new Exception("ILCell: seq.ranged set mismatch. index 0");
                }
                if (!(A[51] is ILLogicalArray))
                {
                    throw new Exception("ILCell: seq.ranged set mismatch. index 1");
                }
                if (!(A[52] is ILArray <double>))
                {
                    throw new Exception("ILCell: seq.ranged set mismatch. index 2");
                }
                if (!(A[59] is ILCell))
                {
                    throw new Exception("ILCell: seq.ranged set mismatch. index 3");
                }
                errorCode = 10;
                // test detached referencing (alter elements of query result)
                // test index access for ranges via ILBaseArray[]
                data = new ILBaseArray[60];
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = new ILArray <Int16>(new Int16[] { (Int16)i });
                }
                A      = new ILCell(data, 20, 3);
                A.Name = "A";
                ILArray <double> r        = ILMath.vector(0, 2);
                ILArray <short>  c        = (ILArray <short>)ILMath.ones(NumericType.Int16, 1);
                ILCell           rangeGet = (ILCell)A[r, c];
                if (rangeGet.Dimensions[0] != 3 || rangeGet.Dimensions[1] != 1)
                {
                    throw new Exception("ILCell: ranged index get access via ILBaseArray failed. Wrong dimension returned.");
                }
                if ((ILArray <short>)rangeGet[0, 0] != 20.0)
                {
                    throw new Exception("ILCell: invalid index returned: exp.20, found:" + ((ILArray <int>)rangeGet[0, 0]).GetValue(0));
                }
                A[0, 1] = new ILArray <double>(17, 18, 1000);
                if ((ILArray <short>)rangeGet[0, 0] != 20.0)
                {
                    throw new Exception("ILCell: invalid index returned: exp.20, found:" + ((ILArray <double>)rangeGet[0, 0]).GetValue(0) + ". The reference returned was not detached properly!");
                }
                errorCode = 11;
                // test ranged setter
                A[c, r] = A[c + 10, r];
                if ((ILArray <short>)A[1, 1] != 31.0)
                {
                    throw new Exception("Wrong value found after copying part of cell to other position.");
                }
                A[1, 1] = -1122.0;
                if ((ILArray <short>)A[11, 1] != 31.0 || (ILArray <double>)A[1, 1] != -1122.0)
                {
                    throw new Exception("wrong value stored or reference not properly un-linked in ILCell.");
                }
                // test removal of elements
                errorCode = 12;
                A[new ILArray <double>(new double[] { 4.0, 5.0, 11.0 }), null] = null;
                if (A.Dimensions[0] != 17 || A.Dimensions[1] != 3)
                {
                    throw new Exception("ILCell removal via ILBaseArray[] failed.");
                }
                A[new ILArray <double>(new double[] { 4.0, 5.0, 11.0 })] = null;
                if (A.Dimensions[0] != 1 || A.Dimensions[1] != 48)
                {
                    throw new Exception("ILCell removal via sequential indexes failed!");
                }
                errorCode = 13;
                // test if error on removal will restore old dimensions
                A   = new ILCell(2, 3, 2);
                ind = new double[] { 15, 16, 22, 223 };
                try {
                    A[ind] = null;
                    throw new Exception("ILCell remove: index out of range not signaled!");
                } catch (Exception) {}
                if (A.Dimensions[0] != 2 || A.Dimensions[1] != 3 || A.Dimensions[2] != 2)
                {
                    throw  new Exception("ILCell: error on remove should restore old dimensions!");
                }

                Success();
            } catch (Exception e) {
                Error(errorCode, e.Message);
            }
        }