Esempio n. 1
0
 private void ComponentsToNewParams()
 {
     // create params collection from this sample motor/trans-analysis
     MotorParams = new ParametersCollection();
     foreach (String name in Components.Keys)
     {
         MotorParams.AddRange(ParametersCollection.FromObject(name, Components[name]));
     }
 }
Esempio n. 2
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeView       tv   = (TreeView)sender;
            ProjectManager pm   = ProjectManager.GetInstance();
            String         item = e.Node.FullPath;

            ParametersCollection pc = new ParametersCollection();

            pc.AddRange(pm.MotorParams.Where(pi => pi.group == item));
            showInputParamsInDGV(dgv_motorParams, pc);

            currentPath = e.Node.FullPath;
            currentNode = e.Node;

            this.Text = currentPath;
        }
        public static ParametersCollection FromJSON(String str)
        {
            Parameter[]          list = JSON.ToObject <Parameter[]>(str);
            ParametersCollection pc   = new ParametersCollection();

            pc.AddRange(list);
            foreach (Parameter p in pc)
            {
                if (p.value != null)
                {
                    if (p.value.GetType() != p.valueType) // p.value can be Jsonxxx type
                    {
                        p.value = JSON.ToObject(p.value.ToString(), p.valueType);
                    }
                }
            }

            return(pc);
        }
Esempio n. 4
0
        public ParametersCollection MotorToParams(AbstractMotor motor)
        {
            // Parameters from motor
            Dictionary <String, object> objs = new Dictionary <string, object>();

            objs.Add("Motor\\General(" + motor.GeneralParams.GetType().Name + ")", motor.GeneralParams);
            objs.Add("Motor\\Rotor(" + motor.Rotor.GetType().Name + ")", motor.Rotor);
            objs.Add("Motor\\Stator(" + motor.Stator.GetType().Name + ")", motor.Stator);
            //objs.Add("Motor\\Materials", motor.MaterialParams);
            objs.Add("Motor\\Airgap(" + motor.Airgap.GetType().Name + ")", motor.Airgap);

            ParametersCollection motorParams = new ParametersCollection();

            foreach (String objname in objs.Keys)
            {
                motorParams.AddRange(ParametersCollection.FromObject(objname, objs[objname]));
            }

            return(motorParams);
        }
Esempio n. 5
0
        public void doSweep()
        {
            // update ID and MD5 in params table before do sweep
            updateID_MD5_inParamsTable();

            // copy params from original
            ParametersCollection swParams = MotorToParams(CurrentMotor);

            // new result table
            ResultsTable           = new DataTable();
            ResultsTable.TableName = RESULTS_TABLE;

            ResultsTable.Columns.Add(COL_ID, typeof(int));
            ResultsTable.Columns.Add(COL_MD5, typeof(string));
            ResultsTable.Columns.Add(COL_STATUS, typeof(string));
            bool newlyTable = true;

            // apply sweeping param from table
            // each variant
            foreach (DataRow paramRow in ParamsTable.Rows)
            {
                int variantNum = ParamsTable.Rows.IndexOf(paramRow);
                // update params from this row (variant)
                foreach (DataColumn dc in ParamsTable.Columns)
                {
                    String colname = dc.ColumnName;
                    foreach (Parameter p in swParams)
                    {
                        if (p.fullname == colname)
                        {
                            p.text = paramRow[colname].ToString();
                            p.EvaluateValue();
                            break;
                        }
                    }
                }

                // create new motor from parameters
                AbstractMotor motor = ParamsToMotor(swParams);

                // motor calculation
                motor.CalcPointsCoordinates();

                // if params invalid, just move on
                if (!motor.IsParamsValid())
                {
                    log.Error(String.Format("Variant {0} invalid:", variantNum));
                    paramRow[COL_STATUS] = "Error: ";
                    foreach (ParamValidationInfo pvi in motor.ListParamsValidation)
                    {
                        if (pvi.msgType == ParamValidationInfo.MessageType.Error)
                        {
                            log.Error("\t+ " + pvi.message);
                        }

                        //update error in param row
                        paramRow[COL_STATUS] += pvi.message + "; ";
                    }

                    //resultRow also
                    DataRow rr = ResultsTable.NewRow();
                    rr[COL_ID]     = paramRow[COL_ID];
                    rr[COL_MD5]    = paramRow[COL_MD5];
                    rr[COL_STATUS] = paramRow[COL_STATUS];
                    ResultsTable.Rows.Add(rr);

                    continue;
                }
                else
                {
                    paramRow[COL_STATUS] = "OK";
                }

                //// organize results
                ParametersCollection pc = new ParametersCollection();

                // calc gmc
                AbstractAnalyticalAnalyser aa = motor.GetAnalyticalAnalyser();
                aa.RunAnalysis();
                pc.AddRange(ParametersCollection.FromObject("analytic", aa.Results));

                // femm
                if (EnableFEMAnalysis)
                {
                    String outdir  = OutputFolder;
                    String femFile = outdir + "\\" + motor.GetMD5String() + ".FEM";
                    Directory.CreateDirectory(outdir);
                    if (!motor.isFEMModelReady(femFile))
                    {
                        motor.BuildFEMModel(femFile);
                    }

                    AbstractStaticAnalyser staticAnalyser = motor.GetStaticAnalyser();
                    staticAnalyser.Path_OriginalFEMFile        = femFile;
                    staticAnalyser.OutputPath                  = outdir;
                    staticAnalyser.DoAnalysisOnOriginalFEMFile = true;
                    staticAnalyser.RunAnalysis();
                    pc.AddRange(ParametersCollection.FromObject("fem", staticAnalyser.Results));
                }
                Dictionary <String, int> countsParam = new Dictionary <string, int>();

                // find params match by name between analytic and fem
                foreach (Parameter p in pc)
                {
                    if (countsParam.ContainsKey(p.name))
                    {
                        countsParam[p.name]++;
                    }
                    else
                    {
                        countsParam[p.name] = 1;
                    }
                }
                // add comparison columns
                foreach (String name in countsParam.Keys)
                {
                    if (countsParam[name] == 2)
                    {
                        Parameter p = new Parameter();
                        p.group = "xCompare";
                        p.name  = name;
                        double d1 = (double)pc.FindParameter("analytic", name).value;
                        double d2 = (double)pc.FindParameter("fem", name).value;
                        p.value     = String.Format("{0:F3}%", (d1 - d2) / d2 * 100.0);
                        p.valueType = typeof(String);
                        pc.Add(p);
                    }
                }

                // sort columns
                pc = new ParametersCollection(pc.OrderBy(param => param.name).ThenBy(param => param.group).ToList());

                // 1 times create
                if (newlyTable)
                {
                    foreach (Parameter p in pc)
                    {
                        if (!p.valueType.IsArray)//don't care about array (airgap flux-density distribution) for now
                        {
                            ResultsTable.Columns.Add(p.fullname, p.valueType);
                        }
                    }

                    newlyTable = false;
                }

                // assign this variant results to row of results table
                DataRow resultRow = ResultsTable.NewRow();
                foreach (Parameter p in pc)
                {
                    if (resultRow.Table.Columns.Contains(p.fullname))
                    {
                        resultRow[p.fullname] = p.value;
                    }
                }
                resultRow[COL_ID]     = paramRow[COL_ID];
                resultRow[COL_MD5]    = paramRow[COL_MD5];
                resultRow[COL_STATUS] = paramRow[COL_STATUS];
                ResultsTable.Rows.Add(resultRow);
            }// for each variant

            // raise event
            ParamSweeperResults r = new ParamSweeperResults();

            r.ResultsTable = ResultsTable;
            OnFinishSweep(this, r);

            saveDataToDisk();
        }