Skip to content

Commit

Permalink
Merge branch 'release/v2.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelduchesne committed May 4, 2020
2 parents 3970613 + 391c331 commit a2c61b3
Show file tree
Hide file tree
Showing 39 changed files with 4,831 additions and 4,582 deletions.
30 changes: 25 additions & 5 deletions DistrictEnergy/DHRunLPModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,26 @@ LinearExpr TotalDemand(LoadTypes loadType1, int t)
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;
LpModel.Add(inputFlow.Value * inputFlow.Key.Item2.ConversionMatrix[loadType] <= inputFlow.Key.Item2.CapacityFactor * TotalDemand(loadType, i)
);
var plant = inputFlow.Key.Item2;
var loadType = plant.OutputType;
LpModel.Add(inputFlow.Value * plant.ConversionMatrix[loadType] <= plant.CapacityFactor * TotalDemand(loadType, i));
}

// Solar & Wind Constraints
// Forced Capacity Constraints
foreach (var plant in DistrictControl.Instance.ListOfPlantSettings.OfType<Dispatchable>())
{
if (plant.IsForced)
{
for (int t = 0; t < timeSteps * dt; t += dt)
{
var loadType = plant.OutputType;
LpModel.Add(P[(t, plant)] * plant.ConversionMatrix[loadType] == plant.CapacityFactor * TotalDemand(loadType, t));
}
}
}

// Solar Constraints
foreach (var solarSupply in DistrictControl.Instance.ListOfPlantSettings.OfType<ISolar>())
{
for (int t = 0; t < timeSteps * dt; t += dt)
Expand All @@ -237,7 +250,7 @@ LinearExpr TotalDemand(LoadTypes loadType1, int t)
solarSupply.AvailableArea);
}
}
// Solar & Wind Constraints
// Wind Constraints
foreach (var windTurbine in DistrictControl.Instance.ListOfPlantSettings.OfType<IWind>())
{
for (int t = 0; t < timeSteps * dt; t += dt)
Expand Down Expand Up @@ -318,6 +331,12 @@ LinearExpr TotalDemand(LoadTypes loadType1, int t)
RhinoApp.WriteLine("Solution:");
RhinoApp.WriteLine("Optimal objective value = " + LpModel.Objective().Value());

double TotalActualDemand(LoadTypes outputType)
{
return P.Where(k => k.Key.Item2.ConversionMatrix.ContainsKey(outputType))
.Select(k => Math.Abs(k.Value.SolutionValue()) * k.Key.Item2.ConversionMatrix[outputType]).ToArray().Sum();
}

foreach (var plant in DistrictControl.Instance.ListOfPlantSettings.OfType<Dispatchable>())
{
var solutionValues = P.Where(o => o.Key.Item2.Name == plant.Name).Select(v => v.Value.SolutionValue());
Expand All @@ -326,6 +345,7 @@ LinearExpr TotalDemand(LoadTypes loadType1, int t)
plant.Input = solutionValues.ToDateTimePoint();
plant.Output = solutionValues.Select(x => x * plant.ConversionMatrix[plant.OutputType])
.ToDateTimePoint();
plant.CapacityFactor = Math.Round(solutionValues.Select(x => x * plant.ConversionMatrix[plant.OutputType]).Sum() / TotalActualDemand(plant.OutputType), 2);
RhinoApp.WriteLine($"{plant.Name} = {cap} Peak ; {energy} Annum");
}

Expand Down
2 changes: 1 addition & 1 deletion DistrictEnergy/Networks/Loads/PipeNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private double[] CalcInput()
foreach (var loads in DistrictControl.Instance.ListOfDistrictLoads.OfType<IBaseLoad>()
.Where(o => o.LoadType == LoadType))
{
var adjustedLoad = loads.Input.Select(x => x * RelativeLoss).ToArray();
var adjustedLoad = loads.Input.Select(x => x * RelativeLoss).ToArray();
for (int i = 0; i < final.Length; i++)
{
final[i] += adjustedLoad[i];
Expand Down
10 changes: 9 additions & 1 deletion DistrictEnergy/Networks/ThermalPlants/AbsorptionChiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.Serialization;
using System.Windows.Media;
using DistrictEnergy.Helpers;
using DistrictEnergy.ViewModels;
using LiveCharts.Defaults;

namespace DistrictEnergy.Networks.ThermalPlants
Expand Down Expand Up @@ -57,7 +58,14 @@ 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 double CapacityFactor
{
get => OFF_ABS;
set => ChilledWaterViewModel.Instance.OFF_ABS = value * 100;
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Cooling, CCOP_ABS},
Expand Down
13 changes: 7 additions & 6 deletions DistrictEnergy/Networks/ThermalPlants/BatteryBank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Media;
using DistrictEnergy.Helpers;
using LiveCharts.Defaults;
using Newtonsoft.Json;

namespace DistrictEnergy.Networks.ThermalPlants
{
Expand Down Expand Up @@ -59,12 +60,12 @@ public BatteryBank()
public override Dictionary<LoadTypes, double> ConversionMatrix { get; set; }
public double Efficiency => ConversionMatrix[OutputType];
public override SolidColorBrush Fill { get; set; } = new SolidColorBrush(Color.FromRgb(231, 71, 126));
public override double ChargingEfficiency => 1 - LOSS_BAT;
public override double DischargingEfficiency => 1 - LOSS_BAT;
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();
[JsonIgnore] public override double ChargingEfficiency => 1 - LOSS_BAT;
[JsonIgnore] public override double DischargingEfficiency => 1 - LOSS_BAT;
[JsonIgnore] public override double MaxChargingRate => Capacity > 0 ? Capacity / AUT_BAT : 0;
[JsonIgnore] public override double MaxDischargingRate => Capacity > 0 ? Capacity / AUT_BAT : 0;
[JsonIgnore] public override double StartingCapacity => Capacity * BAT_START;
[JsonIgnore] 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;
Expand Down
10 changes: 9 additions & 1 deletion DistrictEnergy/Networks/ThermalPlants/CombinedHeatNPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.Serialization;
using System.Windows.Media;
using DistrictEnergy.Helpers;
using DistrictEnergy.ViewModels;
using LiveCharts.Defaults;

namespace DistrictEnergy.Networks.ThermalPlants
Expand Down Expand Up @@ -82,7 +83,14 @@ private double CalcCapacity()
public override Guid Id { get; set; } = Guid.NewGuid();
public override LoadTypes OutputType => TMOD_CHP;
public override LoadTypes InputType => LoadTypes.Gas;
public override double CapacityFactor => OFF_CHP;
public override double CapacityFactor
{
get => OFF_CHP;
set => CombinedHeatAndPowerViewModel.Instance.OFF_CHP = value * 100;
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Elec, EFF_CHP},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using DistrictEnergy.Helpers;
using DistrictEnergy.ViewModels;
using LiveCharts.Defaults;

namespace DistrictEnergy.Networks.ThermalPlants
Expand All @@ -24,8 +25,16 @@ public double ComputeHeatBalance(double demand, int i)

public double[] Used = new double[8760];
public override LoadTypes OutputType => LoadTypes.Cooling;
public override double OFF_Custom { get; set; } = 1;
public override LoadTypes InputType => LoadTypes.Custom;
public override double CapacityFactor => 1;
public override double CapacityFactor
{
get => OFF_Custom;
set { }
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Cooling, 1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ public CustomElectricitySupplyModule()
}

public override LoadTypes OutputType => LoadTypes.Elec;
public override double OFF_Custom { get; set; } = 1;
public override LoadTypes InputType => LoadTypes.Custom;
public override double CapacityFactor => 1;
public override double CapacityFactor
{
get => OFF_Custom;
set => OFF_Custom = value;
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Elec, 1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal abstract class CustomEnergySupplyModule: Dispatchable

public abstract override LoadTypes OutputType { get; }

public abstract double OFF_Custom { get; set; }

public abstract override double F { get; set; }
public abstract override double V { get; set; }
public abstract override double Capacity { get; }
Expand Down Expand Up @@ -103,11 +105,12 @@ public override SolidColorBrush Fill
set => throw new NotImplementedException();
}

public override double CapacityFactor { get; }
public override double CapacityFactor { get; set; }

public Color Color { get; set; } = Color.FromRgb(200, 1, 0);
public abstract override Dictionary<LoadTypes, double> ConversionMatrix { get; }
public abstract override double Efficiency { get; }
public abstract override bool IsForced { get; set; }

public double ComputeHeatBalance(double demand, double chiller, double solar, int i)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ public CustomHeatingSupplyModule()
}

public override LoadTypes OutputType => LoadTypes.Heating;
public override double OFF_Custom { get; set; } = 1;
public override LoadTypes InputType => LoadTypes.Custom;
public override double CapacityFactor => 1;
public override double CapacityFactor => OFF_Custom;
public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Heating, 1}
Expand Down
3 changes: 2 additions & 1 deletion DistrictEnergy/Networks/ThermalPlants/Dispatchable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ 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 abstract double CapacityFactor { get; set; }
public abstract bool IsForced { get; set; }
}

public class FixedCost : GraphCost
Expand Down
9 changes: 8 additions & 1 deletion DistrictEnergy/Networks/ThermalPlants/ElectricChiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ 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 double CapacityFactor
{
get => 1;
set {}
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Cooling, CCOP_ECH},
Expand Down
10 changes: 9 additions & 1 deletion DistrictEnergy/Networks/ThermalPlants/ElectricHeatPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.Serialization;
using System.Windows.Media;
using DistrictEnergy.Helpers;
using DistrictEnergy.ViewModels;
using LiveCharts.Defaults;

namespace DistrictEnergy.Networks.ThermalPlants
Expand Down Expand Up @@ -52,7 +53,14 @@ 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 double CapacityFactor
{
get => OFF_EHP;
set => HotWaterViewModel.Instance.OFF_EHP = value * 100;
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Heating, HCOP_EHP },
Expand Down
9 changes: 8 additions & 1 deletion DistrictEnergy/Networks/ThermalPlants/GridElectricity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ 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 double CapacityFactor
{
get => 1;
set { }
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Elec, 1}
Expand Down
9 changes: 8 additions & 1 deletion DistrictEnergy/Networks/ThermalPlants/GridGas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ 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 double CapacityFactor
{
get => 1;
set { }
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Gas, 1}
Expand Down
13 changes: 7 additions & 6 deletions DistrictEnergy/Networks/ThermalPlants/HotWaterStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Windows.Media;
using DistrictEnergy.Helpers;
using LiveCharts.Defaults;
using Newtonsoft.Json;

namespace DistrictEnergy.Networks.ThermalPlants
{
Expand Down Expand Up @@ -51,12 +52,12 @@ public HotWaterStorage()
public override Dictionary<LoadTypes, double> ConversionMatrix { get; set; }
public double Efficiency => ConversionMatrix[OutputType];
public override SolidColorBrush Fill { get; set; } = new SolidColorBrush(Color.FromRgb(253, 199, 204));
public override double ChargingEfficiency => 1 - LOSS_HWT;
public override double DischargingEfficiency => 1 - LOSS_HWT;
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();
[JsonIgnore] public override double ChargingEfficiency => 1 - LOSS_HWT;
[JsonIgnore] public override double DischargingEfficiency => 1 - LOSS_HWT;
[JsonIgnore] public override double MaxChargingRate => Capacity > 0 ? Capacity / AUT_HWT : 0;
[JsonIgnore] public override double MaxDischargingRate => Capacity > 0 ? Capacity / AUT_HWT : 0;
[JsonIgnore] public override double StartingCapacity => Capacity * TANK_START;
[JsonIgnore] 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;
Expand Down
2 changes: 1 addition & 1 deletion DistrictEnergy/Networks/ThermalPlants/ISolar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace DistrictEnergy.Networks.ThermalPlants
/// </summary>
internal interface ISolar : IThermalPlantSettings
{
double AvailableArea { get; }
[JsonIgnore] double AvailableArea { get; }
[JsonIgnore] double[] SolarAvailableInput { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface IThermalPlantSettings
/// </summary>
[DataMember]
[DefaultValue(double.PositiveInfinity)]
double Capacity { get; }
[JsonIgnore] double Capacity { get; }

/// <summary>
/// Name of the Supply Module
Expand Down Expand Up @@ -68,6 +68,7 @@ public interface IThermalPlantSettings
[JsonIgnore] GraphCost FixedCost { get; }
[JsonIgnore] GraphCost VariableCost { get; }
[JsonIgnore] double TotalCost { get; }
[JsonIgnore] double CapacityFactor { get; }
[JsonIgnore] double CapacityFactor { get; set; }
bool IsForced { get; set; }
}
}
9 changes: 8 additions & 1 deletion DistrictEnergy/Networks/ThermalPlants/NatGasBoiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ 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 double CapacityFactor
{
get => 1;
set { }
}

public override bool IsForced { get; set; }

public override Dictionary<LoadTypes, double> ConversionMatrix => new Dictionary<LoadTypes, double>()
{
{LoadTypes.Heating, EFF_NGB},
Expand Down
Loading

0 comments on commit a2c61b3

Please sign in to comment.