示例#1
0
        private Matrix GenereteMatrix(List <Element> elem)
        {
            var n      = elem.Count;
            var matrix = new DenseMatrix(n + 1, n + 1);

            matrix[0, 0] = Mu.Evaluate(elem[0].MidPoint) / elem[0].H - Beta.Evaluate(elem[0].MidPoint) / 2 + Sigma.Evaluate(elem[0].MidPoint) * elem[0].H / 3 + Alpha;
            matrix[0, 1] = -Mu.Evaluate(elem[0].MidPoint) / elem[0].H + Beta.Evaluate(elem[0].MidPoint) / 2 + Sigma.Evaluate(elem[0].MidPoint) * elem[0].H / 6;
            for (int i = 1; i < n; ++i)
            {
                matrix[i, i - 1] = -Mu.Evaluate(elem[i - 1].MidPoint) / elem[i - 1].H - Beta.Evaluate(elem[i - 1].MidPoint) / 2 + Sigma.Evaluate(elem[i - 1].MidPoint) * elem[i - 1].H / 6;
                matrix[i, i]     = Mu.Evaluate(elem[i - 1].MidPoint) / elem[i - 1].H + Beta.Evaluate(elem[i - 1].MidPoint) / 2 + Sigma.Evaluate(elem[i - 1].MidPoint) * elem[i - 1].H / 3 + Mu.Evaluate(elem[i].MidPoint) / elem[i].H - Beta.Evaluate(elem[i].MidPoint) / 2 + Sigma.Evaluate(elem[i].MidPoint) * elem[i].H / 3;
                matrix[i, i + 1] = -Mu.Evaluate(elem[i].MidPoint) / elem[i].H + Beta.Evaluate(elem[i].MidPoint) / 2 + Sigma.Evaluate(elem[i].MidPoint) * elem[i].H / 6;
            }
            matrix[n, n - 1] = -Mu.Evaluate(elem[n - 1].MidPoint) / elem[n - 1].H - Beta.Evaluate(elem[n - 1].MidPoint) / 2 + Sigma.Evaluate(elem[n - 1].MidPoint) * elem[n - 1].H / 6;
            matrix[n, n]     = Mu.Evaluate(elem[n - 1].MidPoint) / elem[n - 1].H + Beta.Evaluate(elem[n - 1].MidPoint) / 2 + Sigma.Evaluate(elem[n - 1].MidPoint) * elem[n - 1].H / 3 + Gamma;

            return(matrix);
        }
示例#2
0
        private void CalculateErrors(ref Iteration iter)
        {
            var n           = iter.Elements.Count;
            var errors      = new DenseVector(n);
            var errorsNorms = new DenseVector(n);

            var eNormV2 = 0.0;
            var uNormV2 = 0.0;

            for (int i = 0; i < n; ++i)
            {
                var m    = Math.Pow(iter.Elements[i].H, 3) / Mu.Evaluate(iter.Elements[i].MidPoint);
                var b    = F.Evaluate(iter.Elements[i].MidPoint) - (Beta.Evaluate(iter.Elements[i].MidPoint) * iter.SolutionCenterDeriv[i]) - (Sigma.Evaluate(iter.Elements[i].MidPoint) * iter.SolutionCenter[i]);
                var d    = 10 + ((iter.Elements[i].H * Beta.Evaluate(iter.Elements[i].MidPoint)) / Mu.Evaluate(iter.Elements[i].MidPoint) * ((iter.Elements[i].H * iter.Elements[i].H * Sigma.Evaluate(iter.Elements[i].MidPoint)) / Mu.Evaluate(iter.Elements[i].MidPoint)));
                var e_h2 = (5.0 / 6) * m * (b * b / d);
                errorsNorms[i] = Math.Sqrt(Math.Abs(e_h2));
                eNormV2       += Math.Abs(e_h2);

                var q = iter.SolutionCenterDeriv[i];
                uNormV2 += iter.Elements[i].H * q * q;
            }

            iter.UNormV2      = uNormV2;
            iter.ENormV2      = eNormV2;
            iter.ErrorsNormsV = errorsNorms;

            //iter.UNorm = Math.Sqrt(uNormV2);
            iter.UNorm = Math.Sqrt(iter.Solution * GenereteMatrix(iter.Elements) * iter.Solution);
            iter.ENorm = Math.Sqrt(eNormV2);

            for (int i = 0; i < n; ++i)
            {
                errors[i] = (errorsNorms[i] * Math.Sqrt(n) * 100) / Math.Sqrt(uNormV2 + eNormV2);
            }
            iter.Errors = errors;
            if (iter.N == InitialN)
            {
                startEn = iter.ENorm;
            }

            iter.OrderOfConvergence = (iter.N != InitialN) ? (Math.Log(startEn) - Math.Log(iter.ENorm)) / (Math.Log(iter.N) - Math.Log(InitialN)) : 0;
            iter.MaxRelativeError   = iter.Errors.Maximum();
        }