diff --git a/Declaration/VAUX/Fan-Tech.csv b/Declaration/VAUX/Fan-Tech.csv index 81865eb4507ebd2c5c6dbc3a84701ce64a9a5299..3dd384fc44840daa0ef4a12811aba14b26e40705 100644 --- a/Declaration/VAUX/Fan-Tech.csv +++ b/Declaration/VAUX/Fan-Tech.csv @@ -1,12 +1,12 @@ -Technology,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach -Crankshaft mounted - Electronically controlled visco clutch (Default),618,671,516,566,1037,0,0,0,0,0 -Crankshaft mounted - Bimetallic controlled visco clutch,818,871,676,766,1277,0,0,0,0,0 -Crankshaft mounted - Discrete step clutch,668,721,616,616,1157,0,0,0,0,0 -Crankshaft mounted - On/Off clutch,718,771,666,666,1237,0,0,0,0,0 -Belt driven or driven via transm. - Electronically controlled visco clutch,889,944,733,833,1378,0,0,0,0,0 -Belt driven or driven via transm. - Bimetallic controlled visco clutch,1089,1144,893,1033,1618,0,0,0,0,0 -Belt driven or driven via transm. - Discrete step clutch,939,994,883,883,1498,0,0,0,0,0 -Belt driven or driven via transm. - On/Off clutch,989,1044,933,933,1578,0,0,0,0,0 -Hydraulic driven - Variable displacement pump,738,955,632,717,1672,0,0,0,0,0 -Hydraulic driven - Constant displacement pump,1000,1200,800,900,2100,0,0,0,0,0 -Hydraulic driven - Electronically controlled,700,800,600,600,1400,0,0,0,0,0 +Technology,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction +Crankshaft mounted - Electronically controlled visco clutch,618,671,516,566,1037 +Crankshaft mounted - Bimetallic controlled visco clutch,818,871,676,766,1277 +Crankshaft mounted - Discrete step clutch,668,721,616,616,1157 +Crankshaft mounted - On/off clutch,718,771,666,666,1237 +Belt driven or driven via transm. - Electronically controlled visco clutch,989,1044,833,933,1478 +Belt driven or driven via transm. - Bimetallic controlled visco clutch,1189,1244,993,1133,1718 +Belt driven or driven via transm. - Discrete step clutch,1039,1094,983,983,1598 +Belt driven or driven via transm. - On/off clutch,1089,1144,1033,1033,1678 +Hydraulic driven - Variable displacement pump,938,1155,832,917,1872 +Hydraulic driven - Constant displacement pump,1200,1400,1000,1100,2300 +Hydraulic driven - Electronically controlled,700,800,600,600,1400 diff --git a/Declaration/Wheels.csv b/Declaration/Wheels.csv index f49a335209e44ff9951ed5e98a2785bd226be895..5dda0ca85a381b0db0d882056a47ece906c010b2 100644 --- a/Declaration/Wheels.csv +++ b/Declaration/Wheels.csv @@ -1,41 +1,58 @@ -Wheel,Inertia,d,Size-Class (0/1) -9 R22.5,8.9,970,b -9.00 R20,10.5,1018,b -9.5 R17.5,4.9,842,b -10 R17.5,5,858,b -10 R22.5,11,1020,b -10.00 R20,13.1,1025,b -11 R22.5,14.4,1050,b -11.00 R20,14.6,1082,b -12 R22.5,16.8,1084,b -12.00 R20,19.5,1122,b -12.00 R24,27.7,1226,b -12.5 R20,12.7,1120,b -13 R22.5,20,1124,b -14.00 R20,30.8,1238,b -14.5 R20,14.8,1092,b -16.00 R20,47.5,1343,b -215/75 R17.5,3.9,767,b -225/70 R17.5,4,759.5,b -225/75 R17.5,4,782,b -235/75 R17.5,4.5,797,b -245/70 R17.5,5.2,787.5,b -245/70 R19.5,6,838.3,b -255/70 R22.5,9.5,928.5,b -265/70 R19.5,6.5,866.3,b -275/70 R22.5,11.9,956.5,b -275/80 R22.5,12.8,1011.5,b -285/70 R19.5,7.9,894.3,b +Wheel,Inertia,d,Size-Class (0/1) +9.5 R17.5,4.9,842,a +9.00 R20,10.5,1018,a +9 R22.5,8.9,970,a +10 R17.5,5,858,a +10 R22.5,11,1020,a +10.00 R20,13.1,1025,a +11 R22.5,14.4,1050,a +11.00 R20,14.6,1082,a +11.00 R22,16,1089.66,a +12 R22.5,16.85,1084,a +12.00 R20,19.5,1122,a +12.00 R24,27.7,1226,a +12.5 R20,12.7,1120,a +13 R22.5,20,1124,a +14.00 R20,30.8,1238,a +14.5 R20,14.8,1092,a +16.00 R20,47.5,1343,a +205/75 R17.5,3.5,752,a +215/75 R17.5,3.9,767,a +225/70 R17.5,4,759.5,a +225/75 R17.5,4,782,a +235/75 R17.5,4.5,797,a +245/70 R17.5,5.2,787.5,a +245/70 R19.5,6,838.3,a +255/70 R22.5,9.5,928.5,a +265/70 R17.5,5.6,817,a +265/70 R19.5,6.5,866.3,a +275/70 R22.5,11.9,956.5,a +275/80 R22.5,12.8,1011.5,a +285/60 R22.5,10.6,913.5,a +285/70 R19.5,7.9,894.3,a 295/55 R22.5,10.2,896,a 295/60 R22.5,10.8,925.5,a -295/80 R22.5,15.5,1043.5,b -305/70 R19.5,9.2,922.3,b -305/70 R22.5,13.9,998.5,b +295/80 R22.5,15.5,1043.5,a +305/60 R22.5,11.4,922.3,a +305/70 R19.5,9.2,998.5,a +305/70 R22.5,13.9,998.5,a +305/75 R24.5,21.2,1079.8,a 315/45 R22.5,9.9,855,a 315/60 R22.5,12.8,949.5,a -315/70 R22.5,14.9,1012.5,b -315/80 R22.5,17.6,1075.5,b -365/80 R20,17.2,1092,b -365/85 R20,22.5,1128.5,b +315/70 R22.5,14.9,1012.5,a +315/80 R22.5,17.6,1075.5,a +325/95 R24,27.6,1227.1,a +335/80 R20,13.5,1044,a +355/50 R22.5,12.2,926.5,a +365/70 R22.5,18.6,1082.5,a +365/80 R20,17.2,1092,a +365/85 R20,22.5,1128.5,a +375/45 R22.5,11.2,909,a +375/50 R22.5,13,946.5,a +375/90 R22.5,33.8,1246.5,a 385/55 R22.5,15.9,995,a 385/65 R22.5,19.2,1072,a +395/85 R20,27.9,1179.5,a +425/65 R22.5,22.5,1124,a +495/45 R22.5,20.7,1017,a +525/65 R20.5,35,1203.2,a diff --git a/Generic Vehicles/Declaration Mode/40t Long Haul Truck/40t_Long_Haul_Truck.vecto b/Generic Vehicles/Declaration Mode/40t Long Haul Truck/40t_Long_Haul_Truck.vecto index ca10668c60c6829d1fb44897c8c424742aabd3cb..3174f84f5863978d30ad270aa993dc408bae2f0c 100644 --- a/Generic Vehicles/Declaration Mode/40t Long Haul Truck/40t_Long_Haul_Truck.vecto +++ b/Generic Vehicles/Declaration Mode/40t Long Haul Truck/40t_Long_Haul_Truck.vecto @@ -28,7 +28,7 @@ "ID": "STP", "Type": "Steering pump", "Path": "<NOFILE>", - "Technology": "Variable displacement" + "Technology": "Variable displacement mech. controlled" }, { "ID": "AC", diff --git a/Tools/VectoLegacyTests/TorqueConverterTest.cs b/Tools/VectoLegacyTests/TorqueConverterTest.cs index a6c0ef8f81102326957082e9fb24867cb94bfb7c..cbc5b3e0afdcb4bc84af9e31efdacca53e527e8a 100644 --- a/Tools/VectoLegacyTests/TorqueConverterTest.cs +++ b/Tools/VectoLegacyTests/TorqueConverterTest.cs @@ -62,7 +62,6 @@ namespace VectoLegacyTests VECTO_Global.MODdata.CycleInit(); - VECTO_Global.GBX = cGbx; VECTO_Global.ENG = new cENG(); VECTO_Global.ENG.FilePath = diff --git a/VECTO/File Browser/FB_Dialog.designer.vb b/VECTO/File Browser/FB_Dialog.designer.vb index 6a0cb29cbb2ac642e9bc4ece26b37858a6c34be7..5f9329e3f85c31655474bcefffddc9b96ffb796f 100644 --- a/VECTO/File Browser/FB_Dialog.designer.vb +++ b/VECTO/File Browser/FB_Dialog.designer.vb @@ -77,6 +77,7 @@ Partial Class FB_Dialog Me.SplitContainer1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.SplitContainer1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.SplitContainer1.Location = New System.Drawing.Point(0, 46) Me.SplitContainer1.Name = "SplitContainer1" ' @@ -100,8 +101,8 @@ Partial Class FB_Dialog Me.SplitContainer1.Panel2.Controls.Add(Me.ButtonHisFile) Me.SplitContainer1.Panel2.Controls.Add(Me.TextBoxSearchFile) Me.SplitContainer1.Panel2.Controls.Add(Me.ListViewFiles) - Me.SplitContainer1.Size = New System.Drawing.Size(734, 292) - Me.SplitContainer1.SplitterDistance = 365 + Me.SplitContainer1.Size = New System.Drawing.Size(663, 308) + Me.SplitContainer1.SplitterDistance = 329 Me.SplitContainer1.TabIndex = 5 Me.SplitContainer1.TabStop = False ' @@ -109,7 +110,7 @@ Partial Class FB_Dialog ' Me.Label1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) Me.Label1.AutoSize = True - Me.Label1.Location = New System.Drawing.Point(3, 272) + Me.Label1.Location = New System.Drawing.Point(3, 284) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(32, 13) Me.Label1.TabIndex = 28 @@ -118,7 +119,7 @@ Partial Class FB_Dialog 'ButtonNewDir ' Me.ButtonNewDir.Image = Global.VECTO.My.Resources.Resources.new_dir - Me.ButtonNewDir.Location = New System.Drawing.Point(141, 1) + Me.ButtonNewDir.Location = New System.Drawing.Point(119, 1) Me.ButtonNewDir.Name = "ButtonNewDir" Me.ButtonNewDir.Size = New System.Drawing.Size(26, 25) Me.ButtonNewDir.TabIndex = 21 @@ -129,7 +130,7 @@ Partial Class FB_Dialog 'ButtonDesktop ' Me.ButtonDesktop.Image = Global.VECTO.My.Resources.Resources.desktop - Me.ButtonDesktop.Location = New System.Drawing.Point(87, 1) + Me.ButtonDesktop.Location = New System.Drawing.Point(90, 1) Me.ButtonDesktop.Name = "ButtonDesktop" Me.ButtonDesktop.Size = New System.Drawing.Size(26, 25) Me.ButtonDesktop.TabIndex = 22 @@ -139,34 +140,36 @@ Partial Class FB_Dialog ' 'ButtonHisFolder ' - Me.ButtonHisFolder.Image = Global.VECTO.My.Resources.Resources.favorites - Me.ButtonHisFolder.Location = New System.Drawing.Point(114, 1) + Me.ButtonHisFolder.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.ButtonHisFolder.Image = Global.VECTO.My.Resources.Resources.file_history + Me.ButtonHisFolder.Location = New System.Drawing.Point(298, 1) Me.ButtonHisFolder.Name = "ButtonHisFolder" Me.ButtonHisFolder.Size = New System.Drawing.Size(26, 25) Me.ButtonHisFolder.TabIndex = 24 Me.ButtonHisFolder.TabStop = False - Me.ToolTip1.SetToolTip(Me.ButtonHisFolder, "Select from recent directories / favorites") + Me.ToolTip1.SetToolTip(Me.ButtonHisFolder, "History / Favorites") Me.ButtonHisFolder.UseVisualStyleBackColor = True ' 'ButtonFolderBack ' Me.ButtonFolderBack.Image = CType(resources.GetObject("ButtonFolderBack.Image"), System.Drawing.Image) - Me.ButtonFolderBack.Location = New System.Drawing.Point(60, 1) + Me.ButtonFolderBack.Location = New System.Drawing.Point(61, 1) Me.ButtonFolderBack.Name = "ButtonFolderBack" Me.ButtonFolderBack.Size = New System.Drawing.Size(26, 25) Me.ButtonFolderBack.TabIndex = 20 Me.ButtonFolderBack.TabStop = False - Me.ToolTip1.SetToolTip(Me.ButtonFolderBack, "Move up one directory level") + Me.ToolTip1.SetToolTip(Me.ButtonFolderBack, "Move up one directory") Me.ButtonFolderBack.UseVisualStyleBackColor = True ' 'TextBoxSearchFolder ' Me.TextBoxSearchFolder.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) - Me.TextBoxSearchFolder.Location = New System.Drawing.Point(37, 269) + Me.TextBoxSearchFolder.Location = New System.Drawing.Point(37, 281) Me.TextBoxSearchFolder.Name = "TextBoxSearchFolder" - Me.TextBoxSearchFolder.Size = New System.Drawing.Size(328, 20) + Me.TextBoxSearchFolder.Size = New System.Drawing.Size(288, 20) Me.TextBoxSearchFolder.TabIndex = 15 + Me.ToolTip1.SetToolTip(Me.TextBoxSearchFolder, "Filter the directories") ' 'ListViewFolder ' @@ -180,7 +183,7 @@ Partial Class FB_Dialog Me.ListViewFolder.Location = New System.Drawing.Point(-2, 27) Me.ListViewFolder.MultiSelect = False Me.ListViewFolder.Name = "ListViewFolder" - Me.ListViewFolder.Size = New System.Drawing.Size(367, 241) + Me.ListViewFolder.Size = New System.Drawing.Size(327, 253) Me.ListViewFolder.SmallImageList = Me.ImageList1 Me.ListViewFolder.TabIndex = 10 Me.ListViewFolder.UseCompatibleStateImageBehavior = False @@ -210,7 +213,7 @@ Partial Class FB_Dialog ' Me.Label5.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.Label5.AutoSize = True - Me.Label5.Location = New System.Drawing.Point(295, 272) + Me.Label5.Location = New System.Drawing.Point(256, 284) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(10, 13) Me.Label5.TabIndex = 30 @@ -220,7 +223,7 @@ Partial Class FB_Dialog ' Me.Label2.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) Me.Label2.AutoSize = True - Me.Label2.Location = New System.Drawing.Point(3, 272) + Me.Label2.Location = New System.Drawing.Point(3, 284) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(32, 13) Me.Label2.TabIndex = 29 @@ -228,42 +231,45 @@ Partial Class FB_Dialog ' 'ButtonAll ' - Me.ButtonAll.Location = New System.Drawing.Point(25, 2) + Me.ButtonAll.Location = New System.Drawing.Point(2, 2) Me.ButtonAll.Name = "ButtonAll" Me.ButtonAll.Size = New System.Drawing.Size(71, 23) Me.ButtonAll.TabIndex = 19 Me.ButtonAll.Text = "Select All" - Me.ToolTip1.SetToolTip(Me.ButtonAll, "Select All Files") + Me.ToolTip1.SetToolTip(Me.ButtonAll, "Select all shown files") Me.ButtonAll.UseVisualStyleBackColor = True ' 'ComboBoxExt ' Me.ComboBoxExt.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.ComboBoxExt.FormattingEnabled = True - Me.ComboBoxExt.Location = New System.Drawing.Point(307, 269) + Me.ComboBoxExt.Location = New System.Drawing.Point(268, 281) Me.ComboBoxExt.Name = "ComboBoxExt" Me.ComboBoxExt.Size = New System.Drawing.Size(57, 21) Me.ComboBoxExt.TabIndex = 20 + Me.ToolTip1.SetToolTip(Me.ComboBoxExt, "Filter the file type") ' 'ButtonHisFile ' + Me.ButtonHisFile.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.ButtonHisFile.Image = Global.VECTO.My.Resources.Resources.file_history - Me.ButtonHisFile.Location = New System.Drawing.Point(-1, 1) + Me.ButtonHisFile.Location = New System.Drawing.Point(299, 1) Me.ButtonHisFile.Name = "ButtonHisFile" Me.ButtonHisFile.Size = New System.Drawing.Size(26, 25) Me.ButtonHisFile.TabIndex = 24 Me.ButtonHisFile.TabStop = False - Me.ToolTip1.SetToolTip(Me.ButtonHisFile, "Select from recent files") + Me.ToolTip1.SetToolTip(Me.ButtonHisFile, "History") Me.ButtonHisFile.UseVisualStyleBackColor = True ' 'TextBoxSearchFile ' Me.TextBoxSearchFile.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) - Me.TextBoxSearchFile.Location = New System.Drawing.Point(36, 269) + Me.TextBoxSearchFile.Location = New System.Drawing.Point(36, 281) Me.TextBoxSearchFile.Name = "TextBoxSearchFile" - Me.TextBoxSearchFile.Size = New System.Drawing.Size(257, 20) + Me.TextBoxSearchFile.Size = New System.Drawing.Size(218, 20) Me.TextBoxSearchFile.TabIndex = 15 + Me.ToolTip1.SetToolTip(Me.TextBoxSearchFile, "Filter the files") ' 'ListViewFiles ' @@ -277,7 +283,7 @@ Partial Class FB_Dialog Me.ListViewFiles.HideSelection = False Me.ListViewFiles.Location = New System.Drawing.Point(0, 27) Me.ListViewFiles.Name = "ListViewFiles" - Me.ListViewFiles.Size = New System.Drawing.Size(367, 241) + Me.ListViewFiles.Size = New System.Drawing.Size(328, 253) Me.ListViewFiles.SmallImageList = Me.ImageList1 Me.ListViewFiles.TabIndex = 10 Me.ListViewFiles.UseCompatibleStateImageBehavior = False @@ -310,9 +316,9 @@ Partial Class FB_Dialog ' Me.TextBoxPath.Anchor = CType(((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) - Me.TextBoxPath.Location = New System.Drawing.Point(47, 354) + Me.TextBoxPath.Location = New System.Drawing.Point(47, 370) Me.TextBoxPath.Name = "TextBoxPath" - Me.TextBoxPath.Size = New System.Drawing.Size(680, 20) + Me.TextBoxPath.Size = New System.Drawing.Size(609, 20) Me.TextBoxPath.TabIndex = 15 ' 'ContextMenuHisFolder @@ -329,7 +335,7 @@ Partial Class FB_Dialog ' Me.ButtonOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.ButtonOK.DialogResult = System.Windows.Forms.DialogResult.OK - Me.ButtonOK.Location = New System.Drawing.Point(574, 383) + Me.ButtonOK.Location = New System.Drawing.Point(503, 399) Me.ButtonOK.Name = "ButtonOK" Me.ButtonOK.Size = New System.Drawing.Size(75, 23) Me.ButtonOK.TabIndex = 20 @@ -341,7 +347,7 @@ Partial Class FB_Dialog ' Me.ButtonCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.ButtonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel - Me.ButtonCancel.Location = New System.Drawing.Point(652, 383) + Me.ButtonCancel.Location = New System.Drawing.Point(581, 399) Me.ButtonCancel.Name = "ButtonCancel" Me.ButtonCancel.Size = New System.Drawing.Size(75, 23) Me.ButtonCancel.TabIndex = 25 @@ -357,15 +363,16 @@ Partial Class FB_Dialog Me.TextBoxCurrent.Location = New System.Drawing.Point(5, 17) Me.TextBoxCurrent.Name = "TextBoxCurrent" Me.TextBoxCurrent.ReadOnly = True - Me.TextBoxCurrent.Size = New System.Drawing.Size(722, 20) + Me.TextBoxCurrent.Size = New System.Drawing.Size(651, 20) Me.TextBoxCurrent.TabIndex = 0 Me.TextBoxCurrent.TabStop = False + Me.ToolTip1.SetToolTip(Me.TextBoxCurrent, "Click for changing the directory") ' 'Label3 ' Me.Label3.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) Me.Label3.AutoSize = True - Me.Label3.Location = New System.Drawing.Point(5, 357) + Me.Label3.Location = New System.Drawing.Point(5, 373) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(38, 13) Me.Label3.TabIndex = 29 @@ -385,7 +392,7 @@ Partial Class FB_Dialog Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.CancelButton = Me.ButtonCancel - Me.ClientSize = New System.Drawing.Size(734, 412) + Me.ClientSize = New System.Drawing.Size(663, 428) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.TextBoxCurrent) diff --git a/VECTO/File Browser/FB_Dialog.resx b/VECTO/File Browser/FB_Dialog.resx index 1f675622abb70d7027ea8b8d44fcdb5dfc56685b..67a95d3c92ccde32e8069a816021a3528a48b15b 100644 --- a/VECTO/File Browser/FB_Dialog.resx +++ b/VECTO/File Browser/FB_Dialog.resx @@ -138,9 +138,6 @@ jqwl8R39jQOjteHrj7IORZfdCA3xbzsgQUH/AJeyUFejvjvmAAAAAElFTkSuQmCC </value> </data> - <metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - <value>583, 17</value> - </metadata> <metadata name="ImageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>473, 17</value> </metadata> diff --git a/VECTO/GUI/F_GBX.vb b/VECTO/GUI/F_GBX.vb index 9e391c2f87e77e1ec4afa94d43669f32ba262273..71b28e3e8ae80251f3bb0c54a22058b2a5ba049d 100644 --- a/VECTO/GUI/F_GBX.vb +++ b/VECTO/GUI/F_GBX.vb @@ -1,4 +1,4 @@ -' Copyright 2014 European Union. +' Copyright 2014 European Union. ' Licensed under the EUPL (the 'Licence'); ' ' * You may not use this work except in compliance with the Licence. diff --git a/VECTO/GUI/F_MAINForm.Designer.vb b/VECTO/GUI/F_MAINForm.Designer.vb index 8f1600aa8aa84db04467d683f726e0321ecde240..5195446d665ccdb43a26256778b77cb24954b321 100644 --- a/VECTO/GUI/F_MAINForm.Designer.vb +++ b/VECTO/GUI/F_MAINForm.Designer.vb @@ -1050,6 +1050,7 @@ Partial Class F_MAINForm ' 'F_MAINForm ' + Me.AcceptButton = Me.btStartV3 Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(1073, 638) diff --git a/VECTO/GUI/F_VECTO.vb b/VECTO/GUI/F_VECTO.vb index e751fcbb255e5605034cd3c66ec3e3f6bdd6fef1..f967d65c0834e20932a28d5ef39ab960933dc3f0 100644 --- a/VECTO/GUI/F_VECTO.vb +++ b/VECTO/GUI/F_VECTO.vb @@ -8,10 +8,12 @@ ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ' ' See the LICENSE.txt for the specific language governing permissions and limitations. +Option Infer On Imports System.Collections.Generic Imports System.Drawing.Imaging Imports System.IO +Imports System.Linq Imports System.Text.RegularExpressions Imports System.Windows.Forms.DataVisualization.Charting @@ -29,8 +31,6 @@ Public Class F_VECTO Private AuxDlog As F_VEH_AuxDlog - Private EStechs As New List(Of String) - Public n_idle As Single Public FLDfile As String @@ -48,7 +48,7 @@ Public Class F_VECTO 'Initialise form - Private Sub F02_GEN_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load + Private Sub F02_GEN_Load(sender As Object, e As EventArgs) Handles Me.Load Dim x As Int16 n_idle = -1 @@ -56,30 +56,30 @@ Public Class F_VECTO AuxDlog = New F_VEH_AuxDlog - pgDriver = Me.TabPgDriver + pgDriver = TabPgDriver - For x = 0 To Me.TabControl1.TabCount - 1 - Me.TabControl1.TabPages(x).Show() + For x = 0 To TabControl1.TabCount - 1 + TabControl1.TabPages(x).Show() Next - Me.LvAux.Columns(2).Width = -2 + LvAux.Columns(2).Width = -2 'Declaration Mode If Cfg.DeclMode Then - Me.LvAux.Columns(2).Text = "Technology" + LvAux.Columns(2).Text = "Technology" Else - Me.LvAux.Columns(2).Text = "Input File" + LvAux.Columns(2).Text = "Input File" End If - Me.CbEngOnly.Enabled = Not Cfg.DeclMode - Me.GrCycles.Enabled = Not Cfg.DeclMode - Me.GrVACC.Enabled = Not Cfg.DeclMode - Me.PnStartStop.Enabled = Not Cfg.DeclMode - Me.RdOff.Enabled = Not Cfg.DeclMode - Me.GrLAC.Enabled = Not Cfg.DeclMode - Me.ButAuxAdd.Enabled = Not Cfg.DeclMode - Me.ButAuxRem.Enabled = Not Cfg.DeclMode - Me.PnEcoRoll.Enabled = Not Cfg.DeclMode + CbEngOnly.Enabled = Not Cfg.DeclMode + GrCycles.Enabled = Not Cfg.DeclMode + GrVACC.Enabled = Not Cfg.DeclMode + PnStartStop.Enabled = Not Cfg.DeclMode + RdOff.Enabled = Not Cfg.DeclMode + GrLAC.Enabled = Not Cfg.DeclMode + ButAuxAdd.Enabled = Not Cfg.DeclMode + ButAuxRem.Enabled = Not Cfg.DeclMode + PnEcoRoll.Enabled = Not Cfg.DeclMode Changed = False 'AA-TB @@ -89,8 +89,7 @@ Public Class F_VECTO End Sub 'Close - Check for unsaved changes - Private Sub F02_GEN_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) _ - Handles Me.FormClosing + Private Sub F02_GEN_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing If e.CloseReason <> CloseReason.ApplicationExitCall And e.CloseReason <> CloseReason.WindowsShutDown Then e.Cancel = ChangeCheckCancel() End If @@ -102,31 +101,31 @@ Public Class F_VECTO If Not Cfg.DeclMode Then Exit Sub - Me.LvCycles.Items.Clear() - Me.CbEngOnly.Checked = False - Me.TbDesMaxFile.Text = "" - If Not Me.RdEcoRoll.Checked Then Me.RdOverspeed.Checked = True - Me.CbLookAhead.Checked = True - - Me.TbSSspeed.Text = cDeclaration.SSspeed - Me.TbSStime.Text = cDeclaration.SStime - Me.TbSSdelay.Text = cDeclaration.SSdelay - Me.TbAlookahead.Text = cDeclaration.LACa - Me.TbVminLA.Text = cDeclaration.LACvmin + LvCycles.Items.Clear() + CbEngOnly.Checked = False + TbDesMaxFile.Text = "" + If Not RdEcoRoll.Checked Then RdOverspeed.Checked = True + CbLookAhead.Checked = True + + TbSSspeed.Text = cDeclaration.SSspeed + TbSStime.Text = cDeclaration.SStime + TbSSdelay.Text = cDeclaration.SSdelay + TbAlookahead.Text = cDeclaration.LACa + TbVminLA.Text = cDeclaration.LACvmin tbLacPreviewFactor.Text = "10" tbLacDfTargetSpeedFile.Text = "" tbLacDfVelocityDropFile.Text = "" - Me.TbOverspeed.Text = cDeclaration.Overspeed - Me.TbUnderSpeed.Text = cDeclaration.Underspeed - Me.TbVmin.Text = cDeclaration.ECvmin + TbOverspeed.Text = cDeclaration.Overspeed + TbUnderSpeed.Text = cDeclaration.Underspeed + TbVmin.Text = cDeclaration.ECvmin If _ LvAux.Items.Count <> 5 OrElse - (Me.LvAux.Items(0).Text <> sKey.AUX.Fan OrElse Me.LvAux.Items(1).Text <> sKey.AUX.SteerPump OrElse - Me.LvAux.Items(2).Text <> sKey.AUX.HVAC OrElse Me.LvAux.Items(3).Text <> sKey.AUX.ElecSys OrElse - Me.LvAux.Items(4).Text <> sKey.AUX.PneumSys) Then - Me.LvAux.Items.Clear() + (LvAux.Items(0).Text <> sKey.AUX.Fan OrElse LvAux.Items(1).Text <> sKey.AUX.SteerPump OrElse + LvAux.Items(2).Text <> sKey.AUX.HVAC OrElse LvAux.Items(3).Text <> sKey.AUX.ElecSys OrElse + LvAux.Items(4).Text <> sKey.AUX.PneumSys) Then + LvAux.Items.Clear() LV0 = New ListViewItem(sKey.AUX.Fan) LV0.SubItems.Add("Fan") @@ -135,7 +134,7 @@ Public Class F_VECTO Else LV0.SubItems.Add(Declaration.AuxTechs(tAux.Fan)(0)) End If - Me.LvAux.Items.Add(LV0) + LvAux.Items.Add(LV0) LV0 = New ListViewItem(sKey.AUX.SteerPump) LV0.SubItems.Add("Steering pump") @@ -144,16 +143,12 @@ Public Class F_VECTO Else LV0.SubItems.Add(Declaration.AuxTechs(tAux.SteerPump)(0)) End If - Me.LvAux.Items.Add(LV0) + LvAux.Items.Add(LV0) LV0 = New ListViewItem(sKey.AUX.HVAC) LV0.SubItems.Add("HVAC") - If Declaration.AuxTechs(tAux.HVAC).Count > 1 Then - LV0.SubItems.Add("") - Else - LV0.SubItems.Add(Declaration.AuxTechs(tAux.HVAC)(0)) - End If - Me.LvAux.Items.Add(LV0) + LV0.SubItems.Add("") + LvAux.Items.Add(LV0) LV0 = New ListViewItem(sKey.AUX.ElecSys) LV0.SubItems.Add("Electric System") @@ -162,7 +157,7 @@ Public Class F_VECTO Else LV0.SubItems.Add(Declaration.AuxTechs(tAux.ElectricSys)(0)) End If - Me.LvAux.Items.Add(LV0) + LvAux.Items.Add(LV0) LV0 = New ListViewItem(sKey.AUX.PneumSys) LV0.SubItems.Add("Pneumatic System") @@ -171,23 +166,23 @@ Public Class F_VECTO Else LV0.SubItems.Add(Declaration.AuxTechs(tAux.PneumSys)(0)) End If - Me.LvAux.Items.Add(LV0) + LvAux.Items.Add(LV0) End If End Sub 'Show/Hide "Driver Assist" Tab - Private Sub SetDrivertab(ByVal OnOff As Boolean) - If OnOff Then + Private Sub SetDrivertab(onOff As Boolean) + If onOff Then If Not pgDriverON Then pgDriverON = True - Me.TabControl1.TabPages.Insert(1, pgDriver) + TabControl1.TabPages.Insert(1, pgDriver) End If Else If pgDriverON Then pgDriverON = False - Me.TabControl1.Controls.Remove(pgDriver) + TabControl1.Controls.Remove(pgDriver) End If End If End Sub @@ -195,28 +190,32 @@ Public Class F_VECTO #Region "Browse Buttons" - Private Sub ButtonVEH_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonVEH.Click - If fbVEH.OpenDialog(fFileRepl(Me.TbVEH.Text, fPATH(VECTOfile))) Then _ - Me.TbVEH.Text = fFileWoDir(fbVEH.Files(0), fPATH(VECTOfile)) + Private Sub ButtonVEH_Click(sender As Object, e As EventArgs) Handles ButtonVEH.Click + If fbVEH.OpenDialog(fFileRepl(TbVEH.Text, fPATH(VECTOfile))) Then + TbVEH.Text = fFileWoDir(fbVEH.Files(0), fPATH(VECTOfile)) + End If End Sub - Private Sub ButtonMAP_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonMAP.Click - If fbENG.OpenDialog(fFileRepl(Me.TbENG.Text, fPATH(VECTOfile))) Then _ - Me.TbENG.Text = fFileWoDir(fbENG.Files(0), fPATH(VECTOfile)) + Private Sub ButtonMAP_Click(sender As Object, e As EventArgs) Handles ButtonMAP.Click + If fbENG.OpenDialog(fFileRepl(TbENG.Text, fPATH(VECTOfile))) Then + TbENG.Text = fFileWoDir(fbENG.Files(0), fPATH(VECTOfile)) + End If End Sub - Private Sub ButtonGBX_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonGBX.Click - If fbGBX.OpenDialog(fFileRepl(Me.TbGBX.Text, fPATH(VECTOfile))) Then _ - Me.TbGBX.Text = fFileWoDir(fbGBX.Files(0), fPATH(VECTOfile)) + Private Sub ButtonGBX_Click(sender As Object, e As EventArgs) Handles ButtonGBX.Click + If fbGBX.OpenDialog(fFileRepl(TbGBX.Text, fPATH(VECTOfile))) Then + TbGBX.Text = fFileWoDir(fbGBX.Files(0), fPATH(VECTOfile)) + End If End Sub Private Sub BtDesMaxBr_Click_1(sender As Object, e As EventArgs) Handles BtDesMaxBr.Click - If fbACC.OpenDialog(fFileRepl(Me.TbDesMaxFile.Text, fPATH(VECTOfile))) Then _ - Me.TbDesMaxFile.Text = fFileWoDir(fbACC.Files(0), fPATH(VECTOfile)) + If fbACC.OpenDialog(fFileRepl(TbDesMaxFile.Text, fPATH(VECTOfile))) Then + TbDesMaxFile.Text = fFileWoDir(fbACC.Files(0), fPATH(VECTOfile)) + End If End Sub Private Sub BtAccOpen_Click(sender As Object, e As EventArgs) Handles BtAccOpen.Click - OpenFiles(fFileRepl(Me.TbDesMaxFile.Text, fPATH(VECTOfile))) + OpenFiles(fFileRepl(TbDesMaxFile.Text, fPATH(VECTOfile))) End Sub #End Region @@ -224,7 +223,7 @@ Public Class F_VECTO #Region "Open Buttons" 'Open Vehicle Editor - Private Sub ButOpenVEH_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButOpenVEH.Click + Private Sub ButOpenVEH_Click(sender As Object, e As EventArgs) Handles ButOpenVEH.Click Dim f As String f = fFileRepl(TbVEH.Text, fPATH(VECTOfile)) @@ -250,7 +249,7 @@ Public Class F_VECTO End Sub 'Open Engine Editor - Private Sub ButOpenENG_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButOpenENG.Click + Private Sub ButOpenENG_Click(sender As Object, e As EventArgs) Handles ButOpenENG.Click Dim f As String f = fFileRepl(TbENG.Text, fPATH(VECTOfile)) @@ -276,7 +275,7 @@ Public Class F_VECTO End Sub 'Open Gearbox Editor - Private Sub ButOpenGBX_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButOpenGBX.Click + Private Sub ButOpenGBX_Click(sender As Object, e As EventArgs) Handles ButOpenGBX.Click Dim f As String f = fFileRepl(TbGBX.Text, fPATH(VECTOfile)) @@ -365,23 +364,16 @@ Public Class F_VECTO End Function 'Open file - Public Sub VECTOload2Form(ByVal file As String) - Dim x As Int16 - Dim VEC0 As cVECTO - Dim AuxEntryKV As KeyValuePair(Of String, cVECTO.cAuxEntry) - Dim LV0 As ListViewItem - Dim sb As cSubPath - + Public Sub VECTOload2Form(file As String) If ChangeCheckCancel() Then Exit Sub VECTOnew() 'Read GEN - VEC0 = New cVECTO + Dim VEC0 = New cVECTO VEC0.FilePath = file Try If Not VEC0.ReadFile() Then - VEC0 = Nothing MsgBox("Failed to load " & fFILE(file, True) & "!") Exit Sub End If @@ -393,7 +385,7 @@ Public Class F_VECTO If Cfg.DeclMode <> VEC0.SavedInDeclMode Then Select Case WrongMode() Case 1 - Me.Close() + Close() F_MAINForm.RbDecl.Checked = Not F_MAINForm.RbDecl.Checked F_MAINForm.OpenVectoFile(file) Case -1 @@ -412,70 +404,62 @@ Public Class F_VECTO TbGBX.Text = VEC0.PathGBX(True) 'Start/Stop - Me.ChBStartStop.Checked = VEC0.StartStop - Me.TbSSspeed.Text = VEC0.StStV - Me.TbSStime.Text = VEC0.StStT - Me.TbSSdelay.Text = VEC0.StStDelay + ChBStartStop.Checked = VEC0.StartStop + TbSSspeed.Text = VEC0.StStV.ToString() + TbSStime.Text = VEC0.StStT.ToString() + TbSSdelay.Text = VEC0.StStDelay.ToString() 'VACC - Me.TbDesMaxFile.Text = VEC0.DesMaxFile(True) + TbDesMaxFile.Text = VEC0.DesMaxFile(True) 'AA-TB 'Try and Select any previously selected Auxiliary Type For Each item As cAdvancedAuxiliary In cboAdvancedAuxiliaries.Items - - Dim aai As cAdvancedAuxiliary = DirectCast(item, cAdvancedAuxiliary) - - If aai.AssemblyName = VEC0.AuxiliaryAssembly AndAlso VEC0.AuxiliaryVersion = aai.AuxiliaryVersion Then - + If item.AssemblyName = VEC0.AuxiliaryAssembly AndAlso VEC0.AuxiliaryVersion = item.AuxiliaryVersion Then cboAdvancedAuxiliaries.SelectedItem = item Exit For - End If - Next 'AA-TB 'Assign any previously saved Axiliary FilePath txtAdvancedAuxiliaryFile.Text = VEC0.AdvancedAuxiliaryFilePath - Me.LvAux.Items.Clear() + LvAux.Items.Clear() For Each AuxEntryKV In VEC0.AuxPaths - LV0 = New ListViewItem - LV0.SubItems(0).Text = AuxEntryKV.Key - LV0.SubItems.Add(AuxEntryKV.Value.Type) + Dim lv0 = New ListViewItem + lv0.SubItems(0).Text = AuxEntryKV.Key + lv0.SubItems.Add(AuxEntryKV.Value.Type) If Cfg.DeclMode Then - LV0.SubItems.Add(AuxEntryKV.Value.TechStr) + lv0.SubItems.Add(AuxEntryKV.Value.TechStr) Else - LV0.SubItems.Add(AuxEntryKV.Value.Path.OriginalPath) + lv0.SubItems.Add(AuxEntryKV.Value.Path.OriginalPath) End If - LvAux.Items.Add(LV0) + LvAux.Items.Add(lv0) Next - EStechs = VEC0.EStechs - For Each sb In VEC0.CycleFiles - LV0 = New ListViewItem - LV0.Text = sb.OriginalPath - LvCycles.Items.Add(LV0) + Dim lv0 = New ListViewItem + lv0.Text = sb.OriginalPath + LvCycles.Items.Add(lv0) Next - Me.CbEngOnly.Checked = VEC0.EngOnly + CbEngOnly.Checked = VEC0.EngOnly If VEC0.EcoRollOn Then - Me.RdEcoRoll.Checked = True + RdEcoRoll.Checked = True ElseIf VEC0.OverSpeedOn Then - Me.RdOverspeed.Checked = True + RdOverspeed.Checked = True Else - Me.RdOff.Checked = True + RdOff.Checked = True End If - Me.TbOverspeed.Text = CStr(VEC0.OverSpeed) - Me.TbUnderSpeed.Text = CStr(VEC0.UnderSpeed) - Me.TbVmin.Text = CStr(VEC0.vMin) - Me.CbLookAhead.Checked = VEC0.LookAheadOn - Me.TbAlookahead.Text = CStr(VEC0.a_lookahead) - Me.TbVminLA.Text = CStr(VEC0.vMinLA) + TbOverspeed.Text = CStr(VEC0.OverSpeed) + TbUnderSpeed.Text = CStr(VEC0.UnderSpeed) + TbVmin.Text = CStr(VEC0.vMin) + CbLookAhead.Checked = VEC0.LookAheadOn + TbAlookahead.Text = CStr(VEC0.a_lookahead) + TbVminLA.Text = CStr(VEC0.vMinLA) tbLacPreviewFactor.Text = CStr(VEC0.LacPreviewFactor) tbDfCoastingOffset.Text = CStr(VEC0.LacDfOffset) tbDfCoastingScale.Text = CStr(VEC0.LacDfScale) @@ -495,13 +479,13 @@ Public Class F_VECTO VECTOfile = file - x = Len(file) + Dim x As Short = Len(file) While Mid(file, x, 1) <> "\" And x > 0 x = x - 1 End While - Me.Text = Mid(file, x + 1, Len(file) - x) + Text = Mid(file, x + 1, Len(file) - x) Changed = False - Me.ToolStripStatusLabelGEN.Text = "" 'file & " opened." + ToolStripStatusLabelGEN.Text = "" 'file & " opened." UpdatePic() @@ -509,28 +493,19 @@ Public Class F_VECTO End Sub 'Save file - Private Function VECTOsave(ByVal file As String) As Boolean - - Dim VEC0 As cVECTO - Dim AuxEntry As cVECTO.cAuxEntry - Dim LV0 As ListViewItem - Dim sb As cSubPath - Dim absoluteAAUxFile As String = String.Empty - Dim aaAssemblyName As String = String.Empty - Dim aaAssemblyVersion As String = String.Empty + Private Function VECTOsave(file As String) As Boolean Dim message As String = String.Empty - 'AA-TB 'Validation of Auxiliary Types/Advanced Auxiliaries 'if not classic, check the file is valid, if not fail the operation and alert user. If cboAdvancedAuxiliaries.SelectedIndex > 0 Then 'resolve absolute path for auxiliary file. - absoluteAAUxFile = ResolveAAUXFilePath(fPATH(VECTOfile), txtAdvancedAuxiliaryFile.Text) + Dim absoluteAAUxFile = ResolveAAUXFilePath(fPATH(VECTOfile), txtAdvancedAuxiliaryFile.Text) - aaAssemblyName = DirectCast(cboAdvancedAuxiliaries.SelectedItem, cAdvancedAuxiliary).AssemblyName - aaAssemblyVersion = DirectCast(cboAdvancedAuxiliaries.SelectedItem, cAdvancedAuxiliary).AuxiliaryVersion + Dim aaAssemblyName = DirectCast(cboAdvancedAuxiliaries.SelectedItem, cAdvancedAuxiliary).AssemblyName + Dim aaAssemblyVersion = DirectCast(cboAdvancedAuxiliaries.SelectedItem, cAdvancedAuxiliary).AuxiliaryVersion If Not ValidateAAUXFile(absoluteAAUxFile, aaAssemblyName, aaAssemblyVersion, message) Then @@ -543,74 +518,70 @@ Public Class F_VECTO End If - VEC0 = New cVECTO - VEC0.FilePath = file + Dim vec0 = New cVECTO + vec0.FilePath = file 'Files ------------------------------------------------- ----------------- - VEC0.PathVEH = Me.TbVEH.Text - VEC0.PathENG = Me.TbENG.Text + vec0.PathVEH = TbVEH.Text + vec0.PathENG = TbENG.Text - For Each LV0 In LvCycles.Items - sb = New cSubPath - sb.Init(fPATH(file), LV0.Text) - VEC0.CycleFiles.Add(sb) + For Each lv0 As ListViewItem In LvCycles.Items + Dim sb = New cSubPath + sb.Init(fPATH(file), lv0.Text) + vec0.CycleFiles.Add(sb) Next - VEC0.PathGBX = Me.TbGBX.Text + vec0.PathGBX = TbGBX.Text 'Start/Stop - VEC0.StartStop = Me.ChBStartStop.Checked - VEC0.StStV = CSng(fTextboxToNumString(Me.TbSSspeed.Text)) - VEC0.StStT = CSng(fTextboxToNumString(Me.TbSStime.Text)) - VEC0.StStDelay = CInt(fTextboxToNumString(Me.TbSSdelay.Text)) + vec0.StartStop = ChBStartStop.Checked + vec0.StStV = CSng(fTextboxToNumString(TbSSspeed.Text)) + vec0.StStT = CSng(fTextboxToNumString(TbSStime.Text)) + vec0.StStDelay = CInt(fTextboxToNumString(TbSSdelay.Text)) 'a_DesMax - VEC0.DesMaxFile = Me.TbDesMaxFile.Text + vec0.DesMaxFile = TbDesMaxFile.Text 'AA-TB - VEC0.AuxiliaryAssembly = DirectCast(cboAdvancedAuxiliaries.SelectedItem, cAdvancedAuxiliary).AssemblyName - VEC0.AuxiliaryVersion = DirectCast(cboAdvancedAuxiliaries.SelectedItem, cAdvancedAuxiliary).AuxiliaryVersion - VEC0.AdvancedAuxiliaryFilePath = txtAdvancedAuxiliaryFile.Text - + vec0.AuxiliaryAssembly = DirectCast(cboAdvancedAuxiliaries.SelectedItem, cAdvancedAuxiliary).AssemblyName + vec0.AuxiliaryVersion = DirectCast(cboAdvancedAuxiliaries.SelectedItem, cAdvancedAuxiliary).AuxiliaryVersion + vec0.AdvancedAuxiliaryFilePath = txtAdvancedAuxiliaryFile.Text - For Each LV0 In LvAux.Items - AuxEntry = New cVECTO.cAuxEntry + For Each lv0 As ListViewItem In LvAux.Items + Dim auxEntry = New cVECTO.cAuxEntry If Cfg.DeclMode Then - AuxEntry.TechStr = LV0.SubItems(2).Text + auxEntry.TechStr = lv0.SubItems(2).Text Else - AuxEntry.Path.Init(fPATH(file), LV0.SubItems(2).Text) + auxEntry.Path.Init(fPATH(file), lv0.SubItems(2).Text) End If - AuxEntry.Type = LV0.SubItems(1).Text - VEC0.AuxPaths.Add(LV0.SubItems(0).Text, AuxEntry) + auxEntry.Type = lv0.SubItems(1).Text + vec0.AuxPaths.Add(lv0.SubItems(0).Text, auxEntry) Next - VEC0.EStechs = EStechs - - - VEC0.EngOnly = Me.CbEngOnly.Checked - - VEC0.EcoRollOn = RdEcoRoll.Checked - VEC0.OverSpeedOn = RdOverspeed.Checked - VEC0.OverSpeed = CSng(fTextboxToNumString(Me.TbOverspeed.Text)) - VEC0.UnderSpeed = CSng(fTextboxToNumString(Me.TbUnderSpeed.Text)) - VEC0.vMin = CSng(fTextboxToNumString(Me.TbVmin.Text)) - VEC0.LookAheadOn = Me.CbLookAhead.Checked - VEC0.a_lookahead = CSng(fTextboxToNumString(Me.TbAlookahead.Text)) - VEC0.vMinLA = CSng(fTextboxToNumString(Me.TbVminLA.Text)) - - VEC0.LacPreviewFactor = CSng(fTextboxToNumString(tbLacPreviewFactor.Text)) - VEC0.LacDfOffset = CSng(fTextboxToNumString(tbDfCoastingOffset.Text)) - VEC0.LacDfScale = CSng(fTextboxToNumString(tbDfCoastingScale.Text)) - VEC0.LacDfTargetSpeedFile = tbLacDfTargetSpeedFile.Text - VEC0.LacDfVelocityDropFile = tbLacDfVelocityDropFile.Text + vec0.EngOnly = CbEngOnly.Checked + + vec0.EcoRollOn = RdEcoRoll.Checked + vec0.OverSpeedOn = RdOverspeed.Checked + vec0.OverSpeed = CSng(fTextboxToNumString(TbOverspeed.Text)) + vec0.UnderSpeed = CSng(fTextboxToNumString(TbUnderSpeed.Text)) + vec0.vMin = CSng(fTextboxToNumString(TbVmin.Text)) + vec0.LookAheadOn = CbLookAhead.Checked + vec0.a_lookahead = CSng(fTextboxToNumString(TbAlookahead.Text)) + vec0.vMinLA = CSng(fTextboxToNumString(TbVminLA.Text)) + + vec0.LacPreviewFactor = CSng(fTextboxToNumString(tbLacPreviewFactor.Text)) + vec0.LacDfOffset = CSng(fTextboxToNumString(tbDfCoastingOffset.Text)) + vec0.LacDfScale = CSng(fTextboxToNumString(tbDfCoastingScale.Text)) + vec0.LacDfTargetSpeedFile = tbLacDfTargetSpeedFile.Text + vec0.LacDfVelocityDropFile = tbLacDfVelocityDropFile.Text '------------------------------------------------------------ 'SAVE - If Not VEC0.SaveFile Then + If Not vec0.SaveFile Then MsgBox("Cannot safe to " & file, MsgBoxStyle.Critical) Return False End If @@ -619,9 +590,8 @@ Public Class F_VECTO file = fFILE(VECTOfile, True) - Me.Text = file - - Me.ToolStripStatusLabelGEN.Text = "" + Text = file + ToolStripStatusLabelGEN.Text = "" F_MAINForm.AddToJobListView(VECTOfile) @@ -639,28 +609,28 @@ Public Class F_VECTO FLDfile = "" 'Files - Me.TbVEH.Text = "" - Me.TbENG.Text = "" - Me.LvCycles.Items.Clear() - Me.TbGBX.Text = "" - Me.TbDesMaxFile.Text = "" + TbVEH.Text = "" + TbENG.Text = "" + LvCycles.Items.Clear() + TbGBX.Text = "" + TbDesMaxFile.Text = "" 'Start/Stop - Me.TbSSspeed.Text = "5" - Me.TbSStime.Text = "5" - Me.ChBStartStop.Checked = False + TbSSspeed.Text = "5" + TbSStime.Text = "5" + ChBStartStop.Checked = False - Me.LvAux.Items.Clear() + LvAux.Items.Clear() - Me.CbEngOnly.Checked = False + CbEngOnly.Checked = False - Me.RdOff.Checked = True - Me.CbLookAhead.Checked = True - Me.TbAlookahead.Text = "-0.5" - Me.TbOverspeed.Text = "" - Me.TbUnderSpeed.Text = "" - Me.TbVmin.Text = "" - Me.TbVminLA.Text = "50" + RdOff.Checked = True + CbLookAhead.Checked = True + TbAlookahead.Text = "-0.5" + TbOverspeed.Text = "" + TbUnderSpeed.Text = "" + TbVmin.Text = "" + TbVminLA.Text = "50" tbLacPreviewFactor.Text = "10" tbDfCoastingOffset.Text = "2.5" tbDfCoastingScale.Text = "1.5" @@ -674,8 +644,8 @@ Public Class F_VECTO F_ENG.AutoSendTo = False VECTOfile = "" - Me.Text = "Job Editor" - Me.ToolStripStatusLabelGEN.Text = "" + Text = "Job Editor" + ToolStripStatusLabelGEN.Text = "" Changed = False UpdatePic() End Sub @@ -685,19 +655,19 @@ Public Class F_VECTO #Region "'Change' Events" - Private Sub TextBoxVEH_TextChanged(ByVal sender As Object, ByVal e As EventArgs) _ + Private Sub TextBoxVEH_TextChanged(sender As Object, e As EventArgs) _ Handles TbVEH.TextChanged UpdatePic() Change() End Sub - Private Sub TextBoxMAP_TextChanged(ByVal sender As Object, ByVal e As EventArgs) _ + Private Sub TextBoxMAP_TextChanged(sender As Object, e As EventArgs) _ Handles TbENG.TextChanged UpdatePic() Change() End Sub - Private Sub TextBoxFLD_TextChanged(ByVal sender As Object, ByVal e As EventArgs) _ + Private Sub TextBoxFLD_TextChanged(sender As Object, e As EventArgs) _ Handles TbGBX.TextChanged UpdatePic() Change() @@ -744,7 +714,7 @@ Public Class F_VECTO Private Sub Change() If Not Changed Then - Me.ToolStripStatusLabelGEN.Text = "Unsaved changes in current file" + ToolStripStatusLabelGEN.Text = "Unsaved changes in current file" Changed = True End If End Sub @@ -776,22 +746,22 @@ Public Class F_VECTO #Region "Aux Listview" Private Sub ButAuxAdd_Click(sender As Object, e As EventArgs) Handles ButAuxAdd.Click - Dim LV0 As ListViewItem Dim ID As String AuxDlog.VehPath = fPATH(VECTOfile) AuxDlog.TbPath.Text = "" AuxDlog.CbType.SelectedIndex = -1 AuxDlog.CbType.Text = "" - AuxDlog.TbID.Text = "" '!!! Vorher Type setzen weil ID beim ändern von Type überschrieben wird !!!" + AuxDlog.TbID.Text = "" '!!! Set Type before ID, because changing the type will overwrite the id !!! lbDlog: If AuxDlog.ShowDialog = DialogResult.OK Then ID = UCase(Trim(AuxDlog.TbID.Text)) - For Each LV0 In LvAux.Items - If LV0.SubItems(0).Text = ID Then + Dim lv0 As ListViewItem + For Each lv0 In LvAux.Items + If lv0.SubItems(0).Text = ID Then MsgBox("ID '" & ID & "' already defined!", MsgBoxStyle.Critical) AuxDlog.TbID.SelectAll() AuxDlog.TbID.Focus() @@ -799,22 +769,12 @@ lbDlog: End If Next - LV0 = New ListViewItem - LV0.SubItems(0).Text = UCase(Trim(AuxDlog.TbID.Text)) - LV0.SubItems.Add(Trim(AuxDlog.CbType.Text)) - LV0.SubItems.Add(Trim(AuxDlog.TbPath.Text)) - - LvAux.Items.Add(LV0) - - If ID = sKey.AUX.ElecSys Then - EStechs.Clear() - For Each LV0 In AuxDlog.LVTech.CheckedItems - EStechs.Add(LV0.Text) - Next - End If - + lv0 = New ListViewItem + lv0.SubItems(0).Text = UCase(Trim(AuxDlog.TbID.Text)) + lv0.SubItems.Add(Trim(AuxDlog.CbType.Text)) + lv0.SubItems.Add(Trim(AuxDlog.TbPath.Text)) + LvAux.Items.Add(lv0) Change() - End If End Sub @@ -836,56 +796,36 @@ lbDlog: End Sub Private Sub EditAuxItem() - Dim SelItem As ListViewItem - Dim LV0 As ListViewItem - - If LvAux.SelectedItems.Count = 0 Then Exit Sub + If LvAux.SelectedItems.Count = 0 Then + Exit Sub + End If - SelItem = LvAux.SelectedItems(0) + Dim selItem = LvAux.SelectedItems(0) AuxDlog.VehPath = fPATH(VECTOfile) AuxDlog.CbType.SelectedIndex = -1 - AuxDlog.CbType.Text = SelItem.SubItems(1).Text - AuxDlog.TbID.Text = SelItem.SubItems(0).Text 'After Type-set! + AuxDlog.CbType.Text = selItem.SubItems(1).Text + AuxDlog.TbID.Text = selItem.SubItems(0).Text 'After Type-set! If Cfg.DeclMode Then - AuxDlog.CbTech.Text = SelItem.SubItems(2).Text + AuxDlog.CbTech.Text = selItem.SubItems(2).Text AuxDlog.TbPath.Text = "" - - If AuxDlog.TbID.Text = sKey.AUX.ElecSys Then - For Each LV0 In AuxDlog.LVTech.Items - If EStechs.Contains(LV0.Text) Then - LV0.Checked = True - Else - LV0.Checked = False - End If - Next - End If - Else AuxDlog.CbTech.SelectedIndex = -1 - AuxDlog.TbPath.Text = SelItem.SubItems(2).Text + AuxDlog.TbPath.Text = selItem.SubItems(2).Text End If If AuxDlog.ShowDialog = DialogResult.OK Then - SelItem.SubItems(0).Text = UCase(Trim(AuxDlog.TbID.Text)) - SelItem.SubItems(1).Text = Trim(AuxDlog.CbType.Text) + selItem.SubItems(0).Text = UCase(Trim(AuxDlog.TbID.Text)) + selItem.SubItems(1).Text = Trim(AuxDlog.CbType.Text) If Cfg.DeclMode Then - SelItem.SubItems(2).Text = Trim(AuxDlog.CbTech.Text) + selItem.SubItems(2).Text = Trim(AuxDlog.CbTech.Text) Else - SelItem.SubItems(2).Text = Trim(AuxDlog.TbPath.Text) - End If - - If UCase(Trim(AuxDlog.TbID.Text)) = sKey.AUX.ElecSys Then - EStechs.Clear() - For Each LV0 In AuxDlog.LVTech.CheckedItems - EStechs.Add(LV0.Text) - Next + selItem.SubItems(2).Text = Trim(AuxDlog.TbPath.Text) End If Change() - End If End Sub @@ -919,21 +859,21 @@ lbDlog: #End Region 'OK (Save & Close) - Private Sub ButSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButOK.Click + Private Sub ButSave_Click(sender As Object, e As EventArgs) Handles ButOK.Click If Not Save() Then Exit Sub - Me.Close() + Close() End Sub 'Cancel - Private Sub ButCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButCancel.Click - Me.Close() + Private Sub ButCancel_Click(sender As Object, e As EventArgs) Handles ButCancel.Click + Close() End Sub #Region "Cycle list" Private Sub LvCycles_DoubleClick(sender As Object, e As EventArgs) Handles LvCycles.DoubleClick - If Me.LvCycles.SelectedItems.Count > 0 Then _ - OpenFiles(fFileRepl(Me.LvCycles.SelectedItems(0).SubItems(0).Text, fPATH(VECTOfile))) + If LvCycles.SelectedItems.Count > 0 Then _ + OpenFiles(fFileRepl(LvCycles.SelectedItems(0).SubItems(0).Text, fPATH(VECTOfile))) End Sub Private Sub LvCycles_KeyDown(sender As Object, e As KeyEventArgs) Handles LvCycles.KeyDown @@ -941,7 +881,7 @@ lbDlog: Case Keys.Delete, Keys.Back RemoveCycle() Case Keys.Enter - If Me.LvCycles.SelectedItems.Count > 0 Then Me.LvCycles.SelectedItems(0).BeginEdit() + If LvCycles.SelectedItems.Count > 0 Then LvCycles.SelectedItems(0).BeginEdit() End Select End Sub @@ -955,7 +895,7 @@ lbDlog: If fbDRI.OpenDialog("", True) Then For Each str In fbDRI.Files - Me.LvCycles.Items.Add(fFileWoDir(str, GenDir)) + LvCycles.Items.Add(fFileWoDir(str, GenDir)) Next Change() @@ -1025,14 +965,14 @@ lbDlog: Private Sub ChBStartStop_CheckedChanged_1(sender As Object, e As EventArgs) _ Handles ChBStartStop.CheckedChanged Change() - If Not Cfg.DeclMode Then Me.PnStartStop.Enabled = Me.ChBStartStop.Checked + If Not Cfg.DeclMode Then PnStartStop.Enabled = ChBStartStop.Checked End Sub 'LAC changed Private Sub CbLookAhead_CheckedChanged(sender As Object, e As EventArgs) _ Handles CbLookAhead.CheckedChanged Change() - Me.PnLookAhead.Enabled = CbLookAhead.Checked + PnLookAhead.Enabled = CbLookAhead.Checked End Sub 'EcoRoll / Overspeed changed @@ -1043,72 +983,65 @@ lbDlog: Change() - EcoR = Me.RdEcoRoll.Checked - Ovr = Me.RdOverspeed.Checked + EcoR = RdEcoRoll.Checked + Ovr = RdOverspeed.Checked - Me.TbOverspeed.Enabled = Ovr Or EcoR - Me.Label13.Enabled = Ovr Or EcoR - Me.Label14.Enabled = Ovr Or EcoR + TbOverspeed.Enabled = Ovr Or EcoR + Label13.Enabled = Ovr Or EcoR + Label14.Enabled = Ovr Or EcoR - Me.TbUnderSpeed.Enabled = EcoR - Me.Label22.Enabled = EcoR - Me.Label20.Enabled = EcoR + TbUnderSpeed.Enabled = EcoR + Label22.Enabled = EcoR + Label20.Enabled = EcoR - Me.TbVmin.Enabled = Ovr Or EcoR - Me.Label23.Enabled = Ovr Or EcoR - Me.Label21.Enabled = Ovr Or EcoR + TbVmin.Enabled = Ovr Or EcoR + Label23.Enabled = Ovr Or EcoR + Label21.Enabled = Ovr Or EcoR End Sub #End Region Public Sub UpdatePic() Dim VEH0 As New cVEH - Dim ENG0 As cENG - Dim GBX0 As cGBX - Dim FLD0 As cFLD - Dim Shiftpoly As cGBX.cShiftPolygon - Dim MAP0 As cMAP - Dim OkCount As Integer Dim i As Integer Dim pmax As Single - Dim f As cFile_V3 = Nothing + Dim f As cFile_V3 Dim lM As List(Of Single) Dim lup As List(Of Single) Dim ldown As List(Of Single) - Dim line As String() = Nothing + Dim line As String() - Dim s0 As cSegmentTableEntry = Nothing + Dim s0 As cSegmentTableEntry Dim HDVclass As String Dim m0 As tMission - Dim MyChart As Chart Dim s As Series Dim a As ChartArea Dim img As Image - Dim EngOK As Boolean = False + Dim EngOK = False - Me.TbHVCclass.Text = "" - Me.TbVehCat.Text = "" - Me.TbMass.Text = "" - Me.TbAxleConf.Text = "" - Me.TbEngTxt.Text = "" - Me.TbGbxTxt.Text = "" - Me.PicVehicle.Image = Nothing - Me.PicBox.Image = Nothing + TbHVCclass.Text = "" + TbVehCat.Text = "" + TbMass.Text = "" + TbAxleConf.Text = "" + TbEngTxt.Text = "" + TbGbxTxt.Text = "" + PicVehicle.Image = Nothing + PicBox.Image = Nothing - VEH0.FilePath = fFileRepl(Me.TbVEH.Text, fPATH(VECTOfile)) + VEH0.FilePath = fFileRepl(TbVEH.Text, fPATH(VECTOfile)) If VEH0.ReadFile(False) Then s0 = Declaration.SegmentTable.SetRef(VEH0.VehCat, VEH0.AxleConf, VEH0.MassMax) If Not s0 Is Nothing Then HDVclass = s0.HDVclass If Cfg.DeclMode Then - Me.LvCycles.Items.Clear() + LvCycles.Items.Clear() For Each m0 In s0.Missions - Me.LvCycles.Items.Add(Declaration.Missions(m0).NameStr) + LvCycles.Items.Add(Declaration.Missions(m0).NameStr) Next End If @@ -1116,29 +1049,29 @@ lbDlog: HDVclass = "-" End If - Me.PicVehicle.Image = Image.FromFile(Declaration.ConvPicPath(HDVclass, False)) + PicVehicle.Image = Image.FromFile(Declaration.ConvPicPath(HDVclass, False)) - Me.TbHVCclass.Text = "HDV Class " & HDVclass - Me.TbVehCat.Text = ConvVehCat(VEH0.VehCat, True) - Me.TbMass.Text = VEH0.MassMax & " t" - Me.TbAxleConf.Text = ConvAxleConf(VEH0.AxleConf) + TbHVCclass.Text = "HDV Class " & HDVclass + TbVehCat.Text = ConvVehCat(VEH0.VehCat, True) + TbMass.Text = VEH0.MassMax & " t" + TbAxleConf.Text = ConvAxleConf(VEH0.AxleConf) End If - OkCount = 0 + Dim OkCount = 0 - ENG0 = New cENG - ENG0.FilePath = fFileRepl(Me.TbENG.Text, fPATH(VECTOfile)) + Dim ENG0 = New cENG + ENG0.FilePath = fFileRepl(TbENG.Text, fPATH(VECTOfile)) 'Create plot - MyChart = New Chart - MyChart.Width = Me.PicBox.Width - MyChart.Height = Me.PicBox.Height + Dim MyChart = New Chart + MyChart.Width = PicBox.Width + MyChart.Height = PicBox.Height a = New ChartArea - FLD0 = New cFLD + Dim FLD0 = New cFLD If ENG0.ReadFile(False) Then @@ -1172,10 +1105,10 @@ lbDlog: End If - Me.TbEngTxt.Text = (ENG0.Displ / 1000).ToString("0.0") & " l " & pmax.ToString("#") & " kW " & ENG0.ModelName + TbEngTxt.Text = (ENG0.Displ / 1000).ToString("0.0") & " l " & pmax.ToString("#") & " kW " & ENG0.ModelName - MAP0 = New cMAP + Dim MAP0 = New cMAP MAP0.FilePath = ENG0.PathMAP If MAP0.ReadFile(False) Then @@ -1194,12 +1127,12 @@ lbDlog: End If - GBX0 = New cGBX - GBX0.FilePath = fFileRepl(Me.TbGBX.Text, fPATH(VECTOfile)) + Dim GBX0 = New cGBX + GBX0.FilePath = fFileRepl(TbGBX.Text, fPATH(VECTOfile)) If GBX0.ReadFile(False) Then - Me.TbGbxTxt.Text = GBX0.GearCount & "-Speed " & GearboxConv(GBX0.gs_Type) & " " & GBX0.ModelName + TbGbxTxt.Text = GBX0.GearCount & "-Speed " & GearboxConv(GBX0.gs_Type) & " " & GBX0.ModelName If Cfg.DeclMode Then @@ -1213,7 +1146,7 @@ lbDlog: If FLD0.ReadFile(True, False) Then If FLD0.Init(ENG0.Nidle) Then - Shiftpoly = New cGBX.cShiftPolygon("", 0) + Dim Shiftpoly = New cGBX.cShiftPolygon("", 0) Shiftpoly.SetGenericShiftPoly(FLD0, ENG0.Nidle) s = New Series @@ -1325,9 +1258,9 @@ lbDlog: MyChart.Update() img = New Bitmap(MyChart.Width, MyChart.Height, PixelFormat.Format32bppArgb) - MyChart.DrawToBitmap(img, New Rectangle(0, 0, Me.PicBox.Width, Me.PicBox.Height)) + MyChart.DrawToBitmap(img, New Rectangle(0, 0, PicBox.Width, PicBox.Height)) - Me.PicBox.Image = img + PicBox.Image = img End If @@ -1339,14 +1272,11 @@ lbDlog: Private CmFiles As String() Private Sub OpenFiles(ParamArray files() As String) - If files.Length = 0 Then Exit Sub CmFiles = files - OpenWithToolStripMenuItem.Text = "Open with " & Cfg.OpenCmdName - - CmOpenFile.Show(System.Windows.Forms.Cursor.Position) + CmOpenFile.Show(Windows.Forms.Cursor.Position) End Sub Private Sub OpenWithToolStripMenuItem_Click(sender As Object, e As EventArgs) _ @@ -1481,16 +1411,18 @@ lbDlog: 'AA-TB Private Sub btnAAUXOpen_Click(sender As Object, e As EventArgs) Handles btnAAUXOpen.Click - OpenFiles(fFileRepl(Me.txtAdvancedAuxiliaryFile.Text, fPATH(VECTOfile))) + OpenFiles(fFileRepl(txtAdvancedAuxiliaryFile.Text, fPATH(VECTOfile))) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnDfTargetSpeed.Click - If fbDfTargetSpeed.OpenDialog(fFileRepl(Me.tbLacDfTargetSpeedFile.Text, fPATH(VECTOfile))) Then _ - Me.tbLacDfTargetSpeedFile.Text = fFileWoDir(fbDfTargetSpeed.Files(0), fPATH(VECTOfile)) + If fbDfTargetSpeed.OpenDialog(fFileRepl(tbLacDfTargetSpeedFile.Text, fPATH(VECTOfile))) Then _ + tbLacDfTargetSpeedFile.Text = fFileWoDir(fbDfTargetSpeed.Files(0), fPATH(VECTOfile)) End Sub Private Sub btnDfVelocityDrop_Click(sender As Object, e As EventArgs) Handles btnDfVelocityDrop.Click - If fbDfVelocityDrop.OpenDialog(fFileRepl(Me.tbLacDfVelocityDropFile.Text, fPATH(VECTOfile))) Then _ - Me.tbLacDfVelocityDropFile.Text = fFileWoDir(fbDfVelocityDrop.Files(0), fPATH(VECTOfile)) + If fbDfVelocityDrop.OpenDialog(fFileRepl(tbLacDfVelocityDropFile.Text, fPATH(VECTOfile))) Then _ + tbLacDfVelocityDropFile.Text = fFileWoDir(fbDfVelocityDrop.Files(0), fPATH(VECTOfile)) End Sub End Class + + diff --git a/VECTO/GUI/F_VEH.Designer.vb b/VECTO/GUI/F_VEH.Designer.vb index 0e0f400b5d1b6525b74dd8d54aa99be0ed2f8fff..3e49f7dd61eef163b029f8da848a6fd0bb1ea409 100644 --- a/VECTO/GUI/F_VEH.Designer.vb +++ b/VECTO/GUI/F_VEH.Designer.vb @@ -121,6 +121,7 @@ Partial Class F_VEH Me.cbAngularGearType = New System.Windows.Forms.ComboBox() Me.PicVehicle = New System.Windows.Forms.PictureBox() Me.Label8 = New System.Windows.Forms.Label() + Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components) Me.GroupBox6.SuspendLayout() Me.ToolStrip1.SuspendLayout() Me.GroupBox7.SuspendLayout() @@ -547,6 +548,7 @@ Partial Class F_VEH Me.CbRim.Name = "CbRim" Me.CbRim.Size = New System.Drawing.Size(184, 21) Me.CbRim.TabIndex = 4 + Me.ToolTip1.SetToolTip(Me.CbRim, "(Vecto 2 only)" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "The Rims parameter will be removed in Vecto 3") ' 'Label7 ' @@ -1086,4 +1088,5 @@ Partial Class F_VEH Friend WithEvents tbAngularGearRatio As System.Windows.Forms.TextBox Friend WithEvents btAngularGearLossMapBrowse As System.Windows.Forms.Button Friend WithEvents tbAngularGearLossMapPath As System.Windows.Forms.TextBox + Friend WithEvents ToolTip1 As System.Windows.Forms.ToolTip End Class diff --git a/VECTO/GUI/F_VEH.resx b/VECTO/GUI/F_VEH.resx index 994b92ac355e7506d9b05229d838bf53ec7ff58e..4e4715053fc90adfc4aa7ada58644f2a674daa35 100644 --- a/VECTO/GUI/F_VEH.resx +++ b/VECTO/GUI/F_VEH.resx @@ -120,6 +120,9 @@ <metadata name="ToolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>32, 17</value> </metadata> + <metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>376, 21</value> + </metadata> <metadata name="StatusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>142, 21</value> </metadata> diff --git a/VECTO/GUI/F_VEH_AuxDlog.Designer.vb b/VECTO/GUI/F_VEH_AuxDlog.Designer.vb index 50d8813fa9ea20fc9d86e21e28efea662595b082..240ac0a9a0c68f1671f71c167bec1afc97aac9f6 100644 --- a/VECTO/GUI/F_VEH_AuxDlog.Designer.vb +++ b/VECTO/GUI/F_VEH_AuxDlog.Designer.vb @@ -47,8 +47,6 @@ Partial Class F_VEH_AuxDlog Me.CbTech = New System.Windows.Forms.ComboBox() Me.PnTech = New System.Windows.Forms.Panel() Me.PnFile = New System.Windows.Forms.Panel() - Me.LVTech = New System.Windows.Forms.ListView() - Me.ColumnHeader1 = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) Me.TableLayoutPanel1.SuspendLayout() Me.PnTech.SuspendLayout() Me.PnFile.SuspendLayout() @@ -62,7 +60,7 @@ Partial Class F_VEH_AuxDlog Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!)) Me.TableLayoutPanel1.Controls.Add(Me.OK_Button, 0, 0) Me.TableLayoutPanel1.Controls.Add(Me.Cancel_Button, 1, 0) - Me.TableLayoutPanel1.Location = New System.Drawing.Point(301, 388) + Me.TableLayoutPanel1.Location = New System.Drawing.Point(301, 100) Me.TableLayoutPanel1.Name = "TableLayoutPanel1" Me.TableLayoutPanel1.RowCount = 1 Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!)) @@ -72,6 +70,7 @@ Partial Class F_VEH_AuxDlog 'OK_Button ' Me.OK_Button.Anchor = System.Windows.Forms.AnchorStyles.None + Me.OK_Button.DialogResult = System.Windows.Forms.DialogResult.OK Me.OK_Button.Location = New System.Drawing.Point(3, 3) Me.OK_Button.Name = "OK_Button" Me.OK_Button.Size = New System.Drawing.Size(67, 23) @@ -192,37 +191,18 @@ Partial Class F_VEH_AuxDlog Me.PnFile.Controls.Add(Me.Label2) Me.PnFile.Controls.Add(Me.Label3) Me.PnFile.Controls.Add(Me.Label1) - Me.PnFile.Location = New System.Drawing.Point(12, 293) + Me.PnFile.Location = New System.Drawing.Point(12, 8) Me.PnFile.Name = "PnFile" Me.PnFile.Size = New System.Drawing.Size(435, 89) Me.PnFile.TabIndex = 29 ' - 'LVTech - ' - Me.LVTech.CheckBoxes = True - Me.LVTech.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1}) - Me.LVTech.FullRowSelect = True - Me.LVTech.GridLines = True - Me.LVTech.Location = New System.Drawing.Point(12, 52) - Me.LVTech.Name = "LVTech" - Me.LVTech.Size = New System.Drawing.Size(435, 235) - Me.LVTech.TabIndex = 30 - Me.LVTech.UseCompatibleStateImageBehavior = False - Me.LVTech.View = System.Windows.Forms.View.Details - ' - 'ColumnHeader1 - ' - Me.ColumnHeader1.Text = "Technologies" - Me.ColumnHeader1.Width = 420 - ' 'F_VEH_AuxDlog ' Me.AcceptButton = Me.OK_Button Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.CancelButton = Me.Cancel_Button - Me.ClientSize = New System.Drawing.Size(459, 429) - Me.Controls.Add(Me.LVTech) + Me.ClientSize = New System.Drawing.Size(459, 141) Me.Controls.Add(Me.PnFile) Me.Controls.Add(Me.PnTech) Me.Controls.Add(Me.TableLayoutPanel1) @@ -256,7 +236,5 @@ Partial Class F_VEH_AuxDlog Friend WithEvents CbTech As System.Windows.Forms.ComboBox Friend WithEvents PnTech As System.Windows.Forms.Panel Friend WithEvents PnFile As System.Windows.Forms.Panel - Friend WithEvents LVTech As System.Windows.Forms.ListView - Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader End Class diff --git a/VECTO/GUI/F_VEH_AuxDlog.vb b/VECTO/GUI/F_VEH_AuxDlog.vb index 093bac254771ac42978304f1dba7df323784bbe0..ab5b6a27ec558b095587f55e25df74cc4a86dd3f 100644 --- a/VECTO/GUI/F_VEH_AuxDlog.vb +++ b/VECTO/GUI/F_VEH_AuxDlog.vb @@ -8,191 +8,125 @@ ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ' ' See the LICENSE.txt for the specific language governing permissions and limitations. +Option Infer On + Imports System.Windows.Forms -Imports System.Collections.Generic ''' <summary> ''' Aux Config Editor (Job Editor sub-dialog) ''' </summary> -''' <remarks></remarks> Public Class F_VEH_AuxDlog - - Public VehPath As String = "" - - 'New instance - Public Sub New() - - ' Dieser Aufruf ist für den Designer erforderlich. - InitializeComponent() - - ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. - Me.CbType.Items.Add("Fan") - Me.CbType.Items.Add("Steering pump") - Me.CbType.Items.Add("HVAC") - Me.CbType.Items.Add("Electric System") - - Me.PnFile.Enabled = Not Cfg.DeclMode - Me.PnTech.Enabled = Cfg.DeclMode - - - End Sub - - 'Initialise form - Private Sub F_VEH_AuxDlog_Load(sender As Object, e As System.EventArgs) Handles Me.Load - Me.Text = CbType.Text - End Sub - - 'Set generic values for Declaration mode - Private Sub DeclInit() - Dim txt As String - Dim kv As KeyValuePair(Of String, Dictionary(Of tMission, Single)) - - If Not Cfg.DeclMode Then - Me.LVTech.Visible = False - Me.Height = 220 - Exit Sub - End If - - Me.CbTech.Items.Clear() - - Select Case TbID.Text - Case sKey.AUX.Fan - For Each txt In Declaration.AuxTechs(tAux.Fan) - Me.CbTech.Items.Add(txt) - Next - - Case sKey.AUX.SteerPump - For Each txt In Declaration.AuxTechs(tAux.SteerPump) - Me.CbTech.Items.Add(txt) - Next - - Case sKey.AUX.HVAC - For Each txt In Declaration.AuxTechs(tAux.HVAC) - Me.CbTech.Items.Add(txt) - Next - Me.CbTech.SelectedIndex = 0 - - Case sKey.AUX.ElecSys - For Each txt In Declaration.AuxTechs(tAux.ElectricSys) - Me.CbTech.Items.Add(txt) - Next - Me.CbTech.SelectedIndex = 0 - - - Case Else 'sKey.AUX.PneumSys - For Each txt In Declaration.AuxTechs(tAux.PneumSys) - Me.CbTech.Items.Add(txt) - Next - Me.CbTech.SelectedIndex = 0 - - End Select - - - If TbID.Text = sKey.AUX.ElecSys Then - - Me.LVTech.Items.Clear() - For Each kv In Declaration.AuxESpower - Me.LVTech.Items.Add(kv.Key) - Next - Me.LVTech.Visible = True - - Me.Height = 457 - - Else - - Me.LVTech.Visible = False - Me.Height = 220 - - End If - - End Sub - - 'Save and close - Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click - Me.DialogResult = System.Windows.Forms.DialogResult.OK - Me.Close() - End Sub - - 'Cancel - Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click - Me.DialogResult = System.Windows.Forms.DialogResult.Cancel - Me.Close() - End Sub - - 'Close form. Check if form is complete and valid - Private Sub F_VEH_AuxDlog_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing - If e.CloseReason <> CloseReason.WindowsShutDown And Me.DialogResult <> Windows.Forms.DialogResult.Cancel Then - - If Trim(Me.TbID.Text) = "" Or Trim(Me.CbType.Text) = "" Then - MsgBox("Form is incomplete!", MsgBoxStyle.Critical) - e.Cancel = True - End If - - If Me.TbID.Text.Contains(",") Or Me.CbType.Text.Contains(",") Or Me.TbPath.Text.Contains(",") Then - MsgBox("',' is no valid character!", MsgBoxStyle.Critical) - e.Cancel = True - End If - - If Cfg.DeclMode Then - - If Me.CbTech.Text = "" Then - MsgBox("Form is incomplete!", MsgBoxStyle.Critical) - e.Cancel = True - End If - - Else - - If Trim(Me.TbPath.Text) = "" Then - MsgBox("Form is incomplete!", MsgBoxStyle.Critical) - e.Cancel = True - End If - - End If - - End If - End Sub - - 'Browse for .vaux files - Private Sub BtBrowse_Click(sender As System.Object, e As System.EventArgs) Handles BtBrowse.Click - If fbAUX.OpenDialog(fFileRepl(Me.TbPath.Text, VehPath)) Then Me.TbPath.Text = fFileWoDir(fbAUX.Files(0), VehPath) - End Sub - - 'Update ID when Aux Type was changed - Private Sub CbType_TextChanged(sender As Object, e As System.EventArgs) Handles CbType.TextChanged - - If Me.CbType.Text = "" Then - Me.TbID.Text = "" - Else - If Cfg.DeclMode Then - Select Case Me.CbType.SelectedIndex - Case 0 - Me.TbID.Text = sKey.AUX.Fan - Case 1 - Me.TbID.Text = sKey.AUX.SteerPump - - Case Else '2 - Me.TbID.Text = sKey.AUX.HVAC - - End Select - Else - Me.TbID.Text = Trim(UCase(Me.CbType.Text.Substring(0, CInt(Math.Min(Me.CbType.Text.Length, 3))))) - End If - End If - - End Sub - - 'Update help label if ID was changed - Private Sub TbID_TextChanged(sender As System.Object, e As System.EventArgs) Handles TbID.TextChanged - - DeclInit() - - If Trim(Me.TbID.Text) = "" Or Cfg.DeclMode Then - Me.LbIDhelp.Text = "" - Else - Me.LbIDhelp.Text = "Header in Driving cycle: <AUX_" & Trim(Me.TbID.Text) & ">" - End If - - End Sub - - + Public VehPath As String = "" + + Public Sub New() + InitializeComponent() + + CbType.Items.Add("Fan") + CbType.Items.Add("Steering pump") + CbType.Items.Add("HVAC") + CbType.Items.Add("Electric System") + PnTech.Visible = Cfg.DeclMode + PnFile.Visible = Not Cfg.DeclMode + End Sub + + 'Initialise form + Private Sub F_VEH_AuxDlog_Load(sender As Object, e As EventArgs) Handles Me.Load + Text = CbType.Text + End Sub + + 'Set generic values for Declaration mode + Private Sub DeclInit() + CbTech.Items.Clear() + Select Case TbID.Text + Case sKey.AUX.Fan + CbTech.Items.AddRange(Declaration.AuxTechs(tAux.Fan).ToArray()) + Case sKey.AUX.SteerPump + CbTech.Items.AddRange(Declaration.AuxTechs(tAux.SteerPump).ToArray()) + Case sKey.AUX.HVAC + CbTech.Items.AddRange(Declaration.AuxTechs(tAux.HVAC).ToArray()) + Case sKey.AUX.ElecSys + CbTech.Items.AddRange(Declaration.AuxTechs(tAux.ElectricSys).ToArray()) + Case Else 'sKey.AUX.PneumSys + CbTech.Items.AddRange(Declaration.AuxTechs(tAux.PneumSys).ToArray()) + End Select + If CbTech.Items.Count > 0 Then + CbTech.SelectedIndex = 0 + PnTech.Enabled = True + Else + PnTech.Enabled = False + End If + End Sub + + 'Close form. Check if form is complete and valid + Private Sub F_VEH_AuxDlog_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing + If e.CloseReason <> CloseReason.WindowsShutDown And DialogResult <> DialogResult.Cancel Then + + If Trim(TbID.Text) = "" Or Trim(CbType.Text) = "" Then + MsgBox("Form is incomplete!", MsgBoxStyle.Critical) + e.Cancel = True + End If + + If TbID.Text.Contains(",") Or CbType.Text.Contains(",") Or TbPath.Text.Contains(",") Then + MsgBox("',' is no valid character!", MsgBoxStyle.Critical) + e.Cancel = True + End If + + If Cfg.DeclMode Then + + If CbTech.Items.Count > 0 AndAlso CbTech.Text = "" Then + MsgBox("Form is incomplete!", MsgBoxStyle.Critical) + e.Cancel = True + End If + + Else + + If Trim(TbPath.Text) = "" Then + MsgBox("Form is incomplete!", MsgBoxStyle.Critical) + e.Cancel = True + End If + + End If + + End If + End Sub + + 'Browse for .vaux files + Private Sub BtBrowse_Click(sender As Object, e As EventArgs) Handles BtBrowse.Click + If fbAUX.OpenDialog(fFileRepl(TbPath.Text, VehPath)) Then TbPath.Text = fFileWoDir(fbAUX.Files(0), VehPath) + End Sub + + 'Update ID when Aux Type was changed + Private Sub CbType_TextChanged(sender As Object, e As EventArgs) Handles CbType.TextChanged + + If CbType.Text = "" Then + TbID.Text = "" + Else + If Cfg.DeclMode Then + Select Case CbType.SelectedIndex + Case 0 + TbID.Text = sKey.AUX.Fan + Case 1 + TbID.Text = sKey.AUX.SteerPump + + Case Else '2 + TbID.Text = sKey.AUX.HVAC + + End Select + Else + TbID.Text = Trim(UCase(CbType.Text.Substring(0, CInt(Math.Min(CbType.Text.Length, 3))))) + End If + End If + End Sub + + 'Update help label if ID was changed + Private Sub TbID_TextChanged(sender As Object, e As EventArgs) Handles TbID.TextChanged + + DeclInit() + + If Trim(TbID.Text) = "" Or Cfg.DeclMode Then + LbIDhelp.Text = "" + Else + LbIDhelp.Text = "Header in Driving cycle: <AUX_" & Trim(TbID.Text) & ">" + End If + End Sub End Class diff --git a/VECTO/GUI/F_VEH_Axle.vb b/VECTO/GUI/F_VEH_Axle.vb index 19bb2b25cddf8fa9aaa0429cf49bdf46554293e9..6efbbd19002e0a3763ec266012f96701291eecba 100644 --- a/VECTO/GUI/F_VEH_Axle.vb +++ b/VECTO/GUI/F_VEH_Axle.vb @@ -8,87 +8,74 @@ ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ' ' See the LICENSE.txt for the specific language governing permissions and limitations. -Imports System.Windows.Forms +Option Infer On +Option Strict On +Option Explicit On ''' <summary> ''' Axle Config Editor (Vehicle Editor sub-dialog) ''' </summary> -''' <remarks></remarks> Public Class F_VEH_Axle - - Public Sub New() - Dim w As String - - ' Dieser Aufruf ist für den Designer erforderlich. - InitializeComponent() - - ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. - Me.CbWheels.Items.Add("-") - For Each w In Declaration.WheelsList - Me.CbWheels.Items.Add(w) - Next - - - - End Sub - - Public Sub Clear() - Me.CbTwinT.Checked = False - Me.TbAxleShare.Text = "" - Me.TbI_wheels.Text = "" - Me.TbRRC.Text = "" - Me.TbFzISO.Text = "" - Me.CbWheels.SelectedIndex = 0 - End Sub - - 'Initialise - Private Sub F_VEH_Axle_Load(sender As Object, e As System.EventArgs) Handles Me.Load - Me.PnAxle.Enabled = Not Cfg.DeclMode - End Sub - - 'Save and close - Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click - - If Not Cfg.DeclMode Then - If Not IsNumeric(Me.TbAxleShare.Text) OrElse Trim(Me.TbAxleShare.Text) = "" Then - MsgBox("Weight input is not valid!") - Exit Sub - End If - End If - - If Not IsNumeric(Me.TbRRC.Text) OrElse Trim(Me.TbRRC.Text) = "" Then - MsgBox("RRC input is not valid!") - Exit Sub - End If - - If Not IsNumeric(Me.TbFzISO.Text) OrElse Trim(Me.TbFzISO.Text) = "" Then - MsgBox("Fz ISO input is not valid!") - Exit Sub - End If - - Me.DialogResult = System.Windows.Forms.DialogResult.OK - Me.Close() - End Sub - - Private Sub CbWheels_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles CbWheels.SelectedIndexChanged - Dim inertia As Single - If Cfg.DeclMode Then - inertia = Declaration.WheelsInertia(Me.CbWheels.Text) - If inertia < 0 Then - Me.TbI_wheels.Text = "-" - Else - Me.TbI_wheels.Text = inertia - End If - End If - End Sub - - 'Cancel - Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click - Me.DialogResult = System.Windows.Forms.DialogResult.Cancel - Me.Close() - End Sub - - - - + Public Sub New() + InitializeComponent() + + CbWheels.Items.Add("-") + CbWheels.Items.AddRange(Declaration.WheelsList) + End Sub + + Public Sub Clear() + CbTwinT.Checked = False + TbAxleShare.Text = "" + TbI_wheels.Text = "" + TbRRC.Text = "" + TbFzISO.Text = "" + CbWheels.SelectedIndex = 0 + End Sub + + 'Initialise + Private Sub F_VEH_Axle_Load(sender As Object, e As EventArgs) Handles Me.Load + PnAxle.Enabled = Not Cfg.DeclMode + End Sub + + 'Save and close + Private Sub OK_Button_Click(sender As Object, e As EventArgs) Handles OK_Button.Click + + If Not Cfg.DeclMode Then + If Not IsNumeric(TbAxleShare.Text) OrElse Trim(TbAxleShare.Text) = "" Then + MsgBox("Weight input is not valid!") + Exit Sub + End If + End If + + If Not IsNumeric(TbRRC.Text) OrElse Trim(TbRRC.Text) = "" Then + MsgBox("RRC input is not valid!") + Exit Sub + End If + + If Not IsNumeric(TbFzISO.Text) OrElse Trim(TbFzISO.Text) = "" Then + MsgBox("Fz ISO input is not valid!") + Exit Sub + End If + + DialogResult = DialogResult.OK + Close() + End Sub + + Private Sub CbWheels_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CbWheels.SelectedIndexChanged + Dim inertia As Single + If Cfg.DeclMode Then + inertia = Declaration.WheelsInertia(CbWheels.Text) + If inertia < 0 Then + TbI_wheels.Text = "-" + Else + TbI_wheels.Text = inertia.ToString() + End If + End If + End Sub + + 'Cancel + Private Sub Cancel_Button_Click(sender As Object, e As EventArgs) Handles Cancel_Button.Click + DialogResult = DialogResult.Cancel + Close() + End Sub End Class diff --git a/VECTO/Input Files/cVECTO.vb b/VECTO/Input Files/cVECTO.vb index 3fe56319471cea56030e11d9e79fe3ee3e3d99a9..a9c3e11174a2f711f460aaf78a1c1141c06ac36b 100644 --- a/VECTO/Input Files/cVECTO.vb +++ b/VECTO/Input Files/cVECTO.vb @@ -8,12 +8,14 @@ ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ' ' See the LICENSE.txt for the specific language governing permissions and limitations. +Option Infer On Imports System.Collections.Generic +Imports System.Linq +Imports TUGraz.VectoCommon.Utils Public Class cVECTO - Private Const FormatVersion As Short = 2 - Private FileVersion As Short + Private Const FormatVersion As Short = 3 'AA-TB 'STORES THE Type and version of the chosen or default Auxiliary Type ( Classic/Original or other ) @@ -46,7 +48,6 @@ Public Class cVECTO Public AuxRefs As Dictionary(Of String, cAux) _ 'Alle Nebenverbraucher die in der Veh-Datei UND im Zyklus definiert sind Public AuxDef As Boolean 'True wenn ein oder mehrere Nebenverbraucher definiert sind - Public EStechs As List(Of String) Public CycleFiles As List(Of cSubPath) @@ -65,10 +66,9 @@ Public Class cVECTO Public SavedInDeclMode As Boolean - Public Class cAuxEntry Public Type As String - Public Path As cSubPath + Public ReadOnly Path As cSubPath Public TechStr As String = "" Public Sub New() @@ -84,11 +84,11 @@ Public Class cVECTO MyFileList = New List(Of String) '.vecto - MyFileList.Add(Me.sFilePath) + MyFileList.Add(sFilePath) 'Veh - If Not Me.EngOnly Then - MyFileList.Add(Me.PathVEH) + If Not EngOnly Then + MyFileList.Add(PathVEH) If Not VEH.CreateFileList Then Return False For Each str In VEH.FileList @@ -97,17 +97,17 @@ Public Class cVECTO End If 'Eng - MyFileList.Add(Me.PathENG) + MyFileList.Add(PathENG) If Not ENG.CreateFileList Then Return False For Each str In ENG.FileList MyFileList.Add(str) Next - If Not Me.EngOnly Then + If Not EngOnly Then 'Gbx - MyFileList.Add(Me.PathGBX) + MyFileList.Add(PathGBX) If Not GBX.CreateFileList Then Return False For Each str In GBX.FileList @@ -116,18 +116,18 @@ Public Class cVECTO 'Aux If AuxDef And Not Cfg.DeclMode Then - For Each Aux0 In Me.AuxPaths.Values + For Each Aux0 In AuxPaths.Values MyFileList.Add(Aux0.Path.FullPath) Next End If '.vacc - MyFileList.Add(Me.stDesMaxFile.FullPath) + MyFileList.Add(stDesMaxFile.FullPath) End If 'Cycles - For Each sb In Me.CycleFiles + For Each sb In CycleFiles MyFileList.Add(sb.FullPath) Next @@ -153,30 +153,22 @@ Public Class cVECTO AuxPaths = New Dictionary(Of String, cAuxEntry) AuxRefs = New Dictionary(Of String, cAux) AuxDef = False - EStechs = New List(Of String) CycleFiles = New List(Of cSubPath) End Sub Public Function SaveFile() As Boolean - Dim AuxEntryKV As KeyValuePair(Of String, cAuxEntry) - 'Dim s As String - Dim sb As cSubPath Dim JSON As New JSON - Dim ls As List(Of Object) - Dim dic As Dictionary(Of String, Object) - Dim dic0 As Dictionary(Of String, Object) 'Header - dic = New Dictionary(Of String, Object) - dic.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")") - dic.Add("Date", Now.ToString) - dic.Add("AppVersion", VECTOvers) - dic.Add("FileVersion", FormatVersion) - JSON.Content.Add("Header", dic) + JSON.Content.Add("Header", New Dictionary(Of String, Object) From { + {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, + {"Date", Now.ToString}, + {"AppVersion", VECTOvers}, + {"FileVersion", FormatVersion}}) 'Body - dic0 = New Dictionary(Of String, Object) + Dim dic0 = New Dictionary(Of String, Object) dic0.Add("SavedInDeclMode", Cfg.DeclMode) SavedInDeclMode = Cfg.DeclMode @@ -188,7 +180,7 @@ Public Class cVECTO 'Cycles If CycleFiles.Count > 0 Then - ls = New List(Of Object) + Dim ls = New List(Of Object) For Each sb In CycleFiles ls.Add(sb.PathOrDummy) Next @@ -201,95 +193,60 @@ Public Class cVECTO dic0.Add("AuxiliaryVersion", AuxiliaryVersion) dic0.Add("AdvancedAuxiliaryFilePath", AdvancedAuxiliaryFilePath) - 'Aux - If AuxPaths.Count > 0 Then - ls = New List(Of Object) - For Each AuxEntryKV In AuxPaths - dic = New Dictionary(Of String, Object) - dic.Add("ID", Trim(UCase(AuxEntryKV.Key))) - dic.Add("Type", AuxEntryKV.Value.Type) - dic.Add("Path", AuxEntryKV.Value.Path.PathOrDummy) - dic.Add("Technology", AuxEntryKV.Value.TechStr) - - If AuxEntryKV.Key = sKey.AUX.ElecSys Then - dic.Add("TechList", EStechs) - End If - - ls.Add(dic) - Next - dic0.Add("Aux", ls) + If AuxPaths.Any() Then + dic0.Add("Aux", AuxPaths.Select(Function(kv) New Dictionary(Of String, Object) From { + {"ID", Trim(UCase(kv.Key))}, + {"Type", kv.Value.Type}, + {"Path", kv.Value.Path.PathOrDummy}, + {"Technology", kv.Value.TechStr.ToEnumerable()}})) End If - 'VACC dic0.Add("VACC", stDesMaxFile.PathOrDummy) - - 'EngineOnlyMode dic0.Add("EngineOnlyMode", EngOnly) - - 'Start Stop - dic = New Dictionary(Of String, Object) - dic.Add("Enabled", boStartStop) - dic.Add("MaxSpeed", siStStV) - dic.Add("MinTime", siStStT) - dic.Add("Delay", StStDelay) - dic0.Add("StartStop", dic) - - 'LAC - dic = New Dictionary(Of String, Object) - dic.Add("Enabled", LookAheadOn) - dic.Add("Dec", a_lookahead) - dic.Add("MinSpeed", vMinLA) - dic.Add("PreviewDistanceFactor", LacPreviewFactor) - dic.Add("DF_offset", LacDfOffset) - dic.Add("DF_scaling", LacDfScale) - dic.Add("DF_targetSpeedLookup", LacDfTargetSpeedFile) - dic.Add("Df_velocityDropLookup", LacDfVelocityDropFile) - - dic0.Add("LAC", dic) + dic0.Add("StartStop", New Dictionary(Of String, Object) From { + {"Enabled", boStartStop}, + {"MaxSpeed", siStStV}, + {"MinTime", siStStT}, + {"Delay", StStDelay}}) + dic0.Add("LAC", New Dictionary(Of String, Object) From { + {"Enabled", LookAheadOn}, + {"Dec", a_lookahead}, + {"MinSpeed", vMinLA}, + {"PreviewDistanceFactor", LacPreviewFactor}, + {"DF_offset", LacDfOffset}, + {"DF_scaling", LacDfScale}, + {"DF_targetSpeedLookup", LacDfTargetSpeedFile}, + {"Df_velocityDropLookup", LacDfVelocityDropFile}}) 'Overspeed / EcoRoll - dic = New Dictionary(Of String, Object) + Dim overspeedDic = New Dictionary(Of String, Object) If EcoRollOn Then - dic.Add("Mode", "EcoRoll") + overspeedDic.Add("Mode", "EcoRoll") ElseIf OverSpeedOn Then - dic.Add("Mode", "OverSpeed") + overspeedDic.Add("Mode", "OverSpeed") Else - dic.Add("Mode", "Off") + overspeedDic.Add("Mode", "Off") End If - dic.Add("MinSpeed", vMin) - dic.Add("OverSpeed", OverSpeed) - dic.Add("UnderSpeed", UnderSpeed) - dic0.Add("OverSpeedEcoRoll", dic) - - ' - + overspeedDic.Add("MinSpeed", vMin) + overspeedDic.Add("OverSpeed", OverSpeed) + overspeedDic.Add("UnderSpeed", UnderSpeed) + dic0.Add("OverSpeedEcoRoll", overspeedDic) JSON.Content.Add("Body", dic0) - Return JSON.WriteFile(sFilePath) End Function Public Function ReadFile() As Boolean - Dim AuxEntry As cAuxEntry - Dim AuxID As String - Dim MsgSrc As String - Dim SubPath As cSubPath - Dim JSON As New JSON - Dim str As String - Dim dic As Object - - - MsgSrc = "Main/ReadInp/GEN" + Dim msgSrc = "Main/ReadInp/GEN" SetDefault() + Dim JSON As New JSON If Not JSON.ReadFile(sFilePath) Then Return False Try - - FileVersion = JSON.Content("Header")("FileVersion") - - If FileVersion > 1 Then + Dim fileVersion = JSON.Content("Header")("FileVersion") + If fileVersion > 1 Then SavedInDeclMode = JSON.Content("Body")("SavedInDeclMode") Else SavedInDeclMode = Cfg.DeclMode @@ -304,10 +261,10 @@ Public Class cVECTO stPathGBX.Init(MyPath, JSON.Content("Body")("GearboxFile")) If Not JSON.Content("Body")("Cycles") Is Nothing Then - For Each str In JSON.Content("Body")("Cycles") - SubPath = New cSubPath - SubPath.Init(MyPath, str) - CycleFiles.Add(SubPath) + For Each str As String In JSON.Content("Body")("Cycles") + Dim subPath = New cSubPath + subPath.Init(MyPath, str) + CycleFiles.Add(subPath) Next End If @@ -328,41 +285,99 @@ Public Class cVECTO If Not JSON.Content("Body")("Aux") Is Nothing Then For Each dic In JSON.Content("Body")("Aux") - AuxID = UCase(Trim(dic("ID").ToString)) + Dim auxId As String = UCase(Trim(dic("ID").ToString)) - If AuxPaths.ContainsKey(AuxID) Then - WorkerMsg(tMsgID.Err, "Multiple definitions of the same auxiliary type (" & AuxID & ")!", MsgSrc) + If AuxPaths.ContainsKey(auxId) Then + WorkerMsg(tMsgID.Err, "Multiple definitions of the same auxiliary type (" & auxId & ")!", msgSrc) Return False End If - AuxEntry = New cAuxEntry - - AuxEntry.Type = dic("Type") - AuxEntry.Path.Init(MyPath, dic("Path")) + Dim auxEntry = New cAuxEntry - If Not dic("Technology") Is Nothing Then AuxEntry.TechStr = dic("Technology") + auxEntry.Type = dic("Type") + auxEntry.Path.Init(MyPath, dic("Path")) - AuxPaths.Add(AuxID, AuxEntry) + If Not dic("Technology") Is Nothing Then + If fileVersion = 2 Then + auxEntry.TechStr = dic("Technology") + End If + If fileVersion = 3 Then + auxEntry.TechStr = dic("Technology")(0) + End If + End If - AuxDef = True + If (auxId = sKey.AUX.HVAC) Then + If Not String.IsNullOrWhiteSpace(auxEntry.TechStr) Then + auxEntry.TechStr = "" + WorkerMsg(tMsgID.Warn, "Aux: Upgraded HVAC to new format: '" + auxEntry.TechStr + "'", msgSrc) + End If + End If - If AuxID = sKey.AUX.ElecSys Then - If Not dic("TechList") Is Nothing Then - For Each str In dic("TechList") - EStechs.Add(str) - Next + If auxId = sKey.AUX.ElecSys Then + If auxEntry.TechStr = "Custom Technology List" OrElse String.IsNullOrWhiteSpace(auxEntry.TechStr) Then + Dim hasTech = False + + If Not dic("TechList") Is Nothing Then + For Each t In dic("TechList") + hasTech = True + Next + End If + + If Not hasTech Then + auxEntry.TechStr = "Standard technology" + Else + auxEntry.TechStr = "Standard technology - LED headlights, all" + End If + WorkerMsg(tMsgID.Warn, "Aux: Upgraded Electric System to new format: '" + auxEntry.TechStr + "'", msgSrc) End If End If + If auxId = sKey.AUX.SteerPump Then + Select Case auxEntry.TechStr + Case "Variable displacement" + auxEntry.TechStr = "Variable displacement elec. controlled" + WorkerMsg(tMsgID.Warn, + "Aux: Upgraded Steering Pump Technology from 'Variable displacement' to new format: '" + auxEntry.TechStr + + "'", msgSrc) + Case "Hydraulic supported by electric" + auxEntry.TechStr = "Dual displacement" + WorkerMsg(tMsgID.Warn, + "Aux: Upgraded Steering Pump Technology from 'Hydraulic supported by electric' to new format: '" + + auxEntry.TechStr + "'", + msgSrc) + End Select + End If + + If auxId = sKey.AUX.Fan Then + Select Case auxEntry.TechStr + Case "Crankshaft mounted - Electronically controlled visco clutch (Default)" + auxEntry.TechStr = "Crankshaft mounted - Electronically controlled visco clutch" + Case "Crankshaft mounted - On/Off clutch" + auxEntry.TechStr = "Crankshaft mounted - On/off clutch" + Case "Belt driven or driven via transm. - On/Off clutch" + auxEntry.TechStr = "Belt driven or driven via transm. - On/off clutch" + End Select + End If + + If fileVersion = 2 AndAlso auxId = sKey.AUX.PneumSys Then + auxEntry.TechStr = "Medium Supply 1-stage" + WorkerMsg(tMsgID.Warn, "Aux: Upgraded Pneumatic System Technology to new format: '" + auxEntry.TechStr + "'", + msgSrc) + End If + + AuxPaths.Add(auxId, auxEntry) + AuxDef = True Next End If - If Not JSON.Content("Body")("VACC") Is Nothing Then stDesMaxFile.Init(MyPath, JSON.Content("Body")("VACC")) + If Not JSON.Content("Body")("VACC") Is Nothing Then + stDesMaxFile.Init(MyPath, JSON.Content("Body")("VACC")) + End If EngOnly = JSON.Content("Body")("EngineOnlyMode") If Not JSON.Content("Body")("StartStop") Is Nothing Then - dic = JSON.Content("Body")("StartStop") + Dim dic = JSON.Content("Body")("StartStop") boStartStop = dic("Enabled") siStStV = dic("MaxSpeed") siStStT = dic("MinTime") @@ -372,7 +387,7 @@ Public Class cVECTO End If If Not JSON.Content("Body")("LAC") Is Nothing Then - dic = JSON.Content("Body")("LAC") + Dim dic = JSON.Content("Body")("LAC") LookAheadOn = dic("Enabled") a_lookahead = dic("Dec") vMinLA = dic("MinSpeed") @@ -386,8 +401,7 @@ Public Class cVECTO End If If Not JSON.Content("Body")("OverSpeedEcoRoll") Is Nothing Then - - dic = JSON.Content("Body")("OverSpeedEcoRoll") + Dim dic = JSON.Content("Body")("OverSpeedEcoRoll") Select Case UCase(dic("Mode").ToString).Trim Case "ECOROLL" @@ -403,7 +417,7 @@ Public Class cVECTO EcoRollOn = False Case Else - WorkerMsg(tMsgID.Err, "Value '" & dic("Mode") & "' is not valid for OverSpeedEcoRoll/Mode!", MsgSrc) + WorkerMsg(tMsgID.Err, "Value '" & dic("Mode") & "' is not valid for OverSpeedEcoRoll/Mode!", msgSrc) Return False End Select @@ -418,7 +432,7 @@ Public Class cVECTO Catch ex As Exception - WorkerMsg(tMsgID.Err, "Failed to read VECTO file! " & ex.Message, MsgSrc) + WorkerMsg(tMsgID.Err, "Failed to read VECTO file! " & ex.Message, msgSrc) Return False End Try @@ -437,7 +451,6 @@ Public Class cVECTO siStStV = 5 siStStT = 5 StStDelay = 0 - FileVersion = 0 stPathVEH.Clear() stPathENG.Clear() @@ -453,8 +466,6 @@ Public Class cVECTO AuxPaths.Clear() AuxRefs.Clear() AuxDef = False - EStechs.Clear() - EngOnly = False a_lookahead = 0 @@ -470,24 +481,16 @@ Public Class cVECTO End Sub Public Function DeclInit() As Boolean - - Dim cl As List(Of String) - Dim s As String - Dim SubPath As cSubPath - Dim MsgSrc As String - - MsgSrc = "VECTO/DeclInit" - EngOnly = False CycleFiles.Clear() - cl = Declaration.SegRef.GetCycles + Dim cl = Declaration.SegRef.GetCycles For Each s In cl - SubPath = New cSubPath - SubPath.Init(MyPath, s) - CycleFiles.Add(SubPath) + Dim subPath = New cSubPath + subPath.Init(MyPath, s) + CycleFiles.Add(subPath) Next stDesMaxFile.Init(MyPath, Declaration.SegRef.VACCfile) @@ -516,16 +519,14 @@ Public Class cVECTO Dim file As cFile_V3 Dim line As String() - Dim MsgSrc As String - - MsgSrc = "VECTO/Init" + Dim msgSrc = "VECTO/Init" If Not EngOnly Then file = New cFile_V3 If Not file.OpenRead(stDesMaxFile.FullPath) Then - WorkerMsg(tMsgID.Err, "Can't read .vacc file (" & stDesMaxFile.FullPath & ")", MsgSrc) + WorkerMsg(tMsgID.Err, "Can't read .vacc file (" & stDesMaxFile.FullPath & ")", msgSrc) Return False End If @@ -544,7 +545,7 @@ Public Class cVECTO line = file.ReadLine - laDesV.Add(CSng(line(0)) / 3.6) 'km/h => m/s !!!! + laDesV.Add(CSng(line(0)) / 3.6) 'km/h => m/s !!!! laDesMax.Add(CSng(line(1))) laDesMin.Add(CSng(line(2))) @@ -553,7 +554,7 @@ Public Class cVECTO Catch ex As Exception file.Close() - WorkerMsg(tMsgID.Err, "Error in .vacc file. " & ex.Message & " (" & stDesMaxFile.FullPath & ")", MsgSrc, + WorkerMsg(tMsgID.Err, "Error in .vacc file. " & ex.Message & " (" & stDesMaxFile.FullPath & ")", msgSrc, stDesMaxFile.FullPath) Return False @@ -569,143 +570,90 @@ Public Class cVECTO #Region "Aux" Public Function AuxInit() As Boolean - - Dim Aux0 As cAux - Dim AuxPathKV As KeyValuePair(Of String, cAuxEntry) - Dim DRIauxcheck As New Dictionary(Of String, Boolean) - Dim AuxID As String - - Dim MsgSrc As String - - MsgSrc = "VEH/AuxInit" - + Dim msgSrc = "VEH/AuxInit" AuxRefs = New Dictionary(Of String, cAux) If Cfg.DeclMode Then - - For Each AuxPathKV In AuxPaths - AuxRefs.Add(AuxPathKV.Key, Nothing) + For Each auxPathKv In AuxPaths + AuxRefs.Add(auxPathKv.Key, Nothing) Next - Return True - End If - If DRI.AuxDef Xor AuxDef Then - If AuxDef Then - WorkerMsg(tMsgID.Err, "No auxiliary input defined in driving cycle!", MsgSrc) + WorkerMsg(tMsgID.Err, "No auxiliary input defined in driving cycle!", msgSrc) Return False Else - WorkerMsg(tMsgID.Warn, "No auxiliary defined in vehicle file! Psupply input will be ignored!", MsgSrc) + WorkerMsg(tMsgID.Warn, "No auxiliary defined in vehicle file! Psupply input will be ignored!", msgSrc) Return True End If - End If - If Not (DRI.AuxDef Or AuxDef) Then Return True - - - For Each AuxID In DRI.AuxComponents.Keys - DRIauxcheck.Add(AuxID, False) - Next - - For Each AuxPathKV In AuxPaths + If Not (DRI.AuxDef Or AuxDef) Then + Return True + End If - MsgSrc = "VEH/AuxInit/" & AuxPathKV.Key + Dim drIauxcheck = DRI.AuxComponents.Keys.ToDictionary(Function(auxId) auxId, Function(auxId) False) - If Not DRI.AuxComponents.ContainsKey(AuxPathKV.Key) Then - WorkerMsg(tMsgID.Err, "No Psupply input defined in driving cycle for auxiliary '" & AuxPathKV.Key & "'!", MsgSrc) + For Each auxPathKv In AuxPaths + msgSrc = "VEH/AuxInit/" & auxPathKv.Key + If Not DRI.AuxComponents.ContainsKey(auxPathKv.Key) Then + WorkerMsg(tMsgID.Err, "No Psupply input defined in driving cycle for auxiliary '" & auxPathKv.Key & "'!", msgSrc) Return False End If - Aux0 = New cAux - Aux0.Filepath = AuxPathKV.Value.Path.FullPath + Dim aux0 = New cAux + aux0.Filepath = auxPathKv.Value.Path.FullPath - If Not Aux0.Readfile Then - 'Notificationin ReadFile() + If Not aux0.Readfile Then Return False End If - AuxRefs.Add(AuxPathKV.Key, Aux0) - - DRIauxcheck(AuxPathKV.Key) = True - + AuxRefs.Add(auxPathKv.Key, aux0) + drIauxcheck(auxPathKv.Key) = True Next - MsgSrc = "VEH/AuxInit" + msgSrc = "VEH/AuxInit" - For Each AuxID In DRI.AuxComponents.Keys - If Not DRIauxcheck(AuxID) Then _ - WorkerMsg(tMsgID.Warn, "Auxiliary '" & AuxID & "' not found! Psupply input will be ignored!", MsgSrc) + For Each auxId In DRI.AuxComponents.Keys + If Not drIauxcheck(auxId) Then + WorkerMsg(tMsgID.Warn, "Auxiliary '" & auxId & "' not found! Psupply input will be ignored!", msgSrc) + End If Next Return True End Function - Public Function Paux(ByVal AuxID As String, ByVal t As Integer, ByVal nU As Single) As Single - Dim Psupply As Single - Dim Px As Single - Dim Aux0 As cAux - - Dim MsgSrc As String - - MsgSrc = "VEH/Paux" - - If Cfg.DeclMode Then Return Declaration.AuxPower(AuxID) + Public Function Paux(auxId As String, t As Integer, nU As Single) As Single + If Cfg.DeclMode Then Return Declaration.AuxPower(auxId) If AuxDef Then + Dim aux0 = AuxRefs(auxId) + Dim psupply As Single = DRI.AuxComponents(auxId)(t) + If psupply < 0 Then + GoTo lbAuxError + End If - Aux0 = AuxRefs(AuxID) - - Psupply = DRI.AuxComponents(AuxID)(t) - - If Psupply < 0 Then GoTo lbAuxError - - Px = Aux0.Paux(nU, Psupply) - - If Px < 0 Then GoTo lbAuxError - - Return Px - + Dim px As Single = aux0.Paux(nU, psupply) + If px < 0 Then + GoTo lbAuxError + End If + Return px Else - Return 0 - End If - lbAuxError: - MODdata.ModErrors.AuxNegative = AuxID + MODdata.ModErrors.AuxNegative = auxId Return 0 End Function - Public Function PauxSum(ByVal t As Integer, ByVal nU As Single) As Single - Dim sum As Single - Dim AuxID As String - - Dim MsgSrc As String - - MsgSrc = "VEH/Paux" - + Public Function PauxSum(t As Integer, nU As Single) As Single If AuxDef Then - - sum = 0 - - For Each AuxID In AuxRefs.Keys - - sum += Paux(AuxID, t, nU) - - Next - - Return sum - - Else - - Return 0 - + Return AuxRefs.Keys.Sum(Function(auxId) Paux(auxId, t, nU)) End If + Return 0 End Function #End Region @@ -719,12 +667,11 @@ lbAuxError: End Get End Property - - Public Property FilePath() As String + Public Property FilePath As String Get Return sFilePath End Get - Set(ByVal value As String) + Set(value As String) sFilePath = value If sFilePath = "" Then MyPath = "" @@ -735,100 +682,96 @@ lbAuxError: End Property - Public Property PathVEH(Optional ByVal Original As Boolean = False) As String + Public Property PathVEH(Optional ByVal original As Boolean = False) As String Get - If Original Then + If original Then Return stPathVEH.OriginalPath Else Return stPathVEH.FullPath End If End Get - Set(ByVal value As String) + Set(value As String) stPathVEH.Init(MyPath, value) End Set End Property - Public Property PathENG(Optional ByVal Original As Boolean = False) As String + Public Property PathENG(Optional ByVal original As Boolean = False) As String Get - If Original Then + If original Then Return stPathENG.OriginalPath Else Return stPathENG.FullPath End If End Get - Set(ByVal value As String) + Set(value As String) stPathENG.Init(MyPath, value) End Set End Property - Public Property PathGBX(Optional ByVal Original As Boolean = False) As String + Public Property PathGBX(Optional ByVal original As Boolean = False) As String Get - If Original Then + If original Then Return stPathGBX.OriginalPath Else Return stPathGBX.FullPath End If End Get - Set(ByVal value As String) + Set(value As String) stPathGBX.Init(MyPath, value) End Set End Property - Public Property StartStop() As Boolean + Public Property StartStop As Boolean Get Return boStartStop End Get - Set(ByVal value As Boolean) + Set(value As Boolean) boStartStop = value End Set End Property - Public Property StStV() As Single + Public Property StStV As Single Get Return siStStV End Get - Set(ByVal value As Single) + Set(value As Single) siStStV = value End Set End Property - Public Property StStT() As Single + Public Property StStT As Single Get Return siStStT End Get - Set(ByVal value As Single) + Set(value As Single) siStStT = value End Set End Property - Public Property DesMaxFile(Optional ByVal Original As Boolean = False) As String + Public Property DesMaxFile(Optional ByVal original As Boolean = False) As String Get - If Original Then + If original Then Return stDesMaxFile.OriginalPath Else Return stDesMaxFile.FullPath End If End Get - Set(ByVal value As String) + Set(value As String) stDesMaxFile.Init(MyPath, value) End Set End Property Public Property LacPreviewFactor As Single - Public Property LacDfOffset As Single - Public Property LacDfScale As Single - Public Property LacDfTargetSpeedFile As String - Public Property LacDfVelocityDropFile As String #End Region - Public Function aDesMax(ByVal v As Single) As Single + Public Function aDesMax(v As Single) As Single Dim i As Int32 'Extrapolation for x < x(1) @@ -853,7 +796,7 @@ lbInt: Return (v - laDesV(i - 1)) * (laDesMax(i) - laDesMax(i - 1)) / (laDesV(i) - laDesV(i - 1)) + laDesMax(i - 1) End Function - Public Function aDesMin(ByVal v As Single) As Single + Public Function aDesMin(v As Single) As Single Dim i As Int32 'Extrapolation for x < x(1) @@ -879,3 +822,4 @@ lbInt: End Function End Class + diff --git a/VECTO/cDeclaration.vb b/VECTO/cDeclaration.vb index 046ef91cc8038ad218debe78f3ce64f80c47e935..27aea9551f4c1ebefa9882328e9f2f63c618bb7d 100644 --- a/VECTO/cDeclaration.vb +++ b/VECTO/cDeclaration.vb @@ -12,6 +12,7 @@ Imports System.Collections.Generic Imports iTextSharp.text.pdf Imports System.IO +Imports System.Linq Imports iTextSharp.text Public Class cDeclaration @@ -24,7 +25,7 @@ Public Class cDeclaration Public Const SSspeed As Single = 5 Public Const SStime As Single = 5 Public Const SSdelay As Single = 5 - Public Const LACa As Single = -0.5 + Public Const LACa As Single = - 0.5 Public Const LACvmin As Single = 50 Public Const Overspeed As Single = 5 Public Const Underspeed As Single = 5 @@ -60,15 +61,10 @@ Public Class cDeclaration Public AuxPower As Dictionary(Of String, Single) Private AuxFanPower As Dictionary(Of String, Dictionary(Of tMission, Single)) - Private AuxSteerPumpPower As Dictionary(Of String, Dictionary(Of tMission, Single())) Private AuxSteepPumpFactors As Dictionary(Of String, Single()) - Private AuxHVACPower As Dictionary(Of String, Dictionary(Of tMission, Single)) - - Private AuxESbase As Dictionary(Of tMission, Single) Public AuxESpower As Dictionary(Of String, Dictionary(Of tMission, Single)) - Private AuxPSpower As Dictionary(Of String, Dictionary(Of tMission, Single)) Private Wheels As Dictionary(Of String, cWheel) @@ -106,7 +102,6 @@ Public Class cDeclaration Dim TrS As Single Dim TrA As Single Dim stl As String() - Dim First As Boolean Dim BodyTrWeightList As List(Of String) Dim LoadingList As List(Of String) @@ -252,11 +247,11 @@ Public Class cDeclaration Select Case i Case 0 mc0.WHTCWF = New Dictionary(Of tWHTCpart, Single) - mc0.WHTCWF.Add(tWHTCpart.Urban, line(a) / 100) + mc0.WHTCWF.Add(tWHTCpart.Urban, line(a)/100) Case 1 - mc0.WHTCWF.Add(tWHTCpart.Rural, line(a) / 100) + mc0.WHTCWF.Add(tWHTCpart.Rural, line(a)/100) Case Else '2 - mc0.WHTCWF.Add(tWHTCpart.Motorway, line(a) / 100) + mc0.WHTCWF.Add(tWHTCpart.Motorway, line(a)/100) End Select Next Next @@ -373,7 +368,7 @@ Public Class cDeclaration For a = 1 To TrA - l0.Add(TrS / TrA) + l0.Add(TrS/TrA) Next ste0.AxleSharesTr.Add(SegmentTable.MissionList(i), l0) @@ -415,7 +410,7 @@ Public Class cDeclaration at0.Add(line(0)) AuxPower0 = New Dictionary(Of tMission, Single) i = 0 - For Each mt0 In SegmentTable.MissionList + For Each mt0 In SegmentTable.MissionList.Take(5) i += 1 AuxPower0.Add(mt0, line(i)) Next @@ -443,7 +438,7 @@ Public Class cDeclaration Do While Not file.EndOfFile line = file.ReadLine at0.Add(line(0)) - AuxSteepPumpFactors.Add(line(0), New Single() {CSng(line(1)), CSng(line(2)), CSng(line(3)), CSng(line(4))}) + AuxSteepPumpFactors.Add(line(0), New Single() {CSng(line(1)), CSng(line(2)), CSng(line(3))}) Loop file.Close() If Not file.OpenRead(MyDeclPath & "VAUX\SP-Table.csv") Then @@ -462,7 +457,7 @@ Public Class cDeclaration STEpower0.Add(mt0, New Single() {0}) Else stl = line(i).Split("/") - STEpower0.Add(mt0, New Single() {CSng(stl(0)), CSng(stl(1)), CSng(stl(2)), CSng(stl(3))}) + STEpower0.Add(mt0, New Single() {CSng(stl(0)), CSng(stl(1)), CSng(stl(2))}) End If Next AuxSteerPumpPower.Add(line(0), STEpower0) @@ -501,46 +496,37 @@ Public Class cDeclaration Return False End Try - at0 = New List(Of String) - at0.Add("Default") - AuxTechs.Add(tAux.HVAC, at0) + AuxTechs.Add(tAux.HVAC, New List(Of String)) 'Aux - Electric System - AuxESbase = New Dictionary(Of tMission, Single) AuxESpower = New Dictionary(Of String, Dictionary(Of tMission, Single)) Try If Not file.OpenRead(MyDeclPath & "VAUX\ES-Tech.csv") Then - GUImsg(tMsgID.Err, "Failed to load Declaration Config (Electric system config)!") + GUImsg(tMsgID.Err, "Failed to load Declaration Config (Electric system aux config)!") Return False End If 'Skip Header file.ReadLine() - First = True + at0 = New List(Of String) Do While Not file.EndOfFile line = file.ReadLine + at0.Add(line(0)) AuxPower0 = New Dictionary(Of tMission, Single) i = 0 - For Each mt0 In SegmentTable.MissionList + For Each mt0 In SegmentTable.MissionList.Take(5) i += 1 AuxPower0.Add(mt0, line(i)) Next - If First Then - AuxESbase = AuxPower0 - First = False - Else - AuxESpower.Add(line(0), AuxPower0) - End If + AuxESpower.Add(line(0), AuxPower0) Loop + AuxTechs.Add(tAux.ElectricSys, at0) file.Close() Catch ex As Exception file.Close() GUImsg(tMsgID.Err, "Failed to load Declaration Config (Electric system config)!" & ex.Message) Return False End Try - at0 = New List(Of String) - at0.Add("Custom Technology List") - AuxTechs.Add(tAux.ElectricSys, at0) 'Aux - Pneumatic System @@ -553,30 +539,30 @@ Public Class cDeclaration 'Skip Header file.ReadLine() + at0 = New List(Of String) Do While Not file.EndOfFile line = file.ReadLine + at0.Add(line(0)) AuxPower0 = New Dictionary(Of tMission, Single) i = 0 - For Each mt0 In SegmentTable.MissionList + For Each mt0 In SegmentTable.MissionList.Take(5) i += 1 AuxPower0.Add(mt0, line(i)) Next AuxPSpower.Add(line(0), AuxPower0) Loop + AuxTechs.Add(tAux.PneumSys, at0) + file.Close() Catch ex As Exception file.Close() GUImsg(tMsgID.Err, "Failed to load Declaration Config (Pneumatic system config)!" & ex.Message) Return False End Try - at0 = New List(Of String) - at0.Add("Default") - AuxTechs.Add(tAux.PneumSys, at0) - 'Default PT1 values lPT1nU = New List(Of Single) lPT1 = New List(Of Single) - PT1dim = -1 + PT1dim = - 1 If Not file.OpenRead(MyDeclPath & "PT1.csv") Then GUImsg(tMsgID.Err, "Failed to load Declaration Config (PT1 table)!") @@ -677,7 +663,7 @@ Public Class cDeclaration End Function Public Function EngInertia(Displ As Single) As Single - Return 1.3 + 0.41 + 0.27 * (Displ / 1000) + Return 1.3 + 0.41 + 0.27*(Displ/1000) End Function Public Function TracInt(Gearbox As tGearbox) As Single @@ -729,7 +715,7 @@ Public Class cDeclaration If Wheels.ContainsKey(Wheel) Then Return Wheels(Wheel).Inertia Else - Return -1 + Return - 1 End If End Function @@ -738,12 +724,12 @@ Public Class cDeclaration Dim w As cWheel If Not Wheels.ContainsKey(Wheel) Then - Return -1 + Return - 1 End If If Not Rims.ContainsKey(Rim) Then - Return -1 + Return - 1 End If w = Wheels(Wheel) @@ -754,12 +740,12 @@ Public Class cDeclaration F = Rims(Rim).Fb End If - Return (F * w.Diam) / (2 * Math.PI) + Return (F*w.Diam)/(2*Math.PI) End Function - Public ReadOnly Property WheelsList As Dictionary(Of String, cWheel).KeyCollection + Public ReadOnly Property WheelsList As String() Get - Return Wheels.Keys + Return Wheels.Keys.ToArray() End Get End Property @@ -823,9 +809,9 @@ Public Class cDeclaration CurrentMission = Missions(SegRef.Missions(CycleIndex)) - WHTCcorrFactor = CurrentMission.WHTCWF(tWHTCpart.Urban) * ENG.WHTCurban _ - + CurrentMission.WHTCWF(tWHTCpart.Rural) * ENG.WHTCrural _ - + CurrentMission.WHTCWF(tWHTCpart.Motorway) * ENG.WHTCmw + WHTCcorrFactor = CurrentMission.WHTCWF(tWHTCpart.Urban)*ENG.WHTCurban _ + + CurrentMission.WHTCWF(tWHTCpart.Rural)*ENG.WHTCrural _ + + CurrentMission.WHTCWF(tWHTCpart.Motorway)*ENG.WHTCmw If Not VEH.DeclInitCycle Then Return False @@ -851,8 +837,6 @@ Public Class cDeclaration Dim fS As Single Dim sl As Single() Dim Result As Boolean - Dim ESsum As Single - Dim EStech As String MsgSrc = "DeclInit" @@ -867,7 +851,7 @@ Public Class cDeclaration 'Fan Try - AuxPower.Add(sKey.AUX.Fan, AuxFanPower(VEC.AuxPaths(sKey.AUX.Fan).TechStr)(CurrentMission.MissionID) / 1000) + AuxPower.Add(sKey.AUX.Fan, AuxFanPower(VEC.AuxPaths(sKey.AUX.Fan).TechStr)(CurrentMission.MissionID)/1000) Catch ex As Exception WorkerMsg(tMsgID.Err, "Failed to initialise fan! " & ex.Message, MsgSrc) Result = False @@ -885,7 +869,7 @@ Public Class cDeclaration fF = sl(1) fB = sl(2) fS = sl(3) - AuxPower.Add(sKey.AUX.SteerPump, (U * fU + F * fF + B * fB + S * fS) / 1000) + AuxPower.Add(sKey.AUX.SteerPump, (U*fU + F*fF + B*fB + S*fS)/1000) Catch ex As Exception WorkerMsg(tMsgID.Err, "Failed to initialise steering pump! " & ex.Message, MsgSrc) Result = False @@ -893,7 +877,7 @@ Public Class cDeclaration 'HVAC Try - AuxPower.Add(sKey.AUX.HVAC, AuxHVACPower(SegRef.HDVclass)(CurrentMission.MissionID) / 1000) + AuxPower.Add(sKey.AUX.HVAC, AuxHVACPower(SegRef.HDVclass)(CurrentMission.MissionID)/1000) Catch ex As Exception WorkerMsg(tMsgID.Err, "Failed to initialise HVAC! " & ex.Message, MsgSrc) Result = False @@ -901,22 +885,8 @@ Public Class cDeclaration 'Electric System Try - - ESsum = AuxESbase(CurrentMission.MissionID) - - For Each EStech In VEC.EStechs - - If Not AuxESpower.ContainsKey(EStech) Then - WorkerMsg(tMsgID.Err, "Electric system '" & EStech & "' is not supported! ", MsgSrc) - Result = False - End If - - ESsum += AuxESpower(EStech)(CurrentMission.MissionID) - - Next - - AuxPower.Add(sKey.AUX.ElecSys, ESsum / (1000 * AuxESeff)) - + AuxPower.Add(sKey.AUX.ElecSys, + AuxESpower(VEC.AuxPaths(sKey.AUX.ElecSys).TechStr)(CurrentMission.MissionID)/(1000*AuxESeff)) Catch ex As Exception WorkerMsg(tMsgID.Err, "Failed to initialise electric system! " & ex.Message, MsgSrc) Result = False @@ -949,9 +919,9 @@ Public Class cDeclaration i += 1 Loop -lbInt: + lbInt: 'Interpolation - Return (nU - lPT1nU(i - 1)) * (lPT1(i) - lPT1(i - 1)) / (lPT1nU(i) - lPT1nU(i - 1)) + lPT1(i - 1) + Return (nU - lPT1nU(i - 1))*(lPT1(i) - lPT1(i - 1))/(lPT1nU(i) - lPT1nU(i - 1)) + lPT1(i - 1) End Function Public Sub ReportInit() @@ -967,7 +937,7 @@ lbInt: .JobFile = fFILE(JobFile, True) .DateStr = Now.ToString .Creator = Lic.LicString - .EngStr = (ENG.Displ / 1000).ToString("0.0") & " l " & Math.Round(ENG.Pmax, 0).ToString("#") & " kW" + .EngStr = (ENG.Displ/1000).ToString("0.0") & " l " & Math.Round(ENG.Pmax, 0).ToString("#") & " kW" .EngModelStr = ENG.ModelName .GbxStr = GBX.GearCount & "-Speed " & GearboxConv(GBX.gs_Type) .GbxModelStr = GBX.ModelName @@ -998,27 +968,27 @@ lbInt: For t = 0 To t1 sum += MODdata.Vh.V(t) Next - Vquer = 3.6 * sum / (t1 + 1) + Vquer = 3.6*sum/(t1 + 1) With lr - .Loading = VEH.Loading / 1000 + .Loading = VEH.Loading/1000 .Speed = Vquer - .FCkm = (100 * MODdata.FCavgFinal / Vquer) / (Cfg.FuelDens * 1000) - .CO2km = Cfg.CO2perFC * (MODdata.FCavgFinal / Vquer) + .FCkm = (100*MODdata.FCavgFinal/Vquer)/(Cfg.FuelDens*1000) + .CO2km = Cfg.CO2perFC*(MODdata.FCavgFinal/Vquer) If VEH.Loading > 0 Then - .FCtkm = .FCkm / .Loading - .CO2tkm = .CO2km / .Loading + .FCtkm = .FCkm/.Loading + .CO2tkm = .CO2km/.Loading End If .FCerror = MODdata.FCerror d = 0 MODdata.Vh.AltIntp(d, True) For t = 0 To t1 - .ActualSpeed.Add(MODdata.Vh.V(t) * 3.6) - .TargetSpeed.Add(MODdata.Vh.Vsoll(t) * 3.6) + .ActualSpeed.Add(MODdata.Vh.V(t)*3.6) + .TargetSpeed.Add(MODdata.Vh.Vsoll(t)*3.6) d += MODdata.Vh.V(t) - .Distance.Add(CSng(d / 1000)) + .Distance.Add(CSng(d/1000)) .Alt.Add(MODdata.Vh.AltIntp(d, False)) .nU.Add(MODdata.nU(t)) .Tq.Add(nPeToM(MODdata.nU(t), MODdata.Pe(t))) @@ -1103,7 +1073,7 @@ Public Class cSegmentTableEntry If BodyTrWeight.ContainsKey(Mission) AndAlso IsNumeric(BodyTrWeight(Mission)) Then Return CSng(BodyTrWeight(Mission)) Else - Return -1 + Return - 1 End If End Function @@ -1112,18 +1082,18 @@ Public Class cSegmentTableEntry 'Check if Config is valid If Loading.ContainsKey(Mission) Then If Not (Loading(Mission) = "f" OrElse IsNumeric(Loading(Mission))) Then - Return -1 + Return - 1 End If Else - Return -1 + Return - 1 End If 'Return Loading If HDVclass < 4 Then If Mission = tMission.LongHaul Then - Return 588.2 * MassMax - 2511.8 + Return 588.2*MassMax - 2511.8 Else - Return 394.1 * MassMax - 1705.9 + Return 394.1*MassMax - 1705.9 End If Else Return CSng(Loading(Mission)) @@ -1401,7 +1371,7 @@ Public Class cReport s.MarkerSize = 15 s.MarkerStyle = DataVisualization.Charting.MarkerStyle.Circle s.ChartType = DataVisualization.Charting.SeriesChartType.Point - i = -1 + i = - 1 For Each lr In mr.Results i += 1 s.Points.AddXY(lr.Value.Speed, lr.Value.CO2km) diff --git a/VectoCommon/VectoCommon/Exceptions/VectoExceptions.cs b/VectoCommon/VectoCommon/Exceptions/VectoExceptions.cs index 2fa74371cf429282d52cf85fb08df64808186476..78af81434680dbee319b865d4954aec8b70b046c 100644 --- a/VectoCommon/VectoCommon/Exceptions/VectoExceptions.cs +++ b/VectoCommon/VectoCommon/Exceptions/VectoExceptions.cs @@ -30,7 +30,6 @@ */ using System; -using System.IO; using System.Runtime.Serialization; using TUGraz.VectoCommon.Models; @@ -85,7 +84,6 @@ namespace TUGraz.VectoCommon.Exceptions { public InvalidFileFormatException(string message) : base(message) {} public InvalidFileFormatException(string message, params object[] args) : base(string.Format(message, args)) {} - public InvalidFileFormatException(string message, Exception inner) : base(message) {} } /// <summary> @@ -96,10 +94,6 @@ namespace TUGraz.VectoCommon.Exceptions { public UnsupportedFileVersionException(string message) : base(message) {} public UnsupportedFileVersionException(string message, Exception inner) : base(message, inner) {} - - public UnsupportedFileVersionException(string filename, int version, Exception inner = null) - : base(string.Format("Unsupported Version of {0} file. Got Version {1}", - Path.GetExtension(filename), version), inner) {} } /// <summary> diff --git a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs index d2234dc3054e1ed1bdcdef084314c55ff4b70fe4..2d9e2b64cff5737b5f7a057f90922c3478f11403 100644 --- a/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs +++ b/VectoCommon/VectoCommon/InputData/EngineeringInputData.cs @@ -221,7 +221,7 @@ namespace TUGraz.VectoCommon.InputData public interface IAuxiliariesEngineeringInputData { - new IList<IAuxiliaryEngineeringInputData> Auxiliaries { get; } + IList<IAuxiliaryEngineeringInputData> Auxiliaries { get; } // Advanced Auxiliaries AuxiliaryModel AuxiliaryAssembly { get; } diff --git a/VectoCommon/VectoCommon/Models/AuxiliaryType.cs b/VectoCommon/VectoCommon/Models/AuxiliaryType.cs index 4b0e57284524b03045422890c19892506bfc7466..79240f2b3d9a1e1767122819d79cb1ed07ac40db 100644 --- a/VectoCommon/VectoCommon/Models/AuxiliaryType.cs +++ b/VectoCommon/VectoCommon/Models/AuxiliaryType.cs @@ -29,8 +29,6 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System; - namespace TUGraz.VectoCommon.Models { public enum AuxiliaryType diff --git a/VectoCommon/VectoCommon/Utils/EnumHelper.cs b/VectoCommon/VectoCommon/Utils/EnumHelper.cs index ae34734bb61c823079c577cc6854f99e8c631a4a..965a26231e2bd5630a966f633ea885744baee819 100644 --- a/VectoCommon/VectoCommon/Utils/EnumHelper.cs +++ b/VectoCommon/VectoCommon/Utils/EnumHelper.cs @@ -32,8 +32,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; -using System.Text.RegularExpressions; namespace TUGraz.VectoCommon.Utils { @@ -41,29 +39,12 @@ namespace TUGraz.VectoCommon.Utils { public static T ParseEnum<T>(this string s, bool ignoreCase = true) { - return (T)Enum.Parse(typeof(T), Regex.Replace(s, @"\s+", ""), ignoreCase); + return (T)Enum.Parse(typeof(T), s.RemoveWhitespace(), ignoreCase); } public static IEnumerable<T> GetValues<T>() { return Enum.GetValues(typeof(T)).Cast<T>(); } - - private static readonly Dictionary<Type, Dictionary<Enum, string>> Names = - new Dictionary<Type, Dictionary<Enum, string>>(); - - [MethodImpl(MethodImplOptions.Synchronized)] - public static string AsString(this Enum e) - { - var t = e.GetType(); - if (!Names.ContainsKey(t)) { - Names[t] = new Dictionary<Enum, string> { { e, e.ToString() } }; - } - if (!Names[t].ContainsKey(e)) { - Names[t][e] = e.ToString(); - } - - return Names[t][e]; - } } } \ No newline at end of file diff --git a/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs b/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs index c03a7c3bea18ce5a927287cac01d87d2a7c4f657..ad25e2e9619801c032a4adf99e56123c42d058d5 100644 --- a/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs +++ b/VectoCommon/VectoCommon/Utils/EnumerableExtensionMethods.cs @@ -38,9 +38,9 @@ namespace TUGraz.VectoCommon.Utils { public static class EnumerableExtensionMethods { - public static IEnumerable<double> ToDouble(this IEnumerable<string> self) + public static IEnumerable<double> ToDouble(this IEnumerable<string> self, double? defaultValue = null) { - return self.Select(s => s.ToDouble()); + return self.Select(s => s.ToDouble(defaultValue)); } public static bool SequenceEqualFast<T>(this IEnumerable<T> self, IEnumerable<T> other) where T : IComparable diff --git a/VectoCommon/VectoCommon/Utils/SI.cs b/VectoCommon/VectoCommon/Utils/SI.cs index f8065a651c71ab7953801feace22287c927d87a8..a6c1005dc28ab9cf4abba773195dd19c5ffb7e7b 100644 --- a/VectoCommon/VectoCommon/Utils/SI.cs +++ b/VectoCommon/VectoCommon/Utils/SI.cs @@ -39,6 +39,8 @@ using System.Linq.Expressions; using System.Reflection; using TUGraz.VectoCommon.Exceptions; +// ReSharper disable ClassNeverInstantiated.Global + namespace TUGraz.VectoCommon.Utils { /// <summary> @@ -304,6 +306,18 @@ namespace TUGraz.VectoCommon.Utils return SIBase<KilogramPerSecond>.Create(kg.Val / second.Value()); } + [DebuggerHidden] + public static SI operator /(Kilogram kg, Joule j) + { + return (kg as SI) / j; + } + + [DebuggerHidden] + public static Scalar operator /(Kilogram kg, Kilogram kg2) + { + return SIBase<Scalar>.Create(kg.Val / kg2.Val); + } + [DebuggerHidden] public static KilogramPerMeter operator /(Kilogram kg, Meter m) { @@ -316,6 +330,18 @@ namespace TUGraz.VectoCommon.Utils return SIBase<Newton>.Create(kg.Val * m.Value()); } + [DebuggerHidden] + public static Kilogram operator *(Kilogram kg, double d) + { + return new Kilogram(kg.Val * d); + } + + [DebuggerHidden] + public static Kilogram operator *(double d, Kilogram kg) + { + return new Kilogram(d * kg.Val); + } + public static Liter operator /(Kilogram kilogram, KilogramPerCubicMeter kilogramPerCubicMeter) { return SIBase<Liter>.Create(kilogram.Value() / kilogramPerCubicMeter.Value() * 1000); @@ -779,16 +805,16 @@ namespace TUGraz.VectoCommon.Utils /// <typeparam name="T"></typeparam> public abstract class SIBase<T> : SI where T : SIBase<T> { - static T _zeroPrototype; + private static readonly T ZeroPrototype; static SIBase() { - var bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; + const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; var constructorInfo = typeof(T).GetConstructor(bindingFlags, null, new[] { typeof(double) }, null); var parameter = Expression.Parameter(typeof(double)); var lambda = Expression.Lambda<Func<double, T>>(Expression.New(constructorInfo, parameter), parameter); Constructor = lambda.Compile(); - _zeroPrototype = Constructor(0); + ZeroPrototype = Constructor(0); } /// <summary> @@ -802,19 +828,9 @@ namespace TUGraz.VectoCommon.Utils /// <param name="val">The value of the SI object.</param> public static T Create(double val) { - if (val == 0) { - return _zeroPrototype; - } - - return Constructor(val); + return val == 0 ? ZeroPrototype : Constructor(val); } - /// <summary> - /// Initializes a new instance of the <see cref="SIBase{T}"/> class. Is used by specialized sub classes. - /// </summary> - [DebuggerHidden] - protected SIBase(SI si) : base(si) {} - [DebuggerHidden] protected SIBase(double value) : base(value) {} @@ -830,9 +846,6 @@ namespace TUGraz.VectoCommon.Utils Denominator = denominator; } - [DebuggerHidden] - protected SIBase() {} - [DebuggerHidden] public new T Abs() { @@ -1000,7 +1013,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// The basic scalar value of the SI. /// </summary> - protected double Val; + protected readonly double Val; /// <summary> /// The denominator of the SI. @@ -1016,18 +1029,18 @@ namespace TUGraz.VectoCommon.Utils /// The current exponent for conversion operations (Square, Cubic, Linear, e.g. new SI(3).Square.Meter). /// Can be reseted with Reset, Per, Cast. /// </summary> - protected readonly int Exponent; + private readonly int _exponent; /// <summary> /// A flag indicating if the current SI is in reciprocal mode (used in the <see cref="Per"/> method for reciprocal units: e.g. new SI(2).Meter.Per.Second) ==> [m/s] /// Can be reseted with Reset, Per, Cast. /// </summary> - protected readonly bool Reciproc; + private readonly bool _reciproc; /// <summary> /// A flag indicating if the current SI is in reverse mode (used for conversions: e.g. new SI(2).Rounds.Per.Minute.ConverTo.Radian.Per.Second ==> [rpm/min] => [rad/s]). /// </summary> - protected readonly bool Reverse; + private readonly bool _reverse; /// <summary> /// Enum for defining the Units. @@ -1041,7 +1054,6 @@ namespace TUGraz.VectoCommon.Utils g, W, N, - Percent, min, c, d, @@ -1063,11 +1075,11 @@ namespace TUGraz.VectoCommon.Utils public SI(double val = 0.0) { Val = val; - Reciproc = false; - Reverse = false; + _reciproc = false; + _reverse = false; Numerator = new Unit[0]; Denominator = new Unit[0]; - Exponent = 1; + _exponent = 1; if (double.IsNaN(Val)) { throw new VectoException("NaN [{0}] is not allowed for SI-Values in Vecto.", GetUnitString()); @@ -1092,9 +1104,9 @@ namespace TUGraz.VectoCommon.Utils bool reverse = false, int exponent = 1) { Val = val; - Reciproc = reciproc; - Reverse = reverse; - Exponent = exponent; + _reciproc = reciproc; + _reverse = reverse; + _exponent = exponent; var tmpDenominator = denominator.ToList(); Numerator = numerator.Where(n => !tmpDenominator.Remove(n)).ToArray(); @@ -1115,7 +1127,7 @@ namespace TUGraz.VectoCommon.Utils /// <param name="val">The value.</param> /// <param name="unit">The unit.</param> [DebuggerHidden] - protected SI(double val, SI unit) : this(val, unit.Numerator, unit.Denominator) {} + private SI(double val, SI unit) : this(val, unit.Numerator, unit.Denominator) {} [DebuggerHidden] protected SI(SI si, double? factor = null, Unit? fromUnit = null, Unit? toUnit = null, @@ -1125,12 +1137,12 @@ namespace TUGraz.VectoCommon.Utils var denominator = si.Numerator.ToList(); Val = si.Val; - Reciproc = reciproc ?? si.Reciproc; - Reverse = reverse ?? si.Reverse; - Exponent = exponent ?? si.Exponent; + _reciproc = reciproc ?? si._reciproc; + _reverse = reverse ?? si._reverse; + _exponent = exponent ?? si._exponent; // if reverse mode then swap fromUnit and toUnit and invert factor. - if (Reverse) { + if (_reverse) { var tmp = fromUnit; fromUnit = toUnit; toUnit = tmp; @@ -1138,8 +1150,8 @@ namespace TUGraz.VectoCommon.Utils } // add the unit as often as is defined by the exponent. - for (var i = 0; i < Exponent; i++) { - if (!Reciproc) { + for (var i = 0; i < _exponent; i++) { + if (!_reciproc) { UpdateUnit(fromUnit, toUnit, denominator); if (factor.HasValue) { Val *= factor.Value; @@ -1175,7 +1187,7 @@ namespace TUGraz.VectoCommon.Utils [DebuggerHidden] private void UpdateUnit(Unit? fromUnit, Unit? toUnit, ICollection<Unit> units) { - if (Reverse && fromUnit.HasValue) { + if (_reverse && fromUnit.HasValue) { if (units.Contains(fromUnit.Value)) { units.Remove(fromUnit.Value); } else { @@ -1357,7 +1369,7 @@ namespace TUGraz.VectoCommon.Utils [DebuggerHidden] public SI Per { - [DebuggerHidden] get { return new SI(Linear, reciproc: !Reciproc); } + [DebuggerHidden] get { return new SI(Linear, reciproc: !_reciproc); } } /// <summary> @@ -1947,7 +1959,7 @@ namespace TUGraz.VectoCommon.Utils /// <returns> /// A <see cref="System.String" /> that represents this instance. /// </returns> - public virtual string ToString(string format) + private string ToString(string format) { if (string.IsNullOrEmpty(format)) { format = "F4"; @@ -2245,7 +2257,7 @@ namespace TUGraz.VectoCommon.Utils /// <param name="outputFactor">The output factor.</param> /// <param name="showUnit">The show unit.</param> /// <returns></returns> - public virtual string ToOutputFormat(uint? decimals = null, double? outputFactor = null, bool? showUnit = null) + public string ToOutputFormat(uint? decimals = null, double? outputFactor = null, bool? showUnit = null) { decimals = decimals ?? 4; outputFactor = outputFactor ?? 1.0; diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index c382a404ed04b50fedfee16a3f69f67dda2e70a4..ad28b8f6fa686c88435b04f62a2adc3d6a380d84 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -29,13 +29,13 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; -using Newtonsoft.Json.Linq; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; @@ -52,8 +52,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON { private string _basePath; - protected JObject Header; - protected JObject Body; + protected readonly JObject Header; + protected readonly JObject Body; protected JSONFile(JObject data, string filename) { @@ -62,11 +62,6 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON BasePath = filename; } - public int FileVersion - { - get { return Header.GetEx(JsonKeys.JsonHeader_FileVersion).Value<int>(); } - } - public bool SavedInDeclarationMode { get { return Body.GetEx(JsonKeys.SavedInDeclMode).Value<bool>(); } @@ -85,7 +80,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON return VectoCSVFile.Read(Path.Combine(BasePath, filename), true); } catch (Exception e) { Log.Warn("Failed to read file {0} {1}", Path.Combine(BasePath, filename), tableType); - throw new VectoException(string.Format("Failed to read file for {0}: {1}", tableType, filename), e); + throw new VectoException("Failed to read file for {0}: {1}", e, tableType, filename); } } if (required) { @@ -110,13 +105,13 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON IEngineeringJobInputData, IDriverEngineeringInputData, IAuxiliariesEngineeringInputData, IAuxiliariesDeclarationInputData { - protected IGearboxEngineeringInputData Gearbox; - protected IAxleGearInputData AxleGear; - protected ITorqueConverterEngineeringInputData TorqueConverter; - public IAngularGearInputData AngularGear; - protected IEngineEngineeringInputData Engine; - protected IVehicleEngineeringInputData VehicleData; - protected IRetarderInputData Retarder; + protected readonly IGearboxEngineeringInputData Gearbox; + protected readonly IAxleGearInputData AxleGear; + protected readonly ITorqueConverterEngineeringInputData TorqueConverter; + protected readonly IAngularGearInputData AngularGear; + protected readonly IEngineEngineeringInputData Engine; + protected readonly IVehicleEngineeringInputData VehicleData; + protected readonly IRetarderInputData Retarder; private readonly string _jobname; @@ -128,13 +123,22 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON if (!EmptyOrInvalidFileName(gearboxFile)) { Gearbox = JSONInputDataFactory.ReadGearbox(Path.Combine(BasePath, gearboxFile)); } - AxleGear = Gearbox as IAxleGearInputData; TorqueConverter = Gearbox as ITorqueConverterEngineeringInputData; + } catch (Exception e) { + throw new VectoException("JobFile: Failed to read Gearbox file '{0}': {1}", e, Body[JsonKeys.Vehicle_GearboxFile], + e.Message); + } + try { Engine = JSONInputDataFactory.ReadEngine( Path.Combine(BasePath, Body.GetEx(JsonKeys.Vehicle_EngineFile).Value<string>())); + } catch (Exception e) { + throw new VectoException("JobFile: Failed to read Engine file '{0}': {1}", e, Body[JsonKeys.Vehicle_EngineFile], + e.Message); + } + try { var vehicleFile = Body.GetEx(JsonKeys.Vehicle_VehicleFile).Value<string>(); if (!EmptyOrInvalidFileName(vehicleFile)) { VehicleData = JSONInputDataFactory.ReadJsonVehicle( @@ -143,7 +147,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON AngularGear = VehicleData as IAngularGearInputData; } } catch (Exception e) { - throw new VectoException("Failed to read input data: {0}", e, e.Message); + throw new VectoException("JobFile: Failed to read Vehicle file '{0}': {1}", e, Body[JsonKeys.Vehicle_VehicleFile], + e.Message); } var retarder = VehicleData as IRetarderInputData; if (retarder != null) { @@ -461,18 +466,81 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON get { return AuxData().Cast<IAuxiliaryDeclarationInputData>().ToList(); } } - private IList<AuxiliaryDataInputData> AuxData() + protected virtual IList<AuxiliaryDataInputData> AuxData() { var retVal = new List<AuxiliaryDataInputData>(); foreach (var aux in Body["Aux"] ?? Enumerable.Empty<JToken>()) { + var type = (AuxiliaryType)0; + try { + type = AuxiliaryTypeHelper.Parse(aux.GetEx<string>("Type")); + } catch (ArgumentOutOfRangeException) {} + var auxData = new AuxiliaryDataInputData { ID = aux.GetEx<string>("ID"), - Type = AuxiliaryTypeHelper.Parse(aux.GetEx<string>("Type")), - Technology = new List<string>() { aux.GetEx<string>("Technology") }, + Type = type, + Technology = new List<string>(), }; - //if (aux["TechList"] != null) { - // auxData.TechList = aux["TechList"].Select(x => x.ToString()).ToList(); // .Select(x => x.ToString).ToArray(); - //} + var tech = aux.GetEx<string>("Technology"); + + // Convert old Electric System to new format + if (auxData.Type == AuxiliaryType.ElectricSystem) { + if (aux["TechList"] == null || aux["TechList"].Any()) { + auxData.Technology.Add("Standard technology"); + Log.Warn("Aux: Upgraded Electric System to new format: '{0}'", auxData.Technology.Last()); + } else { + auxData.Technology.Add("Standard technology - LED headlights, all"); + Log.Warn("Aux: Upgraded Electric System to new format: '{0}'", auxData.Technology.Last()); + } + } + + // Convert old Steering Pump to new format + if (auxData.Type == AuxiliaryType.SteeringPump) { + switch (tech) { + case "Variable displacement": + auxData.Technology.Add("Variable displacement elec. controlled"); + Log.Warn("Aux: Upgraded Steering Pump Technology from '{0}' to '{1}'", tech, auxData.Technology.Last()); + + break; + case "Hydraulic supported by electric": + auxData.Technology.Add("Dual displacement"); + Log.Warn("Aux: Upgraded Steering Pump Technology from '{0}' to '{1}'", tech, auxData.Technology.Last()); + break; + default: + auxData.Technology.Add(tech); + break; + } + } + + // Convert old Pneumatic System to new format + if (auxData.Type == AuxiliaryType.PneumaticSystem) { + auxData.Technology.Add("Medium Supply 1-stage"); + Log.Warn("Aux: Upgraded Pneumatic System Technology to '{0}'", tech, auxData.Technology.Last()); + } + + // Convert old HVAC to new format + if (auxData.Type == AuxiliaryType.HVAC) { + if (!string.IsNullOrWhiteSpace(tech)) { + Log.Warn("Aux: Upgraded HVAC Technology from '{0}' to '{1}'", tech, ""); + } + } + + if (auxData.Type == AuxiliaryType.Fan) { + switch (tech) { + case "Crankshaft mounted - Electronically controlled visco clutch (Default)": + auxData.Technology.Add("Crankshaft mounted - Electronically controlled visco clutch"); + break; + case "Crankshaft mounted - On/Off clutch": + auxData.Technology.Add("Crankshaft mounted - On/off clutch"); + break; + case "Belt driven or driven via transm. - On/Off clutch": + auxData.Technology.Add("Belt driven or driven via transm. - On/off clutch"); + break; + default: + auxData.Technology.Add(tech); + break; + } + } + var auxFile = aux["Path"]; retVal.Add(auxData); @@ -518,4 +586,50 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON #endregion } + + public class JSONInputDataV3 : JSONInputDataV2 + { + public JSONInputDataV3(JObject data, string filename) : base(data, filename) {} + + protected override IList<AuxiliaryDataInputData> AuxData() + { + var retVal = new List<AuxiliaryDataInputData>(); + foreach (var aux in Body["Aux"] ?? Enumerable.Empty<JToken>()) { + try { + aux.GetEx("Technology").ToObject<List<string>>(); + } catch (Exception) { + throw new VectoException( + "Aux: Technology for aux '{0}' list could not be read. Maybe it is a single string instead of a list of strings?", + aux.GetEx<string>("ID")); + } + + var type = (AuxiliaryType)0; + try { + type = AuxiliaryTypeHelper.Parse(aux.GetEx<string>("Type")); + } catch (ArgumentOutOfRangeException) {} + + var auxData = new AuxiliaryDataInputData { + ID = aux.GetEx<string>("ID"), + Type = type, + Technology = aux.GetEx("Technology").ToObject<List<string>>() + }; + + var auxFile = aux["Path"]; + retVal.Add(auxData); + + if (auxFile == null || EmptyOrInvalidFileName(auxFile.Value<string>())) { + continue; + } + var stream = new StreamReader(Path.Combine(BasePath, auxFile.Value<string>())); + stream.ReadLine(); // skip header "Transmission ration to engine rpm [-]" + auxData.TransmissionRatio = stream.ReadLine().IndulgentParse(); + stream.ReadLine(); // skip header "Efficiency to engine [-]" + auxData.EfficiencyToEngine = stream.ReadLine().IndulgentParse(); + stream.ReadLine(); // skip header "Efficiency auxiliary to supply [-]" + auxData.EfficiencyToSupply = stream.ReadLine().IndulgentParse(); + auxData.DemandMap = VectoCSVFile.ReadStream(new MemoryStream(Encoding.UTF8.GetBytes(stream.ReadToEnd()))); + } + return retVal; + } + } } \ No newline at end of file diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs index 13b6c4183087e5b5bdfc58c99db85a6e212b4ded..c5bfc3d12a13085a2163d3c05da8eb3b830fc098 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputDataFactory.cs @@ -29,18 +29,18 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.IO; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using System.IO; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; namespace TUGraz.VectoCore.InputData.FileIO.JSON { // ReSharper disable once InconsistentNaming - public class JSONInputDataFactory + public static class JSONInputDataFactory { - protected internal static JObject ReadFile(string fileName) + internal static JObject ReadFile(string fileName) { if (!File.Exists(fileName)) { throw new FileNotFoundException("failed to load file: " + fileName, fileName); @@ -57,6 +57,8 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON switch (version) { case 2: return new JSONInputDataV2(json, filename); + case 3: + return new JSONInputDataV3(json, filename); default: throw new VectoException("Job-File: Unsupported FileVersion. Got: {0} ", version); } diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs index 6263b3a1eef2d730a0472127c4a45c88377274e5..6e2da668579e917d7b163eba6fcb4dc03103ad2f 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONVehicleData.cs @@ -150,17 +150,13 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON get { var retarderType = Body.GetEx(JsonKeys.Vehicle_Retarder).GetEx<string>(JsonKeys.Vehicle_Retarder_Type); - try { - return retarderType.ParseEnum<RetarderType>(); - } catch (Exception) { - switch (retarderType.ToLower()) { - case "primary": - return RetarderType.TransmissionInputRetarder; - case "secondary": - return RetarderType.TransmissionOutputRetarder; - default: - throw new VectoException("Unknown retarder type {0}", retarderType); - } + switch (retarderType.ToLowerInvariant()) { + case "primary": + return RetarderType.TransmissionInputRetarder; + case "secondary": + return RetarderType.TransmissionOutputRetarder; + default: + return retarderType.ParseEnum<RetarderType>(); } } } diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/AuxiliaryDataReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/AuxiliaryDataReader.cs index 83aef8d8b764730a22698e01a1d0a5c43d776b79..c99c624a8e2cbfe5d2484c225bc691ac287c5bd9 100644 --- a/VectoCore/VectoCore/InputData/Reader/ComponentData/AuxiliaryDataReader.cs +++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/AuxiliaryDataReader.cs @@ -34,7 +34,6 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData var map = ReadAuxMap(id, table); return new AuxiliaryData(transmissionRatio, efficiencyToEngine, efficiencyToSupply, map); - ; } catch (FileNotFoundException e) { throw new VectoException("Auxiliary file not found: " + fileName, e); } @@ -53,7 +52,6 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData return map; } - private static void FillFromColumnIndizes(DataTable table, DelaunayMap map) { var data = table.Rows.Cast<DataRow>().Select(row => new { diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/AbstractSimulationDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/AbstractSimulationDataAdapter.cs index f56729d5cc01f2781208f27c2ef93f1bdce9cc02..850d530fb75115268510ca6c32dabfa716b89d1c 100644 --- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/AbstractSimulationDataAdapter.cs +++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/AbstractSimulationDataAdapter.cs @@ -32,7 +32,6 @@ using System; using System.Collections.Generic; using System.Linq; -using iTextSharp.text.pdf; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; @@ -40,7 +39,6 @@ using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; -using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter { @@ -62,21 +60,13 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter VehicleCategory = data.VehicleCategory, AxleConfiguration = data.AxleConfiguration, CurbWeight = data.CurbWeightChassis, - //CurbWeigthExtra = data.CurbWeightExtra.SI<Kilogram>(), - //Loading = data.Loading.SI<Kilogram>(), GrossVehicleWeight = data.GrossVehicleMassRating, - //DragCoefficient = data.DragCoefficient, - //CrossSectionArea = data.CrossSectionArea.SI<SquareMeter>(), - //DragCoefficientRigidTruck = data.DragCoefficientRigidTruck, - //CrossSectionAreaRigidTruck = data.CrossSectionAreaRigidTruck.SI<SquareMeter>(), - //TyreRadius = data.TyreRadius.SI().Milli.Meter.Cast<Meter>(), - //Rim = data.Rim, }; return retVal; } - internal RetarderData SetCommonRetarderData(IRetarderInputData data, IVehicleDeclarationInputData vehicle) + internal RetarderData SetCommonRetarderData(IRetarderInputData data) { try { var retarder = new RetarderData { @@ -184,11 +174,14 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter var type = AngularGearType.None; try { type = data.Type; - } catch (Exception) { + } catch (InvalidFileFormatException) { Log.Info("AngularGear not found. Assuming None."); } switch (type) { + case AngularGearType.LossesIncludedInGearbox: + case AngularGearType.None: + return null; case AngularGearType.SeparateAngularGear: var angularGear = new AngularGearData { SavedInDeclarationMode = data.SavedInDeclarationMode, @@ -214,10 +207,6 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter } } return angularGear; - - case AngularGearType.LossesIncludedInGearbox: - case AngularGearType.None: - return null; default: throw new ArgumentOutOfRangeException("data", "Unknown Angulargear Type."); } @@ -230,7 +219,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter /// Intersects full load curves. /// </summary> /// <param name="engineCurve"></param> - /// <param name="gearCurve"></param> + /// <param name="maxTorque"></param> /// <returns>A combined EngineFullLoadCurve with the minimum full load torque over all inputs curves.</returns> internal static EngineFullLoadCurve IntersectFullLoadCurves(EngineFullLoadCurve engineCurve, NewtonMeter maxTorque) { diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs index a97cef888cc604392d393cfa5b0a71224b2fef6c..f91cea32aa1b5928647c23054a67989349e8b4de 100644 --- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs +++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/DeclarationDataAdapter.cs @@ -42,9 +42,7 @@ using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; -using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.Utils; -using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData; namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter { @@ -98,7 +96,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter retVal.CurbWeight += mission.BodyCurbWeight + mission.TrailerCurbWeight; retVal.Loading = loading; retVal.DynamicTyreRadius = - DeclarationData.DynamicTyreRadius(data.Axles[DeclarationData.PoweredAxle()].Wheels, "5° DC Rims"); // TODO! + DeclarationData.DynamicTyreRadius(data.Axles[DeclarationData.PoweredAxle()].Wheels); // TODO! var aerodynamicDragArea = data.AirDragArea + mission.DeltaCdA; @@ -108,7 +106,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter var axles = data.Axles; if (axles.Count < mission.AxleWeightDistribution.Length) { throw new VectoException("Vehicle does not contain sufficient axles. {0} axles defined, {1} axles required", - data.Axles.Count, mission.AxleWeightDistribution.Count()); + data.Axles.Count, mission.AxleWeightDistribution.Length); } var axleData = new List<Axle>(); for (var i = 0; i < mission.AxleWeightDistribution.Length; i++) { @@ -254,7 +252,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter aux.ID = Constants.Auxiliaries.IDs.Fan; break; case AuxiliaryType.SteeringPump: - aux.PowerDemand = DeclarationData.SteeringPump.Lookup(mission, hvdClass, auxData.Technology.First()); + aux.PowerDemand = DeclarationData.SteeringPump.Lookup(mission, hvdClass, auxData.Technology); aux.ID = Constants.Auxiliaries.IDs.SteeringPump; break; case AuxiliaryType.HVAC: @@ -262,14 +260,12 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter aux.ID = Constants.Auxiliaries.IDs.HeatingVentilationAirCondition; break; case AuxiliaryType.PneumaticSystem: - aux.PowerDemand = DeclarationData.PneumaticSystem.Lookup(mission, hvdClass); + aux.PowerDemand = DeclarationData.PneumaticSystem.Lookup(mission, auxData.Technology.First()); aux.ID = Constants.Auxiliaries.IDs.PneumaticSystem; break; case AuxiliaryType.ElectricSystem: - //aux.PowerDemand = DeclarationData.ElectricSystem.Lookup(mission, - // auxData.TechList.DefaultIfNull(Enumerable.Empty<string>()).ToArray()); + aux.PowerDemand = DeclarationData.ElectricSystem.Lookup(mission, auxData.Technology.First()); aux.ID = Constants.Auxiliaries.IDs.ElectricSystem; - //aux.TechList = auxData.TechList.DefaultIfNull(Enumerable.Empty<string>()).ToArray(); break; default: continue; @@ -284,9 +280,9 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter Log.Warn("{0} not in Declaration Mode!", inputData); } - public RetarderData CreateRetarderData(IRetarderInputData retarder, IVehicleDeclarationInputData vehicle) + public RetarderData CreateRetarderData(IRetarderInputData retarder) { - return SetCommonRetarderData(retarder, vehicle); + return SetCommonRetarderData(retarder); } public static List<CrossWindCorrectionCurveReader.CrossWindCorrectionEntry> GetDeclarationAirResistanceCurve( @@ -312,11 +308,9 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter var cdASum = 0.0.SI<SquareMeter>(); for (var alpha = 0; alpha <= maxAlpha; alpha += alphaStep) { - var vWindX = Physics.BaseWindSpeed * Math.Cos(alpha.ToRadian()); - var vWindY = Physics.BaseWindSpeed * Math.Sin(alpha.ToRadian()); - var vAirX = vVeh + vWindX; - var vAirY = vWindY; - var beta = Math.Atan((vAirY / vAirX).Value()).ToDegree(); + var vAirX = vVeh + Physics.BaseWindSpeed * Math.Cos(alpha.ToRadian()); + var vAirY = Physics.BaseWindSpeed * Math.Sin(alpha.ToRadian()); + var beta = Math.Atan(vAirY / vAirX).ToDegree(); var deltaCdA = ComputeDeltaCd(beta, values); var cdA = aerodynamicDragAera + deltaCdA; @@ -337,7 +331,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter return points; } - protected static SquareMeter ComputeDeltaCd(double beta, AirDrag.AirDragEntry values) + protected static SquareMeter ComputeDeltaCd(double beta, AirDrag.Entry values) { return (values.A1 * beta + values.A2 * beta * beta + values.A3 * beta * beta * beta).SI<SquareMeter>(); } diff --git a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs index 42d08bd4dc63366350c6a142eff41b6c2953d7ac..e95e96e88c7b4b5310cbb640e3a2505276c5d744 100644 --- a/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs +++ b/VectoCore/VectoCore/InputData/Reader/DataObjectAdapter/EngineeringDataAdapter.cs @@ -42,7 +42,6 @@ using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; -using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter { @@ -256,7 +255,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter //================================= public RetarderData CreateRetarderData(IRetarderInputData retarder, IVehicleEngineeringInputData vehicle) { - return SetCommonRetarderData(retarder, vehicle); + return SetCommonRetarderData(retarder); } public AdvancedAuxData CreateAdvancedAuxData(IAuxiliariesEngineeringInputData auxInputData) diff --git a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeVectoRunDataFactory.cs b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeVectoRunDataFactory.cs index a2da101383dea4ee7effe178661d77d56bcbe654..a14ddc6b9315b95feaec4a9bf82895bbcfd46f2a 100644 --- a/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeVectoRunDataFactory.cs +++ b/VectoCore/VectoCore/InputData/Reader/Impl/DeclarationModeVectoRunDataFactory.cs @@ -75,7 +75,7 @@ namespace TUGraz.VectoCore.InputData.Reader.Impl var angularGearData = dao.CreateAngularGearData(InputDataProvider.AngularGearInputData, false); var gearboxData = dao.CreateGearboxData(InputDataProvider.GearboxInputData, engineData, axlegearData.AxleGear.Ratio, tempVehicle.DynamicTyreRadius, false); - var retarderData = dao.CreateRetarderData(InputDataProvider.RetarderInputData, InputDataProvider.VehicleInputData); + var retarderData = dao.CreateRetarderData(InputDataProvider.RetarderInputData); if (Report != null) { var powertrainConfig = new VectoRunData() { diff --git a/VectoCore/VectoCore/Models/Connector/Ports/ITnPort.cs b/VectoCore/VectoCore/Models/Connector/Ports/ITnPort.cs index 56f01f368077fd01b963ade06020dd74e4434a06..644c450c3932772ab551a629caef60acb38e98e2 100644 --- a/VectoCore/VectoCore/Models/Connector/Ports/ITnPort.cs +++ b/VectoCore/VectoCore/Models/Connector/Ports/ITnPort.cs @@ -42,7 +42,6 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// <summary> /// Returns the inport to connect it to another outport. /// </summary> - /// <returns></returns> ITnInPort InPort(); } @@ -54,14 +53,9 @@ namespace TUGraz.VectoCore.Models.Connector.Ports /// <summary> /// Returns the outport to send requests to. /// </summary> - /// <returns></returns> ITnOutPort OutPort(); } - - //======================================================================== - - /// <summary> /// Defines a connect method to connect the inport to an outport. /// </summary> diff --git a/VectoCore/VectoCore/Models/Declaration/AirDrag.cs b/VectoCore/VectoCore/Models/Declaration/AirDrag.cs index 119d3bf3d44e59d7c49d8fb7c5926f2f053aaa89..aae5c0b90673d82f317b0fe71f1e1f617c27e107 100644 --- a/VectoCore/VectoCore/Models/Declaration/AirDrag.cs +++ b/VectoCore/VectoCore/Models/Declaration/AirDrag.cs @@ -37,25 +37,26 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public sealed class AirDrag : LookupData<string, AirDrag.AirDragEntry> + public sealed class AirDrag : LookupData<string, AirDrag.Entry> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VCDV.parameters.csv"; + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VCDV.parameters.csv"; } + } - public AirDrag() + protected override string ErrorMessage { - ParseData(ReadCsvResource(ResourceId)); + get { return "AirDrag Lookup Error: no value found. Key: '{0}'"; } } protected override void ParseData(DataTable table) { - Data = table.Rows.Cast<DataRow>().ToDictionary(row => row.Field<string>("Parameters"), row => new AirDragEntry { - A1 = row.ParseDouble("a1"), - A2 = row.ParseDouble("a2"), - A3 = row.ParseDouble("a3") - }); + Data = table.Rows.Cast<DataRow>().ToDictionary( + row => row.Field<string>("Parameters"), + row => new Entry(row.ParseDouble("a1"), row.ParseDouble("a2"), row.ParseDouble("a3"))); } - public AirDragEntry Lookup(VehicleCategory category) + public Entry Lookup(VehicleCategory category) { switch (category) { case VehicleCategory.CityBus: @@ -71,39 +72,17 @@ namespace TUGraz.VectoCore.Models.Declaration } } - public class AirDragEntry + public class Entry { - public double A1 { get; set; } - public double A2 { get; set; } - public double A3 { get; set; } - - protected bool Equals(AirDragEntry other) - { - return A1.Equals(other.A1) && A2.Equals(other.A2) && A3.Equals(other.A3); - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) { - return false; - } - if (ReferenceEquals(this, obj)) { - return true; - } - if (obj.GetType() != GetType()) { - return false; - } - return Equals((AirDragEntry)obj); - } + public double A1; + public double A2; + public double A3; - public override int GetHashCode() + public Entry(double a1, double a2, double a3) { - unchecked { - var hashCode = A1.GetHashCode(); - hashCode = (hashCode * 397) ^ A2.GetHashCode(); - hashCode = (hashCode * 397) ^ A3.GetHashCode(); - return hashCode; - } + A1 = a1; + A2 = a2; + A3 = a3; } } } diff --git a/VectoCore/VectoCore/Models/Declaration/AuxiliaryTypeHelper.cs b/VectoCore/VectoCore/Models/Declaration/AuxiliaryTypeHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..31a73f78d5bcd38017592d788635af74350649ee --- /dev/null +++ b/VectoCore/VectoCore/Models/Declaration/AuxiliaryTypeHelper.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCore.Configuration; + +namespace TUGraz.VectoCore.Models.Declaration +{ + public static class AuxiliaryTypeHelper + { + private static readonly Dictionary<AuxiliaryType, string> AuxToStr = new Dictionary<AuxiliaryType, string> { + { AuxiliaryType.Fan, Constants.Auxiliaries.Names.Fan }, + { AuxiliaryType.SteeringPump, Constants.Auxiliaries.Names.SteeringPump }, + { AuxiliaryType.HVAC, Constants.Auxiliaries.Names.HeatingVentilationAirCondition }, + { AuxiliaryType.PneumaticSystem, Constants.Auxiliaries.Names.PneumaticSystem }, + { AuxiliaryType.ElectricSystem, Constants.Auxiliaries.Names.ElectricSystem }, + }; + + private static readonly Dictionary<string, AuxiliaryType> StrToAux = AuxToStr.ToDictionary(kv => kv.Value, + kv => kv.Key); + + public static AuxiliaryType Parse(string s) + { + AuxiliaryType aux; + if (StrToAux.TryGetValue(s, out aux)) + return aux; + + throw new ArgumentOutOfRangeException("s", s, "Could not parse auxiliary type string."); + } + + public static string ToString(AuxiliaryType t) + { + return AuxToStr[t]; + } + } +} \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs index 592758e8df095caff2c199e4261277f5a0382581..bfdba25f3f0eee7f1116fced90f0fa929d68e27b 100644 --- a/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs +++ b/VectoCore/VectoCore/Models/Declaration/DeclarationData.cs @@ -32,14 +32,11 @@ using System; using System.Collections.Generic; using System.Linq; -using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; -using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { @@ -47,7 +44,6 @@ namespace TUGraz.VectoCore.Models.Declaration { private static DeclarationData _instance; private Segments _segments; - private Rims _rims; private Wheels _wheels; private PT1 _pt1; private ElectricSystem _electricSystem; @@ -57,7 +53,6 @@ namespace TUGraz.VectoCore.Models.Declaration private SteeringPump _steeringPump; private WHTCCorrection _whtcCorrection; private AirDrag _airDrag; - private TorqueConverter _torqueConverter; private StandardBodies _standardBodies; private Payloads _payloads; @@ -66,11 +61,6 @@ namespace TUGraz.VectoCore.Models.Declaration get { return Instance()._wheels ?? (Instance()._wheels = new Wheels()); } } - public static Rims Rims - { - get { return Instance()._rims ?? (Instance()._rims = new Rims()); } - } - public static Segments Segments { get { return Instance()._segments ?? (Instance()._segments = new Segments()); } @@ -91,19 +81,10 @@ namespace TUGraz.VectoCore.Models.Declaration get { return Instance()._electricSystem ?? (Instance()._electricSystem = new ElectricSystem()); } } - public static Meter DynamicTyreRadius(string wheels, string rims) + public static Meter DynamicTyreRadius(string wheels) { var wheelsEntry = Wheels.Lookup(wheels.RemoveWhitespace()); - try { - var rimsEntry = Rims.Lookup(rims); - - var correction = wheelsEntry.SizeClass != "a" ? rimsEntry.F_b : rimsEntry.F_a; - - return wheelsEntry.DynamicTyreRadius * correction / (2 * Math.PI); - } catch (KeyNotFoundException) { - throw new VectoException( - "Calculating Dynamic Tyre Radius not possible: Declaration Lookup could not find Key '{0}' for rim.", rims); - } + return wheelsEntry.DynamicTyreRadius * wheelsEntry.CircumferenceFactor / (2 * Math.PI); } /// <summary> @@ -164,11 +145,6 @@ namespace TUGraz.VectoCore.Models.Declaration get { return Instance()._airDrag ?? (Instance()._airDrag = new AirDrag()); } } - public static TorqueConverter TorqueConverter - { - get { return Instance()._torqueConverter ?? (Instance()._torqueConverter = new TorqueConverter()); } - } - public static int PoweredAxle() { return 1; @@ -179,30 +155,12 @@ namespace TUGraz.VectoCore.Models.Declaration return _instance ?? (_instance = new DeclarationData()); } - // Public Const SSspeed As Single = 5 - //Public Const SStime As Single = 5 - //Public Const SSdelay As Single = 5 - //Public Const LACa As Single = -0.5 - //Public Const LACvmin As Single = 50 - //Public Const Overspeed As Single = 5 - //Public Const Underspeed As Single = 5 - //Public Const ECvmin As Single = 50 - - //Public Const AirDensity As Single = 1.188 - //Public Const FuelDens As Single = 0.832 - //Public Const CO2perFC As Single = 3.16 - - //Public Const AuxESeff As Single = 0.7 - public static class Driver { public static class LookAhead { public const bool Enabled = true; - //public static readonly MeterPerSquareSecond Deceleration = -0.5.SI<MeterPerSquareSecond>(); - //public static readonly MeterPerSecond MinimumSpeed = 50.KMPHtoMeterPerSecond(); - public const double DecisionFactorCoastingOffset = 2.5; public const double DecisionFactorCoastingScaling = 1.5; public const double LookAheadDistanceFactor = 10; @@ -258,8 +216,8 @@ namespace TUGraz.VectoCore.Models.Declaration public static readonly KilogramSquareMeter Inertia = 0.SI<KilogramSquareMeter>(); public static readonly MeterPerSecond TruckMaxAllowedSpeed = 85.KMPHtoMeterPerSecond(); - public static double ShiftPolygonRPMMargin = 7; - private static double ShiftPolygonEngineFldMargin = 0.98; + public const double ShiftPolygonRPMMargin = 7; + private const double ShiftPolygonEngineFldMargin = 0.98; public static readonly Second MinTimeBetweenGearshifts = 2.SI<Second>(); public static readonly Second DownshiftAfterUpshiftDelay = 10.SI<Second>(); @@ -279,10 +237,8 @@ namespace TUGraz.VectoCore.Models.Declaration public static ShiftPolygon ComputeShiftPolygon(int gear, FullLoadCurve fullLoadCurve, IList<ITransmissionInputData> gears, CombustionEngineData engine, double axlegearRatio, Meter dynamicTyreRadius) { - var engineSpeed85kmhLastGear = ComputeEngineSpeed85kmh(gears[gears.Count - 1], axlegearRatio, dynamicTyreRadius, - engine); - //var engineSpeed85kmhSecondToLastGear = ComputeEngineSpeed85kmh(gears[gears.Count - 2], axlegearRatio, - // dynamicTyreRadius, engine); + // ReSharper disable once InconsistentNaming + var engineSpeed85kmhLastGear = ComputeEngineSpeed85kmh(gears[gears.Count - 1], axlegearRatio, dynamicTyreRadius); var nVHigh = VectoMath.Min(engineSpeed85kmhLastGear, engine.FullLoadCurve.RatedSpeed); @@ -324,11 +280,13 @@ namespace TUGraz.VectoCore.Models.Declaration var gearRatio = gears[gear].Ratio / gears[gear + 1].Ratio; var rpmMarginFactor = 1 + ShiftPolygonRPMMargin / 100.0; + // ReSharper disable InconsistentNaming var p2p = new Point(p2.X * gearRatio * rpmMarginFactor, p2.Y / gearRatio); var p3p = new Point(p3.X * gearRatio * rpmMarginFactor, p3.Y / gearRatio); var p6p = new Point(p6.X * gearRatio * rpmMarginFactor, p6.Y / gearRatio); var edgeP6pP3p = new Edge(p6p, p3p); var p3pExt = new Point((1.1 * p5.Y - edgeP6pP3p.OffsetXY) / edgeP6pP3p.SlopeXY, 1.1 * p5.Y); + // ReSharper restore InconsistentNaming upShift = IntersectShiftPolygon(new[] { p4, p7, p5 }.ToList(), new[] { p2p, p6p, p3pExt }.ToList()) .Select(point => new ShiftPolygon.ShiftPolygonEntry() { @@ -374,18 +332,11 @@ namespace TUGraz.VectoCore.Models.Declaration .ToList(); } - internal static PerSecond ComputeEngineSpeed85kmh(ITransmissionInputData gear, double axleRatio, - Meter dynamicTyreRadius, CombustionEngineData engine) + // ReSharper disable once InconsistentNaming + private static PerSecond ComputeEngineSpeed85kmh(ITransmissionInputData gear, double axleRatio, + Meter dynamicTyreRadius) { var engineSpeed = TruckMaxAllowedSpeed / dynamicTyreRadius * axleRatio * gear.Ratio; - //if (engineSpeed < engine.IdleSpeed) { - // throw new VectoException("engine speed at velocity {0} in gear {1} is below engine's idle speed! {2}", - // DeclarationData.Gearbox.TruckMaxAllowedSpeed, gear.Gear, engineSpeed); - //} - //if (engineSpeed > engine.FullLoadCurve.FullLoadEntries.Last().EngineSpeed) { - // throw new VectoException("engine speed at velocity {0} in gear {1} is above engine's max speed! {2}", - // DeclarationData.Gearbox.TruckMaxAllowedSpeed, gear.Gear, engineSpeed); - //} return engineSpeed; } @@ -454,13 +405,13 @@ namespace TUGraz.VectoCore.Models.Declaration } } - public static IEnumerable<string> AuxiliaryIDs() - { - return new[] { - Constants.Auxiliaries.IDs.Fan, Constants.Auxiliaries.IDs.SteeringPump, - Constants.Auxiliaries.IDs.HeatingVentilationAirCondition, Constants.Auxiliaries.IDs.ElectricSystem, - Constants.Auxiliaries.IDs.PneumaticSystem - }; - } + //public static IEnumerable<string> AuxiliaryIDs() + //{ + // return new[] { + // Constants.Auxiliaries.IDs.Fan, Constants.Auxiliaries.IDs.SteeringPump, + // Constants.Auxiliaries.IDs.HeatingVentilationAirCondition, Constants.Auxiliaries.IDs.ElectricSystem, + // Constants.Auxiliaries.IDs.PneumaticSystem + // }; + //} } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/DeclarationRims.cs b/VectoCore/VectoCore/Models/Declaration/DeclarationRims.cs deleted file mode 100644 index f9522e8812e9b8c85e5019fb37b7dc9e06ce12fb..0000000000000000000000000000000000000000 --- a/VectoCore/VectoCore/Models/Declaration/DeclarationRims.cs +++ /dev/null @@ -1,65 +0,0 @@ -/* -* This file is part of VECTO. -* -* Copyright © 2012-2016 European Union -* -* Developed by Graz University of Technology, -* Institute of Internal Combustion Engines and Thermodynamics, -* Institute of Technical Informatics -* -* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved -* by the European Commission - subsequent versions of the EUPL (the "Licence"); -* You may not use VECTO except in compliance with the Licence. -* You may obtain a copy of the Licence at: -* -* https://joinup.ec.europa.eu/community/eupl/og_page/eupl -* -* Unless required by applicable law or agreed to in writing, VECTO -* distributed under the Licence is distributed on an "AS IS" basis, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the Licence for the specific language governing permissions and -* limitations under the Licence. -* -* Authors: -* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology -* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology -* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology -* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology -* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology -* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology -*/ - -using System.Data; -using System.Linq; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.Declaration -{ - public class DeclarationRims : LookupData<string, DeclarationRims.RimsEntry> - { - protected string ResourceId = "TUGraz.VectoCore.Resources.Declaration.Rims.csv"; - - public DeclarationRims() - { - ParseData(ReadCsvResource(ResourceId)); - } - - - protected override sealed void ParseData(DataTable table) - { - Data = (from DataRow row in table.Rows - select new RimsEntry { - RimsType = row[0].ToString(), - F_a = row.ParseDouble(1), - F_b = row.ParseDouble(2) - }).ToDictionary(e => e.RimsType); - } - - public class RimsEntry - { - public string RimsType; - public double F_a; - public double F_b; - } - } -} \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs b/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs index f183e9e5037932a2181b08dee8253d23cedf908d..b68718cc1fab9bb45f3a0eae597c333936dce4d6 100644 --- a/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs +++ b/VectoCore/VectoCore/Models/Declaration/ElectricSystem.cs @@ -30,98 +30,82 @@ */ using System; -using System.Collections.Generic; using System.Data; -using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public sealed class ElectricSystem : LookupData<MissionType, string[], Watt> + public sealed class ElectricSystem : LookupData<MissionType, string, Watt> { private readonly Alternator _alternator = new Alternator(); - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VAUX.ES-Tech.csv"; - private const string BaseLine = "Baseline electric power consumption"; + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.ES-Tech.csv"; } + } - private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = - new Dictionary<Tuple<MissionType, string>, Watt>(); - - public ElectricSystem() + protected override string ErrorMessage { - ParseData(ReadCsvResource(ResourceId)); + get { return "Auxiliary Lookup Error: No value found for Electric System. Mission: '{0}', Technology: '{1}'"; } } protected override void ParseData(DataTable table) { + Data.Clear(); NormalizeTable(table); foreach (DataRow row in table.Rows) { - var name = row.Field<string>("Technology"); - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - _data[Tuple.Create(mission, name)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); + var name = row.Field<string>("technology"); + foreach (DataColumn col in table.Columns) { + if (col.Caption != "technology") { + Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), name)] = + row.ParseDouble(col).SI<Watt>(); + } } } } - public override Watt Lookup(MissionType missionType, string[] technologies) + public override Watt Lookup(MissionType missionType, string technology = null) { - var sum = _data[Tuple.Create(missionType, BaseLine)]; - - if (technologies != null) { - foreach (var technology in technologies) { - try { - sum += _data[Tuple.Create(missionType, technology)]; - } catch (KeyNotFoundException) { - throw new VectoException( - "Auxiliary Lookup Error: No value found for Electric System with mission '{0}' and technology '{1}'", - missionType, technology); - } - } - } - - return sum / _alternator.Lookup(missionType, null); + if (string.IsNullOrWhiteSpace(technology)) + technology = "Standard technology"; + var value = base.Lookup(missionType, technology); + return value / _alternator.Lookup(missionType); } - private sealed class Alternator : LookupData<MissionType, string, double> + internal sealed class Alternator : LookupData<MissionType, string, double> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VAUX.ALT-Tech.csv"; - private const string Default = "Standard alternator"; + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.ALT-Tech.csv"; } + } - private readonly Dictionary<Tuple<MissionType, string>, double> _data = - new Dictionary<Tuple<MissionType, string>, double>(); - - public Alternator() + protected override string ErrorMessage { - ParseData(ReadCsvResource(ResourceId)); + get { return "Auxiliary Lookup Error: No value found for Alternator. Mission: '{0}', Technology: '{1}'"; } } protected override void ParseData(DataTable table) { + Data.Clear(); NormalizeTable(table); foreach (DataRow row in table.Rows) { - var name = row.Field<string>("Technology"); - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - _data[Tuple.Create(mission, name)] = row.ParseDouble(mission.ToString().ToLower()); + var name = row.Field<string>("technology"); + foreach (DataColumn col in table.Columns) { + if (col.Caption != "technology") { + Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), name)] = row.ParseDouble(col); + } } } } - public override double Lookup(MissionType missionType, string technology) + public override double Lookup(MissionType missionType, string technology = null) { - if (string.IsNullOrWhiteSpace(technology)) { - technology = Default; - } - - try { - return _data[Tuple.Create(missionType, technology)]; - } catch (KeyNotFoundException) { - throw new VectoException( - "Auxiliary Lookup Error: No value found for Alternator with mission '{0}' and technology '{1}'", - missionType, technology); - } + if (string.IsNullOrWhiteSpace(technology)) + technology = "Standard alternator efficiency"; + return base.Lookup(missionType, technology); } } } diff --git a/VectoCore/VectoCore/Models/Declaration/Fan.cs b/VectoCore/VectoCore/Models/Declaration/Fan.cs index e3aa0a43a97d57fcd0f3d4ba88e92d9c0142f798..b1940483d84025c8169bf112fc8fa45c5885035d 100644 --- a/VectoCore/VectoCore/Models/Declaration/Fan.cs +++ b/VectoCore/VectoCore/Models/Declaration/Fan.cs @@ -30,9 +30,7 @@ */ using System; -using System.Collections.Generic; using System.Data; -using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Utils; @@ -40,43 +38,36 @@ namespace TUGraz.VectoCore.Models.Declaration { public sealed class Fan : LookupData<MissionType, string, Watt> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VAUX.Fan-Tech.csv"; - private const string DefaultTechnology = "Crankshaft mounted - Electronically controlled visco clutch (Default)"; - - private readonly Dictionary<Tuple<MissionType, string>, Watt> _data = - new Dictionary<Tuple<MissionType, string>, Watt>(); - - public Fan() + protected override string ResourceId { - ParseData(ReadCsvResource(ResourceId)); + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.Fan-Tech.csv"; } } + protected override string ErrorMessage + { + get { return "Auxiliary Lookup Error: No value found for Fan. Mission: '{0}', Technology: '{1}'"; } + } protected override void ParseData(DataTable table) { + Data.Clear(); NormalizeTable(table); - _data.Clear(); foreach (DataRow row in table.Rows) { - foreach (var mission in EnumHelper.GetValues<MissionType>()) { - _data[Tuple.Create(mission, row.Field<string>("Technology"))] = - row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); + var name = row.Field<string>("technology"); + foreach (DataColumn col in table.Columns) { + if (col.Caption != "technology") { + Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), name)] = row.ParseDouble(col).SI<Watt>(); + } } } } - public override Watt Lookup(MissionType mission, string technology) + public override Watt Lookup(MissionType mission, string technology = null) { - if (string.IsNullOrWhiteSpace(technology)) { - technology = DefaultTechnology; - } - - try { - return _data[Tuple.Create(mission, technology)]; - } catch (KeyNotFoundException) { - throw new VectoException("Auxiliary Lookup Error: No value found for Fan with key '{0}' in mission '{1}'", - technology, mission); - } + if (string.IsNullOrWhiteSpace(technology)) + technology = "Crankshaft mounted - Electronically controlled visco clutch"; + return base.Lookup(mission, technology); } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/HVAC.cs b/VectoCore/VectoCore/Models/Declaration/HVAC.cs index a0a8201492a396b12f2384b124967d85c7791de2..2dbdaa761814e506ee4347cea9b10aa736880f86 100644 --- a/VectoCore/VectoCore/Models/Declaration/HVAC.cs +++ b/VectoCore/VectoCore/Models/Declaration/HVAC.cs @@ -30,9 +30,7 @@ */ using System; -using System.Collections.Generic; using System.Data; -using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Utils; @@ -40,34 +38,28 @@ namespace TUGraz.VectoCore.Models.Declaration { public sealed class HeatingVentilationAirConditioning : LookupData<MissionType, VehicleClass, Watt> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VAUX.HVAC-Table.csv"; - private readonly Dictionary<Tuple<MissionType, VehicleClass>, Watt> _data = - new Dictionary<Tuple<MissionType, VehicleClass>, Watt>(); - - public HeatingVentilationAirConditioning() + protected override string ResourceId { - ParseData(ReadCsvResource(ResourceId)); + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.HVAC-Table.csv"; } } - public override Watt Lookup(MissionType mission, VehicleClass hdvClass) + protected override string ErrorMessage { - try { - return _data[Tuple.Create(mission, hdvClass)]; - } catch (KeyNotFoundException) { - throw new VectoException("Auxiliary Lookup Error: No value found for HVAC with mission '{0}' and HDVClass '{1}'", - mission, hdvClass); - } + get { return "Auxiliary Lookup Error: No value found for HVAC. Mission: '{0}', HDVClass: '{1}'"; } } protected override void ParseData(DataTable table) { - _data.Clear(); + Data.Clear(); NormalizeTable(table); foreach (DataRow row in table.Rows) { - var hdvClass = VehicleClassHelper.Parse(row.Field<string>("hdvclass/power")); - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - _data[Tuple.Create(mission, hdvClass)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); + var hdvClass = VehicleClassHelper.Parse(row.Field<string>("hdvclass")); + foreach (DataColumn col in table.Columns) { + var value = row.ParseDoubleOrGetDefault(col.Caption, double.NaN); + if (col.Caption != "hdvclass" && !double.IsNaN(value)) { + Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), hdvClass)] = value.SI<Watt>(); + } } } } diff --git a/VectoCore/VectoCore/Models/Declaration/LACDecisionFactor.cs b/VectoCore/VectoCore/Models/Declaration/LACDecisionFactor.cs index 355a2d79956868017505d2c63f8619ed24e36059..bb91fd2e35d28a6dfa59dcca384f4200b60f35aa 100644 --- a/VectoCore/VectoCore/Models/Declaration/LACDecisionFactor.cs +++ b/VectoCore/VectoCore/Models/Declaration/LACDecisionFactor.cs @@ -37,70 +37,51 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public class LACDecisionFactor + /// <summary> + /// Class for Look Ahead Coasting Decision Factor (DF_coast) + /// </summary> + public sealed class LACDecisionFactor { - private readonly DecisionFactor LAC; + private readonly LACDecisionFactorVTarget _vTarget; + private readonly LACDecisionFactorVdrop _vDrop; + private readonly double _offset; + private readonly double _scaling; public LACDecisionFactor() { - LAC = new DecisionFactor(); + _offset = DeclarationData.Driver.LookAhead.DecisionFactorCoastingOffset; + _scaling = DeclarationData.Driver.LookAhead.DecisionFactorCoastingScaling; + _vTarget = new LACDecisionFactorVTarget(); + _vDrop = new LACDecisionFactorVdrop(); } public LACDecisionFactor(double offset, double scaling, DataTable vTargetLookup, DataTable vDropLookup) { - LAC = new DecisionFactor(offset, scaling, vTargetLookup, vDropLookup); + _offset = offset; + _scaling = scaling; + _vTarget = new LACDecisionFactorVTarget(vTargetLookup); + _vDrop = new LACDecisionFactorVdrop(vDropLookup); } public double Lookup(MeterPerSecond targetVelocity, MeterPerSecond velocityDrop) { - return LAC.Lookup(targetVelocity, velocityDrop); + // normalize values from [0 .. 1] to [2.5 .. 1] + return _offset - _scaling * _vTarget.Lookup(targetVelocity) * _vDrop.Lookup(velocityDrop); } - /// <summary> - /// Class for Look Ahead Coasting Decision Factor (DF_coast) - /// </summary> - public sealed class DecisionFactor : LookupData<MeterPerSecond, MeterPerSecond, double> + private sealed class LACDecisionFactorVdrop : LookupData<MeterPerSecond, double> { - private readonly LACDecisionFactorVTarget _vTarget; - private readonly LACDecisionFactorVdrop _vDrop; - private readonly double _offset; - private readonly double _scaling; - - public DecisionFactor(double offset, double scaling, DataTable vTargetLookup, DataTable vDropLookup) + protected override string ResourceId { - _offset = offset; - _scaling = scaling; - _vTarget = new LACDecisionFactorVTarget(vTargetLookup); - _vDrop = new LACDecisionFactorVdrop(vDropLookup); + get { return "TUGraz.VectoCore.Resources.Declaration.LAC-DF-Vdrop.csv"; } } - public DecisionFactor() - { - _offset = DeclarationData.Driver.LookAhead.DecisionFactorCoastingOffset; - _scaling = DeclarationData.Driver.LookAhead.DecisionFactorCoastingScaling; - _vTarget = new LACDecisionFactorVTarget(); - _vDrop = new LACDecisionFactorVdrop(); - } - - - public override double Lookup(MeterPerSecond targetVelocity, MeterPerSecond velocityDrop) + protected override string ErrorMessage { - // normalize values inverse from [0 .. 1] to [2.5 .. 1] - return _offset - _scaling * _vTarget.Lookup(targetVelocity) * _vDrop.Lookup(velocityDrop); + get { throw new System.NotImplementedException(); } } - - protected override void ParseData(DataTable table) {} - } - - public sealed class LACDecisionFactorVdrop : LookupData<MeterPerSecond, double> - { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.LAC-DF-Vdrop.csv"; - - public LACDecisionFactorVdrop() - { - ParseData(ReadCsvResource(ResourceId)); - } + public LACDecisionFactorVdrop() {} public LACDecisionFactorVdrop(DataTable vDrop) { @@ -135,22 +116,27 @@ namespace TUGraz.VectoCore.Models.Declaration } } - public static class Fields + private static class Fields { - public const string VelocityDrop = "v_drop"; public const string DecisionFactor = "decision_factor"; + public const string VelocityDrop = "v_drop"; } } - public sealed class LACDecisionFactorVTarget : LookupData<MeterPerSecond, double> + private sealed class LACDecisionFactorVTarget : LookupData<MeterPerSecond, double> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.LAC-DF-Vtarget.csv"; + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.LAC-DF-Vtarget.csv"; } + } - public LACDecisionFactorVTarget() + protected override string ErrorMessage { - ParseData(ReadCsvResource(ResourceId)); + get { throw new System.NotImplementedException(); } } + public LACDecisionFactorVTarget() {} + public LACDecisionFactorVTarget(DataTable vTargetLookup) { ParseData(vTargetLookup ?? ReadCsvResource(ResourceId)); @@ -184,7 +170,7 @@ namespace TUGraz.VectoCore.Models.Declaration } } - public static class Fields + private static class Fields { public const string TargetVelocity = "v_target"; public const string DecisionFactor = "decision_factor"; diff --git a/VectoCore/VectoCore/Models/Declaration/LookupData.cs b/VectoCore/VectoCore/Models/Declaration/LookupData.cs index cc6b34ab7f2265907c6628086f37f53bf61b3b08..07b2754593904654c281b222ba6b8468492bd674 100644 --- a/VectoCore/VectoCore/Models/Declaration/LookupData.cs +++ b/VectoCore/VectoCore/Models/Declaration/LookupData.cs @@ -29,8 +29,10 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using System; using System.Collections.Generic; using System.Data; +using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Utils; @@ -39,6 +41,15 @@ namespace TUGraz.VectoCore.Models.Declaration { public abstract class LookupData : LoggingObject { + protected LookupData() + { + if (!string.IsNullOrWhiteSpace(ResourceId)) + ParseData(ReadCsvResource(ResourceId)); + } + + protected abstract string ResourceId { get; } + protected abstract string ErrorMessage { get; } + protected abstract void ParseData(DataTable table); protected DataTable ReadCsvResource(string resourceId) @@ -60,25 +71,46 @@ namespace TUGraz.VectoCore.Models.Declaration } } - public abstract class LookupData<TKey, TValue> : LookupData { protected Dictionary<TKey, TValue> Data = new Dictionary<TKey, TValue>(); public virtual TValue Lookup(TKey key) { - return Data[key]; + try { + return Data[key]; + } catch (KeyNotFoundException) { + throw new VectoException(string.Format(ErrorMessage, key)); + } } } public abstract class LookupData<TKey1, TKey2, TValue> : LookupData { - public abstract TValue Lookup(TKey1 key1, TKey2 key2); + protected Dictionary<Tuple<TKey1, TKey2>, TValue> Data = new Dictionary<Tuple<TKey1, TKey2>, TValue>(); + + public virtual TValue Lookup(TKey1 key1, TKey2 key2) + { + try { + return Data[new Tuple<TKey1, TKey2>(key1, key2)]; + } catch (KeyNotFoundException) { + throw new VectoException(string.Format(ErrorMessage, key1, key2)); + } + } } public abstract class LookupData<TKey1, TKey2, TKey3, TValue> : LookupData { - public abstract TValue Lookup(TKey1 key1, TKey2 key2, TKey3 key3); + protected Dictionary<Tuple<TKey1, TKey2, TKey3>, TValue> Data = new Dictionary<Tuple<TKey1, TKey2, TKey3>, TValue>(); + + public virtual TValue Lookup(TKey1 key1, TKey2 key2, TKey3 key3) + { + try { + return Data[new Tuple<TKey1, TKey2, TKey3>(key1, key2, key3)]; + } catch (KeyNotFoundException) { + throw new VectoException(string.Format(ErrorMessage, key1, key2, key3)); + } + } } public abstract class LookupData<TKey1, TKey2, TKey3, TKey4, TValue> : LookupData diff --git a/VectoCore/VectoCore/Models/Declaration/PT1.cs b/VectoCore/VectoCore/Models/Declaration/PT1.cs index 4aae13967b97b2653c79f6b757daf33df4a6af4f..db88c2e9e115983ea4af701a8d1a4c5cd20c27fb 100644 --- a/VectoCore/VectoCore/Models/Declaration/PT1.cs +++ b/VectoCore/VectoCore/Models/Declaration/PT1.cs @@ -29,6 +29,7 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using System; using System.Collections.Generic; using System.Data; using System.Linq; @@ -40,9 +41,18 @@ namespace TUGraz.VectoCore.Models.Declaration { public sealed class PT1 : LookupData<PerSecond, Second> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.PT1.csv"; + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.PT1.csv"; } + } + + protected override string ErrorMessage + { + get { throw new InvalidOperationException("ErrorMessage not applicable."); } + } + private List<KeyValuePair<PerSecond, Second>> _entries; - + public PT1() { ParseData(ReadCsvResource(ResourceId)); diff --git a/VectoCore/VectoCore/Models/Declaration/Payloads.cs b/VectoCore/VectoCore/Models/Declaration/Payloads.cs index 56495305f3da176a8ef80872c8a8e051955cae06..abf14d3cc6a82c56a7f7af06ec593d3ca62d06c3 100644 --- a/VectoCore/VectoCore/Models/Declaration/Payloads.cs +++ b/VectoCore/VectoCore/Models/Declaration/Payloads.cs @@ -39,23 +39,23 @@ namespace TUGraz.VectoCore.Models.Declaration { public sealed class Payloads : LookupData<Kilogram, Payloads.PayloadEntry> { - public sealed class PayloadEntry + protected override string ResourceId { - public Kilogram Payload50Percent; - public Kilogram Payload75Percent; + get { return "TUGraz.VectoCore.Resources.Declaration.Payloads.csv"; } } - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.Payloads.csv"; - - public Payloads() + protected override string ErrorMessage { - ParseData(ReadCsvResource(ResourceId)); + get { throw new InvalidOperationException("ErrorMessage not applicable."); } } + /// <summary> + /// Obsolete. Call Lookup50Percent, Lookup75Percent or LookupTrailer instead! + /// </summary> [Obsolete("Call Lookup50Percent, Lookup75Percent or LookupTrailer!", true)] private new PayloadEntry Lookup(Kilogram grossVehicleWeight) { - throw new NotImplementedException("Call Lookup50Percent, Lookup75Percent or LookupTrailer!"); + throw new InvalidOperationException("Call Lookup50Percent, Lookup75Percent or LookupTrailer!"); } public Kilogram Lookup50Percent(Kilogram grossVehicleWeight) @@ -82,6 +82,7 @@ namespace TUGraz.VectoCore.Models.Declaration protected override void ParseData(DataTable table) { NormalizeTable(table); + Data = table.Rows.Cast<DataRow>() .ToDictionary( kv => kv.ParseDouble("grossvehicleweight").SI<Kilogram>(), @@ -90,5 +91,11 @@ namespace TUGraz.VectoCore.Models.Declaration Payload75Percent = kv.ParseDouble("payload75%").SI<Kilogram>() }); } + + public sealed class PayloadEntry + { + public Kilogram Payload50Percent; + public Kilogram Payload75Percent; + } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs b/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs index 3dbbfe6f2de33fe632be41abfe76b1a112c63b49..c0d2bbc79945a59c84b482361c16e98bfa08e79a 100644 --- a/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs +++ b/VectoCore/VectoCore/Models/Declaration/PneumaticSystem.cs @@ -30,45 +30,35 @@ */ using System; -using System.Collections.Generic; using System.Data; -using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public sealed class PneumaticSystem : LookupData<MissionType, VehicleClass, Watt> + public sealed class PneumaticSystem : LookupData<MissionType, string, Watt> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VAUX.PS-Table.csv"; - private readonly Dictionary<Tuple<MissionType, VehicleClass>, Watt> _data = - new Dictionary<Tuple<MissionType, VehicleClass>, Watt>(); - - public PneumaticSystem() + protected override string ResourceId { - ParseData(ReadCsvResource(ResourceId)); + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.PS-Table.csv"; } } - public override Watt Lookup(MissionType mission, VehicleClass hdvClass) + protected override string ErrorMessage { - try { - return _data[Tuple.Create(mission, hdvClass)]; - } catch (KeyNotFoundException) { - throw new VectoException( - "Auxiliary Lookup Error: No value found for Pneumatic System with mission '{0}' and HDVClass '{1}'", - mission, hdvClass); - } + get { return "Auxiliary Lookup Error: No value found for Pneumatic System. Mission: '{0}', Technology: '{1}'"; } } protected override void ParseData(DataTable table) { - _data.Clear(); + Data.Clear(); NormalizeTable(table); foreach (DataRow row in table.Rows) { - var hdvClass = VehicleClassHelper.Parse(row.Field<string>("hdvclass/power")); - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - _data[Tuple.Create(mission, hdvClass)] = row.ParseDouble(mission.ToString().ToLower()).SI<Watt>(); + var technology = row.Field<string>("technology"); + foreach (DataColumn col in table.Columns) { + if (col.Caption != "technology") { + Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), technology)] = row.ParseDouble(col.Caption).SI<Watt>(); + } } } } diff --git a/VectoCore/VectoCore/Models/Declaration/Rims.cs b/VectoCore/VectoCore/Models/Declaration/Rims.cs deleted file mode 100644 index e6935f8606707112b34ceac1e66737ebe880ad47..0000000000000000000000000000000000000000 --- a/VectoCore/VectoCore/Models/Declaration/Rims.cs +++ /dev/null @@ -1,65 +0,0 @@ -/* -* This file is part of VECTO. -* -* Copyright © 2012-2016 European Union -* -* Developed by Graz University of Technology, -* Institute of Internal Combustion Engines and Thermodynamics, -* Institute of Technical Informatics -* -* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved -* by the European Commission - subsequent versions of the EUPL (the "Licence"); -* You may not use VECTO except in compliance with the Licence. -* You may obtain a copy of the Licence at: -* -* https://joinup.ec.europa.eu/community/eupl/og_page/eupl -* -* Unless required by applicable law or agreed to in writing, VECTO -* distributed under the Licence is distributed on an "AS IS" basis, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the Licence for the specific language governing permissions and -* limitations under the Licence. -* -* Authors: -* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology -* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology -* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology -* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology -* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology -* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology -*/ - -using System.Data; -using System.Linq; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.Declaration -{ - public class Rims : LookupData<string, Rims.RimsEntry> - { - protected const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.Rims.csv"; - - public Rims() - { - ParseData(ReadCsvResource(ResourceId)); - } - - - protected override sealed void ParseData(DataTable table) - { - Data = (from DataRow row in table.Rows - select new RimsEntry { - RimsType = row[0].ToString(), - F_a = row.ParseDouble(1), - F_b = row.ParseDouble(2) - }).ToDictionary(e => e.RimsType); - } - - public class RimsEntry - { - public string RimsType; - public double F_a; - public double F_b; - } - } -} \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/Segments.cs b/VectoCore/VectoCore/Models/Declaration/Segments.cs index 892732d581769fa50d65145a18a5d8068e26ad4f..4ce4fe1ad153ca27f84177b7c044e91661bdd2ad 100644 --- a/VectoCore/VectoCore/Models/Declaration/Segments.cs +++ b/VectoCore/VectoCore/Models/Declaration/Segments.cs @@ -43,21 +43,27 @@ namespace TUGraz.VectoCore.Models.Declaration { public sealed class Segments : LookupData<VehicleCategory, AxleConfiguration, Kilogram, Kilogram, Segment> { - public Segments() + private DataTable _segmentTable; + + protected override string ResourceId { - ParseData(ReadCsvResource(RessourceHelper.Namespace + "SegmentTable.csv")); + get { return RessourceHelper.Namespace + "SegmentTable.csv"; } } - protected override void ParseData(DataTable table) + protected override string ErrorMessage { - // normalize column names, remove whitespaces and lowercase - foreach (DataColumn col in table.Columns) { - table.Columns[col.ColumnName].ColumnName = col.ColumnName.ToLower().RemoveWhitespace(); + get + { + return + "ERROR: Could not find the declaration segment for vehicle. Category: {0}, AxleConfiguration: {1}, GrossVehicleWeight: {2}"; } - SegmentTable = table.Copy(); } - private DataTable SegmentTable { get; set; } + protected override void ParseData(DataTable table) + { + NormalizeTable(table); + _segmentTable = table.Copy(); + } public override Segment Lookup(VehicleCategory vehicleCategory, AxleConfiguration axleConfiguration, Kilogram grossVehicleMassRating, Kilogram curbWeight) @@ -68,7 +74,7 @@ namespace TUGraz.VectoCore.Models.Declaration DataRow row; try { - row = SegmentTable.Rows.Cast<DataRow>().First(r => { + row = _segmentTable.Rows.Cast<DataRow>().First(r => { var isValid = r.Field<string>("valid"); var category = r.Field<string>("vehiclecategory"); var axleConf = r.Field<string>("axleconf."); @@ -83,9 +89,7 @@ namespace TUGraz.VectoCore.Models.Declaration && grossVehicleMassRating <= massMax; }); } catch (InvalidOperationException e) { - var errorMessage = string.Format( - "ERROR: Could not find the declaration segment for vehicle. Category: {0}, AxleConfiguration: {1}, GrossVehicleWeight: {2}", - vehicleCategory, axleConfiguration.GetName(), grossVehicleMassRating); + var errorMessage = string.Format(ErrorMessage, vehicleCategory, axleConfiguration.GetName(), grossVehicleMassRating); Log.Fatal(errorMessage); throw new VectoException(errorMessage, e); } @@ -117,12 +121,12 @@ namespace TUGraz.VectoCore.Models.Declaration : TrailerType.None; var trailer = trailerIsUsed ? DeclarationData.StandardBodies.Lookup(trailerField) - : DeclarationData.StandardBodies.Empty; + : StandardBodies.Empty; var semiTrailerField = row.Field<string>("semitrailer"); var semiTrailer = !string.IsNullOrWhiteSpace(semiTrailerField) ? DeclarationData.StandardBodies.Lookup(semiTrailerField) - : DeclarationData.StandardBodies.Empty; + : StandardBodies.Empty; trailer += semiTrailer; @@ -131,7 +135,7 @@ namespace TUGraz.VectoCore.Models.Declaration Constants.SimulationSettings.MaximumGrossVehicleWeight); var maxLoad = gvw - curbWeight - body.CurbWeight - trailer.CurbWeight; - var refLoadValue = row.Field<string>(missionType.ToString()).ToDouble(double.NaN); + var refLoadValue = row.ParseDoubleOrGetDefault(missionType.ToString(), double.NaN); Kilogram refLoad; if (double.IsNaN(refLoadValue)) { refLoad = DeclarationData.GetPayloadForGrossVehicleWeight(grossVehicleWeight, missionType) + diff --git a/VectoCore/VectoCore/Models/Declaration/StandardBodies.cs b/VectoCore/VectoCore/Models/Declaration/StandardBodies.cs index aeecd0fbeff54fdcaa1f3dca7d6ce6eeafa79b77..9fc0ffb834e3dd0cf175b1d764945300d5946279 100644 --- a/VectoCore/VectoCore/Models/Declaration/StandardBodies.cs +++ b/VectoCore/VectoCore/Models/Declaration/StandardBodies.cs @@ -29,10 +29,8 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.Collections.Generic; using System.Data; using System.Linq; -using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Utils; @@ -40,30 +38,30 @@ namespace TUGraz.VectoCore.Models.Declaration { public sealed class StandardBody { - public StandardBody(Kilogram curbWeight, Kilogram grossVehicleWeight, SquareMeter deltaCrossWindArea, - Wheels.WheelsEntry wheels) - { - CurbWeight = curbWeight; - GrossVehicleWeight = grossVehicleWeight; - DeltaCrossWindArea = deltaCrossWindArea; - Wheels = wheels; - } - public Kilogram CurbWeight; public Kilogram GrossVehicleWeight; + public SquareMeter DeltaCrossWindArea; + public string Name; + public Wheels.Entry Wheels; public Kilogram MaxPayLoad { get { return GrossVehicleWeight - CurbWeight; } } - public SquareMeter DeltaCrossWindArea; - - public Wheels.WheelsEntry Wheels; + public StandardBody(string name, Kilogram curbWeight, Kilogram grossVehicleWeight, SquareMeter deltaCrossWindArea, + Wheels.Entry wheels) + { + Name = name; + CurbWeight = curbWeight; + GrossVehicleWeight = grossVehicleWeight; + DeltaCrossWindArea = deltaCrossWindArea; + Wheels = wheels; + } public static StandardBody operator +(StandardBody first, StandardBody second) { - return new StandardBody(first.CurbWeight + second.CurbWeight, + return new StandardBody(first.Name + second.Name, first.CurbWeight + second.CurbWeight, first.GrossVehicleWeight + second.GrossVehicleWeight, first.DeltaCrossWindArea + second.DeltaCrossWindArea, null); @@ -81,42 +79,36 @@ namespace TUGraz.VectoCore.Models.Declaration /// </summary> public sealed class StandardBodies : LookupData<string, StandardBody> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.Body_Trailers_Weights.csv"; + public static StandardBody Empty = new StandardBody("", 0.SI<Kilogram>(), 0.SI<Kilogram>(), 0.SI<SquareMeter>(), null); - public StandardBodies() + protected override string ResourceId { - ParseData(ReadCsvResource(ResourceId)); + get { return "TUGraz.VectoCore.Resources.Declaration.Body_Trailers_Weights.csv"; } } - public StandardBody Empty = new StandardBody(0.SI<Kilogram>(), 0.SI<Kilogram>(), 0.SI<SquareMeter>(), null); + protected override string ErrorMessage + { + get { return "StandardWeigths Lookup Error: No value found for ID '{0}'"; } + } public override StandardBody Lookup(string id) { - if (string.IsNullOrWhiteSpace(id)) { - return Empty; - } - - try { - return Data[id]; - } catch (KeyNotFoundException) { - throw new VectoException("StandardWeigths Lookup Error: No value found for ID '{0}'", id); - } + return string.IsNullOrWhiteSpace(id) ? Empty : base.Lookup(id); } protected override void ParseData(DataTable table) { NormalizeTable(table); - Data = table.Rows.Cast<DataRow>() - .ToDictionary( - kv => kv.Field<string>("name"), - kv => new StandardBody( - kv.ParseDoubleOrGetDefault("curbmass").SI<Kilogram>(), - kv.ParseDoubleOrGetDefault("maxgrossmass").SI<Kilogram>(), - kv.ParseDoubleOrGetDefault("deltacdxafortraileroperationinlonghaul").SI<SquareMeter>(), - !string.IsNullOrWhiteSpace(kv.Field<string>("wheels")) - ? DeclarationData.Wheels.Lookup(kv.Field<string>("wheels")) - : null)); + Data = table.Rows.Cast<DataRow>().Select(k => new StandardBody( + k.Field<string>("name"), + k.ParseDoubleOrGetDefault("curbmass").SI<Kilogram>(), + k.ParseDoubleOrGetDefault("maxgrossmass").SI<Kilogram>(), + k.ParseDoubleOrGetDefault("deltacdxafortraileroperationinlonghaul").SI<SquareMeter>(), + !string.IsNullOrWhiteSpace(k.Field<string>("wheels")) + ? DeclarationData.Wheels.Lookup(k.Field<string>("wheels")) + : null)) + .ToDictionary(kv => kv.Name); } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs b/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs index 4fbaf72c36eb87a08c36d975902cc3cc8fabf553..dc2965fc589a36893cd3b05299c895d239e2f3ba 100644 --- a/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs +++ b/VectoCore/VectoCore/Models/Declaration/SteeringPump.cs @@ -33,81 +33,163 @@ using System; using System.Collections.Generic; using System.Data; using System.Linq; -using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public sealed class SteeringPump : LookupData<MissionType, VehicleClass, string, Watt> + public sealed class SteeringPump { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VAUX.SP-Table.csv"; - private readonly SteeringPumpTechnologies _technologies = new SteeringPumpTechnologies(); - private readonly Dictionary<Tuple<MissionType, VehicleClass>, Watt[]> _data = - new Dictionary<Tuple<MissionType, VehicleClass>, Watt[]>(); - - public SteeringPump() + public Watt Lookup(MissionType mission, VehicleClass hdvClass, IEnumerable<string> technologies) { - ParseData(ReadCsvResource(ResourceId)); + var baseLookup = new SteeringPumpBaseLine(); + var axleLookup = new SteeringPumpAxles(); + var techLookup = new SteeringPumpTechnologies(); + + var baseLine = baseLookup.Lookup(mission, hdvClass); + var power = new SteeringPumpValues<Watt>(0.SI<Watt>(), 0.SI<Watt>(), 0.SI<Watt>()); + var factors = new SteeringPumpValues<double>(0, 0, 0); + var i = 0; + foreach (var technology in technologies) { + i++; + var axles = axleLookup.Lookup(mission, i); + power.UnloadedFriction += baseLine.UnloadedFriction * axles.UnloadedFriction; + power.Banking += baseLine.Banking * axles.Banking; + power.Steering += baseLine.Steering * axles.Steering; + + var f = techLookup.Lookup(technology, mission); + factors.UnloadedFriction += f.UnloadedFriction; + factors.Banking += f.Banking; + factors.Steering += f.Steering; + } + + power.UnloadedFriction *= factors.UnloadedFriction / i; + power.Banking *= factors.Banking / i; + power.Steering *= factors.Steering / i; + + return power.UnloadedFriction + power.Banking + power.Steering; } - public override Watt Lookup(MissionType mission, VehicleClass hdvClass, string technology) + private sealed class SteeringPumpBaseLine : LookupData<MissionType, VehicleClass, SteeringPumpValues<Watt>> { - try { - var shares = _data[Tuple.Create(mission, hdvClass)]; - var factors = _technologies.Lookup(technology); + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.SP-Table.csv"; } + } + + protected override string ErrorMessage + { + get { return "Auxiliary Lookup Error: No value found for Steering Pump. Mission: '{0}', HDVClass: '{1}'"; } + } - var sum = 0.SI<Watt>(); - for (var i = 0; i < factors.Length; i++) { - sum += shares[i] * factors[i]; + protected override void ParseData(DataTable table) + { + NormalizeTable(table); + Data.Clear(); + + foreach (DataRow row in table.Rows) { + var hdvClass = VehicleClassHelper.Parse(row.Field<string>("hdvclass")); + foreach (DataColumn col in table.Columns) { + if (col.Caption == "hdvclass" || string.IsNullOrWhiteSpace(row.Field<string>(col.Caption))) + continue; + var values = row.Field<string>(col.Caption).Split('/') + .Select(v => v.ToDouble() / 100.0).Concat(0.0.Repeat(3)).SI<Watt>().ToList(); + Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), hdvClass)] = new SteeringPumpValues<Watt>(values[0], + values[1], values[2]); + } } - return sum; - } catch (KeyNotFoundException) { - throw new VectoException( - "Auxiliary Lookup Error: No value found for Steering Pump with mission '{0}', HDVClass '{1}' and technology '{3}'", - mission, hdvClass, technology); } } - protected override void ParseData(DataTable table) + private sealed class SteeringPumpTechnologies : LookupData<string, SteeringPumpValues<double>> { - _data.Clear(); - NormalizeTable(table); + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.SP-Tech.csv"; } + } + + protected override string ErrorMessage + { + get { return "Auxiliary Lookup Error: No value found for SteeringPump Technology. Key: '{0}'"; } + } - foreach (DataRow row in table.Rows) { - var hdvClass = VehicleClassHelper.Parse(row.Field<string>("hdvclass/powerdemandpershare")); - foreach (var mission in EnumHelper.GetValues<MissionType>()) { - var values = row.Field<string>(mission.ToString().ToLower()).Split('/').ToDouble(); - values = values.Concat(Enumerable.Repeat(0.0, 3)); + protected override void ParseData(DataTable table) + { + NormalizeTable(table); + Data.Clear(); + + Data = table.Rows.Cast<DataRow>().ToDictionary( + key => key.Field<string>("Technology"), + value => new SteeringPumpValues<double>(value.ParseDouble("UF"), value.ParseDouble("B"), value.ParseDouble("S"))); + } - _data[Tuple.Create(mission, hdvClass)] = values.Take(4).SI<Watt>().ToArray(); + public override SteeringPumpValues<double> Lookup(string key) + { + throw new InvalidOperationException("Standard lookup is not supported. Use Lookup(string, MissionType) instead."); + } + + /// <summary> + /// Lookup for Steering Pump Technologies. + /// </summary> + /// <param name="tech">The technology string.</param> + /// <param name="mission">Only used when Tech is Electric System.</param> + /// <returns></returns> + public SteeringPumpValues<double> Lookup(string tech, MissionType mission) + { + var values = base.Lookup(tech); + if (tech == "Electric") { + var alternator = new ElectricSystem.Alternator(); + values.Banking /= alternator.Lookup(mission); + values.Steering /= alternator.Lookup(mission); } + return values; } } - private sealed class SteeringPumpTechnologies : LookupData<string, double[]> + private sealed class SteeringPumpAxles : LookupData<MissionType, int, SteeringPumpValues<double>> { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.VAUX.SP-Tech.csv"; + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.VAUX.SP-Axles.csv"; } + } - public SteeringPumpTechnologies() + protected override string ErrorMessage { - ParseData(ReadCsvResource(ResourceId)); + get { return "Auxiliary Lookup Error: No value found for SteeringPump Axle. Mission: '{0}', Axle Count: '{1}'"; } } protected override void ParseData(DataTable table) { - Data = table.Rows.Cast<DataRow>().ToDictionary( - key => key.Field<string>("Scaling Factors"), - value => new[] { value.ParseDouble("U"), value.ParseDouble("F"), value.ParseDouble("B"), value.ParseDouble("S") }); + NormalizeTable(table); + Data.Clear(); + + foreach (DataRow row in table.Rows) { + var axleNumber = int.Parse(row.Field<string>("steeredaxles")); + foreach (DataColumn col in table.Columns) { + if (col.Caption == "steeredaxles") + continue; + var field = row.Field<string>(col.Caption); + if (string.IsNullOrWhiteSpace(field)) + continue; + var values = field.Split('/').ToDouble().Concat(0.0.Repeat(3)).ToList(); + Data[Tuple.Create(col.Caption.ParseEnum<MissionType>(), axleNumber)] = new SteeringPumpValues<double>(values[0], + values[1], values[2]); + } + } } + } + + private class SteeringPumpValues<T> + { + public T UnloadedFriction; + public T Banking; + public T Steering; - public override double[] Lookup(string tech) + public SteeringPumpValues(T unloadedFriction, T banking, T steering) { - try { - return Data[tech]; - } catch (KeyNotFoundException) { - throw new VectoException("Auxiliary Lookup Error: No value found for SteeringPump Technology with key '{0}'", tech); - } + UnloadedFriction = unloadedFriction; + Banking = banking; + Steering = steering; } } } diff --git a/VectoCore/VectoCore/Models/Declaration/TorqueConverter.cs b/VectoCore/VectoCore/Models/Declaration/TorqueConverter.cs deleted file mode 100644 index 9aa9837f63135794a7a34dcb24ed659679b1d40c..0000000000000000000000000000000000000000 --- a/VectoCore/VectoCore/Models/Declaration/TorqueConverter.cs +++ /dev/null @@ -1,98 +0,0 @@ -/* -* This file is part of VECTO. -* -* Copyright © 2012-2016 European Union -* -* Developed by Graz University of Technology, -* Institute of Internal Combustion Engines and Thermodynamics, -* Institute of Technical Informatics -* -* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved -* by the European Commission - subsequent versions of the EUPL (the "Licence"); -* You may not use VECTO except in compliance with the Licence. -* You may obtain a copy of the Licence at: -* -* https://joinup.ec.europa.eu/community/eupl/og_page/eupl -* -* Unless required by applicable law or agreed to in writing, VECTO -* distributed under the Licence is distributed on an "AS IS" basis, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the Licence for the specific language governing permissions and -* limitations under the Licence. -* -* Authors: -* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology -* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology -* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology -* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology -* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology -* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology -*/ - -using System; -using System.Data; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Utils; - -namespace TUGraz.VectoCore.Models.Declaration -{ - public sealed class TorqueConverter : LookupData<double, TorqueConverter.TorqueConverterEntry> - { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.DefaultTC.vtcc"; - - public TorqueConverter() - { - ParseData(ReadCsvResource(ResourceId)); - } - - - [Obsolete("Default Lookup not available. Use LookupMu or LookupTorque instead.", true)] - private new TorqueConverterEntry Lookup(double key) - { - throw new InvalidOperationException( - "Default Lookup not available. Use TorqueConverter.LookupMu() or TorqueConverter.LookupTorque() instead."); - } - - - public NewtonMeter LookupTorque(double nu, PerSecond angularSpeedIn, PerSecond referenceSpeed) - { - var sec = Data.GetSection(kv => kv.Key < nu); - - if (nu < sec.Item1.Key || sec.Item2.Key < nu) { - Log.Warn(string.Format("TCextrapol: nu = {0} [n_out/n_in]", nu)); - } - - var torque = VectoMath.Interpolate(sec.Item1.Key, sec.Item2.Key, sec.Item1.Value.Torque, sec.Item2.Value.Torque, nu); - return torque * Math.Pow((angularSpeedIn / referenceSpeed).Cast<Scalar>(), 2); - } - - public double LookupMu(double nu) - { - var sec = Data.GetSection(kv => kv.Key < nu); - - if (nu < sec.Item1.Key || sec.Item2.Key < nu) { - Log.Warn(string.Format("TCextrapol: nu = {0} [n_out/n_in]", nu)); - } - - return VectoMath.Interpolate(sec.Item1.Key, sec.Item2.Key, sec.Item1.Value.Mu, sec.Item2.Value.Mu, nu); - } - - - protected override void ParseData(DataTable table) - { - Data.Clear(); - foreach (DataRow row in table.Rows) { - Data[row.ParseDouble("nue")] = new TorqueConverterEntry { - Mu = row.ParseDouble("mue"), - Torque = row.ParseDouble("MP1000 (1000/rpm)^2*Nm").SI<NewtonMeter>() - }; - } - } - - public class TorqueConverterEntry - { - public double Mu { get; set; } - public NewtonMeter Torque { get; set; } - } - } -} \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/WHTCCorrection.cs b/VectoCore/VectoCore/Models/Declaration/WHTCCorrection.cs index fa7e2073d3691837b01b32f479ef72998efe8994..06b305fffd088267fe3f23194c5759bcf229b0cf 100644 --- a/VectoCore/VectoCore/Models/Declaration/WHTCCorrection.cs +++ b/VectoCore/VectoCore/Models/Declaration/WHTCCorrection.cs @@ -30,7 +30,6 @@ */ using System; -using System.Collections.Generic; using System.Data; using System.Linq; using TUGraz.VectoCommon.Utils; @@ -38,39 +37,45 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public sealed class WHTCCorrection : LookupData<MissionType, double, double, double, double> + public sealed class WHTCCorrection { - private const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.WHTC-Weighting-Factors.csv"; - private readonly Dictionary<MissionType, WHTCCorrectionEntry> _data = - new Dictionary<MissionType, WHTCCorrectionEntry>(); - - public WHTCCorrection() - { - ParseData(ReadCsvResource(ResourceId)); - } + private readonly WHTCCorrectionData _data = new WHTCCorrectionData(); - public override double Lookup(MissionType mission, double rural, double urban, double motorway) + public double Lookup(MissionType mission, double rural, double urban, double motorway) { - var entry = _data[mission]; + var entry = _data.Lookup(mission); return rural * entry.Rural + urban * entry.Urban + motorway * entry.Motorway; } - - protected override void ParseData(DataTable table) + private sealed class WHTCCorrectionData : LookupData<MissionType, Entry> { - _data.Clear(); - NormalizeTable(table); - foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { - var values = table.Columns[mission.ToString().ToLower()].Values<string>().ToDouble().ToArray(); - _data[mission] = new WHTCCorrectionEntry { Urban = values[0], Rural = values[1], Motorway = values[2] }; + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.WHTC-Weighting-Factors.csv"; } + } + + protected override string ErrorMessage + { + get { return "WHTC Correction Lookup Error: no value found. Mission: '{0}'"; } + } + + protected override void ParseData(DataTable table) + { + NormalizeTable(table); + Data.Clear(); + + foreach (MissionType mission in Enum.GetValues(typeof(MissionType))) { + var values = table.Columns[mission.ToString().ToLower()].Values<string>().ToDouble().ToArray(); + Data[mission] = new Entry { Urban = values[0], Rural = values[1], Motorway = values[2] }; + } } } - private class WHTCCorrectionEntry + private class Entry { - public double Rural { get; set; } - public double Urban { get; set; } - public double Motorway { get; set; } + public double Rural; + public double Urban; + public double Motorway; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Declaration/Wheels.cs b/VectoCore/VectoCore/Models/Declaration/Wheels.cs index dbc2aa5606bc5183a437c58423cb7cb62955cf00..8d70ab77e922540b9e0ec93f499e337c7900ab74 100644 --- a/VectoCore/VectoCore/Models/Declaration/Wheels.cs +++ b/VectoCore/VectoCore/Models/Declaration/Wheels.cs @@ -36,37 +36,40 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.Declaration { - public class Wheels : LookupData<string, Wheels.WheelsEntry> + public sealed class Wheels : LookupData<string, Wheels.Entry> { - protected const string ResourceId = "TUGraz.VectoCore.Resources.Declaration.Wheels.csv"; + protected override string ResourceId + { + get { return "TUGraz.VectoCore.Resources.Declaration.Wheels.csv"; } + } - public Wheels() + protected override string ErrorMessage { - ParseData(ReadCsvResource(ResourceId)); + get { return "Auxiliary Lookup Error: No value found for Wheels. Key: '{0}'"; } } - public override WheelsEntry Lookup(string key) + public override Entry Lookup(string key) { return base.Lookup(key.RemoveWhitespace()); } - protected sealed override void ParseData(DataTable table) + protected override void ParseData(DataTable table) { - Data = (from DataRow row in table.Rows - select new WheelsEntry { + Data = table.Rows.Cast<DataRow>() + .Select(row => new Entry { WheelType = row.Field<string>(0).RemoveWhitespace(), - Inertia = row.ParseDouble(1).SI<KilogramSquareMeter>(), - DynamicTyreRadius = row.ParseDouble(2).SI().Milli.Meter.Cast<Meter>(), - SizeClass = row.Field<string>(3) + Inertia = row.ParseDouble("inertia").SI<KilogramSquareMeter>(), + DynamicTyreRadius = row.ParseDouble("d").SI().Milli.Meter.Cast<Meter>(), + CircumferenceFactor = row.ParseDouble("f") }).ToDictionary(e => e.WheelType); } - public class WheelsEntry + public class Entry { public string WheelType; public KilogramSquareMeter Inertia; public Meter DynamicTyreRadius; - public string SizeClass; + public double CircumferenceFactor; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs b/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs index b1a536787dc597d6a584ec6245c52c3db544eccf..efa73eb085071895e608b7390bd92ad5d0810c1f 100644 --- a/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs +++ b/VectoCore/VectoCore/Models/Simulation/Data/VectoRunData.cs @@ -29,7 +29,6 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using TUGraz.VectoCommon.Exceptions; @@ -38,9 +37,7 @@ using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; using TUGraz.VectoCore.OutputData; -using TUGraz.VectoCore.Utils; using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData; namespace TUGraz.VectoCore.Models.Simulation.Data @@ -144,10 +141,10 @@ namespace TUGraz.VectoCore.Models.Simulation.Data string.Format("Interpolation of Gear-{0}-LossMap failed with torque={1} and angularSpeed={2}", gear.Key, inTorque, angularVelocity.ConvertTo().Rounds.Per.Minute)); } - var velocity = angularVelocity / gear.Value.Ratio / axleGearData.AxleGear.Ratio * - runData.VehicleData.DynamicTyreRadius; if (axleGearData != null) { + var velocity = angularVelocity / gear.Value.Ratio / axleGearData.AxleGear.Ratio * + runData.VehicleData.DynamicTyreRadius; var axleAngularVelocity = angularVelocity / gear.Value.Ratio; try { axleGearData.AxleGear.LossMap.GetOutTorque(axleAngularVelocity, axleTorque); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/Engine/PT1Curve.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/Engine/PT1Curve.cs index 3a8434e773ba8023eae91b3c8697c6466e610f53..817e5ef2d842c5dccd318c33f82ee6e9d76d8140 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Data/Engine/PT1Curve.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/Engine/PT1Curve.cs @@ -44,14 +44,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine { private List<KeyValuePair<PerSecond, Second>> _entries; - public static PT1Curve ReadFromFile(string fileName) + // just for Lookup-inheritance compatibility + protected override string ResourceId { - return new PT1Curve(fileName); + get { return null; } } - public static PT1Curve Create(DataTable data) + // just for Lookup-inheritance compatibility + protected override string ErrorMessage { - return new PT1Curve(data); + get { throw new InvalidOperationException(); } } private PT1Curve(DataTable data) @@ -71,6 +73,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine ParseData(data); } + public static PT1Curve ReadFromFile(string fileName) + { + return new PT1Curve(fileName); + } + + public static PT1Curve Create(DataTable data) + { + return new PT1Curve(data); + } protected override void ParseData(DataTable data) { @@ -83,33 +94,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine "FullLoadCurve/PT1 must consist of at least two lines with numeric values (below file header)"); } - if (HeaderIsValid(data.Columns)) { + if (data.Columns.Contains(Fields.EngineSpeed) && data.Columns.Contains(Fields.PT1)) { _entries = data.Rows.Cast<DataRow>() - .Select( - r => - new KeyValuePair<PerSecond, Second>(r.ParseDouble(Fields.EngineSpeed).RPMtoRad(), - r.ParseDouble(Fields.PT1).SI<Second>())) - .OrderBy(x => x.Key) - .ToList(); + .Select(r => new KeyValuePair<PerSecond, Second>(r.ParseDouble(Fields.EngineSpeed).RPMtoRad(), + r.ParseDouble(Fields.PT1).SI<Second>())) + .OrderBy(x => x.Key).ToList(); } else { _entries = data.Rows.Cast<DataRow>() - .Select( - r => new KeyValuePair<PerSecond, Second>(r.ParseDouble(0).RPMtoRad(), r.ParseDouble(3).SI<Second>())) - .OrderBy(x => x.Key) - .ToList(); + .Select(r => new KeyValuePair<PerSecond, Second>(r.ParseDouble(0).RPMtoRad(), r.ParseDouble(3).SI<Second>())) + .OrderBy(x => x.Key).ToList(); } } - private bool HeaderIsValid(DataColumnCollection columns) - { - return columns.Contains(Fields.EngineSpeed) && columns.Contains(Fields.PT1); - } - - /// <summary> - /// [rad/s] => [s] - /// </summary> - /// <param name="key">[rad/s]</param> - /// <returns>[s]</returns> public override Second Lookup(PerSecond key) { var index = 1; @@ -133,15 +129,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine private static class Fields { - /// <summary> - /// [rpm] engine speed - /// </summary> - public const string EngineSpeed = "engine speed"; - - /// <summary> - /// [s] time constant - /// </summary> public const string PT1 = "PT1"; + public const string EngineSpeed = "engine speed"; } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AMTShiftStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AMTShiftStrategy.cs index d2edb373da86ea2aa746a443c73ce742d589344c..3c30b7274508c8865bde7b69e26e5279364a4d60 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/AMTShiftStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/AMTShiftStrategy.cs @@ -56,7 +56,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Data.SkipGears = true; } - private bool SpeedTooLowForEngine(uint gear, PerSecond outAngularSpeed) { return (outAngularSpeed * Data.Gears[gear].Ratio).IsSmaller(DataBus.EngineIdleSpeed); @@ -71,7 +70,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl (outAngularSpeed * Data.Gears[gear].Ratio).IsGreaterOrEqual(DataBus.EngineN95hSpeed); } - public override uint Engage(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity) { while (NextGear > 1 && SpeedTooLowForEngine(NextGear, outAngularVelocity)) { @@ -165,7 +163,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return true; } - // normal shift when all requirements are fullfilled ------------------ var minimumShiftTimePassed = (lastShiftTime + Data.ShiftTime).IsSmallerOrEqual(absTime); if (!minimumShiftTimePassed) { @@ -257,26 +254,24 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Gearbox.Gear = tryNextGear; var response = (ResponseDryRun)Gearbox.Request(absTime, dt, outTorque, outAngularVelocity, true); Gearbox.Gear = tmpGear; - if (!(response is ResponseEngineSpeedTooLow)) { - inAngularVelocity = Data.Gears[tryNextGear].Ratio * outAngularVelocity; - inTorque = response.ClutchPowerRequest / inAngularVelocity; - - // if next gear supplied enough power reserve: take it - // otherwise take - if (!IsBelowDownShiftCurve(tryNextGear, inTorque, inAngularVelocity)) { - var fullLoadPower = response.EnginePowerRequest - response.DeltaFullLoad; - var reserve = 1 - response.EnginePowerRequest / fullLoadPower; - - if (reserve >= Data.TorqueReserve) { - currentGear = tryNextGear; - } + + inAngularVelocity = Data.Gears[tryNextGear].Ratio * outAngularVelocity; + inTorque = response.ClutchPowerRequest / inAngularVelocity; + + // if next gear supplied enough power reserve: take it + // otherwise take + if (!IsBelowDownShiftCurve(tryNextGear, inTorque, inAngularVelocity)) { + var fullLoadPower = response.EnginePowerRequest - response.DeltaFullLoad; + var reserve = 1 - response.EnginePowerRequest / fullLoadPower; + + if (reserve >= Data.TorqueReserve) { + currentGear = tryNextGear; } } } return currentGear; } - protected virtual uint DoCheckDownshift(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, NewtonMeter inTorque, PerSecond inAngularVelocity, uint currentGear) { diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs index 92981608182d131cf6b2dea3ee2e0eb0eb1437ba..a08e3ab4bbb175956267f94489c251cd19dde245 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Brakes.cs @@ -40,26 +40,23 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Brakes : StatefulVectoSimulationComponent<SimpleComponentState>, IPowerTrainComponent, ITnOutPort, + public class Brakes : StatefulProviderComponent<SimpleComponentState, ITnOutPort, ITnInPort, ITnOutPort>, + IPowerTrainComponent, ITnOutPort, ITnInPort, IBrakes { - protected ITnOutPort NextComponent; + public Watt BrakePower { get; set; } public Brakes(IVehicleContainer dataBus) : base(dataBus) {} - - public ITnInPort InPort() - { - return this; - } - - public ITnOutPort OutPort() + public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) { - return this; + BrakePower = 0.SI<Watt>(); + PreviousState.SetState(torque, angularVelocity, torque, angularVelocity); + return DataBus.DriverBehavior == DrivingBehavior.Halted && DataBus.VehicleStopped + ? NextComponent.Initialize(0.SI<NewtonMeter>(), 0.SI<PerSecond>()) + : NextComponent.Initialize(torque, angularVelocity); } - public Watt BrakePower { get; set; } - public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun = false) { var brakeTorque = 0.SI<NewtonMeter>(); @@ -83,21 +80,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return retVal; } - public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) - { - BrakePower = 0.SI<Watt>(); - PreviousState.SetState(torque, angularVelocity, torque, angularVelocity); - return DataBus.DriverBehavior == DrivingBehavior.Halted && DataBus.VehicleStopped - ? NextComponent.Initialize(0.SI<NewtonMeter>(), 0.SI<PerSecond>()) - : NextComponent.Initialize(torque, angularVelocity); - } - - - public void Connect(ITnOutPort other) - { - NextComponent = other; - } - protected override void DoWriteModalResults(IModalDataContainer container) { container[ModalResultField.P_brake_loss] = BrakePower; @@ -108,7 +90,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected override void DoCommitSimulationStep() { BrakePower = 0.SI<Watt>(); - AdvanceState(); + base.DoCommitSimulationStep(); } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs index 7a83449f43ce8599eb55edf164ff4fb60f5c9264..de044761e86e2a76e1b04cc9ca7f93ba87922c48 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs @@ -34,7 +34,6 @@ using System.IO; using System.Windows.Forms.VisualStyles; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.DataBus; diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs index b0dd61dfe904ac4875999873f7d78cf55f419d79..e5715462930140503ccd880c73d46e5d9f85b635 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Clutch.cs @@ -33,7 +33,6 @@ using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Connector.Ports; -using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.DataBus; @@ -43,11 +42,11 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Clutch : StatefulVectoSimulationComponent<SimpleComponentState>, IClutch, ITnOutPort, ITnInPort + public class Clutch : StatefulProviderComponent<SimpleComponentState, ITnOutPort, ITnInPort, ITnOutPort>, IClutch, + ITnOutPort, ITnInPort { private readonly PerSecond _idleSpeed; private readonly PerSecond _ratedSpeed; - protected ITnOutPort NextComponent; private const double ClutchEff = 1; private ClutchState _clutchState = ClutchState.ClutchSlipping; @@ -56,10 +55,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected Clutch(IVehicleContainer container) : base(container) {} - public Clutch(IVehicleContainer container, CombustionEngineData engineData, - ICombustionEngineIdleController idleController) - : base(container) + ICombustionEngineIdleController idleController) : base(container) { _idleSpeed = engineData.IdleSpeed; _ratedSpeed = engineData.FullLoadCurve.RatedSpeed; @@ -73,27 +70,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return _clutchState; } - public ITnInPort InPort() - { - return this; - } - - public ITnOutPort OutPort() - { - return this; - } - - public void Connect(ITnOutPort other) - { - NextComponent = other; - } - public ITnOutPort IdleControlPort { get { return NextComponent; } } - public virtual IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) { NewtonMeter torqueIn; @@ -150,28 +131,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return retVal; } - - protected override void DoWriteModalResults(IModalDataContainer container) - { - if (PreviousState.InAngularVelocity == null || CurrentState.InAngularVelocity == null) { - container[ModalResultField.P_clutch_out] = 0.SI<Watt>(); - container[ModalResultField.P_clutch_loss] = 0.SI<Watt>(); - } else { - var avgOutAngularVelocity = (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0; - var avgInAngularVelocity = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0; - container[ModalResultField.P_clutch_out] = CurrentState.OutTorque * avgOutAngularVelocity; - container[ModalResultField.P_clutch_loss] = CurrentState.InTorque * avgInAngularVelocity - - CurrentState.OutTorque * avgOutAngularVelocity; - //(CurrentState.InTorque - CurrentState.OutTorque) * avgInAngularVelocity; - } - } - - protected override void DoCommitSimulationStep() - { - AdvanceState(); - } - - private void AddClutchLoss(NewtonMeter torque, PerSecond angularVelocity, out NewtonMeter torqueIn, out PerSecond angularVelocityIn) { @@ -197,5 +156,20 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _clutchState = ClutchState.ClutchClosed; } } + + protected override void DoWriteModalResults(IModalDataContainer container) + { + if (PreviousState.InAngularVelocity == null || CurrentState.InAngularVelocity == null) { + container[ModalResultField.P_clutch_out] = 0.SI<Watt>(); + container[ModalResultField.P_clutch_loss] = 0.SI<Watt>(); + } else { + var avgOutAngularVelocity = (PreviousState.OutAngularVelocity + CurrentState.OutAngularVelocity) / 2.0; + var avgInAngularVelocity = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0; + container[ModalResultField.P_clutch_out] = CurrentState.OutTorque * avgOutAngularVelocity; + container[ModalResultField.P_clutch_loss] = CurrentState.InTorque * avgInAngularVelocity - + CurrentState.OutTorque * avgOutAngularVelocity; + //(CurrentState.InTorque - CurrentState.OutTorque) * avgInAngularVelocity; + } + } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs index f058ce1e323d1c757cd178ddde816627e8b47cb5..106687a6350b81515df6181176aa2edc714c2400 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CombustionEngine.cs @@ -72,7 +72,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl protected readonly Watt StationaryIdleFullLoadPower; - [ValidateObject] internal readonly CombustionEngineData ModelData; + internal readonly CombustionEngineData ModelData; protected IEngineAuxPort EngineAux; diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs index 60df00dc2c75486ddcdea1918f610c9e92855251..7a8cfa22ff762124bfda8fe425ed459b811d71e4 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs @@ -45,97 +45,16 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class CycleGearbox : StatefulVectoSimulationComponent<Gearbox.GearboxState>, IGearbox, ITnOutPort, ITnInPort, - IClutchInfo + public class CycleGearbox : StatefulProviderComponent<Gearbox.GearboxState, ITnOutPort, ITnInPort, ITnOutPort>, + IGearbox, ITnOutPort, ITnInPort, IClutchInfo { - /// <summary> - /// The next port. - /// </summary> - protected ITnOutPort NextComponent; + internal readonly GearboxData ModelData; - /// <summary> - /// The data and settings for the gearbox. - /// </summary> - [ValidateObject] internal readonly GearboxData ModelData; - - public bool ClutchClosed(Second absTime) - { - return DataBus.CycleData.LeftSample.Gear != 0; - } - - public CycleGearbox(IVehicleContainer container, GearboxData gearboxModelData) - : base(container) + public CycleGearbox(IVehicleContainer container, GearboxData gearboxModelData) : base(container) { ModelData = gearboxModelData; } - #region ITnInProvider - - public ITnInPort InPort() - { - return this; - } - - #endregion - - #region ITnOutProvider - - [DebuggerHidden] - public ITnOutPort OutPort() - { - return this; - } - - #endregion - - #region IGearboxCockpit - - /// <summary> - /// The current gear. - /// </summary> - public uint Gear { get; private set; } - - [DebuggerHidden] - public MeterPerSecond StartSpeed - { - get { return ModelData.StartSpeed; } - } - - [DebuggerHidden] - public MeterPerSquareSecond StartAcceleration - { - get { return ModelData.StartAcceleration; } - } - - public FullLoadCurve GearFullLoadCurve - { - get { return Gear == 0 ? null : ModelData.Gears[Gear].FullLoadCurve; } - } - - public Watt GearboxLoss() - { - //var outTorque = ModelData.Gears[Gear].LossMap.GetOutTorque(inAngularVelocity, inTorque, true); - //var torqueLoss = inTorque - outTorque * ModelData.Gears[Gear].Ratio; - - //return torqueLoss * inAngularVelocity; - - return (PreviousState.TransmissionTorqueLoss + - PreviousState.InertiaTorqueLossOut / ModelData.Gears[PreviousState.Gear].Ratio) * PreviousState.InAngularVelocity; - } - - #endregion - - #region ITnInPort - - public void Connect(ITnOutPort other) - { - NextComponent = other; - } - - #endregion - - #region ITnOutPort - public IResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity) { var dt = Constants.SimulationSettings.TargetTimeInterval; @@ -306,10 +225,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } } - #endregion - - #region VectoSimulationComponent - protected override void DoWriteModalResults(IModalDataContainer container) { container[ModalResultField.Gear] = Gear; @@ -337,8 +252,46 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } } } + base.DoCommitSimulationStep(); + } + + #region IGearboxCockpit + + /// <summary> + /// The current gear. + /// </summary> + public uint Gear { get; private set; } + + [DebuggerHidden] + public MeterPerSecond StartSpeed + { + get { return ModelData.StartSpeed; } + } + + [DebuggerHidden] + public MeterPerSquareSecond StartAcceleration + { + get { return ModelData.StartAcceleration; } + } + + public FullLoadCurve GearFullLoadCurve + { + get { return Gear == 0 ? null : ModelData.Gears[Gear].FullLoadCurve; } + } + + public Watt GearboxLoss() + { + return (PreviousState.TransmissionTorqueLoss + + PreviousState.InertiaTorqueLossOut / ModelData.Gears[PreviousState.Gear].Ratio) * PreviousState.InAngularVelocity; + } - AdvanceState(); + #endregion + + #region ICluchInfo + + public bool ClutchClosed(Second absTime) + { + return DataBus.CycleData.LeftSample.Gear != 0; } #endregion diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs index dccb11799781a4bf6c6b73a3e524a18323b883c2..b7bdbece7b45bd81079751c5f259a7652f40def3 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DefaultDriverStrategy.cs @@ -33,19 +33,13 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Windows.Markup; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; -using TUGraz.VectoCore.InputData.Impl; using TUGraz.VectoCore.Models.Connector.Ports.Impl; -using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.DataBus; using TUGraz.VectoCore.Models.SimulationComponent.Data; -using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.Utils; -using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData; - namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { @@ -119,103 +113,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return retVal; } - ///// <summary> - ///// Checks if Look Ahead Coasting triggers - ///// </summary> - //public Dictionary<string, object> LookAheadCoasting(Meter ds) - //{ - // var dict = new Dictionary<string, object>(); - - // // (1) & (2) : x_decelerationpoint - d_prev <= x_veh < x_decelerationpoint - // var v_veh = Driver.DataBus.CycleData.LeftSample.VehicleTargetSpeed; //Driver.DataBus.VehicleSpeed; - // var d_prev = 10 * Driver.DataBus.VehicleSpeed.ConvertTo().Kilo.Meter.Per.Hour.Value(); - // var lookaheadData = Driver.DataBus.LookAhead(d_prev.SI<Meter>()); - // var nextActions = new SortedDictionary<Meter, DrivingCycleData.DrivingCycleEntry>(); - // foreach (var entry in lookaheadData.Where(e => e.VehicleTargetSpeed <= v_veh)) { - // var nextTargetSpeed = entry.VehicleTargetSpeed; - // if (nextTargetSpeed < Driver.DataBus.VehicleSpeed) { - // var coastingDistance = Formulas.DecelerationDistance(Driver.DataBus.VehicleSpeed, nextTargetSpeed, - // Driver.DriverData.LookAheadCoasting.Deceleration); - // nextActions.Add(entry.Distance - coastingDistance, entry); - // } - // } - - // var dec = nextActions.FirstOrDefault().Value; - - // // (4) v_veh < v_max_deceleration * 0.98 - // if (dec != null) { - // var x_dec = dec.Distance; - // dict["x_dec"] = x_dec.Value(); - - // var x_delta = x_dec - Driver.DataBus.Distance; - // dict["x_delta"] = x_delta.Value(); - - // var v_target = dec.VehicleTargetSpeed; - // dict["v_target"] = v_target.Value(); - - // var x_max_deceleration = Driver.ComputeDecelerationDistance(v_target); - // dict["x_max_deceleration"] = x_max_deceleration.Value(); - // var coastingPossible = x_delta >= x_max_deceleration * 0.98; - // dict["CoastingAllowed"] = coastingPossible ? 1 : 0; - - // // 3. CDP > DF_coasting - // if (coastingPossible) { - // var m = Driver.DataBus.TotalMass; - // var g = Physics.GravityAccelleration; - // var h_target = dec.Altitude; - // dict["h_target"] = h_target.Value(); - - // var h_vehicle = Driver.DataBus.Altitude; - // dict["h_vehicle"] = h_vehicle.Value(); - - // var E_kin_veh = m * v_veh * v_veh / 2; - // var E_kin_target = m * v_target * v_target / 2; - // var E_pot_target = m * g * h_target; - // var E_pot_veh = m * g * h_vehicle; - // dict["E_kin_veh"] = E_kin_veh.Value(); - // dict["E_kin_target"] = E_kin_target.Value(); - // dict["E_pot_target"] = E_pot_target.Value(); - // dict["E_pot_veh"] = E_pot_veh.Value(); - - // var delta_E = (E_kin_veh + E_pot_veh) - (E_kin_target + E_pot_target); - // dict["delta_E"] = delta_E.Value(); - - // var F_dec_average = delta_E / x_delta; - // dict["F_dec_average"] = F_dec_average.Value(); - - // //var avgVelocity = (v_veh + v_target) / 2; - // //var acc = (v_target - v_veh) * (avgVelocity / x_delta); - // var F_air = Driver.DataBus.AirDragResistance(v_veh, v_target); - // dict["F_air"] = F_air.Value(); - - // var F_roll = Driver.DataBus.RollingResistance(((h_target - h_vehicle) / x_delta).Value().SI<Radian>()); - // dict["F_roll"] = F_roll.Value(); - - // var F_enginedrag = Driver.DataBus.EngineDragPower(Driver.DataBus.EngineSpeed) / v_veh; - // dict["F_enginedrag"] = F_enginedrag.Value(); - - // var F_loss_gb = Driver.DataBus.GearboxLoss(Driver.DataBus.EngineSpeed, Driver.DataBus.EngineTorque) / v_veh; - // dict["F_loss_gb"] = F_loss_gb.Value(); - - // // todo mk-2016-05-11 calculate ra loss - // var F_loss_ra = 0.SI<Newton>(); - // dict["F_loss_ra"] = F_loss_ra.Value(); - - // var F_coasting = F_enginedrag - F_air - F_roll - F_loss_gb - F_loss_ra; - // dict["F_coasting"] = F_coasting.Value(); - - // var CDP = F_dec_average / -F_coasting; - // dict["CDP"] = CDP.Value(); - - // var DF_coasting = LACDecisionFactor.Lookup(v_target, v_veh - v_target); - // dict["DF_coasting"] = DF_coasting; - - // dict["EnableCoasting"] = CDP > DF_coasting ? 1 : 0; - // } - // } - // return dict; - //} - public IResponse Request(Second absTime, Second dt, MeterPerSecond targetVelocity, Radian gradient) { Driver.DriverBehavior = DrivingBehavior.Halted; @@ -363,7 +260,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return coastingDistance; } - public bool OverspeedAllowed(Radian gradient, MeterPerSecond velocity) { return Driver.DriverData.OverSpeedEcoRoll.Mode == DriverMode.Overspeed && @@ -468,7 +364,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { protected override IResponse DoHandleRequest(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { - IResponse response = null; + IResponse response; Driver.DriverBehavior = DrivingBehavior.Driving; var velocity = targetVelocity; @@ -583,7 +479,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } protected BrakingPhase Phase; - protected bool RetryDistanceExceeded = false; + protected bool RetryDistanceExceeded; protected override IResponse DoHandleRequest(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient) { diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs index 0ca0f5565473c9fd802623be4cd0e7e4da29576c..f216e777b9eb816ffc915a124f548a474b5b3f30 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DistanceBasedDrivingCycle.cs @@ -40,7 +40,6 @@ using TUGraz.VectoCore.Models.Connector.Ports; using TUGraz.VectoCore.Models.Connector.Ports.Impl; using TUGraz.VectoCore.Models.Simulation; using TUGraz.VectoCore.Models.Simulation.Data; -using TUGraz.VectoCore.Models.Simulation.DataBus; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.Utils; @@ -50,17 +49,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// Class representing one Distance Based Driving Cycle /// </summary> - public sealed class DistanceBasedDrivingCycle : - StatefulVectoSimulationComponent<DistanceBasedDrivingCycle.DrivingCycleState>, IDrivingCycle, ISimulationOutPort, - IDrivingCycleInPort, IDisposable + public sealed class DistanceBasedDrivingCycle : StatefulProviderComponent + <DistanceBasedDrivingCycle.DrivingCycleState, ISimulationOutPort, IDrivingCycleInPort, IDrivingCycleOutPort>, + IDrivingCycle, ISimulationOutPort, IDrivingCycleInPort, IDisposable { private const double LookaheadTimeSafetyMargin = 1.5; private readonly DrivingCycleData _data; - internal readonly DrivingCycleEnumerator CycleIntervalIterator; - - private IDrivingCycleOutPort _nextComponent; - private bool _intervalProlonged; public DistanceBasedDrivingCycle(IVehicleContainer container, DrivingCycleData cycle) : base(container) @@ -79,50 +74,26 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState = PreviousState.Clone(); } - #region IDrivingCycleInProvider - - public IDrivingCycleInPort InPort() + public IResponse Initialize() { - return this; - } - - #endregion - - #region ISimulationOutProvider + if (CycleIntervalIterator.LeftSample.VehicleTargetSpeed.IsEqual(0)) { + var retVal = NextComponent.Initialize(DataBus.StartSpeed, + CycleIntervalIterator.LeftSample.RoadGradient, DataBus.StartAcceleration); + if (!(retVal is ResponseSuccess)) { + throw new UnexpectedResponseException("Couldn't find start gear.", retVal); + } + } - public ISimulationOutPort OutPort() - { - return this; + return NextComponent.Initialize(CycleIntervalIterator.LeftSample.VehicleTargetSpeed, + CycleIntervalIterator.LeftSample.RoadGradient); } - #endregion - - #region IDrivingCycleInPort - - public void Connect(IDrivingCycleOutPort other) + public IResponse Request(Second absTime, Second dt) { - _nextComponent = other; + throw new NotImplementedException("Distance Based Driving Cycle does not support time requests."); } - #endregion - - #region ISimulationOutPort - public IResponse Request(Second absTime, Meter ds) - { - var retVal = DoHandleRequest(absTime, ds); - CurrentState.Response = retVal; - return retVal; - } - - /// <summary> - /// Does the handle request. - /// </summary> - /// <param name="absTime">The abs time.</param> - /// <param name="ds">The ds.</param> - /// <returns></returns> - /// <exception cref="VectoSimulationException">Stopping Time only allowed when target speed is zero!</exception> - private IResponse DoHandleRequest(Second absTime, Meter ds) { if (CycleIntervalIterator.LeftSample.Distance.IsEqual(PreviousState.Distance.Value())) { // exactly on an entry in the cycle... @@ -145,39 +116,45 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } } } - return DriveTimeInterval(absTime, dt); + CurrentState.Response = DriveTimeInterval(absTime, dt); + return CurrentState.Response; } } if (CycleIntervalIterator.LastEntry && PreviousState.Distance.IsEqual(CycleIntervalIterator.RightSample.Distance)) { - return new ResponseCycleFinished(); + CurrentState.Response = new ResponseCycleFinished(); + return CurrentState.Response; } var nextSpeedChange = GetSpeedChangeWithinSimulationInterval(ds); if (nextSpeedChange == null || ds.IsSmallerOrEqual(nextSpeedChange - PreviousState.Distance)) { if (nextSpeedChange == null || DataBus.VehicleSpeed.IsEqual(0.SI<MeterPerSecond>())) { - return DriveDistance(absTime, ds); + CurrentState.Response = DriveDistance(absTime, ds); + return CurrentState.Response; } var remainingDistance = nextSpeedChange - PreviousState.Distance - ds; var estimatedRemainingTime = remainingDistance / DataBus.VehicleSpeed; if (_intervalProlonged || remainingDistance.IsEqual(0.SI<Meter>()) || estimatedRemainingTime.IsGreater(Constants.SimulationSettings.LowerBoundTimeInterval)) { - return DriveDistance(absTime, ds); + CurrentState.Response = DriveDistance(absTime, ds); + return CurrentState.Response; } Log.Debug("Extending distance by {0} to next sample point. ds: {1} new ds: {2}", remainingDistance, ds, nextSpeedChange - PreviousState.Distance); _intervalProlonged = true; - return new ResponseDrivingCycleDistanceExceeded { + CurrentState.Response = new ResponseDrivingCycleDistanceExceeded { Source = this, MaxDistance = nextSpeedChange - PreviousState.Distance }; + return CurrentState.Response; } // only drive until next sample point in cycle with speed change Log.Debug("Limiting distance to next sample point {0}", CycleIntervalIterator.RightSample.Distance - PreviousState.Distance); - return new ResponseDrivingCycleDistanceExceeded { + CurrentState.Response = new ResponseDrivingCycleDistanceExceeded { Source = this, MaxDistance = nextSpeedChange - PreviousState.Distance }; + return CurrentState.Response; } private IResponse DriveTimeInterval(Second absTime, Second dt) @@ -187,7 +164,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState.Gradient = ComputeGradient(0.SI<Meter>()); CurrentState.VehicleTargetSpeed = CycleIntervalIterator.LeftSample.VehicleTargetSpeed; - return _nextComponent.Request(absTime, dt, CycleIntervalIterator.LeftSample.VehicleTargetSpeed, CurrentState.Gradient); + return NextComponent.Request(absTime, dt, CycleIntervalIterator.LeftSample.VehicleTargetSpeed, CurrentState.Gradient); } private IResponse DriveDistance(Second absTime, Meter ds) @@ -208,16 +185,57 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState.VehicleTargetSpeed = CycleIntervalIterator.LeftSample.VehicleTargetSpeed; CurrentState.Gradient = ComputeGradient(ds); - var retVal = _nextComponent.Request(absTime, ds, CurrentState.VehicleTargetSpeed, CurrentState.Gradient); + var retVal = NextComponent.Request(absTime, ds, CurrentState.VehicleTargetSpeed, CurrentState.Gradient); retVal.Switch() .Case<ResponseFailTimeInterval>( r => { - retVal = _nextComponent.Request(absTime, r.DeltaT, 0.SI<MeterPerSecond>(), CurrentState.Gradient); - retVal = _nextComponent.Request(absTime, ds, CurrentState.VehicleTargetSpeed, CurrentState.Gradient); + retVal = NextComponent.Request(absTime, r.DeltaT, 0.SI<MeterPerSecond>(), CurrentState.Gradient); + retVal = NextComponent.Request(absTime, ds, CurrentState.VehicleTargetSpeed, CurrentState.Gradient); }); return retVal; } + protected override void DoWriteModalResults(IModalDataContainer container) + { + container[ModalResultField.dist] = CurrentState.Distance; // (CurrentState.Distance + PreviousState.Distance) / 2.0; + container[ModalResultField.simulationDistance] = CurrentState.SimulationDistance; + container[ModalResultField.v_targ] = CurrentState.VehicleTargetSpeed; + container[ModalResultField.grad] = (Math.Tan(CurrentState.Gradient.Value()) * 100).SI<Scalar>(); + container[ModalResultField.altitude] = CurrentState.Altitude; + } + + protected override void DoCommitSimulationStep() + { + if (!(CurrentState.Response is ResponseSuccess)) { + throw new VectoSimulationException("Previous request did not succeed!"); + } + + PreviousState = CurrentState; + CurrentState = CurrentState.Clone(); + _intervalProlonged = false; + + if (!CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) && + CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(PreviousState.WaitTime)) { + // we needed to stop at the current interval in the cycle and have already waited enough time, move on.. + CycleIntervalIterator.MoveNext(); + } + + // separately test for equality and greater than to have tolerance for equality comparison + if (CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0)) { + while (CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) && + CurrentState.Distance.IsGreaterOrEqual(CycleIntervalIterator.RightSample.Distance) && + !CycleIntervalIterator.LastEntry) { + // we have reached the end of the current interval in the cycle, move on... + CycleIntervalIterator.MoveNext(); + } + } else { + if (CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(PreviousState.WaitTime)) { + // we needed to stop at the current interval in the cycle and have already waited enough time, move on.. + CycleIntervalIterator.MoveNext(); + } + } + } + private Radian ComputeGradient(Meter ds) { //var leftSamplePoint = CycleIntervalIterator.LeftSample; @@ -260,25 +278,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return null; } - public IResponse Request(Second absTime, Second dt) - { - throw new NotImplementedException("Distance Based Driving Cycle does not support time requests."); - } - - public IResponse Initialize() - { - if (CycleIntervalIterator.LeftSample.VehicleTargetSpeed.IsEqual(0)) { - var retVal = _nextComponent.Initialize(DataBus.StartSpeed, - CycleIntervalIterator.LeftSample.RoadGradient, DataBus.StartAcceleration); - if (!(retVal is ResponseSuccess)) { - throw new UnexpectedResponseException("Couldn't find start gear.", retVal); - } - } - - return _nextComponent.Initialize(CycleIntervalIterator.LeftSample.VehicleTargetSpeed, - CycleIntervalIterator.LeftSample.RoadGradient); - } - /// <summary> /// Progress of the distance in the driving cycle. /// </summary> @@ -295,53 +294,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public Meter CycleStartDistance { get; internal set; } - #endregion - - #region VectoSimulationComponent - - protected override void DoWriteModalResults(IModalDataContainer container) - { - container[ModalResultField.dist] = CurrentState.Distance; // (CurrentState.Distance + PreviousState.Distance) / 2.0; - container[ModalResultField.simulationDistance] = CurrentState.SimulationDistance; - container[ModalResultField.v_targ] = CurrentState.VehicleTargetSpeed; - container[ModalResultField.grad] = (Math.Tan(CurrentState.Gradient.Value()) * 100).SI<Scalar>(); - container[ModalResultField.altitude] = CurrentState.Altitude; - } - - protected override void DoCommitSimulationStep() - { - if (!(CurrentState.Response is ResponseSuccess)) { - throw new VectoSimulationException("Previous request did not succeed!"); - } - - PreviousState = CurrentState; - CurrentState = CurrentState.Clone(); - _intervalProlonged = false; - - if (!CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) && - CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(PreviousState.WaitTime)) { - // we needed to stop at the current interval in the cycle and have already waited enough time, move on.. - CycleIntervalIterator.MoveNext(); - } - - // separately test for equality and greater than to have tolerance for equality comparison - if (CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0)) { - while (CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(0) && - CurrentState.Distance.IsGreaterOrEqual(CycleIntervalIterator.RightSample.Distance) && - !CycleIntervalIterator.LastEntry) { - // we have reached the end of the current interval in the cycle, move on... - CycleIntervalIterator.MoveNext(); - } - } else { - if (CycleIntervalIterator.LeftSample.StoppingTime.IsEqual(PreviousState.WaitTime)) { - // we needed to stop at the current interval in the cycle and have already waited enough time, move on.. - CycleIntervalIterator.MoveNext(); - } - } - } - - #endregion - public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance) { var retVal = new List<DrivingCycleData.DrivingCycleEntry>(); @@ -406,7 +358,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl while (myIterator.RightSample.Distance < absDistance) { myIterator.MoveNext(); } - + return InterpolateCycleEntry(absDistance, myIterator.RightSample); } @@ -428,11 +380,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl private DrivingCycleData.DrivingCycleEntry ExtrapolateCycleEntry(Meter absDistance, DrivingCycleData.DrivingCycleEntry lookahead) { - var retVal = new DrivingCycleData.DrivingCycleEntry(lookahead) - { + var retVal = new DrivingCycleData.DrivingCycleEntry(lookahead) { Distance = absDistance, Altitude = lookahead.Altitude + lookahead.RoadGradient * (absDistance - lookahead.Distance), - //VectoMath.Interpolate(CurrentState.Distance, lookahead.Distance, CurrentState.Altitude,lookahead.Altitude, absDistance) }; retVal.RoadGradient = @@ -449,7 +399,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl internal void SetDriveOffDistance(Meter startDistance) { while (CycleIntervalIterator.MoveNext() && CycleIntervalIterator.RightSample.Distance < startDistance) {} - //CycleIntervalIterator.MoveNext(); PreviousState.Distance = startDistance; CycleStartDistance = startDistance; } @@ -457,7 +406,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public sealed class DrivingCycleEnumerator : IEnumerator<DrivingCycleData.DrivingCycleEntry> { private int _currentCycleIndex; - private DrivingCycleData _data; + private readonly DrivingCycleData _data; public DrivingCycleEnumerator(DrivingCycleData data) { @@ -524,7 +473,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public void Dispose() {} } - public class DrivingCycleState + public sealed class DrivingCycleState { public DrivingCycleState Clone() { diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs index beec23dfcf8fa4730b36678b7b654ce1b82a3c3c..fbb2929d6882802e7f9c043aefb5c953786a9a59 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Driver.cs @@ -30,7 +30,6 @@ */ using System; -using System.Linq; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; @@ -46,12 +45,10 @@ using DriverData = TUGraz.VectoCore.Models.SimulationComponent.Data.DriverData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Driver : StatefulVectoSimulationComponent<Driver.DriverState>, IDriver, IDrivingCycleOutPort, - IDriverDemandInPort, IDriverActions, - IDriverInfo + public class Driver : + StatefulProviderComponent<Driver.DriverState, IDrivingCycleOutPort, IDriverDemandInPort, IDriverDemandOutPort>, + IDriver, IDrivingCycleOutPort, IDriverDemandInPort, IDriverActions, IDriverInfo { - protected IDriverDemandOutPort NextComponent; - public DriverData DriverData { get; protected set; } protected IDriverStrategy DriverStrategy; @@ -64,16 +61,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl strategy.Driver = this; } - public IDriverDemandInPort InPort() - { - return this; - } - - public void Connect(IDriverDemandOutPort other) - { - NextComponent = other; - } - public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient) { DriverBehavior = vehicleSpeed.IsEqual(0) ? DrivingBehavior.Halted : DrivingBehavior.Driving; @@ -586,13 +573,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return response; }, criterion: response => { - if (response is ResponseEngineSpeedTooLow) { - LogManager.EnableLogging(); - Log.Debug("Got EngineSpeedTooLow during SearchOperatingPoint. Aborting!"); - LogManager.DisableLogging(); - //throw new VectoEngineSpeedTooLowException("EngineSpeed too low during search."); - } - var r = (ResponseDryRun)response; delta = actionRoll ? r.GearboxPowerRequest : (coastingOrRoll ? r.DeltaDragLoad : r.DeltaFullLoad); return delta.Value(); @@ -720,11 +700,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return retVal; } - public IDrivingCycleOutPort OutPort() - { - return this; - } - protected override void DoWriteModalResults(IModalDataContainer container) { container[ModalResultField.acc] = CurrentState.Acceleration; diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DummyRetarder.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DummyRetarder.cs index 88b948d0b129cf1fcadfa80a811efae1b6b5ca9b..11c80be8909b34081cf0231983c6dded921d8527 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/DummyRetarder.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/DummyRetarder.cs @@ -38,26 +38,15 @@ using TUGraz.VectoCore.OutputData; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class DummyRetarder : StatefulVectoSimulationComponent<SimpleComponentState>, IPowerTrainComponent, ITnInPort, - ITnOutPort + public class DummyRetarder : StatefulProviderComponent<SimpleComponentState, ITnOutPort, ITnInPort, ITnOutPort>, + IPowerTrainComponent, ITnInPort, ITnOutPort { - protected ITnOutPort NextComponent; - public DummyRetarder(IVehicleContainer dataBus) : base(dataBus) {} - public ITnInPort InPort() - { - return this; - } - - public ITnOutPort OutPort() - { - return this; - } - - public void Connect(ITnOutPort other) + public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) { - NextComponent = other; + PreviousState.SetState(torque, angularVelocity, torque, angularVelocity); + return NextComponent.Initialize(torque, angularVelocity); } public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun = false) @@ -66,12 +55,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return NextComponent.Request(absTime, dt, torque, angularVelocity, dryRun); } - public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) - { - PreviousState.SetState(torque, angularVelocity, torque, angularVelocity); - return NextComponent.Initialize(torque, angularVelocity); - } - protected override void DoWriteModalResults(IModalDataContainer container) { container[ModalResultField.P_ret_loss] = 0.SI<Watt>(); @@ -83,10 +66,5 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl (CurrentState.InAngularVelocity + PreviousState.InAngularVelocity) / 2.0; } } - - protected override void DoCommitSimulationStep() - { - AdvanceState(); - } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs index 86cab7ebb7ee32036489d58deab98691a8b866c2..48f8c0ed5f50f8fcb747c215f55cbf8853f9b83f 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Gearbox.cs @@ -47,14 +47,9 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Gearbox : StatefulVectoSimulationComponent<Gearbox.GearboxState>, IGearbox, ITnOutPort, ITnInPort, - IClutchInfo + public class Gearbox : StatefulProviderComponent<Gearbox.GearboxState, ITnOutPort, ITnInPort, ITnOutPort>, IGearbox, + ITnOutPort, ITnInPort, IClutchInfo { - /// <summary> - /// The next port. - /// </summary> - protected ITnOutPort NextComponent; - /// <summary> /// The data and settings for the gearbox. /// </summary> @@ -94,63 +89,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl LastUpshift = -double.MaxValue.SI<Second>(); } - #region ITnInProvider - - public ITnInPort InPort() - { - return this; - } - - #endregion - - #region ITnOutProvider - - [DebuggerHidden] - public ITnOutPort OutPort() - { - return this; - } - - #endregion - - #region IGearboxCockpit - - /// <summary> - /// The current gear. - /// </summary> - public uint Gear { get; set; } - - [DebuggerHidden] - public MeterPerSecond StartSpeed - { - get { return ModelData.StartSpeed; } - } - - [DebuggerHidden] - public MeterPerSquareSecond StartAcceleration - { - get { return ModelData.StartAcceleration; } - } - - public FullLoadCurve GearFullLoadCurve - { - get { return Gear == 0 ? null : ModelData.Gears[Gear].FullLoadCurve; } - } - - public Watt GearboxLoss() - { - //var outTorque = ModelData.Gears[Gear].LossMap.GetOutTorque(inAngularVelocity, inTorque, true); - //var torqueLoss = inTorque - outTorque * ModelData.Gears[Gear].Ratio; - - //return torqueLoss * inAngularVelocity; - return (PreviousState.TransmissionTorqueLoss + - PreviousState.InertiaTorqueLossOut / ModelData.Gears[PreviousState.Gear].Ratio) * PreviousState.InAngularVelocity; - } - - #endregion - - #region ITnOutPort - public IResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity) { var absTime = 0.SI<Second>(); @@ -436,19 +374,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return response; } - #endregion - - #region ITnInPort - - public void Connect(ITnOutPort other) - { - NextComponent = other; - } - - #endregion - - #region VectoSimulationComponent - protected override void DoWriteModalResults(IModalDataContainer container) { //var avgAngularSpeed = ((PreviousState.InAngularVelocity * ModelData.Gears[CurrentState.Gear].Ratio / @@ -483,7 +408,41 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl Disengaged = true; _engageTime = -double.MaxValue.SI<Second>(); } - AdvanceState(); + base.DoCommitSimulationStep(); + } + + #region IGearboxCockpit + + /// <summary> + /// The current gear. + /// </summary> + public uint Gear { get; set; } + + [DebuggerHidden] + public MeterPerSecond StartSpeed + { + get { return ModelData.StartSpeed; } + } + + [DebuggerHidden] + public MeterPerSquareSecond StartAcceleration + { + get { return ModelData.StartAcceleration; } + } + + public FullLoadCurve GearFullLoadCurve + { + get { return Gear == 0 ? null : ModelData.Gears[Gear].FullLoadCurve; } + } + + public Watt GearboxLoss() + { + //var outTorque = ModelData.Gears[Gear].LossMap.GetOutTorque(inAngularVelocity, inTorque, true); + //var torqueLoss = inTorque - outTorque * ModelData.Gears[Gear].Ratio; + + //return torqueLoss * inAngularVelocity; + return (PreviousState.TransmissionTorqueLoss + + PreviousState.InertiaTorqueLossOut / ModelData.Gears[PreviousState.Gear].Ratio) * PreviousState.InAngularVelocity; } #endregion diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs index 95d534a251891b46f1149b5ef9fd23fc5ad88367..6dfaafcbbcaa9e5165d981e8063fdb89738a8272 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/PowertrainDrivingCycle.cs @@ -238,12 +238,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Second time) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } } @@ -319,7 +319,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// Driving Cycle for the Measured Speed Gear driving cycle. /// </summary> - public class MeasuredSpeedDrivingCycle : StatefulVectoSimulationComponent<MeasuredSpeedDrivingCycle.DrivingCycleState>, + public class MeasuredSpeedDrivingCycle : + StatefulProviderComponent + <MeasuredSpeedDrivingCycle.DrivingCycleState, ISimulationOutPort, IDriverDemandInPort, IDriverDemandOutPort>, IDriverInfo, IDrivingCycleInfo, IMileageCounter, IDriverDemandInProvider, IDriverDemandInPort, ISimulationOutProvider, ISimulationOutPort { @@ -340,7 +342,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } protected DrivingCycleData Data; - protected IDriverDemandOutPort NextComponent; private bool _isInitializing; protected IEnumerator<DrivingCycleData.DrivingCycleEntry> RightSample { get; set; } protected IEnumerator<DrivingCycleData.DrivingCycleEntry> LeftSample { get; set; } @@ -371,25 +372,24 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState = PreviousState.Clone(); } - #region IDriverDemandInProvider - - public IDriverDemandInPort InPort() + public IResponse Initialize() { - return this; - } + var first = Data.Entries.First(); - #endregion + AbsTime = first.Time; - #region ISimulationOutProvider + _isInitializing = true; - public ISimulationOutPort OutPort() - { - return this; - } + var response = NextComponent.Initialize(first.VehicleTargetSpeed, first.RoadGradient); + if (!(response is ResponseSuccess)) { + throw new UnexpectedResponseException("Couldn't find start gear.", response); + } - #endregion + _isInitializing = false; - #region ISimulationOutPort + response.AbsTime = AbsTime; + return response; + } public IResponse Request(Second absTime, Meter ds) { @@ -481,23 +481,25 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return response; } - public IResponse Initialize() + protected override void DoWriteModalResults(IModalDataContainer container) { - var first = Data.Entries.First(); - - AbsTime = first.Time; - - _isInitializing = true; + container[ModalResultField.dist] = CurrentState.Distance; + container[ModalResultField.simulationDistance] = CurrentState.SimulationDistance; + container[ModalResultField.v_targ] = LeftSample.Current.VehicleTargetSpeed; + container[ModalResultField.grad] = LeftSample.Current.RoadGradientPercent; + container[ModalResultField.altitude] = LeftSample.Current.Altitude; + container[ModalResultField.acc] = CurrentState.Acceleration; + } - var response = NextComponent.Initialize(first.VehicleTargetSpeed, first.RoadGradient); - if (!(response is ResponseSuccess)) { - throw new UnexpectedResponseException("Couldn't find start gear.", response); + protected override void DoCommitSimulationStep() + { + if ((RightSample.Current == null) || AbsTime.IsGreaterOrEqual(RightSample.Current.Time)) { + RightSample.MoveNext(); + LeftSample.MoveNext(); } - _isInitializing = false; - - response.AbsTime = AbsTime; - return response; + PreviousState = CurrentState; + CurrentState = CurrentState.Clone(); } public string CycleName @@ -510,32 +512,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl get { return AbsTime == null ? 0 : AbsTime.Value() / Data.Entries.Last().Time.Value(); } } - #endregion - - #region IDriverDemandInPort - - public void Connect(IDriverDemandOutPort other) - { - NextComponent = other; - } - - #endregion - - #region VectoSimulationComponent - - protected override void DoCommitSimulationStep() - { - if ((RightSample.Current == null) || AbsTime.IsGreaterOrEqual(RightSample.Current.Time)) { - RightSample.MoveNext(); - LeftSample.MoveNext(); - } - - PreviousState = CurrentState; - CurrentState = CurrentState.Clone(); - } - - #endregion - public CycleData CycleData { get @@ -567,22 +543,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Meter lookaheadDistance) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public IReadOnlyList<DrivingCycleData.DrivingCycleEntry> LookAhead(Second time) { - throw new System.NotImplementedException(); - } - - protected override void DoWriteModalResults(IModalDataContainer container) - { - container[ModalResultField.dist] = CurrentState.Distance; - container[ModalResultField.simulationDistance] = CurrentState.SimulationDistance; - container[ModalResultField.v_targ] = LeftSample.Current.VehicleTargetSpeed; - container[ModalResultField.grad] = LeftSample.Current.RoadGradientPercent; - container[ModalResultField.altitude] = LeftSample.Current.Altitude; - container[ModalResultField.acc] = CurrentState.Acceleration; + throw new NotImplementedException(); } public bool VehicleStopped diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Retarder.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Retarder.cs index 68db358a8c3446be766920faade9930b8759c2e1..3797ed6a0a2597163dd720fd526ba2ef2d7f3bce 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Retarder.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Retarder.cs @@ -43,10 +43,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl /// <summary> /// Retarder component. /// </summary> - public class Retarder : StatefulVectoSimulationComponent<SimpleComponentState>, IPowerTrainComponent, ITnInPort, + public class Retarder : StatefulProviderComponent<SimpleComponentState, ITnOutPort, ITnInPort, ITnOutPort>, + IPowerTrainComponent, ITnInPort, ITnOutPort { - protected ITnOutPort NextComponent; private readonly RetarderLossMap _lossMap; private readonly double _ratio; @@ -62,6 +62,24 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _ratio = ratio; } + public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) + { + var retarderTorqueLoss = _lossMap.RetarderLoss(angularVelocity * _ratio) / _ratio; + PreviousState.SetState(torque + retarderTorqueLoss, angularVelocity, torque, angularVelocity); + return NextComponent.Initialize(PreviousState.InTorque, PreviousState.InAngularVelocity); + } + + public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun = false) + { + if (angularVelocity == null) { + return NextComponent.Request(absTime, dt, torque, null, dryRun); + } + var avgAngularSpeed = (PreviousState.InAngularVelocity + angularVelocity) / 2.0; + var retarderTorqueLoss = _lossMap.RetarderLoss(avgAngularSpeed * _ratio) / _ratio; + CurrentState.SetState(torque + retarderTorqueLoss, angularVelocity, torque, angularVelocity); + return NextComponent.Request(absTime, dt, CurrentState.InTorque, CurrentState.InAngularVelocity, dryRun); + } + protected override void DoWriteModalResults(IModalDataContainer container) { var avgAngularSpeed = (PreviousState.InAngularVelocity + CurrentState.InAngularVelocity) / 2.0; @@ -82,40 +100,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl CurrentState.OutAngularVelocity.AsRPM, _lossMap.MinSpeed.AsRPM, _lossMap.MaxSpeed.AsRPM, _ratio); } } - AdvanceState(); - } - - public ITnInPort InPort() - { - return this; - } - - public ITnOutPort OutPort() - { - return this; - } - - public void Connect(ITnOutPort other) - { - NextComponent = other; - } - - public IResponse Request(Second absTime, Second dt, NewtonMeter torque, PerSecond angularVelocity, bool dryRun = false) - { - if (angularVelocity == null) { - return NextComponent.Request(absTime, dt, torque, null, dryRun); - } - var avgAngularSpeed = (PreviousState.InAngularVelocity + angularVelocity) / 2.0; - var retarderTorqueLoss = _lossMap.RetarderLoss(avgAngularSpeed * _ratio) / _ratio; - CurrentState.SetState(torque + retarderTorqueLoss, angularVelocity, torque, angularVelocity); - return NextComponent.Request(absTime, dt, CurrentState.InTorque, CurrentState.InAngularVelocity, dryRun); - } - - public IResponse Initialize(NewtonMeter torque, PerSecond angularVelocity) - { - var retarderTorqueLoss = _lossMap.RetarderLoss(angularVelocity * _ratio) / _ratio; - PreviousState.SetState(torque + retarderTorqueLoss, angularVelocity, torque, angularVelocity); - return NextComponent.Initialize(PreviousState.InTorque, PreviousState.InAngularVelocity); + base.DoCommitSimulationStep(); } } } \ No newline at end of file diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index 02596feeb2bcd22e6ddd56b3d277e31d0ce6041c..1a6f138c55412228ee3d74212d32774784eaf6df 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -43,13 +43,11 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Vehicle : StatefulVectoSimulationComponent<Vehicle.VehicleState>, IVehicle, IMileageCounter, IFvInPort, + public class Vehicle : StatefulProviderComponent<Vehicle.VehicleState, IDriverDemandOutPort, IFvInPort, IFvOutPort>, + IVehicle, IMileageCounter, IFvInPort, IDriverDemandOutPort { - //private readonly CrossWindCorrectionCurve _airResistanceCurve; - [ValidateObject] internal readonly VehicleData ModelData; - - protected IFvOutPort NextComponent; + internal readonly VehicleData ModelData; public Vehicle(IVehicleContainer container, VehicleData modelData) : base(container) { @@ -118,51 +116,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return retval; } - public void Connect(IFvOutPort other) - { - NextComponent = other; - } - - public Meter Distance - { - get { return PreviousState.Distance; } - } - - public MeterPerSecond VehicleSpeed - { - get { return PreviousState.Velocity; } - } - - public bool VehicleStopped - { - get { return PreviousState.Velocity.IsEqual(0.SI<MeterPerSecond>(), 0.01.SI<MeterPerSecond>()); } - } - - public Kilogram VehicleMass - { - get { return ModelData.TotalCurbWeight(); } - } - - public Kilogram VehicleLoading - { - get { return ModelData.Loading; } - } - - public Kilogram TotalMass - { - get { return ModelData.TotalVehicleWeight(); } - } - - public IFvInPort InPort() - { - return this; - } - - public IDriverDemandOutPort OutPort() - { - return this; - } - protected override void DoWriteModalResults(IModalDataContainer container) { var averageVelocity = (PreviousState.Velocity + CurrentState.Velocity) / 2.0; @@ -187,11 +140,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } } - protected override void DoCommitSimulationStep() - { - AdvanceState(); - } - public Newton RollingResistance(Radian gradient) { var weight = ModelData.TotalVehicleWeight(); @@ -229,16 +177,41 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return result; } - //public Newton AirDragResistance(MeterPerSecond previousVelocity, MeterPerSquareSecond acceleration, Second dt) - //{ - // return AirDragResistance(previousVelocity, previousVelocity + acceleration * dt); - //} - private Watt ComputeAirDragPowerLoss(MeterPerSecond v1, MeterPerSecond v2) { return ModelData.CrossWindCorrectionCurve.AverageAirDragPowerLoss(v1, v2); } + public Meter Distance + { + get { return PreviousState.Distance; } + } + + public MeterPerSecond VehicleSpeed + { + get { return PreviousState.Velocity; } + } + + public bool VehicleStopped + { + get { return PreviousState.Velocity.IsEqual(0.SI<MeterPerSecond>(), 0.01.SI<MeterPerSecond>()); } + } + + public Kilogram VehicleMass + { + get { return ModelData.TotalCurbWeight(); } + } + + public Kilogram VehicleLoading + { + get { return ModelData.Loading; } + } + + public Kilogram TotalMass + { + get { return ModelData.TotalVehicleWeight(); } + } + public class VehicleState { public Meter Distance = 0.SI<Meter>(); diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs index 84f15dce78ef74d1e4da9bf2bf4d1744bbfe2b1c..eab8b0be2ab39eb625d995fb61d0e24f99087fe7 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/Wheels.cs @@ -39,13 +39,19 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Wheels : StatefulVectoSimulationComponent<Wheels.WheelsState>, IWheels, IFvOutPort, ITnInPort + public class Wheels : StatefulProviderComponent<Wheels.WheelsState, IFvOutPort, ITnInPort, ITnOutPort>, IWheels, + IFvOutPort, ITnInPort { - protected ITnOutPort NextComponent; - private readonly Meter _dynamicWheelRadius; private readonly KilogramSquareMeter _totalWheelsInertia; + public class WheelsState + { + public PerSecond AngularVelocity; + public NewtonMeter TorqueIn; + public NewtonMeter InertiaTorqueLoss; + } + public Wheels(IVehicleContainer cockpit, Meter rdyn, KilogramSquareMeter totalWheelsInertia) : base(cockpit) { @@ -53,26 +59,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _totalWheelsInertia = totalWheelsInertia; } - #region IFvOutProvider - - public IFvOutPort OutPort() + public IResponse Initialize(Newton force, MeterPerSecond velocity) { - return this; - } - - #endregion - - #region ITnInProvider + PreviousState.TorqueIn = force * _dynamicWheelRadius; + PreviousState.AngularVelocity = velocity / _dynamicWheelRadius; + PreviousState.InertiaTorqueLoss = 0.SI<NewtonMeter>(); - public ITnInPort InPort() - { - return this; + return NextComponent.Initialize(PreviousState.TorqueIn, PreviousState.AngularVelocity); } - #endregion - - #region IFvOutPort - public IResponse Request(Second absTime, Second dt, Newton force, MeterPerSecond velocity, bool dryRun) { Log.Debug("request: force: {0}, velocity: {1}", force, velocity); @@ -91,29 +86,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl return retVal; } - - public IResponse Initialize(Newton force, MeterPerSecond velocity) - { - PreviousState.TorqueIn = force * _dynamicWheelRadius; - PreviousState.AngularVelocity = velocity / _dynamicWheelRadius; - PreviousState.InertiaTorqueLoss = 0.SI<NewtonMeter>(); - - return NextComponent.Initialize(PreviousState.TorqueIn, PreviousState.AngularVelocity); - } - - #endregion - - #region ITnInPort - - public void Connect(ITnOutPort other) - { - NextComponent = other; - } - - #endregion - - #region VectoSimulationComponent - protected override void DoWriteModalResults(IModalDataContainer container) { var avgAngularSpeed = (CurrentState.AngularVelocity + PreviousState.AngularVelocity) / 2.0; @@ -122,20 +94,6 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl container[ModalResultField.P_wheel_inertia] = CurrentState.InertiaTorqueLoss * avgAngularSpeed; } - protected override void DoCommitSimulationStep() - { - AdvanceState(); - } - - #endregion - - public class WheelsState - { - public PerSecond AngularVelocity; - public NewtonMeter TorqueIn; - public NewtonMeter InertiaTorqueLoss; - } - public Kilogram ReducedMassWheels { get { return (_totalWheelsInertia / _dynamicWheelRadius / _dynamicWheelRadius).Cast<Kilogram>(); } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs b/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs index b447fd6b49e201cf7bfdb14d7eb8791bf34f3270..1a414f120d6985901cbe3a645b07ed0e0b3be7a3 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/VectoSimulationComponent.cs @@ -92,6 +92,37 @@ namespace TUGraz.VectoCore.Models.SimulationComponent } } + public abstract class StatefulProviderComponent<TStateType, TProviderOutPort, TProviderInPort, TOutPort> : + StatefulVectoSimulationComponent<TStateType> + where TStateType : new() + where TProviderOutPort : class + where TProviderInPort : class + { + protected TOutPort NextComponent; + + protected StatefulProviderComponent(IVehicleContainer container) : base(container) {} + + public TProviderOutPort OutPort() + { + return this as TProviderOutPort; + } + + public TProviderInPort InPort() + { + return this as TProviderInPort; + } + + public void Connect(TOutPort other) + { + NextComponent = other; + } + + protected override void DoCommitSimulationStep() + { + AdvanceState(); + } + } + public class SimpleComponentState { public NewtonMeter OutTorque = 0.SI<NewtonMeter>(); diff --git a/VectoCore/VectoCore/Resources/Declaration/Rims.csv b/VectoCore/VectoCore/Resources/Declaration/Rims.csv deleted file mode 100644 index 9634612212a0b9967e20d938c2506cdab408e012..0000000000000000000000000000000000000000 --- a/VectoCore/VectoCore/Resources/Declaration/Rims.csv +++ /dev/null @@ -1,5 +0,0 @@ -rims,F(a),F(b) -5° DC Rims,3.03,3.03 -15° DC Rims,3.03,3.05 -Multipurpose - Radial,3,3 -Multipurpose - Diagonal,2.94,2.94 diff --git a/VectoCore/VectoCore/Resources/Declaration/VAUX/ALT-Tech.csv b/VectoCore/VectoCore/Resources/Declaration/VAUX/ALT-Tech.csv index 7ea13e6650e083af87b6fe8cb67d354a2d679272..93b5fd09015a4fabe1af46677226f47e054d4f19 100644 --- a/VectoCore/VectoCore/Resources/Declaration/VAUX/ALT-Tech.csv +++ b/VectoCore/VectoCore/Resources/Declaration/VAUX/ALT-Tech.csv @@ -1,2 +1,2 @@ -Technology ,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach -Standard alternator,0.7 ,0.7 ,0.7 ,0.7 ,0.7 ,1 ,1 ,1 ,1 ,1 \ No newline at end of file +Technology ,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction +Standard alternator efficiency,0.7 ,0.7 ,0.7 ,0.7 ,0.7 \ No newline at end of file diff --git a/VectoCore/VectoCore/Resources/Declaration/VAUX/ES-Tech.csv b/VectoCore/VectoCore/Resources/Declaration/VAUX/ES-Tech.csv index 66df1bda5bebb52c5782daa1c896f8ad89e0cf7c..699348660812e4f0122fc0040cc06431ca267e9a 100644 --- a/VectoCore/VectoCore/Resources/Declaration/VAUX/ES-Tech.csv +++ b/VectoCore/VectoCore/Resources/Declaration/VAUX/ES-Tech.csv @@ -1,3 +1,3 @@ -Technology,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach -Baseline electric power consumption,1240,1055,974,974,975,0,0,0,0,0 -LED lights,-50,-50,-50,-50,-50,0,0,0,0,0 +Technology, Long haul, Regional delivery, Urban delivery, Municipal utility, Construction +Standard technology, 1200, 1000, 1000, 1000, 1000 +"Standard technology - LED headlights, all", 1150, 950, 950, 950, 950 diff --git a/VectoCore/VectoCore/Resources/Declaration/VAUX/Fan-Tech.csv b/VectoCore/VectoCore/Resources/Declaration/VAUX/Fan-Tech.csv index 6f2a7ad9b3e49a4d910e5d6c92df9faeaec41285..2b84f3480cf73f4dcb2fb9516af33baebfeddc17 100644 --- a/VectoCore/VectoCore/Resources/Declaration/VAUX/Fan-Tech.csv +++ b/VectoCore/VectoCore/Resources/Declaration/VAUX/Fan-Tech.csv @@ -1,12 +1,12 @@ -Technology,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach -Crankshaft mounted - Electronically controlled visco clutch (Default),618,671,516,566,1037,0,0,0,0,0 -Crankshaft mounted - Bimetallic controlled visco clutch,818,871,676,766,1277,0,0,0,0,0 -Crankshaft mounted - Discrete step clutch,668,721,616,616,1157,0,0,0,0,0 -Crankshaft mounted - On/Off clutch,718,771,666,666,1237,0,0,0,0,0 -Belt driven or driven via transm. - Electronically controlled visco clutch,889,944,733,833,1378,0,0,0,0,0 -Belt driven or driven via transm. - Bimetallic controlled visco clutch,1089,1144,893,1033,1618,0,0,0,0,0 -Belt driven or driven via transm. - Discrete step clutch,939,994,883,883,1498,0,0,0,0,0 -Belt driven or driven via transm. - On/Off clutch,989,1044,933,933,1578,0,0,0,0,0 -Hydraulic driven - Variable displacement pump,738,955,632,717,1672,0,0,0,0,0 -Hydraulic driven - Constant displacement pump,1000,1200,800,900,2100,0,0,0,0,0 -Hydraulic driven - Electronically controlled,700,800,600,600,1400,0,0,0,0,0 +Technology,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction +Crankshaft mounted - Electronically controlled visco clutch,618,671,516,566,1037 +Crankshaft mounted - Bimetallic controlled visco clutch,818,871,676,766,1277 +Crankshaft mounted - Discrete step clutch,668,721,616,616,1157 +Crankshaft mounted - On/off clutch,718,771,666,666,1237 +Belt driven or driven via transm. - Electronically controlled visco clutch,989,1044,833,933,1478 +Belt driven or driven via transm. - Bimetallic controlled visco clutch,1189,1244,993,1133,1718 +Belt driven or driven via transm. - Discrete step clutch,1039,1094,983,983,1598 +Belt driven or driven via transm. - On/off clutch,1089,1144,1033,1033,1678 +Hydraulic driven - Variable displacement pump,938,1155,832,917,1872 +Hydraulic driven - Constant displacement pump,1200,1400,1000,1100,2300 +Hydraulic driven - Electronically controlled,700,800,600,600,1400 diff --git a/VectoCore/VectoCore/Resources/Declaration/VAUX/HVAC-Table.csv b/VectoCore/VectoCore/Resources/Declaration/VAUX/HVAC-Table.csv index e259441670a07f6b83258084eb9036e086f8b351..93962b78bbd055128725016421f4585e976ee00c 100644 --- a/VectoCore/VectoCore/Resources/Declaration/VAUX/HVAC-Table.csv +++ b/VectoCore/VectoCore/Resources/Declaration/VAUX/HVAC-Table.csv @@ -1,13 +1,11 @@ -HDV Class / Power,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach -1,0,150,150,0,0,0,0,0,0,0 -2,200,200,150,0,0,0,0,0,0,0 -3,0,200,150,0,0,0,0,0,0,0 -4,350,200,0,300,0,0,0,0,0,0 -5,350,200,0,0,0,0,0,0,0,0 -6,0,0,0,0,0,0,0,0,0,0 -7,0,0,0,0,200,0,0,0,0,0 -8,0,0,0,0,0,0,0,0,0,0 -9,350,200,0,300,0,0,0,0,0,0 -10,350,200,0,0,0,0,0,0,0,0 -11,0,0,0,0,200,0,0,0,0,0 -12,0,0,0,0,200,0,0,0,0,0 +HDV Class,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction +1,,150,150,, +2,200,200,150,, +3,,200,150,, +4,350,200,,300, +5,350,200,,, +9,350,200,,300, +10,350,200,,, +11,350,200,,300,200 +12,350,200,,,200 +16,,,,,200 diff --git a/VectoCore/VectoCore/Resources/Declaration/VAUX/PS-Table.csv b/VectoCore/VectoCore/Resources/Declaration/VAUX/PS-Table.csv index cfbb35d7d3419cd95deb26a7da171ac279823eb3..916cf5a81a11dbad8fac464eb74e0b6622a58bf4 100644 --- a/VectoCore/VectoCore/Resources/Declaration/VAUX/PS-Table.csv +++ b/VectoCore/VectoCore/Resources/Declaration/VAUX/PS-Table.csv @@ -1,13 +1,29 @@ -HDV Class / Power,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach -1,0.0,1300.0,1240.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -2,1180.0,1280.0,1320.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -3,0.0,1360.0,1380.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -4,1300.0,1340.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -5,1340.0,1820.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -6,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -7,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -8,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -9,1340.0,1540.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -10,1340.0,1820.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -11,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -12,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 +Technology,Long Haul,Regional Delivery,Urban Delivery,Municipal utility,Construction +Small,1400,1300,1200,1200,1300 +Small + ESS,900,800,800,800,800 +Small + visco clutch,800,700,700,700,700 +Small + mech. clutch,600,600,650,650,600 +Small + ESS + AMS,500,400,500,500,400 +Small + visco clutch + AMS,400,300,400,400,300 +Small + mech. clutch + AMS,200,200,350,350,200 +Medium Supply 1-stage,1600,1400,1350,1350,1500 +Medium Supply 1-stage + ESS,1000,900,900,900,900 +Medium Supply 1-stage + visco clutch,850,800,800,800,750 +Medium Supply 1-stage + mech. clutch,600,550,550,550,600 +Medium Supply 1-stage + ESS + AMS,600,700,700,700,500 +Medium Supply 1-stage + visco clutch + AMS,450,600,600,600,350 +Medium Supply 1-stage + mech. clutch + AMS,200,350,350,350,200 +Medium Supply 2-stage,2100,1750,1700,1700,2100 +Medium Supply 2-stage + ESS,1100,1050,1000,1000,1000 +Medium Supply 2-stage + visco clutch,1000,850,800,800,900 +Medium Supply 2-stage + mech. clutch,700,650,600,600,800 +Medium Supply 2-stage + ESS + AMS,700,850,800,800,500 +Medium Supply 2-stage + visco clutch + AMS,600,650,600,600,400 +Medium Supply 2-stage + mech. clutch + AMS,300,450,400,400,300 +Large Supply,4300,3600,3500,3500,4100 +Large Supply + ESS,1600,1300,1200,1200,1500 +Large Supply + visco clutch,1300,1100,1000,1000,1200 +Large Supply + mech. clutch,800,800,700,700,900 +Large Supply + ESS + AMS,1100,1000,1000,1000,1000 +Large Supply + visco clutch + AMS,800,800,800,800,700 +Large Supply + mech. clutch + AMS,300,500,500,500,400 diff --git a/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Axles.csv b/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Axles.csv new file mode 100644 index 0000000000000000000000000000000000000000..10f0a576ec75bae5b336277d9571fd2a53e23580 --- /dev/null +++ b/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Axles.csv @@ -0,0 +1,5 @@ +Steered axles,Long haul,Regional delivery,Urban delivery,Municipal utility,construction +1,100/100/100,100/100/100,100/100/100,100/100/100,100/100/100 +2,100/70/70,100/70/70,100/70/70,100/70/70,100/70/70 +3,100/50/50,100/50/50,100/50/50,100/50/50,100/50/50 +4,100/50/50,100/50/50,100/50/50,100/50/50,100/50/50 diff --git a/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Table.csv b/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Table.csv index 53a2136afe86d583e780cb3928dcac2ca9f0f415..66a43eee79e97a7462474bd77ac78691bfc808da 100644 --- a/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Table.csv +++ b/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Table.csv @@ -1,11 +1,14 @@ -HDV Class / Power demand per share,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction,Heavy Urban,Urban,Suburban,Interurban,Coach -1,0,110/130/20/0,100/120/20/30,0,0,0,0,0,0,0 -2,150/190/30/0,130/160/30/0,120/140/20/30,0,0,0,0,0,0,0 -3,0,140/170/30/0,130/150/30/40,0,0,0,0,0,0,0 -4,230/280/100/0,220/270/40/0,0,220/270/40/0,0,0,0,0,0,0 -5,270/330/120/0,250/290/90/0,220/260/80/60,0,0,0,0,0,0,0 -6,0,0,0,0,0,0,0,0,0,0 -7,0,0,0,0,0,0,0,0,0,0 -8,0,0,0,0,0,0,0,0,0,0 -9,270/330/120/0,220/270/60/0,0,220/270/60/0,0,0,0,0,0,0 -10,200/250/120/0,200/240/90/0,0,0,0,0,0,0,0,0 +HDV Class,Long haul,Regional delivery,Urban delivery,Municipal utility,Construction +1,,240/20/20,220/20/30,, +2,340/30/0,290/30/20,260/20/30,, +3,,310/30/30,280/30/40,, +4,510/100/0,490/40/40,,430/30/50, +5,600/120/0,540/90/40,480/80/60,, +6,,,,, +7,,,,, +8,,,,, +9,600/120/0,490/60/40,,430/30/50, +10,450/120/0,440/90/40,,, +11,600/120/0,490/60/40,,430/30/50,640/50/80 +12,450/120/0,440/90/40,,,640/50/80 +16,,,,,640/50/80 diff --git a/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Tech.csv b/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Tech.csv index ca7ebfb7833faa126ff5108c221b3a805d55929f..494581d6c09dce30c428ab1b6880079aaf34b87f 100644 --- a/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Tech.csv +++ b/VectoCore/VectoCore/Resources/Declaration/VAUX/SP-Tech.csv @@ -1,4 +1,7 @@ -Scaling Factors,U,F,B,S -Fixed displacement,1,1,1,1 -Variable displacement,0.6,0.6,0.6,0.6 -Hydraulic supported by electric,0.7,1,0.9,0.9 +Technology,UF,B,S +Fixed displacement,1,1,1 +Fixed displacement with elec. control,0.95,1,1 +Dual displacement,0.85,0.85,0.85 +Variable displacement mech. controlled,0.75,0.75,0.75 +Variable displacement elec. controlled,0.6,0.6,0.6 +Electric,0,1.5,1 diff --git a/VectoCore/VectoCore/Resources/Declaration/Wheels.csv b/VectoCore/VectoCore/Resources/Declaration/Wheels.csv index 782e9ba6938fbc3f94f01f1b48bdd568536ed417..81aef7c3bbcba4c6107c848aedb15e30ab819625 100644 --- a/VectoCore/VectoCore/Resources/Declaration/Wheels.csv +++ b/VectoCore/VectoCore/Resources/Declaration/Wheels.csv @@ -1,41 +1,58 @@ -Wheel,Inertia,d,Size-Class (0/1) -9 R22.5,8.9,970,b -9.00 R20,10.5,1018,b -9.5 R17.5,4.9,842,b -10 R17.5,5,858,b -10 R22.5,11,1020,b -10.00 R20,13.1,1025,b -11 R22.5,14.4,1050,b -11.00 R20,14.6,1082,b -12 R22.5,16.8,1084,b -12.00 R20,19.5,1122,b -12.00 R24,27.7,1226,b -12.5 R20,12.7,1120,b -13 R22.5,20,1124,b -14.00 R20,30.8,1238,b -14.5 R20,14.8,1092,b -16.00 R20,47.5,1343,b -215/75 R17.5,3.9,767,b -225/70 R17.5,4,759.5,b -225/75 R17.5,4,782,b -235/75 R17.5,4.5,797,b -245/70 R17.5,5.2,787.5,b -245/70 R19.5,6,838.3,b -255/70 R22.5,9.5,928.5,b -265/70 R19.5,6.5,866.3,b -275/70 R22.5,11.9,956.5,b -275/80 R22.5,12.8,1011.5,b -285/70 R19.5,7.9,894.3,b -295/55 R22.5,10.2,896,a -295/60 R22.5,10.8,925.5,a -295/80 R22.5,15.5,1043.5,b -305/70 R19.5,9.2,922.3,b -305/70 R22.5,13.9,998.5,b -315/45 R22.5,9.9,855,a -315/60 R22.5,12.8,949.5,a -315/70 R22.5,14.9,1012.5,b -315/80 R22.5,17.6,1075.5,b -365/80 R20,17.2,1092,b -365/85 R20,22.5,1128.5,b -385/55 R22.5,15.9,995,a -385/65 R22.5,19.2,1072,a +Wheel ,cross-sectional width [mm],tire aspect ratio [%],rim diameter [inch],d [mm],Inertia,F [-] +9.5 R17.5 ,241.3 ,0.95 ,17.5 ,842.0 ,4.9 ,3.05 +9.00 R20 ,228.6 ,0.95 ,20 ,1018.0,10.5 ,3.05 +9 R22.5 ,228.6 ,0.95 ,22.5 ,970.0 ,8.9 ,3.05 +10 R17.5 ,254 ,0.95 ,17.5 ,858.0 ,5 ,3.05 +10 R22.5 ,254 ,0.95 ,22.5 ,1020.0,11 ,3.05 +10.00 R20 ,254 ,0.95 ,20 ,1052.0,13.1 ,3.05 +11 R22.5 ,279.4 ,0.95 ,22.5 ,1050.0,14.4 ,3.05 +11.00 R20 ,279.4 ,0.95 ,20 ,1082.0,14.6 ,3.05 +11.00 R22 ,279.4 ,0.95 ,22 ,1050.0,16 ,3.05 +12 R22.5 ,304.8 ,0.95 ,22.5 ,1084.0,16.85 ,3.05 +12.00 R20 ,304.8 ,0.95 ,20 ,1122.0,19.5 ,3.05 +12.00 R24 ,304.8 ,0.95 ,24 ,1226.0,27.7 ,3.05 +12.5 R20 ,317.5 ,0.95 ,20 ,1120 ,12.7 ,3.05 +13 R22.5 ,330.2 ,0.95 ,22.5 ,1124.0,20 ,3.05 +14.00 R20 ,355.6 ,0.95 ,20 ,1238.0,30.8 ,3.05 +14.5 R20 ,368.3 ,0.95 ,20 ,1092 ,14.8 ,3.05 +16.00 R20 ,406.4 ,0.95 ,20 ,1343 ,47.5 ,3.05 +205/75 R17.5,205 ,0.75 ,17.5 ,753.0 ,3.5 ,3.05 +215/75 R17.5,215 ,0.75 ,17.5 ,767.0 ,3.9 ,3.05 +225/70 R17.5,225 ,0.7 ,17.5 ,759.5 ,4 ,3.05 +225/75 R17.5,225 ,0.75 ,17.5 ,782 ,4 ,3.05 +235/75 R17.5,235 ,0.75 ,17.5 ,797.0 ,4.5 ,3.05 +245/70 R17.5,245 ,0.7 ,17.5 ,789.0 ,5.2 ,3.05 +245/70 R19.5,245 ,0.7 ,19.5 ,839.0 ,6 ,3.05 +255/70 R22.5,255 ,0.7 ,22.5 ,930.0 ,9.5 ,3.05 +265/70 R17.5,265 ,0.7 ,17.5 ,817 ,5.6 ,3.05 +265/70 R19.5,265 ,0.7 ,19.5 ,867.0 ,6.5 ,3.05 +275/70 R22.5,275 ,0.7 ,22.5 ,958.0 ,11.9 ,3.05 +275/80 R22.5,275 ,0.8 ,22.5 ,1012.0,12.8 ,3.05 +285/60 R22.5,285 ,0.6 ,22.5 ,914.0 ,10.6 ,3.03 +285/70 R19.5,285 ,0.7 ,19.5 ,895.0 ,7.9 ,3.05 +295/55 R22.5,295 ,0.55 ,22.5 ,896.0 ,10.2 ,3.03 +295/60 R22.5,295 ,0.6 ,22.5 ,926.0 ,10.8 ,3.03 +295/80 R22.5,295 ,0.8 ,22.5 ,1044.0,15.5 ,3.05 +305/60 R22.5,305 ,0.6 ,22.5 ,938.0 ,11.4 ,3.03 +305/70 R19.5,305 ,0.7 ,19.5 ,923.0 ,9.2 ,3.05 +305/70 R22.5,305 ,0.7 ,22.5 ,1000.0,13.9 ,3.05 +305/75 R24.5,305 ,0.75 ,24.5 ,1079.8,21.2 ,3.05 +315/45 R22.5,315 ,0.45 ,22.5 ,856.0 ,9.9 ,3.03 +315/60 R22.5,315 ,0.6 ,22.5 ,950.0 ,12.8 ,3.03 +315/70 R22.5,315 ,0.7 ,22.5 ,1014.0,14.9 ,3.05 +315/80 R22.5,315 ,0.8 ,22.5 ,1076.0,17.6 ,3.05 +325/95 R24 ,325 ,0.95 ,24 ,1228.0,27.6 ,3.05 +335/80 R20 ,335 ,0.8 ,20 ,1044.0,13.5 ,3.05 +355/50 R22.5,355 ,0.5 ,22.5 ,928.0 ,12.2 ,3.03 +365/70 R22.5,365 ,0.7 ,22.5 ,1084.0,18.6 ,3.05 +365/80 R20 ,365 ,0.8 ,20 ,1092.0,17.2 ,3.05 +365/85 R20 ,365 ,0.85 ,20 ,1128.0,22.5 ,3.05 +375/45 R22.5,375 ,0.45 ,22.5 ,910.0 ,11.2 ,3.03 +375/50 R22.5,375 ,0.5 ,22.5 ,948.0 ,13 ,3.03 +375/90 R22.5,375 ,0.9 ,22.5 ,1246.5,33.8 ,3.05 +385/55 R22.5,385 ,0.55 ,22.5 ,996.0 ,15.9 ,3.03 +385/65 R22.5,385 ,0.65 ,22.5 ,1072.0,19.2 ,3.03 +395/85 R20 ,395 ,0.85 ,20 ,1180.0,27.9 ,3.05 +425/65 R22.5,425 ,0.65 ,22.5 ,1124.0,22.5 ,3.03 +495/45 R22.5,495 ,0.45 ,22.5 ,1018.0,20.7 ,3.03 +525/65 R20.5,525 ,0.65 ,20.5 ,1203.2,35 ,3.03 \ No newline at end of file diff --git a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs index 5cd19a06d38e0ab31d01de30fed8689de71743e0..0d3b6e9723ccb04bfce22dbb2f31777d75b8e248 100644 --- a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs +++ b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs @@ -36,10 +36,10 @@ using System.IO; using System.Linq; using System.Threading; using System.Windows.Forms; -using TUGraz.VectoCore.Configuration; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.Models.Connector.Ports.Impl; namespace TUGraz.VectoCore.Utils diff --git a/VectoCore/VectoCore/Utils/StreamExtensions.cs b/VectoCore/VectoCore/Utils/StreamExtensions.cs new file mode 100644 index 0000000000000000000000000000000000000000..7ff3dff43ace3080358bbce61766afe4dbd7f95d --- /dev/null +++ b/VectoCore/VectoCore/Utils/StreamExtensions.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace TUGraz.VectoCore.Utils +{ + internal static class StreamExtensions + { + public static IEnumerable<string> ReadLines(this Stream stream) + { + using (var reader = new StreamReader(stream, Encoding.UTF8)) { + while (!reader.EndOfStream) { + yield return reader.ReadLine(); + } + } + } + } +} \ No newline at end of file diff --git a/VectoCore/VectoCore/Utils/VectoCSVFile.cs b/VectoCore/VectoCore/Utils/VectoCSVFile.cs index 5c9f77ca31050b8c7f0011788d80d4321c77af23..33722c85ce398ee0ff45910f8b1524d82b8559fd 100644 --- a/VectoCore/VectoCore/Utils/VectoCSVFile.cs +++ b/VectoCore/VectoCore/Utils/VectoCSVFile.cs @@ -29,8 +29,8 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using Microsoft.VisualBasic.FileIO; using System; -using System.Collections.Generic; using System.Data; using System.Globalization; using System.IO; @@ -59,8 +59,8 @@ namespace TUGraz.VectoCore.Utils public static class VectoCSVFile { private static readonly Regex HeaderFilter = new Regex(@"\[.*?\]|\<|\>", RegexOptions.Compiled); - private const char Delimiter = ','; - private const char Comment = '#'; + private const string Delimiter = ","; + private const string Comment = "#"; /// <summary> /// Reads a CSV file which is stored in Vecto-CSV-Format. @@ -90,85 +90,62 @@ namespace TUGraz.VectoCore.Utils /// <returns>A DataTable which represents the CSV File.</returns> public static DataTable ReadStream(Stream stream, bool ignoreEmptyColumns = false, bool fullHeader = false) { - try { - return ReadData(ReadLines(stream), ignoreEmptyColumns, fullHeader); - } catch (Exception e) { - LogManager.GetLogger(typeof(VectoCSVFile).FullName).Error(e); - throw new VectoException("Failed to read stream: " + e.Message, e); - } - } + var p = new TextFieldParser(stream) { + TextFieldType = FieldType.Delimited, + Delimiters = new[] { Delimiter }, + CommentTokens = new[] { Comment }, + HasFieldsEnclosedInQuotes = true, + TrimWhiteSpace = true + }; - private static IEnumerable<string> ReadLines(Stream stream) - { - using (var reader = new StreamReader(stream, Encoding.UTF8)) { - while (!reader.EndOfStream) { - yield return reader.ReadLine(); - } - } - } + string[] colsWithoutComment; - /// <summary> - /// - /// </summary> - /// <param name="allLines"></param> - /// <param name="ignoreEmptyColumns"></param> - /// <param name="fullHeader"></param> - /// <returns></returns> - private static DataTable ReadData(IEnumerable<string> allLines, bool ignoreEmptyColumns = false, - bool fullHeader = false) - { - // trim, remove comments and filter empty lines - var lines = allLines - .Select(l => l.Trim()) - .Select(l => l.Contains(Comment) ? l.Substring(0, l.IndexOf(Comment)) : l) - .Where(l => !string.IsNullOrWhiteSpace(l)) - .GetEnumerator(); - - // start the enumerable - lines.MoveNext(); - - // add columns - var line = lines.Current; - if (!fullHeader) { - line = HeaderFilter.Replace(line, ""); + try { + colsWithoutComment = p.ReadFields() + .Select(l => l.Contains(Comment) ? l.Substring(0, l.IndexOf(Comment)) : l) + .ToArray(); + } catch (ArgumentNullException) { + throw new CSVReadException("CSV Read Error: File was empty."); } - double tmp; - var splittedColumns = line - .Split(Delimiter); - var columns = splittedColumns - .Select(col => col.Trim()) + double tmp; + var columns = colsWithoutComment + .Select(l => fullHeader ? l : HeaderFilter.Replace(l, "")) + .Select(l => l.Trim()) .Where(col => !double.TryParse(col, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp)) + .Distinct() .ToList(); - if (columns.Count > 0) { - // first line was a valid header: advance to first data line - lines.MoveNext(); - } else { + var firstLineIsData = columns.Count == 0; + + if (firstLineIsData) { LogManager.GetLogger(typeof(VectoCSVFile).FullName) .Warn("No valid Data Header found. Interpreting the first line as data line."); // set the validColumns to: {"0", "1", "2", "3", ...} for all columns in first line. - columns = splittedColumns.Select((_, index) => index.ToString()).ToList(); + columns = colsWithoutComment.Select((_, i) => i.ToString()).ToList(); } var table = new DataTable(); foreach (var col in columns) { table.Columns.Add(col); } - if (lines.Current == null) { + + if (p.EndOfData) return table; - } - // read data into table - var i = 0; - do { - i++; - line = lines.Current; - var cells = line.Split(Delimiter).Select(s => s.Trim()).ToArray(); - if (cells.Length != table.Columns.Count && !ignoreEmptyColumns) { + var lineNumber = 1; + do { + var cells = firstLineIsData + ? colsWithoutComment + : p.ReadFields() + .Select(l => l.Contains(Comment) ? l.Substring(0, l.IndexOf(Comment)) : l) + .Select(s => s.Trim()) + .ToArray(); + firstLineIsData = false; + if (table.Columns.Count != cells.Length && !ignoreEmptyColumns) { throw new CSVReadException( - string.Format("Line {0}: The number of values is not correct. Expected {1} Columns, Got {2} Columns", i, - table.Columns.Count, cells.Length)); + string.Format("Line {0}: The number of values is not correct. Expected {1} Columns, Got {2} Columns", + lineNumber, table.Columns.Count, cells.Length)); } try { @@ -176,9 +153,11 @@ namespace TUGraz.VectoCore.Utils table.Rows.Add(cells); } catch (InvalidCastException e) { throw new CSVReadException( - string.Format("Line {0}: The data format of a value is not correct. {1}", i, e.Message), e); + string.Format("Line {0}: The data format of a value is not correct. {1}", lineNumber, e.Message), e); } - } while (lines.MoveNext()); + lineNumber++; + } while (!p.EndOfData); + return table; } diff --git a/VectoCore/VectoCore/VectoCore.csproj b/VectoCore/VectoCore/VectoCore.csproj index 2bae0791eb8da8bebd2aacca1ae3fca61ed9d303..65809cc45e896b2a87586ddcfd263b2d516de534 100644 --- a/VectoCore/VectoCore/VectoCore.csproj +++ b/VectoCore/VectoCore/VectoCore.csproj @@ -87,6 +87,7 @@ <Reference Include="itextsharp"> <HintPath>..\..\packages\iTextSharp.5.5.9\lib\itextsharp.dll</HintPath> </Reference> + <Reference Include="Microsoft.VisualBasic" /> <Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> @@ -126,6 +127,7 @@ <Compile Include="InputData\Reader\Impl\EngineeringModeVectoRunDataFactory.cs" /> <Compile Include="InputData\Reader\Impl\EngineOnlyVectoRunDataFactory.cs" /> <Compile Include="InputData\Reader\ShiftPolygonReader.cs" /> + <Compile Include="Models\Declaration\AuxiliaryTypeHelper.cs" /> <Compile Include="Models\Connector\Ports\IDriverDemandPort.cs" /> <Compile Include="Models\Connector\Ports\IDrivingCyclePort.cs" /> <Compile Include="Models\Connector\Ports\Impl\Response.cs" /> @@ -138,8 +140,6 @@ <Compile Include="InputData\Reader\ComponentData\TorqueConverterDataReader.cs" /> <Compile Include="InputData\Reader\ComponentData\AuxiliaryDataReader.cs" /> <Compile Include="Models\SimulationComponent\Data\Engine\FuelConsumptionMapReader.cs" /> - <Compile Include="Models\SimulationComponent\Impl\TorqueConverter.cs" /> - <Compile Include="Utils\AuxiliaryTypeHelper.cs" /> <Compile Include="Utils\ProviderExtensions.cs" /> <Compile Include="Models\Declaration\AirDrag.cs" /> <Compile Include="Models\Declaration\Fan.cs" /> @@ -148,11 +148,9 @@ <Compile Include="Models\Declaration\Payloads.cs" /> <Compile Include="Models\Declaration\PneumaticSystem.cs" /> <Compile Include="Models\Declaration\PT1.cs" /> - <Compile Include="Models\Declaration\Rims.cs" /> <Compile Include="Models\Declaration\Segments.cs" /> <Compile Include="Models\Declaration\StandardBodies.cs" /> <Compile Include="Models\Declaration\SteeringPump.cs" /> - <Compile Include="Models\Declaration\TorqueConverter.cs" /> <Compile Include="Models\Declaration\VehicleClass.cs" /> <Compile Include="Models\Declaration\Wheels.cs" /> <Compile Include="Models\Declaration\WHTCCorrection.cs" /> @@ -166,7 +164,6 @@ <Compile Include="Models\Declaration\DeclarationData.cs" /> <Compile Include="Models\Declaration\ElectricSystem.cs" /> <Compile Include="Models\Declaration\LookupData.cs" /> - <Compile Include="Models\Declaration\DeclarationRims.cs" /> <Compile Include="Models\Declaration\Mission.cs" /> <Compile Include="Models\Declaration\MissionType.cs" /> <Compile Include="Models\SimulationComponent\Data\DriverData.cs" /> @@ -281,6 +278,7 @@ <Compile Include="Models\Simulation\DataBus\IVehicleInfo.cs" /> <Compile Include="Models\Simulation\IVehicleContainer.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="Utils\StreamExtensions.cs" /> <Compile Include="Utils\SwitchExtension.cs" /> <Compile Include="Utils\VectoCSVFile.cs" /> <Compile Include="Utils\DelaunayMap.cs" /> @@ -293,7 +291,6 @@ <LastGenOutput>JsonKeys.Designer.cs</LastGenOutput> <SubType>Designer</SubType> </EmbeddedResource> - <EmbeddedResource Include="Resources\Declaration\Rims.csv" /> <EmbeddedResource Include="Resources\Declaration\Wheels.csv" /> <EmbeddedResource Include="Resources\Declaration\SegmentTable.csv" /> <EmbeddedResource Include="Resources\Declaration\MissionCycles\HeavyUrban.vdri" /> @@ -329,6 +326,7 @@ <EmbeddedResource Include="Resources\Declaration\LAC-DF-Vtarget.csv" /> <EmbeddedResource Include="Resources\Declaration\Body_Trailers_Weights.csv" /> <EmbeddedResource Include="Resources\Declaration\Payloads.csv" /> + <EmbeddedResource Include="Resources\Declaration\VAUX\SP-Axles.csv" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="Resources\Declaration\Report\4x2r.png" /> diff --git a/VectoCore/VectoCoreTest/FileIO/JsonTest.cs b/VectoCore/VectoCoreTest/FileIO/JsonTest.cs index e086e41bc5ba9b4ad05ff19b7e7244c28a76aa79..69d2075f311267cf909028ce0166f4fca8fe9a74 100644 --- a/VectoCore/VectoCoreTest/FileIO/JsonTest.cs +++ b/VectoCore/VectoCoreTest/FileIO/JsonTest.cs @@ -29,11 +29,10 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.IO; -using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using System.IO; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; @@ -65,7 +64,7 @@ namespace TUGraz.VectoCore.Tests.FileIO ((JObject)json["Body"]).Property("EngineFile").Remove(); AssertHelper.Exception<VectoException>(() => new JSONInputDataV2(json, TestJobFile), - "Failed to read input data: Key EngineFile not found"); + "JobFile: Failed to read Engine file '': Key EngineFile not found"); } [TestMethod] @@ -75,7 +74,7 @@ namespace TUGraz.VectoCore.Tests.FileIO ((JObject)json["Body"]).Property("GearboxFile").Remove(); AssertHelper.Exception<VectoException>(() => new JSONInputDataV2(json, TestJobFile), - "Failed to read input data: Key GearboxFile not found"); + "JobFile: Failed to read Gearbox file '': Key GearboxFile not found"); } [TestMethod] @@ -85,7 +84,7 @@ namespace TUGraz.VectoCore.Tests.FileIO ((JObject)json["Body"]).Property("VehicleFile").Remove(); AssertHelper.Exception<VectoException>(() => new JSONInputDataV2(json, TestJobFile), - "Failed to read input data: Key VehicleFile not found"); + "JobFile: Failed to read Vehicle file '': Key VehicleFile not found"); } [TestMethod] @@ -95,7 +94,9 @@ namespace TUGraz.VectoCore.Tests.FileIO ((JObject)json["Body"]).Property("Cycles").Remove(); AssertHelper.Exception<InvalidFileFormatException>( - () => { var tmp = new JSONInputDataV2(json, TestJobFile).Cycles; }, "Key Cycles not found"); + () => { + var tmp = new JSONInputDataV2(json, TestJobFile).Cycles; + }, "Key Cycles not found"); } [TestMethod] @@ -152,7 +153,9 @@ namespace TUGraz.VectoCore.Tests.FileIO ((JObject)json["Body"]).Property("OverSpeedEcoRoll").Remove(); AssertHelper.Exception<VectoException>( - () => { var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.OverSpeedEcoRoll; }, + () => { + var tmp = new JSONInputDataV2(json, TestJobFile).DriverInputData.OverSpeedEcoRoll; + }, "Key OverSpeedEcoRoll not found"); } diff --git a/VectoCore/VectoCoreTest/FileIO/SimulationDataReaderTest.cs b/VectoCore/VectoCoreTest/FileIO/SimulationDataReaderTest.cs index 700b7477fe2d0ff8bcd91c14dae19861d15b79d5..d950221af21865df59987d5148d7bbac165d989a 100644 --- a/VectoCore/VectoCoreTest/FileIO/SimulationDataReaderTest.cs +++ b/VectoCore/VectoCoreTest/FileIO/SimulationDataReaderTest.cs @@ -29,9 +29,9 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.IO; using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; @@ -39,6 +39,7 @@ using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader.Impl; using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Tests.Utils; namespace TUGraz.VectoCore.Tests.FileIO { @@ -70,7 +71,7 @@ namespace TUGraz.VectoCore.Tests.FileIO Assert.AreEqual(11900, runData.VehicleData.GrossVehicleWeight.Value()); Assert.AreEqual(AxleConfiguration.AxleConfig_4x2, runData.VehicleData.AxleConfiguration); - Assert.AreEqual(0.4069297458, runData.VehicleData.DynamicTyreRadius.Value(), Tolerance); + AssertHelper.AreRelativeEqual(0.40726954, runData.VehicleData.DynamicTyreRadius); Assert.AreEqual(VehicleClass.Class2, runData.VehicleData.VehicleClass); Assert.AreEqual(3, runData.VehicleData.AxleData.Count); diff --git a/VectoCore/VectoCoreTest/FileIO/VectoCSVFileTest.cs b/VectoCore/VectoCoreTest/FileIO/VectoCSVFileTest.cs index 450e460d615a5a416fff4da3e7d19e02f4e51d92..aaac2213965bdc030722bf5029128830ed9d6cd5 100644 --- a/VectoCore/VectoCoreTest/FileIO/VectoCSVFileTest.cs +++ b/VectoCore/VectoCoreTest/FileIO/VectoCSVFileTest.cs @@ -78,6 +78,45 @@ namespace TUGraz.VectoCore.Tests.FileIO CollectionAssert.AreEqual(new[] { "4", "5", "6" }, table.Rows[1].ItemArray); } + [Test] + public void VectoCSVFile_ReadStream_Escaped() + { + var stream = "a,b,c\n\"1,1\",2,3\n4,5,6".GetStream(); + var table = VectoCSVFile.ReadStream(stream); + + CollectionAssert.AreEqual(new[] { "a", "b", "c" }, table.Columns.Cast<DataColumn>().Select(c => c.ColumnName)); + Assert.AreEqual(2, table.Rows.Count); + + CollectionAssert.AreEqual(new[] { "1,1", "2", "3" }, table.Rows[0].ItemArray); + CollectionAssert.AreEqual(new[] { "4", "5", "6" }, table.Rows[1].ItemArray); + } + + [Test] + public void VectoCSVFile_ReadStream_Comment() + { + var stream = "a,b,c\n\"1,1\",2,3#asdf\n4,5,6".GetStream(); + var table = VectoCSVFile.ReadStream(stream); + + CollectionAssert.AreEqual(new[] { "a", "b", "c" }, table.Columns.Cast<DataColumn>().Select(c => c.ColumnName)); + Assert.AreEqual(2, table.Rows.Count); + + CollectionAssert.AreEqual(new[] { "1,1", "2", "3" }, table.Rows[0].ItemArray); + CollectionAssert.AreEqual(new[] { "4", "5", "6" }, table.Rows[1].ItemArray); + } + + [Test] + public void VectoCSVFile_ReadStream_EscapedComment() + { + var stream = "a,b,c\n\"1,1\",2,\"3#asdf\"\n4,5,6".GetStream(); + var table = VectoCSVFile.ReadStream(stream); + + CollectionAssert.AreEqual(new[] { "a", "b", "c" }, table.Columns.Cast<DataColumn>().Select(c => c.ColumnName)); + Assert.AreEqual(2, table.Rows.Count); + + CollectionAssert.AreEqual(new[] { "1,1", "2", "3" }, table.Rows[0].ItemArray); + CollectionAssert.AreEqual(new[] { "4", "5", "6" }, table.Rows[1].ItemArray); + } + [Test] public void VectoCSVFile_ReadStream_No_Header() { diff --git a/VectoCore/VectoCoreTest/Integration/Truck40tPowerTrain.cs b/VectoCore/VectoCoreTest/Integration/Truck40tPowerTrain.cs index b7bcfd76a24825e460d7b024b07f208927e5db9e..c9fb1ecaa341981d79cc14ac459ba00e5a297a4b 100644 --- a/VectoCore/VectoCoreTest/Integration/Truck40tPowerTrain.cs +++ b/VectoCore/VectoCoreTest/Integration/Truck40tPowerTrain.cs @@ -35,7 +35,6 @@ using System.IO; using System.Linq; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.InputData.Reader; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.Data; diff --git a/VectoCore/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs b/VectoCore/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs index d8f0fbc69346dfa4825981874fb1f72b578cb9b0..89d2a3c987ac2ff9f0fcd669f3d15aff698f5e70 100644 --- a/VectoCore/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs +++ b/VectoCore/VectoCoreTest/Models/Declaration/DeclarationDataTest.cs @@ -29,11 +29,10 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using NUnit.Framework; using System; -using System.Collections.Generic; using System.IO; using System.Linq; -using NUnit.Framework; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; @@ -44,33 +43,32 @@ using TUGraz.VectoCore.InputData.Reader.Impl; using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Tests.Utils; -using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Models.Declaration { [TestFixture] public class DeclarationDataTest { - public const double Tolerance = 0.0001; - public readonly MissionType[] Missions = EnumHelper.GetValues<MissionType>().ToArray(); - - [TestCase("285/70 R19.5", 7.9, 0.8943, "b")] - public void WheelDataTest(string wheels, double intertia, double dynamicRadius, string sizeClass) + private const double Tolerance = 0.0001; + + private readonly MissionType[] _missions = { + MissionType.LongHaul, + MissionType.RegionalDelivery, + MissionType.UrbanDelivery, + MissionType.MunicipalUtility, + MissionType.Construction, + }; + + [TestCase("285/60 R22.5", 10.6, 0.914, 3.03), + TestCase("285/70 R19.5", 7.9, 0.895, 3.05), + TestCase("395/85 R20", 27.9, 1.18, 3.05)] + public void WheelDataTest(string wheels, double inertia, double dynamicRadius, double circumferenceFactor) { var tmp = DeclarationData.Wheels.Lookup(wheels); - Assert.AreEqual(intertia, tmp.Inertia.Value(), Tolerance); - Assert.AreEqual(dynamicRadius, tmp.DynamicTyreRadius.Value(), Tolerance); - Assert.AreEqual(sizeClass, tmp.SizeClass); - } - - [TestCase("15° DC Rims", 3.03, 3.05)] - public void RimsDataTest(string rim, double fa, double fb) - { - var tmp = DeclarationData.Rims.Lookup(rim); - - Assert.AreEqual(fa, tmp.F_a, Tolerance); - Assert.AreEqual(fb, tmp.F_b, Tolerance); + AssertHelper.AreRelativeEqual(inertia, tmp.Inertia); + AssertHelper.AreRelativeEqual(dynamicRadius, tmp.DynamicTyreRadius); + AssertHelper.AreRelativeEqual(circumferenceFactor, tmp.CircumferenceFactor); } [ @@ -103,6 +101,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration Assert.AreEqual(expectedPt1, DeclarationData.PT1.Lookup(rpm.RPMtoRad()).Value(), Tolerance); } + [TestCase] public void PT1ExceptionsTest() { // EXTRAPOLATE @@ -122,11 +121,11 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration }; var r = new Random(); - for (var i = 0; i < Missions.Length; i++) { + for (var i = 0; i < _missions.Length; i++) { var urban = r.NextDouble() * 2; var rural = r.NextDouble() * 2; var motorway = r.NextDouble() * 2; - var whtcValue = whtc.Lookup(Missions[i], rural: rural, urban: urban, motorway: motorway); + var whtcValue = whtc.Lookup(_missions[i], rural: rural, urban: urban, motorway: motorway); Assert.AreEqual(urban * factors.urban[i] + rural * factors.rural[i] + motorway * factors.motorway[i], whtcValue); } @@ -160,43 +159,29 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration Assert.AreEqual(expected, lookup, 1e-8); } - [Test] - public void AirDragTest() + [TestCase("RigidSolo", 0.013526, 0.017746, -0.000666), + TestCase("RigidTrailer", 0.017125, 0.072275, -0.004148), + TestCase("TractorSemitrailer", 0.034767, 0.039367, -0.001897), + TestCase("CoachBus", -0.000794, 0.02109, -0.00109)] + public void AirDrag_WithStringKey(string key, double a1, double a2, double a3) { - var airDrag = DeclarationData.AirDrag; - - var expected = new Dictionary<string, AirDrag.AirDragEntry> { - { "RigidSolo", new AirDrag.AirDragEntry { A1 = 0.013526, A2 = 0.017746, A3 = -0.000666 } }, - { "RigidTrailer", new AirDrag.AirDragEntry { A1 = 0.017125, A2 = 0.072275, A3 = -0.004148 } }, - { "TractorSemitrailer", new AirDrag.AirDragEntry { A1 = 0.034767, A2 = 0.039367, A3 = -0.001897 } }, - { "CoachBus", new AirDrag.AirDragEntry { A1 = -0.000794, A2 = 0.02109, A3 = -0.00109 } } - }; - - foreach (var kv in expected) { - Assert.AreEqual(kv.Value, airDrag.Lookup(kv.Key)); - } - - var expectedCat = new Dictionary<VehicleCategory, AirDrag.AirDragEntry> { - { - VehicleCategory.RigidTruck, - new AirDrag.AirDragEntry { A1 = 0.013526, A2 = 0.017746, A3 = -0.000666 } - }, { - VehicleCategory.Tractor, - new AirDrag.AirDragEntry { A1 = 0.034767, A2 = 0.039367, A3 = -0.001897 } - }, { - VehicleCategory.CityBus, - new AirDrag.AirDragEntry { A1 = -0.000794, A2 = 0.02109, A3 = -0.00109 } - }, { - VehicleCategory.Coach, new AirDrag.AirDragEntry { A1 = -0.000794, A2 = 0.02109, A3 = -0.00109 } - }, { - VehicleCategory.InterurbanBus, - new AirDrag.AirDragEntry { A1 = -0.000794, A2 = 0.02109, A3 = -0.00109 } - } - }; + var value = DeclarationData.AirDrag.Lookup(key); + Assert.AreEqual(a1, value.A1); + Assert.AreEqual(a2, value.A2); + Assert.AreEqual(a3, value.A3); + } - foreach (var kv in expectedCat) { - Assert.AreEqual(kv.Value, airDrag.Lookup(kv.Key)); - } + [TestCase(VehicleCategory.RigidTruck, 0.013526, 0.017746, -0.000666), + TestCase(VehicleCategory.Tractor, 0.034767, 0.039367, -0.001897), + TestCase(VehicleCategory.CityBus, -0.000794, 0.02109, -0.00109), + TestCase(VehicleCategory.Coach, -0.000794, 0.02109, -0.00109), + TestCase(VehicleCategory.InterurbanBus, -0.000794, 0.02109, -0.00109)] + public void AirDrag_WithVehicleCategory(VehicleCategory cat, double a1, double a2, double a3) + { + var value = DeclarationData.AirDrag.Lookup(cat); + Assert.AreEqual(a1, value.A1); + Assert.AreEqual(a2, value.A2); + Assert.AreEqual(a3, value.A3); } [ @@ -239,216 +224,192 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration } [ - // fixed points - TestCase(150, 1.000, 1.000, 0.00), - TestCase(150, 1.100, 1.000, -40.34), - TestCase(150, 1.222, 1.000, -80.34), - TestCase(150, 1.375, 1.000, -136.11), - TestCase(150, 1.571, 1.000, -216.52), - TestCase(150, 1.833, 1.000, -335.19), - TestCase(150, 2.200, 1.000, -528.77), - TestCase(150, 2.750, 1.000, -883.40), - TestCase(150, 4.400, 1.000, -2462.17), - TestCase(150, 11.000, 1.000, -16540.98), - // interpolated - TestCase(150, 1.0025, 1.0, 0.0), - TestCase(150, 1.0525, 1.0, -20.17), - TestCase(150, 1.161, 1.0, -60.34), - TestCase(150, 1.2985, 1.0, -108.225), - TestCase(150, 1.473, 1.0, -176.315), - TestCase(150, 1.702, 1.0, -275.855), - TestCase(150, 2.0165, 1.0, -431.98), - TestCase(150, 2.475, 1.0, -706.085), - TestCase(150, 3.575, 1.0, -1672.785), - TestCase(150, 7.7, 1.0, -9501.575), - // extrapolated - TestCase(150, 0.5, 1.0, 0.0), - TestCase(150, 12.0, 1.0, -18674.133), // = (12-4.4)*(-16540.98- -2462.17)/(11-4.4)+ -2462.17 + TestCase(MissionType.LongHaul, "Standard technology", 1200, 0.7), + TestCase(MissionType.RegionalDelivery, "Standard technology", 1000, 0.7), + TestCase(MissionType.UrbanDelivery, "Standard technology", 1000, 0.7), + TestCase(MissionType.MunicipalUtility, "Standard technology", 1000, 0.7), + TestCase(MissionType.Construction, "Standard technology", 1000, 0.7), + TestCase(MissionType.LongHaul, "Standard technology - LED headlights, all", 1150, 0.7), + TestCase(MissionType.RegionalDelivery, "Standard technology - LED headlights, all", 950, 0.7), + TestCase(MissionType.UrbanDelivery, "Standard technology - LED headlights, all", 950, 0.7), + TestCase(MissionType.MunicipalUtility, "Standard technology - LED headlights, all", 950, 0.7), + TestCase(MissionType.Construction, "Standard technology - LED headlights, all", 950, 0.7), ] - public void DefaultTcTest(double referenceRpm, double nu, double mu, double torque) + public void AuxElectricSystemTest(MissionType mission, string technology, double value, double efficiency) { - var referenceSpeed = referenceRpm.SI<PerSecond>(); - - var r = new Random(); - - var muLookup = DeclarationData.TorqueConverter.LookupMu(nu); - Assert.AreEqual(muLookup, mu); - - var angularSpeed = r.Next(1000).SI<PerSecond>(); - var torqueLookup = DeclarationData.TorqueConverter.LookupTorque(nu, angularSpeed, referenceSpeed); - AssertHelper.AreRelativeEqual( - torque.SI<NewtonMeter>() * Math.Pow((angularSpeed / referenceSpeed).Cast<Scalar>(), 2), torqueLookup); + AssertHelper.AreRelativeEqual(value / efficiency, DeclarationData.ElectricSystem.Lookup(mission, technology)); } - [Test] - public void AuxElectricSystemTest() + [ + TestCase(MissionType.Interurban, "Standard technology"), + TestCase(MissionType.LongHaul, "Standard technology - Flux-Compensator") + ] + public void AuxElectricSystem_NotExistingError(MissionType mission, string technology) { - var es = DeclarationData.ElectricSystem; - - var expected = new[] { - new { Mission = MissionType.LongHaul, Base = 1240.SI<Watt>(), LED = 1190.SI<Watt>(), Efficiency = 0.7 }, - new { - Mission = MissionType.RegionalDelivery, - Base = 1055.SI<Watt>(), - LED = 1005.SI<Watt>(), - Efficiency = 0.7 - }, - new { - Mission = MissionType.UrbanDelivery, - Base = 974.SI<Watt>(), - LED = 924.SI<Watt>(), - Efficiency = 0.7 - }, - new { - Mission = MissionType.MunicipalUtility, - Base = 974.SI<Watt>(), - LED = 924.SI<Watt>(), - Efficiency = 0.7 - }, - new { - Mission = MissionType.Construction, - Base = 975.SI<Watt>(), - LED = 925.SI<Watt>(), - Efficiency = 0.7 - }, - new { Mission = MissionType.HeavyUrban, Base = 0.SI<Watt>(), LED = 0.SI<Watt>(), Efficiency = 1.0 }, - new { Mission = MissionType.Urban, Base = 0.SI<Watt>(), LED = 0.SI<Watt>(), Efficiency = 1.0 }, - new { Mission = MissionType.Suburban, Base = 0.SI<Watt>(), LED = 0.SI<Watt>(), Efficiency = 1.0 }, - new { Mission = MissionType.Interurban, Base = 0.SI<Watt>(), LED = 0.SI<Watt>(), Efficiency = 1.0 }, - new { Mission = MissionType.Coach, Base = 0.SI<Watt>(), LED = 0.SI<Watt>(), Efficiency = 1.0 } - }; - Assert.AreEqual(expected.Length, Enum.GetValues(typeof(MissionType)).Length); - - foreach (var expectation in expected) { - var baseConsumption = es.Lookup(expectation.Mission, null); - var leds = es.Lookup(expectation.Mission, new[] { "LED lights" }); - - AssertHelper.AreRelativeEqual(expectation.Base / expectation.Efficiency, baseConsumption); - AssertHelper.AreRelativeEqual(expectation.LED / expectation.Efficiency, leds); - } + AssertHelper.Exception<VectoException>(() => { DeclarationData.ElectricSystem.Lookup(mission, technology); }); } [ - TestCase("", - new[] { 618, 671, 516, 566, 1037, 0, 0, 0, 0, 0 }), - TestCase("Crankshaft mounted - Electronically controlled visco clutch (Default)", - new[] { 618, 671, 516, 566, 1037, 0, 0, 0, 0, 0 }), - TestCase("Crankshaft mounted - Bimetallic controlled visco clutch", new[] { 818, 871, 676, 766, 1277, 0, 0, 0, 0, 0 } - ), - TestCase("Crankshaft mounted - Discrete step clutch", new[] { 668, 721, 616, 616, 1157, 0, 0, 0, 0, 0 }), - TestCase("Crankshaft mounted - On/Off clutch", new[] { 718, 771, 666, 666, 1237, 0, 0, 0, 0, 0 }), + TestCase("", new[] { 618, 671, 516, 566, 1037 }), + TestCase("Crankshaft mounted - Electronically controlled visco clutch", new[] { 618, 671, 516, 566, 1037 }), + TestCase("Crankshaft mounted - Bimetallic controlled visco clutch", new[] { 818, 871, 676, 766, 1277 }), + TestCase("Crankshaft mounted - Discrete step clutch", new[] { 668, 721, 616, 616, 1157 }), + TestCase("Crankshaft mounted - On/off clutch", new[] { 718, 771, 666, 666, 1237 }), TestCase("Belt driven or driven via transm. - Electronically controlled visco clutch", - new[] { 889, 944, 733, 833, 1378, 0, 0, 0, 0, 0 }), + new[] { 989, 1044, 833, 933, 1478 }), TestCase("Belt driven or driven via transm. - Bimetallic controlled visco clutch", - new[] { 1089, 1144, 893, 1033, 1618, 0, 0, 0, 0, 0 }), - TestCase("Belt driven or driven via transm. - Discrete step clutch", - new[] { 939, 994, 883, 883, 1498, 0, 0, 0, 0, 0 } - ), - TestCase("Belt driven or driven via transm. - On/Off clutch", new[] { 989, 1044, 933, 933, 1578, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic driven - Variable displacement pump", new[] { 738, 955, 632, 717, 1672, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic driven - Constant displacement pump", new[] { 1000, 1200, 800, 900, 2100, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic driven - Electronically controlled", new[] { 700, 800, 600, 600, 1400, 0, 0, 0, 0, 0 }), + new[] { 1189, 1244, 993, 1133, 1718 }), + TestCase("Belt driven or driven via transm. - Discrete step clutch", new[] { 1039, 1094, 983, 983, 1598 }), + TestCase("Belt driven or driven via transm. - On/off clutch", new[] { 1089, 1144, 1033, 1033, 1678 }), + TestCase("Hydraulic driven - Variable displacement pump", new[] { 938, 1155, 832, 917, 1872 }), + TestCase("Hydraulic driven - Constant displacement pump", new[] { 1200, 1400, 1000, 1100, 2300 }), + TestCase("Hydraulic driven - Electronically controlled", new[] { 700, 800, 600, 600, 1400 }), ] public void AuxFanTechTest(string technology, int[] expected) { - for (var i = 0; i < Missions.Length; i++) { - var value = DeclarationData.Fan.Lookup(Missions[i], technology); + for (var i = 0; i < _missions.Length; i++) { + var value = DeclarationData.Fan.Lookup(_missions[i], technology); Assert.AreEqual(expected[i], value.Value(), Tolerance); } } - [Test] - public void AuxHeatingVentilationAirConditionTest() + [TestCase("Superfluid Hydraulic", MissionType.LongHaul, TestName = "AuxFanTechError( wrong tech )"), + TestCase("Hydraulic driven - Electronically controlled", MissionType.Coach, + TestName = "AuxFanTechError( wrong mission )") + ] + public void AuxFanTechError(string technology, MissionType missionType) { - var hvac = DeclarationData.HeatingVentilationAirConditioning; - - var expected = new Dictionary<VehicleClass, int[]> { - { VehicleClass.Class1, new[] { 0, 150, 150, 0, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class2, new[] { 200, 200, 150, 0, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class3, new[] { 0, 200, 150, 0, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class4, new[] { 350, 200, 0, 300, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class5, new[] { 350, 200, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class6, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class7, new[] { 0, 0, 0, 0, 200, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class8, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class9, new[] { 350, 200, 0, 300, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class10, new[] { 350, 200, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class11, new[] { 0, 0, 0, 0, 200, 0, 0, 0, 0, 0 } }, - { VehicleClass.Class12, new[] { 0, 0, 0, 0, 200, 0, 0, 0, 0, 0 } } - }; + AssertHelper.Exception<VectoException>(() => DeclarationData.Fan.Lookup(missionType, technology)); + } - for (var i = 0; i < Missions.Length; i++) { - foreach (var expect in expected) { - var value = hvac.Lookup(Missions[i], expect.Key); - Assert.AreEqual(expect.Value[i], value.Value(), Tolerance); + [TestCase(VehicleClass.Class1, new[] { 0, 150, 150, 0, 0 }), + TestCase(VehicleClass.Class2, new[] { 200, 200, 150, 0, 0 }), + TestCase(VehicleClass.Class3, new[] { 0, 200, 150, 0, 0 }), + TestCase(VehicleClass.Class4, new[] { 350, 200, 0, 300, 0 }), + TestCase(VehicleClass.Class5, new[] { 350, 200, 0, 0, 0 }), + TestCase(VehicleClass.Class9, new[] { 350, 200, 0, 300, 0 }), + TestCase(VehicleClass.Class10, new[] { 350, 200, 0, 0, 0 }), + TestCase(VehicleClass.Class11, new[] { 350, 200, 0, 300, 200 }), + TestCase(VehicleClass.Class12, new[] { 350, 200, 0, 0, 200 }), + TestCase(VehicleClass.Class16, new[] { 0, 0, 0, 0, 200 })] + public void AuxHeatingVentilationAirConditionTest(VehicleClass vehicleClass, int[] expected) + { + for (var i = 0; i < expected.Length; i++) { + if (expected[i] > 0) { + AssertHelper.AreRelativeEqual(expected[i], + DeclarationData.HeatingVentilationAirConditioning.Lookup(_missions[i], vehicleClass)); + } else { + var i1 = i; + AssertHelper.Exception<VectoException>( + () => DeclarationData.HeatingVentilationAirConditioning.Lookup(_missions[i1], vehicleClass)); } } } [Test, - TestCase(VehicleClass.Class1, new[] { 0, 1300, 1240, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class2, new[] { 1180, 1280, 1320, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class3, new[] { 0, 1360, 1380, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class4, new[] { 1300, 1340, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class5, new[] { 1340, 1820, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class6, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class7, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class8, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class9, new[] { 1340, 1540, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class10, new[] { 1340, 1820, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class11, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase(VehicleClass.Class12, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), + TestCase("Small", new[] { 1400, 1300, 1200, 1200, 1300 }), + TestCase("Small + ESS", new[] { 900, 800, 800, 800, 800 }), + TestCase("Small + visco clutch", new[] { 800, 700, 700, 700, 700 }), + TestCase("Small + mech. clutch", new[] { 600, 600, 650, 650, 600 }), + TestCase("Small + ESS + AMS", new[] { 500, 400, 500, 500, 400 }), + TestCase("Small + visco clutch + AMS", new[] { 400, 300, 400, 400, 300 }), + TestCase("Small + mech. clutch + AMS", new[] { 200, 200, 350, 350, 200 }), + TestCase("Medium Supply 1-stage", new[] { 1600, 1400, 1350, 1350, 1500 }), + TestCase("Medium Supply 1-stage + ESS", new[] { 1000, 900, 900, 900, 900 }), + TestCase("Medium Supply 1-stage + visco clutch", new[] { 850, 800, 800, 800, 750 }), + TestCase("Medium Supply 1-stage + mech. clutch", new[] { 600, 550, 550, 550, 600 }), + TestCase("Medium Supply 1-stage + ESS + AMS", new[] { 600, 700, 700, 700, 500 }), + TestCase("Medium Supply 1-stage + visco clutch + AMS", new[] { 450, 600, 600, 600, 350 }), + TestCase("Medium Supply 1-stage + mech. clutch + AMS", new[] { 200, 350, 350, 350, 200 }), + TestCase("Medium Supply 2-stage", new[] { 2100, 1750, 1700, 1700, 2100 }), + TestCase("Medium Supply 2-stage + ESS", new[] { 1100, 1050, 1000, 1000, 1000 }), + TestCase("Medium Supply 2-stage + visco clutch", new[] { 1000, 850, 800, 800, 900 }), + TestCase("Medium Supply 2-stage + mech. clutch", new[] { 700, 650, 600, 600, 800 }), + TestCase("Medium Supply 2-stage + ESS + AMS", new[] { 700, 850, 800, 800, 500 }), + TestCase("Medium Supply 2-stage + visco clutch + AMS", new[] { 600, 650, 600, 600, 400 }), + TestCase("Medium Supply 2-stage + mech. clutch + AMS", new[] { 300, 450, 400, 400, 300 }), + TestCase("Large Supply", new[] { 4300, 3600, 3500, 3500, 4100 }), + TestCase("Large Supply + ESS", new[] { 1600, 1300, 1200, 1200, 1500 }), + TestCase("Large Supply + visco clutch", new[] { 1300, 1100, 1000, 1000, 1200 }), + TestCase("Large Supply + mech. clutch", new[] { 800, 800, 700, 700, 900 }), + TestCase("Large Supply + ESS + AMS", new[] { 1100, 1000, 1000, 1000, 1000 }), + TestCase("Large Supply + visco clutch + AMS", new[] { 800, 800, 800, 800, 700 }), + TestCase("Large Supply + mech. clutch + AMS", new[] { 300, 500, 500, 500, 400 }), ] - public void AuxPneumaticSystemTest(VehicleClass vehicleClass, int[] expected) + public void AuxPneumaticSystemTest(string technology, int[] expected) { - var ps = DeclarationData.PneumaticSystem; - - for (var i = 0; i < Missions.Length; i++) { - var value = ps.Lookup(Missions[i], vehicleClass); - Assert.AreEqual(expected[i], value.Value(), Tolerance); + for (var i = 0; i < _missions.Length; i++) { + var value = DeclarationData.PneumaticSystem.Lookup(_missions[i], technology); + AssertHelper.AreRelativeEqual(expected[i], value); } } - [Test, - TestCase("Fixed displacement", VehicleClass.Class1, new[] { 0, 260, 270, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class2, new[] { 370, 320, 310, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class3, new[] { 0, 340, 350, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class4, new[] { 610, 530, 0, 530, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class5, new[] { 720, 630, 620, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class6, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class7, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class8, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class9, new[] { 720, 550, 0, 550, 0, 0, 0, 0, 0, 0 }), - TestCase("Fixed displacement", VehicleClass.Class10, new[] { 570, 530, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class1, new[] { 0, 156, 162, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class2, new[] { 222, 192, 186, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class3, new[] { 0, 204, 210, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class4, new[] { 366, 318, 0, 318, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class5, new[] { 432, 378, 372, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class6, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class7, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class8, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class9, new[] { 432, 330, 0, 330, 0, 0, 0, 0, 0, 0 }), - TestCase("Variable displacement", VehicleClass.Class10, new[] { 342, 318, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class1, new[] { 0, 225, 235, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class2, new[] { 322, 278, 269, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class3, new[] { 0, 295, 304, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class4, new[] { 531, 460, 0, 460, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class5, new[] { 627, 546, 540, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class6, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class7, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class8, new[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class9, new[] { 627, 478, 0, 478, 0, 0, 0, 0, 0, 0 }), - TestCase("Hydraulic supported by electric", VehicleClass.Class10, new[] { 498, 461, 0, 0, 0, 0, 0, 0, 0, 0 }), + [ + TestCase(MissionType.LongHaul, VehicleClass.Class2, 370, "Fixed displacement", null, null, null), + TestCase(MissionType.LongHaul, VehicleClass.Class4, 610, "Fixed displacement", null, null, null), + TestCase(MissionType.LongHaul, VehicleClass.Class5, 720, "Fixed displacement", null, null, null), + TestCase(MissionType.LongHaul, VehicleClass.Class9, 720, "Fixed displacement", null, null, null), + TestCase(MissionType.LongHaul, VehicleClass.Class10, 570, "Fixed displacement", null, null, null), + TestCase(MissionType.LongHaul, VehicleClass.Class11, 720, "Fixed displacement", null, null, null), + TestCase(MissionType.LongHaul, VehicleClass.Class12, 570, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class1, 280, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 340, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class3, 370, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class4, 570, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class5, 670, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class9, 590, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class10, 570, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class11, 590, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class12, 570, "Fixed displacement", null, null, null), + TestCase(MissionType.UrbanDelivery, VehicleClass.Class1, 270, "Fixed displacement", null, null, null), + TestCase(MissionType.UrbanDelivery, VehicleClass.Class2, 310, "Fixed displacement", null, null, null), + TestCase(MissionType.UrbanDelivery, VehicleClass.Class3, 350, "Fixed displacement", null, null, null), + TestCase(MissionType.UrbanDelivery, VehicleClass.Class5, 620, "Fixed displacement", null, null, null), + TestCase(MissionType.MunicipalUtility, VehicleClass.Class4, 510, "Fixed displacement", null, null, null), + TestCase(MissionType.MunicipalUtility, VehicleClass.Class9, 510, "Fixed displacement", null, null, null), + TestCase(MissionType.MunicipalUtility, VehicleClass.Class11, 510, "Fixed displacement", null, null, null), + TestCase(MissionType.Construction, VehicleClass.Class11, 770, "Fixed displacement", null, null, null), + TestCase(MissionType.Construction, VehicleClass.Class12, 770, "Fixed displacement", null, null, null), + TestCase(MissionType.Construction, VehicleClass.Class16, 770, "Fixed displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 325.5, "Fixed displacement with elec. control", null, + null, + null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 289, "Dual displacement", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 255, "Variable displacement mech. controlled", null, null, + null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 204, "Variable displacement elec. controlled", null, null, + null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 92.8571, "Electric", null, null, null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 665, "Fixed displacement", "Fixed displacement", null, + null), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 1295, "Fixed displacement", "Fixed displacement", + "Fixed displacement", "Fixed displacement"), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, 1021.5, "Dual displacement", + "Variable displacement mech. controlled", "Fixed displacement with elec. control", + "Variable displacement elec. controlled"), ] - public void AuxSteeringPumpTest(string technology, VehicleClass hdvClass, int[] expected) + public void Aux_SteeringPumpLookupValues(MissionType mission, VehicleClass hdvClass, double expected, string axle1, + string axle2, string axle3, string axle4) { - var sp = DeclarationData.SteeringPump; + // mk remark: made the test call with 4 axle params, so that the test name is clear in the test explorer. + AssertHelper.AreRelativeEqual(expected, + DeclarationData.SteeringPump.Lookup(mission, hdvClass, + new[] { axle1, axle2, axle3, axle4 }.TakeWhile(a => a != null).ToArray())); + } - for (var i = 0; i < Missions.Length; i++) { - var value = sp.Lookup(Missions[i], hdvClass, technology); - Assert.AreEqual(expected[i], value.Value(), Tolerance); - } + [TestCase(MissionType.LongHaul, VehicleClass.Class1, "Dual displacement", + TestName = "Aux_SteeringPumpLookupFail( No Value )"), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, "Super displacement", + TestName = "Aux_SteeringPumpLookupFail( Wrong Tech )"), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, "Dual displacement", "Dual displacement", + "Dual displacement", "Dual displacement", "Dual displacement", TestName = "Aux_SteeringPumpLookupFail( >4 Techs )"), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, TestName = "Aux_SteeringPumpLookupFail( Null Techs )"), + TestCase(MissionType.RegionalDelivery, VehicleClass.Class2, new string[0], + TestName = "Aux_SteeringPumpLookupFail( 0 Techs )"), + ] + public void Aux_SteeringPumpLookupFail(MissionType mission, VehicleClass hdvClass, params string[] tech) + { + AssertHelper.Exception<VectoException>(() => DeclarationData.SteeringPump.Lookup(mission, hdvClass, tech)); } [ @@ -699,7 +660,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration Assert.AreEqual(deltaCdA.SI<SquareMeter>(), m.DeltaCdA); } - public void EqualAcceleration(AccelerationCurveData data, double velocity, double acceleration, + private static void EqualAcceleration(AccelerationCurveData data, double velocity, double acceleration, double deceleration) { var entry = data.Lookup(velocity.KMPHtoMeterPerSecond()); @@ -707,7 +668,7 @@ namespace TUGraz.VectoCore.Tests.Models.Declaration Assert.AreEqual(entry.Deceleration.Value(), deceleration, Tolerance); } - public void TestAcceleration(AccelerationCurveData data) + private static void TestAcceleration(AccelerationCurveData data) { // FIXED POINTS EqualAcceleration(data, 0, 1, -1); diff --git a/VectoCore/VectoCoreTest/Models/Simulation/AuxTests.cs b/VectoCore/VectoCoreTest/Models/Simulation/AuxTests.cs index 45c5cd482438e933d404c1671665243337ec265f..1c4aa724d8ff6e60a2c4cf93440a6d687e86de6b 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/AuxTests.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/AuxTests.cs @@ -29,10 +29,6 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using TUGraz.VectoCore.Tests.Utils; -using TUGraz.VectoCore.Models.Declaration; -using TUGraz.VectoCore.Models.Simulation.Data; -using TUGraz.VectoCore.Models.Simulation.Impl; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; @@ -40,10 +36,14 @@ using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader; using TUGraz.VectoCore.InputData.Reader.ComponentData; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Impl; using TUGraz.VectoCore.OutputData; using TUGraz.VectoCore.OutputData.FileIO; +using TUGraz.VectoCore.Tests.Utils; // ReSharper disable ObjectCreationAsStatement @@ -77,10 +77,11 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation aux.AddConstant("FAN", DeclarationData.Fan.Lookup(MissionType.LongHaul, "Hydraulic driven - Constant displacement pump")); - aux.AddConstant("PS", DeclarationData.PneumaticSystem.Lookup(mission, hdvClass)); + aux.AddConstant("PS", DeclarationData.PneumaticSystem.Lookup(mission, "Medium Supply 1-stage")); aux.AddConstant("STP", - DeclarationData.SteeringPump.Lookup(MissionType.LongHaul, hdvClass, "Variable displacement")); - aux.AddConstant("ES", DeclarationData.ElectricSystem.Lookup(mission, null)); + DeclarationData.SteeringPump.Lookup(MissionType.LongHaul, hdvClass, + new[] { "Variable displacement mech. controlled" })); + aux.AddConstant("ES", DeclarationData.ElectricSystem.Lookup(mission)); aux.AddConstant("AC", DeclarationData.HeatingVentilationAirConditioning.Lookup(mission, hdvClass)); diff --git a/VectoCore/VectoCoreTest/Models/Simulation/LossMapRangeValidationTest.cs b/VectoCore/VectoCoreTest/Models/Simulation/LossMapRangeValidationTest.cs index 9c9dfc44e7f822c0d1efda443bdda9c2c006f760..38f859b658ba3abd0302b10ca4bff15a5b219dbe 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/LossMapRangeValidationTest.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/LossMapRangeValidationTest.cs @@ -29,22 +29,23 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using Microsoft.VisualStudio.TestTools.UnitTesting; using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.InputData.Reader; +using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Models.Simulation.Data; using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; using TUGraz.VectoCore.OutputData.FileIO; using TUGraz.VectoCore.Tests.Utils; -using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Models.Simulation { @@ -70,8 +71,27 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation var gearboxData = CreateGearboxData(GearboxDirectLoss, GearboxIndirectLoss); var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(EngineFile); var axleGearData = CreateAxleGearData(AxleGearLossMap); + var vehicleData = new VehicleData { + DynamicTyreRadius = 0.85.SI<Meter>(), + Loading = 0.SI<Kilogram>(), + CurbWeight = 2000.SI<Kilogram>(), + AxleData = + new List<Axle> { + new Axle { + TwinTyres = false, + AxleWeightShare = 1, + TyreTestLoad = 50000.SI<Newton>(), + Inertia = 10.SI<KilogramSquareMeter>() + } + } + }; - var runData = new VectoRunData { GearboxData = gearboxData, EngineData = engineData, AxleGearData = axleGearData }; + var runData = new VectoRunData { + GearboxData = gearboxData, + EngineData = engineData, + AxleGearData = axleGearData, + VehicleData = vehicleData + }; var result = VectoRunData.ValidateRunData(runData, new ValidationContext(runData)); Assert.IsTrue(ValidationResult.Success == result); @@ -114,7 +134,21 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation { var gearboxData = CreateGearboxData(GearboxDirectLoss, GearboxIndirectLoss); var engineData = MockSimulationDataFactory.CreateEngineDataFromFile(EngineFile); - var runData = new VectoRunData { GearboxData = gearboxData, EngineData = engineData }; + var vehicleData = new VehicleData { + DynamicTyreRadius = 0.85.SI<Meter>(), + Loading = 0.SI<Kilogram>(), + CurbWeight = 2000.SI<Kilogram>(), + AxleData = + new List<Axle> { + new Axle { + TwinTyres = false, + AxleWeightShare = 1, + TyreTestLoad = 50000.SI<Newton>(), + Inertia = 10.SI<KilogramSquareMeter>() + } + } + }; + var runData = new VectoRunData { GearboxData = gearboxData, EngineData = engineData, VehicleData = vehicleData }; var result = VectoRunData.ValidateRunData(runData, new ValidationContext(runData)); Assert.IsTrue(ValidationResult.Success == result); Assert.IsFalse(runData.IsValid()); diff --git a/VectoCore/VectoCoreTest/Models/Simulation/MeasuredSpeedModeTest.cs b/VectoCore/VectoCoreTest/Models/Simulation/MeasuredSpeedModeTest.cs index 5e8691d2b833e4a8924faef6e3e7812fb99a7711..20c3df20358d0ef065c5b9c9664bba0345b6b9e6 100644 --- a/VectoCore/VectoCoreTest/Models/Simulation/MeasuredSpeedModeTest.cs +++ b/VectoCore/VectoCoreTest/Models/Simulation/MeasuredSpeedModeTest.cs @@ -29,25 +29,26 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Collections.Generic; using System.Data; using System.Linq; -using TUGraz.VectoCore.Utils; -using System.Collections.Generic; -using TUGraz.VectoCore.OutputData; -using TUGraz.VectoCore.InputData.Reader; -using TUGraz.VectoCore.OutputData.FileIO; -using TUGraz.VectoCore.InputData.FileIO.JSON; -using TUGraz.VectoCore.Models.Simulation.Data; -using TUGraz.VectoCore.Models.Simulation.Impl; -using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.InputData.FileIO.JSON; +using TUGraz.VectoCore.InputData.Reader; +using TUGraz.VectoCore.Models.Declaration; +using TUGraz.VectoCore.Models.Simulation.Data; +using TUGraz.VectoCore.Models.Simulation.Impl; using TUGraz.VectoCore.Models.SimulationComponent.Data; using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine; using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.OutputData; +using TUGraz.VectoCore.OutputData.FileIO; using TUGraz.VectoCore.Tests.Utils; +using TUGraz.VectoCore.Utils; // ReSharper disable UnusedVariable @@ -114,7 +115,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation inputData = @"<t>,<grad>,<Padd>,<n>,<gear> 0 ,0"; AssertHelper.Exception<VectoException>(() => TestCycleRead(inputData, CycleType.MeasuredSpeedGear), - "Failed to read stream: Line 1: The number of values is not correct. Expected 5 Columns, Got 2 Columns"); + "Line 1: The number of values is not correct. Expected 5 Columns, Got 2 Columns"); } /// <summary> @@ -171,7 +172,7 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation inputData = @"<t>,<v>,<grad>,<Padd>,<vair_res>,<vair_beta>,<Aux_Alt> 0 ,0"; AssertHelper.Exception<VectoException>(() => TestCycleRead(inputData, CycleType.MeasuredSpeed), - "Failed to read stream: Line 1: The number of values is not correct. Expected 7 Columns, Got 2 Columns"); + "Line 1: The number of values is not correct. Expected 7 Columns, Got 2 Columns"); } private static void TestCycleRead(string inputData, CycleType cycleType, bool autoCycle = true, @@ -231,7 +232,14 @@ namespace TUGraz.VectoCore.Tests.Models.Simulation CrossWindCorrectionCurve = new CrosswindCorrectionCdxALookup( CrossWindCorrectionCurveReader.GetNoCorrectionCurve(6.16498344.SI<SquareMeter>()), - CrossWindCorrectionMode.NoCorrection) + CrossWindCorrectionMode.NoCorrection), + GrossVehicleWeight = 12000.SI<Kilogram>(), + CurbWeight = 3400.SI<Kilogram>(), + DynamicTyreRadius = 0.5.SI<Meter>(), + AxleData = + new List<Axle> { + new Axle { AxleWeightShare = 1.0, TyreTestLoad = 52532.SI<Newton>(), Inertia = 10.SI<KilogramSquareMeter>() } + } }, AxleGearData = new AxleGearData { AxleGear = new GearData { Ratio = 2.3 } }, EngineData = new CombustionEngineData { IdleSpeed = 560.RPMtoRad(), FullLoadCurve = fullLoadCurve }, diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponentData/AuxiliaryTypeHelperTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponentData/AuxiliaryTypeHelperTest.cs index 868c10ab9c72ee76c6a5c0aa3cfd020c700fbcdd..6e611b978cd4a4f2f902a2cd60b42a68ab133685 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponentData/AuxiliaryTypeHelperTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponentData/AuxiliaryTypeHelperTest.cs @@ -33,9 +33,8 @@ using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCommon.Models; using TUGraz.VectoCore.Configuration; -using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.Declaration; using TUGraz.VectoCore.Tests.Utils; -using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData { diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponentData/ValidationTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponentData/ValidationTest.cs index dfa575304fc3de210ef6f9e3409274d7a05dfe69..f1513ef86e9744d8f1fb45c6a489e7dbadb77b75 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponentData/ValidationTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponentData/ValidationTest.cs @@ -29,12 +29,12 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data; using System.Diagnostics.CodeAnalysis; using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.InputData.Reader; @@ -173,7 +173,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData [TestMethod] public void ValidationModeVehicleDataTest() { - var vehicleData = new VehicleData() { + var vehicleData = new VehicleData { AxleConfiguration = AxleConfiguration.AxleConfig_4x2, Creator = "Mr. Test", CrossWindCorrectionMode = CrossWindCorrectionMode.NoCorrection, @@ -184,29 +184,30 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData DynamicTyreRadius = 0.5.SI<Meter>(), //CurbWeigthExtra = 0.SI<Kilogram>(), Loading = 12000.SI<Kilogram>(), - GrossVehicleWeight = 16000.SI<Kilogram>() - }; - vehicleData.AxleData = new List<Axle>() { - new Axle() { - AxleType = AxleType.VehicleNonDriven, - AxleWeightShare = 0.4, - Inertia = 0.5.SI<KilogramSquareMeter>(), - RollResistanceCoefficient = 0.00555, - TyreTestLoad = 33000.SI<Newton>() - }, - new Axle() { - AxleType = AxleType.VehicleNonDriven, - AxleWeightShare = 0.6, - Inertia = 0.5.SI<KilogramSquareMeter>(), - RollResistanceCoefficient = 0.00555, - TyreTestLoad = 33000.SI<Newton>() - }, + GrossVehicleWeight = 16000.SI<Kilogram>(), + TrailerGrossVehicleWeight = 0.SI<Kilogram>(), + AxleData = new List<Axle> { + new Axle { + AxleType = AxleType.VehicleNonDriven, + AxleWeightShare = 0.4, + Inertia = 0.5.SI<KilogramSquareMeter>(), + RollResistanceCoefficient = 0.00555, + TyreTestLoad = 33000.SI<Newton>() + }, + new Axle { + AxleType = AxleType.VehicleNonDriven, + AxleWeightShare = 0.6, + Inertia = 0.5.SI<KilogramSquareMeter>(), + RollResistanceCoefficient = 0.00555, + TyreTestLoad = 33000.SI<Newton>() + }, + } }; var result = vehicleData.Validate(ExecutionMode.Engineering); - Assert.IsTrue(!result.Any()); + Assert.IsTrue(!result.Any(), "validation should have succeded but failed." + string.Concat(result)); result = vehicleData.Validate(ExecutionMode.Declaration); - Assert.IsTrue(result.Any(), "validation should have failed, but succeeded"); + Assert.IsTrue(result.Any(), "validation should have failed, but succeeded."); } /// <summary> @@ -234,7 +235,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData LossMap = TransmissionLossMapReader.ReadFromFile(@"TestData\Components\limited.vtlm", 1, "1"), } }; - var vehicleData = new VehicleData() { + var vehicleData = new VehicleData { AxleConfiguration = AxleConfiguration.AxleConfig_4x2, Creator = "Mr. Test", CrossWindCorrectionMode = CrossWindCorrectionMode.NoCorrection, @@ -245,23 +246,24 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData DynamicTyreRadius = 0.5.SI<Meter>(), //CurbWeigthExtra = 0.SI<Kilogram>(), Loading = 12000.SI<Kilogram>(), - GrossVehicleWeight = 16000.SI<Kilogram>() - }; - vehicleData.AxleData = new List<Axle>() { - new Axle() { - AxleType = AxleType.VehicleNonDriven, - AxleWeightShare = 0.4, - Inertia = 0.5.SI<KilogramSquareMeter>(), - RollResistanceCoefficient = 0.00555, - TyreTestLoad = 33000.SI<Newton>() - }, - new Axle() { - AxleType = AxleType.VehicleNonDriven, - AxleWeightShare = 0.6, - Inertia = 0.5.SI<KilogramSquareMeter>(), - RollResistanceCoefficient = 0.00555, - TyreTestLoad = 33000.SI<Newton>() - }, + GrossVehicleWeight = 16000.SI<Kilogram>(), + TrailerGrossVehicleWeight = 0.SI<Kilogram>(), + AxleData = new List<Axle> { + new Axle { + AxleType = AxleType.VehicleNonDriven, + AxleWeightShare = 0.4, + Inertia = 0.5.SI<KilogramSquareMeter>(), + RollResistanceCoefficient = 0.00555, + TyreTestLoad = 33000.SI<Newton>() + }, + new Axle { + AxleType = AxleType.VehicleNonDriven, + AxleWeightShare = 0.6, + Inertia = 0.5.SI<KilogramSquareMeter>(), + RollResistanceCoefficient = 0.00555, + TyreTestLoad = 33000.SI<Newton>() + }, + } }; container.RunData = new VectoRunData { @@ -294,13 +296,13 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var gearboxData = new GearboxData(); gearboxData.Gears[1] = new GearData { LossMap = TransmissionLossMapReader.ReadFromFile(@"TestData\Components\Direct Gear.vtlm", 1, "1"), - Ratio = 1 + Ratio = 1, }; var axleGearData = new AxleGearData { AxleGear = new GearData { - Ratio = 1, LossMap = TransmissionLossMapReader.ReadFromFile(@"TestData\Components\limited.vtlm", 1, "1"), + Ratio = 1, } }; diff --git a/VectoCore/VectoCoreTest/TestData/Jobs/12t Delivery Truck Engineering Efficiency.vecto b/VectoCore/VectoCoreTest/TestData/Jobs/12t Delivery Truck Engineering Efficiency.vecto index a02cb241aa72cab4521369ceb4480e3ca37d049f..ce7e7e6f07f9f0b3ed2d89a8461153a3d3a2ba32 100644 --- a/VectoCore/VectoCoreTest/TestData/Jobs/12t Delivery Truck Engineering Efficiency.vecto +++ b/VectoCore/VectoCoreTest/TestData/Jobs/12t Delivery Truck Engineering Efficiency.vecto @@ -11,7 +11,7 @@ "EngineFile": "../Components/12t Delivery Truck.veng", "GearboxFile": "../Components/12t Delivery Truck Efficiency.vgbx", "Cycles": [ - "../Cycles/Regional_Delivery.vdri", + "../Cycles/Regional_Delivery.vdri" ], "AuxiliaryAssembly": "CLASSIC", "AuxiliaryVersion": "CLASSIC",