Beispiel #1
0
        static double[][] TimeProblem(ProblemInfo info, IMatrix A, double[] b)
        {
            ISolver      solver = new LOSLU();
            LSlaeBuilder tsb    = new LSlaeBuilder(info);

            double[]   t = info.TimeMesh;
            double[][] Q = new double[info.TimeMesh.Length][];
            Q[0] = new double[A.N];
            for (int i = 0; i < A.N; i++)
            {
                Q[0][i] = 25.0;
            }

            tsb.Layer = new TwoLayer();
            tsb.Layer.SetQ(new double[1][] { Q[0] });
            tsb.Layer.SetT(new double[] { t[0], t[1] });
            tsb.CurrentT = info.TimeMesh[1];
            tsb.Build(A, b);
            Q[1] = solver.Solve(A, b);
            ClearMatrix(A, b);

            tsb.Layer = new ThreeLayer();
            tsb.Layer.SetQ(new double[2][] { Q[0], Q[1] });
            tsb.Layer.SetT(new double[3] {
                t[0], t[1], t[2]
            });
            tsb.CurrentT = t[2];
            tsb.Build(A, b);
            Q[2] = solver.Solve(A, b);
            ClearMatrix(A, b);

            tsb.Layer = new FourLayer();
            tsb.Layer.SetQ(new double[3][] { Q[0], Q[1], Q[2] });
            tsb.Layer.SetT(new double[4] {
                t[0], t[1], t[2], t[3]
            });
            tsb.CurrentT = t[3];
            tsb.Build(A, b);
            Q[3] = solver.Solve(A, b);
            ClearMatrix(A, b);

            for (int i = 4; i < info.TimeMesh.Length; i++)
            {
                tsb.Layer.SetQ(new double[3][] { Q[i - 3], Q[i - 2], Q[i - 1] });
                tsb.Layer.SetT(new double[4] {
                    t[i - 3], t[i - 2], t[i - 1], t[i]
                });
                tsb.CurrentT = t[i];
                tsb.Build(A, b);
                Q[i] = solver.Solve(A, b);
                Console.WriteLine($"Невязка = {solver.Difference:E4}");
                ClearMatrix(A, b);
            }

            return(Q);
        }
Beispiel #2
0
        static void Problem(ProblemInfo info, IMatrix A, double[] b)
        {
            LSlaeBuilder builder = new LSlaeBuilder(info);

            builder.Build(A, b);

            ISolver solver = new LOSLU();

            double[] q = solver.Solve(A, b);
        }
Beispiel #3
0
        public FEMrzDelta(FEMProblemInfoDelta info)
        {
            Info = info;
            switch (Info.SolverType)
            {
            case SolverTypes.LOSLU:
                Solver = new LOSLU();
                break;

            default:
                Solver = new LOSLU();
                break;
            }
        }
        public NonlinearProblem(NonlinearProblemInfo info)
        {
            LinearMesh = info.LinearMesh;
            Mesh       = info.NonlinearMesh;

            MaxIters       = info.MaxIters;
            Eps            = info.Eps;
            Delta          = info.Delta;
            DoOptimization = info.DoOptimization;

            PB  = new PortraitBuilder(Mesh);
            LSB = new NewtonSLAEBuilder(Mesh);
            NSB = new NonlinearSLAEBuilder(Mesh);

            relaxQ = new double[Mesh.NodeCount];
            Aq     = new double[Mesh.NodeCount];

            switch (info.SolverType)
            {
            case SolverTypes.LOSLLT:
            {
                Solver = new LOSLLT();
                break;
            }

            case SolverTypes.LOSLU:
            {
                Solver = new LOSLU();
                break;
            }

            case SolverTypes.CGMLLT:
            {
                Solver = new CGMLLT();
                break;
            }

            default:
            {
                Solver = new LOSLU();
                break;
            }
            }
        }
Beispiel #5
0
        public FEMrz(FEMProblemInfo info)
        {
            Info = info;

            switch (Info.SolverType)
            {
            case SolverTypes.LOSLU:
                Solver = new LOSLU();
                break;

            case SolverTypes.LOSLUParallel:
                Solver = new LOSLUParallel();
                break;

            default:
                Solver = new LOSLU();
                break;
            }
        }
        static void Main(string[] args)
        {
            System.Globalization.CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture.Clone() as System.Globalization.CultureInfo ?? throw new InvalidCastException();
            culture.NumberFormat = System.Globalization.CultureInfo.InvariantCulture.NumberFormat;
            System.Threading.Thread.CurrentThread.CurrentCulture           = culture;
            System.Globalization.CultureInfo.DefaultThreadCurrentCulture   = culture;
            System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = culture;

            const int xCellCount = 9;
            const int zCellCount = 6;
            const int k          = xCellCount * zCellCount;
            const int n          = 800;

            double[] x     = new double[xCellCount + 1];
            double[] z     = new double[zCellCount + 1];
            double[] p     = new double[k];
            double[] gamma = new double[k];
            double   alpha = 1.0e-5;

            double xbegin = 0.0;
            double xstep  = 500.0;

            for (int i = 0; i < xCellCount + 1; i++)
            {
                x[i] = xbegin + xstep * i;
            }

            double zbegin = -1500.0;
            double zstep  = 250.0;

            for (int i = 0; i < zCellCount + 1; i++)
            {
                z[i] = zbegin + zstep * i;
            }

            p[23] = 1.0;
            p[24] = 1.0;
            p[32] = 1.0;
            p[33] = 1.0;

            Point[] receivers = new Point[n];

            double beginX = -2000;
            double endX   = 6000;
            double stepX  = (endX - beginX) / (n - 1);

            for (int i = 0; i < n; i++)
            {
                receivers[i] = new Point(beginX + i * stepX, 0.0);
            }

            double[]          realG = new double[n];
            GravityCalculator calc  = new GravityCalculator(x, z, p);

            for (int i = 0; i < n; i++)
            {
                realG[i] = calc.CalculateFromAll(receivers[i]);
            }

            for (int i = 0; i < k; i++)
            {
                p[i] = 0.1;
            }

            // for (int i = 0; i < n; i++)
            //     Console.WriteLine($"{receivers[i].X}; {realG[i]}");

            ProblemInfo info = new ProblemInfo();

            info.P         = p;
            info.X         = x;
            info.Z         = z;
            info.Receivers = receivers;
            info.realG     = realG;
            info.Alpha     = alpha;
            info.Gamma     = gamma;

            Functional F = new Functional(info);

            double f = F.Calculate(p);

            SlaeBuilder builder = new SlaeBuilder(info);
            IMatrix     A       = new FullSparseMatrix(k);

            double[] b = new double[k];

            builder.Build(A, b);

            ISolver solver = new LOSLU();

            double[] newP = solver.Solve(A, b);

            f = F.Calculate(newP);
        }