Exemple #1
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)
        {
            // INPUT
            // declaration
            string simName_        = null;
            string _INXfileAddress = null;
            string startDate_      = null;
            string startTime_      = null;

            int    simDuration_        = 0;
            double windSpeed_          = 0;
            double windDirection_      = 0;
            double roughness_          = 0;
            double initialTemperature_ = 0;
            double specificHumidity_   = 0;
            double relativeHumidity_   = 0;

            DA.GetData(0, ref simName_);
            DA.GetData(1, ref _INXfileAddress);
            DA.GetData(2, ref startDate_);
            DA.GetData(3, ref startTime_);
            DA.GetData(4, ref simDuration_);
            DA.GetData(5, ref windSpeed_);
            DA.GetData(6, ref windDirection_);
            DA.GetData(7, ref roughness_);
            DA.GetData(8, ref initialTemperature_);
            DA.GetData(9, ref specificHumidity_);
            DA.GetData(10, ref relativeHumidity_);

            // actions
            envimetSimulationFile.MainSettings baseSetting = new envimetSimulationFile.MainSettings()
            {
                SimName            = simName_,
                INXfileAddress     = _INXfileAddress,
                StartDate          = startDate_,
                StartTime          = startTime_,
                SimDuration        = simDuration_,
                WindSpeed          = windSpeed_,
                WindDir            = windDirection_,
                Roughness          = roughness_,
                InitialTemperature = initialTemperature_ + 273.15,
                SpecificHumidity   = specificHumidity_,
                RelativeHumidity   = relativeHumidity_
            };

            // OUTPUT
            DA.SetData(0, baseSetting);
        }
Exemple #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)
        {
            // INPUT
            // declaration
            List <double> _dryBulbTemperature = new List <double>();
            List <double> _relativeHumidity   = new List <double>();

            bool parallel_ = false;
            bool _runIt    = false;

            envimetSimulationFile.MainSettings          baseSetting   = new envimetSimulationFile.MainSettings();
            envimetSimulationFile.SampleForcingSettings simpleForcing = new envimetSimulationFile.SampleForcingSettings(_dryBulbTemperature, _relativeHumidity);

            DA.GetData(0, ref baseSetting);
            DA.GetData(1, ref simpleForcing);
            DA.GetData(2, ref parallel_);
            DA.GetData(3, ref _runIt);

            // action
            // preparation
            var    now          = DateTime.Now;
            string revisionDate = now.ToString("yyyy.MM.dd HH:mm:ss");
            string destination  = System.IO.Path.GetDirectoryName(baseSetting.INXfileAddress);
            string fileName     = System.IO.Path.Combine(destination, baseSetting.SimName + ".simx");

            string[] empty = { };
            int      simulationDuration = (simpleForcing.TotNumbers != 0) ? simpleForcing.TotNumbers : baseSetting.SimDuration;

            if (_runIt)
            {
                XmlTextWriter xWriter = new XmlTextWriter(fileName, Encoding.UTF8);

                // root
                xWriter.WriteStartElement("ENVI-MET_Datafile");
                xWriter.WriteString("\n ");

                // contents
                // Header section
                string   headerTitle = "Header";
                string[] headerTag   = new string[] { "filetype", "version", "revisiondate", "remark", "encryptionlevel" };
                string[] headerValue = new string[] { "SIMX", "1", revisionDate, "Created with lb_envimet", "0" };

                WriteINX.xmlSection(xWriter, headerTitle, headerTag, headerValue, 0, empty);


                // Main section
                string   mainTitle = "mainData";
                string[] mainTag   = new string[] { "simName", "INXFile", "filebaseName", "outDir", "startDate", "startTime", "simDuration", "windSpeed", "windDir", "z0", "T_H", "Q_H", "Q_2m" };
                string[] mainValue = new string[]
                { baseSetting.SimName,
                  baseSetting.INXfileAddress,
                  baseSetting.SimName,
                  " ",
                  baseSetting.StartDate,
                  baseSetting.StartTime,
                  simulationDuration.ToString(),
                  baseSetting.WindSpeed.ToString(),
                  baseSetting.WindDir.ToString(),
                  baseSetting.Roughness.ToString(),
                  baseSetting.InitialTemperature.ToString(),
                  baseSetting.SpecificHumidity.ToString(),
                  baseSetting.RelativeHumidity.ToString() };

                WriteINX.xmlSection(xWriter, mainTitle, mainTag, mainValue, 0, empty);


                // SimpleForcing section
                if (simpleForcing.TotNumbers != 0)
                {
                    string   sfTitle = "SimpleForcing";
                    string[] sfTag   = new string[] { "TAir", "Qrel" };
                    string[] sfValue = new string[] { simpleForcing.Temperature, simpleForcing.RelativeHumidity };

                    WriteINX.xmlSection(xWriter, sfTitle, sfTag, sfValue, 0, empty);
                }


                // Parallel section
                if (parallel_)
                {
                    string   parallelTitle = "Parallel";
                    string[] parallelTag   = new string[] { "CPUdemand" };
                    string[] parallelValue = new string[] { "ALL" };

                    WriteINX.xmlSection(xWriter, parallelTitle, parallelTag, parallelValue, 0, empty);
                }


                // close root and file
                xWriter.WriteEndElement();
                xWriter.Close();

                DA.SetData(0, fileName);
            }
        }