Example #1
0
        List <double> ThomasAlgorithm(ThomasArguments args)
        {
            List <double> xi = new List <double>(args.A.Count)
            {
                Double.NaN, -args.M0 / args.K0
            };
            List <double> eta = new List <double>(args.A.Count)
            {
                Double.NaN, args.P0 / args.K0
            };

            // Straight running
            for (int i = 1; i < args.A.Count; i++)
            {
                double x = args.C[i] / (args.B[i] - args.A[i] * xi[i]);
                double e = (args.D[i] + args.A[i] * eta[i]) / (args.B[i] - args.A[i] * xi[i]);

                xi.Add(x);
                eta.Add(e);
            }

            // Reverse running
            List <double> y = new List <double>(args.A.Count)
            {
                (args.PN - args.MN * eta.Last()) / (args.KN + args.MN * xi.Last())
            };

            for (int i = args.A.Count - 2; i >= -1; i--)
            {
                double yi = xi[i + 1] * y[0] + eta[i + 1];
                y.Insert(0, yi);
            }

            return(y);
        }
Example #2
0
        public void Process(InitialData data, out IList <double> y, out IList <double> x)
        {
            _data = data;

            int countOfValues = (int)Math.Ceiling((data.RodLength - data.X0) / data.Step);

            // A B C D
            List <double> A = new List <double>(countOfValues);
            List <double> B = new List <double>(countOfValues);
            List <double> C = new List <double>(countOfValues);
            List <double> D = new List <double>(countOfValues);

            CalculateCoefficients(A, B, C, D);

            // Left boundary conditions. k0, m0, p0
            double k0, m0, p0;

            LeftBoundaryConditions(out k0, out m0, out p0);

            // Right boundary conditions. kN, mN, pN
            double kN, mN, pN;

            RightBoundaryConditions(out kN, out mN, out pN);

            ThomasArguments args = new ThomasArguments()
            {
                A  = A, B = B, C = C, D = D,
                K0 = k0, M0 = m0, P0 = p0,
                KN = kN, MN = mN, PN = pN
            };

            y = ThomasAlgorithm(args);

            x = new List <double>(y.Count);
            double xi = _data.X0;

            for (int i = 0; i < y.Count; i++)
            {
                x.Add(xi);
                xi += _data.Step;
            }

            if (_data.DoDebugPrint)
            {
                PrintValue("A", A);
                PrintValue("B", B);
                PrintValue("C", C);
                PrintValue("D", D);

                PrintValue("K0", k0);
                PrintValue("M0", m0);
                PrintValue("P0", p0);

                PrintValue("KN", kN);
                PrintValue("MN", mN);
                PrintValue("PN", pN);
            }
        }