Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();

            lua_state = LuaHelper.GetLuaState();

            projectManager = ProjectManager.GetInstance();
            projectManager.OnMotorAnalysisResultsUpdate += new EventHandler(projectManager_RequestRefreshUI);
            projectManager.loadStartupProject();

            form_motorParams           = new Form_MotorParams();
            form_motorParams.MdiParent = this;

            resultsWindow           = new ResultsWindow();
            resultsWindow.MdiParent = this;

            logwindow           = new LogWindow();
            logwindow.MdiParent = this;

            previewWindow           = new PreviewWindow();
            previewWindow.MdiParent = this;

            initMenu();
        }
        /// <summary>
        /// Analyze 1 step, using femm window
        /// </summary>
        /// <param name="data"></param>
        /// <param name="step"></param>
        /// <param name="femm"></param>
        private void AnalyzeOne(int step, FEMM femm = null)
        {
            if (femm == null)
            {
                femm = FEMM.DefaultFEMM;
            }

            double t          = Results.Times[step];
            double rotorAngle = RotorSpeedDegreeSecond * t + StartAngle;

            // run script to update IA,IB,IC
            NLua.Lua lua_state                   = LuaHelper.GetLuaState();
            String[] currentFormulas             = { IA, IB, IC };
            String[] circuitNames                = { "A", "B", "C" };
            Dictionary <String, double> currents = new Dictionary <string, double>();

            try
            {
                lua_state["step"]  = step;
                lua_state["time"]  = t;
                lua_state["omega"] = RotorSpeedRadSecond;

                for (int i = 0; i < currentFormulas.Length; i++)
                {
                    double Ix = (double)lua_state.DoString("return " + currentFormulas[i])[0];
                    currents[circuitNames[i]] = Ix;
                }
            }
            catch (Exception ex)
            {
                log.Error("Lua error :" + ex.Message);
                //TODO: maybe halt analysis since there maybe big problem
            }

            // open femm file
            femm.open(Motor.Path_FEMMFile);

            // clear the way (line-boundary conditional in airgap)
            Motor.Airgap.MakeWayInAirgapBeforeRotationInFEMM(femm);

            // normalize, make rotorAngle inside (-2alpha,2alpha)
            double xRotorAngle = rotorAngle;

            if (!Motor.GeneralParams.FullBuildFEMModel)
            {
                double alphax2 = 2 * Motor.Rotor.alphaDegree;
                if (xRotorAngle > alphax2 || xRotorAngle < -alphax2)
                {
                    xRotorAngle = xRotorAngle - Math.Round(xRotorAngle / (2 * alphax2)) * 2 * alphax2;
                }
            }

            // rotate rotor
            Motor.Rotor.RotateRotorInFEMM(xRotorAngle, femm);

            // modify airgap (in case partial build)
            Motor.Airgap.ModifyAirgapAfterRotationInFEMM(xRotorAngle, femm);

            // modify stator currents using args passed from OnBeginAnalyzeOne
            Motor.Stator.SetStatorCurrentsInFEMM(currents, femm);

            // save as new file fem (temp only)
            String stepfileFEM = OutDir + "\\" + String.Format("{0:D4}.FEM", step);

            femm.mi_saveas(stepfileFEM);

            // analyze
            femm.mi_analyze(true);

            // close
            femm.mi_close();

            // delete temp file
            //File.Delete(stepfileFEM);

            // open ans file to measure ?
            String stepfileANS = Path.GetDirectoryName(stepfileFEM) + "\\" + Path.GetFileNameWithoutExtension(stepfileFEM) + ".ans";

            femm.open(stepfileANS);

            //String bmpFile = config.OutDir + "\\bmp\\" + Path.GetFileNameWithoutExtension(stepfileFEM) + ".bmp";
            //femm.mo_savebitmap(bmpFile);

            // get circuits properties from stator
            TransientStepResult result = new TransientStepResult();

            Dictionary <String, FEMM.CircuitProperties> cps = Motor.Stator.getCircuitsPropertiesInAns(femm);
            double torque = Motor.Rotor.getTorqueInAns(femm);

            result.Torque            = torque;
            result.RotorAngle        = rotorAngle;
            result.CircuitProperties = cps;

            Results[step] = result;

            OnFinishAnalyzeOneStep(this, result);

            log.Info(String.Format("Time {0:F5}: {1}", t, torque));

            femm.mo_close();
        }