Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. 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
No related branches found
No related tags found
No related merge requests found
Showing
with 3072 additions and 37 deletions
......@@ -203,3 +203,4 @@ Documentation/VehiclesReleaseComparisonDeclarationMode/*.vmod
Documentation/VehiclesReleaseComparisonDeclarationMode/*.vsum
DISTR/
[0-9][0-9][0-9][0-9]_[0-9][0-9]_[0-9][0-9]-VECTO-*.zip
......@@ -13,16 +13,11 @@ EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "VectoAuxiliaries", "VECTOAux\VectoAuxiliaries\VectoAuxiliaries.vbproj", "{FDEEE460-0B8A-4EF6-8D9E-72F203A50F65}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoCore", "VectoCore\VectoCore\VectoCore.csproj", "{CD36938A-ADD9-4C65-96DA-B397CDEEA90A}"
ProjectSection(ProjectDependencies) = postProject
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD} = {B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}
EndProjectSection
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "VectoAuxiliariesTests", "VECTOAux\VectoAuxiliariesTests\VectoAuxiliariesTests.vbproj", "{6F31F8B2-6AB3-4F85-8AC9-D09ADCA6432D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoCoreTest", "VectoCore\VectoCoreTest\VectoCoreTest.csproj", "{6A27F93E-4A58-48F6-B00B-3908C5D3D5A2}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "AdvancedAuxiliaryInterfaces", "VectoCommon\AdvancedAuxiliaryInterfaces\AdvancedAuxiliaryInterfaces.vbproj", "{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoConsole", "VectoConsole\VectoConsole.csproj", "{60AD4DF0-6648-4374-83CB-C7A162EFB391}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphDrawer", "Tools\GraphDrawer\GraphDrawer.csproj", "{6589CAEC-ECC9-4BCC-9699-DE3F22BBCBD4}"
......@@ -75,6 +70,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "VECTO-GIT", "VECTO-GIT", "{
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VECTO_GIT_TEST", "..\STUDENTEN_PROJEKTE\Kober_VectoGIT\VECTO_GIT\VECTO_GIT_TEST\VECTO_GIT_TEST.csproj", "{52430C51-892A-4D8E-9189-B6C9D09791C0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusAuxiliaries", "VECTOAux\BusAuxiliaries\BusAuxiliaries.csproj", "{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug PerformanceStats|Any CPU = Debug PerformanceStats|Any CPU
......@@ -241,32 +238,6 @@ Global
{6A27F93E-4A58-48F6-B00B-3908C5D3D5A2}.ReleaseTUG|Any CPU.Build.0 = Release|Any CPU
{6A27F93E-4A58-48F6-B00B-3908C5D3D5A2}.ReleaseTUG|x64.ActiveCfg = Release|Any CPU
{6A27F93E-4A58-48F6-B00B-3908C5D3D5A2}.ReleaseTUG|x86.ActiveCfg = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug PerformanceStats|Any CPU.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug PerformanceStats|x64.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug PerformanceStats|x86.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug PerformanceTrace|Any CPU.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug PerformanceTrace|x64.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug PerformanceTrace|x86.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug|x64.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Debug|x86.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.DebugTUG|Any CPU.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.DebugTUG|Any CPU.Build.0 = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.DebugTUG|x64.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.DebugTUG|x86.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Deploy|Any CPU.ActiveCfg = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Deploy|Any CPU.Build.0 = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Deploy|x64.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Deploy|x86.ActiveCfg = Debug|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Release|Any CPU.Build.0 = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Release|x64.ActiveCfg = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.Release|x86.ActiveCfg = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.ReleaseTUG|Any CPU.ActiveCfg = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.ReleaseTUG|Any CPU.Build.0 = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.ReleaseTUG|x64.ActiveCfg = Release|Any CPU
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD}.ReleaseTUG|x86.ActiveCfg = Release|Any CPU
{60AD4DF0-6648-4374-83CB-C7A162EFB391}.Debug PerformanceStats|Any CPU.ActiveCfg = Debug|Any CPU
{60AD4DF0-6648-4374-83CB-C7A162EFB391}.Debug PerformanceStats|Any CPU.Build.0 = Debug|Any CPU
{60AD4DF0-6648-4374-83CB-C7A162EFB391}.Debug PerformanceStats|x64.ActiveCfg = Debug|Any CPU
......@@ -835,6 +806,48 @@ Global
{52430C51-892A-4D8E-9189-B6C9D09791C0}.ReleaseTUG|x64.Build.0 = Release|Any CPU
{52430C51-892A-4D8E-9189-B6C9D09791C0}.ReleaseTUG|x86.ActiveCfg = Release|Any CPU
{52430C51-892A-4D8E-9189-B6C9D09791C0}.ReleaseTUG|x86.Build.0 = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceStats|Any CPU.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceStats|Any CPU.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceStats|x64.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceStats|x64.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceStats|x86.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceStats|x86.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceTrace|Any CPU.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceTrace|Any CPU.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceTrace|x64.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceTrace|x64.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceTrace|x86.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug PerformanceTrace|x86.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug|x64.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug|x64.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug|x86.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Debug|x86.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.DebugTUG|Any CPU.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.DebugTUG|Any CPU.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.DebugTUG|x64.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.DebugTUG|x64.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.DebugTUG|x86.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.DebugTUG|x86.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Deploy|Any CPU.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Deploy|Any CPU.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Deploy|x64.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Deploy|x64.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Deploy|x86.ActiveCfg = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Deploy|x86.Build.0 = Debug|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Release|Any CPU.Build.0 = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Release|x64.ActiveCfg = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Release|x64.Build.0 = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Release|x86.ActiveCfg = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.Release|x86.Build.0 = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.ReleaseTUG|Any CPU.ActiveCfg = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.ReleaseTUG|Any CPU.Build.0 = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.ReleaseTUG|x64.ActiveCfg = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.ReleaseTUG|x64.Build.0 = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.ReleaseTUG|x86.ActiveCfg = Release|Any CPU
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}.ReleaseTUG|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -844,7 +857,6 @@ Global
{CD36938A-ADD9-4C65-96DA-B397CDEEA90A} = {CC93EA68-F3FE-4BCB-9292-1101F94A4D09}
{6F31F8B2-6AB3-4F85-8AC9-D09ADCA6432D} = {B7C0A40B-E468-44DE-A784-7A5B8DAC1042}
{6A27F93E-4A58-48F6-B00B-3908C5D3D5A2} = {CC93EA68-F3FE-4BCB-9292-1101F94A4D09}
{B4B9BD2F-FD8F-4BB8-82FA-E2154D2C7FBD} = {73A5BF70-6168-456F-95E5-A1402BFA488C}
{6589CAEC-ECC9-4BCC-9699-DE3F22BBCBD4} = {351FF7E8-B56B-445E-8E98-A61E07C990DA}
{2320CD6F-FE7B-4341-A9BB-3ABCA7EF18F6} = {351FF7E8-B56B-445E-8E98-A61E07C990DA}
{E8B0B447-1A54-4BEC-A160-AF0017000781} = {351FF7E8-B56B-445E-8E98-A61E07C990DA}
......@@ -860,5 +872,6 @@ Global
{A684BC49-C9B3-4C0C-8D2E-A13077853EDA} = {5DDEEEC2-743F-4395-B058-687B5773E3D2}
{C234077C-F81E-42FA-9367-1319753678A6} = {D29E62A2-CF08-469F-B29F-1B25DCB35386}
{52430C51-892A-4D8E-9189-B6C9D09791C0} = {5DDEEEC2-743F-4395-B058-687B5773E3D2}
{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D} = {B7C0A40B-E468-44DE-A784-7A5B8DAC1042}
EndGlobalSection
EndGlobal
Imports System.Collections.Generic
Imports VectoAuxiliaries
Imports System.IO
Imports System.Linq
Imports System.Runtime.Remoting
Imports TUGraz.VectoCore.BusAuxiliaries.Interfaces
Imports VectoAuxiliaries
Module AdvancedAuxiliariesModule
Public WithEvents AdvancedAuxModel As IAdvancedAuxiliaries
......@@ -100,7 +101,7 @@ Module AdvancedAuxiliariesModule
o = Activator.CreateInstance(chosenAssembly.Value.AssemblyName, "VectoAuxiliaries.AdvancedAuxiliaries")
iAdvancedAux = DirectCast(o.Unwrap, IAdvancedAuxiliaries)
iAdvancedAux.Configure(filePath, vectoFilePath)
Configure(filePath, vectoFilePath)
Catch ex As Exception
......@@ -111,6 +112,31 @@ Module AdvancedAuxiliariesModule
Return result
End Function
Function Configure(filePath As String, vectoFilePath As String) As Boolean
Try
Dim frmAuxiliaryConfig As New frmAuxiliaryConfig(filePath, vectoFilePath)
frmAuxiliaryConfig.Show()
If frmAuxiliaryConfig.DialogResult <> DialogResult.OK Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
''' <summary>
''' Gets location of Advanced Auxiliaries Directory which contains all the assemblies available.
......
......@@ -519,9 +519,13 @@
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VectoCommon\AdvancedAuxiliaryInterfaces\AdvancedAuxiliaryInterfaces.vbproj">
<Project>{b4b9bd2f-fd8f-4bb8-82fa-e2154d2c7fbd}</Project>
<Name>AdvancedAuxiliaryInterfaces</Name>
<ProjectReference Include="..\VECTOAux\BusAuxiliaries\BusAuxiliaries.csproj">
<Project>{550d99d4-25f7-48d9-b0f0-e5dd6cb3485d}</Project>
<Name>BusAuxiliaries</Name>
</ProjectReference>
<ProjectReference Include="..\VECTOAux\VectoAuxiliaries\VectoAuxiliaries.vbproj">
<Project>{FDEEE460-0B8A-4EF6-8D9E-72F203A50F65}</Project>
<Name>VectoAuxiliaries</Name>
</ProjectReference>
<ProjectReference Include="..\VectoCommon\VectoCommon\VectoCommon.csproj">
<Project>{79a066ad-69a9-4223-90f6-6ed5d2d084f4}</Project>
......
// 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.Windows.Forms;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl;
using TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics;
using TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC;
using TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Pneumatics;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.PneumaticSystem;
using TUGraz.VectoCore.BusAuxiliaries.Util;
namespace TUGraz.VectoCore.BusAuxiliaries {
/// <summary>
/// ''' Main entry point for the advanced auxiliary module.
/// ''' This class represents slide number 17 titled Calculations of Cycle FC accounting for Smart Auxiliaries.
/// ''' </summary>
/// ''' <remarks></remarks>
public class AdvancedAuxiliaries : IAdvancedAuxiliaries
{
protected internal AuxiliaryConfig auxConfig;
// Supporting classes which may generate event messages
private ICompressorMap compressorMap;
private SSMTOOL ssmTool;
private SSMTOOL ssmToolModule14;
private IAlternatorMap alternatorMap;
public IPneumaticActuationsMAP actuationsMap;
private IFuelConsumptionMap fuelMap;
// Classes which compose the model.
private IM0_NonSmart_AlternatorsSetEfficiency M0;
private IM0_5_SmartAlternatorSetEfficiency M05;
private IM1_AverageHVACLoadDemand M1;
private IM2_AverageElectricalLoadDemand M2;
private IM3_AveragePneumaticLoadDemand M3;
private IM4_AirCompressor M4;
private IM5_SmartAlternatorSetGeneration M5;
private IM6 M6;
private IM7 M7;
private IM8 M8;
private IM9 M9;
private IM10 M10;
private IM11 M11;
private IM12 M12;
private IM13 M13;
private IM14 M14;
private string vectoDirectory;
private HVACConstants hvacConstants;
// Event Handler top level bubble.
// Public Sub VectoEventHandler(ByRef sender As Object, message As String, messageType As AdvancedAuxiliaryMessageType) _
// Handles compressorMap.AuxiliaryEvent, alternatorMap.AuxiliaryEvent, ssmTool.Message, ssmToolModule14.Message
// If Signals.AuxiliaryEventReportingLevel <= messageType Then
// RaiseEvent AuxiliaryEvent(sender, message, messageType)
// End If
// End Sub
// Constructor
public AdvancedAuxiliaries()
{
VectoInputs = new VectoInputs();
Signals = new Signals();
}
// Initialise Model
public void Initialise(string IAuxPath, string vectoFilePath)
{
string auxPath;
vectoDirectory = FilePathUtils.fPATH(vectoFilePath);
auxPath = FilePathUtils.ResolveFilePath(vectoDirectory, IAuxPath);
hvacConstants = new HVACConstants(VectoInputs.FuelDensity);
Signals.CurrentCycleTimeInSeconds = 0;
auxConfig = new AuxiliaryConfig(auxPath);
// Pass some signals from config to Signals. ( These are stored in the configuration but shared in the signal distribution around modules )
Signals.SmartElectrics = auxConfig.ElectricalUserInputsConfig.SmartElectrical;
Signals.StoredEnergyEfficiency = auxConfig.ElectricalUserInputsConfig.StoredEnergyEfficiency;
Signals.SmartPneumatics = auxConfig.PneumaticUserInputsConfig.SmartAirCompression;
Signals.PneumaticOverrunUtilisation = auxConfig.PneumaticAuxillariesConfig.OverrunUtilisationForCompressionFraction;
alternatorMap = new CombinedAlternator(FilePathUtils.ResolveFilePath(vectoDirectory, auxConfig.ElectricalUserInputsConfig.AlternatorMap), Signals);
actuationsMap = new PneumaticActuationsMap(FilePathUtils.ResolveFilePath(vectoDirectory, auxConfig.PneumaticUserInputsConfig.ActuationsMap));
compressorMap = new CompressorMap(FilePathUtils.ResolveFilePath(vectoDirectory, auxConfig.PneumaticUserInputsConfig.CompressorMap));
compressorMap.Initialise();
// fuelMap = New cMAP()
// fuelMap.FilePath = FilePathUtils.ResolveFilePath(vectoDirectory, VectoInputs.FuelMap)
// If Not fuelMap.ReadFile() Then
// MessageBox.Show("Unable to read fuel map, aborting.")
// Return
// End If
// fuelMap.Triangulate()
fuelMap = VectoInputs.FuelMap;
auxConfig.ElectricalUserInputsConfig.ElectricalConsumers.DoorDutyCycleFraction = GetDoorActuationTimeFraction();
// SSM HVAC
var ssmPath = FilePathUtils.ResolveFilePath(vectoDirectory, auxConfig.HvacUserInputsConfig.SSMFilePath);
var BusDatabase = FilePathUtils.ResolveFilePath(vectoDirectory, auxConfig.HvacUserInputsConfig.BusDatabasePath);
ssmTool = new SSMTOOL(ssmPath, hvacConstants, auxConfig.HvacUserInputsConfig.SSMDisabled);
// This duplicate SSM is being created for use in M14 as its properties will be dynamically changed at that point
// to honour EngineWaste Heat Usage in Fueling calculations.
ssmToolModule14 = new SSMTOOL(ssmPath, hvacConstants, auxConfig.HvacUserInputsConfig.SSMDisabled);
if ((ssmTool.Load(ssmPath) == false || ssmToolModule14.Load(ssmPath) == false))
throw new Exception(string.Format("Unable to load the ssmTOOL with file {0}", ssmPath));
M0 = new M00Impl(auxConfig.ElectricalUserInputsConfig.ElectricalConsumers, alternatorMap, auxConfig.ElectricalUserInputsConfig.PowerNetVoltage.SI<Volt>(), Signals, ssmTool);
IM0_5_SmartAlternatorSetEfficiency M05tmp = new M0_5Impl(M0, auxConfig.ElectricalUserInputsConfig.ElectricalConsumers, alternatorMap, auxConfig.ElectricalUserInputsConfig.ResultCardIdle, auxConfig.ElectricalUserInputsConfig.ResultCardTraction, auxConfig.ElectricalUserInputsConfig.ResultCardOverrun, Signals);
M05 = M05tmp;
M1 = new M01Impl(M0, auxConfig.ElectricalUserInputsConfig.AlternatorGearEfficiency, auxConfig.PneumaticUserInputsConfig.CompressorGearEfficiency, auxConfig.ElectricalUserInputsConfig.PowerNetVoltage.SI<Volt>(), Signals, ssmTool);
M2 = new M02Impl(auxConfig.ElectricalUserInputsConfig.ElectricalConsumers, M0, auxConfig.ElectricalUserInputsConfig.AlternatorGearEfficiency, auxConfig.ElectricalUserInputsConfig.PowerNetVoltage.SI<Volt>(), Signals);
M3 = new M03Impl(auxConfig.PneumaticUserInputsConfig, auxConfig.PneumaticAuxillariesConfig, actuationsMap, compressorMap, VectoInputs.VehicleWeightKG, VectoInputs.Cycle, Signals);
M4 = new M04Impl(compressorMap, auxConfig.PneumaticUserInputsConfig.CompressorGearRatio, auxConfig.PneumaticUserInputsConfig.CompressorGearEfficiency, Signals);
M5 = new M05Impl(M05tmp, auxConfig.ElectricalUserInputsConfig.PowerNetVoltage.SI<Volt>(), auxConfig.ElectricalUserInputsConfig.AlternatorGearEfficiency);
M6 = new M06Impl(M1, M2, M3, M4, M5, Signals);
M7 = new M07Impl(M5, M6, Signals);
M8 = new M08Impl(M1, M6, M7, Signals);
M9 = new M09Impl(M1, M4, M6, M8, fuelMap, auxConfig.PneumaticAuxillariesConfig, Signals);
M10 = new M10Impl(M3, M9, Signals);
M11 = new M11Impl(M1, M3, M6, M8, fuelMap, Signals);
M12 = new M12Impl(M10, M11, Signals);
M13 = new M13Impl(M10, M11, M12, Signals);
M14 = new M14Impl(M13, ssmToolModule14, hvacConstants, Signals);
}
public ISignals Signals { get; set; }
public IVectoInputs VectoInputs { get; set; }
public event TUGraz.VectoCore.BusAuxiliaries.Interfaces.AuxiliaryEventEventHandler AuxiliaryEvent;
public delegate void AuxiliaryEventEventHandler(ref object sender, string message, AdvancedAuxiliaryMessageType messageType);
//public bool Configure(string filePath, string vectoFilePath)
//{
// try {
// frmAuxiliaryConfig frmAuxiliaryConfig = new frmAuxiliaryConfig(filePath, vectoFilePath);
// frmAuxiliaryConfig.Show();
// if (frmAuxiliaryConfig.DialogResult != DialogResult.OK) {
// return true;
// }
// return false;
// } catch (Exception ex) {
// return false;
// }
//}
public bool CycleStep(Second seconds, ref string message)
{
try {
M9.CycleStep(seconds);
M10.CycleStep(seconds);
M11.CycleStep(seconds);
Signals.CurrentCycleTimeInSeconds += seconds.Value();
} catch (Exception ex) {
MessageBox.Show("Exception: " + ex.Message + " Stack Trace: " + ex.StackTrace);
return false;
}
return true;
}
public bool Running
{
get {
throw new NotImplementedException();
}
}
public bool RunStart(string auxFilePath, string vectoFilePath)
{
try {
Initialise(auxFilePath, vectoFilePath);
} catch (Exception ex) {
return false;
}
return true;
}
public bool RunStop(ref string message)
{
throw new NotImplementedException();
}
public void ResetCalculations()
{
var modules = new List<IAbstractModule>() { M0, M05, M1, M2, M3, M4, M5, M6, M7, M8, M9, M10, M11, M12, M13, M14 };
foreach (var moduel in modules)
moduel.ResetCalculations();
}
public Kilogram TotalFuelGRAMS
{
get {
if (M13 != null)
return M14.TotalCycleFCGrams;
else
return 0.SI<Kilogram>();
}
}
public Liter TotalFuelLITRES
{
get {
if (M14 != null)
return M14.TotalCycleFCLitres;
else
return 0.SI<Liter>();
}
}
public string AuxiliaryName
{
get {
return "BusAuxiliaries";
}
}
public string AuxiliaryVersion
{
get {
return "Version 1.0 Beta";
}
}
// Helpers
private double GetDoorActuationTimeFraction()
{
var actuationsMap = new PneumaticActuationsMap(FilePathUtils.ResolveFilePath(vectoDirectory, auxConfig.PneumaticUserInputsConfig.ActuationsMap));
var actuationsKey = new ActuationsKey("Park brake + 2 doors", VectoInputs.Cycle);
var numActuations = actuationsMap.GetNumActuations(actuationsKey);
var secondsPerActuation = auxConfig.ElectricalUserInputsConfig.DoorActuationTimeSecond;
var doorDutyCycleFraction = (numActuations * secondsPerActuation) / (double)Signals.TotalCycleTimeSeconds;
return doorDutyCycleFraction;
}
public bool ValidateAAUXFile(string filePath, ref string message)
{
var validResult = FilePathUtils.ValidateFilePath(filePath, ".aaux", ref message);
return validResult;
}
// Diagnostics outputs for testing purposes in Vecto.
// Eventually this can be removed or rendered non effective to reduce calculation load on the model.
public double AA_NonSmartAlternatorsEfficiency
{
get {
return M0.AlternatorsEfficiency;
}
}
public Ampere AA_SmartIdleCurrent_Amps
{
get {
return M05.SmartIdleCurrent;
}
}
public double AA_SmartIdleAlternatorsEfficiency
{
get {
return M05.AlternatorsEfficiencyIdleResultCard;
}
}
public Ampere AA_SmartTractionCurrent_Amps
{
get {
return M05.SmartTractionCurrent;
}
}
public double AA_SmartTractionAlternatorEfficiency
{
get {
return M05.AlternatorsEfficiencyTractionOnResultCard;
}
}
public Ampere AA_SmartOverrunCurrent_Amps
{
get {
return M05.SmartOverrunCurrent;
}
}
public double AA_SmartOverrunAlternatorEfficiency
{
get {
return M05.AlternatorsEfficiencyOverrunResultCard;
}
}
public NormLiterPerSecond AA_CompressorFlowRate_LitrePerSec
{
get {
return M4.GetFlowRate();
}
}
public bool AA_OverrunFlag
{
get {
return M6.OverrunFlag;
}
}
public int? AA_EngineIdleFlag
{
get {
return Signals.EngineSpeed <= Signals.EngineIdleSpeed && (!Signals.ClutchEngaged || Signals.InNeutral) ? 1 : 0;
}
}
public bool AA_CompressorFlag
{
get {
return M8.CompressorFlag;
}
}
public Kilogram AA_TotalCycleFC_Grams
{
get {
return M14.TotalCycleFCGrams;
}
}
public Liter AA_TotalCycleFC_Litres
{
get {
return M14.TotalCycleFCLitres;
}
}
public Watt AuxiliaryPowerAtCrankWatts
{
get {
return M8.AuxPowerAtCrankFromElectricalHVACAndPneumaticsAncillaries;
}
}
public Watt AA_AveragePowerDemandCrankHVACMechanicals
{
get {
return M1.AveragePowerDemandAtCrankFromHVACMechanicalsWatts();
}
}
public Watt AA_AveragePowerDemandCrankHVACElectricals
{
get {
return M1.AveragePowerDemandAtCrankFromHVACElectricsWatts();
}
}
public Watt AA_AveragePowerDemandCrankElectrics
{
get {
return M2.GetAveragePowerAtCrankFromElectrics();
}
}
public Watt AA_AveragePowerDemandCrankPneumatics
{
get {
return M3.GetAveragePowerDemandAtCrankFromPneumatics();
}
}
public Kilogram AA_TotalCycleFuelConsumptionCompressorOff
{
get {
return M9.TotalCycleFuelConsumptionCompressorOffContinuously;
}
}
public Kilogram AA_TotalCycleFuelConsumptionCompressorOn
{
get {
return M9.TotalCycleFuelConsumptionCompressorOnContinuously;
}
}
}
}
// 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.IO;
using System.Windows.Forms;
using Newtonsoft.Json;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics;
using TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.HVAC;
using TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Pneumatics;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.HVAC;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.PneumaticSystem;
using TUGraz.VectoCore.BusAuxiliaries.Legacy;
namespace TUGraz.VectoCore.BusAuxiliaries {
[Serializable()]
public class AuxiliaryConfig : IAuxiliaryConfig
{
// Vecto
public IVectoInputs VectoInputs { get; set; }
// Electrical
public IElectricsUserInputsConfig ElectricalUserInputsConfig { get; set; }
// Pneumatics
public IPneumaticUserInputsConfig PneumaticUserInputsConfig { get; set; }
public IPneumaticsAuxilliariesConfig PneumaticAuxillariesConfig { get; set; }
// Hvac
public IHVACUserInputsConfig HvacUserInputsConfig { get; set; }
// Vecto Signals
[JsonIgnore]
public ISignals Signals { get; set; }
// Constructors
public AuxiliaryConfig() : this("EMPTY") { }
public AuxiliaryConfig(string auxConfigFile)
{
// Special Condition
if (auxConfigFile == "EMPTY") {
ElectricalUserInputsConfig = new ElectricsUserInputsConfig() { PowerNetVoltage = 28.3 };
ElectricalUserInputsConfig.ElectricalConsumers = new ElectricalConsumerList(28.3, 0.096, false);
ElectricalUserInputsConfig.ResultCardIdle = new ResultCard(new List<SmartResult>());
ElectricalUserInputsConfig.ResultCardOverrun = new ResultCard(new List<SmartResult>());
ElectricalUserInputsConfig.ResultCardTraction = new ResultCard(new List<SmartResult>());
PneumaticAuxillariesConfig = new PneumaticsAuxilliariesConfig(false);
PneumaticUserInputsConfig = new PneumaticUserInputsConfig(false);
HvacUserInputsConfig = new HVACUserInputsConfig(string.Empty, string.Empty, false);
return;
}
if (auxConfigFile == null || auxConfigFile.Trim().Length == 0 || !File.Exists(auxConfigFile))
setDefaults();
else {
setDefaults();
if (!Load(auxConfigFile))
MessageBox.Show(string.Format("Unable to load file {0}", auxConfigFile));
}
}
// Set Default Values
private void setDefaults()
{
var tmp = new VectoInputs
() {
Cycle = "Urban",
VehicleWeightKG = 16500.SI<Kilogram>(),
PowerNetVoltage = 28.3.SI<Volt>()
};
VectoInputs = tmp;
Signals = new Signals() { EngineSpeed = 2000.RPMtoRad(), TotalCycleTimeSeconds = 3114, ClutchEngaged = false };
// Pneumatics set deault values
PneumaticUserInputsConfig = new PneumaticUserInputsConfig(true);
PneumaticAuxillariesConfig = new PneumaticsAuxilliariesConfig(true);
// Electrical set deault values
ElectricalUserInputsConfig = new ElectricsUserInputsConfig(true, tmp);
ElectricalUserInputsConfig.ElectricalConsumers = new ElectricalConsumerList(28.3, 0.096, true);
// HVAC set deault values
HvacUserInputsConfig = new HVACUserInputsConfig(string.Empty, string.Empty, false);
}
private double GetDoorActuationTimeFraction()
{
var actuationsMap = new PneumaticActuationsMap(PneumaticUserInputsConfig.ActuationsMap);
var actuationsKey = new ActuationsKey("Park brake + 2 doors", VectoInputs.Cycle);
var numActuations = actuationsMap.GetNumActuations(actuationsKey);
var secondsPerActuation = ElectricalUserInputsConfig.DoorActuationTimeSecond;
var doorDutyCycleFraction = (numActuations * secondsPerActuation) / (double)Signals.TotalCycleTimeSeconds;
return doorDutyCycleFraction;
}
private bool CompareElectricalConfiguration(AuxiliaryConfig other)
{
// AlternatorGearEfficiency
if (ElectricalUserInputsConfig.AlternatorGearEfficiency != other.ElectricalUserInputsConfig.AlternatorGearEfficiency)
return false;
// AlternatorMap
if (ElectricalUserInputsConfig.AlternatorMap != other.ElectricalUserInputsConfig.AlternatorMap)
return false;
// DoorActuationTimeSecond
if (ElectricalUserInputsConfig.DoorActuationTimeSecond != other.ElectricalUserInputsConfig.DoorActuationTimeSecond)
return false;
// Consumer list
if (ElectricalUserInputsConfig.ElectricalConsumers.Items.Count !=
other.ElectricalUserInputsConfig.ElectricalConsumers.Items.Count)
return false;
int i;
for (i = 0; i <= ElectricalUserInputsConfig.ElectricalConsumers.Items.Count - 1; i++) {
IElectricalConsumer thisConsumer, otherConsumer;
thisConsumer = ElectricalUserInputsConfig.ElectricalConsumers.Items[i];
otherConsumer = other.ElectricalUserInputsConfig.ElectricalConsumers.Items[i];
if (thisConsumer.AvgConsumptionAmps != otherConsumer.AvgConsumptionAmps ||
thisConsumer.BaseVehicle != otherConsumer.BaseVehicle || thisConsumer.Category != otherConsumer.Category ||
thisConsumer.ConsumerName != otherConsumer.ConsumerName ||
thisConsumer.NominalConsumptionAmps != otherConsumer.NominalConsumptionAmps ||
thisConsumer.NumberInActualVehicle != otherConsumer.NumberInActualVehicle ||
thisConsumer.PhaseIdle_TractionOn != otherConsumer.PhaseIdle_TractionOn ||
thisConsumer.TotalAvgConsumptionInWatts() != otherConsumer.TotalAvgConsumptionInWatts() ||
thisConsumer.TotalAvgConumptionAmps() != otherConsumer.TotalAvgConumptionAmps())
return false;
}
// PowerNetVoltage
if (ElectricalUserInputsConfig.PowerNetVoltage != other.ElectricalUserInputsConfig.PowerNetVoltage)
return false;
// ResultCardIdle
if (ElectricalUserInputsConfig.ResultCardIdle.Results.Count !=
other.ElectricalUserInputsConfig.ResultCardIdle.Results.Count)
return false;
for (i = 0; i <= ElectricalUserInputsConfig.ResultCardIdle.Results.Count - 1; i++) {
if (ElectricalUserInputsConfig.ResultCardIdle.Results[i].Amps !=
other.ElectricalUserInputsConfig.ResultCardIdle.Results[i].Amps ||
ElectricalUserInputsConfig.ResultCardIdle.Results[i].SmartAmps !=
other.ElectricalUserInputsConfig.ResultCardIdle.Results[i].SmartAmps)
return false;
}
// ResultCardOverrun
if (ElectricalUserInputsConfig.ResultCardOverrun.Results.Count !=
other.ElectricalUserInputsConfig.ResultCardOverrun.Results.Count)
return false;
for (i = 0; i <= ElectricalUserInputsConfig.ResultCardOverrun.Results.Count - 1; i++) {
if (ElectricalUserInputsConfig.ResultCardOverrun.Results[i].Amps !=
other.ElectricalUserInputsConfig.ResultCardOverrun.Results[i].Amps ||
ElectricalUserInputsConfig.ResultCardOverrun.Results[i].SmartAmps !=
other.ElectricalUserInputsConfig.ResultCardOverrun.Results[i].SmartAmps)
return false;
}
// ResultCardTraction
if (ElectricalUserInputsConfig.ResultCardTraction.Results.Count !=
other.ElectricalUserInputsConfig.ResultCardTraction.Results.Count)
return false;
for (i = 0; i <= ElectricalUserInputsConfig.ResultCardTraction.Results.Count - 1; i++) {
if (ElectricalUserInputsConfig.ResultCardTraction.Results[i].Amps !=
other.ElectricalUserInputsConfig.ResultCardTraction.Results[i].Amps ||
ElectricalUserInputsConfig.ResultCardTraction.Results[i].SmartAmps !=
other.ElectricalUserInputsConfig.ResultCardTraction.Results[i].SmartAmps)
return false;
}
// SmartElectrical
if (ElectricalUserInputsConfig.SmartElectrical != other.ElectricalUserInputsConfig.SmartElectrical)
return false;
return true;
}
private bool ComparePneumaticAuxiliariesConfig(AuxiliaryConfig other)
{
if (PneumaticAuxillariesConfig.AdBlueNIperMinute != other.PneumaticAuxillariesConfig.AdBlueNIperMinute)
return false;
if (PneumaticAuxillariesConfig.AirControlledSuspensionNIperMinute !=
other.PneumaticAuxillariesConfig.AirControlledSuspensionNIperMinute)
return false;
if (PneumaticAuxillariesConfig.BrakingNoRetarderNIperKG != other.PneumaticAuxillariesConfig.BrakingNoRetarderNIperKG)
return false;
if (PneumaticAuxillariesConfig.BrakingWithRetarderNIperKG !=
other.PneumaticAuxillariesConfig.BrakingWithRetarderNIperKG)
return false;
if (PneumaticAuxillariesConfig.BreakingPerKneelingNIperKGinMM !=
other.PneumaticAuxillariesConfig.BreakingPerKneelingNIperKGinMM)
return false;
if (PneumaticAuxillariesConfig.DeadVolBlowOutsPerLitresperHour !=
other.PneumaticAuxillariesConfig.DeadVolBlowOutsPerLitresperHour)
return false;
if (PneumaticAuxillariesConfig.DeadVolumeLitres != other.PneumaticAuxillariesConfig.DeadVolumeLitres)
return false;
if (PneumaticAuxillariesConfig.NonSmartRegenFractionTotalAirDemand !=
other.PneumaticAuxillariesConfig.NonSmartRegenFractionTotalAirDemand)
return false;
if (PneumaticAuxillariesConfig.PerDoorOpeningNI != other.PneumaticAuxillariesConfig.PerDoorOpeningNI)
return false;
if (PneumaticAuxillariesConfig.PerStopBrakeActuationNIperKG !=
other.PneumaticAuxillariesConfig.PerStopBrakeActuationNIperKG)
return false;
if (PneumaticAuxillariesConfig.SmartRegenFractionTotalAirDemand !=
other.PneumaticAuxillariesConfig.SmartRegenFractionTotalAirDemand)
return false;
if (PneumaticAuxillariesConfig.OverrunUtilisationForCompressionFraction !=
other.PneumaticAuxillariesConfig.OverrunUtilisationForCompressionFraction)
return false;
return true;
}
private bool ComparePneumaticUserConfig(AuxiliaryConfig other)
{
if (PneumaticUserInputsConfig.ActuationsMap != other.PneumaticUserInputsConfig.ActuationsMap)
return false;
if (PneumaticUserInputsConfig.AdBlueDosing != other.PneumaticUserInputsConfig.AdBlueDosing)
return false;
if (PneumaticUserInputsConfig.AirSuspensionControl != other.PneumaticUserInputsConfig.AirSuspensionControl)
return false;
if (PneumaticUserInputsConfig.CompressorGearEfficiency != other.PneumaticUserInputsConfig.CompressorGearEfficiency)
return false;
if (PneumaticUserInputsConfig.CompressorGearRatio != other.PneumaticUserInputsConfig.CompressorGearRatio)
return false;
if (PneumaticUserInputsConfig.CompressorMap != other.PneumaticUserInputsConfig.CompressorMap)
return false;
if (PneumaticUserInputsConfig.Doors != other.PneumaticUserInputsConfig.Doors)
return false;
if (PneumaticUserInputsConfig.KneelingHeightMillimeters != other.PneumaticUserInputsConfig.KneelingHeightMillimeters)
return false;
if (PneumaticUserInputsConfig.RetarderBrake != other.PneumaticUserInputsConfig.RetarderBrake)
return false;
if (PneumaticUserInputsConfig.SmartAirCompression != other.PneumaticUserInputsConfig.SmartAirCompression)
return false;
if (PneumaticUserInputsConfig.SmartRegeneration != other.PneumaticUserInputsConfig.SmartRegeneration)
return false;
return true;
}
private bool CompareHVACConfig(AuxiliaryConfig other)
{
if (HvacUserInputsConfig.SSMFilePath != other.HvacUserInputsConfig.SSMFilePath)
return false;
if (HvacUserInputsConfig.BusDatabasePath != other.HvacUserInputsConfig.BusDatabasePath)
return false;
if (HvacUserInputsConfig.SSMDisabled != other.HvacUserInputsConfig.SSMDisabled)
return false;
return true;
}
public bool ConfigValuesAreTheSameAs(AuxiliaryConfig other)
{
if (!CompareElectricalConfiguration(other))
return false;
if (!ComparePneumaticAuxiliariesConfig(other))
return false;
if (!ComparePneumaticUserConfig(other))
return false;
if (!CompareHVACConfig(other))
return false;
return true;
}
// Persistance Functions
public bool Save(string auxFile)
{
var returnValue = true;
var settings = new JsonSerializerSettings();
settings.TypeNameHandling = TypeNameHandling.Objects;
// JSON METHOD
try {
var output = JsonConvert.SerializeObject(this, Formatting.Indented, settings);
File.WriteAllText(auxFile, output);
} catch (Exception ex) {
returnValue = false;
}
return returnValue;
}
public bool Load(string auxFile)
{
var returnValue = true;
var settings = new JsonSerializerSettings();
AuxiliaryConfig tmpAux;
settings.TypeNameHandling = TypeNameHandling.Objects;
// JSON METHOD
try {
var output = File.ReadAllText(auxFile);
tmpAux = JsonConvert.DeserializeObject<AuxiliaryConfig>(output, settings);
// This is where we Assume values of loaded( Deserialized ) object.
AssumeValuesOfOther(tmpAux);
if (tmpAux.VectoInputs.FuelMapFile != null) {
var tmp = new cMAP();
tmp.FilePath = Path.Combine(Path.GetDirectoryName(auxFile), tmpAux.VectoInputs.FuelMapFile);
if (!tmp.ReadFile()) {
MessageBox.Show("Unable to read fuel map, aborting.");
return false;
}
tmp.Triangulate();
VectoInputs.FuelMap = tmp;
}
} catch (Exception ex) {
returnValue = false;
}
return returnValue;
}
// Persistance Helpers
public void AssumeValuesOfOther(AuxiliaryConfig other)
{
CloneElectricaConfiguration(other);
ClonePneumaticsAuxiliariesConfig(other);
ClonePneumaticsUserInputsConfig(other);
CloneHVAC(other);
}
private void CloneElectricaConfiguration(AuxiliaryConfig other)
{
// AlternatorGearEfficiency
ElectricalUserInputsConfig.AlternatorGearEfficiency = other.ElectricalUserInputsConfig.AlternatorGearEfficiency;
// AlternatorMap
ElectricalUserInputsConfig.AlternatorMap = other.ElectricalUserInputsConfig.AlternatorMap;
// DoorActuationTimeSecond
ElectricalUserInputsConfig.DoorActuationTimeSecond = other.ElectricalUserInputsConfig.DoorActuationTimeSecond;
// Electrical Consumer list
ElectricalUserInputsConfig.ElectricalConsumers.Items.Clear();
foreach (var otherConsumer in other.ElectricalUserInputsConfig.ElectricalConsumers.Items) {
var newConsumer = new ElectricalConsumer(
otherConsumer.BaseVehicle, otherConsumer.Category, otherConsumer.ConsumerName, otherConsumer.NominalConsumptionAmps,
otherConsumer.PhaseIdle_TractionOn, otherConsumer.PowerNetVoltage, otherConsumer.NumberInActualVehicle,
otherConsumer.Info);
ElectricalUserInputsConfig.ElectricalConsumers.Items.Add(newConsumer);
}
// PowerNetVoltage
ElectricalUserInputsConfig.PowerNetVoltage = other.ElectricalUserInputsConfig.PowerNetVoltage;
// ResultCardIdle
ElectricalUserInputsConfig.ResultCardIdle.Results.Clear();
foreach (var result in other.ElectricalUserInputsConfig.ResultCardIdle.Results)
ElectricalUserInputsConfig.ResultCardIdle.Results.Add(new SmartResult(result.Amps, result.SmartAmps));
// ResultCardOverrun
ElectricalUserInputsConfig.ResultCardOverrun.Results.Clear();
foreach (var result in other.ElectricalUserInputsConfig.ResultCardOverrun.Results)
ElectricalUserInputsConfig.ResultCardOverrun.Results.Add(new SmartResult(result.Amps, result.SmartAmps));
// ResultCardTraction
ElectricalUserInputsConfig.ResultCardTraction.Results.Clear();
foreach (var result in other.ElectricalUserInputsConfig.ResultCardTraction.Results)
ElectricalUserInputsConfig.ResultCardTraction.Results.Add(new SmartResult(result.Amps, result.SmartAmps));
// SmartElectrical
ElectricalUserInputsConfig.SmartElectrical = other.ElectricalUserInputsConfig.SmartElectrical;
}
private void ClonePneumaticsAuxiliariesConfig(AuxiliaryConfig other)
{
PneumaticAuxillariesConfig.AdBlueNIperMinute = other.PneumaticAuxillariesConfig.AdBlueNIperMinute;
PneumaticAuxillariesConfig.AirControlledSuspensionNIperMinute =
other.PneumaticAuxillariesConfig.AirControlledSuspensionNIperMinute;
PneumaticAuxillariesConfig.BrakingNoRetarderNIperKG = other.PneumaticAuxillariesConfig.BrakingNoRetarderNIperKG;
PneumaticAuxillariesConfig.BrakingWithRetarderNIperKG = other.PneumaticAuxillariesConfig.BrakingWithRetarderNIperKG;
PneumaticAuxillariesConfig.BreakingPerKneelingNIperKGinMM =
other.PneumaticAuxillariesConfig.BreakingPerKneelingNIperKGinMM;
PneumaticAuxillariesConfig.DeadVolBlowOutsPerLitresperHour =
other.PneumaticAuxillariesConfig.DeadVolBlowOutsPerLitresperHour;
PneumaticAuxillariesConfig.DeadVolumeLitres = other.PneumaticAuxillariesConfig.DeadVolumeLitres;
PneumaticAuxillariesConfig.NonSmartRegenFractionTotalAirDemand =
other.PneumaticAuxillariesConfig.NonSmartRegenFractionTotalAirDemand;
PneumaticAuxillariesConfig.PerDoorOpeningNI = other.PneumaticAuxillariesConfig.PerDoorOpeningNI;
PneumaticAuxillariesConfig.PerStopBrakeActuationNIperKG =
other.PneumaticAuxillariesConfig.PerStopBrakeActuationNIperKG;
PneumaticAuxillariesConfig.SmartRegenFractionTotalAirDemand =
other.PneumaticAuxillariesConfig.SmartRegenFractionTotalAirDemand;
PneumaticAuxillariesConfig.OverrunUtilisationForCompressionFraction =
other.PneumaticAuxillariesConfig.OverrunUtilisationForCompressionFraction;
}
private void ClonePneumaticsUserInputsConfig(AuxiliaryConfig other)
{
PneumaticUserInputsConfig.ActuationsMap = other.PneumaticUserInputsConfig.ActuationsMap;
PneumaticUserInputsConfig.AdBlueDosing = other.PneumaticUserInputsConfig.AdBlueDosing;
PneumaticUserInputsConfig.AirSuspensionControl = other.PneumaticUserInputsConfig.AirSuspensionControl;
PneumaticUserInputsConfig.CompressorGearEfficiency = other.PneumaticUserInputsConfig.CompressorGearEfficiency;
PneumaticUserInputsConfig.CompressorGearRatio = other.PneumaticUserInputsConfig.CompressorGearRatio;
PneumaticUserInputsConfig.CompressorMap = other.PneumaticUserInputsConfig.CompressorMap;
PneumaticUserInputsConfig.Doors = other.PneumaticUserInputsConfig.Doors;
PneumaticUserInputsConfig.KneelingHeightMillimeters = other.PneumaticUserInputsConfig.KneelingHeightMillimeters;
PneumaticUserInputsConfig.RetarderBrake = other.PneumaticUserInputsConfig.RetarderBrake;
PneumaticUserInputsConfig.SmartAirCompression = other.PneumaticUserInputsConfig.SmartAirCompression;
PneumaticUserInputsConfig.SmartRegeneration = other.PneumaticUserInputsConfig.SmartRegeneration;
}
private void CloneHVAC(AuxiliaryConfig other)
{
HvacUserInputsConfig.SSMFilePath = other.HvacUserInputsConfig.SSMFilePath;
HvacUserInputsConfig.BusDatabasePath = other.HvacUserInputsConfig.BusDatabasePath;
HvacUserInputsConfig.SSMDisabled = other.HvacUserInputsConfig.SSMDisabled;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{550D99D4-25F7-48D9-B0F0-E5DD6CB3485D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TUGraz.VectoCore.BusAuxiliaries</RootNamespace>
<AssemblyName>BusAuxiliaries</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Omu.ValueInjecter, Version=3.1.1.0, Culture=neutral, PublicKeyToken=c7694541b0ac80e4, processorArchitecture=MSIL">
<HintPath>..\..\packages\ValueInjecter.3.1.1.5\lib\net40\Omu.ValueInjecter.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AuxiliaryConfig.cs" />
<Compile Include="AdvancedAuxiliaries.cs" />
<Compile Include="IAuxiliaryConfig.cs" />
<Compile Include="DownstreamModules\Impl\AbstractModule.cs" />
<Compile Include="DownstreamModules\Impl\AlternatorMap.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\Alternator.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\ElectricsUserInputsConfig.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\ResultCard.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\ElectricalConsumer.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\ElectricalConsumerList.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\CombinedAlternatorSignals.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\CombinedAlternatorMapRow.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\CombinedAlternator.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\M00Impl.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\M02Impl.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\Bus.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\BusDatabase.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\BusEngineType.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\SSMTOOL.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\SSMTechList.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\SSMRun.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\SSMGenInputs.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\SSMCalculate.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\HVACUserInputsConfig.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\HVACSteadyStateModel.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\HVACConstants.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\EnvironmentalConditionsMap.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\EnvironmentalCondition.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\DeleteCell.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\DeleteColumn.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\IBusDatabase.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\IBus.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\TechListBenefitLine.cs" />
<Compile Include="DownstreamModules\Impl\Pneumatics\PneumaticUserInputsConfig.cs" />
<Compile Include="DownstreamModules\Impl\Pneumatics\PneumaticsAuxilliariesConfig.cs" />
<Compile Include="DownstreamModules\Impl\Pneumatics\PneumaticActuationsMap.cs" />
<Compile Include="DownstreamModules\Impl\Pneumatics\CompressorMap.cs" />
<Compile Include="DownstreamModules\Impl\Pneumatics\M03Impl.cs" />
<Compile Include="DownstreamModules\Impl\Pneumatics\M04Impl.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\M05Impl.cs" />
<Compile Include="DownstreamModules\Impl\Electrics\M0_5Impl.cs" />
<Compile Include="DownstreamModules\Impl\M10Impl.cs" />
<Compile Include="DownstreamModules\Impl\M11Impl.cs" />
<Compile Include="DownstreamModules\Impl\M12Impl.cs" />
<Compile Include="DownstreamModules\Impl\M13Impl.cs" />
<Compile Include="DownstreamModules\Impl\M14Impl.cs" />
<Compile Include="DownstreamModules\Impl\HVAC\M01Impl.cs" />
<Compile Include="DownstreamModules\Impl\M06Impl.cs" />
<Compile Include="DownstreamModules\Impl\M07Impl.cs" />
<Compile Include="DownstreamModules\Impl\M08Impl.cs" />
<Compile Include="DownstreamModules\Impl\M09Impl.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\SmartResult.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\IResultCard.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\IElectricsUserInputsConfig.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\IElectricalConsumerList.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\IElectricalConsumer.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\ICombinedAlternatorSignals.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\ICombinedAlternatorMapRow.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\AlternatorMapValues.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\AltUserInput.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\ElectricConstants.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\IAlternator.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\IAlternatorMap.cs" />
<Compile Include="Interfaces\DownstreamModules\Electrics\ICombinedAlternator.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\Class1.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\ISSMTOOL.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\ISSMTechList.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\ISSMRun.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\ISSMGenInputs.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\ISSMCalculate.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\IHVACUserInputsConfig.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\IHVACSteadyStateModel.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\IHVACConstants.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\IEnvironmentalConditionsMap.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\IEnvironmentalCondition.cs" />
<Compile Include="Interfaces\DownstreamModules\HVAC\ITechListBenefitLine.cs" />
<Compile Include="Interfaces\DownstreamModules\IAbstractModule.cs" />
<Compile Include="Interfaces\DownstreamModules\IM0_5_SmartAlternatorSetEfficiency.cs" />
<Compile Include="Interfaces\DownstreamModules\IM0_NonSmart_AlternatorsSetEfficiency.cs" />
<Compile Include="Interfaces\DownstreamModules\IM10.cs" />
<Compile Include="Interfaces\DownstreamModules\IM11.cs" />
<Compile Include="Interfaces\DownstreamModules\IM13.cs" />
<Compile Include="Interfaces\DownstreamModules\IM14.cs" />
<Compile Include="Interfaces\DownstreamModules\IM1_AverageHVACLoadDemand.cs" />
<Compile Include="Interfaces\DownstreamModules\IM2_AverageElectrialLoadDemand.cs" />
<Compile Include="Interfaces\DownstreamModules\IM3_AveragePneumaticLoadDemand.cs" />
<Compile Include="Interfaces\DownstreamModules\IM4_AirCompressor.cs" />
<Compile Include="Interfaces\DownstreamModules\IM5_SmartAlternatorSetGeneration.cs" />
<Compile Include="Interfaces\DownstreamModules\IM6.cs" />
<Compile Include="Interfaces\DownstreamModules\IM7.cs" />
<Compile Include="Interfaces\DownstreamModules\IM8.cs" />
<Compile Include="Interfaces\DownstreamModules\IM9.cs" />
<Compile Include="Interfaces\DownstreamModules\PneumaticSystem\ActuationsKey.cs" />
<Compile Include="Interfaces\DownstreamModules\PneumaticSystem\IPneumaticUserInputsConfig.cs" />
<Compile Include="Interfaces\DownstreamModules\PneumaticSystem\IPneumaticsAuxilliariesConfig.cs" />
<Compile Include="Interfaces\DownstreamModules\PneumaticSystem\IPneumaticActuationsMAP.cs" />
<Compile Include="Interfaces\DownstreamModules\PneumaticSystem\ICompressorMap.cs" />
<Compile Include="Interfaces\Enumerations.cs" />
<Compile Include="Interfaces\IAdvancedAuxiliaries.cs" />
<Compile Include="Interfaces\IAuxiliaryEvent.cs" />
<Compile Include="Interfaces\IFuelConsumptionMap.cs" />
<Compile Include="Interfaces\IM12.cs" />
<Compile Include="Interfaces\ISignals.cs" />
<Compile Include="Interfaces\IVectoInputs.cs" />
<Compile Include="Interfaces\Signals.cs" />
<Compile Include="Interfaces\VectoInputs.cs" />
<Compile Include="Legacy\cDelaunayMap.cs" />
<Compile Include="Legacy\cFile_V3.cs" />
<Compile Include="Legacy\Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Util\FilePathUtils.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VectoCommon\VectoCommon\VectoCommon.csproj">
<Project>{79A066AD-69A9-4223-90F6-6ED5D2D084F4}</Project>
<Name>VectoCommon</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="Images\application-export-icon-small.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Images\Delete.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<ItemGroup>
<None Include="Images\Delete1.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Blank.bmp" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\desktop.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\favorites.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\file-history.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Image1.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Info.bmp" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\new_dir.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Open-icon.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl
{
public abstract class AbstractModule
{
protected bool calculationValid { get; private set; }
public AbstractModule()
{
calculationValid = false;
}
public virtual void ResetCalculations()
{
calculationValid = false;
}
protected virtual void Calculate()
{
DoCalculate();
calculationValid = true;
}
protected virtual void DoCalculate() { }
}
}
// 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.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl
{
public class AlternatorMap : IAlternatorMap
{
private readonly string filePath;
private List<MapPoint> _map = new List<MapPoint>();
private List<double> _yRange;
private List<double> _xRange;
private double _minX, _minY, _maxX, _maxY;
// Required Action Test or Interpolation Type
public bool OnBoundaryYInterpolatedX(double x, double y)
{
return _yRange.Contains(y) && !_xRange.Contains(x);
}
public bool OnBoundaryXInterpolatedY(double x, double y)
{
return !_yRange.Contains(y) && _xRange.Contains(x);
}
public bool ONBoundaryXY(double x, double y)
{
return (from sector in _map
where sector.Y == y && sector.x == x
select sector).Count() == 1;
}
// Determine Value Methods
private double GetOnBoundaryXY(double x, double y)
{
return (from sector in _map
where sector.Y == y && sector.x == x
select sector).First().v;
}
private double GetOnBoundaryYInterpolatedX(double x, double y)
{
double x0, x1, v0, v1, slope, dx;
x0 = (from p in _xRange
orderby p
where p < x
select p).Last();
x1 = (from p in _xRange
orderby p
where p > x
select p).First();
dx = x1 - x0;
v0 = GetOnBoundaryXY(x0, y);
v1 = GetOnBoundaryXY(x1, y);
slope = (v1 - v0) / (x1 - x0);
return v0 + ((x - x0) * slope);
}
private double GetOnBoundaryXInterpolatedY(double x, double y)
{
double y0, y1, v0, v1, dy, v, slope;
y0 = (from p in _yRange
orderby p
where p < y
select p).Last();
y1 = (from p in _yRange
orderby p
where p > y
select p).First();
dy = y1 - y0;
v0 = GetOnBoundaryXY(x, y0);
v1 = GetOnBoundaryXY(x, y1);
slope = (v1 - v0) / (y1 - y0);
v = v0 + ((y - y0) * slope);
return v;
}
private double GetBiLinearInterpolatedValue(double x, double y)
{
double q11, q12, q21, q22, x1, x2, y1, y2, r1, r2, p;
y1 = (from mapSector in _map
where mapSector.Y < y
select mapSector).Last().Y;
y2 = (from mapSector in _map
where mapSector.Y > y
select mapSector).First().Y;
x1 = (from mapSector in _map
where mapSector.x < x
select mapSector).Last().x;
x2 = (from mapSector in _map
where mapSector.x > x
select mapSector).First().x;
q11 = GetOnBoundaryXY(x1, y1);
q12 = GetOnBoundaryXY(x1, y2);
q21 = GetOnBoundaryXY(x2, y1);
q22 = GetOnBoundaryXY(x2, y2);
r1 = ((x2 - x) / (x2 - x1)) * q11 + ((x - x1) / (x2 - x1)) * q21;
r2 = ((x2 - x) / (x2 - x1)) * q12 + ((x - x1) / (x2 - x1)) * q22;
p = ((y2 - y) / (y2 - y1)) * r1 + ((y - y1) / (y2 - y1)) * r2;
return p;
}
// Utilities
private void fillMapWithDefaults()
{
_map.Add(new MapPoint(10, 1500, 0.615));
_map.Add(new MapPoint(27, 1500, 0.7));
_map.Add(new MapPoint(53, 1500, 0.1947));
_map.Add(new MapPoint(63, 1500, 0.0));
_map.Add(new MapPoint(68, 1500, 0.0));
_map.Add(new MapPoint(125, 1500, 0.0));
_map.Add(new MapPoint(136, 1500, 0.0));
_map.Add(new MapPoint(10, 2000, 0.62));
_map.Add(new MapPoint(27, 2000, 0.7));
_map.Add(new MapPoint(53, 2000, 0.3));
_map.Add(new MapPoint(63, 2000, 0.1462));
_map.Add(new MapPoint(68, 2000, 0.692));
_map.Add(new MapPoint(125, 2000, 0.0));
_map.Add(new MapPoint(136, 2000, 0.0));
_map.Add(new MapPoint(10, 4000, 0.64));
_map.Add(new MapPoint(27, 4000, 0.6721));
_map.Add(new MapPoint(53, 4000, 0.7211));
_map.Add(new MapPoint(63, 4000, 0.74));
_map.Add(new MapPoint(68, 4000, 0.7352));
_map.Add(new MapPoint(125, 4000, 0.68));
_map.Add(new MapPoint(136, 4000, 0.6694));
_map.Add(new MapPoint(10, 6000, 0.53));
_map.Add(new MapPoint(27, 6000, 0.5798));
_map.Add(new MapPoint(53, 6000, 0.656));
_map.Add(new MapPoint(63, 6000, 0.6853));
_map.Add(new MapPoint(68, 6000, 0.7));
_map.Add(new MapPoint(125, 6000, 0.6329));
_map.Add(new MapPoint(136, 6000, 0.62));
_map.Add(new MapPoint(10, 7000, 0.475));
_map.Add(new MapPoint(27, 7000, 0.5337));
_map.Add(new MapPoint(53, 7000, 0.6235));
_map.Add(new MapPoint(63, 7000, 0.658));
_map.Add(new MapPoint(68, 7000, 0.6824));
_map.Add(new MapPoint(125, 7000, 0.6094));
_map.Add(new MapPoint(136, 7000, 0.5953));
}
private void getMapRanges()
{
;/*
Input:
_yRange = (From coords As MapPoint In _map Order By coords.Y Select coords.Y Distinct).ToList()
*/
;/*
Input:
_xRange = (From coords As MapPoint In _map Order By coords.x Select coords.x Distinct).ToList()
*/
_yRange = _map.Select(x => x.Y).Distinct().OrderBy(x => x).ToList();
_xRange = _map.Select(x => x.x).Distinct().OrderBy(x => x).ToList();
_minX = _xRange.First();
_maxX = _xRange.Last();
_minY = _yRange.First();
_maxY = _yRange.Last();
}
// Single entry point to determine Value on map
public double GetValue(double x, double y)
{
if (x < _minX || x > _maxX || y < _minY || y > _maxY) {
// OnAuxiliaryEvent(String.Format("Alternator Map Limiting : RPM{0}, AMPS{1}",x,y),AdvancedAuxiliaryMessageType.Warning)
// Limiting
if (x < _minX)
x = _minX;
if (x > _maxX)
x = _maxX;
if (y < _minY)
y = _minY;
if (y > _maxY)
y = _maxY;
}
// Satisfies both data points - non interpolated value
if (ONBoundaryXY(x, y))
return GetOnBoundaryXY(x, y);
// Satisfies only x or y - single interpolation value
if (OnBoundaryXInterpolatedY(x, y))
return GetOnBoundaryXInterpolatedY(x, y);
if (OnBoundaryYInterpolatedX(x, y))
return GetOnBoundaryYInterpolatedX(x, y);
// satisfies no data points - Bi-Linear interpolation
return GetBiLinearInterpolatedValue(x, y);
}
public string ReturnDefaultMapValueTests()
{
var sb = new StringBuilder();
// All Sector Values
sb.AppendLine("All Values From Map");
sb.AppendLine("-------------------");
foreach (var xr in _xRange) {
foreach (var yr in _yRange)
sb.AppendLine(string.Format("X:{0}, Y:{1}, V:{2}", xr, yr, GetValue(xr, yr)));
}
sb.AppendLine("");
sb.AppendLine("Four Corners with interpolated other");
sb.AppendLine("-------------------");
var x = 1500.0;
var y = 18.5;
sb.AppendLine(string.Format("X:{0}, Y:{1}, V:{2}", x, y, GetValue(x, y)));
x = 7000;
y = 96.5;
sb.AppendLine(string.Format("X:{0}, Y:{1}, V:{2}", x, y, GetValue(x, y)));
x = 1750;
y = 10;
sb.AppendLine(string.Format("X:{0}, Y:{1}, V:{2}", x, y, GetValue(x, y)));
x = 6500;
y = 10;
sb.AppendLine(string.Format("X:{0}, Y:{1}, V:{2}", x, y, GetValue(x, y)));
sb.AppendLine("");
sb.AppendLine("Interpolated both");
sb.AppendLine("-------------------");
double mx, my;
int x2, y2;
for (x2 = 0; x2 <= _xRange.Count - 2; x2++) {
for (y2 = 0; y2 <= _yRange.Count - 2; y2++) {
mx = _xRange[x2] + (_xRange[x2 + 1] - _xRange[x2]) / 2;
my = _yRange[y2] + (_yRange[y2 + 1] - _yRange[y2]) / 2;
sb.AppendLine(string.Format("X:{0}, Y:{1}, V:{2}", mx, my, GetValue(mx, my)));
}
}
sb.AppendLine("");
sb.AppendLine("MIKE -> 40 & 1000");
sb.AppendLine("-------------------");
x = 1000;
y = 40;
sb.AppendLine(string.Format("X:{0}, Y:{1}, V:{2}", x, y, GetValue(x, y)));
return sb.ToString();
}
// Constructors
public AlternatorMap(string filepath)
{
this.filePath = filepath;
Initialise();
getMapRanges();
}
private class MapPoint
{
public double Y;
public double x;
public double v;
public MapPoint(double y, double x, double v)
{
this.Y = y;
this.x = x;
this.v = v;
}
}
// Get Alternator Efficiency
public AlternatorMapValues GetEfficiency(double rpm, Ampere amps)
{
return new AlternatorMapValues(GetValue(rpm, amps.Value()));
}
// Initialises the map.
public bool Initialise()
{
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.Count() < 3)
throw new ArgumentException("Insufficient rows in csv to build a usable map");
_map = new List<MapPoint>();
var firstline = true;
foreach (var line in lines) {
if (!firstline) {
// Advanced Alternator Source Check.
if (line.Contains("[MODELSOURCE"))
break;
// split the line
var elements = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// 3 entries per line required
if ((elements.Length != 3))
throw new ArgumentException("Incorrect number of values in csv file");
// add values to map
// Create AlternatorKey
var newPoint = new MapPoint(float.Parse(elements[0], CultureInfo.InvariantCulture), float.Parse(elements[1], CultureInfo.InvariantCulture), float.Parse(elements[2], CultureInfo.InvariantCulture));
_map.Add(newPoint);
}
firstline = false;
}
}
return true;
}
throw new ArgumentException("Supplied input file does not exist");
}
// Public Events
public event AuxiliaryEventEventHandler AuxiliaryEvent;
//public delegate void AuxiliaryEventEventHandler(ref object sender, string message, AdvancedAuxiliaryMessageType messageType);
protected void OnAuxiliaryEvent(string message, AdvancedAuxiliaryMessageType messageType)
{
object alternatorMap = this;
AuxiliaryEvent?.Invoke(ref alternatorMap, message, messageType);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
// Model based on CombinedALTS_V02_Editable.xlsx
public class Alternator : IAlternator
{
private ICombinedAlternatorSignals signals;
// D6
public string AlternatorName { get; set; }
// G6
public double PulleyRatio { get; set; }
// C10-D15
public List<AltUserInput> InputTable2000 { get; set; } = new List<AltUserInput>();
// F10-G15
public List<AltUserInput> InputTable4000 { get; set; } = new List<AltUserInput>();
// I10-J15
public List<AltUserInput> InputTable6000 { get; set; } = new List<AltUserInput>();
// M10-N15
public List<Table4Row> RangeTable { get; set; } = new List<Table4Row>();
// S9
public double SpindleSpeed
{
get { return signals.CrankRPM * PulleyRatio; }
}
// S10
public double Efficiency
{
get {
// First build RangeTable, table 4
InitialiseRangeTable();
CalculateRangeTable();
// Calculate ( Interpolate ) Efficiency
var range = RangeTable.Select(s => new AltUserInput(s.RPM, s.Efficiency)).ToList();
return Alternator.Iterpolate(range, Convert.ToSingle(SpindleSpeed));
}
}
// Constructors
public Alternator() { }
public Alternator(ICombinedAlternatorSignals isignals, List<ICombinedAlternatorMapRow> inputs)
{
if (isignals == null)
throw new ArgumentException("Alternator - ISignals supplied is nothing");
signals = isignals;
AlternatorName = inputs.First().AlternatorName;
PulleyRatio = inputs.First().PulleyRatio;
var values2k = inputs.Where(x => x.RPM == 2000)
.Select(x => new KeyValuePair<double, double>(x.Amps, x.Efficiency))
.ToDictionary(x => x.Key, x => x.Value);
var values4k = inputs.Where(x => x.RPM == 4000)
.Select(x => new KeyValuePair<double, double>(x.Amps, x.Efficiency))
.ToDictionary(x => x.Key, x => x.Value);
var values6k = inputs.Where(x => x.RPM == 6000)
.Select(x => new KeyValuePair<double, double>(x.Amps, x.Efficiency))
.ToDictionary(x => x.Key, x => x.Value);
BuildInputTable(values2k, InputTable2000);
BuildInputTable(values4k, InputTable4000);
BuildInputTable(values6k, InputTable6000);
CreateRangeTable();
}
public static double Iterpolate(List<AltUserInput> values, double x)
{
var lowestX = values.Min(m => m.Amps);
var highestX = values.Max(m => m.Amps);
// Out of range, returns efficiency for lowest
if (x < lowestX)
return values.First(f => f.Amps == lowestX).Eff;
// Out of range, efficiency for highest
if (x > highestX)
return values.First(f => f.Amps == highestX).Eff;
// On Bounds check
if (values.Where(w => w.Amps == x).Count() == 1)
return values.First(w => w.Amps == x).Eff;
// OK, we need to interpolate.
var preKey = values.Last(l => l.Amps < x).Amps;
var postKey = values.First(l => l.Amps > x).Amps;
var preEff = values.First(f => f.Amps == preKey).Eff;
var postEff = values.First(f => f.Amps == postKey).Eff;
var deltaX = postKey - preKey;
var deltaEff = postEff - preEff;
// slopes
var effSlope = deltaEff / deltaX;
var retVal = ((x - preKey) * effSlope) + preEff;
return retVal;
}
private void CalculateRangeTable()
{
// M10=Row0-Rpm - N10=Row0-Eff
// M11=Row1-Rpm - N11=Row1-Eff
// M12=Row2-Rpm - N12=Row2-Eff - 2000
// M13=Row3-Rpm - N13=Row3-Eff - 4000
// M14=Row4-Rpm - N14=Row4-Eff - 6000
// M15=Row5-Rpm - N15=Row5-Eff
// M16=Row6-Rpm - N16=Row6-Eff
double N10, N11, N12, N13, N14, N15, N16;
double M10, M11, M12, M13, M14, M15, M16;
// EFFICIENCY
// 2000
N12 = Alternator.Iterpolate(InputTable2000, signals.CurrentDemandAmps.Value());
RangeTable[2].Efficiency = N12;
// 4000
N13 = Alternator.Iterpolate(InputTable4000, signals.CurrentDemandAmps.Value());
RangeTable[3].Efficiency = N13;
// 6000
N14 = Alternator.Iterpolate(InputTable6000, signals.CurrentDemandAmps.Value());
RangeTable[4].Efficiency = N14;
// Row0 & Row1 Efficiency =IF(N13>N12,0,MAX(N12:N14)) - Example Alt 1 N13=
N11 = N13 > N12 ? 0 : Math.Max(Math.Max(N12, N13), N14);
RangeTable[1].Efficiency = N11;
N10 = N11;
RangeTable[0].Efficiency = N10;
// Row 5 Efficiency
N15 = N13 > N14 ? 0 : Math.Max(Math.Max(N12, N13), N14);
RangeTable[5].Efficiency = N15;
// Row 6 - Efficiency
N16 = N15;
RangeTable[6].Efficiency = N16;
// RPM
// 2000 Row 2 - RPM
M12 = 2000;
RangeTable[2].RPM = M12;
// 4000 Row 3 - RPM
M13 = 4000;
RangeTable[3].RPM = M13;
// 6000 Row 4 - RPM
M14 = 6000;
RangeTable[4].RPM = M14;
// Row 1 - RPM
// NOTE: Update to reflect CombineALternatorSchematicV02 20150429
// IF(M12=IF(N12>N13,M12-((M12-M13)/(N12-N13))*(N12-N11),M12-((M12-M13)/(N12-N13))*(N12-N11)), M12-0.01, IF(N12>N13,M12-((M12-M13)/(N12-N13))*(N12-N11),M12-((M12-M13)/(N12-N13))*(N12-N11)))
M11 =
Convert.ToSingle(
N12 - N13 == 0
? 0
: (
M12 == (N12 > N13
? M12 - (M12 - M13) / (N12 - N13) * (N12 - N11)
: M12 - (M12 - M13) / (N12 - N13) * (N12 - N11))
? M12 - 0.01
: (N12 > N13
? M12 - (M12 - M13) / (N12 - N13) * (N12 - N11)
: M12 - (M12 - M13) / (N12 - N13) * (N12 - N11))));
RangeTable[1].RPM = M11;
// Row 0 - RPM
M10 = M11 < 1500 ? M11 - 1 : 1500;
RangeTable[0].RPM = M10;
// Row 5 - RPM
M15 =
Convert.ToSingle(
M14 == (N14 == 0 || N14 == N13
? M14 + 1
: (N13 > N14 ? (M14 - M13) / (N13 - N14) * N14 + M14 : (M14 - M13) / (N13 - N14) * (N14 - N15) + M14)
)
? M14 + 0.01
: (N14 == 0 || N14 == N13
? M14 + 1
: (N13 > N14 ? (M14 - M13) / (N13 - N14) * N14 + M14 : (M14 - M13) / (N13 - N14) * (N14 - N15) + M14)));
RangeTable[5].RPM = M15;
// Row 6 - RPM
M16 = M15 > 10000 ? M15 + 1 : 10000;
RangeTable[6].RPM = M16;
}
private void InitialiseRangeTable()
{
RangeTable[0].RPM = 0;
RangeTable[0].Efficiency = 0;
RangeTable[1].RPM = 0;
RangeTable[0].Efficiency = 0;
RangeTable[2].RPM = 2000;
RangeTable[0].Efficiency = 0;
RangeTable[3].RPM = 4000;
RangeTable[0].Efficiency = 0;
RangeTable[4].RPM = 6000;
RangeTable[0].Efficiency = 0;
RangeTable[5].RPM = 0;
RangeTable[0].Efficiency = 0;
RangeTable[6].RPM = 0;
RangeTable[0].Efficiency = 0;
}
private void CreateRangeTable()
{
RangeTable.Clear();
RangeTable.Add(new Table4Row(0, 0));
RangeTable.Add(new Table4Row(0, 0));
RangeTable.Add(new Table4Row(0, 0));
RangeTable.Add(new Table4Row(0, 0));
RangeTable.Add(new Table4Row(0, 0));
RangeTable.Add(new Table4Row(0, 0));
RangeTable.Add(new Table4Row(0, 0));
}
public void BuildInputTable(Dictionary<double, double> inputs, List<AltUserInput> targetTable)
{
double C11, C12, C13, C14, C15, D11, D12, D13, D14, D15;
targetTable.Clear();
// Row0
D14 = 0;
targetTable.Add(new AltUserInput(0, D14));
// Row1
targetTable.Add(new AltUserInput(inputs.OrderBy(x => x.Key).First().Key, inputs.OrderBy(x => x.Key).First().Value));
// Row2
targetTable.Add(
new AltUserInput(inputs.OrderBy(x => x.Key).Skip(1).First().Key, inputs.OrderBy(x => x.Key).Skip(1).First().Value));
// Row3
targetTable.Add(
new AltUserInput(inputs.OrderBy(x => x.Key).Skip(2).First().Key, inputs.OrderBy(x => x.Key).Skip(2).First().Value));
C11 = targetTable[1].Amps;
C12 = targetTable[2].Amps;
C13 = targetTable[3].Amps;
D11 = targetTable[1].Eff;
D12 = targetTable[2].Eff;
D13 = targetTable[3].Eff;
D14 = D12 > D13 ? 0 : Math.Max(Math.Max(D11, D12), D13);
// Row4 - Eff
targetTable.Add(new AltUserInput(0, D14));
// Row4 - Amps
// Should probably refactor this into some sort of helper/extension method
var numarray = new[] { D11, D12, D13 };
var maxD11_D13 = numarray.Max();
// =IF(OR(D13=0,D13=D12),C13+1,IF(D12>D13,((((C13-C12)/(D12-D13))*D13)+C13),((((C13-C12)/(D12-D13))*(D13-D14))+C13)))
C14 = (D13 == 0 || D13 == D12 || D13 == maxD11_D13)
? C13 + 1
: D12 > D13
? ((((C13 - C12) / (D12 - D13)) * D13) + C13)
: ((((C13 - C12) / (D12 - D13)) * (D13 - D14)) + C13);
targetTable[4].Amps = C14;
// Row5
C15 = C14 > 200 ? C14 + 1 : 200;
D15 = D14;
targetTable.Add(new AltUserInput(C15, D15));
// Row0
targetTable[0].Eff = D11;
}
public bool IsEqualTo(IAlternator other)
{
if (AlternatorName != other.AlternatorName) {
return false;
}
if (PulleyRatio != other.PulleyRatio) {
return false;
}
for (var i = 1; i <= 3; i++) {
if (InputTable2000[i].Eff != other.InputTable2000[i].Eff)
return false;
if (InputTable4000[i].Eff != other.InputTable4000[i].Eff)
return false;
if (InputTable6000[i].Eff != other.InputTable6000[i].Eff)
return false;
}
return true;
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
using TUGraz.VectoCore.BusAuxiliaries.Util;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
public class CombinedAlternator : IAlternatorMap, ICombinedAlternator
{
private List<ICombinedAlternatorMapRow> map = new List<ICombinedAlternatorMapRow>();
public List<IAlternator> Alternators { get; set; } = new List<IAlternator>();
private List<IAlternator> OriginalAlternators = new List<IAlternator>();
private string FilePath;
private ICombinedAlternatorSignals altSignals;
private ISignals Signals;
private AlternatorMapValues AverageAlternatorsEfficiency;
// Interface Implementation
public AlternatorMapValues GetEfficiency(double CrankRPM, Ampere Amps)
{
altSignals.CrankRPM = CrankRPM;
altSignals.CurrentDemandAmps = (Amps.Value() / (double)Alternators.Count).SI<Ampere>();
AlternatorMapValues alternatorMapValues; /* TODO Change to default(_) if this is not a reference type */;
if (Signals == null || Signals.RunningCalc)
// If running calc cycle get efficiency from interpolation function
alternatorMapValues = new AlternatorMapValues(Convert.ToSingle(Alternators.Average(a => a.Efficiency) / (double)100));
else
// If running Pre calc cycle get an average of inputs
alternatorMapValues = AverageAlternatorsEfficiency;
if (alternatorMapValues.Efficiency <= 0)
alternatorMapValues = new AlternatorMapValues(0.01);
return alternatorMapValues;
}
public bool Initialise()
{
// From the map we construct this CombinedAlternator object and original CombinedAlternator Object
Alternators.Clear();
OriginalAlternators.Clear();
foreach (var alt in map.GroupBy(g => g.AlternatorName)) {
var altName = alt.First().AlternatorName;
var pulleyRatio = alt.First().PulleyRatio;
IAlternator alternator = new Alternator(altSignals, alt.ToList());
Alternators.Add(alternator);
}
return true;
}
// Constructors
public CombinedAlternator(string filePath, ISignals signals = null/* TODO Change to default(_) if this is not a reference type */)
{
var feedback = string.Empty;
this.Signals = signals;
if (!FilePathUtils.ValidateFilePath(filePath, ".aalt", ref feedback))
throw new ArgumentException(string.Format("Combined Alternator requires a valid .AALT filename. : {0}", feedback));
else
this.FilePath = filePath;
this.altSignals = new CombinedAlternatorSignals();
// IF file exists then read it otherwise create a default.
if (File.Exists(filePath) && InitialiseMap(filePath))
Initialise();
else {
// Create Default Map
CreateDefaultMap();
Initialise();
}
// Calculate alternators average which is used only in the pre-run
var efficiencySum = 0.0;
foreach (var alt in Alternators) {
efficiencySum += alt.InputTable2000.ElementAt(1).Eff;
efficiencySum += alt.InputTable2000.ElementAt(2).Eff;
efficiencySum += alt.InputTable2000.ElementAt(3).Eff;
efficiencySum += alt.InputTable4000.ElementAt(1).Eff;
efficiencySum += alt.InputTable4000.ElementAt(2).Eff;
efficiencySum += alt.InputTable4000.ElementAt(3).Eff;
efficiencySum += alt.InputTable6000.ElementAt(1).Eff;
efficiencySum += alt.InputTable6000.ElementAt(2).Eff;
efficiencySum += alt.InputTable6000.ElementAt(3).Eff;
}
var efficiencyAverage = efficiencySum / (Alternators.Count * 9);
AverageAlternatorsEfficiency = new AlternatorMapValues(efficiencyAverage / 100);
}
event TUGraz.VectoCore.BusAuxiliaries.Interfaces.AuxiliaryEventEventHandler IAuxiliaryEvent.AuxiliaryEvent
{
add {
throw new NotImplementedException();
}
remove {
throw new NotImplementedException();
}
}
// Helpers
private void CreateDefaultMap()
{
map.Clear();
map.Add(new CombinedAlternatorMapRow("Alt1", 2000, 10, 62, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt1", 2000, 27, 70, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt1", 2000, 53, 30, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt1", 4000, 10, 64, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt1", 4000, 63, 74, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt1", 4000, 125, 68, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt1", 6000, 10, 53, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt1", 6000, 68, 70, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt1", 6000, 136, 62, 3.6));
map.Add(new CombinedAlternatorMapRow("Alt2", 2000, 10, 62, 3));
map.Add(new CombinedAlternatorMapRow("Alt2", 2000, 27, 70, 3));
map.Add(new CombinedAlternatorMapRow("Alt2", 2000, 53, 30, 3));
map.Add(new CombinedAlternatorMapRow("Alt2", 4000, 10, 64, 3));
map.Add(new CombinedAlternatorMapRow("Alt2", 4000, 63, 74, 3));
map.Add(new CombinedAlternatorMapRow("Alt2", 4000, 125, 68, 3));
map.Add(new CombinedAlternatorMapRow("Alt2", 6000, 10, 53, 3));
map.Add(new CombinedAlternatorMapRow("Alt2", 6000, 68, 70, 3));
map.Add(new CombinedAlternatorMapRow("Alt2", 6000, 136, 62, 3));
}
// Grid Management
private bool AddNewAlternator(List<ICombinedAlternatorMapRow> list, ref string feeback)
{
var altName = list.First().AlternatorName;
var pulleyRatio = list.First().PulleyRatio;
// Check alt does not already exist in list
if (Alternators.Any(w => w.AlternatorName == altName)) {
feeback = "This alternator already exists in in the list, operation not completed.";
return false;
}
IAlternator alternator = new Alternator(altSignals, list.ToList());
Alternators.Add(alternator);
return true;
}
public bool AddAlternator(List<ICombinedAlternatorMapRow> rows, ref string feedback)
{
if (!AddNewAlternator(rows, ref feedback)) {
feedback = string.Format("Unable to add new alternator : {0}", feedback);
return false;
}
return true;
}
public bool DeleteAlternator(string alternatorName, ref string feedback, bool CountValidation)
{
// Is this the last alternator, if so deny the user the right to remove it.
if (CountValidation && Alternators.Count < 2) {
feedback = "There must be at least one alternator remaining, operation aborted.";
return false;
}
if (Alternators.All(w => w.AlternatorName != alternatorName)) {
feedback = "This alternator does not exist";
return false;
}
var altToRemove = Alternators.First(w => w.AlternatorName == alternatorName);
var numAlternators = Alternators.Count;
Alternators.Remove(altToRemove);
if (Alternators.Count == numAlternators - 1) {
return true;
}
feedback = string.Format("The alternator {0} could not be removed : {1}", alternatorName, feedback);
return false;
}
public bool Save(string aaltPath)
{
var sb = new StringBuilder();
// write headers
sb.AppendLine("[AlternatorName],[RPM],[Amps],[Efficiency],[PulleyRatio]");
// write details
foreach (var alt in Alternators.OrderBy(o => o.AlternatorName)) {
// 2000 - IE Alt1,2000,10,50,3
for (var row = 1; row <= 3; row++) {
var amps = alt.InputTable2000[row].Amps;
var eff = alt.InputTable2000[row].Eff;
sb.Append(alt.AlternatorName + ",2000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000"));
sb.AppendLine("");
}
// 4000 - IE Alt1,2000,10,50,3
for (var row = 1; row <= 3; row++) {
var amps = alt.InputTable4000[row].Amps;
var eff = alt.InputTable4000[row].Eff;
sb.Append(alt.AlternatorName + ",4000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000"));
sb.AppendLine("");
}
// 6000 - IE Alt1,2000,10,50,3
for (var row = 1; row <= 3; row++) {
var amps = alt.InputTable6000[row].Amps;
var eff = alt.InputTable6000[row].Eff;
sb.Append(alt.AlternatorName + ",6000," + amps.ToString("0.000") + "," + eff.ToString("0.000") + "," + alt.PulleyRatio.ToString("0.000"));
sb.AppendLine("");
}
}
// Add Model Source
sb.AppendLine("[MODELSOURCE]");
sb.Append(ToString());
// Write the stream cotnents to a new file named "AllTxtFiles.txt"
using (var outfile = new StreamWriter(aaltPath)) {
outfile.Write(sb.ToString());
}
return true;
}
private bool Load()
{
if (!InitialiseMap(FilePath))
return false;
return true;
}
// Initialises the map, only valid when loadingUI for first time in edit mode or always in operational mode.
private bool InitialiseMap(string filePath)
{
var returnValue = false;
string[] elements;
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.Count() < 10))
throw new ArgumentException("Insufficient rows in csv to build a usable map");
map = new List<ICombinedAlternatorMapRow>();
var firstline = true;
foreach (var line in lines) {
if (!firstline) {
// Advanced Alternator Source Check.
if (line.Contains("[MODELSOURCE"))
break;
// split the line
elements = line.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
// 3 entries per line required
if ((elements.Length != 5))
throw new ArgumentException("Incorrect number of values in csv file");
// add values to map
map.Add(new CombinedAlternatorMapRow(elements[0], float.Parse(elements[1], CultureInfo.InvariantCulture), float.Parse(elements[2], CultureInfo.InvariantCulture), float.Parse(elements[3], CultureInfo.InvariantCulture), float.Parse(elements[4], CultureInfo.InvariantCulture)));
} else
firstline = false;
}
}
return true;
} else
throw new ArgumentException("Supplied input file does not exist");
return returnValue;
}
// Can be used to send messages to Vecto.
public event AuxiliaryEventEventHandler AuxiliaryEvent;
public delegate void AuxiliaryEventEventHandler(ref object sender, string message, AdvancedAuxiliaryMessageType messageType);
// This is used to generate a diagnostics output which enables the user to
// Determine if they beleive the resulting map is what is expected
// Basically it is a check against the model/Spreadsheet
public override string ToString()
{
var sb = new StringBuilder();
string a1, a2, a3, e1, e2, e3;
const string vbTab = "\t";
foreach (Alternator alt in Alternators.OrderBy(o => o.AlternatorName)) {
sb.AppendLine("");
sb.AppendFormat("** {0} ** , PulleyRatio {1}", alt.AlternatorName, alt.PulleyRatio);
sb.AppendLine("");
sb.AppendLine("******************************************************************");
sb.AppendLine("");
var i = 1;
sb.AppendLine("Table 1 (2000)" + vbTab + "Table 2 (4000)" + vbTab + "Table 3 (6000)");
sb.AppendLine("Amps" + vbTab + "Eff" + vbTab + "Amps" + vbTab + "Eff" + vbTab + "Amps" + vbTab + "Eff" + vbTab);
sb.AppendLine("");
for (i = 1; i <= 3; i++) {
a1 = alt.InputTable2000[i].Amps.ToString("0");
e1 = alt.InputTable2000[i].Eff.ToString("0.000");
a2 = alt.InputTable4000[i].Amps.ToString("0");
e2 = alt.InputTable4000[i].Eff.ToString("0.000");
a3 = alt.InputTable6000[i].Amps.ToString("0");
e3 = alt.InputTable6000[i].Eff.ToString("0.000");
sb.AppendLine(a1 + vbTab + e1 + vbTab + a2 + vbTab + e2 + vbTab + a3 + vbTab + e3 + vbTab);
}
}
// sb.AppendLine("")
// sb.AppendLine("********* COMBINED EFFICIENCY VALUES **************")
// sb.AppendLine("")
// sb.AppendLine(vbTab + "RPM VALUES")
// sb.AppendLine("AMPS" + vbTab + "500" + vbTab + "1500" + vbTab + "2500" + vbTab + "3500" + vbTab + "4500" + vbTab + "5500" + vbTab + "6500" + vbTab + "7500")
// For a As Single = 1 To Alternators.Count * 50
// sb.Append(a.ToString("0") + vbTab)
// For Each r As Single In {500, 1500, 2500, 3500, 4500, 5500, 6500, 7500}
// Dim eff As Single = GetEfficiency(r, a).Efficiency
// sb.Append(eff.ToString("0.000") + vbTab)
// Next
// sb.AppendLine("")
// Next
return sb.ToString();
}
// Equality
public bool IsEqualTo(ICombinedAlternator other)
{
// Count Check.
if (this.Alternators.Count != other.Alternators.Count)
return false;
foreach (var alt in this.Alternators) {
// Can we find the same alternatorName in other
if (other.Alternators.Where(f => f.AlternatorName == alt.AlternatorName).Count() != 1)
return false;
// get the alternator to compare and compare it.
if (!alt.IsEqualTo(other.Alternators.First(f => f.AlternatorName == alt.AlternatorName)))
return false;
}
return true;
}
}
}
using System;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
// This class is reflective of the stored entries for the combined alternator
// And is used by the Combined Alternator Form and any related classes.
public class CombinedAlternatorMapRow : ICombinedAlternatorMapRow
{
public string AlternatorName { get; set; }
public double RPM { get; set; }
public double Amps { get; set; }
public double Efficiency { get; set; }
public double PulleyRatio { get; set; }
// Constructors
public CombinedAlternatorMapRow()
{
}
public CombinedAlternatorMapRow(string alternatorName, double rpm, double amps, double efficiency, double pulleyRatio)
{
// Sanity Check
if (alternatorName.Trim().Length == 0)
throw new ArgumentException("Alternator name cannot be zero length");
if (efficiency < 0 | efficiency > 100)
throw new ArgumentException("Alternator Efficiency must be between 0 and 100");
if (pulleyRatio <= 0)
throw new ArgumentException("Alternator Pully ratio must be a positive number");
// Assignments
AlternatorName = alternatorName;
RPM = rpm;
Amps = amps;
Efficiency = efficiency;
PulleyRatio = pulleyRatio;
}
}
}
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
// Used by the CombinedAlternator class and any other related classes.
public class CombinedAlternatorSignals : ICombinedAlternatorSignals
{
public double CrankRPM { get; set; }
public Ampere CurrentDemandAmps { get; set; }
// Number of alternators in the Combined Alternator
public int NumberOfAlternators { get; set; }
}
}
using System;
using System.ComponentModel;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
// 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.
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
/// <summary>
/// ''' Described a consumer of Alternator electrical power
/// ''' </summary>
/// ''' <remarks></remarks>
public class ElectricalConsumer : IElectricalConsumer
{
// Fields
private bool _BaseVehicle;
private string _Category;
private string _ConsumerName;
private double _NominalConsumptionAmps;
private int _NumberInActualVehicle;
private double _PhaseIdle_TractionOn;
private double _PowerNetVoltage;
private string _Info;
// Calculated
public double AvgConsumptionAmps { get; set; }
// Properties
public bool BaseVehicle
{
get {
return _BaseVehicle;
}
set {
_BaseVehicle = value;
NotifyPropertyChanged("BaseVehicle");
}
}
public string Category
{
get {
return _Category;
}
set {
_Category = value;
NotifyPropertyChanged("Category");
}
}
public string ConsumerName
{
get {
return _ConsumerName;
}
set {
_ConsumerName = value;
NotifyPropertyChanged("ConsumerName");
}
}
public double NominalConsumptionAmps
{
get {
return _NominalConsumptionAmps;
}
set {
_NominalConsumptionAmps = value;
NotifyPropertyChanged("NominalConsumptionAmps");
}
}
public int NumberInActualVehicle
{
get {
return _NumberInActualVehicle;
}
set {
_NumberInActualVehicle = value;
NotifyPropertyChanged("NumberInActualVehicle");
}
}
public double PhaseIdle_TractionOn
{
get {
return _PhaseIdle_TractionOn;
}
set {
_PhaseIdle_TractionOn = value;
NotifyPropertyChanged("PhaseIdle_TractionOn");
}
}
public double PowerNetVoltage
{
get {
return _PowerNetVoltage;
}
set {
_PowerNetVoltage = value;
NotifyPropertyChanged("PowerNetVoltage");
}
}
public string Info
{
get {
return _Info;
}
set {
_Info = value;
NotifyPropertyChanged("Info");
}
}
// Public class outputs
public Ampere TotalAvgConumptionAmps(double PhaseIdle_TractionOnBasedOnCycle = default(Double))
{
if (ConsumerName == "Doors per Door")
return NominalConsumptionAmps.SI<Ampere>() * (NumberInActualVehicle * PhaseIdle_TractionOnBasedOnCycle);
else
return NominalConsumptionAmps.SI<Ampere>() * (NumberInActualVehicle * PhaseIdle_TractionOn);
}
public Watt TotalAvgConsumptionInWatts(double PhaseIdle_TractionOnBasedOnCycle = 0.0)
{
return TotalAvgConumptionAmps(PhaseIdle_TractionOnBasedOnCycle) * PowerNetVoltage.SI<Volt>();
}
// Constructor
public ElectricalConsumer(bool BaseVehicle, string Category, string ConsumerName, double NominalConsumptionAmps, double PhaseIdle_TractionOn, double PowerNetVoltage, int numberInVehicle, string info)
{
// Illegal Value Check.
if (Category.Trim().Length == 0)
throw new ArgumentException("Category Name cannot be empty");
if (ConsumerName.Trim().Length == 0)
throw new ArgumentException("ConsumerName Name cannot be empty");
if (PhaseIdle_TractionOn < ElectricConstants.PhaseIdleTractionOnMin | PhaseIdle_TractionOn > ElectricConstants.PhaseIdleTractionMax)
throw new ArgumentException("PhaseIdle_TractionOn must have a value between 0 and 1");
if (NominalConsumptionAmps < ElectricConstants.NonminalConsumerConsumptionAmpsMin | NominalConsumptionAmps > ElectricConstants.NominalConsumptionAmpsMax)
throw new ArgumentException("NominalConsumptionAmps must have a value between 0 and 100");
if (PowerNetVoltage < ElectricConstants.PowenetVoltageMin | PowerNetVoltage > ElectricConstants.PowenetVoltageMax)
throw new ArgumentException("PowerNetVoltage must have a value between 6 and 48");
if (numberInVehicle < 0)
throw new ArgumentException("Cannot have less than 0 consumers in the vehicle");
// Good, now assign.
this.BaseVehicle = BaseVehicle;
this.Category = Category;
this.ConsumerName = ConsumerName;
this.NominalConsumptionAmps = NominalConsumptionAmps;
this.PhaseIdle_TractionOn = PhaseIdle_TractionOn;
this.PowerNetVoltage = PowerNetVoltage;
this.NumberInActualVehicle = numberInVehicle;
this.Info = info;
}
// Comparison Overrides
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
var other = (IElectricalConsumer)obj;
return this.ConsumerName == other.ConsumerName;
}
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public override int GetHashCode()
{
return 0;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string p)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(p));
}
}
}
// 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 ElectricalConsumerList : IElectricalConsumerList
{
private List<IElectricalConsumer> _items = new List<IElectricalConsumer>();
private double _powernetVoltage;
private double _doorDutyCycleZeroToOne;
// Constructor
public ElectricalConsumerList(double powernetVoltage, double doorDutyCycle_ZeroToOne, bool createDefaultList = false)
{
_powernetVoltage = powernetVoltage;
if (createDefaultList)
_items = GetDefaultConsumerList();
_doorDutyCycleZeroToOne = doorDutyCycle_ZeroToOne;
}
// Transfers the Info comments from a default set of consumables to a live set.
// This way makes the comments not dependent on saved data.
public void MergeInfoData()
{
if (_items.Count != GetDefaultConsumerList().Count)
return;
var dflt = GetDefaultConsumerList();
for (var idx = 0; idx <= _items.Count - 1; idx++)
_items[idx].Info = dflt[idx].Info;
}
// Initialise default set of consumers
public List<IElectricalConsumer> GetDefaultConsumerList()
{
// This populates the default settings as per engineering spreadsheet.
// Vehicle Basic Equipment' category can be added or remove by customers.
// At some time in the future, this may be removed and replace with file based consumer lists.
var items = new List<IElectricalConsumer>();
IElectricalConsumer c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20;
c1 = (IElectricalConsumer)new ElectricalConsumer(false, "Doors", "Doors per Door", 3.0, 0.096339, _powernetVoltage, 3, "");
c2 = (IElectricalConsumer)new ElectricalConsumer(true, "Veh Electronics &Engine", "Controllers,Valves etc", 25.0, 1.0, _powernetVoltage, 1, "");
c3 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "Radio City", 2.0, 0.8, _powernetVoltage, 1, "");
c4 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "Radio Intercity", 5.0, 0.8, _powernetVoltage, 0, "");
c5 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "Radio/Audio Tourism", 9.0, 0.8, _powernetVoltage, 0, "");
c6 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "Fridge", 4.0, 0.5, _powernetVoltage, 0, "");
c7 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "Kitchen Standard", 67.0, 0.05, _powernetVoltage, 0, "");
c8 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "Interior lights City/ Intercity + Doorlights [Should be 1/m]", 1.0, 0.7, _powernetVoltage, 12, "1 Per metre length of bus");
c9 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "LED Interior lights ceiling city/Intercity + door [Should be 1/m]", 0.6, 0.7, _powernetVoltage, 0, "1 Per metre length of bus");
c10 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "Interior lights Tourism + reading [1/m]", 1.1, 0.7, _powernetVoltage, 0, "1 Per metre length of bus");
c11 = (IElectricalConsumer)new ElectricalConsumer(false, "Vehicle basic equipment", "LED Interior lights ceiling Tourism + LED reading [Should be 1/m]", 0.66, 0.7, _powernetVoltage, 0, "1 Per metre length of bus");
c12 = (IElectricalConsumer)new ElectricalConsumer(false, "Customer Specific Equipment", "External Displays Font/Side/Rear", 2.65017667844523, 1.0, _powernetVoltage, 4, "");
c13 = (IElectricalConsumer)new ElectricalConsumer(false, "Customer Specific Equipment", "Internal display per unit ( front side rear)", 1.06007067137809, 1.0, _powernetVoltage, 1, "");
c14 = (IElectricalConsumer)new ElectricalConsumer(false, "Customer Specific Equipment", "CityBus Ref EBSF Table4 Devices ITS No Displays", 9.3, 1.0, _powernetVoltage, 1, "");
c15 = (IElectricalConsumer)new ElectricalConsumer(false, "Lights", "Exterior Lights BULB", 7.4, 1.0, _powernetVoltage, 1, "");
c16 = (IElectricalConsumer)new ElectricalConsumer(false, "Lights", "Day running lights LED bonus", -0.723, 1.0, _powernetVoltage, 1, "");
c17 = (IElectricalConsumer)new ElectricalConsumer(false, "Lights", "Antifog rear lights LED bonus", -0.17, 1.0, _powernetVoltage, 1, "");
c18 = (IElectricalConsumer)new ElectricalConsumer(false, "Lights", "Position lights LED bonus", -1.2, 1.0, _powernetVoltage, 1, "");
c19 = (IElectricalConsumer)new ElectricalConsumer(false, "Lights", "Direction lights LED bonus", -0.3, 1.0, _powernetVoltage, 1, "");
c20 = (IElectricalConsumer)new ElectricalConsumer(false, "Lights", "Brake Lights LED bonus", -1.2, 1.0, _powernetVoltage, 1, "");
items.Add(c1);
items.Add(c2);
items.Add(c3);
items.Add(c4);
items.Add(c5);
items.Add(c6);
items.Add(c7);
items.Add(c8);
items.Add(c9);
items.Add(c10);
items.Add(c11);
items.Add(c12);
items.Add(c13);
items.Add(c14);
items.Add(c15);
items.Add(c16);
items.Add(c17);
items.Add(c18);
items.Add(c19);
items.Add(c20);
return items;
}
// Interface implementation
public double DoorDutyCycleFraction
{
get {
return _doorDutyCycleZeroToOne;
}
set {
_doorDutyCycleZeroToOne = value;
}
}
public List<IElectricalConsumer> Items
{
get {
return _items;
}
}
public void AddConsumer(IElectricalConsumer consumer)
{
if (!_items.Contains(consumer))
_items.Add(consumer);
else
throw new ArgumentException("Consumer Already Present in the list");
}
public void RemoveConsumer(IElectricalConsumer consumer)
{
if (_items.Contains(consumer))
_items.Remove(consumer);
else
throw new ArgumentException("Consumer Not In List");
}
public Ampere GetTotalAverageDemandAmps(bool excludeOnBase)
{
Ampere Amps;
if (excludeOnBase)
Amps = Items.Where(x => x.BaseVehicle == false)
.Sum(consumer => consumer.TotalAvgConumptionAmps(DoorDutyCycleFraction));
// Aggregate item In Items Where item.BaseVehicle = False Into Sum(item.TotalAvgConumptionAmps(DoorDutyCycleFraction))
else
Amps = Items.Sum(x => x.TotalAvgConumptionAmps(DoorDutyCycleFraction));
//Aggregate item In Items Into Sum(item.TotalAvgConumptionAmps(DoorDutyCycleFraction))
return Amps;
}
}
}
// 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.Collections.Generic;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
public class ElectricsUserInputsConfig : IElectricsUserInputsConfig
{
public double PowerNetVoltage { get; set; }
public string AlternatorMap { get; set; }
public double AlternatorGearEfficiency { get; set; }
public IElectricalConsumerList ElectricalConsumers { get; set; }
public int DoorActuationTimeSecond { get; set; }
public double StoredEnergyEfficiency { get; set; }
public IResultCard ResultCardIdle { get; set; }
public IResultCard ResultCardTraction { get; set; }
public IResultCard ResultCardOverrun { get; set; }
public bool SmartElectrical { get; set; }
public ElectricsUserInputsConfig(bool setToDefaults = false, VectoInputs vectoInputs = null/* TODO Change to default(_) if this is not a reference type */)
{
if (setToDefaults)
SetPropertiesToDefaults(vectoInputs);
}
public void SetPropertiesToDefaults(VectoInputs vectoInputs)
{
DoorActuationTimeSecond = 4;
StoredEnergyEfficiency = 0.935;
AlternatorGearEfficiency = 0.92;
PowerNetVoltage = vectoInputs.PowerNetVoltage.Value();
ResultCardIdle = new ResultCard(new List<SmartResult>());
ResultCardOverrun = new ResultCard(new List<SmartResult>());
ResultCardTraction = new ResultCard(new List<SmartResult>());
SmartElectrical = false;
AlternatorMap = string.Empty;
}
}
}
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.Electrics
{
public class M00Impl : AbstractModule, IM0_NonSmart_AlternatorsSetEfficiency
{
protected Ampere _getHVACElectricalPowerDemandAmps;
protected double _alternatorsEfficiency;
protected IElectricalConsumerList _electricalConsumersList;
protected IAlternatorMap _alternatorEfficiencyMap;
protected Volt _powernetVoltage;
protected ISignals _signals;
protected ISSMTOOL _steadyStateModelHVAC;
protected Watt _ElectricalPowerW;
protected Watt _MechanicalPowerW;
protected LiterPerSecond _FuelingLPerH;
public M00Impl(
IElectricalConsumerList electricalConsumers, IAlternatorMap alternatorEfficiencyMap, Volt powernetVoltage,
ISignals signals, ISSMTOOL ssmHvac)
{
if (electricalConsumers == null) {
throw new ArgumentException("No ElectricalConsumersList Supplied");
}
if (alternatorEfficiencyMap == null) {
throw new ArgumentException("No Alternator Efficiency Map Supplied");
}
if (powernetVoltage < ElectricConstants.PowenetVoltageMin || powernetVoltage > ElectricConstants.PowenetVoltageMax) {
throw new ArgumentException("Powernet Voltage out of range");
}
if (signals == null) {
throw new ArgumentException("No Signals reference was supplied.");
}
_electricalConsumersList = electricalConsumers;
_alternatorEfficiencyMap = alternatorEfficiencyMap;
_powernetVoltage = powernetVoltage;
_signals = signals;
_steadyStateModelHVAC = ssmHvac;
_ElectricalPowerW = ssmHvac.ElectricalWAdjusted.SI<Watt>();
_MechanicalPowerW = ssmHvac.MechanicalWBaseAdjusted.SI<Watt>();
_FuelingLPerH = ssmHvac.FuelPerHBaseAdjusted.SI<LiterPerSecond>();
}
#region Implementation of IM0_NonSmart_AlternatorsSetEfficiency
public Ampere GetHVACElectricalPowerDemandAmps
{
get { return _ElectricalPowerW / _powernetVoltage; }
}
public double AlternatorsEfficiency
{
get {
var baseCurrentDemandAmps = _electricalConsumersList.GetTotalAverageDemandAmps(false);
var totalDemandAmps = baseCurrentDemandAmps + GetHVACElectricalPowerDemandAmps;
return _alternatorEfficiencyMap.GetEfficiency(_signals.EngineSpeed.AsRPM, totalDemandAmps).Efficiency;
}
}
#endregion
}
}
using System;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
public class M02Impl : AbstractModule, IM2_AverageElectricalLoadDemand
{
private Volt _powerNetVoltage;
private IElectricalConsumerList _electricalConsumers;
private IM0_NonSmart_AlternatorsSetEfficiency _module0;
private double _alternatorPulleyEffiency;
public M02Impl(
IElectricalConsumerList electricalConsumers, IM0_NonSmart_AlternatorsSetEfficiency m0, double altPulleyEfficiency,
Volt powerNetVoltage, ISignals signals)
{
if (electricalConsumers == null) {
throw new ArgumentException("Electrical Consumer List must be supplied");
}
if (m0 == null) {
throw new ArgumentException("Must supply module 0");
}
if (altPulleyEfficiency.IsEqual(0) || altPulleyEfficiency > 1) {
throw new ArgumentException("Alternator Gear efficiency out of range.");
}
if (powerNetVoltage < ElectricConstants.PowenetVoltageMin || powerNetVoltage > ElectricConstants.PowenetVoltageMax) {
throw new ArgumentException("Powernet Voltage out of known range.");
}
_powerNetVoltage = powerNetVoltage;
_electricalConsumers = electricalConsumers;
_module0 = m0;
_alternatorPulleyEffiency = altPulleyEfficiency;
}
#region Implementation of IM2_AverageElectricalLoadDemand
public Watt GetAveragePowerDemandAtAlternator()
{
return _powerNetVoltage * _electricalConsumers.GetTotalAverageDemandAmps(false);
}
public Watt GetAveragePowerAtCrankFromElectrics()
{
var ElectricalPowerDemandsWatts = GetAveragePowerDemandAtAlternator();
var alternatorsEfficiency = _module0.AlternatorsEfficiency;
var ElectricalPowerDemandsWattsDividedByAlternatorEfficiency =
ElectricalPowerDemandsWatts * (1 / alternatorsEfficiency);
var averagePowerDemandAtCrankFromElectricsWatts =
ElectricalPowerDemandsWattsDividedByAlternatorEfficiency * (1 / _alternatorPulleyEffiency);
return averagePowerDemandAtCrankFromElectricsWatts;
}
#endregion
}
}
using System;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
public class M05Impl : AbstractModule, IM5_SmartAlternatorSetGeneration
{
private IM0_5_SmartAlternatorSetEfficiency _m05;
private Volt _powerNetVoltage;
private double _alternatorGearEfficiency;
public M05Impl(IM0_5_SmartAlternatorSetEfficiency m05, Volt powernetVoltage, double alternatorGearEfficiency)
{
//'sanity check
if (m05 == null) {
throw new ArgumentException("Please supply a valid module M05");
}
if (powernetVoltage < ElectricConstants.PowenetVoltageMin || powernetVoltage > ElectricConstants.PowenetVoltageMax) {
throw new ArgumentException("Powernet Voltage out of range");
}
if (alternatorGearEfficiency < 0 || alternatorGearEfficiency > 1) {
throw new ArgumentException("AlternatorGearEfficiency Out of bounds, should be 0 to 1");
}
_m05 = m05;
_powerNetVoltage = powernetVoltage;
_alternatorGearEfficiency = alternatorGearEfficiency;
}
#region Implementation of IM5_SmartAlternatorSetGeneration
public Watt AlternatorsGenerationPowerAtCrankIdleWatts()
{
return _m05.SmartIdleCurrent * _powerNetVoltage *
(1 / (_m05.AlternatorsEfficiencyIdleResultCard * _alternatorGearEfficiency));
}
public Watt AlternatorsGenerationPowerAtCrankTractionOnWatts()
{
return _m05.SmartTractionCurrent * _powerNetVoltage *
(1 / (_m05.AlternatorsEfficiencyTractionOnResultCard * _alternatorGearEfficiency));
}
public Watt AlternatorsGenerationPowerAtCrankOverrunWatts()
{
return _m05.SmartOverrunCurrent * _powerNetVoltage *
(1 / (_m05.AlternatorsEfficiencyOverrunResultCard * _alternatorGearEfficiency));
}
#endregion
}
}
using System;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules;
using TUGraz.VectoCore.BusAuxiliaries.Interfaces.DownstreamModules.Electrics;
namespace TUGraz.VectoCore.BusAuxiliaries.DownstreamModules.Impl.Electrics
{
public class M0_5Impl : AbstractModule, IM0_5_SmartAlternatorSetEfficiency
{
protected Ampere _smartIdleCurrent;
protected double _alternatorsEfficiencyIdleResultCard;
protected Ampere _smartTractionCurrent;
protected double _alternatorsEfficiencyTractionOnResultCard;
protected Ampere _smartOverrunCurrent;
protected double _alternatorsEfficiencyOverrunResultCard;
protected IM0_NonSmart_AlternatorsSetEfficiency _m0;
protected IElectricalConsumerList _electricalConsumables;
protected IAlternatorMap _alternatorMap;
protected IResultCard _resultCardIdle;
protected IResultCard _resultCardTraction;
protected IResultCard _resultCardOverrun;
protected ISignals _signals;
public M0_5Impl(IM0_NonSmart_AlternatorsSetEfficiency m0, IElectricalConsumerList electricalConsumables, IAlternatorMap alternatorMap, IResultCard resultCardIdle, IResultCard resultCardTraction, IResultCard resultCardOverrun, ISignals signals)
{
//'Sanity Check on supplied arguments, throw an argument exception
if (m0 == null) {
throw new ArgumentException("Module 0 must be supplied");}
if (electricalConsumables == null) {
throw new ArgumentException("ElectricalConsumablesList must be supplied even if empty");
}
if (alternatorMap ==null) {throw new ArgumentException("Must supply a valid alternator map");
}
if (resultCardIdle == null) {
throw new ArgumentException("Result Card 'IDLE' must be supplied even if it has no contents");
}
if (resultCardTraction == null) {
throw new ArgumentException("Result Card 'TRACTION' must be supplied even if it has no contents");
}
if (resultCardOverrun == null) {
throw new ArgumentException("Result Card 'OVERRUN' must be supplied even if it has no contents");
}
if (signals == null) {
throw new ArgumentException("No Signals Reference object was provided ");}
//'Assignments to private variables.
_m0 = m0;
_electricalConsumables = electricalConsumables;
_alternatorMap = alternatorMap;
_resultCardIdle = resultCardIdle;
_resultCardTraction = resultCardTraction;
_resultCardOverrun = resultCardOverrun;
_signals = signals;
}
#region Implementation of IM0_5_SmartAlternatorSetEfficiency
private Ampere HvacPlusNonBaseCurrents()
{
//'Stored Energy Efficience removed from V8.0 21/4/15 by Mike Preston //tb
return _m0.GetHVACElectricalPowerDemandAmps + _electricalConsumables.GetTotalAverageDemandAmps(true); //'/ElectricConstants.StoredEnergyEfficiency)
}
public Ampere SmartIdleCurrent
{
get {
var hvac_Plus_None_Base = HvacPlusNonBaseCurrents();
var smart_idle_current = _resultCardIdle.GetSmartCurrentResult(hvac_Plus_None_Base);
return smart_idle_current;
}
}
public double AlternatorsEfficiencyIdleResultCard
{
get { return _alternatorMap.GetEfficiency(_signals.EngineSpeed.AsRPM, SmartIdleCurrent).Efficiency; }
}
public Ampere SmartTractionCurrent
{
get { return _resultCardTraction.GetSmartCurrentResult(HvacPlusNonBaseCurrents()); }
}
public double AlternatorsEfficiencyTractionOnResultCard
{
get { return _alternatorMap.GetEfficiency(_signals.EngineSpeed.AsRPM, SmartTractionCurrent).Efficiency; }
}
public Ampere SmartOverrunCurrent
{
get { return _resultCardOverrun.GetSmartCurrentResult(HvacPlusNonBaseCurrents()); }
}
public double AlternatorsEfficiencyOverrunResultCard
{
get { return _alternatorMap.GetEfficiency(_signals.EngineSpeed.AsRPM, SmartOverrunCurrent).Efficiency; }
}
#endregion
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment