示例#1
0
        public void Step(IAlgebraicSolver solver)
        {
            SolverStatus = solver.Solve(SystemToSolve);

            if (!SolverStatus)
            {
                _logger.Error("Could not solve algebraic equation system.");
            }
        }
示例#2
0
        public List <TimeStep> Integrate(DAEProblem problem, ILogger logger)
        {
            StepSizeMax = Math.Abs(EndTime - StartTime) / 50.0;

            var results = new List <TimeStep>();

            problem.Time.SetValue(StartTime);
            problem.TimeStep.SetValue(StepSize);

            if (UseDulmageMendelsohnSolver)
            {
                Solver = new DecompositionSolver(logger);
            }
            else
            {
                Solver = new BasicNewtonSolver(logger);
            }

            double rho = 0;
            double eps = 0;


            Vector y1h = new Vector(problem.AlgebraicVariables.Count);
            Vector y2h = new Vector(problem.AlgebraicVariables.Count);

            Vector y0   = new Vector(problem.AlgebraicVariables.Count);
            Vector yt_1 = new Vector(problem.AlgebraicVariables.Count);
            Vector yt_2 = new Vector(problem.AlgebraicVariables.Count);

            Vector dummy           = new Vector(problem.AlgebraicVariables.Count);
            double lastProgress    = 0;
            double currentProgress = 0;

            while (problem.Time.InternalValue <= EndTime)
            {
                var x           = problem.AlgebraicVariables.Select(v => v.InternalValue).ToArray();
                var y           = problem.DifferentialVariables.Select(v => v.InternalValue).ToArray();
                var t0          = problem.Time.InternalValue;
                var currentStep = new TimeStep()
                {
                    Time               = t0,
                    AlgebraicStates    = x,
                    DifferentialStates = y
                };
                results.Add(currentStep);
                rho = 0;

                fillVector(y0, yt_1, yt_2, problem);
                var dt = 0.0;

                int iter = 0;


                while (rho < 1)
                {
                    dt = 2 * StepSize;
                    resetVariables(y0, yt_1, yt_2, problem);
                    problem.Time.SetValue(t0);
                    TakeStep(problem, 2 * StepSize);
                    fillVector(y2h, dummy, dummy, problem);

                    resetVariables(y0, yt_1, yt_2, problem);
                    problem.Time.SetValue(t0);
                    TakeStep(problem, StepSize);
                    TakeStep(problem, StepSize);
                    fillVector(y1h, dummy, dummy, problem);

                    eps = (y1h - y2h).GetNorm() / 6.0;
                    rho = StepSize * eps / Tolerance;

                    StepSize = Math.Min(StepSize * Math.Pow(1.0 / rho, 1.0 / 3.0), 2 * StepSize);

                    if (problem.Time.InternalValue + 2 * StepSize > EndTime)
                    {
                        StepSize = (EndTime - problem.Time.InternalValue) / 2.0;
                    }
                    if (StepSize < MinStepSize)
                    {
                        StepSize = MinStepSize;
                    }


                    problem.Time.SetValue(t0);
                    if (iter > 10)
                    {
                        break;
                    }
                    iter++;
                }


                problem.Time.AddDelta(dt);
                currentProgress = problem.Time.InternalValue / EndTime;
                if (currentProgress - lastProgress > 0.01)
                {
                    OnIteration?.Invoke(problem.Time.InternalValue / EndTime);
                    lastProgress = currentProgress;
                }
            }



            return(results);
        }
示例#3
0
        public List <TimeStep> Integrate(DAEProblem problem, ILogger logger)
        {
            var results = new List <TimeStep>();

            TotalSteps = (int)((EndTime - StartTime) / StepSize);

            problem.Time.SetValue(StartTime);
            problem.TimeStep.SetValue(StepSize);

            if (UseDulmageMendelsohnSolver)
            {
                Solver = new DecompositionSolver(logger);
            }
            else
            {
                Solver = new BasicNewtonSolver(logger);
            }


            var x = problem.AlgebraicVariables.Select(v => v.InternalValue).ToArray();
            var y = problem.DifferentialVariables.Select(v => v.InternalValue).ToArray();

            var currentStep = new TimeStep()
            {
                Time               = StartTime,
                AlgebraicStates    = x,
                DifferentialStates = y
            };

            results.Add(currentStep);

            var reportingInveral = TotalSteps / 100;

            for (int i = 0; i < TotalSteps; i++)
            {
                problem.Time.AddDelta(StepSize);

                problem.Step(Solver);

                foreach (var dery in problem.DifferentialVariables)
                {
                    var cury = problem.Mapping[dery];
                    var yt_1 = PreMap[cury];
                    var yt_2 = PreMap[yt_1];
                    yt_2.SetValue(yt_1.InternalValue);
                    yt_1.SetValue(cury.InternalValue);
                }

                x = problem.AlgebraicVariables.Select(v => v.InternalValue).ToArray();
                y = problem.DifferentialVariables.Select(v => v.InternalValue).ToArray();

                currentStep = new TimeStep()
                {
                    Time               = problem.Time.InternalValue,
                    AlgebraicStates    = x,
                    DifferentialStates = y
                };
                results.Add(currentStep);
                logger.Log(currentStep.ToString());

                if (i % reportingInveral == 0)
                {
                    OnIteration?.Invoke(problem.Time.InternalValue / EndTime);
                }
                //System.Threading.Thread.Sleep(2);
            }
            return(results);
        }
        public List <TimeStep> Integrate(DAEProblem problem, ILogger logger)
        {
            var results  = new List <TimeStep>();
            int numSteps = (int)((EndTime - StartTime) / StepSize);

            double time = StartTime;

            problem.Time.SetValue(StartTime);
            problem.TimeStep.SetValue(StepSize);

            if (UseDulmageMendelsohnSolver)
            {
                Solver = new DecompositionSolver(logger);
            }
            else
            {
                Solver = new BasicNewtonSolver(logger);
            }


            var x = problem.AlgebraicVariables.Select(v => v.InternalValue).ToArray();
            var y = problem.DifferentialVariables.Select(v => v.InternalValue).ToArray();

            var currentStep = new TimeStep()
            {
                Time               = time,
                AlgebraicStates    = x,
                DifferentialStates = y
            };

            results.Add(currentStep);


            for (int i = 0; i < numSteps; i++)
            {
                problem.Step(Solver);

                foreach (var dery in problem.DifferentialVariables)
                {
                    var cury = problem.Mapping[dery];
                    cury.AddDelta(dery.InternalValue);
                }

                time += StepSize;
                problem.Time.AddDelta(StepSize);

                x = problem.AlgebraicVariables.Select(v => v.InternalValue).ToArray();
                y = problem.DifferentialVariables.Select(v => v.InternalValue).ToArray();

                currentStep = new TimeStep()
                {
                    Time               = time,
                    AlgebraicStates    = x,
                    DifferentialStates = y
                };
                results.Add(currentStep);
                logger.Log(currentStep.ToString());
            }

            return(results);
        }