コード例 #1
0
        public SimulationThread(ProjectHLK project, List <Simulation> simulations, HowLeakyOutputType outputType = HowLeakyOutputType.DailyBin)
        {
            var remapdict = BuildOutputsRemapDict(project.OutputsCSV.Split(',').ToList());

            OutputType = outputType;
            //    SQLiteFilename=Path.Combine(project.OutputsDirectory,$"Outputs.sqlite");
            HLEngine    = new HowLeakyEngine(project.OutputsCSV, remapdict);
            Simulations = simulations;
            Project     = project;
        }
コード例 #2
0
        //   public string SQLiteFilename{get;set;}

        public SimulationThread(ProjectHLK project, KeyValuePair <string, List <Simulation> > pair, HowLeakyOutputType outputType = HowLeakyOutputType.DailyBin)
        {
            var remapdict = BuildOutputsRemapDict(project.OutputsCSV.Split(',').ToList());

            OutputType = outputType;
            //    SQLiteFilename=Path.Combine(project.OutputsDirectory,$"{pair.Key}.sqlite");
            HLEngine    = new HowLeakyEngine(project.OutputsCSV, remapdict);
            Simulations = pair.Value;
            Project     = project;
        }
コード例 #3
0
        public void Execute(ProjectHLK project, CancellationTokenSource tokenSource, int cores, int?targetindex, HowLeakyOutputType outputType, GlobalProgress progress = null)
        {
            try
            {
                if (progress == null)
                {
                    Progress = new GlobalProgress(project.Simulations.Count);
                }
                else
                {
                    Progress = progress;
                }


                CancellationToken ct = tokenSource.Token;
                var simdict          = project.GroupedSimulations;

                ct.ThrowIfCancellationRequested();
                Progress.Max = targetindex == null?project.Simulations.Count:1;
                project.PrepareReferenceCounts();
                if (project.GroupedSimulations.Count() > 1)//cores)
                {
                    Parallel.ForEach(simdict.ToList(), new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = cores
                    }, simkeypair =>
                    {
                        var worker = new SimulationThread(project, simkeypair, outputType);
                        if (ct.IsCancellationRequested)
                        {
                            ct.ThrowIfCancellationRequested();
                        }
                        worker.Execute(Progress, ct);

                        Debug.WriteLine("");
                    });
                }
                else
                {
                    var climatedatasets = project.DataFiles.ToList();
                    foreach (var datafile in climatedatasets)
                    {
                        datafile.OpenFull();
                    }

                    var simulations = targetindex == null?project.Simulations:new List <Simulation>()
                    {
                        project.Simulations.FirstOrDefault(x => x.Index == (int)targetindex)
                    };

                    Parallel.ForEach(simulations, new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = cores
                    }, sim =>
                    {
                        var worker = new SimulationThread(project, new List <Simulation>()
                        {
                            sim
                        }, outputType);
                        if (ct.IsCancellationRequested)
                        {
                            ct.ThrowIfCancellationRequested();
                        }
                        worker.Execute(Progress, ct);
                    });
                }
            }
            catch (Exception ex)
            {
                throw ErrorLogger.CreateException(ex);
            }
        }
コード例 #4
0
ファイル: Simulation.cs プロジェクト: HowLeaky/HowLeaky-Core
 public Simulation(ProjectHLK project, string name)
 {
     Project     = project;
     ProjectName = name;
 }