Exemple #1
0
        public int MathInsert(MathModel model)
        {
            int mathId = 0;

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("dbo.UsersMath_Insert", conn))
                {
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@UserId", model.UserId);
                    cmd.Parameters.AddWithValue("@Easy", model.Easy);
                    cmd.Parameters.AddWithValue("@Medium", model.Medium);
                    cmd.Parameters.AddWithValue("@Hard", model.Hard);

                    SqlParameter parm = new SqlParameter("@Id", SqlDbType.Int);
                    parm.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(parm);
                    cmd.ExecuteNonQuery();
                    mathId = (int)cmd.Parameters["@Id"].Value;
                };
                conn.Close();
            }
            return(mathId);
        }
Exemple #2
0
        public void TestFuncX8_A16_EV6_928()
        {
            double x             = 8;
            double a             = 16;
            double ExpectedValue = 6.928;

            Assert.AreEqual(ExpectedValue, Math.Round(MathModel.GetFunc(x, a), 3));
        }
Exemple #3
0
        public ActionResult SimpleMath()
        {
            ViewBag.title = "Simple Math";
            MathModel m = new MathModel();

            m.Result = 0;
            return(View(m));
        }
Exemple #4
0
        public void TestFuncX16_A16_EV0()
        {
            double x             = 16;
            double a             = 16;
            double ExpectedValue = 0;

            Assert.AreEqual(ExpectedValue, Math.Round(MathModel.GetFunc(x, a), 3));
        }
Exemple #5
0
        public void TestFuncX20_A16_EVNaN()
        {
            double x             = 20;
            double a             = 16;
            double ExpectedValue = double.NaN;

            Assert.AreEqual(ExpectedValue, Math.Round(MathModel.GetFunc(x, a), 3));
        }
        public void Insert(MathModel mathModel)
        {
            _experiments.Add(nameof(MathModel.SynthesizedModelInLpFormat), mathModel.SynthesizedModelInLpFormat);
            _experiments.Add(nameof(MathModel.ReferenceModelInLpFormat), mathModel.ReferenceModelInLpFormat);

            _mathModels.Add(nameof(MathModel.SynthesizedModelInLpFormat), mathModel.SynthesizedModelInLpFormat);
            _mathModels.Add(nameof(MathModel.ReferenceModelInLpFormat), mathModel.ReferenceModelInLpFormat);
        }
Exemple #7
0
 public void Log(MathModel mathModel)
 {
     _logBuilder.AppendLine("================= REFERENCE MODEL ==================");
     _logBuilder.AppendLine(mathModel.ReferenceModelInLpFormat);
     _logBuilder.AppendLine("====================================================");
     _logBuilder.AppendLine("================ SYNTHESIZED MODEL =================");
     _logBuilder.AppendLine(mathModel.SynthesizedModelInLpFormat);
     _logBuilder.AppendLine("====================================================");
 }
Exemple #8
0
        private static void GetArguements(NodeClass node)
        {
            while (true)
            {
                Console.WriteLine("Enter a <http port> <1st Number> <2nd Number> Or to get all services write `GETALL` command");
                string commandString = Console.ReadLine();

                if (commandString == Command.EXIT)
                {
                    break;
                }

                if (commandString == Command.GETALL)
                {
                    GetAllServices(node);
                    continue;
                }

                string[] command = commandString.Split(" ");

                if (command.Length != 3)
                {
                    continue;
                }

                string communicatePort = GetPortOfService(node, command[0]);
                Console.WriteLine($"#{communicatePort}#");
                if (String.IsNullOrEmpty(communicatePort))
                {
                    Console.WriteLine($"Not found communicate port for {command[0]}: ({communicatePort})");
                    continue;
                }

                MathModel mathModel = new MathModel
                {
                    Value1 = Int32.Parse(command[1]),
                    Value2 = Int32.Parse(command[2])
                };

                string serializedMathModel = JsonConvert.SerializeObject(mathModel);

                string        url           = $"http://127.0.0.1:{communicatePort}/api/values";
                StringContent stringContent = CreateStringContent(serializedMathModel);

                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));

                    using (HttpResponseMessage response = httpClient.PostAsync(url, stringContent).Result)
                        using (HttpContent content = response.Content)
                        {
                            Console.WriteLine(content.ReadAsStringAsync().Result);
                        }
                }
            }
        }
        public IActionResult Index()
        {
            MathModel mm = new MathModel();

            mm.Cities = new List <string>()
            {
                "Warszawa", "Praga", "Moskwa", "Madryt"
            };
            return(View(mm));
        }
Exemple #10
0
        public Math(MathModel model, ExecutionEngine logic)
        {
            this.create = () =>
            {
                var left  = logic.Operators.CreateFrom(model.Left);
                var right = logic.Operators.CreateFrom(model.Right, left.Expression.Type);

                return(Expression.MakeBinary(model.Operation, left.Expression, right.Expression));
            };
        }
Exemple #11
0
 [HttpPost] // POST Request
 public ActionResult SimpleMath(MathModel model)
 {
     ViewBag.title = "Simple Math";
     if (ModelState.IsValid)
     {
         decimal v1 = model.FirstNumber;  // Input Text
         decimal v2 = model.SecondNumber; // Input Text
         model.Result = v1 + v2;          // Output
     }
     return(View(model));                 // Returing here
 }
        public IActionResult Index(MathModel mm)
        {
            //  if (ModelState.IsValid) {

            mm.Result = mm.A + mm.B;
            return(View(mm));
            //    }
            //    else {
            //        return View(mm);
            //    }
        }
Exemple #13
0
        public void Calc_IncompleteMathModelException()
        {
            //arrange
            MathModel model     = new MathModel();
            uint      stepCount = 10;

            model.Expressions.Add(new MathModelExpression("s = t * v"));
            model.Expressions.Add(new MathModelExpression("t = 1"));


            Assert.ThrowsException <IncompleteMathModelException>(() => calculator.Calc(model, stepCount));
        }
Exemple #14
0
 public HttpResponseMessage MathInsert(MathModel model)
 {
     try
     {
         MathService        svc  = new MathService();
         ItemResponse <int> resp = new ItemResponse <int>();
         resp.Item = svc.MathInsert(model);
         return(Request.CreateResponse(HttpStatusCode.OK, resp));
     }
     catch (Exception e)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e.Message));
     }
 }
Exemple #15
0
        public void Calc_TrivialSolution()
        {
            //arrange
            MathModel model     = new MathModel();
            uint      stepCount = 10;

            model.Expressions.Add(new MathModelExpression("s = t * v"));
            model.Expressions.Add(new MathModelExpression("t = 1"));
            model.Expressions.Add(new MathModelExpression("v = 0"));

            var resutls = calculator.Calc(model, stepCount);

            Assert.AreEqual(Convert.ToInt32(stepCount + 1), resutls["s"].Count, "Each step should result in an entry. Additional to the start value there will be n + 1 entries.");
            Assert.IsTrue(resutls["s"].All(entry => entry.Equals(0)), "Each result item must be calculated correctly.");
        }
        public IActionResult Index([Bind("addAnswer", "subAnswer", "divAnswer", "multiplyAnswer", "multipleNumbAnswer", "piAnswer", "sumAnswer")] MathModel mathobj)
        {
            addNumbers(mathobj.addAnswer, mathobjpublic.mulNumb1, mathobjpublic.mulNumb2);
            subNumbers(mathobj.subAnswer, mathobjpublic.subNumb1, mathobjpublic.subNumb2);
            divNumbers(mathobj.divAnswer, mathobjpublic.divNumb1, mathobjpublic.divNumb2);
            multiplyNumbers(mathobj.multiplyAnswer, mathobjpublic.addNumb1, mathobjpublic.addNumb2);
            //multipleNumbers(mathobj.multipleNumbAnswer);
            int [] array = RemoveCommasFromStringOfNumbers(mathobj.multipleNumbAnswer);
            CheckOddAndEvenNumbers(array);
            piSymbol(mathobj.piAnswer.ToLower(), mathobjpublic.piCorrect.ToLower());
            sumSymbol(mathobj.sumAnswer.ToLower(), mathobjpublic.sumCorrect.ToLower());



            ViewBag.score = score;
            return(View("Results"));
        }
 private ModelParams modParams;      //Parametry modelu
 //------
 public Solver(ModelParams modParams, MathModel model)
 {
     this.model     = model;
     this.modParams = modParams;
     //---
     this.hc       = 0.00001;
     this.varSize  = modParams.Size;
     this.vars1    = new double[varSize];
     this.vars2    = new double[varSize];
     this.derivSys = new double[varSize];
     this.vecSys   = new double[varSize];
     //copy initial conditions array to vars1 and vars2 arrays
     for (int i = 0; i < varSize; i++)
     {
         vars1[i] = modParams.InitCondit[i];
         vars2[i] = modParams.InitCondit[i];
     }
 }
Exemple #18
0
        public Visualization PreparePlots(IList <Point> testPoints, MathModel mathModel)
        {
            var positiveTestPoints = testPoints.Where(tp => tp.ClassificationType == ClassificationType.Positive).ToList();
            var negativeTestPoints = testPoints.Where(tp => tp.ClassificationType == ClassificationType.Negative).ToList();

            AddNextPlot("Reference model - Test points", _plotWidth, _plotHeight, _yAxisMin, _yAxisMax, _xAxisMin, _xAxisMax);
            AddPoints(positiveTestPoints, OxyColors.Green);
            AddPoints(negativeTestPoints, OxyColors.DarkRed);
            AddConstraints(mathModel.ReferenceModel, OxyPalettes.Rainbow, xMin: mathModel.Domains[0].LowerLimit,
                           xMax: mathModel.Domains[0].UpperLimit);
            AddNextPlot("Synthesized model - Test points", _plotWidth, _plotHeight, _yAxisMin, _yAxisMax, _xAxisMin, _xAxisMax);
            AddPoints(positiveTestPoints, OxyColors.Green);
            AddPoints(negativeTestPoints, OxyColors.DarkRed);
            AddConstraints(mathModel.SynthesizedModel, OxyPalettes.Rainbow, xMin: mathModel.Domains[0].LowerLimit,
                           xMax: mathModel.Domains[0].UpperLimit);

            return(this);
        }
Exemple #19
0
        public void Calc_LinearEquation()
        {
            //arrange
            MathModel model     = new MathModel();
            uint      stepCount = 10;

            model.Expressions.Add(new MathModelExpression("s = t * v"));
            model.Expressions.Add(new MathModelExpression("t = t + dt"));
            model.Expressions.Add(new MathModelExpression("v = 1"));
            model.Expressions.Add(new MathModelExpression("t = 0"));
            model.Expressions.Add(new MathModelExpression("dt = 1"));

            //act
            var resutls = calculator.Calc(model, stepCount);

            //assert
            Assert.AreEqual(Convert.ToInt32(stepCount + 1), resutls["s"].Count, "Each step should result in an entry. Additional to the start value there will be n + 1 entries.");
            Assert.IsTrue(resutls["s"].All(entry => !entry.Equals(double.NaN) && !entry.Equals(double.NaN)), "Each result item must be valid.");
        }
Exemple #20
0
        //public IList<Constraint> GetSynthesizedModel()
        //{
        //    return SynthesizedModel;
        //}

        //public IList<Constraint> GetReferenceModel()
        //{
        //    return Benchmark.Constraints;
        //}

        public virtual MathModel SynthesizeModel(Point[] trainingPoints)
        {
            var offspringPopulationSize = ExperimentParameters.OffspringPopulationSize;
            var numberOfGenerations     = ExperimentParameters.NumberOfGenerations;

            Evaluator.PositivePoints = trainingPoints.Where(tp => tp.ClassificationType == ClassificationType.Positive).ToArray();
            Evaluator.NegativePoints = trainingPoints.Where(tp => tp.ClassificationType == ClassificationType.Negative).ToArray();

            BasePopulation = PopulationGenerator.GeneratePopulation(ExperimentParameters);

            for (var i = 0; i < offspringPopulationSize; i++)
            {
                OffspringPopulation[i] = new Solution(ExperimentParameters);
            }

            InitialPopulation = BasePopulation.DeepCopyByExpressionTree();

            Stoper.Restart();

            for (var i = 0; i < numberOfGenerations; i++)
            {
                Evolve(offspringPopulationSize);
            }

            Stoper.Stop();

            Statistics.TotalEvolutionTime = Stoper.Elapsed;
            Statistics.MeanSingleGenerationEvolutionTime = TimeSpan.FromTicks(Statistics.TotalEvolutionTime.Ticks / numberOfGenerations);

            Stoper.Restart();

            SynthesizedModel = RedundantConstriantsRemover.ApplyProcessing(BasePopulation.First().GetConstraints(ExperimentParameters));

            Stoper.Stop();

            Statistics.RedundantConstraintsRemovingTime = Stoper.Elapsed;
            Statistics.TotalSynthesisTime = Statistics.TotalEvolutionTime + Stoper.Elapsed;

            Stoper.Reset();

            MathModel = new MathModel(SynthesizedModel, Benchmark);
            return(MathModel);
        }
Exemple #21
0
        public void Calc_MultipleUsage()
        {
            //arrange
            MathModel model     = new MathModel();
            uint      stepCount = 1;

            model.Expressions.Add(new MathModelExpression("s = t * v"));
            model.Expressions.Add(new MathModelExpression("t = 2"));
            model.Expressions.Add(new MathModelExpression("v = 1"));

            var results = calculator.Calc(model, stepCount);

            Assert.AreEqual(Convert.ToInt32(stepCount + 1), results["s"].Count, "Each step should result in an entry. Additional to the start value there will be n + 1 entries.");
            Assert.IsTrue(results["s"].All(entry => entry.Equals(2)), "Each result item must be calculated correctly.");

            MathModel model2     = new MathModel();
            uint      stepCount2 = 1;

            model2.Expressions.Add(new MathModelExpression("s = t * v"));
            model2.Expressions.Add(new MathModelExpression("t = 2"));
            model2.Expressions.Add(new MathModelExpression("v = 5"));

            var results2 = calculator.Calc(model2, stepCount2);

            Assert.AreEqual(Convert.ToInt32(stepCount2 + 1), results["s"].Count, "Calling the calculator twice with different step count should led to the use of the new count only.");
            Assert.IsTrue(results2["s"].All(entry => entry.Equals(10)), "Each result item must be calculated correctly, when the calculator got a new math model. (All global paramater should be reset.)");

            MathModel model3     = new MathModel();
            uint      stepCount3 = 1;

            model3.Expressions.Add(new MathModelExpression("s = t * v"));
            model3.Expressions.Add(new MathModelExpression("t = 0"));
            model3.Expressions.Add(new MathModelExpression("v = 0"));

            var results3 = calculator.Calc(model3, stepCount3);

            Assert.AreEqual(Convert.ToInt32(stepCount3 + 1), results["s"].Count, "Calling the calculator with new step count should always lead to the usage of the latest counter.");
            Assert.IsTrue(results3["s"].All(entry => entry.Equals(0)), "Each result item must be calculated correctly, when the calculator got another new math model. (All global paramater should be reset.)");
        }
 public async Task Calc()
 {
     Runned = true;
     var model = new MathModel();
     ResultData = await model.Process(_inputViewModel.InputData);
     Runned = false;
 }
        public MathModel SynthesizeModel(Point[] trainingPoints)
        {
            var means = trainingPoints.Means();
            var standardDeviations = trainingPoints.StandardDeviations(means);

            if (Parameters.UseDataNormalization)
            {
                trainingPoints           = _pointsNormalizer.ApplyProcessing(trainingPoints);
                NormalizedTrainingPoints = trainingPoints.DeepCopyByExpressionTree();
            }

            var evolutionEnginesFactory = new EnginesFactory();
            var evolutionEngine         = evolutionEnginesFactory.Create(Parameters.EvolutionParameters);
            var positiveTrainingPoints  = trainingPoints.Where(tp => tp.ClassificationType == ClassificationType.Positive).ToArray();
            var negativeTrainingPoints  = trainingPoints.Where(tp => tp.ClassificationType == ClassificationType.Negative).ToArray();
            var evaluator = new Evaluator(positiveTrainingPoints, negativeTrainingPoints, _constraintsBuilder);

            //HACK TODO

            //var numberOfConstraintsCoefficients = Parameters.MaximumNumberOfConstraints * (Parameters.NumberOfDimensions + 1);
            //var constraintsCoefficients = new List<double>(numberOfConstraintsCoefficients);
            //var benchmarkConstraintsIndexer = 0;

            //for (var i = 0; i < Parameters.MaximumNumberOfConstraints; i++)
            //{
            //    if (benchmarkConstraintsIndexer >= Benchmark.Constraints.Length)
            //        benchmarkConstraintsIndexer = 0;

            //    constraintsCoefficients.AddRange(Benchmark.Constraints[benchmarkConstraintsIndexer].Terms.Select(t => t.Coefficient));
            //    constraintsCoefficients.Add(Benchmark.Constraints[benchmarkConstraintsIndexer++].LimitingValue);
            //}

            //PopulationGeneratorBase.ObjectCoefficients = constraintsCoefficients.ToArray();

            //

            Solution bestSolution;

            if (Parameters.UseSeeding)
            {
                var singleConstraintModel = Parameters.TypeOfBenchmark == BenchmarkType.Balln && Parameters.AllowQuadraticTerms
                    ? Benchmark.Constraints.Take(1).DeepCopyByExpressionTree().ToArray()
                    : new[] { new LinearConstraint(Benchmark.Constraints.First().Terms.Where(t => t.Type == TermType.Linear).ToArray(), 0) };
                var singleConstraintBuilder   = new ConstraintsBuilder(singleConstraintModel);
                var singleConstraintEvaluator = new Evaluator(positiveTrainingPoints, negativeTrainingPoints, singleConstraintBuilder);
                var seedingProcessor          = new SeedingProcessor(singleConstraintEvaluator, _constraintsBuilder, positiveTrainingPoints);

                bestSolution = evolutionEngine.RunEvolution(evaluator, seedingProcessor);
            }
            else
            {
                bestSolution = evolutionEngine.RunEvolution(evaluator);
            }

            CoreEvolutionSteps = evolutionEngine.EvolutionSteps;

            Statistics.EvolutionStatistics = evolutionEngine.Statistics;
            var synthesizedConstraints = _constraintsBuilder.BuildConstraints(bestSolution);

            if (Parameters.UseDataNormalization)
            {
                NormalizedSynthesizedConstraints = synthesizedConstraints.DeepCopyByExpressionTree();
                _constaintsDenormalizer          = new StandardScoreConstraintsDenormalizer(means, standardDeviations);
                synthesizedConstraints           = _constaintsDenormalizer.ApplyProcessing(synthesizedConstraints);
            }

            if (Parameters.TrackEvolutionSteps)
            {
                var evolutionStepsAsSolutions = evolutionEngine.EvolutionStepsSimple.ToList();

                foreach (var evolutionStepsAsSolution in evolutionStepsAsSolutions)
                {
                    var evolutionStep = _constraintsBuilder.BuildConstraints(evolutionStepsAsSolution);

                    if (Parameters.UseDataNormalization)
                    {
                        NormalizedEvolutionSteps.Add(evolutionStep.DeepCopyByExpressionTree());
                        evolutionStep = _constaintsDenormalizer.ApplyProcessing(evolutionStep);
                    }

                    EvolutionSteps.Add(evolutionStep);
                }
            }

            if (Parameters.UseRedundantConstraintsRemoving)
            {
                _stoper.Restart();
                synthesizedConstraints = _redundantConstraintsRemover.ApplyProcessing(synthesizedConstraints);
                _stoper.Stop();
                Statistics.RedundantConstraintsRemovingTime = _stoper.Elapsed;
            }

            MathModel = new MathModel(synthesizedConstraints, Benchmark);
            Statistics.NumberOfConstraints = synthesizedConstraints.Length;
            Statistics.MeanAngle           = Parameters.TypeOfBenchmark != BenchmarkType.Balln ? _meanAngleCalculator.Calculate(synthesizedConstraints, Benchmark.Constraints) : double.NaN;

            return(MathModel);
        }
        public ActionResult DrawWaveforms(Parameters param)
        {
            //solver results
            //0   |1  |2  |3  |4  |5  |6  |7    |8   |9  |10 |11 |12 |13 |14 |15  |16
            //time|Isu|Isv|Isw|Iru|Irv|Irw|Omega|Alfa|Usu|Usv|Usw|Uru|Urv|Urv|Text|Telem
            //-------

            DataTable  dTableIU;
            DataTable  dTableOmegaTorque;
            DataView   dViewIU;
            DataView   dViewOmegaTorque;
            DataColumn column;
            DataRow    row;



            ModelParams modelParams = new ModelParams();

            parametersPassing(param, modelParams);

            MathModel mathModel = new MathModel(modelParams, modelParams.TimeStart, modelParams.InitCondit);
            Solver    solver    = new Solver(modelParams, mathModel);



            solver.SolverStart(modelParams);

            //currents and voltages chart
            dTableIU          = new DataTable();
            column            = new DataColumn();
            column.DataType   = Type.GetType("System.Double");
            column.ColumnName = "Time";
            dTableIU.Columns.Add(column);
            //______________________
            column            = new DataColumn();
            column.DataType   = Type.GetType("System.Double");
            column.ColumnName = "Iu";
            dTableIU.Columns.Add(column);
            //_______________________
            column            = new DataColumn();
            column.DataType   = Type.GetType("System.Double");
            column.ColumnName = "Iv";
            dTableIU.Columns.Add(column);
            //_______________________
            column            = new DataColumn();
            column.DataType   = Type.GetType("System.Double");
            column.ColumnName = "Iw";
            dTableIU.Columns.Add(column);
            //________________________
            column            = new DataColumn();
            column.DataType   = Type.GetType("System.Double");
            column.ColumnName = "Uuv";
            dTableIU.Columns.Add(column);
            // Adding rows

            double Ki = 1; // or Math.Sqrt(3)
            double Ku = 1; // or 0.25

            for (int i = 0; i < modelParams.PtsResults; i++)
            {
                row         = dTableIU.NewRow();
                row["Time"] = solver.Results[i, 0];
                row["Iu"]   = solver.Results[i, 1] * Ki;
                row["Iv"]   = solver.Results[i, 2] * Ki;
                row["Iw"]   = solver.Results[i, 3] * Ki;
                row["Uuv"]  = solver.Results[i, 9] * Ku;
                dTableIU.Rows.Add(row);
            }
            dViewIU = new DataView(dTableIU);

            Chart chartIU = new Chart();

            chartIU.Width  = 1050;
            chartIU.Height = 700;

            chartIU.Series.Clear();
            chartIU.Titles.Clear();
            chartIU.Titles.Add("Currents and voltages waveforms");

            chartIU.DataBindTable(dViewIU, "Time");
            chartIU.ChartAreas.Add(new ChartArea("Current"));
            chartIU.ChartAreas.Add(new ChartArea("Voltage"));
            chartIU.ChartAreas["Voltage"].AxisY.Title = "Uuv[V]";
            chartIU.ChartAreas["Current"].AxisY.Title = "Stator currents [A]";
            chartIU.Series["Uuv"].ChartType           = SeriesChartType.Line;
            chartIU.Series["Iu"].ChartType            = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
            chartIU.Series["Iv"].ChartType            = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
            chartIU.Series["Iw"].ChartType            = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
            chartIU.Series["Uuv"].ChartArea           = "Voltage";
            chartIU.Series["Iu"].ChartArea            = "Current";
            chartIU.Series["Iv"].ChartArea            = "Current";
            chartIU.Series["Iw"].ChartArea            = "Current";
            chartIU.ChartAreas[0].AxisX.Minimum       = 0;
            chartIU.ChartAreas[1].AxisX.Minimum       = 0;

            //________________________________________________________________________________________________

            chartIU.Titles[0].Font = new System.Drawing.Font(
                "Times New Roman", 16F, System.Drawing.FontStyle.Bold);
            chartIU.Titles[0].ForeColor = System.Drawing.Color.FromArgb(250, 0, 0);
            //***********************************************************

            //Speed and torque
            dTableOmegaTorque = new DataTable();
            column            = new DataColumn();
            column.DataType   = Type.GetType("System.Double");
            column.ColumnName = "Time";
            dTableOmegaTorque.Columns.Add(column);
            //___________________________
            column            = new DataColumn();
            column.DataType   = Type.GetType("System.Double");
            column.ColumnName = "Omega";
            dTableOmegaTorque.Columns.Add(column);
            //___________________________
            column            = new DataColumn();
            column.DataType   = Type.GetType("System.Double");
            column.ColumnName = "Torque";
            dTableOmegaTorque.Columns.Add(column);
            //___________________________
            double Kt = 2;

            //adding rows
            for (int i = 0; i < modelParams.PtsResults; i++)
            {
                row           = dTableOmegaTorque.NewRow();
                row["Time"]   = solver.Results[i, 0];
                row["Omega"]  = solver.Results[i, 7];
                row["Torque"] = solver.Results[i, 16] * Kt;
                dTableOmegaTorque.Rows.Add(row);
            }

            dViewOmegaTorque = new DataView(dTableOmegaTorque);

            Chart chartOmegaTorque = new Chart();

            chartOmegaTorque.Width  = 1050;
            chartOmegaTorque.Height = 700;

            dViewOmegaTorque = new DataView(dTableOmegaTorque);

            chartOmegaTorque.ChartAreas.Add("Waveforms");
            chartOmegaTorque.DataBindTable(dViewOmegaTorque, "Time");
            chartOmegaTorque.Series["Omega"].ChartType                       = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
            chartOmegaTorque.Series["Torque"].ChartType                      = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
            chartOmegaTorque.ChartAreas["Waveforms"].AxisX.Minimum           = 0.0;
            chartOmegaTorque.ChartAreas["Waveforms"].AxisX.Maximum           = (double)solver.Results[modelParams.PtsResults - 1, 0];
            chartOmegaTorque.ChartAreas["Waveforms"].AxisX.LabelStyle.Format = "{#0.000}";
            chartOmegaTorque.Width  = 1050;
            chartOmegaTorque.Height = 400;

            // Legend and title
            chartOmegaTorque.ChartAreas["Waveforms"].AxisY.Title = "Omega and Torque";
            chartOmegaTorque.Legends.Add(new Legend("Legend"));
            chartOmegaTorque.Legends["Legend"].DockedToChartArea = "Waveforms";
            chartOmegaTorque.Series["Omega"].Legend            = "Legend";
            chartOmegaTorque.Series["Omega"].IsVisibleInLegend = true;
            chartOmegaTorque.Series["Omega"].LegendText        = "Omega [rad/s]";
            chartOmegaTorque.Series["Torque"].LegendText       = "Torque*2 [Nm]";
            chartOmegaTorque.Legends["Legend"].Alignment       = StringAlignment.Center;



            // ------------- Creating chart list ------------

            var chartList = new List <Chart> {
                chartIU, chartOmegaTorque
            };
            var imageList = ChartsToImages(chartList);

            // ----- Final size of image and bonding charts into one .bmp file
            var size = new Size();

            foreach (var image in imageList)
            {
                if (image.Width > size.Width)
                {
                    size.Width = image.Width;
                }
                size.Height += image.Height;
            }
            var finalImage = new Bitmap(size.Width, size.Height);

            using (var gfx = Graphics.FromImage(finalImage))
            {
                var y = 0;
                foreach (var image in imageList)
                {
                    gfx.DrawImage(image, 0, y);
                    y += image.Height;
                }
            }
            MemoryStream finalms = new MemoryStream();

            finalImage.Save(finalms, System.Drawing.Imaging.ImageFormat.Png);
            for (int i = 0; i < 8; i++)
            {
                modelParams.InitCondit[i] = 0;
            }

            return(File(finalms.GetBuffer(), "image/png"));
        }
Exemple #25
0
    protected void btnOblicz_Click(object sender, EventArgs e)
    {
        bool bVal1  = Double.TryParse(txtTmin.Text, out tmin);
        bool bVal2  = Double.TryParse(txtTmax.Text, out tmax);
        bool bVal4  = Double.TryParse(txtUa.Text, out Ua);
        bool bVal5  = Double.TryParse(txtRa_ext.Text, out Ra_ext);
        bool bVal6  = Double.TryParse(txtRf_ext.Text, out Rf_ext);
        bool bVal7  = Double.TryParse(txtMa_ext.Text, out Ma_ext);
        bool bVal8  = Double.TryParse(txtMf_ext.Text, out Mf_ext);
        bool bVal9  = Double.TryParse(txtJr_ext.Text, out Jr_ext);
        bool bVal10 = Double.TryParse(txtDr_ext.Text, out Dr_ext);
        bool bVal11 = Double.TryParse(txtText.Text, out Text);
        bool bVal12 = Double.TryParse(txtText_t1.Text, out Text_t1);
        bool bVal13 = Double.TryParse(txtText_t2.Text, out Text_t2);

        //Chart1.Visible = true;
        //Chart4.Visible = true;
        //---

        modelParams = new ModelParams();

        //modelParams.TimeStart = tmin;
        modelParams.TimeStop = tmax;

        modelParams.Uarma = Ua;
        modelParams.Uflux = Uf;

        modelParams.Raext = Ra_ext;
        modelParams.Rfext = Rf_ext;
        modelParams.Maext = Ma_ext * 0.001;   //przeliczenie jednostek do µF i mH
        modelParams.Mfext = Mf_ext * 0.001;   //przeliczenie jednostek do µF i mH

        modelParams.Jrext = Jr_ext;
        modelParams.Drext = Dr_ext;

        //ustawianie parametrow momentu zewnetrznego
        modelParams.Textern    = Text;
        modelParams.Textern_t1 = Text_t1;
        modelParams.Textern_t2 = Text_t2;
        //----
        flag = false;


        size = Convert.ToInt32(tmax / delta); //liczenie ilości próbek

        modelParams.PtsResults = size;
        //------------Sprawdzenie poprawności wprowadzania danych - walidacja-------------
        if (tmin >= tmax || tmax > 5 || tmin < 0 || !bVal1 || !bVal2)
        {
            validation.Visible           = true;
            labErrorMessage_time.Visible = true;
            labErrorMessage_time.Text    = "Wartości parametrów t<sub>min</sub> oraz t<sub>max</sub> zostały wprowadzone błędnie ";
            txtTmin.BackColor            = System.Drawing.Color.Red;
            txtTmax.BackColor            = System.Drawing.Color.Red;
            flag = true;
        }

        /* Sprawdzenie poprawności napięć*/

        if (!bVal4 || Ua < 0)
        {
            validation.Visible = true;
            labErrorMessage_Voltage.Visible = true;
            labErrorMessage_Voltage.Text    = "Błędnie wprowadzona wartość napięcia twornika";
            txtUa.BackColor = System.Drawing.Color.Red;
            flag            = true;
        }
        /* Sprawdzenie poprawności parametrów obwodu*/

        if (!bVal5 || Ra_ext < 0)
        {
            validation.Visible           = true;
            labErrorMessage_Reza.Visible = true;
            labErrorMessage_Reza.Text    = "Błędnie wprowadzona wartość rezystancji obwodu twornika";
            txtRa_ext.BackColor          = System.Drawing.Color.Red;
            flag = true;
        }
        if (!bVal6 || Rf_ext < 0)
        {
            validation.Visible           = true;
            labErrorMessage_Rezf.Visible = true;
            labErrorMessage_Rezf.Text    = "Błędnie wprowadzona wartość rezystancji obwodu wzbudzenia";
            txtRf_ext.BackColor          = System.Drawing.Color.Red;
            flag = true;
        }
        if (!bVal7 || Ma_ext < 0)
        {
            validation.Visible           = true;
            labErrorMessage_Inda.Visible = true;
            labErrorMessage_Inda.Text    = "Błędnie wprowadzona wartość indukcyjności obwodu twornika";
            txtMa_ext.BackColor          = System.Drawing.Color.Red;
            flag = true;
        }
        if (!bVal8 || Mf_ext < 0)
        {
            validation.Visible           = true;
            labErrorMessage_Indf.Visible = true;
            labErrorMessage_Indf.Text    = "Błędnie wprowadzona wartość indukcyjności obwodu wzbudzenia";
            txtMf_ext.BackColor          = System.Drawing.Color.Red;
            flag = true;
        }
        /********sprawdzenie  momentu bezwładności oraz współczynnika tłumienia********/
        if (!bVal9 || Jr_ext < 0 || Jr_ext > 1)
        {
            validation.Visible         = true;
            labErrorMessage_Jr.Visible = true;
            labErrorMessage_Jr.Text    = "Wprowadzono niepoprawną wartość momentu bezwładności";
            txtJr_ext.BackColor        = System.Drawing.Color.Red;
            flag = true;
        }
        if (!bVal10 || Dr_ext < 0 || Dr_ext > 1)
        {
            validation.Visible         = true;
            labErrorMessage_Dr.Visible = true;
            labErrorMessage_Dr.Text    = "Wprowadzono niepoprawną wartość współczynnika tłumienia";
            txtDr_ext.BackColor        = System.Drawing.Color.Red;
            flag = true;
        }
        /*Sprawdzenie warunku momentu*/
        if (Text_t1 > Text_t2 || Text_t2 > tmax || Text_t1 < 0 || Text_t1 < 0 || Text_t2 < 0 || !bVal12 || !bVal13 || !bVal11)
        {
            validation.Visible           = true;
            labErrorMessage_Text.Visible = true;
            labErrorMessage_Text.Text    = "Błędne wartości parametrów Text<sub>t1</sub>, Text<sub>t2</sub> oraz Text";
            txtText.BackColor            = System.Drawing.Color.Red;
            txtText_t1.BackColor         = System.Drawing.Color.Red;
            txtText_t2.BackColor         = System.Drawing.Color.Red;
            flag = true;
        }
        /*pętla*/
        if (flag == true)
        {
            return;
        }
        else
        {
            labErrorMessage.Visible = true;
            labErrorMessage.Text    = "Dane zostały wprowadzone poprawnie";
            Chart1.Visible          = true;
        }

        this.mathModel = new MathModel(modelParams, modelParams.TimeStart, modelParams.InitCondit);
        this.solver    = new Solver(modelParams, mathModel);
        //---
        solver.SolverStart(modelParams);
        double[,] wyniki = solver.Results;
        //-- pierwsza tabela danych do wykresu 1
        table1 = new DataTable();
        //--
        DataColumn column1;
        DataRow    row1;

        //--
        column1            = new DataColumn();
        column1.DataType   = Type.GetType("System.Double");
        column1.ColumnName = "Torque";
        table1.Columns.Add(column1);
        //=--
        //column = new DataColumn();
        //column.DataType = Type.GetType("System.Double");
        //column.ColumnName = "Voltage";
        //table.Columns.Add(column);
        //=--
        column1            = new DataColumn();
        column1.DataType   = Type.GetType("System.Double");
        column1.ColumnName = "Omega";
        table1.Columns.Add(column1);
        //=--
        //column1 = new DataColumn();
        //column1.DataType = Type.GetType("System.Double");
        //column1.ColumnName = "Uf";
        //table1.Columns.Add(column1);
        //=--
        //column1 = new DataColumn();
        //column1.DataType = Type.GetType("System.Double");
        //column1.ColumnName = "Ics";
        //table1.Columns.Add(column1);


        //----- tabela do drugiego wykresu

        //table2 = new DataTable();

        //DataColumn column2;
        //DataRow row2;
        //--
        //column2 = new DataColumn();
        //column2.DataType = Type.GetType("System.Double");
        //column2.ColumnName = "Time";
        //table2.Columns.Add(column2);

        //column2 = new DataColumn();
        //column2.DataType = Type.GetType("System.Double");
        //column2.ColumnName = "Uas";
        //table2.Columns.Add(column2);
        ////=--
        //column2 = new DataColumn();
        //column2.DataType = Type.GetType("System.Double");
        //column2.ColumnName = "Ubs";
        //table2.Columns.Add(column2);
        ////=--
        //column2 = new DataColumn();
        //column2.DataType = Type.GetType("System.Double");
        //column2.ColumnName = "Ucs";
        //table2.Columns.Add(column2);

        //-------tabela do trzeciego wykresu

        //table3 = new DataTable();

        //DataColumn column3;
        //DataRow row3;
        //--
        //column3 = new DataColumn();
        //column3.DataType = Type.GetType("System.Double");
        //column3.ColumnName = "Time";
        //table3.Columns.Add(column3);

        //column3 = new DataColumn();
        //column3.DataType = Type.GetType("System.Double");
        //column3.ColumnName = "Iar";
        //table3.Columns.Add(column3);
        ////=--
        //column3 = new DataColumn();
        //column3.DataType = Type.GetType("System.Double");
        //column3.ColumnName = "Ibr";
        //table3.Columns.Add(column3);
        ////=--
        //column3 = new DataColumn();
        //column3.DataType = Type.GetType("System.Double");
        //column3.ColumnName = "Icr";
        //table3.Columns.Add(column3);

        //-------tabela do czwartego wykresu

        //table2 = new DataTable();

        //DataColumn column2;
        //DataRow row2;
        //--
        //column2 = new DataColumn();
        //column2.DataType = Type.GetType("System.Double");
        //column2.ColumnName = "Time";
        //table2.Columns.Add(column2);

        //column2 = new DataColumn();
        //column2.DataType = Type.GetType("System.Double");
        //column2.ColumnName = "ω";
        //table2.Columns.Add(column2);
        //=--
        //column2 = new DataColumn();
        //column2.DataType = Type.GetType("System.Double");
        //column2.ColumnName = "Text";
        //table2.Columns.Add(column2);
        //=--
        //column2 = new DataColumn();
        //column2.DataType = Type.GetType("System.Double");
        //column2.ColumnName = "Telem";
        //table2.Columns.Add(column2);


        //----------------
        int size_tmin = Convert.ToInt32(tmin / delta);

        //labErrorMessage.Text = "jest to ilosc " + (int)size;
        for (int i = 0; i <= size; i++)
        {
            row1           = table1.NewRow();
            row1["Torque"] = wyniki[i, 7];
            row1["Omega"]  = wyniki[i, 3]; //
            //row1["Uf"] = wyniki[i, 6]; //
            //row1["Ics"] = wyniki[i, 3]; //

            table1.Rows.Add(row1);

            //row2 = table2.NewRow();
            //row2["Time"] = wyniki[i, 0];
            //row2["Uas"] = wyniki[i, 9]; //
            //row2["Ubs"] = wyniki[i, 10]; //
            //row2["Ucs"] = wyniki[i, 11]; //

            //table2.Rows.Add(row2);

            //row3 = table3.NewRow();
            //row3["Time"] = wyniki[i, 0];
            //row3["Iar"] = wyniki[i, 4]; //
            //row3["Ibr"] = wyniki[i, 5]; //
            //row3["Icr"] = wyniki[i, 6]; //

            //table3.Rows.Add(row3);

            //row2 = table2.NewRow();
            //row2["Time"] = wyniki[i, 0];
            //row2["ω"] = wyniki[i, 3]; //
            //row2["Text"] = wyniki[i, 5]; //
            //row2["Telem"] = wyniki[i, 6]; //

            //table2.Rows.Add(row2);
        }
        //table1.Rows.RemoveAt(table1.Rows.Count - 1);
        dView1 = new DataView(table1);
        //--

        Chart1.Series.Clear();
        Chart1.ChartAreas.Add("Wykres01");
        //--
        Chart1.DataBindTable(dView1, "Torque");
        Chart1.Width  = 900;
        Chart1.Height = 750;

        //Chart3.Series["Voltage"].ChartType = SeriesChartType.Line;

        Chart1.Series["Omega"].ChartType   = SeriesChartType.Spline;
        Chart1.Series["Omega"].BorderWidth = 3;//grubosc wykresu



        //Chart1.Series["Uf"].ChartType = SeriesChartType.Spline;
        //Chart1.Series["Uf"].BorderWidth = 3;//grubosc wykresu
        //Chart1.ChartAreas["ChartArea1"].AxisY2.Enabled = AxisEnabled.True;
        //Chart1.Series["Uf"].YAxisType = AxisType.Secondary;

        //if (chkIcs.Checked)
        //{
        //    Chart1.Visible = true;
        //    Chart1.Series["Ics"].ChartType = SeriesChartType.Line;
        //    Chart1.Series["Ics"].BorderWidth = 3;//grubosc wykresu
        //}
        //Chart1.ChartAreas[0].AxisX.LineWidth = 2;
        Chart1.ChartAreas[0].AxisX.Minimum = tmin;
        //Chart1.ChartAreas[0].AxisX.Maximum = (double)table.Rows[size]["Time"];
        //Chart1.ChartAreas[0].AxisY.Minimum = 0.0;
        Chart1.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Lines;//strzałki wykresu
        //Chart1.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines;
        Chart1.ChartAreas[0].AxisY2.ArrowStyle = AxisArrowStyle.Lines;
        //Chart1.ChartAreas[0].AxisY2.Minimum = 0.0;
        //Chart1.ChartAreas[0].AxisY2.Maximum = 2.4;
        Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "{#0.###}";
        Chart1.ChartAreas[0].AxisX.Title             = "Moment obrotowy [Nm]";
        Chart1.ChartAreas[0].AxisY.Title             = "Omega [rad/s]";
        //Chart1.ChartAreas[0].AxisY2.Title = "Uf [V]";
        Chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Calibri", 11F, System.Drawing.FontStyle.Bold);
        Chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Calibri", 11F, System.Drawing.FontStyle.Bold);
        //Chart1.ChartAreas[0].AxisY2.TitleFont = new System.Drawing.Font("Calibri", 11F, System.Drawing.FontStyle.Bold);


        //DRUGI WYKRES

        //dView2 = new DataView(table2);
        ////--

        //Chart2.Series.Clear();
        //Chart2.ChartAreas.Add("Wykres02");
        //Chart2.Series.Add("Series2");
        ////--
        //Chart2.DataBindTable(dView2, "Time");
        //Chart2.Width = 1200;
        //Chart2.Height = 800;

        ////Chart3.Series["Voltage"].ChartType = SeriesChartType.Line;
        //if (chkUas.Checked)
        //{
        //    Chart2.Visible = true;
        //    Chart2.Series["Uas"].ChartType = SeriesChartType.Line;
        //    Chart2.Series["Uas"].BorderWidth = 3;//grubosc wykresu
        //}

        //if (chkUbs.Checked)
        //{
        //    Chart2.Visible = true;
        //    Chart2.Series["Ubs"].ChartType = SeriesChartType.Line;
        //    Chart2.Series["Ubs"].BorderWidth = 3;//grubosc wykresu
        //}

        //if (chkUcs.Checked)
        //{
        //    Chart2.Visible = true;
        //    Chart2.Series["Ucs"].ChartType = SeriesChartType.Line;
        //    Chart2.Series["Ucs"].BorderWidth = 3;//grubosc wykresu
        //}

        ////Chart1.ChartAreas[0].AxisX.LineWidth = 2;
        //Chart2.ChartAreas[0].AxisX.Minimum = tmin;
        ////Chart1.ChartAreas[0].AxisX.Maximum = (double)table.Rows[size]["Time"];
        ////Chart1.ChartAreas[0].AxisY.Minimum = 0.0;
        //Chart2.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Lines;//strzałki wykresu
        //Chart2.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines;
        //Chart2.ChartAreas[0].AxisY2.Minimum = 0.0;
        //Chart2.ChartAreas[0].AxisY2.Maximum = 100.0;
        //Chart2.ChartAreas[0].AxisX.LabelStyle.Format = "{#0.###}";
        //Chart2.ChartAreas[0].AxisX.Title = "Czas [s]";
        //Chart2.ChartAreas[0].AxisY.Title = "Napięcie [U]";
        //Chart2.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Calibri", 15F, System.Drawing.FontStyle.Bold);
        //Chart2.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Calibri", 15F, System.Drawing.FontStyle.Bold);

        //Trzeci WYKRES

        //dView3 = new DataView(table3);
        ////--

        //Chart3.Series.Clear();
        //Chart3.ChartAreas.Add("Wykres03");
        ////--
        //Chart3.DataBindTable(dView3, "Time");
        //Chart3.Width = 1200;
        //Chart3.Height = 800;

        //if (chkIar.Checked)
        //{
        //    Chart3.Visible = true;
        //    Chart3.Series["Iar"].ChartType = SeriesChartType.Line;
        //    Chart3.Series["Iar"].BorderWidth = 3;//grubosc wykresu
        //}

        //if (chkIbr.Checked)
        //{
        //    Chart3.Visible = true;
        //    Chart3.Series["Ibr"].ChartType = SeriesChartType.Line;
        //    Chart3.Series["Ibr"].BorderWidth = 3;//grubosc wykresu
        //}

        //if (chkIcr.Checked)
        //{
        //    Chart3.Visible = true;
        //    Chart3.Series["Icr"].ChartType = SeriesChartType.Line;
        //    Chart3.Series["Icr"].BorderWidth = 3;//grubosc wykresu
        //}

        ////Chart1.ChartAreas[0].AxisX.LineWidth = 2;
        //Chart3.ChartAreas[0].AxisX.Minimum = tmin;
        ////Chart1.ChartAreas[0].AxisX.Maximum = (double)table.Rows[size]["Time"];
        ////Chart1.ChartAreas[0].AxisY.Minimum = 0.0;
        //Chart3.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Lines;//strzałki wykresu
        //Chart3.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines;
        //Chart3.ChartAreas[0].AxisY2.Minimum = 0.0;
        //Chart3.ChartAreas[0].AxisY2.Maximum = 100.0;
        //Chart3.ChartAreas[0].AxisX.LabelStyle.Format = "{#0.###}";
        //Chart3.ChartAreas[0].AxisX.Title = "Czas [s]";
        //Chart3.ChartAreas[0].AxisY.Title = "Prąd [A]";
        //Chart3.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Calibri", 15F, System.Drawing.FontStyle.Bold);
        //Chart3.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Calibri", 15F, System.Drawing.FontStyle.Bold);

        //Czwarty WYKRES

        //dView2 = new DataView(table2);
        //--

        //Chart2.Series.Clear();
        //Chart2.ChartAreas.Add("Wykres04");
        //--

        //Chart2.DataBindTable(dView2, "Time");
        //Chart2.Width = 900;
        //Chart2.Height = 750;



        //Chart4.Visible = true;
        //Chart4.ChartAreas["ChartArea1"].AxisY2.Enabled = AxisEnabled.True;
        //Chart4.Series["ω"].ChartType = SeriesChartType.Line;
        //Chart4.Series["ω"].BorderWidth = 3;//grubosc wykresu
        //Chart4.Series["ω"].YAxisType = AxisType.Secondary;



        //Chart2.Series["ω"].ChartType = SeriesChartType.Line;
        //Chart2.Series["ω"].BorderWidth = 3;//grubosc wykresu
        //Chart2.ChartAreas["ChartArea1"].AxisY2.Enabled = AxisEnabled.True;
        //Chart2.Series["ω"].YAxisType = AxisType.Secondary;



        //Chart2.Series["Text"].ChartType = SeriesChartType.Line;
        //Chart2.Series["Text"].BorderWidth = 3;//grubosc wykresu


        //Chart2.Series["Telem"].ChartType = SeriesChartType.Line;
        //Chart2.Series["Telem"].BorderWidth = 3;//grubosc wykresu



        //Chart1.ChartAreas[0].AxisX.LineWidth = 2;
        //Chart2.ChartAreas[0].AxisX.Minimum = tmin;
        //Chart1.ChartAreas[0].AxisX.Maximum = (double)table.Rows[size]["Time"];
        //Chart1.ChartAreas[0].AxisY.Minimum = 0.0;
        //Chart2.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Lines;//strzałki wykresu
        //Chart2.ChartAreas[0].AxisY2.ArrowStyle = AxisArrowStyle.Lines;
        //Chart4.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines;
        //Chart4.ChartAreas[0].AxisY2.Minimum = 0.0;
        //Chart4.ChartAreas[0].AxisY2.Maximum = 110.0;
        //Chart2.ChartAreas[0].AxisY2.Title = "prędkość kątowa [rad/s]";
        //Chart2.ChartAreas[0].AxisX.LabelStyle.Format = "{#0.###}";
        //Chart2.ChartAreas[0].AxisX.Title = "Czas [s]";
        //Chart2.ChartAreas[0].AxisY.Title = "Moment [Nm]";
        //Chart2.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Calibri", 11F, System.Drawing.FontStyle.Bold);
        //Chart2.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Calibri", 11F, System.Drawing.FontStyle.Bold);
        //Chart2.ChartAreas[0].AxisY2.TitleFont = new System.Drawing.Font("Calibri", 11F, System.Drawing.FontStyle.Bold);
    }
Exemple #26
0
        public Visualization PreparePlots(IList <Point> positivePoints, IList <Point> negativePoints, IList <Point> testPoints, MathModel mathModel, IList <IList <Constraint> > evolutionSteps, int numberOfSteps)
        {
            PreparePlots(positivePoints, negativePoints, mathModel, evolutionSteps, numberOfSteps);
            PreparePlots(testPoints, mathModel);

            return(this);
        }
 public MainWindowController(MainWindow parent)
 {
     mainWindow = parent;
     Model      = new MathModel();
 }
 private void HandleMathFact(MathModel message)
 {
     _mathActor.Tell(message);
 }
    protected void btnOblicz_Click(object sender, EventArgs e)
    {
        bool bVal1 = Int32.TryParse(txtTmin.Text, out Tmin);
        bool bVal2 = Int32.TryParse(txtTmax.Text, out Tmax);
        bool bVal4 = Double.TryParse(txtUt_m.Text, out U_mnoznik);


        //Chart1.Visible = true;
        //Chart4.Visible = true;
        //---

        modelParams = new ModelParams();

        //modelParams.TimeStart = tmin;
        //modelParams.TimeStop = tmax;
        modelParams.Uarma = Ua * U_mnoznik;
        modelParams.Uflux = Uf;

        modelParams.Raext = Ra_ext;
        modelParams.Rfext = Rf_ext;
        modelParams.Maext = Ma_ext * 0.001;   //przeliczenie jednostek do µF i mH
        modelParams.Mfext = Mf_ext * 0.001;   //przeliczenie jednostek do µF i mH



        If = modelParams.Uflux / modelParams.Rfint;
        //Ia = (modelParams.Uarma - modelParams.Gaf * If * ω) / modelParams.Raint;
        //ω = (modelParams.Uarma - modelParams.Raint * Ia) / (modelParams.Gaf * If);

        //modelParams.Jrext = Jr_ext;
        modelParams.Drext = Dr_ext;

        //Text = modelParams.Drext * ω - modelParams.Gaf * If * Ia;

        //ustawianie parametrow momentu zewnetrznego
        modelParams.Textern    = Text;
        modelParams.Textern_t1 = Text_t1;
        modelParams.Textern_t2 = Text_t2;
        //----
        flag = false;

        //size = Convert.ToInt32(Tmax / delta); //liczenie ilości próbek ; modelParams.Tstop
        //modelParams.PtsResults = size;

        size = modelParams.PtsResults;
        //------------Sprawdzenie poprawności wprowadzania danych - walidacja-------------
        if (Tmin >= Tmax || Tmin < 0 || !bVal1 || !bVal2)
        {
            validation.Visible         = true;
            labErrorMessage_Tm.Visible = true;
            labErrorMessage_Tm.Text    = "Wartości parametrów t<sub>min</sub> oraz t<sub>max</sub> zostały wprowadzone błędnie ";
            txtTmin.BackColor          = System.Drawing.Color.Red;
            txtTmax.BackColor          = System.Drawing.Color.Red;
            flag = true;
        }

        /* Sprawdzenie poprawności napięć*/

        if (!bVal4 || Ua < 0)
        {
            validation.Visible = true;
            labErrorMessage_Voltage.Visible = true;
            labErrorMessage_Voltage.Text    = "Błędnie wprowadzona wartość napięcia twornika";
            txtUt_m.BackColor = System.Drawing.Color.Red;
            flag = true;
        }

        /*pętla*/

        if (flag == true)
        {
            return;
        }
        else
        {
            labErrorMessage.Visible = true;
            labErrorMessage.Text    = "Dane zostały wprowadzone poprawnie";
            Chart1.Visible          = true;
        }

        this.mathModel = new MathModel(modelParams, modelParams.TimeStart, modelParams.InitCondit);
        this.solver    = new Solver(modelParams, mathModel);
        //---
        solver.SolverStart(modelParams);
        double[,] wyniki = solver.Results;

        //-- pierwsza tabela danych do wykresu 1

        table1 = new DataTable();
        //--
        DataColumn column1;
        DataRow    row1;

        //--
        column1            = new DataColumn();
        column1.DataType   = Type.GetType("System.Double");
        column1.ColumnName = "Torque";
        table1.Columns.Add(column1);

        column1            = new DataColumn();
        column1.DataType   = Type.GetType("System.Double");
        column1.ColumnName = "ω";
        table1.Columns.Add(column1);

        column1            = new DataColumn();
        column1.DataType   = Type.GetType("System.Double");
        column1.ColumnName = "ω przy Uan";
        table1.Columns.Add(column1);

        //----------------
        //int size_tmin = Convert.ToInt32(Tmin / delta);
        //labErrorMessage.Text = "jest to ilosc " + (int)size;

        double[,] array;

        for (int i = Tmin; i <= Tmax; i++)
        {
            array              = new double[Tmax + 1, 3];
            array[i, 0]        = i;
            array[i, 1]        = ((modelParams.Uarma / modelParams.Gaf * If) - (modelParams.Raint / Math.Pow(modelParams.Gaf * If, 2)) * i) * 10;
            array[i, 2]        = ((Ua / modelParams.Gaf * If) - (modelParams.Raint / Math.Pow(modelParams.Gaf * If, 2)) * i) * 10;
            row1               = table1.NewRow();
            row1["Torque"]     = array[i, 0];
            row1["ω"]          = array[i, 1];
            row1["ω przy Uan"] = array[i, 2];



            table1.Rows.Add(row1);
        }
        //--
        dView1 = new DataView(table1);
        //--
        Chart1.Series.Clear();
        Chart1.ChartAreas.Add("Wykres01");
        //--
        Chart1.DataBindTable(dView1, "Torque");
        Chart1.Width  = 900;
        Chart1.Height = 750;
        Chart1.Series["ω"].ChartType            = SeriesChartType.Line;
        Chart1.Series["ω"].BorderWidth          = 3; //grubosc wykresu
        Chart1.Series["ω przy Uan"].ChartType   = SeriesChartType.Line;
        Chart1.Series["ω przy Uan"].BorderWidth = 3; //grubosc wykresu


        //if (chkIcs.Checked)
        //{
        //    Chart1.Visible = true;
        //    Chart1.Series["Ics"].ChartType = SeriesChartType.Line;
        //    Chart1.Series["Ics"].BorderWidth = 3;//grubosc wykresu
        //}
        //Chart1.ChartAreas[0].AxisX.LineWidth = 2;
        Chart1.ChartAreas[0].AxisX.Minimum = 0;
        //Chart1.ChartAreas[0].AxisX.Maximum = (double)table1.Rows[size]["Torque"];
        //Chart1.ChartAreas[0].AxisY.Minimum = 0.0;
        Chart1.ChartAreas[0].AxisY.ArrowStyle = AxisArrowStyle.Lines;//strzałki wykresu
        //Chart1.ChartAreas[0].AxisX.ArrowStyle = AxisArrowStyle.Lines;
        Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "{#0.###}";
        Chart1.ChartAreas[0].AxisX.Title             = "Text [Nm]";
        Chart1.ChartAreas[0].AxisY.Title             = "ω [rad/s]";
        Chart1.ChartAreas[0].AxisX.TitleFont         = new System.Drawing.Font("Calibri", 11F, System.Drawing.FontStyle.Bold);
        Chart1.ChartAreas[0].AxisY.TitleFont         = new System.Drawing.Font("Calibri", 11F, System.Drawing.FontStyle.Bold);
    }
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     // Perform any additional setup after loading the view, typically from a nib.
     mathModel = new MathModel();
 }
Exemple #31
0
        public void Calc_ArgumentNullExceptions()
        {
            MathModel nullModel = null;

            Assert.ThrowsException <ArgumentNullException>(() => calculator.Calc(nullModel, 10));
        }