예제 #1
0
        /// <summary>
        /// Performs iteration
        /// </summary>
        /// <returns>Residue</returns>
        public double Iterate()
        {
            PrepareIteration();
            double           sigma = 0;
            List <IIterator> iterators;

            if (ownIterators.Count != 0)
            {
                iterators = ownIterators;
            }
            else
            {
                iterators = this.iterators;
            }
            if (iterators.Count == 0)
            {
                return(1);
            }
            foreach (IIterator it in iterators)
            {
                it.Reset();
            }
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    a[i, j] = d[i, j];
                }
            }
            for (int i = 0; i < z.Length; i++)
            {
                z[i] = 0;
            }
            while (true)
            {
                consumer.Reset();
                try
                {
                    consumer.UpdateChildrenData();
                }
                catch (Exception ex)
                {
                    ex.ShowError(10);
                    goto cycle;
                }
                for (int i = 0; i < y.Length; i++)
                {
                    object o = left[i].Parameter();
                    if (o == null)
                    {
                        goto cycle;
                    }
                    y[i] = (double)o;
                    o    = right[i].Parameter();
                    if (o == null | o is DBNull)
                    {
                        goto cycle;
                    }
                    double res = (double)o - y[i];
                    yr[i]  = res;
                    sigma += res * res;
                }
                for (int i = 0; i < aliases.Length; i++)
                {
                    IAliasName a     = aliases[i];
                    double     delta = dx[i];
                    SetDelta(a, delta);
                    consumer.Reset();
                    consumer.UpdateChildrenData();
                    for (int j = 0; j < y.Length; j++)
                    {
                        object obj = left[j].Parameter();
                        if (obj == null)
                        {
                            SetDelta(a, -delta);
                            goto cycle;
                        }
                        ht[i, j] = ((double)obj - y[j]) / delta;
                    }
                    SetDelta(a, -delta);
                }
                for (int i = 0; i < y.Length; i++)
                {
                    for (int j = 0; j <= i; j++)
                    {
                        mr[i, j] = (double)r[i, j].Parameter();
                        mr[j, i] = mr[i, j];
                    }
                }
                RealMatrix.Invert(mr, mr1);
                RealMatrix.Multiply(ht, mr1, htr);
                for (int i = 0; i < a.GetLength(0); i++)
                {
                    for (int k = 0; k < htr.GetLength(1); k++)
                    {
                        z[i] += htr[i, k] * yr[k];
                        for (int j = 0; j < a.GetLength(1); j++)
                        {
                            a[i, j] += htr[i, k] * ht[j, k];
                        }
                    }
                }
cycle:
                foreach (IIterator it in iterators)
                {
                    if (!it.Next())
                    {
                        goto m;
                    }
                }
            }
m:
            RealMatrix.Solve(a, z, indxa);
            for (int i = 0; i < z.Length; i++)
            {
                SetDelta(aliases[i], z[i]);
            }
            return(sigma);
        }
예제 #2
0
        /// <summary>
        /// Performs full iteration
        /// </summary>
        /// <returns>Residue</returns>
        public double FullIterate()
        {
            PrepareIteration();
            for (int i = 0; i < a.GetLength(0); i++)
            {
                for (int j = 0; j < a.GetLength(1); j++)
                {
                    a[i, j] = d[i, j];
                }
            }
            for (int i = 0; i < z.Length; i++)
            {
                z[i] = 0;
            }
            currentSigma = 0;
            List <double[]> c = Calculate();
            double          s = currentSigma;

            List <double[]>[] ll = new List <double[]> [aliases.Length];
            double[,] h = new double[aliases.Length, c.Count];
            for (int i = 0; i < aliases.Length; i++)
            {
                IAliasName alias = aliases[i];
                double     delta = dx[i];
                SetDelta(alias, delta);
                ll[i] = Calculate();
                SetDelta(alias, -delta);
            }
            for (int i = 0; i < y.Length; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    mr[i, j] = (double)r[i, j].Parameter();
                    mr[j, i] = mr[i, j];
                }
            }
            RealMatrix.Invert(mr, mr1);
            for (int im = 0; im < c.Count; im++)
            {
                double[] y0 = c[im];
                for (int i = 0; i < aliases.Length; i++)
                {
                    double[] y = ll[i][im];
                    for (int j = 0; j < y.Length; j++)
                    {
                        ht[i, j] = (y[j] - y0[j]) / dx[i];
                    }
                }
                RealMatrix.Multiply(ht, mr1, htr);
                for (int i = 0; i < a.GetLength(0); i++)
                {
                    for (int k = 0; k < htr.GetLength(1); k++)
                    {
                        z[i] -= htr[i, k] * y0[k];
                        for (int j = 0; j < a.GetLength(1); j++)
                        {
                            a[i, j] += htr[i, k] * ht[j, k];
                        }
                    }
                }
            }
            RealMatrix.Solve(a, z, indxa);
            for (int i = 0; i < z.Length; i++)
            {
                SetDelta(aliases[i], z[i]);
            }
            return(s);
        }