示例#1
0
        public static void SolveDirectProblem()
        {
            double radius       = 2;
            int    pointsNumber = 32;

            //IDirectProblemTestData testData = new PlanarTestData();
            //IDirectProblemTestData testData = new FundamentalSolutionTestData();
            var outerCurve = new StarCurve((t) => radius);
            IDirectProblemTestData testData = new FundamentalSolutionDevidedTastData(outerCurve);
            //IDirectProblemTestData testData = new CoordinatesDeviationDoubleTestData();
            DirectProblemState  state  = new DirectProblemState(radius, pointsNumber, testData);
            DirectProblemSolver solver = new DirectProblemSolver(state);

            Printer.Append = false;
            Printer.Mode   = WriteMode.Console;
            double[] density = solver.CalculateDensity();
            Printer.WriteLine("Density :");
            Printer.Write(density);
            double[] solution = solver.BuildSolutionOn(density,
                                                       xFunc: SolutionCurveX,
                                                       yFunc: SolutionCurveY,
                                                       paramStart: 0.001,
                                                       paramEnd: Math.PI - 0.001,
                                                       solutionPointsNumber: 16);

            DeviationCalculator calculator = new DeviationCalculator();
            double deviation = calculator.MaxDeviation(
                solution,
                accurate: (double t) =>
            {
                Point x = new Point(SolutionCurveX(t), SolutionCurveY(t));
                return(testData.OnTestCurveValue(x));
            },
                paramStart: 0.001,
                paramEnd: Math.PI - 0.001);

            Printer.Append = true;
            Printer.WriteLine("Solution :");
            Printer.Write(solution);
            Printer.WriteLine($"Deviation : {deviation}");
            Console.ReadLine();
        }
        public void CalculateCurve()
        {
            if (_state.DerivativeOnOuterCurve == null)
            {
                // Solver is in testing mode
                // Find derivative
                var initialInnerCurve = _state.InnerCurve;
                _state.InnerCurve = _state.InversProblemTestData.CorrectInnerCurve;
                DirectProblemSolver solver  = new DirectProblemSolver(_state);
                double[]            density = solver.CalculateDensity();
                Printer.WriteLine("Correct density:");
                Printer.Write(density);
                _state.DerivativeOnOuterCurve = _state.BuildSolutionDerivativeOnOuterCurve(density);
                Printer.WriteLine("Derivetive on outer curve:");
                Printer.Write(_state.DerivativeOnOuterCurve);

                // change initial state back
                _state.InnerCurve = initialInnerCurve;
            }

            double[] points = IntegralEquationDiscretezer.GetDiscretePoints(_state.PointsNumber);
            Printer.WriteLine("Innitial inner curve X:");
            Printer.Write(GetCurveValues(_state.InnerCurve, points, onX: true));
            Printer.WriteLine("Innitial inner curve Y:");
            Printer.Write(GetCurveValues(_state.InnerCurve, points, onX: false));

            bool innerCurveFound = false;
            int  iteration       = 0;

            while (iteration < 6)
            {
                Printer.WriteLine($"ITERATION {iteration} ................................");
                DirectProblemSolver solver = new DirectProblemSolver(_state);
                _state.Density = solver.CalculateDensity();
                Printer.WriteLine("Calculated density");
                Printer.Write(_state.Density);

                var curveCorrection = CalculateCurveCorrection();
                Printer.WriteLine("Correction coefficients");
                Printer.Write(curveCorrection);
                var correctedCurve = BuildNewCurve(_state.InnerCurve,
                                                   new ArraySegment <double>(curveCorrection, 0, _state.CorrectionPolinomPower + 1),
                                                   new ArraySegment <double>(curveCorrection, _state.CorrectionPolinomPower + 1,
                                                                             _state.CorrectionPolinomPower + 1));
                // TODO calculate exit conditiona

                Printer.WriteLine("Correct curve X");
                Printer.Write(GetCurveValues(_state.InversProblemTestData.CorrectInnerCurve, points, onX: true));
                Printer.WriteLine("Solution curve x");
                Printer.Write(GetCurveValues(correctedCurve, points, onX: true));
                Printer.WriteLine("Solution curve x pol coeffients");
                Printer.Write((correctedCurve as ApproxParametrizedCurve)._xApproxPolinom.Coefficients.ToArray());
                Printer.WriteLine("Correct curve y");
                Printer.Write(GetCurveValues(_state.InversProblemTestData.CorrectInnerCurve, points, onX: false));
                Printer.WriteLine("Solution curve y");
                Printer.Write(GetCurveValues(correctedCurve, points, onX: false));
                Printer.WriteLine("Solution curve y pol coeffients");
                Printer.Write((correctedCurve as ApproxParametrizedCurve)._yApproxPolinom.Coefficients.ToArray());
                Printer.WriteLine("Correct curve derivative Y");
                Printer.Write(GetCurveDerivativeValues(_state.InversProblemTestData.CorrectInnerCurve, points, onX: false));
                Printer.WriteLine("Solution curve derivative Y");
                Printer.Write(GetCurveDerivativeValues(correctedCurve, points, onX: false));
                Printer.WriteLine("Correct curve derivative X");
                Printer.Write(GetCurveDerivativeValues(_state.InversProblemTestData.CorrectInnerCurve, points, onX: true));
                Printer.WriteLine("Solution curve derivative X");
                Printer.Write(GetCurveDerivativeValues(correctedCurve, points, onX: true));

                _state.InnerCurve = correctedCurve;
                iteration++;
            }
        }