示例#1
0
 protected virtual void AppendTimeStep(DateTime Time)
 {
     if (_timeAxis != TimeAxisType.CalendarNonEquidistant & _currentTimeStep > 0)
     {
         TimeSteps.Add(Time);
     }
 }
示例#2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            double _sunheightDelta0_   = 40.00;
            double _sunheightDelta1_   = 50.00;
            double _timeStepInterval1_ = 2.00;
            double _timeStepInterval2_ = 2.00;
            double _timeStepInterval3_ = 1.00;

            DA.GetData(0, ref _sunheightDelta0_);
            DA.GetData(1, ref _sunheightDelta1_);
            DA.GetData(2, ref _timeStepInterval1_);
            DA.GetData(3, ref _timeStepInterval2_);
            DA.GetData(4, ref _timeStepInterval3_);

            TimeSteps timestepsSettings = new TimeSteps()
            {
                SunheightStep01 = _sunheightDelta0_,
                SunheightStep02 = _sunheightDelta1_,
                DtStep00        = _timeStepInterval1_,
                DtStep01        = _timeStepInterval2_,
                DtStep02        = _timeStepInterval3_
            };

            DA.SetData(0, timestepsSettings);
        }
示例#3
0
        /// <summary>
        /// Writes timestep and starttime
        /// </summary>
        protected void WriteTime()
        {
            if (!_initializedForWriting)
            {
                InitializeForWriting();
            }
            switch (_timeAxis)
            {
            case TimeAxisType.CalendarEquidistant:
                DfsDLLWrapper.dfsSetEqCalendarAxis(_headerPointer, TimeSteps.First().ToString("yyyy-MM-dd"), TimeSteps.First().ToString("HH:mm:ss"), (int)timeStepUnit, 0, _timeStep.TotalSeconds, 0);
                break;

            case TimeAxisType.CalendarNonEquidistant:
                DfsDLLWrapper.dfsSetNeqCalendarAxis(_headerPointer, TimeSteps.First().ToString("yyyy-MM-dd"), TimeSteps.First().ToString("HH:mm:ss"), (int)timeStepUnit, 0, 0);

                break;

            case TimeAxisType.TimeEquidistant:
                break;

            case TimeAxisType.TimeNonEquidistant:
                break;

            case TimeAxisType.Undefined:
                break;

            default:
                break;
            }
        }
示例#4
0
        /// <summary>
        /// Writes data for the TimeStep and Item
        /// </summary>
        /// <param name="TimeStep"></param>
        /// <param name="Item"></param>
        public void WriteItemTimeStep(int TimeStep, int Item, float[] data)
        {
            if (!_initializedForWriting)
            {
                InitializeForWriting();
            }

            if (_filePointer == IntPtr.Zero)
            {
                CreateFile();
            }

            MoveToItemTimeStep(TimeStep, Item);

            double time = 0;

            if (_timeAxis == TimeAxisType.CalendarNonEquidistant & _currentTimeStep > 0)
            {
                TimeSpan ts = TimeSteps[_currentTimeStep].Subtract(TimeSteps[0]);
                switch (timeStepUnit)
                {
                case TimeInterval.Second:
                    time = ts.TotalSeconds;
                    break;

                case TimeInterval.Minute:
                    time = ts.TotalMinutes;
                    break;

                case TimeInterval.Hour:
                    time = ts.TotalHours;
                    break;

                default:
                    break;
                }
            }

            if (EndOfFile)
            {
                if (_currentItem == NumberOfItems)
                {
                    NumberOfTimeStepsWritten++;
                }
                AppendTimeStep(TimeSteps.Last().Add(_timeStep));
            }

            //Writes the data
            DfsDLLWrapper.dfsWriteItemTimeStep(_headerPointer, _filePointer, time, data);
            IncrementItemTimeStep();
        }
示例#5
0
        /// <summary>
        /// Returns the zero-based index of the TimeStep closest to the TimeStamp. If the timestamp falls exactly between two timestep the smallest is returned.
        /// If the TimeStamp is before the first timestep 0 is returned.
        /// If the TimeStamp is after the last timestep the index of the last timestep is returned
        /// </summary>
        /// <param name="TimeStamp"></param>
        /// <returns></returns>
        public int GetTimeStep(DateTime TimeStamp)
        {
            if (TimeStamp < TimeSteps.First() || NumberOfTimeSteps == 1)
            {
                return(0);
            }
            int TimeStep;

            //fixed timestep
            if (_timeAxis == TimeAxisType.CalendarEquidistant)
            {
                TimeStep = (int)Math.Round(TimeStamp.Subtract(TimeSteps.First()).TotalSeconds / _timeStep.TotalSeconds, 0);
            }
            //Variabale timestep
            else
            {
                //Last timestep is known
                if (TimeStamp >= TimeSteps[NumberOfTimeSteps - 1])
                {
                    return(NumberOfTimeSteps - 1);
                }

                int i = 1;
                //Loop the timesteps
                while (TimeStamp > TimeSteps[i])
                {
                    i++;
                }
                //Check if last one was actually closer
                if (TimeSteps[i].Subtract(TimeStamp) < TimeStamp.Subtract(TimeSteps[i - 1]))
                {
                    return(i);
                }
                else
                {
                    return(i - 1);
                }
            }
            return(Math.Min(NumberOfTimeSteps - 1, TimeStep));
        }
示例#6
0
        /// <summary>
        /// Starts the export while suppressing the output and opens the first
        /// exported file in an external viewer.
        /// </summary>
        public void AndOpenYouMust()
        {
            Process process = PrepareProcess(CreateConfiguration(), PlotDirPath);

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardInput  = true;
            process.StartInfo.RedirectStandardOutput = true;

            Console.Write("Starting export (this may take a while)...");
            process.Start();

            // Try to find out when process stops writing data (without
            // resorting to threads...)
            bool probablyFinished = false;

            while (true)
            {
                Thread.Sleep(300);
                if (process.StandardOutput.Peek() == -1)
                {
                    if (probablyFinished)
                    {
                        break;
                    }
                    else
                    {
                        probablyFinished = true;
                    }
                }
                else
                {
                    process.StandardOutput.ReadLine();
                    probablyFinished = false;
                }
            }

            // Automated key-press
            process.StandardInput.WriteLine(true);
            if (process.WaitForExit(2000))
            {
                Console.WriteLine("Done.");
            }
            else
            {
                process.Kill();
                Console.WriteLine("The process did not end as expected and has been aborted");
            }

            if (process.ExitCode != 0)
            {
                return;
            }

            DirectoryInfo dir = new DirectoryInfo(PlotDirPath);

            FileInfo[] matchingFiles = dir.GetFiles("state_" + TimeSteps.First() + "*");

            if (matchingFiles.IsNullOrEmpty())
            {
                throw new Exception(
                          "Could not find plot file. This should not have happened");
            }

            FileInfo file = matchingFiles.OrderBy(f => f.CreationTime).Last();

            Console.WriteLine("Opening file in external viewer.");
            process = new Process();
            process.StartInfo.FileName = Path.Combine(file.DirectoryName, file.Name);
            process.Start();
        }
示例#7
0
        /// <summary>
        /// Sums the values of the items to the selected time interval and puts them in the new dfs file
        /// Assumes that the there are delete values at the same places in all items and timesteps!
        /// </summary>
        /// <param name="Items"></param>
        /// <param name="df"></param>
        /// <param name="SumTim"></param>
        public void MonthAggregation(int Item, DFSBase df)
        {
            SortedList <int, float[]> SumBuffer    = new SortedList <int, float[]>();
            SortedList <int, float[]> MaxBuffer    = new SortedList <int, float[]>();
            SortedList <int, float[]> MinBuffer    = new SortedList <int, float[]>();
            Dictionary <int, int>     TstepCounter = new Dictionary <int, int>();


            df.Items[0].Name    = "MonthlyAverage";
            df.items[0].EumItem = this.Items[Item - 1].EumItem;
            df.Items[1].Name    = "MonthlyMax";
            df.items[1].EumItem = this.Items[Item - 1].EumItem;
            df.Items[2].Name    = "MonthlyMin";
            df.items[2].EumItem = this.Items[Item - 1].EumItem;


            //Initialize arrays
            foreach (var month in TimeSteps.Select(t => t.Month).Distinct())
            {
                TstepCounter.Add(month, 0);
                SumBuffer.Add(month, new float[dfsdata.Count()]);
                MaxBuffer.Add(month, new float[dfsdata.Count()]);
                MinBuffer.Add(month, new float[dfsdata.Count()]);
                //Set everything to delete values
                for (int i = 0; i < dfsdata.Count(); i++)
                {
                    SumBuffer[month][i] = (float)DeleteValue;
                    MaxBuffer[month][i] = (float)DeleteValue;
                    MinBuffer[month][i] = (float)DeleteValue;
                }
                ReadItemTimeStep(0, Item);
                foreach (var k in NonDeleteIndex)
                {
                    SumBuffer[month][k] = 0;
                    MaxBuffer[month][k] = float.MinValue;
                    MinBuffer[month][k] = float.MaxValue;
                }
            }


            //Loop the time steps
            for (int i = 0; i < NumberOfTimeSteps; i++)
            {
                int currentmonth = TimeSteps[i].Month;
                ReadItemTimeStep(i, Item);

                TstepCounter[currentmonth] += 1;

                foreach (var k in NonDeleteIndex)
                {
                    SumBuffer[currentmonth][k] += dfsdata[k];
                    if (dfsdata[k] != (float)DeleteValue)
                    {
                        MaxBuffer[currentmonth][k] = Math.Max(MaxBuffer[currentmonth][k], dfsdata[k]);
                        MinBuffer[currentmonth][k] = Math.Min(MinBuffer[currentmonth][k], dfsdata[k]);
                    }
                }
            }

            //Go from sum to average
            for (int i = 0; i < SumBuffer.Count; i++)
            {
                foreach (var k in NonDeleteIndex)
                {
                    SumBuffer.Values[i][k] /= TstepCounter[SumBuffer.Keys[i]];
                }

                df.WriteItemTimeStep(i, 1, SumBuffer.Values[i]);
                df.WriteItemTimeStep(i, 2, MaxBuffer.Values[i]);
                df.WriteItemTimeStep(i, 3, MinBuffer.Values[i]);
            }
        }
示例#8
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            MainSettings         _mainSettings  = null;
            List <Configuration> otherSettings_ = new List <Configuration> ();
            bool _runIt = false;

            DA.GetData(0, ref _mainSettings);
            DA.GetDataList(1, otherSettings_);
            DA.GetData(2, ref _runIt);

            SimpleForcingSettings simpleForcingSettings = null;
            TThread          tThread          = null;
            TimeSteps        timeSteps        = null;
            ModelTiming      modelTiming      = null;
            SoilConfig       soilConfig       = null;
            Sources          sources          = null;
            Turbulence       turbulence       = null;
            OutputSettings   outputSettings   = null;
            Cloud            cloud            = null;
            Background       background       = null;
            SolarAdjust      solarAdjust      = null;
            BuildingSettings buildingSettings = null;
            IVS          ivs          = null;
            ParallelCPU  parallelCPU  = null;
            SOR          sor          = null;
            InflowAvg    inflowAvg    = null;
            Facades      facades      = null;
            PlantSetting plantSetting = null;
            LBC          lbc          = null;
            FullForcing  fullForcing  = null;

            if (_runIt)
            {
                try
                {
                    foreach (Configuration o in otherSettings_)
                    {
                        Type obj = o.GetType();

                        if (obj == typeof(SimpleForcingSettings))
                        {
                            simpleForcingSettings = o as SimpleForcingSettings;
                        }
                        else if (obj == typeof(TThread))
                        {
                            tThread = o as TThread;
                        }
                        else if (obj == typeof(TimeSteps))
                        {
                            timeSteps = o as TimeSteps;
                        }
                        else if (obj == typeof(ModelTiming))
                        {
                            modelTiming = o as ModelTiming;
                        }
                        else if (obj == typeof(SoilConfig))
                        {
                            soilConfig = o as SoilConfig;
                        }
                        else if (obj == typeof(Sources))
                        {
                            sources = o as Sources;
                        }
                        else if (obj == typeof(Turbulence))
                        {
                            turbulence = o as Turbulence;
                        }
                        else if (obj == typeof(OutputSettings))
                        {
                            outputSettings = o as OutputSettings;
                        }
                        else if (obj == typeof(Cloud))
                        {
                            cloud = o as Cloud;
                        }
                        else if (obj == typeof(Background))
                        {
                            background = o as Background;
                        }
                        else if (obj == typeof(SolarAdjust))
                        {
                            solarAdjust = o as SolarAdjust;
                        }
                        else if (obj == typeof(BuildingSettings))
                        {
                            buildingSettings = o as BuildingSettings;
                        }
                        else if (obj == typeof(IVS))
                        {
                            ivs = o as IVS;
                        }
                        else if (obj == typeof(ParallelCPU))
                        {
                            parallelCPU = o as ParallelCPU;
                        }
                        else if (obj == typeof(SOR))
                        {
                            sor = o as SOR;
                        }
                        else if (obj == typeof(InflowAvg))
                        {
                            inflowAvg = o as InflowAvg;
                        }
                        else if (obj == typeof(Facades))
                        {
                            facades = o as Facades;
                        }
                        else if (obj == typeof(PlantSetting))
                        {
                            plantSetting = o as PlantSetting;
                        }
                        else if (obj == typeof(LBC))
                        {
                            lbc = o as LBC;
                        }
                        else if (obj == typeof(FullForcing))
                        {
                            fullForcing = o as FullForcing;
                        }
                    }


                    Simx simx = new Simx(_mainSettings)
                    {
                        SimpleForcing    = simpleForcingSettings,
                        TThread          = tThread,
                        TimeSteps        = timeSteps,
                        ModelTiming      = modelTiming,
                        SoilSettings     = soilConfig,
                        Sources          = sources,
                        Turbulence       = turbulence,
                        OutputSettings   = outputSettings,
                        Cloud            = cloud,
                        Background       = background,
                        SolarAdjust      = solarAdjust,
                        BuildingSettings = buildingSettings,
                        IVS          = ivs,
                        ParallelCPU  = parallelCPU,
                        SOR          = sor,
                        InflowAvg    = inflowAvg,
                        Facades      = facades,
                        PlantSetting = plantSetting,
                        LBC          = lbc,
                        FullForcing  = fullForcing
                    };

                    simx.WriteSimx();
                    DA.SetData(0, Path.Combine(Path.GetDirectoryName(_mainSettings.Inx), _mainSettings.Name + ".simx"));
                }
                catch
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Please provide a valid mainSettings.");
                }
            }
        }