Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
        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);
            }
        }
Exemplo n.º 4
0
 public Simulation(ProjectHLK project, string name)
 {
     Project     = project;
     ProjectName = name;
 }