Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit fb69e30e authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Merge branch 'dev/RefactoringAAUX' into feature/VECTO-1190-declaration-mode-for-heavy-buses

parents 8616ab28 6f61cd5b
Branches
Tags
No related merge requests found
Showing
with 3411 additions and 0 deletions
// Copyright 2017 European Union.
// Licensed under the EUPL (the 'Licence');
//
// * You may not use this work except in compliance with the Licence.
// * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
// * Unless required by applicable law or agreed to in writing,
// software distributed under the Licence is distributed on an "AS IS" basis,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the LICENSE.txt for the specific language governing permissions and limitations.
using System;
using System.Collections.Generic;
using System.Linq;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
public class ResultCard : IResultCard
{
private List<SmartResult> _results;
// Constructor
public ResultCard(List<SmartResult> results)
{
if (results == null)
throw new ArgumentException("A list of smart results must be supplied.");
_results = results;
}
// Public class outputs
public List<SmartResult> Results
{
get { return _results; }
}
public Ampere GetSmartCurrentResult(Ampere Amps)
{
if (_results.Count < 2)
return 10.SI<Ampere>();
return GetOrInterpolate(Amps.Value()).SI<Ampere>();
}
// Helpers
/// <summary>
/// ''' Gets or interpolates value (A)
/// ''' </summary>
/// ''' <param name="amps"></param>
/// ''' <returns></returns>
/// ''' <remarks></remarks>
private double GetOrInterpolate(double amps)
{
double pre;
double post;
double dAmps;
double dSmartAmps;
double smartAmpsSlope;
double smartAmps;
double maxKey;
double minKey;
maxKey = _results.Max().Amps;
minKey = _results.Min().Amps;
var compareKey = new SmartResult(amps, 0);
// Is on boundary check
if (_results.Contains(compareKey))
return _results.OrderBy(x => x.Amps).First(x => x.Amps == compareKey.Amps).SmartAmps;
// Is over map - Extrapolate
if (amps > maxKey) {
// get the entries before and after the supplied key
pre = (from a in _results
orderby a.Amps
where a.Amps < maxKey
select a).Last().Amps;
post = maxKey;
// get the delta values
dAmps = post - pre;
dSmartAmps = (from da in _results
orderby da.Amps
where da.Amps == post
select da).First().SmartAmps - (from da in _results
orderby da.Amps
where da.Amps == pre
select da).First().SmartAmps;
// calculate the slopes
smartAmpsSlope = dSmartAmps / dAmps;
// calculate the new values
smartAmps = ((amps - post) * smartAmpsSlope) + (from da in _results
orderby da.Amps
where da.Amps == post
select da).First().SmartAmps;
return smartAmps;
}
// Is under map - Extrapolate
if (amps < minKey) {
// get the entries before and after the supplied key
// Post is the first entry and pre is the penultimate to first entry
post = minKey;
pre = (from k in _results
orderby k.Amps
where k.Amps > minKey
select k).First().Amps;
// get the delta values
dAmps = post - pre;
dSmartAmps = (from da in _results
orderby da.Amps
where da.Amps == post
select da).First().SmartAmps - (from da in _results
orderby da.Amps
where da.Amps == pre
select da).First().SmartAmps;
// calculate the slopes
smartAmpsSlope = dSmartAmps / dAmps;
// calculate the new values
smartAmps = ((amps - post) * smartAmpsSlope) + (from da in _results
orderby da.Amps
where da.Amps == post
select da).First().SmartAmps;
return smartAmps;
}
// Is Inside map - Interpolate
// get the entries before and after the supplied rpm
pre = (from m in _results
orderby m.Amps
where m.Amps < amps
select m).Last().Amps;
post = (from m in _results
where m.Amps > amps
select m).First().Amps;
// get the delta values for rpm and the map values
dAmps = post - pre;
dSmartAmps = (from da in _results
orderby da.Amps
where da.Amps == post
select da).First().SmartAmps - (from da in _results
orderby da.Amps
where da.Amps == pre
select da).First().SmartAmps;
// calculate the slopes
smartAmpsSlope = dSmartAmps / dAmps;
// calculate the new values
smartAmps = ((amps - post) * smartAmpsSlope) + (from da in _results
orderby da.Amps
where da.Amps == post
select da).First().SmartAmps;
return smartAmps;
}
}
}
using System;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public class Bus : IBus
{
// Private Property Backing
private int _id;
private string _model;
private string _floorType;
private string _engineType;
private double _lengthInMetres;
private double _widthInMetres;
private double _heightInMetres;
private int _registeredPassengers;
private bool _isDoubleDecker;
public int Id
{
get {
return _id;
}
}
public string Model
{
get {
return _model;
}
set {
if (!ModelOK(value))
throw new ArgumentException("Model argument is invalid");
_model = value;
}
}
public string FloorType
{
get {
return _floorType;
}
set {
if (!FloorTypeOK(value))
throw new ArgumentException("Model argument is invalid");
_floorType = value;
}
}
public string EngineType
{
get {
return _engineType;
}
set {
if (!EngineOK(value))
throw new ArgumentException("EngineType argument is invalid");
_engineType = value;
}
}
public double LengthInMetres
{
get {
return _lengthInMetres;
}
set {
if (!DimensionOK(value))
throw new ArgumentException("Invalid Length");
_lengthInMetres = value;
}
}
public double WidthInMetres
{
get {
return _widthInMetres;
}
set {
if (!DimensionOK(value))
throw new ArgumentException("Invalid Width");
_widthInMetres = value;
}
}
public double HeightInMetres
{
get {
return _heightInMetres;
}
set {
if (!DimensionOK(value))
throw new ArgumentException("Invalid Height");
_heightInMetres = value;
}
}
public int RegisteredPassengers
{
get {
return _registeredPassengers;
}
set {
if (!PassengersOK(value))
throw new ArgumentException("Invalid Number Of Passengers");
_registeredPassengers = value;
}
}
public bool IsDoubleDecker
{
get {
return _isDoubleDecker;
}
set {
_isDoubleDecker = value;
}
}
// Constructors
public Bus(int _id, string _model, string _floorType, string _engineType, double _lengthInMetres, double _widthInMetres, double _heightInMetres, int _registeredPassengers, bool _doubleDecker)
{
// Validity checks.
if (!ModelOK(_model))
throw new ArgumentException("Model argument is invalid");
if (!FloorTypeOK(_floorType))
throw new ArgumentException("Model argument is invalid");
if (!EngineOK(_engineType))
throw new ArgumentException("EngineType argument is invalid");
if (!DimensionOK(_lengthInMetres))
throw new ArgumentException("Invalid Length");
if (!DimensionOK(_widthInMetres))
throw new ArgumentException("Invalid Width");
if (!DimensionOK(_heightInMetres))
throw new ArgumentException("Invalid Height");
if (!PassengersOK(_registeredPassengers))
throw new ArgumentException("Invalid Number Of Passengers");
// Set Private Members
this._id = _id;
this._model = _model;
this._floorType = _floorType;
this._engineType = _engineType;
this._lengthInMetres = _lengthInMetres;
this._widthInMetres = _widthInMetres;
this._heightInMetres = _heightInMetres;
this._registeredPassengers = _registeredPassengers;
this._isDoubleDecker = _doubleDecker;
}
// Construction Validators Helpers
private bool ModelOK(string model)
{
model = model.ToLower();
if (model == null || model.Trim().Length == 0)
return false;
return true;
}
private bool FloorTypeOK(string floorType)
{
floorType = floorType.ToLower();
if (floorType == null || floorType.Trim().Length == 0)
return false;
if (floorType != "raised floor" && floorType != "low floor" && floorType != "semi low floor")
return false;
return true;
}
private bool EngineOK(string engine)
{
engine = engine.ToLower();
if (engine == null || engine.Trim().Length == 0)
return false;
if (engine != "diesel" && engine != "gas" && engine != "hybrid")
return false;
return true;
}
private bool DimensionOK(double dimension)
{
return dimension > 0.5;
}
private bool PassengersOK(int registeredPassengers)
{
return registeredPassengers > 1;
}
// To String function
public override string ToString()
{
return string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", _model, _floorType, _engineType, _lengthInMetres, _widthInMetres, _heightInMetres, _registeredPassengers, _isDoubleDecker);
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public class BusDatabase : IBusDatabase
{
private List<IBus> buses = new List<IBus>();
private List<IBus> selectListBuses = new List<IBus>();
public bool AddBus(IBus bus)
{
var result = true;
try {
buses.Add(bus);
} catch (Exception ex) {
result = false;
}
return result;
}
public List<IBus> GetBuses(string busModel, bool AsSelectList = false)
{
if (AsSelectList) {
selectListBuses = new List<IBus>();
selectListBuses = buses.Where(v => v.Model == "" || v.Model.ToLower().Contains(busModel.ToLower())).ToList();
selectListBuses.Insert(0, new Bus(0, "<Select>", "low floor", "gas", 1, 1, 1, 2, false));
return selectListBuses;
}
return buses.Where(v => v.Model == "" || v.Model.ToLower().Contains(busModel.ToLower())).ToList();
}
public bool Initialise(string filepath)
{
var returnStatus = true;
if (File.Exists(filepath)) {
using (var sr = new StreamReader(filepath)) {
// get array og lines fron csv
var lines = sr.ReadToEnd().Split(new [] { Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
// Must have at least 2 entries in map to make it usable [dont forget the header row]
if (lines.Length < 2) {
return false;
}
var firstline = true;
var id = 1;
foreach (var line in lines) {
if (!firstline) {
// split the line
var elements = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// 7 or 8 entries per line required
if ((elements.Length != 7 && elements.Length != 8))
throw new ArgumentException("Incorrect number of values in csv file");
// Bus
try {
var bus = new Bus(id, elements[0], elements[1], elements[2], double.Parse(elements[3], CultureInfo.InvariantCulture), double.Parse(elements[4], CultureInfo.InvariantCulture), double.Parse(elements[5], CultureInfo.InvariantCulture), int.Parse(elements[6], CultureInfo.InvariantCulture), elements.Length == 8 ? bool.Parse(elements[7]) : false);
buses.Add(bus);
} catch (Exception ex) {
// Indicate problems
returnStatus = false;
}
id = id + 1;
} else {
firstline = false;
}
}
}
} else {
returnStatus = false;
}
var uniqueBuses = buses.Select(b => b.Model).Distinct().Count();
if (buses.Count != uniqueBuses) {
returnStatus = false;
}
return returnStatus;
}
public bool UpdateBus(int id, IBus bus)
{
var result = true;
try {
var existingBus = buses.Single(b => b.Id == id);
existingBus.Model = bus.Model;
existingBus.RegisteredPassengers = bus.RegisteredPassengers;
existingBus.FloorType = bus.FloorType;
existingBus.LengthInMetres = bus.LengthInMetres;
existingBus.WidthInMetres = bus.WidthInMetres;
existingBus.HeightInMetres = bus.HeightInMetres;
existingBus.IsDoubleDecker = bus.IsDoubleDecker;
} catch (Exception ex) {
result = false;
}
return result;
}
public bool Save(string filepath)
{
var result = true;
var output = new StringBuilder();
try {
output.AppendLine("Bus Model,Type,engine Type,length in m,wide in m,height in m,registered passengers,double decker");
foreach (var bus in buses)
output.AppendLine(bus.ToString());
File.WriteAllText(filepath, output.ToString());
} catch (Exception ex) {
result = false;
}
return result;
}
}
}
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public enum BusEngineType
{
Diesal = 1,
Gas = 2,
Hybrid = 3
}
}
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC {
public class DeleteCell : DataGridViewButtonCell
{
public string ToolTip { get; set; } = "Delete tech benefit line";
private Image del = null; //= My.Resources.ResourceManager.GetObject("Delete") as Image;
protected override void Paint(
Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
if (del == null) {
var assembly = Assembly.GetExecutingAssembly();
var file = assembly.GetManifestResourceStream("Delete");
del = Image.FromStream(file);
}
advancedBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
this.ToolTipText = ToolTip;
cellStyle.BackColor = Color.White;
base.Paint(
graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle,
advancedBorderStyle, paintParts);
graphics.DrawImage(del, cellBounds);
}
}
public class DeleteAlternatorCell : DataGridViewButtonCell
{
public string ToolTip { get; set; } = "Delete alternator";
protected Image del = null;
//private Image del = My.Resources.ResourceManager.GetObject("Delete") as Image;
protected override void Paint(
Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState,
object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
if (del == null) {
var assembly = Assembly.GetExecutingAssembly();
var file = assembly.GetManifestResourceStream("Delete");
del = Image.FromStream(file);
}
advancedBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Single;
this.ToolTipText = ToolTip;
cellStyle.BackColor = Color.White;
base.Paint(
graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle,
advancedBorderStyle, paintParts);
graphics.DrawImage(del, cellBounds);
}
}
}
\ No newline at end of file
using System.Windows.Forms;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC {
public class DeleteColumn : DataGridViewButtonColumn
{
public DeleteColumn() : base()
{
this.CellTemplate = new DeleteCell();
}
}
public class DeleteAlternatorColumn : DataGridViewButtonColumn
{
public DeleteAlternatorColumn() : base()
{
this.CellTemplate = new DeleteAlternatorCell();
}
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.Linq;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.HVAC;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public class EnvironmentalCondition : IEnvironmentalCondition
{
private double _temperature;
private double _solar;
private double _weight;
public EnvironmentalCondition(double temperature, double solar, double weight)
{
_temperature = temperature;
_solar = solar;
_weight = weight;
}
public double GetTemperature()
{
return _temperature;
}
public double GetSolar()
{
return _solar;
}
public double GetWeighting()
{
return _weight;
}
public double GetNormalisedWeighting(List<IEnvironmentalCondition> map)
{
return _weight / map.Sum(w => w.GetWeighting());
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.HVAC;
using TUGraz.VectoCore.BusAuxiliaries.Util;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public class EnvironmentalConditionsMap : IEnvironmentalConditionsMap
{
private string filePath;
private string vectoDirectory;
private List<IEnvironmentalCondition> _map = new List<IEnvironmentalCondition>();
public EnvironmentalConditionsMap(string filepath, string vectoDirectory)
{
this.filePath = filepath;
this.vectoDirectory = vectoDirectory;
Initialise();
}
public bool Initialise()
{
if ((!string.IsNullOrWhiteSpace(filePath))) {
filePath = FilePathUtils.ResolveFilePath(vectoDirectory, filePath);
if (File.Exists(filePath)) {
using (var sr = new StreamReader(filePath)) {
// get array og lines fron csv
var lines = sr.ReadToEnd().Split(new [] { Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
// Must have at least 1 entries to make it usable [dont forget the header row]
if ((lines.Count() < 2))
return false;
var firstline = true;
foreach (var line in lines) {
if (!firstline) {
// split the line
var elements = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// 3 entries per line required
if ((elements.Length != 4))
return false;
// Add environment condition
var newCondition = new EnvironmentalCondition(double.Parse(elements[1], CultureInfo.InvariantCulture), double.Parse(elements[2], CultureInfo.InvariantCulture), double.Parse(elements[3], CultureInfo.InvariantCulture));
_map.Add(newCondition);
} else
firstline = false;
}
}
} else
return false;
}
return true;
}
public List<IEnvironmentalCondition> GetEnvironmentalConditions()
{
return _map;
}
}
}
// Copyright 2017 European Union.
// Licensed under the EUPL (the 'Licence');
//
// * You may not use this work except in compliance with the Licence.
// * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
// * Unless required by applicable law or agreed to in writing,
// software distributed under the Licence is distributed on an "AS IS" basis,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the LICENSE.txt for the specific language governing permissions and limitations.
using Newtonsoft.Json;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.HVAC;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public class HVACConstants : IHVACConstants
{
[JsonProperty("FuelDensity")]
private readonly double _fuelDensity;
[JsonProperty("DieselGCVJperGram")]
private readonly double _dieselGcvJperGram = 44800;
public HVACConstants()
{
_fuelDensity = 835; // .SI(Of KilogramPerCubicMeter)()
}
public HVACConstants(KilogramPerCubicMeter fuelDensitySingle)
{
_fuelDensity = fuelDensitySingle.Value();
}
[JsonIgnore]
public JoulePerKilogramm DieselGCVJperGram
{
get {
return _dieselGcvJperGram.SI(Unit.SI.Joule.Per.Gramm).Cast<JoulePerKilogramm>();
}
}
[JsonIgnore()]
public KilogramPerCubicMeter FuelDensity
{
get {
return _fuelDensity.SI<KilogramPerCubicMeter>();
}
}
[JsonIgnore()]
public double FuelDensityAsGramPerLiter
{
get {
return _fuelDensity * 1000;
}
}
}
}
// Copyright 2017 European Union.
// Licensed under the EUPL (the 'Licence');
//
// * You may not use this work except in compliance with the Licence.
// * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
// * Unless required by applicable law or agreed to in writing,
// software distributed under the Licence is distributed on an "AS IS" basis,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the LICENSE.txt for the specific language governing permissions and limitations.
using System;
using System.IO;
using System.Linq;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.HVAC;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public class HVACSteadyStateModel : IHVACSteadyStateModel
{
public float HVACElectricalLoadPowerWatts { get; set; }
public float HVACFuellingLitresPerHour { get; set; }
public float HVACMechanicalLoadPowerWatts { get; set; }
// Constructors
public HVACSteadyStateModel()
{
}
public HVACSteadyStateModel(float elecPowerW, float mechPowerW, float fuellingLPH)
{
HVACElectricalLoadPowerWatts = elecPowerW;
HVACFuellingLitresPerHour = mechPowerW;
HVACMechanicalLoadPowerWatts = fuellingLPH;
}
// Implementation
public bool SetValuesFromMap(string filePath, ref string message)
{
string myData;
string[] linesArray;
var vbLf = '\n';
// Check map file can be found.
try {
myData = System.IO.File.ReadAllText(filePath, System.Text.Encoding.UTF8);
} catch (FileNotFoundException ex) {
message = "HVAC Steady State Model : The map file was not found";
return false;
}
linesArray = (from s in myData.Split(vbLf)
select s.Trim()).ToArray();
// Check count is at least 2 rows
if (linesArray.Count() < 2) {
message = "HVAC Steady State Model : Insufficient Lines in this File";
return false;
}
// validate headers
var headers = linesArray[0].Split(',');
if (headers.Length != 3 || headers[0].Trim() != "[Electrical Power (w)]" || headers[1].Trim() != "[Mechanical Power (w)]" || headers[2].Trim() != "[Fuelling (L/H)]") {
message = "HVAC Steady State Model : Column headers in *.AHSM file being read are incompatable.";
return false;
}
// validate values
var values = linesArray[1].Split(',');
double unused;
if (headers.Length != 3 || !double.TryParse(values[0], out unused) || !double.TryParse(values[1], out unused) || !double.TryParse(values[2], out unused)) {
message = "Steady State Model : Unable to confirm numeric values in the *.AHSM file being read.";
return false;
}
// OK we have the values so lets set the properties
float out1, out2, out3;
out1 = HVACElectricalLoadPowerWatts;
out2 = HVACMechanicalLoadPowerWatts;
out3 = HVACFuellingLitresPerHour;
try {
HVACElectricalLoadPowerWatts = float.Parse(values[0]);
HVACMechanicalLoadPowerWatts = float.Parse(values[1]);
HVACFuellingLitresPerHour = float.Parse(values[2]);
} catch (Exception ex) {
// Restore in the event of failure to fully assign
HVACElectricalLoadPowerWatts = out1;
HVACMechanicalLoadPowerWatts = out2;
HVACFuellingLitresPerHour = out3;
// Return result
message = "Steady State Model : Unable to parse the values in the *.AHSM file being read no values were harmed in reading of this file.";
return false;
}
return true;
}
}
}
// Copyright 2017 European Union.
// Licensed under the EUPL (the 'Licence');
//
// * You may not use this work except in compliance with the Licence.
// * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl
// * Unless required by applicable law or agreed to in writing,
// software distributed under the Licence is distributed on an "AS IS" basis,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the LICENSE.txt for the specific language governing permissions and limitations.
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.HVAC;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public class HVACUserInputsConfig : IHVACUserInputsConfig
{
// Constructor
public HVACUserInputsConfig(string ssmFilePath, string busDatabasePath, bool isDisabled)
{
this.SSMFilePath = ssmFilePath;
this.BusDatabasePath = busDatabasePath;
this.SSMDisabled = isDisabled;
}
public string SSMFilePath { get; set; }
public string BusDatabasePath { get; set; }
public bool SSMDisabled { get; set; }
}
}
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public interface IBus
{
int Id { get; }
string Model { get; set; }
string FloorType { get; set; }
string EngineType { get; set; }
double LengthInMetres { get; set; }
double WidthInMetres { get; set; }
double HeightInMetres { get; set; }
int RegisteredPassengers { get; set; }
bool IsDoubleDecker { get; set; }
}
}
using System.Collections.Generic;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public interface IBusDatabase
{
bool AddBus(IBus bus);
List<IBus> GetBuses(string busModel, bool AsSelectList = false);
bool Initialise(string busFileCSV);
bool UpdateBus(int id, IBus bus);
bool Save(string filepath);
}
}
using System;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.HVAC;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC
{
public class M01Impl : AbstractModule, IM1_AverageHVACLoadDemand
{
protected IM0_NonSmart_AlternatorsSetEfficiency _m0;
protected Double _alternatorGearEfficiency;
protected Double _compressorGearEfficiency;
protected ISignals _signals;
protected Volt _powernetVoltage;
protected ISSMTOOL _steadyStateModel;
protected Watt _ElectricalPowerW;
protected Watt _MechanicalPowerW;
protected LiterPerSecond _FuelingLPerH;
public M01Impl(IM0_NonSmart_AlternatorsSetEfficiency m0, double altGearEfficiency, double compressorGearEfficiency, Volt powernetVoltage, ISignals signals, ISSMTOOL ssm)
{
//'Sanity Check - Illegal operations without all params.
if (m0 == null) {
throw new ArgumentException("Module0 as supplied is null");
}
if (altGearEfficiency < ElectricConstants.AlternatorPulleyEfficiencyMin ||
altGearEfficiency > ElectricConstants.AlternatorPulleyEfficiencyMax) {
throw new ArgumentException(
string.Format
(
"Gear efficiency must be between {0} and {1}",
ElectricConstants.AlternatorPulleyEfficiencyMin, ElectricConstants.AlternatorPulleyEfficiencyMax));
}
if (signals == null) {
throw new Exception("Signals object as supplied is null");
}
if (powernetVoltage < ElectricConstants.PowenetVoltageMin || powernetVoltage > ElectricConstants.PowenetVoltageMax) {
throw new ArgumentException(
string.Format(
"PowenetVoltage supplied must be in the range {0} to {1}", ElectricConstants.PowenetVoltageMin,
ElectricConstants.PowenetVoltageMax));
}
if (ssm == null ) {
throw new ArgumentException("Steady State model was not supplied");
}
if (compressorGearEfficiency < 0 || altGearEfficiency > 1) {
throw new ArgumentException(String.Format("Compressor Gear efficiency must be between {0} and {1}", 0, 1));
}
//'Assign
_m0 = m0;
_alternatorGearEfficiency = altGearEfficiency;
_signals = signals;
_compressorGearEfficiency = compressorGearEfficiency;
_powernetVoltage = powernetVoltage;
_steadyStateModel = ssm;
_ElectricalPowerW = ssm.ElectricalWAdjusted.SI<Watt>();
_MechanicalPowerW = ssm.MechanicalWBaseAdjusted.SI<Watt>();
_FuelingLPerH = ssm.FuelPerHBaseAdjusted.SI(Unit.SI.Liter.Per.Hour).Cast<LiterPerSecond>(); // ' SI(Of LiterPerHour)()
}
#region Implementation of IM1_AverageHVACLoadDemand
public Watt AveragePowerDemandAtCrankFromHVACMechanicalsWatts()
{
return _MechanicalPowerW * (1 / _compressorGearEfficiency);
}
public Watt AveragePowerDemandAtAlternatorFromHVACElectricsWatts()
{
return _ElectricalPowerW;
}
public Watt AveragePowerDemandAtCrankFromHVACElectricsWatts()
{
return _ElectricalPowerW * (1 / _m0.AlternatorsEfficiency / _alternatorGearEfficiency);
}
public LiterPerSecond HVACFuelingLitresPerHour()
{
return _FuelingLPerH;
}
#endregion
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment