Ejemplo n.º 1
0
        private List <ControlSystemDataSample> ExtractChartData(BackgroundSimulationOutput output)
        {
            var data        = output.data;
            int skipSamples = (int)((1d / output.timeStep) / pointsPerSecond);

            if (skipSamples != 0)
            {
                return(data.Where((s, i) => i % skipSamples == 0).ToList());
            }
            else
            {
                return(data);
            }
        }
Ejemplo n.º 2
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Debug.WriteLine("Worker started");
            worker.ReportProgress(0);

            // extract all data from worker input
            BackgroundSimulationInput input = (BackgroundSimulationInput)e.Argument;
            double             timeHorizon  = input.timeHorizon;
            double             timeStep     = input.timeStep;
            IterativeSimulator simulator    = input.iterativeSimulator;

            int iterations    = (int)Math.Floor(timeHorizon / timeStep) + 1;
            var executionTime = ExecTime.Run(() =>
            {
                // first iteration - simulation initialization
                simulator.PrepareSimulation(timeStep);
                progressCounter.Initialize(iterations);
                progressCounter.NextIteration();

                // perform calculations
                for (int i = 1; i < iterations; i++)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }

                    simulator.NextIteration();
                    progressCounter.NextIteration();
                }
            });

            // return result
            BackgroundSimulationOutput output = new BackgroundSimulationOutput()
            {
                totalIterations = iterations,
                timeStep        = timeStep,
                executionTime   = executionTime,
                data            = simulator.GetData()
            };

            e.Result = output;
        }