From fbd53575d9ce178d8715d7d70b8674198f7126f3 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 14:07:16 -0400 Subject: [PATCH 01/12] Fixes an issue where the solver could not access variables --- DistrictEnergy/DHRunLPModel.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/DistrictEnergy/DHRunLPModel.cs b/DistrictEnergy/DHRunLPModel.cs index d071a25..456afc0 100644 --- a/DistrictEnergy/DHRunLPModel.cs +++ b/DistrictEnergy/DHRunLPModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using DistrictEnergy.Helpers; @@ -15,31 +15,27 @@ public class DHRunLPModel : Command public DHRunLPModel() { Instance = this; - Qin = new Dictionary<(int, IThermalPlantSettings), Variable>(); - Qout = new Dictionary<(int, IThermalPlantSettings), Variable>(); - S = new Dictionary<(int, IThermalPlantSettings), Variable>(); - P = new Dictionary<(int, IThermalPlantSettings), Variable>(); } /// /// Input energy flow at each supply module of the energy hub at each time step" /// - public Dictionary<(int, IThermalPlantSettings), Variable> P { get; set; } + public Dictionary<(int, IThermalPlantSettings), Variable> P { get; set; } = new Dictionary<(int, IThermalPlantSettings), Variable>(); /// /// Storage state at each storage module of the energy hub at each time step" /// - public Dictionary<(int, IThermalPlantSettings), Variable> S { get; set; } + public Dictionary<(int, IThermalPlantSettings), Variable> S = new Dictionary<(int, IThermalPlantSettings), Variable>(); /// /// Output energy flow at each storage module of the energy hub at each time step" /// - public Dictionary<(int, IThermalPlantSettings), Variable> Qout { get; set; } + public Dictionary<(int, IThermalPlantSettings), Variable> Qout = new Dictionary<(int, IThermalPlantSettings), Variable>(); /// /// Input energy flow at each storage module of the energy hub at each time step" /// - public Dictionary<(int, IThermalPlantSettings), Variable> Qin { get; set; } + public Dictionary<(int, IThermalPlantSettings), Variable> Qin = new Dictionary<(int, IThermalPlantSettings), Variable>(); ///The only instance of the DHRunLPModel command. public static DHRunLPModel Instance { get; private set; } From ebac380b0bb9bb0d03f39589e1538e09075f7ee6 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 14:07:40 -0400 Subject: [PATCH 02/12] Name change --- DistrictEnergy/DHRunLPModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DistrictEnergy/DHRunLPModel.cs b/DistrictEnergy/DHRunLPModel.cs index 456afc0..880cc9a 100644 --- a/DistrictEnergy/DHRunLPModel.cs +++ b/DistrictEnergy/DHRunLPModel.cs @@ -52,7 +52,7 @@ private void Main() { DHSimulateDistrictEnergy.Instance.PreSolve(); // Create the linear solver with the CBC backend. - var solver = Solver.CreateSolver("SimpleMipProgram", "GLOP_LINEAR_PROGRAMMING"); + var solver = Solver.CreateSolver("SimpleLP", "GLOP_LINEAR_PROGRAMMING"); // Define Model Variables. Here each variable is the supply power of each available supply module int timeSteps = (int) DistrictControl.PlanningSettings.TimeSteps; // Number of Time Steps From 3368bba80333e299d7bc0ef710a230f89b7beb9b Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 14:08:46 -0400 Subject: [PATCH 03/12] Adds export placeholders for cooling and heating excess --- DistrictEnergy/DHRunLPModel.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/DistrictEnergy/DHRunLPModel.cs b/DistrictEnergy/DHRunLPModel.cs index 880cc9a..05428d8 100644 --- a/DistrictEnergy/DHRunLPModel.cs +++ b/DistrictEnergy/DHRunLPModel.cs @@ -98,6 +98,8 @@ private void Main() for (var t = 0; t < timeSteps * dt; t += dt) { E[(t, LoadTypes.Elec)] = solver.MakeNumVar(0.0, double.PositiveInfinity, $"Export{t}_Electricity"); + E[(t, LoadTypes.Cooling)] = solver.MakeNumVar(0.0, double.PositiveInfinity, $"Export{t}_Cooling"); + E[(t, LoadTypes.Heating)] = solver.MakeNumVar(0.0, double.PositiveInfinity, $"Export{t}_Heating"); } RhinoApp.WriteLine("Number of variables = " + solver.NumVariables()); @@ -127,7 +129,7 @@ private void Main() .Select(x => x.Value).ToArray() .Sum() == Load.Where(x => x.Key.Item2 == loadTypes && x.Key.Item1 == i).Select(o => o.Value) - .Sum()); + .Sum() + E[(i, loadTypes)]); } } @@ -144,7 +146,7 @@ private void Main() .Select(x => x.Value).ToArray() .Sum() == Load.Where(x => x.Key.Item2 == loadTypes && x.Key.Item1 == i).Select(o => o.Value) - .Sum()); + .Sum() + E[(i, loadTypes)]); } } @@ -279,11 +281,16 @@ private void Main() storage.Stored = S.Where(x => x.Key.Item2 == storage).Select(v => v.Value.SolutionValue()) .ToDateTimePoint(); RhinoApp.WriteLine( - $"{storage.Name} = Qin {storage.Input.Sum()}; Qout {storage.Output.Sum()}; EndStorageState {storage.Stored.Last().Value}"); + $"{storage.Name} = Qin {storage.Input.Sum()}; Qout {storage.Output.Sum()}; Storage Balance {storage.Input.Sum() - storage.Output.Sum()}"); } // Write Exports - RhinoApp.WriteLine($"Export_Electricity = {E.Select(x => x.Value.SolutionValue()).ToArray().Sum()}"); + foreach (LoadTypes loadTypes in Enum.GetValues(typeof(LoadTypes))) + { + var sum = E.Where(o => o.Key.Item2 == loadTypes).Select(x => x.Value.SolutionValue()).ToArray().Sum(); + if (sum > 0) RhinoApp.WriteLine($"Export_{loadTypes} = {sum}"); + } + RhinoApp.WriteLine("\nAdvanced usage:"); From 4b52dd7ba5429eb091b24d6640b9949f8e7e83a5 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 14:13:43 -0400 Subject: [PATCH 04/12] Calculates Battery capacity dynamically --- .../Networks/ThermalPlants/BatteryBank.cs | 6 ++++++ .../Networks/ThermalPlants/HotWaterStorage.cs | 6 ++++++ .../Networks/ThermalPlants/Storage.cs | 3 ++- .../ViewModels/ElectricGenerationViewModel.cs | 18 ------------------ DistrictEnergy/ViewModels/HotWaterViewModel.cs | 18 ------------------ 5 files changed, 14 insertions(+), 37 deletions(-) diff --git a/DistrictEnergy/Networks/ThermalPlants/BatteryBank.cs b/DistrictEnergy/Networks/ThermalPlants/BatteryBank.cs index a2f690b..8f23e8a 100644 --- a/DistrictEnergy/Networks/ThermalPlants/BatteryBank.cs +++ b/DistrictEnergy/Networks/ThermalPlants/BatteryBank.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; using System.Runtime.Serialization; using System.Windows.Media; using DistrictEnergy.Helpers; @@ -63,5 +64,10 @@ public BatteryBank() public override double MaxChargingRate => Capacity > 0 ? Capacity / AUT_BAT : 0; public override double MaxDischargingRate => Capacity > 0 ? Capacity / AUT_BAT : 0; public override double StartingCapacity => Capacity * BAT_START; + public override double Capacity => CalcCapacity(); + private double CalcCapacity() + { + return DistrictControl.Instance.ListOfDistrictLoads.Where(x => x.LoadType == LoadTypes.Elec).Select(v => v.Input.Average()).Sum() * AUT_BAT * 24; + } } } \ No newline at end of file diff --git a/DistrictEnergy/Networks/ThermalPlants/HotWaterStorage.cs b/DistrictEnergy/Networks/ThermalPlants/HotWaterStorage.cs index 4a3b6c4..7148492 100644 --- a/DistrictEnergy/Networks/ThermalPlants/HotWaterStorage.cs +++ b/DistrictEnergy/Networks/ThermalPlants/HotWaterStorage.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Linq; using System.Runtime.Serialization; using System.Windows.Media; using DistrictEnergy.Helpers; @@ -55,5 +56,10 @@ public HotWaterStorage() public override double MaxChargingRate => Capacity > 0 ? Capacity / AUT_HWT : 0; public override double MaxDischargingRate => Capacity > 0 ? Capacity / AUT_HWT : 0; public override double StartingCapacity => Capacity * TANK_START; + public override double Capacity => CalcCapacity(); + private double CalcCapacity() + { + return DistrictControl.Instance.ListOfDistrictLoads.Where(x => x.LoadType == LoadTypes.Heating).Select(v => v.Input.Average()).Sum() * AUT_HWT * 24; + } } } \ No newline at end of file diff --git a/DistrictEnergy/Networks/ThermalPlants/Storage.cs b/DistrictEnergy/Networks/ThermalPlants/Storage.cs index b2d7533..9082dcd 100644 --- a/DistrictEnergy/Networks/ThermalPlants/Storage.cs +++ b/DistrictEnergy/Networks/ThermalPlants/Storage.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Windows.Media; using DistrictEnergy.Helpers; using LiveCharts.Defaults; @@ -18,7 +19,7 @@ public abstract class Storage : IThermalPlantSettings public abstract double StartingCapacity { get; } public abstract double F { get; set; } public abstract double V { get; set; } - public double Capacity { get; set; } + public abstract double Capacity { get; } public abstract string Name { get; set; } public Guid Id { get; set; } = Guid.NewGuid(); public abstract LoadTypes OutputType { get; } diff --git a/DistrictEnergy/ViewModels/ElectricGenerationViewModel.cs b/DistrictEnergy/ViewModels/ElectricGenerationViewModel.cs index b06abd8..575ddf2 100644 --- a/DistrictEnergy/ViewModels/ElectricGenerationViewModel.cs +++ b/DistrictEnergy/ViewModels/ElectricGenerationViewModel.cs @@ -173,7 +173,6 @@ public double AUT_BAT { DistrictControl.Instance.ListOfPlantSettings.OfType().First().AUT_BAT = value; OnPropertyChanged(); - CalcBatCapacity(); } } @@ -217,23 +216,6 @@ public double V_BAT } } - public double BatCapacity - { - get { return _windCapacity; } - set - { - DistrictControl.Instance.ListOfPlantSettings.OfType().First().Capacity = value; - OnPropertyChanged(); - } - } - - private void CalcBatCapacity() - { - // todo Define a more advanced capacity formulation - BatCapacity = DistrictControl.Instance.ListOfDistrictLoads.Where(x => x.LoadType == LoadTypes.Elec).Select(v => v.Input.Average()).Sum() * - DistrictControl.Instance.ListOfPlantSettings.OfType().First().AUT_BAT * 24; - } - #endregion } } \ No newline at end of file diff --git a/DistrictEnergy/ViewModels/HotWaterViewModel.cs b/DistrictEnergy/ViewModels/HotWaterViewModel.cs index 1f295f6..99a4908 100644 --- a/DistrictEnergy/ViewModels/HotWaterViewModel.cs +++ b/DistrictEnergy/ViewModels/HotWaterViewModel.cs @@ -145,7 +145,6 @@ public double AUT_HWT { DistrictControl.Instance.ListOfPlantSettings.OfType().First().AUT_HWT = value; OnPropertyChanged(); - CalcHwStoCapacityCapacity(); } } @@ -179,23 +178,6 @@ public double V_HWT } } - public double HwStoCapacity - { - get { return _hwStoCapacity; } - set - { - DistrictControl.Instance.ListOfPlantSettings.OfType().First().Capacity = value; - OnPropertyChanged(); - } - } - - private void CalcHwStoCapacityCapacity() - { - // todo Define a more advanced capacity formulation - HwStoCapacity = DistrictControl.Instance.ListOfDistrictLoads.Where(x=>x.LoadType == LoadTypes.Heating).Select(v=>v.Input.Average()).Sum() * - DistrictControl.Instance.ListOfPlantSettings.OfType().First().AUT_HWT * 24; - } - #endregion #region SolarThermal From 7839f4c0202cd06ce18f0631b275ae51ec058fc6 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 16:36:05 -0400 Subject: [PATCH 05/12] Plant capacity is now set as a constraint --- DistrictEnergy/DHRunLPModel.cs | 65 ++++++++++++++++--- .../ThermalPlants/AbsorptionChiller.cs | 1 + .../ThermalPlants/CombinedHeatNPower.cs | 1 + .../CustomCoolingSupplyModule.cs | 1 + .../CustomElectricitySupplyModule.cs | 1 + .../ThermalPlants/CustomEnergySupplyModule.cs | 2 + .../CustomHeatingSupplyModule.cs | 1 + .../Networks/ThermalPlants/Dispatchable.cs | 1 + .../Networks/ThermalPlants/ElectricChiller.cs | 1 + .../ThermalPlants/ElectricHeatPump.cs | 1 + .../Networks/ThermalPlants/GridElectricity.cs | 1 + .../Networks/ThermalPlants/GridGas.cs | 1 + .../ThermalPlants/IThermalPlantSettings.cs | 1 + .../Networks/ThermalPlants/NatGasBoiler.cs | 1 + .../ThermalPlants/PhotovoltaicArray.cs | 1 + .../ThermalPlants/SolarThermalCollector.cs | 1 + .../Networks/ThermalPlants/Storage.cs | 1 + .../Networks/ThermalPlants/WindTurbine.cs | 1 + .../ViewModels/HotWaterViewModel.cs | 17 ----- 19 files changed, 74 insertions(+), 26 deletions(-) diff --git a/DistrictEnergy/DHRunLPModel.cs b/DistrictEnergy/DHRunLPModel.cs index 05428d8..a1ab783 100644 --- a/DistrictEnergy/DHRunLPModel.cs +++ b/DistrictEnergy/DHRunLPModel.cs @@ -1,7 +1,8 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using DistrictEnergy.Helpers; +using DistrictEnergy.Metrics; using DistrictEnergy.Networks.Loads; using DistrictEnergy.Networks.ThermalPlants; using Google.OrTools.LinearSolver; @@ -20,22 +21,37 @@ public DHRunLPModel() /// /// Input energy flow at each supply module of the energy hub at each time step" /// - public Dictionary<(int, IThermalPlantSettings), Variable> P { get; set; } = new Dictionary<(int, IThermalPlantSettings), Variable>(); + public Dictionary<(int, IThermalPlantSettings), Variable> P = + new Dictionary<(int, IThermalPlantSettings), Variable>(); /// /// Storage state at each storage module of the energy hub at each time step" /// - public Dictionary<(int, IThermalPlantSettings), Variable> S = new Dictionary<(int, IThermalPlantSettings), Variable>(); + public Dictionary<(int, IThermalPlantSettings), Variable> S = + new Dictionary<(int, IThermalPlantSettings), Variable>(); /// /// Output energy flow at each storage module of the energy hub at each time step" /// - public Dictionary<(int, IThermalPlantSettings), Variable> Qout = new Dictionary<(int, IThermalPlantSettings), Variable>(); + public Dictionary<(int, IThermalPlantSettings), Variable> Qout = + new Dictionary<(int, IThermalPlantSettings), Variable>(); /// /// Input energy flow at each storage module of the energy hub at each time step" /// - public Dictionary<(int, IThermalPlantSettings), Variable> Qin = new Dictionary<(int, IThermalPlantSettings), Variable>(); + public Dictionary<(int, IThermalPlantSettings), Variable> Qin = + new Dictionary<(int, IThermalPlantSettings), Variable>(); + + /// + /// DistrictLoad Demand (Umi Buildings + Losses) + /// + public Dictionary<(int, LoadTypes, AbstractDistrictLoad), double> Load = + new Dictionary<(int, LoadTypes, AbstractDistrictLoad), double>(); + + /// + /// Exported Energy. Subject To LargeNumber Cost. + /// + public Dictionary<(int, LoadTypes), Variable> E = new Dictionary<(int, LoadTypes), Variable>(); ///The only instance of the DHRunLPModel command. public static DHRunLPModel Instance { get; private set; } @@ -50,6 +66,7 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode) private void Main() { + ClearVariables(); DHSimulateDistrictEnergy.Instance.PreSolve(); // Create the linear solver with the CBC backend. var solver = Solver.CreateSolver("SimpleLP", "GLOP_LINEAR_PROGRAMMING"); @@ -65,7 +82,7 @@ private void Main() { for (var t = 0; t < timeSteps * dt; t += dt) { - P[(t, supplymodule)] = solver.MakeNumVar(0.0, supplymodule.Capacity / supplymodule.Efficiency * dt, + P[(t, supplymodule)] = solver.MakeNumVar(0.0, double.PositiveInfinity, string.Format($"P_{t}_{supplymodule.Name}")); } } @@ -94,7 +111,6 @@ private void Main() $"Computed {Qin.Count + Qout.Count + S.Count} S variables in {watch.ElapsedMilliseconds} milliseconds"); // Exports (per supply module) - var E = new Dictionary<(int, LoadTypes), Variable>(); for (var t = 0; t < timeSteps * dt; t += dt) { E[(t, LoadTypes.Elec)] = solver.MakeNumVar(0.0, double.PositiveInfinity, $"Export{t}_Electricity"); @@ -104,7 +120,6 @@ private void Main() RhinoApp.WriteLine("Number of variables = " + solver.NumVariables()); - var Load = new Dictionary<(int, LoadTypes, AbstractDistrictLoad), double>(); foreach (var load in DistrictControl.Instance.ListOfDistrictLoads) { for (int t = 0; t < timeSteps * dt; t += dt) @@ -179,6 +194,27 @@ private void Main() } } + // Capacity Constraints + foreach (var inputFlow in P.Where(x => + x.Key.Item2.OutputType == LoadTypes.Elec || x.Key.Item2.OutputType == LoadTypes.Heating || + x.Key.Item2.OutputType == LoadTypes.Cooling)) + { + var loadType = inputFlow.Key.Item2.OutputType; + var i = inputFlow.Key.Item1; + solver.Add(inputFlow.Value * inputFlow.Key.Item2.ConversionMatrix[loadType] <= + inputFlow.Key.Item2.CapacityFactor * + ( + P.Where(k => k.Key.Item2.ConversionMatrix.ContainsKey(loadType) && k.Key.Item1 == i) + .Select(k => k.Value * k.Key.Item2.ConversionMatrix[loadType]).ToArray().Sum() + + Qin.Where(k => k.Key.Item2.OutputType == loadType && k.Key.Item1 == i) + .Select(x => x.Value).ToArray().Sum() - + Qout.Where(k => k.Key.Item2.OutputType == loadType && k.Key.Item1 == i) + .Select(x => x.Value).ToArray().Sum() + + Load.Where(x => x.Key.Item2 == loadType && x.Key.Item1 == i).Select(o => o.Value).Sum() + + E[(i, loadType)]) + ); + } + // Solar & Wind Constraints foreach (var solarSupply in DistrictControl.Instance.ListOfPlantSettings.OfType()) { @@ -188,6 +224,7 @@ private void Main() solarSupply.AvailableArea); } } + // Todo: Add wind constraints // Storage Rules foreach (var storage in DistrictControl.Instance.ListOfPlantSettings.OfType()) @@ -199,6 +236,7 @@ private void Main() // (1 / storage.DischargingEfficiency) * Qout[(0, storage)]); // storage content initial <= final, both variable + // Todo: Why Skip first timestep solver.Add(S.Where(x => x.Key.Item2 == storage).Select(o => o.Value).Skip(1).First() <= S.Where(x => x.Key.Item2 == storage).Select(o => o.Value).Last()); @@ -290,7 +328,6 @@ private void Main() var sum = E.Where(o => o.Key.Item2 == loadTypes).Select(x => x.Value.SolutionValue()).ToArray().Sum(); if (sum > 0) RhinoApp.WriteLine($"Export_{loadTypes} = {sum}"); } - RhinoApp.WriteLine("\nAdvanced usage:"); @@ -300,6 +337,16 @@ private void Main() OnCompletion(new SimulationCompleted() {TimeSteps = timeSteps, Period = dt}); } + private void ClearVariables() + { + P.Clear(); + Qin.Clear(); + Qout.Clear(); + S.Clear(); + Load.Clear(); + E.Clear(); + } + public event EventHandler Completion; protected virtual void OnCompletion(EventArgs e) diff --git a/DistrictEnergy/Networks/ThermalPlants/AbsorptionChiller.cs b/DistrictEnergy/Networks/ThermalPlants/AbsorptionChiller.cs index aee9e48..405628e 100644 --- a/DistrictEnergy/Networks/ThermalPlants/AbsorptionChiller.cs +++ b/DistrictEnergy/Networks/ThermalPlants/AbsorptionChiller.cs @@ -63,6 +63,7 @@ private double CalcCapacity() public override Guid Id { get; set; } = Guid.NewGuid(); public override LoadTypes OutputType { get; } = LoadTypes.Cooling; public override LoadTypes InputType => LoadTypes.Heating; + public override double CapacityFactor => OFF_ABS; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs b/DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs index dda1b37..78781af 100644 --- a/DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs +++ b/DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs @@ -88,6 +88,7 @@ private double CalcCapacity() public override Guid Id { get; set; } = Guid.NewGuid(); public override LoadTypes OutputType => LoadTypes.Elec; public override LoadTypes InputType => LoadTypes.Gas; + public override double CapacityFactor => OFF_CHP; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/CustomCoolingSupplyModule.cs b/DistrictEnergy/Networks/ThermalPlants/CustomCoolingSupplyModule.cs index 4359f89..9d21c25 100644 --- a/DistrictEnergy/Networks/ThermalPlants/CustomCoolingSupplyModule.cs +++ b/DistrictEnergy/Networks/ThermalPlants/CustomCoolingSupplyModule.cs @@ -29,6 +29,7 @@ public double ComputeHeatBalance(double demand, int i) public double[] Used = new double[8760]; public override LoadTypes OutputType => LoadTypes.Cooling; public override LoadTypes InputType => LoadTypes.Custom; + public override double CapacityFactor => 1; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/CustomElectricitySupplyModule.cs b/DistrictEnergy/Networks/ThermalPlants/CustomElectricitySupplyModule.cs index 7ece398..388e862 100644 --- a/DistrictEnergy/Networks/ThermalPlants/CustomElectricitySupplyModule.cs +++ b/DistrictEnergy/Networks/ThermalPlants/CustomElectricitySupplyModule.cs @@ -18,6 +18,7 @@ public CustomElectricitySupplyModule() public override LoadTypes OutputType => LoadTypes.Elec; public override LoadTypes InputType => LoadTypes.Custom; + public override double CapacityFactor => 1; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/CustomEnergySupplyModule.cs b/DistrictEnergy/Networks/ThermalPlants/CustomEnergySupplyModule.cs index a03f55d..446d874 100644 --- a/DistrictEnergy/Networks/ThermalPlants/CustomEnergySupplyModule.cs +++ b/DistrictEnergy/Networks/ThermalPlants/CustomEnergySupplyModule.cs @@ -103,6 +103,8 @@ public override SolidColorBrush Fill set => throw new NotImplementedException(); } + public override double CapacityFactor { get; } + public Color Color { get; set; } = Color.FromRgb(200, 1, 0); public abstract override Dictionary ConversionMatrix { get; set; } public abstract override double Efficiency { get; } diff --git a/DistrictEnergy/Networks/ThermalPlants/CustomHeatingSupplyModule.cs b/DistrictEnergy/Networks/ThermalPlants/CustomHeatingSupplyModule.cs index 55eb5d6..93113b5 100644 --- a/DistrictEnergy/Networks/ThermalPlants/CustomHeatingSupplyModule.cs +++ b/DistrictEnergy/Networks/ThermalPlants/CustomHeatingSupplyModule.cs @@ -16,6 +16,7 @@ public CustomHeatingSupplyModule() public override LoadTypes OutputType => LoadTypes.Heating; public override LoadTypes InputType => LoadTypes.Custom; + public override double CapacityFactor => 1; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs b/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs index e951350..49d5d7c 100644 --- a/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs +++ b/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs @@ -25,6 +25,7 @@ public abstract class Dispatchable : IThermalPlantSettings public GraphCost FixedCost => new FixedCost(this); public GraphCost VariableCost => new VariableCost(this, 200); public double TotalCost => FixedCost.Cost + VariableCost.Cost; + public abstract double CapacityFactor { get; } } public class FixedCost : GraphCost diff --git a/DistrictEnergy/Networks/ThermalPlants/ElectricChiller.cs b/DistrictEnergy/Networks/ThermalPlants/ElectricChiller.cs index 1850f7f..0d3f178 100644 --- a/DistrictEnergy/Networks/ThermalPlants/ElectricChiller.cs +++ b/DistrictEnergy/Networks/ThermalPlants/ElectricChiller.cs @@ -33,6 +33,7 @@ public ElectricChiller() public override Guid Id { get; set; } public override LoadTypes OutputType => LoadTypes.Cooling; public override LoadTypes InputType => LoadTypes.Elec; + public override double CapacityFactor => 1; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/ElectricHeatPump.cs b/DistrictEnergy/Networks/ThermalPlants/ElectricHeatPump.cs index b1a3a48..9f645ab 100644 --- a/DistrictEnergy/Networks/ThermalPlants/ElectricHeatPump.cs +++ b/DistrictEnergy/Networks/ThermalPlants/ElectricHeatPump.cs @@ -58,6 +58,7 @@ private double CalcCapacity() public override Guid Id { get; set; } = Guid.NewGuid(); public override LoadTypes OutputType => LoadTypes.Heating; public override LoadTypes InputType => LoadTypes.Elec; + public override double CapacityFactor => OFF_EHP; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/GridElectricity.cs b/DistrictEnergy/Networks/ThermalPlants/GridElectricity.cs index 21b915c..7e03e40 100644 --- a/DistrictEnergy/Networks/ThermalPlants/GridElectricity.cs +++ b/DistrictEnergy/Networks/ThermalPlants/GridElectricity.cs @@ -38,6 +38,7 @@ public override double V public override Guid Id { get; set; } = Guid.NewGuid(); public override LoadTypes OutputType => LoadTypes.Elec; public override LoadTypes InputType => LoadTypes.GridElec; + public override double CapacityFactor => 1; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/GridGas.cs b/DistrictEnergy/Networks/ThermalPlants/GridGas.cs index 3eeb8ab..741b6cc 100644 --- a/DistrictEnergy/Networks/ThermalPlants/GridGas.cs +++ b/DistrictEnergy/Networks/ThermalPlants/GridGas.cs @@ -36,6 +36,7 @@ public override double V public override Guid Id { get; set; } = Guid.NewGuid(); public override LoadTypes OutputType => LoadTypes.Gas; public override LoadTypes InputType => LoadTypes.GridGas; + public override double CapacityFactor => 1; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/IThermalPlantSettings.cs b/DistrictEnergy/Networks/ThermalPlants/IThermalPlantSettings.cs index 4204e86..d8c8840 100644 --- a/DistrictEnergy/Networks/ThermalPlants/IThermalPlantSettings.cs +++ b/DistrictEnergy/Networks/ThermalPlants/IThermalPlantSettings.cs @@ -68,5 +68,6 @@ public interface IThermalPlantSettings [JsonIgnore] GraphCost FixedCost { get; } [JsonIgnore] GraphCost VariableCost { get; } [JsonIgnore] double TotalCost { get; } + [JsonIgnore] double CapacityFactor { get; } } } \ No newline at end of file diff --git a/DistrictEnergy/Networks/ThermalPlants/NatGasBoiler.cs b/DistrictEnergy/Networks/ThermalPlants/NatGasBoiler.cs index ff7696c..8d87bd6 100644 --- a/DistrictEnergy/Networks/ThermalPlants/NatGasBoiler.cs +++ b/DistrictEnergy/Networks/ThermalPlants/NatGasBoiler.cs @@ -31,6 +31,7 @@ public NatGasBoiler() public override Guid Id { get; set; } = Guid.NewGuid(); public override LoadTypes OutputType => LoadTypes.Heating; public override LoadTypes InputType => LoadTypes.Gas; + public override double CapacityFactor => 1; public override Dictionary ConversionMatrix { get; set; } public override List Input { get; set; } public override List Output { get; set; } diff --git a/DistrictEnergy/Networks/ThermalPlants/PhotovoltaicArray.cs b/DistrictEnergy/Networks/ThermalPlants/PhotovoltaicArray.cs index 9e4e4cd..3abad07 100644 --- a/DistrictEnergy/Networks/ThermalPlants/PhotovoltaicArray.cs +++ b/DistrictEnergy/Networks/ThermalPlants/PhotovoltaicArray.cs @@ -50,6 +50,7 @@ public PhotovoltaicArray() [DataMember] [DefaultValue(1313)] public override double F { get; set; } = 1313; [DataMember] [DefaultValue(0)] public override double V { get; set; } public override double Capacity => CalcCapacity(); + public override double CapacityFactor => OFF_PV; private double CalcCapacity() { diff --git a/DistrictEnergy/Networks/ThermalPlants/SolarThermalCollector.cs b/DistrictEnergy/Networks/ThermalPlants/SolarThermalCollector.cs index 269fb0f..2fe3222 100644 --- a/DistrictEnergy/Networks/ThermalPlants/SolarThermalCollector.cs +++ b/DistrictEnergy/Networks/ThermalPlants/SolarThermalCollector.cs @@ -55,6 +55,7 @@ public SolarThermalCollector() [DataMember] [DefaultValue(7191)] public override double F { get; set; } = 7191; [DataMember] [DefaultValue(0.00887)] public override double V { get; set; } = 0.00887; public override double Capacity => CalcCapacity(); + public override double CapacityFactor => OFF_SHW; private double CalcCapacity() { diff --git a/DistrictEnergy/Networks/ThermalPlants/Storage.cs b/DistrictEnergy/Networks/ThermalPlants/Storage.cs index 9082dcd..8f8768a 100644 --- a/DistrictEnergy/Networks/ThermalPlants/Storage.cs +++ b/DistrictEnergy/Networks/ThermalPlants/Storage.cs @@ -31,5 +31,6 @@ public abstract class Storage : IThermalPlantSettings public GraphCost FixedCost => new FixedCost(this); public GraphCost VariableCost => new VariableCost(this, 200); public double TotalCost => FixedCost.Cost + VariableCost.Cost; + public double CapacityFactor => 1; } } \ No newline at end of file diff --git a/DistrictEnergy/Networks/ThermalPlants/WindTurbine.cs b/DistrictEnergy/Networks/ThermalPlants/WindTurbine.cs index 3cd3cb2..c43e2db 100644 --- a/DistrictEnergy/Networks/ThermalPlants/WindTurbine.cs +++ b/DistrictEnergy/Networks/ThermalPlants/WindTurbine.cs @@ -64,6 +64,7 @@ public WindTurbine() [DataMember] [DefaultValue(1347)] public override double F { get; set; } = 1347; [DataMember] [DefaultValue(0)] public override double V { get; set; } public override double Capacity => CalcCapacity(); + public override double CapacityFactor => OFF_WND; private double CalcCapacity() { diff --git a/DistrictEnergy/ViewModels/HotWaterViewModel.cs b/DistrictEnergy/ViewModels/HotWaterViewModel.cs index 99a4908..0387ecc 100644 --- a/DistrictEnergy/ViewModels/HotWaterViewModel.cs +++ b/DistrictEnergy/ViewModels/HotWaterViewModel.cs @@ -60,7 +60,6 @@ public double OFF_EHP { DistrictControl.Instance.ListOfPlantSettings.OfType().First().OFF_EHP = value / 100; OnPropertyChanged(); - CalcHpCapacity(); } } @@ -118,22 +117,6 @@ public double V_EHP } } - public double HpCapacity - { - get { return _hpCapacity; } - set - { - _hpCapacity = value; - OnPropertyChanged(); - } - } - - private void CalcHpCapacity() - { - HpCapacity = DistrictControl.Instance.ListOfPlantSettings.OfType().First().OFF_EHP * - DistrictControl.Instance.ListOfDistrictLoads.Where(x => x.LoadType == LoadTypes.Heating).Select(v => v.Input.Max()).Sum(); - } - #endregion #region HWSto From e4c6e09eae5dc06e1d40ee02d03fcf0e11fd5325 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 16:47:11 -0400 Subject: [PATCH 06/12] Fixes Tooltips and buttons --- DistrictEnergy/Views/PlantSettings/ChilledWaterView.xaml | 4 ++-- .../Views/PlantSettings/CombinedHeatAndPowerView.xaml | 2 +- .../Views/PlantSettings/ElectricGenerationView.xaml | 6 +++--- DistrictEnergy/Views/PlantSettings/HotWaterView.xaml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DistrictEnergy/Views/PlantSettings/ChilledWaterView.xaml b/DistrictEnergy/Views/PlantSettings/ChilledWaterView.xaml index e55d921..91e57b4 100644 --- a/DistrictEnergy/Views/PlantSettings/ChilledWaterView.xaml +++ b/DistrictEnergy/Views/PlantSettings/ChilledWaterView.xaml @@ -72,7 +72,7 @@ - Electric Chiller + Electric Chiller diff --git a/DistrictEnergy/Views/PlantSettings/CombinedHeatAndPowerView.xaml b/DistrictEnergy/Views/PlantSettings/CombinedHeatAndPowerView.xaml index b429215..5ffd2fd 100644 --- a/DistrictEnergy/Views/PlantSettings/CombinedHeatAndPowerView.xaml +++ b/DistrictEnergy/Views/PlantSettings/CombinedHeatAndPowerView.xaml @@ -85,7 +85,7 @@ - + diff --git a/DistrictEnergy/Views/PlantSettings/HotWaterView.xaml b/DistrictEnergy/Views/PlantSettings/HotWaterView.xaml index 7cc9b74..c44b753 100644 --- a/DistrictEnergy/Views/PlantSettings/HotWaterView.xaml +++ b/DistrictEnergy/Views/PlantSettings/HotWaterView.xaml @@ -87,7 +87,7 @@ Date: Thu, 30 Apr 2020 18:27:08 -0400 Subject: [PATCH 07/12] Refactors the SummaryView and LoadsView to Use the cMatrix instead of the Output --- DistrictEnergy/ViewModels/LoadsViewModel.cs | 94 ++++++++----------- .../Views/ResultViews/Summary.xaml.cs | 42 ++++++--- 2 files changed, 69 insertions(+), 67 deletions(-) diff --git a/DistrictEnergy/ViewModels/LoadsViewModel.cs b/DistrictEnergy/ViewModels/LoadsViewModel.cs index 42e5985..be4db27 100644 --- a/DistrictEnergy/ViewModels/LoadsViewModel.cs +++ b/DistrictEnergy/ViewModels/LoadsViewModel.cs @@ -161,7 +161,7 @@ private void UpdateLoadsChart(object sender, EventArgs e) SeriesCollection.Clear(); DemandLineCollection.Clear(); - // Plot Demand (Negative) + // Plot District Demand (Negative) var plot_duration = args.TimeSteps; foreach (var demand in DistrictControl.Instance.ListOfDistrictLoads) { @@ -171,7 +171,7 @@ private void UpdateLoadsChart(object sender, EventArgs e) { Values = demand.Input.ToDateTimePoint().Split(plot_duration) .Select(v => new DateTimePoint(v.First().DateTime, -v.Sum())).AsGearedValues(), - Title = "[+] " + demand.Name, + Title = $"[{demand.LoadType}] {demand.Name}", LineSmoothness = lineSmoothness, LabelPoint = KWhLabelPointFormatter, AreaLimit = 0, @@ -191,63 +191,36 @@ private void UpdateLoadsChart(object sender, EventArgs e) Total = Total.Zip(demand.Input, (a, b) => a + b).ToArray(); } - // Plot Additional Demand from Supply Modules (Negative) - foreach (var dispatchable in DistrictControl.Instance.ListOfPlantSettings.OfType() - .Where(x => - x.InputType == LoadTypes.Cooling || x.InputType == LoadTypes.Heating || - x.InputType == LoadTypes.Elec)) - { - if (dispatchable.Input.Sum() > 0) - { - var series = new GStackedAreaSeries - { - Values = dispatchable.Input.Split(plot_duration) - .Select(v => new DateTimePoint(v.First().DateTime, -v.Sum())).AsGearedValues(), - Title = "[+] " + dispatchable.Name, - LineSmoothness = lineSmoothness, - LabelPoint = KWhLabelPointFormatter, - AreaLimit = 0, - Fill = dispatchable.Fill - }; - SeriesCollection.Add(series); - } - - Total = Total.Zip(dispatchable.Input, (a, b) => a + b.Value).ToArray(); - } - - // Plot Total Demand as Line - // var gLineSeries = new GLineSeries - // { - // Values = Total.AsChartValues(), - // Title = "Total", - // //LineSmoothness = lineSmoothness, - // LabelPoint = KWhLabelPointFormatter, - // Stroke = new SolidColorBrush(Color.FromRgb(0, 0, 0)), - // Fill = null, - // }; - // SeriesCollection.Add(gLineSeries); - // Panel.SetZIndex(gLineSeries, 60); - - - // Plot Supply (Positive) - foreach (var supply in DistrictControl.Instance.ListOfPlantSettings.OfType().Where(x => + // Plot Plant Supply & Demand + foreach (var plant in DistrictControl.Instance.ListOfPlantSettings.OfType().Where(x => x.OutputType == LoadTypes.Cooling || x.OutputType == LoadTypes.Heating || x.OutputType == LoadTypes.Elec)) - if (supply.Output.Sum() > 0) + { + foreach (var cMat in plant.ConversionMatrix.Where(x => + x.Key == LoadTypes.Cooling || + x.Key == LoadTypes.Heating || + x.Key == LoadTypes.Elec)) { - var series = new GStackedAreaSeries + var loadType = cMat.Key; + var eff = cMat.Value; + if (plant.Input.Sum() > 0) { - Values = supply.Output.Split(plot_duration) - .Select(v => new DateTimePoint(v.First().DateTime, v.Sum())).AsGearedValues(), - Title = supply.Name, - LineSmoothness = lineSmoothness, - LabelPoint = KWhLabelPointFormatter, - AreaLimit = 0, - Fill = supply.Fill - }; - SeriesCollection.Add(series); + var series = new GStackedAreaSeries + { + Values = plant.Input.Split(plot_duration).Select(v => + new DateTimePoint(v.First().DateTime, v.Select(o => o.Value * eff).Sum())) + .AsGearedValues(), + Title = $"[{loadType}] {plant.Name}", + LineSmoothness = lineSmoothness, + LabelPoint = KWhLabelPointFormatter, + AreaLimit = 0, + Fill = plant.Fill + }; + SeriesCollection.Add(series); + } } + } StorageSeriesCollection.Clear(); foreach (var storage in DistrictControl.Instance.ListOfPlantSettings.OfType()) @@ -270,7 +243,20 @@ private void UpdateLoadsChart(object sender, EventArgs e) { Values = storage.Output.Split(plot_duration) .Select(v => new DateTimePoint(v.First().DateTime, v.Sum())).AsGearedValues(), - Title = storage.Name, + Title = $"[{storage.OutputType}] {storage.Name} Out", + Fill = storage.Fill, + LineSmoothness = lineSmoothness, + AreaLimit = 0, + LabelPoint = KWhLabelPointFormatter, + }); + IsStorageVisible = true; + + // Plot Demand From Storage + SeriesCollection.Add(new GStackedAreaSeries() + { + Values = storage.Input.Split(plot_duration) + .Select(v => new DateTimePoint(v.First().DateTime, -v.Sum())).AsGearedValues(), + Title = $"[{storage.OutputType}] {storage.Name} In", Fill = storage.Fill, LineSmoothness = lineSmoothness, AreaLimit = 0, diff --git a/DistrictEnergy/Views/ResultViews/Summary.xaml.cs b/DistrictEnergy/Views/ResultViews/Summary.xaml.cs index 348226c..e5efe4f 100644 --- a/DistrictEnergy/Views/ResultViews/Summary.xaml.cs +++ b/DistrictEnergy/Views/ResultViews/Summary.xaml.cs @@ -2,7 +2,10 @@ using System.Linq; using System.Windows.Controls; using DistrictEnergy.Helpers; +using DistrictEnergy.Networks.ThermalPlants; using DistrictEnergy.ViewModels; +using LiveCharts.Defaults; +using LiveCharts.Geared; namespace DistrictEnergy.Views.ResultViews { @@ -48,22 +51,35 @@ public void GenerateControls() NamePlantStack.Children.Clear(); PeakPlantStack.Children.Clear(); EnergyPlantStack.Children.Clear(); - foreach (var plant in DistrictControl.Instance.ListOfPlantSettings) + + // Plot Plant Supply & Demand + foreach (var plant in DistrictControl.Instance.ListOfPlantSettings.OfType().Where(x => + x.OutputType == LoadTypes.Cooling || + x.OutputType == LoadTypes.Heating || + x.OutputType == LoadTypes.Elec)) { - TextBlock name = new TextBlock(); - name.Text = plant.Name; - NamePlantStack.Children.Add(name); - Grid.SetColumn(name, 2); + foreach (var cMat in plant.ConversionMatrix) + { + var loadType = cMat.Key; + var eff = cMat.Value; + if (plant.Input.Sum() > 0) + { + TextBlock name = new TextBlock(); + name.Text = $"[{loadType}] {plant.Name}"; + NamePlantStack.Children.Add(name); + Grid.SetColumn(name, 2); - TextBlock demandValue = new TextBlock(); - demandValue.Text = plant.Input.Max().ToString("N2"); - PeakPlantStack.Children.Add(demandValue); - Grid.SetColumn(name, 2); + TextBlock demandValue = new TextBlock(); + demandValue.Text = plant.Input.Select(v =>v.Value * eff).Max().ToString("N2"); + PeakPlantStack.Children.Add(demandValue); + Grid.SetColumn(name, 2); - TextBlock energyValue = new TextBlock(); - energyValue.Text = plant.Input.Sum().ToString("N2"); - EnergyPlantStack.Children.Add(energyValue); - Grid.SetColumn(name, 2); + TextBlock energyValue = new TextBlock(); + energyValue.Text = plant.Input.Select(v => v.Value * eff).Sum().ToString("N2"); + EnergyPlantStack.Children.Add(energyValue); + Grid.SetColumn(name, 2); + } + } } } } From 1c9353966589f6c5e978ca8374a861c454bf94ec Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 19:09:02 -0400 Subject: [PATCH 08/12] Fixes Tracking Mode for CHP plants --- DistrictEnergy/DistrictControl.xaml.cs | 2 +- .../ThermalPlants/CombinedHeatNPower.cs | 17 +++++------------ .../ViewModels/CombinedHeatAndPowerViewModel.cs | 7 ++++--- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/DistrictEnergy/DistrictControl.xaml.cs b/DistrictEnergy/DistrictControl.xaml.cs index 2acfa4c..5d9fb61 100644 --- a/DistrictEnergy/DistrictControl.xaml.cs +++ b/DistrictEnergy/DistrictControl.xaml.cs @@ -204,7 +204,7 @@ private void OnSimCaseChanged(object sender, SelectionChangedEventArgs e) { ChilledWaterViewModel.Instance.OFF_ABS = 100; CombinedHeatAndPowerViewModel.Instance.OFF_CHP = 100; - CombinedHeatAndPowerViewModel.Instance.TMOD_CHP = TrakingModeEnum.Electrical; + CombinedHeatAndPowerViewModel.Instance.TMOD_CHP = LoadTypes.Elec; ElectricGenerationViewModel.Instance.OFF_PV = 0; HotWaterViewModel.Instance.OFF_EHP = 0; HotWaterViewModel.Instance.OFF_SHW = 0; diff --git a/DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs b/DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs index 78781af..51bb557 100644 --- a/DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs +++ b/DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs @@ -25,8 +25,8 @@ public CombinedHeatNPower() /// Tracking Mode /// [DataMember] - [DefaultValue(TrakingModeEnum.Thermal)] - public TrakingModeEnum TMOD_CHP { get; set; } = TrakingModeEnum.Thermal; + [DefaultValue(LoadTypes.Heating)] + public LoadTypes TMOD_CHP { get; set; } = LoadTypes.Heating; /// /// Capacity as percent of peak electric load (%) @@ -70,10 +70,10 @@ private double CalcCapacity() if (DistrictControl.Instance is null) return 0; switch (TMOD_CHP) { - case TrakingModeEnum.Electrical: + case LoadTypes.Elec: return OFF_CHP * DistrictControl.Instance.ListOfDistrictLoads .Where(x => x.LoadType == LoadTypes.Elec).Select(v => v.Input.Max()).Sum(); - case TrakingModeEnum.Thermal: + case LoadTypes.Heating: return OFF_CHP * DistrictControl.Instance.ListOfDistrictLoads .Where(x => x.LoadType == LoadTypes.Heating).Select(v => v.Input.Max()).Sum(); } @@ -86,7 +86,7 @@ private double CalcCapacity() public override string Name { get; set; } = "Combined Heat&Power"; public override Guid Id { get; set; } = Guid.NewGuid(); - public override LoadTypes OutputType => LoadTypes.Elec; + public override LoadTypes OutputType => TMOD_CHP; public override LoadTypes InputType => LoadTypes.Gas; public override double CapacityFactor => OFF_CHP; public override Dictionary ConversionMatrix { get; set; } @@ -95,11 +95,4 @@ private double CalcCapacity() public override double Efficiency => ConversionMatrix[OutputType]; public override SolidColorBrush Fill { get; set; } = new SolidColorBrush(Color.FromRgb(247, 96, 21)); } - - [DataContract(Name = "TMOD_CHP")] - public enum TrakingModeEnum - { - [EnumMember] Thermal, - [EnumMember] Electrical - } } \ No newline at end of file diff --git a/DistrictEnergy/ViewModels/CombinedHeatAndPowerViewModel.cs b/DistrictEnergy/ViewModels/CombinedHeatAndPowerViewModel.cs index d11720c..44f26d0 100644 --- a/DistrictEnergy/ViewModels/CombinedHeatAndPowerViewModel.cs +++ b/DistrictEnergy/ViewModels/CombinedHeatAndPowerViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using DistrictEnergy.Helpers; using DistrictEnergy.Networks.ThermalPlants; namespace DistrictEnergy.ViewModels @@ -16,10 +17,10 @@ public CombinedHeatAndPowerViewModel() public new static CombinedHeatAndPowerViewModel Instance { get; set; } - public IList PosibleTrackingModes => - Enum.GetValues(typeof(TrakingModeEnum)).Cast().ToList(); + public IList PosibleTrackingModes => + new List() {LoadTypes.Elec, LoadTypes.Heating}; - public TrakingModeEnum TMOD_CHP + public LoadTypes TMOD_CHP { get => DistrictControl.Instance.ListOfPlantSettings.OfType().First().TMOD_CHP; set From 471588823b0b0a3ddd5eb8f3ec5d2e966c28a908 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 19:44:07 -0400 Subject: [PATCH 09/12] Removes the export in the Upper Capacity Bound --- DistrictEnergy/DHRunLPModel.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/DistrictEnergy/DHRunLPModel.cs b/DistrictEnergy/DHRunLPModel.cs index a1ab783..b5d93cb 100644 --- a/DistrictEnergy/DHRunLPModel.cs +++ b/DistrictEnergy/DHRunLPModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using DistrictEnergy.Helpers; @@ -210,8 +210,7 @@ private void Main() .Select(x => x.Value).ToArray().Sum() - Qout.Where(k => k.Key.Item2.OutputType == loadType && k.Key.Item1 == i) .Select(x => x.Value).ToArray().Sum() + - Load.Where(x => x.Key.Item2 == loadType && x.Key.Item1 == i).Select(o => o.Value).Sum() + - E[(i, loadType)]) + Load.Where(x => x.Key.Item2 == loadType && x.Key.Item1 == i).Select(o => o.Value).Sum()) ); } From 21f73ecb18b03bc89883912779f133f2970b322d Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 19:44:54 -0400 Subject: [PATCH 10/12] Fixes the cost functions and Display (improper period length) --- DistrictEnergy/DHRunLPModel.cs | 4 ++-- DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/DistrictEnergy/DHRunLPModel.cs b/DistrictEnergy/DHRunLPModel.cs index b5d93cb..892d098 100644 --- a/DistrictEnergy/DHRunLPModel.cs +++ b/DistrictEnergy/DHRunLPModel.cs @@ -264,7 +264,7 @@ private void Main() for (int t = dt; t < timeSteps * dt; t += dt) { objective.SetCoefficient(P[(t, supplymodule)], - supplymodule.F * DistrictEnergy.Settings.AnnuityFactor + supplymodule.V * dt); + supplymodule.F * DistrictEnergy.Settings.AnnuityFactor / dt + supplymodule.V); } } @@ -273,7 +273,7 @@ private void Main() for (int t = dt; t < timeSteps * dt; t += dt) { objective.SetCoefficient(S[(t, storage)], - storage.F * DistrictEnergy.Settings.AnnuityFactor + storage.V * dt); + storage.F * DistrictEnergy.Settings.AnnuityFactor / dt + storage.V); } } diff --git a/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs b/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs index 49d5d7c..20006df 100644 --- a/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs +++ b/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows.Media; @@ -42,7 +42,8 @@ public FixedCost(IThermalPlantSettings plant, byte alpha = 255) Fill = new SolidColorBrush(Color.FromArgb(alpha, color.R, color.G, color.B)); Name = plant.Name + " Fixed Cost"; if (plant.Output != null) - Cost = plant.Output.Max() * DistrictControl.PlanningSettings.AnnuityFactor * plant.F; + Cost = plant.Output.Max() * DistrictControl.PlanningSettings.AnnuityFactor * plant.F / + (8760 / DistrictControl.PlanningSettings.TimeSteps); } } From 27dd1514434ad5537cc5e218e36107c825c0a0c0 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 19:45:29 -0400 Subject: [PATCH 11/12] Sets the Export price to the ElectricityDollars --- DistrictEnergy/DHRunLPModel.cs | 5 +++-- DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DistrictEnergy/DHRunLPModel.cs b/DistrictEnergy/DHRunLPModel.cs index 892d098..54f2448 100644 --- a/DistrictEnergy/DHRunLPModel.cs +++ b/DistrictEnergy/DHRunLPModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using DistrictEnergy.Helpers; @@ -8,6 +8,7 @@ using Google.OrTools.LinearSolver; using Rhino; using Rhino.Commands; +using Umi.RhinoServices.Context; namespace DistrictEnergy { @@ -279,7 +280,7 @@ private void Main() foreach (var variable in E) { - objective.SetCoefficient(variable.Value, 1000000); + objective.SetCoefficient(variable.Value, UmiContext.Current.ProjectSettings.ElectricityDollars); } objective.SetMinimization(); diff --git a/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs b/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs index 20006df..936eeda 100644 --- a/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs +++ b/DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Windows.Media; From 9980818b57f22c9042a6e439141e10e85e536000 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Thu, 30 Apr 2020 19:50:21 -0400 Subject: [PATCH 12/12] Bumps version to 2.0.2 --- DistrictEnergy/Properties/AssemblyInfo.cs | 2 +- SetupProject/DistrictPlugInInstaller.wixproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DistrictEnergy/Properties/AssemblyInfo.cs b/DistrictEnergy/Properties/AssemblyInfo.cs index 6b94467..563a144 100644 --- a/DistrictEnergy/Properties/AssemblyInfo.cs +++ b/DistrictEnergy/Properties/AssemblyInfo.cs @@ -24,7 +24,7 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: AssemblyProduct("DistricEnergyPlugIn")] -[assembly: AssemblyVersion("2.0.1.*")] +[assembly: AssemblyVersion("2.0.2.*")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/SetupProject/DistrictPlugInInstaller.wixproj b/SetupProject/DistrictPlugInInstaller.wixproj index 80c82b0..2e77824 100644 --- a/SetupProject/DistrictPlugInInstaller.wixproj +++ b/SetupProject/DistrictPlugInInstaller.wixproj @@ -6,7 +6,7 @@ 3.10 2a10a76b-558f-424d-965b-d2c84703cee0 2.0 - DistrictPluginInstaller-4.433-2020-dev-2.0.1 + DistrictPluginInstaller-4.433-2020-dev-2.0.2 Package DistrictPlugInInstaller