diff --git a/VECTOAux/VectoAuxiliaries/Electrics/AverageElectricalDemand.vb b/VECTOAux/VectoAuxiliaries/Electrics/AverageElectricalDemand.vb index 6cf5c5cd19d5b440df0920ea61bcdccbe621bf34..9acb645f5ad0b5a1738792d9c3b4e6ce5742dc4b 100644 --- a/VECTOAux/VectoAuxiliaries/Electrics/AverageElectricalDemand.vb +++ b/VECTOAux/VectoAuxiliaries/Electrics/AverageElectricalDemand.vb @@ -44,7 +44,7 @@ ''' <returns></returns> ''' <remarks></remarks> Public Function Initialise() As Boolean - Return True ''TODO: Initialisation of the alternator model + Return _alternator.Initialise() End Function ''' <summary> @@ -52,7 +52,7 @@ ''' </summary> ''' <returns></returns> ''' <remarks></remarks> - Public Function GetAveragePowerAtAlternator() As Single + Public Function GetAveragePowerDemandAtAlternator() As Single Dim total As Single = (From ctx In ElectricalConsumers Select ctx.Power).Sum() Return total @@ -65,7 +65,7 @@ ''' <returns></returns> ''' <remarks></remarks> Public Function GetAveragePowerAtCrank(ByVal engineRpm As Integer) As Single - Dim elecPower As Single = GetAveragePowerAtAlternator() + Dim elecPower As Single = GetAveragePowerDemandAtAlternator() Dim alternatorEfficiency As Single = _alternator.GetEfficiency(engineRpm) Dim demandFromAlternator As Single = elecPower / alternatorEfficiency Dim powerAtCrank As Single = demandFromAlternator / _alternator.PulleyGearEfficiency diff --git a/VECTOAux/VectoAuxiliaries/Hvac/AverageHVACLoadDemand.vb b/VECTOAux/VectoAuxiliaries/Hvac/AverageHVACLoadDemand.vb index 80e18987c4e2c917eed30c70e1ee06429739217e..bc349f24cab0fd3ea5c558103bf2a641fd72f0ce 100644 --- a/VECTOAux/VectoAuxiliaries/Hvac/AverageHVACLoadDemand.vb +++ b/VECTOAux/VectoAuxiliaries/Hvac/AverageHVACLoadDemand.vb @@ -9,6 +9,7 @@ Namespace Hvac Public Property Region As Integer Public Property Season As Integer + Public Sub New(ByVal map As IHVACMap, ByVal alternator As IAlternator, inputs As IHVACInputs) Me.map = map Me.alternator = alternator diff --git a/VECTOAux/VectoAuxiliaries/Pneumatics/AirFlowRateMechanicalDemandMap.vb b/VECTOAux/VectoAuxiliaries/Pneumatics/AirFlowRateMechanicalDemandMap.vb new file mode 100644 index 0000000000000000000000000000000000000000..913243455f7ef9f6a056dcb4cf5e0ec46eaa5883 --- /dev/null +++ b/VECTOAux/VectoAuxiliaries/Pneumatics/AirFlowRateMechanicalDemandMap.vb @@ -0,0 +1,80 @@ +Imports System.IO + +Namespace Pneumatics + + Public Class AirFlowRateMechanicalDemandMap + Implements IAirFlowRateMechanicalDemandMap + + Private _filePath As String + + Private _map As New Dictionary(Of Integer, Single) + + + Public Sub New(iFilePath As String) + + _filePath = iFilePath + + End Sub + + + Public Function Initialise() As Boolean Implements IAirFlowRateMechanicalDemandMap.Initialise + + If File.Exists(_filePath) Then + Using sr As StreamReader = New StreamReader(_filePath) + 'get array of lines from csv + Dim lines() As String = sr.ReadToEnd().Split(CType(Environment.NewLine, Char()), StringSplitOptions.RemoveEmptyEntries) + + 'Must have at least 2 entries in map to make it usable [dont forget the header row] + If lines.Length < 3 Then Throw New ArgumentException("Insufficient rows in csv to build a usable map") + + _map = New Dictionary(Of Integer, Single) + Dim firstline As Boolean = True + + For Each line As String In lines + If Not firstline Then + 'split the line + Dim elements() As String = line.Split(New Char() {","}, StringSplitOptions.RemoveEmptyEntries) + '2 entries per line required + If (elements.Length <> 2) Then Throw New ArgumentException("Incorrect number of values in csv file") + 'add values to map + _map.Add(elements(0), elements(1)) + + + 'Test For Non Numeric Data, + If (Not firstline AndAlso (Not IsNumeric(elements(0)) OrElse Not IsNumeric(elements(1)))) Then + Throw (New ArgumentException("SomeValues were not numeric")) + End If + + Else + firstline = False + End If + Next + End Using + Else + Throw New ArgumentException("supplied input file does not exist") + End If + + Return True + End Function + + Public Function GetPower(flowRate As Integer) As Integer Implements IAirFlowRateMechanicalDemandMap.GetPower + + If _map.ContainsKey(flowRate) = False Then + + Throw New ArgumentException("Flow rate was not a key in the FlowRate Mechanical power map") + + + End If + + Return _map(flowRate) + + End Function + + + + End Class + +End Namespace + + + diff --git a/VECTOAux/VectoAuxiliaries/Pneumatics/AveragePneumaticLoadDemand.vb b/VECTOAux/VectoAuxiliaries/Pneumatics/AveragePneumaticLoadDemand.vb new file mode 100644 index 0000000000000000000000000000000000000000..f94494886da8965d16b7060e2d016c2d350e8097 --- /dev/null +++ b/VECTOAux/VectoAuxiliaries/Pneumatics/AveragePneumaticLoadDemand.vb @@ -0,0 +1,68 @@ +Imports VectoAuxiliaries.Pneumatics + +Namespace Pneumatics + + Public Class AveragePneumaticLoadDemand + + + Private _map As ICompressorMap + Private _pneumaticConsumers As List(Of IPneumaticConsumer) + Private _pulleyGearEfficiency As Single + + Public Property PulleyGearEfficiancy As Single + + Private Set(value As Single) + _pulleyGearEfficiency = value + End Set + Get + Return _pulleyGearEfficiency + End Get + + End Property + + Public Property TotalCycleTimeSeconds As Single + + + Public ReadOnly Property PneumaticConsumers As List(Of IPneumaticConsumer) + Get + Return _pneumaticConsumers + End Get + End Property + + 'Constructors + Public Sub New(iMap As ICompressorMap, iTotalCycleTimeSeconds As Integer, iPulleyGearEfficiency As Single) + + _map = iMap + _pulleyGearEfficiency = iPulleyGearEfficiency + _TotalCycleTimeSeconds = iTotalCycleTimeSeconds + + End Sub + + + 'Get Average Power Demand @ Crank From Pneumatics + Public Function GetAveragePowerDemandAtCrankFromPneumatics() As Single + + + + 'TODO + Return -1 + + End Function + + + 'Get Total Required Air Delivery Rate + Public Function GetTotalRequiredAirPerCompressorUnitDeliveryRate() As Single + + Return PneumaticConsumers.Sum(Function(item) item.VolumePerCycle()) + + End Function + + + + + + End Class + +End Namespace + + diff --git a/VECTOAux/VectoAuxiliaries/Pneumatics/CompressorMap.vb b/VECTOAux/VectoAuxiliaries/Pneumatics/CompressorMap.vb index 2f1da924360063723a6f514244c40a2213fc2e67..22f40116ca120bf0a355f1fbfc899dd281708960 100644 --- a/VECTOAux/VectoAuxiliaries/Pneumatics/CompressorMap.vb +++ b/VECTOAux/VectoAuxiliaries/Pneumatics/CompressorMap.vb @@ -185,5 +185,8 @@ Namespace Pneumatics End Structure + + + End Class End Namespace \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliaries/Pneumatics/IAirFlowRateMechanicalDemandMap.vb b/VECTOAux/VectoAuxiliaries/Pneumatics/IAirFlowRateMechanicalDemandMap.vb new file mode 100644 index 0000000000000000000000000000000000000000..9c5af12888017ba62f09ed346559a3db98a2759c --- /dev/null +++ b/VECTOAux/VectoAuxiliaries/Pneumatics/IAirFlowRateMechanicalDemandMap.vb @@ -0,0 +1,28 @@ + +Namespace Pneumatics + + Public Interface IAirFlowRateMechanicalDemandMap + + + ''' <summary> + ''' Initialises the map with a privately stored field referring to filename and path. + ''' </summary> + ''' <returns></returns> + ''' <remarks></remarks> + Function Initialise() As Boolean + + ''' <summary> + ''' Gets Power From Map for a given flow rate + ''' </summary> + ''' <param name="flowRate"></param> + ''' <returns></returns> + ''' <remarks></remarks> + Function GetPower(flowRate As Integer) As Integer + + + End Interface + +End Namespace + + + diff --git a/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj b/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj index 36dd220114973703be89f552fc0416eff1c5b84e..b8ffe23ad7c5c31e5c5334fd8727e30683995d1b 100644 --- a/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj +++ b/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj @@ -78,12 +78,15 @@ <Compile Include="Electrics\AlternatorMap.vb" /> <Compile Include="Electrics\AverageElectricalDemand.vb" /> <Compile Include="Hvac\AverageHVACLoadDemand.vb" /> + <Compile Include="Pneumatics\AirFlowRateMechanicalDemandMap.vb" /> + <Compile Include="Pneumatics\AveragePneumaticLoadDemand.vb" /> <Compile Include="Pneumatics\CompressorMap.vb" /> <Compile Include="Electrics\ElectricalConsumer.vb" /> <Compile Include="Hvac\HVACMap.vb" /> <Compile Include="Electrics\IAlternator.vb" /> <Compile Include="Electrics\IAlternatorMap.vb" /> <Compile Include="Pneumatics\IAirCompressor.vb" /> + <Compile Include="Pneumatics\IAirFlowRateMechanicalDemandMap.vb" /> <Compile Include="Pneumatics\ICompressorMap.vb" /> <Compile Include="Electrics\IElectricalConsumer.vb" /> <Compile Include="My Project\AssemblyInfo.vb" /> diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - GoodMap.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - GoodMap.csv new file mode 100644 index 0000000000000000000000000000000000000000..9fae6b85f75df3d658407e3ee015dd64d204aa28 --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - GoodMap.csv @@ -0,0 +1,5 @@ +FlowRate [L/S], Power [KW] +100,2.0 +200,3.0 +300,4.0 +500,5.0 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - InvalidElements.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - InvalidElements.csv new file mode 100644 index 0000000000000000000000000000000000000000..50ed797c61fd306d89ae68964b925e77d44c950a --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - InvalidElements.csv @@ -0,0 +1,5 @@ +FlowRate [L/S], Power [KW] +100,2.0 +200,a +300,4.0 +500,5.0 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - InvalidKey.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - InvalidKey.csv new file mode 100644 index 0000000000000000000000000000000000000000..9fae6b85f75df3d658407e3ee015dd64d204aa28 --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - InvalidKey.csv @@ -0,0 +1,5 @@ +FlowRate [L/S], Power [KW] +100,2.0 +200,3.0 +300,4.0 +500,5.0 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - NotEnoughElements.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - NotEnoughElements.csv new file mode 100644 index 0000000000000000000000000000000000000000..fc0c020d14c806ca9ff99415a76f1da992a6490f --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - NotEnoughElements.csv @@ -0,0 +1,5 @@ +FlowRate [L/S], Power [KW] +100,2.0 +200 +300,4.0 +500,5.0 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - NotEnoughRows.csv b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - NotEnoughRows.csv new file mode 100644 index 0000000000000000000000000000000000000000..abf714f7c45016392739edb043bc5a3885241c2f --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/TestFiles/testPneumaticAirFlowRateToMechanicalDemandMap - NotEnoughRows.csv @@ -0,0 +1,3 @@ +FlowRate [L/S], Power [KW] +100,2.0 +200,3.0 \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/AirCompressorTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/AirCompressorTests.vb index 94b9b277ec6f9e7307f39b42904504cc844dbebe..fac5c39c662f2c71c165b3d1125def5cf975948f 100644 --- a/VECTOAux/VectoAuxiliariesTests/UnitTests/AirCompressorTests.vb +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/AirCompressorTests.vb @@ -5,7 +5,6 @@ Imports VectoAuxiliariesTests.Mocks Namespace UnitTests <TestFixture()> - <Category("Pnuematic - Compressor")> Public Class AirCompressorTests #Region "Test Constants" Private Const GoodEfficiency As Single = 1 diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageElectricalDemandTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageElectricalDemandTests.vb index e845469ef082b35ecf5f8064cc067a49e0cdc24d..aca085354e471b8ab36cd1d6bd7bda4bfcaa5ea0 100644 --- a/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageElectricalDemandTests.vb +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageElectricalDemandTests.vb @@ -61,10 +61,11 @@ Namespace UnitTests <Test()> Public Sub GetAveragePowerAtAlternatorTest() + Dim target As AverageElectricalDemand = GetAverageElectricalDemandInstance() + Dim actual As Single = target.GetAveragePowerDemandAtAlternator() + Assert.AreEqual(actual, 200) - Dim actual As Single = target.GetAveragePowerAtAlternator() - Assert.Fail("test not complete") End Sub <Test()> diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageHVACLoadDemandTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/AverageHVACLoadDemandMAPTests.vb similarity index 100% rename from VECTOAux/VectoAuxiliariesTests/UnitTests/AverageHVACLoadDemandTests.vb rename to VECTOAux/VectoAuxiliariesTests/UnitTests/AverageHVACLoadDemandMAPTests.vb diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/AveragePneumaticLoadTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/AveragePneumaticLoadTests.vb new file mode 100644 index 0000000000000000000000000000000000000000..6622a535ae5298b509ed4bd717e19215f8f0a867 --- /dev/null +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/AveragePneumaticLoadTests.vb @@ -0,0 +1,84 @@ +Imports NUnit.Framework +Imports VectoAuxiliaries.Pneumatics + +Namespace UnitTests + + <TestFixture()> + Public Class AveragePneumaticLoadDemandMAPTests + + Private Const MAP_GOOD As String = "TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap - GoodMap.csv" + Private Const MAP_INVALIDELEMENTS As String = "TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap_Invalid Elements.csv" + Private Const MAP_INVALIDKEY As String = "TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap_InvalidKey.csv" + Private Const MAP_NOTENOUGHELEMENTS As String = "TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap_NotEnoughElements.csv" + Private Const MAP_NOTENOUGHROWS As String = "TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap_NotEnoughRows.csv" + Private Const MAP_FILENOTFOUND As String = "File_NotFound.csv" + + + <Test> + Public Sub CreateNewFlowMechPowerMap() + + Dim target As New AirFlowRateMechanicalDemandMap(MAP_GOOD) + Assert.IsNotNull(target) + + End Sub + + <Test> + Public Sub InitialiseTest() + + Dim target As New AirFlowRateMechanicalDemandMap(MAP_GOOD) + Assert.IsTrue(target.Initialise()) + + End Sub + + <Test> + <ExpectedException("System.ArgumentException")> + Public Sub InvalidElementsFlowMechPowerMap() + + Dim target As New AirFlowRateMechanicalDemandMap(MAP_INVALIDELEMENTS) + Assert.IsTrue(target.Initialise()) + + End Sub + + <Test> + <ExpectedException("System.ArgumentException")> + Public Sub NotEnoughElementsFlowMechPowerMap() + + Dim target As New AirFlowRateMechanicalDemandMap(MAP_NOTENOUGHELEMENTS) + Assert.IsTrue(target.Initialise()) + + End Sub + + <Test> + <ExpectedException("System.ArgumentException")> + Public Sub NotEnoughRowsFlowMechPowerMap() + + Dim target As New AirFlowRateMechanicalDemandMap(MAP_NOTENOUGHROWS) + Assert.IsTrue(target.Initialise()) + + End Sub + + <Test> + <ExpectedException("System.ArgumentException")> + Public Sub FileNotFoundFlowMechPowerMap_ThrowArgumentException() + + Dim target As New AirFlowRateMechanicalDemandMap(MAP_FILENOTFOUND) + Assert.IsTrue(target.Initialise()) + + End Sub + + <Test> + <ExpectedException("System.ArgumentException")> + Public Sub InvalidKeyFlowRatePowerMap_ThrowArgumentOutOfRangeException() + + Dim target As New AirFlowRateMechanicalDemandMap(MAP_GOOD) + Assert.IsTrue(target.Initialise()) + + target.GetPower(-100) + + End Sub + + + End Class + + +End Namespace \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliariesTests/UnitTests/CompressorMapTests.vb b/VECTOAux/VectoAuxiliariesTests/UnitTests/CompressorMapTests.vb index d0f7beb0f6899a7f1bfc7ca1b28e83199afa13ae..0ec679de5e6f2051f546a2b98f7d62bd7c9cb34b 100644 --- a/VECTOAux/VectoAuxiliariesTests/UnitTests/CompressorMapTests.vb +++ b/VECTOAux/VectoAuxiliariesTests/UnitTests/CompressorMapTests.vb @@ -12,6 +12,7 @@ Namespace UnitTests Private Const INVALIDFLOWRATEMAP As String = "TestFiles\testCompressorMapInvalidFlow.csv" Private Const INSSUFICIENTROWSMAP As String = "TestFiles\testCompressorMapNotEnoughRows.csv" Private Const INVALIDRPMMAP As String = "TestFiles\testCompressorMapInvalidRpm.csv" + Private Const INVALIDNUMBEROFCOLUMNS As String = "TestFiles\testCompressorMapWrongNumberOfColumns.csv" #Region "Helpers" @@ -52,7 +53,7 @@ Namespace UnitTests <Test(), ExpectedException("System.ArgumentException")> Public Sub InitialisationWrongNumberOfColumnsThrowsExceptionTest() - Dim path As String = "C:\DEV\VECTO\VectoAuxiliaries\VectoAuxiliariesTests\TestFiles\testCompressorMapWrongNumberOfColumns.csv" + Dim path As String = INVALIDNUMBEROFCOLUMNS Dim target As CompressorMap = New CompressorMap(path) target.Initialise() End Sub diff --git a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj index 99df40ff9a57659ad89906cb7de63eb3fd9d3436..80837c536ff1d8b67d38397da88de833b58245c0 100644 --- a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj +++ b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj @@ -88,7 +88,8 @@ </ItemGroup> <ItemGroup> <Compile Include="Mocks\HVACMapMock.vb" /> - <Compile Include="UnitTests\AverageHVACLoadDemandTests.vb" /> + <Compile Include="UnitTests\AverageHVACLoadDemandMAPTests.vb" /> + <Compile Include="UnitTests\AveragePneumaticLoadTests.vb" /> <Compile Include="UnitTests\HVACMapTests.vb" /> <Compile Include="UnitTests\PneumaticConsumerTests.vb" /> <Compile Include="UnitTests\AirCompressorTests.vb" /> @@ -188,6 +189,21 @@ <Content Include="TestFiles\testHvacMapWrongColumns.csv"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> + <Content Include="TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap - InvalidKey.csv"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap - NotEnoughElements.csv"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap - InvalidElements.csv"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap - NotEnoughRows.csv"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="TestFiles\testPneumaticAirFlowRateToMechanicalDemandMap - GoodMap.csv"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> <None Include="TestFiles\HVACMap.vaux" /> <Content Include="TestFiles\TestHvacMap - ExtraBlankLines.csv"> <CopyToOutputDirectory>Always</CopyToOutputDirectory>