public static List <UmiObject> ContextBuildings(UmiContext umiContext, RhinoDoc doc)
        {
            var selection = new BuildingGetter().GetSelectedBuildings(
                doc,
                umiContext.Buildings.Visible).ToArray();

            var idList = selection.Any()
                ? selection.Select(building => building.Id.ToString()).ToList()
                : umiContext.Buildings.Visible.Select(building => building.Id.ToString()).ToList();
            // var idList = umiContext.Buildings.Visible.Select(building => building.Id.ToString()).ToList();
            // Getting the Aggregated Load Curve for all buildings
            var contextBuildings =
                umiContext.GetObjects()
                .Where(o => o.Data.Any(x => x.Value.Resolution == "Hour") && idList.Contains(o.Id)).ToList();
            var buttons = MessageBoxButton.YesNo;

            if (contextBuildings.Count == 0)
            {
                var result = MessageBox.Show(
                    "There are no buildings with hourly results. Would you like to run an hourly energy simulation now?",
                    "Cannot continue with District simulation", buttons);
                if (result == MessageBoxResult.Yes)
                {
                    // Sets hourly results true and calls UMISimulateEnergy
                    umiContext.ProjectSettings.GenerateHourlyEnergyResults = true;
                    RhinoApp.RunScript("-UmiSimulateEnergy", true);
                }
                else
                {
                    throw new Exception("Canceled by user");
                }
            }

            return(contextBuildings);
        }
Exemple #2
0
        public override void GetUmiLoads(List <UmiObject> contextObjects, UmiContext umiContext)
        {
            RhinoApp.WriteLine("Getting all Buildings and aggregating cooling loads");

            Input = contextObjects.Select(umiObject =>
                                          umiObject.Data["SDL/Cooling"].Data.Select(o => o * umiContext.Buildings
                                                                                    .TryGet(Guid.Parse(umiObject.Id))
                                                                                    .Template.Perimeter.Conditioning.CoolingCoeffOfPerf))
                    .Aggregate((sum, val) => sum.Zip(val, (a, b) => a + b)).ToArray();
        }
        public static void GetHourlyLocationWind(UmiContext context)
        {
            RhinoApp.WriteLine("Calculating wind for location...");
            var a = new EPWeatherData();

            a.GetRawData(context.WeatherFilePath);
            var wind = a.HourlyWeatherDataRawList.Select(b => (double)b.WindSpeed);

            RhinoApp.WriteLine("Completed wind");
            WindSpeed = wind;
        }
Exemple #4
0
        private void SaveSettings(UmiContext e)
        {
            var context = e;

            if (context == null)
            {
                return;
            }
            var dSjson = SerializeToString(DistrictControl.Instance.ListOfPlantSettings);

            context.AuxiliaryFiles.StoreText("ThermalPlantSettings.json", dSjson);
        }
        public static void GetHourlyLocationSolarRadiation(UmiContext context)
        {
            RhinoApp.WriteLine("Calculating Solar Radiation on horizontal surfaces...");
            var a = new EPWeatherData();

            a.GetRawData(context.WeatherFilePath);
            var radiation = a.HourlyWeatherDataRawList.Select(b => (double)b.GHorRadiation / 1000.0);

            RhinoApp.WriteLine("Completed Solar Radiation");
            SolarNormalRadiation = radiation;
            // return radiation; // from Wh to kWh
        }
Exemple #6
0
 private void PopulateFrom(object sender, UmiContext e)
 {
     try
     {
         LoadSettings(e);
     }
     catch (Exception exception)
     {
         RhinoApp.WriteLine(exception.Message);
         //throw new ArgumentException("A project settings viewmodel cannot be instantiated from a project with no instantiated settings object");
     }
 }
        private void SaveSettings(UmiContext e)
        {
            var context = e;

            if (context == null)
            {
                return;
            }

            var pSjson = JsonConvert.SerializeObject(DistrictControl.PlanningSettings);

            context.AuxiliaryFiles.StoreText("planningSettings.json", pSjson);
        }
 public override void GetUmiLoads(List <UmiObject> contextObjects, UmiContext umiContext)
 {
     RhinoApp.WriteLine("Getting all Buildings and aggregating hot water loads");
     Input = contextObjects.Select(umiObject =>
                                   umiObject.Data["SDL/Heating"].Data
                                   .Zip(
                                       umiObject.Data["SDL/Domestic Hot Water"].Data.Count == 0
                         ? new double[8760]
                         : umiObject.Data["SDL/Domestic Hot Water"].Data, (x, y) => x * umiContext
                                       .Buildings.TryGet(Guid.Parse(umiObject.Id)).Template.Perimeter
                                       .Conditioning.HeatingCoeffOfPerf + y))
             .Aggregate((sum, val) => sum.Zip(val, (a, b) => a + b)).ToArray();
 }
Exemple #9
0
        public override void GetUmiLoads(List <UmiObject> contextObjects, UmiContext umiContext)
        {
            RhinoApp.WriteLine("Getting all Buildings and aggregating electrical loads: SDL/Equipment + SDL/Lighting");

            Input = contextObjects.Select(umiObject =>
                                          (umiObject.Data["SDL/Equipment"].Data.Count == 0
                        ? new double[8760]
                        : umiObject.Data["SDL/Equipment"].Data)
                                          .Zip(umiObject.Data["SDL/Lighting"].Data.Count == 0
                        ? new double[8760]
                        : umiObject.Data["SDL/Lighting"].Data, (x, y) => x + y))
                    .Aggregate((sum, val) => sum.Zip(val, (a, b) => a + b)).ToArray();
        }
Exemple #10
0
        /// <summary>
        ///     Reads a CSV file with 3 columns.
        /// </summary>
        /// <param name="filePath">The path to the csv file</param>
        /// <param name="context"></param>
        /// <param name="refId"></param>
        /// <returns></returns>
        public static void AddAdditionalLoad(string filePath, UmiContext context, Guid refId)
        {
            // Start stream reader
            using (var reader = new StreamReader(filePath))
            {
                // Using CSV reader class
                using (var csv = new CsvReader(reader, CultureInfo.CurrentCulture))
                {
                    ICollection <IUmiObject> records = new Collection <IUmiObject>();
                    const string             name    = "Additional Loads";
                    var record = new UmiAdditionalLoad
                    {
                        Name     = name, //Path.GetFileName(filePath),
                        Id       = refId.ToString(),
                        Data     = new Dictionary <string, UmiDataSeries>(),
                        FilePath = filePath
                    };


                    foreach (var type in DHLoadAdditionalProfile.Types)
                    {
                        var seriesName = $"Additional {type} Load";
                        record.Data[seriesName] = new UmiDataSeries
                        {
                            Name       = seriesName,
                            Units      = "kWh",
                            Resolution = "Hourly",
                            Data       = new List <double>()
                        };
                    }

                    // Actual reading of the columns
                    csv.Read();
                    csv.ReadHeader();
                    while (csv.Read())
                    {
                        // Iterate over 3 columns
                        foreach (var type in DHLoadAdditionalProfile.Types)
                        {
                            var value = csv.GetField <double>(type);
                            record.Data[$"Additional {type} Load"].Data.Add(value);
                        }
                    }

                    records.Add(record);
                    context.StoreObjects(records);
                }
            }
        }
Exemple #11
0
        /// <summary>
        ///     Reads a CSV file with 3 columns.
        /// </summary>
        /// <param name="filePath">The path to the csv file</param>
        /// <param name="context"></param>
        /// <returns></returns>
        private static double[] LoadCustomDemand(string filePath, UmiContext context)
        {
            // Start stream reader
            double[] records;
            using (var reader = new StreamReader(filePath))
            {
                using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                {
                    csv.Configuration.HasHeaderRecord = false;
                    records = csv.GetRecords <double>().ToArray();
                }
            }

            return(records);
        }
        private void LoadSettings(UmiContext context)
        {
            if (context == null)
            {
                return;
            }

            var path = context.AuxiliaryFiles.GetFullPath("planningSettings.json");

            if (File.Exists(path))
            {
                var json = File.ReadAllText(path);
                DistrictControl.PlanningSettings = JsonConvert.DeserializeObject <PlanningSettings>(json);
            }

            UseDistrictLosses = DistrictControl.PlanningSettings.UseDistrictLosses;
            RelDistCoolLoss   = DistrictControl.PlanningSettings.RelDistCoolLoss * 100;
            RelDistHeatLoss   = DistrictControl.PlanningSettings.RelDistHeatLoss * 100;
            OnPropertyChanged(string.Empty);
        }
Exemple #13
0
        private void LoadSettings(UmiContext context)
        {
            if (context == null)
            {
                return;
            }
            var path = context.AuxiliaryFiles.GetFullPath("ThermalPlantSettings.json");

            if (File.Exists(path))
            {
                var json = File.ReadAllText(path);
                DistrictControl.Instance.ListOfPlantSettings = DeserializeFromString(json);

                if (!DistrictControl.Instance.ListOfPlantSettings.OfType <GridElectricity>().Any())
                {
                    DistrictControl.Instance.ListOfPlantSettings.Add(new GridElectricity());
                }

                if (!DistrictControl.Instance.ListOfPlantSettings.OfType <GridGas>().Any())
                {
                    DistrictControl.Instance.ListOfPlantSettings.Add(new GridGas());
                }
                if (!DistrictControl.Instance.ListOfPlantSettings.OfType <ElectricityExport>().Any())
                {
                    DistrictControl.Instance.ListOfPlantSettings.Add(new ElectricityExport());
                }
                if (!DistrictControl.Instance.ListOfPlantSettings.OfType <CoolingExport>().Any())
                {
                    DistrictControl.Instance.ListOfPlantSettings.Add(new CoolingExport());
                }
                if (!DistrictControl.Instance.ListOfPlantSettings.OfType <HeatingExport>().Any())
                {
                    DistrictControl.Instance.ListOfPlantSettings.Add(new HeatingExport());
                }
            }

            OnPropertyChanged(string.Empty);
        }
        public override Result Run(RhinoDoc doc, UmiContext context, RunMode mode)
        {
            var maxHeatinLoadQuery = context.GetObjects().
                                     Select(b => new
                                            { BuildingId = b.Id, MaxLoad = MaxHeatingLoad(b), AverageLoad = AverageHeatingLoad(b) });

            List <double> cap = new List <double>();

            foreach (var a in maxHeatinLoadQuery)
            {
                try
                {
                    cap.Add(Metrics.CalcCapacityFactor(a.AverageLoad, a.MaxLoad));
                }
                catch (DivideByZeroException e)
                {
                    Console.WriteLine(e.Message);
                    throw;
                }
            }


            return(Result.Success);
        }
Exemple #15
0
 private void LoadThis(object sender, UmiContext e)
 {
     PlantSettingsViewModel.Instance.PropertyChanged += LoadThis;
 }
Exemple #16
0
 private void SubscribeEvents(object sender, UmiContext e)
 {
     DhRunLpModel.Instance.Completion += UpdateCarbonChart;
 }
Exemple #17
0
 public override void GetUmiLoads(List <UmiObject> contextObjects, UmiContext umiContext)
 {
 }
 public abstract void GetUmiLoads(List <UmiObject> contextObjects, UmiContext umiContext);
 public void GetUmiLoads(List <UmiObject> contextBuilding, UmiContext umiContext)
 {
     Input = new double[8760];
 }
Exemple #20
0
 private void RhinoDoc_EndSaveDocument(object sender, UmiContext e)
 {
     SaveSettings(e);
 }
        public override Result Run(RhinoDoc doc, UmiContext context, RunMode mode)
        {
            WaterConsumptionPlugIn.VM.ScriptInvoked(doc, context);

            return(Result.Success);
        }
 private void PopulateFrom(object sender, UmiContext e)
 {
     LoadSettings(e);
 }