Example #1
0
        /// <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;
            }

            if (SkewAngle <= 0 || NSkewSegment <= 0)
            {
                // prepare arguments for this step
                TransientStepArgs args = PrepareStepArgs(step);

                // before analyzing
                OnStartAnalyzeOneStep(this, args);

                // open femm file
                femm.open(Path_OriginalFEMFile);

                // modify rotor: rotate, or other things that we can think of
                DoModifyRotor(args, femm);

                // modify stator: change current, or something else?
                DoModifyStator(args, femm);

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

                // analyze
                femm.mi_analyze(true);

                // close
                femm.mi_close();

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

                // do measure torque or anything else
                DoMeasureData(args, femm);

                // put in the list
                var Results = this.Results as Transient3PhaseMotorResults;
                Results[step] = args;

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

                // save as bitmap
                if (ExportGif)
                {
                    femm.mo_clearblock();
                    femm.mo_zoom(0, -Motor.Stator.RYoke, Motor.Stator.RYoke, Motor.Stator.RYoke);
                    femm.mo_showdensityplot(true, false, 0, 2.1, FEMM.DensityPlotType.bmag);
                    femm.mo_savebitmap(Path.GetDirectoryName(stepfileFEM) + "\\" + Path.GetFileNameWithoutExtension(stepfileFEM) + ".bmp");
                }

                // close
                femm.mo_close();

                // after analyzing
                OnFinishAnalyzeOneStep(this, args);
            }
            else // has skewangle
            {
                // prepare arguments for this step
                TransientStepArgs total_args = PrepareStepArgs(step);

                // before analyzing
                OnStartAnalyzeOneStep(this, total_args);

                for (int k = 0; k < 2 * NSkewSegment + 1; k++)
                {
                    TransientStepArgs args = PrepareStepArgs(step);
                    double            sk   = (k - NSkewSegment) * SkewAngle / (2 * NSkewSegment);
                    args.skewAngleAdded = sk;
                    args.RotorAngle    += sk;

                    // open femm file
                    femm.open(Path_OriginalFEMFile);

                    // modify rotor: rotate, or other things that we can think of
                    DoModifyRotor(args, femm);

                    // modify stator: change current, or something else?
                    DoModifyStator(args, femm);

                    // save as new file fem (temp only)
                    String stepfileFEM = Path_ToAnalysisVariant + "\\" + String.Format("{0:D4}_{1}.FEM", step, k);
                    femm.mi_saveas(stepfileFEM);

                    // analyze
                    femm.mi_analyze(true);

                    // close
                    femm.mi_close();

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

                    // do measure torque or anything else
                    DoMeasureData(args, femm);

                    // initialize data for total
                    if (k == 0)
                    {
                        total_args        = JSON.DeepCopy(args);
                        total_args.Torque = 0;
                        foreach (string key in total_args.CircuitProperties.Keys)
                        {
                            total_args.CircuitProperties[key].fluxlinkage = 0;
                        }
                    }

                    femm.mo_close();

                    total_args.Torque += args.Torque / (2 * NSkewSegment + 1);
                    foreach (string key in total_args.CircuitProperties.Keys)
                    {
                        total_args.CircuitProperties[key].fluxlinkage += args.CircuitProperties[key].fluxlinkage / (2 * NSkewSegment + 1);
                    }
                }

                // put in the list
                var Results = this.Results as Transient3PhaseMotorResults;
                Results[step] = total_args;

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

                // after analyzing
                OnFinishAnalyzeOneStep(this, total_args);
            }
        }