Example #1
0
 public MMAnalysisResults LoadResultsFromDisk()
 {
     generateOutputPath();
     Results = MMAnalysisResults.loadResultsFromFile(Path_resultsFile);
     //if (Results != null && Results.MD5String != GetMD5String())
     //    return null;
     return(Results);
 }
Example #2
0
        public void RunAnalysis()
        {
            if (Motor == null)
            {
                throw new InvalidOperationException("Motor hasn't been assigned");
            }

            if (!File.Exists(Motor.Path_FEMMFile))
            {
                log.Error("File doesn't exist: " + Motor.Path_FEMMFile);
                return;
            }

            // gen output path
            generateOutputPath();

            // create directory
            Directory.CreateDirectory(OutDir);

            // load results from disk
            MMAnalysisResults existedResults = MMAnalysisResults.loadResultsFromFile(Path_resultsFile);

            log.Info("Output results file:" + Path_resultsFile);
            // if has
            if (existedResults != null)
            {
                if (GetMD5String() == existedResults.MD5String)
                {
                    log.Info("M analysis already been done.");
                    Results = existedResults;
                    //OnFinishedAnalysis(this, Results);
                    return;
                }
                log.Info("M analysis exists but different. New analysis will be done.");
            }

            // create new
            Results           = new MMAnalysisResults(2 * StepCount + 1);
            Results.MD5String = GetMD5String();//assign md5 (signature of this)

            // steps numbering are put in queue for multi-thread
            Queue <int>    steps    = new Queue <int>();
            Queue <double> currents = new Queue <double>();

            for (int i = 0; i <= 2 * StepCount; i++)
            {
                if (i != StepCount)// meaning I=0
                {
                    steps.Enqueue(i);
                }
            }

            // for multi-thread config
            int threadCount = 4;

            ManualResetEvent[] MREs  = new ManualResetEvent[threadCount];
            FEMM[]             femms = new FEMM[threadCount];
            for (int i = 0; i < threadCount; i++)
            {
                MREs[i]  = new ManualResetEvent(false);
                femms[i] = new FEMM();
            }

            // calculate the first (I=0), to get FluxLinkageM
            AnalyzeOne(StepCount, femms[0]);

            // start all threads
            for (int i = 0; i < threadCount; i++)
            {
                ManualResetEvent mre  = MREs[i];
                FEMM             femm = femms[i];
                new Thread(delegate()
                {
                    while (steps.Count > 0)
                    {
                        AnalyzeOne(steps.Dequeue(), femm);
                    }

                    mre.Set();
                }).Start();
            }

            // wait for all thread to finish
            for (int i = 0; i < threadCount; i++)
            {
                MREs[i].WaitOne();
            }

            //create folder if needed
            Directory.CreateDirectory(OutDir);
            // save results data to disk
            Results.saveResultsToFile(Path_resultsFile);

            // finished event
            OnFinishedAnalysis(this, Results);
        }