diff --git a/VECTO.sln b/VECTO.sln index a7af431e59edd0dbe531dac7319b0cbba300f764..5f1e46d7833ba0df233ce93f045e75b0a2c75038 100644 --- a/VECTO.sln +++ b/VECTO.sln @@ -40,8 +40,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "VECTO 3", "VECTO 3", "{CC93 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoCommon", "VectoCommon\VectoCommon\VectoCommon.csproj", "{79A066AD-69A9-4223-90F6-6ED5D2D084F4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.csproj", "{9CB799AC-5025-4F91-9DC5-5048F59DE004}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelbasedTests", "VectoCore\ModelbasedTests\ModelbasedTests.csproj", "{A0256B2A-09F8-45AD-B46A-FD98D7AAAA0C}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoLegacyTests", "Tools\VectoLegacyTests\VectoLegacyTests.csproj", "{49F0275A-4517-49FA-859E-77279B9C8B18}" diff --git a/VECTO/Configuration.vb b/VECTO/Configuration.vb index 867e09ff04b597a999d119b3926c76d3fb489210..f4a18ed4ef2b193f1770165b08bb5ca9330648c1 100644 --- a/VECTO/Configuration.vb +++ b/VECTO/Configuration.vb @@ -73,7 +73,7 @@ Public Class Configuration LogSize = body.GetEx(Of Double)("LogSize") AirDensity = body.GetEx(Of Double)("AirDensity") FuelDens = body.GetEx(Of Double)("FuelDensity") - CO2perFC = body.GetEx(Of Double)("CO2perFC") + Co2PerFc = body.GetEx(Of Double)("CO2perFC") OpenCmd = body.GetEx(Of String)("OpenCmd") OpenCmdName = body.GetEx(Of String)("OpenCmdName") FirstRun = body.GetEx(Of Boolean)("FirstRun") @@ -85,7 +85,6 @@ Public Class Configuration End Sub Public Sub Save() - Dim json As New JSONWriter Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")") @@ -93,21 +92,19 @@ Public Class Configuration header.Add("AppVersion", VECTOvers) header.Add("FileVersion", FormatVersion) - Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) body.Add("ModOut", ModOut) body.Add("Mod1Hz", Mod1Hz) body.Add("LogSize", LogSize) body.Add("AirDensity", AirDensity) body.Add("FuelDensity", FuelDens) - body.Add("CO2perFC", CO2perFC) + body.Add("CO2perFC", Co2PerFc) body.Add("OpenCmd", OpenCmd) body.Add("OpenCmdName", OpenCmdName) body.Add("FirstRun", FirstRun) body.Add("DeclMode", DeclMode) - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - json.WriteFile(FilePath) + JSONFileWriter.WriteFile(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}, FilePath) End Sub End Class diff --git a/VECTO/GUI/MainForm.Designer.vb b/VECTO/GUI/MainForm.Designer.vb index 3919df2b4f99161783d2ad1189c41a17078ae9cb..c2574209af51bce6640c5dce1fb644ae2b17d0a1 100644 --- a/VECTO/GUI/MainForm.Designer.vb +++ b/VECTO/GUI/MainForm.Designer.vb @@ -43,13 +43,14 @@ Partial Class MainForm Me.ToolStripProgBarOverall = New System.Windows.Forms.ToolStripProgressBar() Me.TabControl1 = New System.Windows.Forms.TabControl() Me.TabPageGEN = New System.Windows.Forms.TabPage() + Me.btnImportXML = New System.Windows.Forms.Button() + Me.btnExportXML = New System.Windows.Forms.Button() Me.Label6 = New System.Windows.Forms.Label() Me.btStartV3 = New System.Windows.Forms.Button() Me.LbDecl = New System.Windows.Forms.Label() Me.PictureBox1 = New System.Windows.Forms.PictureBox() Me.BtGENdown = New System.Windows.Forms.Button() Me.BtGENup = New System.Windows.Forms.Button() - Me.LbAutoShDown = New System.Windows.Forms.Label() Me.ChBoxAllGEN = New System.Windows.Forms.CheckBox() Me.LvGEN = New System.Windows.Forms.ListView() Me.ColGENpath = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader) @@ -184,13 +185,14 @@ Partial Class MainForm ' 'TabPageGEN ' + Me.TabPageGEN.Controls.Add(Me.btnImportXML) + Me.TabPageGEN.Controls.Add(Me.btnExportXML) Me.TabPageGEN.Controls.Add(Me.Label6) Me.TabPageGEN.Controls.Add(Me.btStartV3) Me.TabPageGEN.Controls.Add(Me.LbDecl) Me.TabPageGEN.Controls.Add(Me.PictureBox1) Me.TabPageGEN.Controls.Add(Me.BtGENdown) Me.TabPageGEN.Controls.Add(Me.BtGENup) - Me.TabPageGEN.Controls.Add(Me.LbAutoShDown) Me.TabPageGEN.Controls.Add(Me.ChBoxAllGEN) Me.TabPageGEN.Controls.Add(Me.LvGEN) Me.TabPageGEN.Controls.Add(Me.ButtonGENremove) @@ -203,6 +205,29 @@ Partial Class MainForm Me.TabPageGEN.Text = "Job Files" Me.TabPageGEN.UseVisualStyleBackColor = True ' + 'btnImportXML + ' + Me.btnImportXML.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) + Me.btnImportXML.Location = New System.Drawing.Point(464, 271) + Me.btnImportXML.Name = "btnImportXML" + Me.btnImportXML.Size = New System.Drawing.Size(104, 23) + Me.btnImportXML.TabIndex = 23 + Me.btnImportXML.Text = "Import from XML" + Me.btnImportXML.UseVisualStyleBackColor = True + Me.btnImportXML.Visible = False + ' + 'btnExportXML + ' + Me.btnExportXML.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) + Me.btnExportXML.Enabled = False + Me.btnExportXML.Location = New System.Drawing.Point(343, 272) + Me.btnExportXML.Name = "btnExportXML" + Me.btnExportXML.Size = New System.Drawing.Size(115, 23) + Me.btnExportXML.TabIndex = 22 + Me.btnExportXML.Text = "Export as XML" + Me.btnExportXML.UseVisualStyleBackColor = True + Me.btnExportXML.Visible = False + ' 'Label6 ' Me.Label6.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) @@ -269,19 +294,6 @@ Partial Class MainForm Me.ToolTip1.SetToolTip(Me.BtGENup, "Move job up one row") Me.BtGENup.UseVisualStyleBackColor = True ' - 'LbAutoShDown - ' - Me.LbAutoShDown.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) - Me.LbAutoShDown.AutoSize = True - Me.LbAutoShDown.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.LbAutoShDown.ForeColor = System.Drawing.Color.Red - Me.LbAutoShDown.Location = New System.Drawing.Point(408, 275) - Me.LbAutoShDown.Name = "LbAutoShDown" - Me.LbAutoShDown.Size = New System.Drawing.Size(225, 13) - Me.LbAutoShDown.TabIndex = 17 - Me.LbAutoShDown.Text = "!!! Automatic Shutdown is activated !!!" - Me.LbAutoShDown.Visible = False - ' 'ChBoxAllGEN ' Me.ChBoxAllGEN.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) @@ -833,7 +845,6 @@ Partial Class MainForm Friend WithEvents TabPgOptions As TabPage Friend WithEvents ChBoxModOut As CheckBox Friend WithEvents PanelOptAllg As Panel - Friend WithEvents LbAutoShDown As Label Friend WithEvents LvMsg As ListView Friend WithEvents ColumnHeader1 As ColumnHeader Friend WithEvents SplitContainer1 As SplitContainer @@ -899,5 +910,7 @@ Partial Class MainForm Friend WithEvents toolStripSeparator1 As ToolStripSeparator Friend WithEvents HelpToolStripButton As ToolStripButton Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox + Friend WithEvents btnExportXML As System.Windows.Forms.Button + Friend WithEvents btnImportXML As System.Windows.Forms.Button End Class diff --git a/VECTO/GUI/MainForm.resx b/VECTO/GUI/MainForm.resx index 1ab95c20be0eb1a9777f7aae6720fb67961848f1..851f4024a3ae6d8b88b0c9c9cb15cd69128464c9 100644 --- a/VECTO/GUI/MainForm.resx +++ b/VECTO/GUI/MainForm.resx @@ -205,6 +205,9 @@ sDbhv9/4m+ZgnX1wey9Idfa/Y3WQPgGrg/QJWB2kj96I/gcOkiuMy/nVgwAAAABJRU5ErkJggg== </value> </data> + <metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>850, 12</value> + </metadata> <metadata name="ConMenFilelist.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>219, 14</value> </metadata> @@ -223,6 +226,9 @@ <metadata name="CmOpenFile.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <value>732, 12</value> </metadata> + <metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>850, 12</value> + </metadata> <metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <value>49</value> </metadata> diff --git a/VECTO/GUI/MainForm.vb b/VECTO/GUI/MainForm.vb index 5a723d326ff47e04b33bb83ec6d9725ff1614821..47f43c18a93b0b0028ac565f27628ddbee180940 100644 --- a/VECTO/GUI/MainForm.vb +++ b/VECTO/GUI/MainForm.vb @@ -42,10 +42,12 @@ Imports System.Threading Imports Microsoft.VisualBasic.FileIO Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.Models +Imports TUGraz.VectoCommon.OutputData Imports TUGraz.VectoCommon.Utils Imports TUGraz.VectoCore.OutputData Imports TUGraz.VectoCore.OutputData.FileIO Imports TUGraz.VectoCore.Utils +Imports VectoAuxiliaries ''' <summary> ''' Main application form. Loads at application start. Closing form ends application. @@ -249,6 +251,17 @@ Imports TUGraz.VectoCore.Utils 'Set mode (Batch/Standard) ModeUpdate() + DetectPlugins() + + 'Dim exportPlugins As Dictionary(Of String, String) = PluginRegistry.Instance.GetExportPluginList() + Dim exportPlugin As IExportPlugin = PluginRegistry.Instance.GetExportPlugin("TUG.IVT.Vecto.XMLExport") + btnExportXML.Visible = Not exportPlugin Is Nothing + + + Dim importPlugin As IImportPlugin = PluginRegistry.Instance.GetImportPlugin("TUG.IVT.Vecto.XMLImport") + btnImportXML.Visible = Not importPlugin Is Nothing + + #If DEBUG Then Const LicCheck As Boolean = False #Else @@ -318,7 +331,6 @@ Imports TUGraz.VectoCore.Utils fwelcome = New WelcomeDialog fwelcome.ShowDialog() End If - 'End If End Sub 'Open file @@ -541,8 +553,13 @@ Imports TUGraz.VectoCore.Utils x = New String() {""} + Dim extensions As String = "vecto" + Dim inputDataExtensions As String() = + PluginRegistry.Instance.GetKnownInputExtensions().Select(Function(e) e.Substring(1)).ToArray() + If (inputDataExtensions.Any()) Then extensions = String.Join(",", extensions, String.Join(",", inputDataExtensions)) + 'STANDARD/BATCH - If JobfileFileBrowser.OpenDialog("", True, "vecto") Then + If JobfileFileBrowser.OpenDialog("", True, extensions) Then chck = True x = JobfileFileBrowser.Files End If @@ -564,6 +581,10 @@ Imports TUGraz.VectoCore.Utils f = LvGEN.SelectedItems(0).SubItems(0).Text f = FileRepl(f) + If Path.GetExtension(f) <> VectoCore.Configuration.Constants.FileExtensions.VectoJobFile Then + MsgBox("Job File " + f + " can not be opened in Job Editor. Try importing the file.") + Exit Sub + End If If Not File.Exists(f) Then MsgBox(f & " not found!") Else @@ -982,23 +1003,45 @@ Imports TUGraz.VectoCore.Utils 'list of finished runs Dim finishedRuns As List(Of Integer) = New List(Of Integer) - + Dim plugins As KeyValuePair(Of String, IInputDataPlugin)() = PluginRegistry.Instance.GetInputDataPlugins().ToArray() For Each jobFile As String In JobFileList Try sender.ReportProgress(0, New VectoProgress With {.Target = "ListBox", .Message = "Reading File " + jobFile, .Link = jobFile}) - Dim dataProvider As IInputDataProvider = JSONInputDataFactory.ReadJsonJob(jobFile) - Dim fileWriter As FileOutputWriter = New FileOutputWriter(jobFile) + If (Path.GetExtension(jobFile) = VectoCore.Configuration.Constants.FileExtensions.VectoJobFile) Then + Dim dataProvider As IInputDataProvider = JSONInputDataFactory.ReadJsonJob(jobFile) + Dim fileWriter As FileOutputWriter = New FileOutputWriter(jobFile) - Dim runsFactory As SimulatorFactory = New SimulatorFactory(mode, dataProvider, fileWriter) - runsFactory.WriteModalResults = Cfg.ModOut - runsFactory.ModalResults1Hz = Cfg.Mod1Hz - - For Each runId As Integer In jobContainer.AddRuns(runsFactory) - fileWriters.Add(runId, fileWriter) - Next + Dim runsFactory As SimulatorFactory = New SimulatorFactory(mode, dataProvider, fileWriter) + runsFactory.WriteModalResults = Cfg.ModOut + runsFactory.ModalResults1Hz = Cfg.Mod1Hz + For Each runId As Integer In jobContainer.AddRuns(runsFactory) + fileWriters.Add(runId, fileWriter) + Next + Else + Dim handled As Boolean = False + For Each entry As KeyValuePair(Of String, IInputDataPlugin) In plugins + If Not handled AndAlso entry.Value.CanHandleJob(jobFile) Then + Dim dataprovider As IInputDataProvider = entry.Value.ReadVectoJob(jobFile) + Dim fileWriter As FileOutputWriter = New FileOutputWriter(jobFile) + + Dim runsFactory As SimulatorFactory = New SimulatorFactory(mode, dataprovider, fileWriter) + runsFactory.WriteModalResults = Cfg.ModOut + runsFactory.ModalResults1Hz = Cfg.Mod1Hz + + For Each runId As Integer In jobContainer.AddRuns(runsFactory) + fileWriters.Add(runId, fileWriter) + Next + handled = True + End If + Next + If Not handled Then + sender.ReportProgress(0, + New VectoProgress With {.Target = "ListBoxError", .Message = "No Input Provider for job: " + jobFile}) + End If + End If sender.ReportProgress(0, New VectoProgress With {.Target = "ListBox", .Message = "Finished Reading Data for job: " + jobFile}) @@ -1952,6 +1995,45 @@ Imports TUGraz.VectoCore.Utils Public Message As String Public Link As String End Class + + Private Sub CbExportJob_SelectedIndexChanged(sender As Object, e As EventArgs) + End Sub + + Private Sub btnExportXML_Click(sender As Object, e As EventArgs) Handles btnExportXML.Click + + If LvGEN.SelectedItems.Count < 1 Then + If LvGEN.Items.Count = 1 Then + LvGEN.Items(0).Selected = True + Else + Exit Sub + End If + End If + + Dim f As String = LvGEN.SelectedItems(0).SubItems(0).Text + f = FileRepl(f) + If Not File.Exists(f) Then + MsgBox(f & " not found!") + Return + End If + Try + PluginRegistry.Instance.GetExportPlugin("TUG.IVT.Vecto.XMLExport").ExportJob(JSONInputDataFactory.ReadJsonJob(f)) + Catch ex As Exception + MsgBox("Exporting job failed: " + ex.Message) + End Try + End Sub + + Private Sub LvGEN_SelectedIndexChanged(sender As Object, e As EventArgs) Handles LvGEN.SelectedIndexChanged + btnExportXML.Enabled = (LvGEN.SelectedItems.Count = 1) + End Sub + + Private Sub btnImportXML_Click(sender As Object, e As EventArgs) Handles btnImportXML.Click + Try + Dim jobFile As String = PluginRegistry.Instance.GetImportPlugin("TUG.IVT.Vecto.XMLImport").ImportJob() + AddToJobListView(jobFile) + Catch ex As Exception + MsgBox("Importing job failed: " + ex.Message) + End Try + End Sub End Class diff --git a/VECTO/Input Files/Engine.vb b/VECTO/Input Files/Engine.vb index 8479cbe155d06d663b623b1153833a514525be20..36428639bb5769bfa4c198e09ca0fec644975cde 100644 --- a/VECTO/Input Files/Engine.vb +++ b/VECTO/Input Files/Engine.vb @@ -159,7 +159,15 @@ Public Class Engine Return False End If - Return New JSONFileWriter().SaveEngine(Me, _filePath) + Try + Dim writer As JSONFileWriter = New JSONFileWriter() + writer.SaveEngine(Me, _filePath) + + Catch ex As Exception + MsgBox("Faled to write Engine file: " + ex.Message) + Return False + End Try + Return True End Function diff --git a/VECTO/Input Files/Gearbox.vb b/VECTO/Input Files/Gearbox.vb index f9aaf778a10e9c6cbd4c2b1ea3758b20f9595bfa..128d21118ef9475f31909bb0c0c6dee05ecb7b67 100644 --- a/VECTO/Input Files/Gearbox.vb +++ b/VECTO/Input Files/Gearbox.vb @@ -115,7 +115,14 @@ Public Class Gearbox Return False End If - Return JSONFileWriter.Instance.SaveGearbox(Me, Me, _filePath) + Try + Dim writer As JSONFileWriter = JSONFileWriter.Instance + writer.SaveGearbox(Me, Me, _filePath) + Catch ex As Exception + MsgBox("failed to write Gearbox file: " + ex.Message) + Return False + End Try + Return True End Function @@ -390,7 +397,7 @@ Public Class Gearbox Public ReadOnly Property StartTorqueReserve As Double Implements IGearboxEngineeringInputData.StartTorqueReserve Get - Return TorqueResvStart + Return TorqueResvStart / 100 End Get End Property diff --git a/VECTO/Input Files/VectoJob.vb b/VECTO/Input Files/VectoJob.vb index e2f4d82bc17b3cca6b881d0bf37e51e10c7973fd..4c0f0882d4c63cad5aa4a632b7713d4857f73364 100644 --- a/VECTO/Input Files/VectoJob.vb +++ b/VECTO/Input Files/VectoJob.vb @@ -118,7 +118,14 @@ Public Class VectoJob Return False End If - Return JSONFileWriter.Instance.SaveJob(Me, _sFilePath) + Try + Dim writer As JSONFileWriter = JSONFileWriter.Instance + writer.SaveJob(Me, _sFilePath) + Catch ex As Exception + MsgBox("Failed to save Job file: " + ex.Message) + Return False + End Try + Return True End Function 'This Sub reads those Input-files that do not have their own class, etc. diff --git a/VECTO/Input Files/Vehicle.vb b/VECTO/Input Files/Vehicle.vb index 8d983d9737151747d9654acacf8098477a8320c0..86d76167b1ce8ebc6d9663fe2a1748fe0f5bdc1c 100644 --- a/VECTO/Input Files/Vehicle.vb +++ b/VECTO/Input Files/Vehicle.vb @@ -31,7 +31,6 @@ Public Class Vehicle IAngledriveInputData 'V2 MassMax is now saved in [t] instead of [kg] - Private _filePath As String Private _path As String @@ -203,7 +202,14 @@ Public Class Vehicle Return False End If - Return JSONFileWriter.Instance.SaveVehicle(Me, Me, Me, Me, _filePath) + Try + Dim writer As JSONFileWriter = JSONFileWriter.Instance + writer.SaveVehicle(Me, Me, Me, Me, _filePath) + Catch ex As Exception + MsgBox("Failed to save Vehicle file: " + ex.Message) + Return False + End Try + Return True End Function diff --git a/VECTO/JSONWriter.vb b/VECTO/JSONWriter.vb deleted file mode 100644 index 7cabc5ab5db7e3e219dc9313429509710961bafe..0000000000000000000000000000000000000000 --- a/VECTO/JSONWriter.vb +++ /dev/null @@ -1,55 +0,0 @@ -' Copyright 2014 European Union. -' Licensed under the EUPL (the 'Licence'); -' -' * You may not use this work except in compliance with the Licence. -' * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl -' * Unless required by applicable law or agreed to in writing, -' software distributed under the Licence is distributed on an "AS IS" basis, -' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -' -' See the LICENSE.txt for the specific language governing permissions and limitations. - -Imports System.IO -Imports System.Linq -Imports Newtonsoft.Json -Imports Newtonsoft.Json.Linq - -''' <summary> -''' uses JSON.NET http://json.codeplex.com/ -''' </summary> -''' <remarks></remarks> -Public Class JSONWriter - Public Content As JToken 'Dictionary(Of String, Object) - - Public Sub New() - 'Content = New Dictionary(Of String, Object) - End Sub - - - ''' <summary> - ''' Writes the Content variable into a JSON file. - ''' </summary> - ''' <param name="path"></param> - ''' <returns></returns> - ''' <remarks></remarks> - Public Function WriteFile(path As String) As Boolean - Dim file As StreamWriter - Dim str As String - - If Content.Count = 0 Then - Return False - End If - - Try - str = JsonConvert.SerializeObject(Content, Formatting.Indented) - file = My.Computer.FileSystem.OpenTextFileWriter(path, False) - Catch ex As Exception - Return False - End Try - - file.Write(str) - file.Close() - - Return True - End Function -End Class diff --git a/VECTO/MainModule.vb b/VECTO/MainModule.vb index 86ff56db402c958788ace6fad2b1e1e142bdc64d..ed21da1c77d25c47b58c7ed15292bd04b5570470 100644 --- a/VECTO/MainModule.vb +++ b/VECTO/MainModule.vb @@ -10,9 +10,15 @@ ' See the LICENSE.txt for the specific language governing permissions and limitations. Imports System.Collections.Generic Imports System.IO +Imports System.Reflection +Imports System.Runtime.Remoting +Imports TUGraz.VectoCommon +Imports TUGraz.VectoCommon.InputData +Imports TUGraz.VectoCommon.OutputData Imports TUGraz.VectoCommon.Utils Imports TUGraz.VectoCore.Models.SimulationComponent.Data Imports TUGraz.VectoCore.Models.SimulationComponent.Data.Engine +Imports VectoAuxiliaries ''' <summary> ''' Main calculation routines. @@ -57,4 +63,56 @@ Module MainModule End If Return filePath End Function + + Public Sub DetectPlugins() + + Dim dllFileNames As String() + Dim Path As String = "." + 'If Directory.Exists(Path) Then + dllFileNames = Directory.GetFiles(Path, "*.dll") + + Dim assemblies As ICollection(Of Assembly) = New List(Of Assembly)(dllFileNames.Length) + For Each dllFile As String In dllFileNames + Dim an As AssemblyName = AssemblyName.GetAssemblyName(dllFile) + Dim assembly As Assembly = assembly.Load(an) + assemblies.Add(assembly) + Next + + Dim exportPluginType As Type = GetType(IExportPlugin) + Dim importPluginType As Type = GetType(IImportPlugin) + Dim inputDataPluginType As Type = GetType(IInputDataPlugin) + + For Each assembly As Assembly In assemblies + If assembly <> Nothing Then + Dim types As Type() = assembly.GetTypes() + + For Each type As Type In types + If type.IsInterface Or type.IsAbstract Then + Continue For + Else + If type.GetInterface(exportPluginType.FullName) <> Nothing Then + Dim plugin As IExportPlugin = TryCast(Activator.CreateInstance(type), IExportPlugin) + If Not plugin Is Nothing Then + PluginRegistry.Instance.RegisterPlugin(plugin) + End If + End If + If type.GetInterface(importPluginType.FullName) <> Nothing Then + Dim plugin As IImportPlugin = TryCast(Activator.CreateInstance(type), IImportPlugin) + If Not plugin Is Nothing Then + PluginRegistry.Instance.RegisterPlugin(plugin) + End If + End If + If type.GetInterface(inputDataPluginType.FullName) <> Nothing Then + Dim plugin As IInputDataPlugin = TryCast(Activator.CreateInstance(type), IInputDataPlugin) + If Not plugin Is Nothing Then + PluginRegistry.Instance.RegisterPlugin(plugin) + End If + End If + End If + Next + End If + Next + + 'End If + End Sub End Module diff --git a/VECTO/OutputData/JSONFileWriter.vb b/VECTO/OutputData/JSONFileWriter.vb index e39037ace9e058e865a820a38a4e861470373103..020149a33a82083a17f722354bd42a5253c09427 100644 --- a/VECTO/OutputData/JSONFileWriter.vb +++ b/VECTO/OutputData/JSONFileWriter.vb @@ -1,19 +1,22 @@ Imports System.Collections.Generic Imports System.IO Imports System.Linq +Imports Newtonsoft.Json Imports Newtonsoft.Json.Linq Imports TUGraz.VectoCommon.InputData Imports TUGraz.VectoCommon.Models +Imports TUGraz.VectoCommon.OutputData Imports TUGraz.VectoCore.Models.Declaration Public Class JSONFileWriter - Public Const EngineFormatVersion As Short = 3 + Implements IOutputFileWriter + Public Const EngineFormatVersion As Integer = 3 - Public Const GearboxFormatVersion As Short = 6 + Public Const GearboxFormatVersion As Integer = 6 - Public Const VehicleFormatVersion As Short = 7 + Public Const VehicleFormatVersion As Integer = 7 - Private Const VectoJobFormatVersion As Short = 3 + Private Const VectoJobFormatVersion As Integer = 3 Private Shared _instance As JSONFileWriter @@ -24,15 +27,11 @@ Public Class JSONFileWriter End Get End Property - Public Function SaveEngine(eng As IEngineEngineeringInputData, filename As String) As Boolean - Dim json As New JSONWriter + Public Sub SaveEngine(eng As IEngineEngineeringInputData, filename As String) _ + Implements IOutputFileWriter.SaveEngine 'Header - Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) - header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")") - header.Add("Date", Now.ToUniversalTime().ToString("o")) - header.Add("AppVersion", VECTOvers) - header.Add("FileVersion", EngineFormatVersion) + Dim header As Dictionary(Of String, Object) = GetHeader(EngineFormatVersion) 'Body Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) @@ -54,22 +53,24 @@ Public Class JSONFileWriter body.Add("WHTC-Motorway", eng.WHTCMotorway) body.Add("ColdHotBalancingFactor", eng.ColdHotBalancingFactor) - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - - Return json.WriteFile(filename) - End Function + WriteFile(header, body, filename) + End Sub - Public Function SaveGearbox(gbx As IGearboxEngineeringInputData, axl As IAxleGearInputData, filename As String) _ - As Boolean - - Dim json As New JSONWriter - - 'Header + Protected Function GetHeader(fileVersion As Integer) As Dictionary(Of String, Object) Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) + header.Add("CreatedBy", Lic.LicString & " (" & Lic.GUID & ")") header.Add("Date", Now.ToUniversalTime().ToString("o")) header.Add("AppVersion", VECTOvers) - header.Add("FileVersion", GearboxFormatVersion) + header.Add("FileVersion", fileVersion) + Return header + End Function + + Public Sub SaveGearbox(gbx As IGearboxEngineeringInputData, axl As IAxleGearInputData, filename As String) _ + Implements IOutputFileWriter.SaveGearbox + + 'Header + Dim header As Dictionary(Of String, Object) = GetHeader(GearboxFormatVersion) 'Body @@ -139,21 +140,16 @@ Public Class JSONFileWriter body.Add("UpshiftAfterDownshiftDelay", gbx.UpshiftAfterDownshiftDelay.Value()) body.Add("UpshiftMinAcceleration", gbx.UpshiftMinAcceleration.Value()) - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - - Return json.WriteFile(filename) - End Function + WriteFile(header, body, filename) + End Sub - Public Function SaveVehicle(vehicle As IVehicleEngineeringInputData, retarder As IRetarderInputData, - pto As IPTOTransmissionInputData, angledrive As IAngledriveInputData, filename As String) As Boolean + Public Sub SaveVehicle(vehicle As IVehicleEngineeringInputData, retarder As IRetarderInputData, + pto As IPTOTransmissionInputData, angledrive As IAngledriveInputData, filename As String) _ + Implements IOutputFileWriter.SaveVehicle Dim basePath As String = Path.GetDirectoryName(filename) - Dim json As New JSONWriter + 'Header - Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { - {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, - {"Date", Now.ToUniversalTime().ToString("o")}, - {"AppVersion", VECTOvers}, - {"FileVersion", VehicleFormatVersion}} + Dim header As Dictionary(Of String, Object) = GetHeader(VehicleFormatVersion) 'Body @@ -228,19 +224,14 @@ Public Class JSONFileWriter } } - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - Return json.WriteFile(filename) - End Function + WriteFile(header, body, filename) + End Sub - Public Function SaveJob(input As IEngineeringInputDataProvider, filename As String) As Boolean - Dim json As New JSONWriter + Public Sub SaveJob(input As IEngineeringInputDataProvider, filename As String) _ + Implements IOutputFileWriter.SaveJob Dim basePath As String = Path.GetDirectoryName(filename) 'Header - Dim header As Dictionary(Of String, Object) = New Dictionary(Of String, Object) From { - {"CreatedBy", Lic.LicString & " (" & Lic.GUID & ")"}, - {"Date", Now.ToUniversalTime().ToString("o")}, - {"AppVersion", VECTOvers}, - {"FileVersion", VectoJobFormatVersion}} + Dim header As Dictionary(Of String, Object) = GetHeader(VectoJobFormatVersion) 'Body Dim body As Dictionary(Of String, Object) = New Dictionary(Of String, Object) @@ -259,7 +250,8 @@ Public Class JSONFileWriter body.Add("EngineFile", GetRelativePath(input.EngineInputData.Source, basePath)) body.Add("Cycles", job.Cycles.Select(Function(x) GetRelativePath(x.CycleData.Source, Path.GetDirectoryName(filename))).ToArray()) - Return True + WriteFile(header, body, filename) + Return End If 'Main Files @@ -343,7 +335,44 @@ Public Class JSONFileWriter job.Cycles.Select(Function(x) GetRelativePath(x.CycleData.Source, Path.GetDirectoryName(filename))).ToArray()) End If - json.Content = JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}) - Return json.WriteFile(filename) - End Function + WriteFile(header, body, filename) + End Sub + + Public Sub ExportJob(input As IEngineeringInputDataProvider, filename As String, separateFiles As Boolean) _ + Implements IOutputFileWriter.ExportJob + Throw New NotImplementedException + End Sub + + ''' <summary> + ''' Writes the Content variable into a JSON file. + ''' </summary> + ''' <param name="path"></param> + ''' <remarks></remarks> + Public Shared Sub WriteFile(content As JToken, path As String) + Dim file As StreamWriter + Dim str As String + + If content.Count = 0 Then + Return + End If + + Try + str = JsonConvert.SerializeObject(content, Formatting.Indented) + file = My.Computer.FileSystem.OpenTextFileWriter(path, False) + Catch ex As Exception + Throw + End Try + + file.Write(str) + file.Close() + End Sub + + Public Shared Sub WriteFile(content As Dictionary(Of String, Object), path As String) + WriteFile(JToken.FromObject(content), path) + End Sub + + Protected Shared Sub WriteFile(header As Dictionary(Of String, Object), body As Dictionary(Of String, Object), + path As String) + WriteFile(JToken.FromObject(New Dictionary(Of String, Object) From {{"Header", header}, {"Body", body}}), path) + End Sub End Class \ No newline at end of file diff --git a/VECTO/VECTO.vbproj b/VECTO/VECTO.vbproj index 7f05bf4509f9e97a47ec7e044c9c8c49fc72f02a..a0ac8e042f15a4a7c76999b7a3031e3f6e8dbbce 100644 --- a/VECTO/VECTO.vbproj +++ b/VECTO/VECTO.vbproj @@ -19,10 +19,14 @@ <UpgradeBackupLocation /> <IsWebBootstrapper>false</IsWebBootstrapper> <TargetFrameworkProfile /> - <SccProjectName>SAK</SccProjectName> - <SccLocalPath>SAK</SccLocalPath> - <SccAuxPath>SAK</SccAuxPath> - <SccProvider>SAK</SccProvider> + <SccProjectName> + </SccProjectName> + <SccLocalPath> + </SccLocalPath> + <SccAuxPath> + </SccAuxPath> + <SccProvider> + </SccProvider> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <PublishUrl>C:\Users\tb28\Documents\VectoOut\</PublishUrl> <Install>true</Install> @@ -169,7 +173,6 @@ <ItemGroup> <Compile Include="ApplicationEvents.vb" /> <Compile Include="Input Files\AdvancedAuxiliary.vb" /> - <Compile Include="JSONWriter.vb" /> <Compile Include="GUI\FileSignDialog.Designer.vb"> <DependentUpon>FileSignDialog.vb</DependentUpon> </Compile> @@ -906,10 +909,6 @@ <WCFMetadata Include="Service References\" /> </ItemGroup> <ItemGroup> - <ProjectReference Include="..\VECTOAux\VectoAuxiliaries\VectoAuxiliaries.vbproj"> - <Project>{fdeee460-0b8a-4ef6-8d9e-72f203a50f65}</Project> - <Name>VectoAuxiliaries</Name> - </ProjectReference> <ProjectReference Include="..\VectoCommon\AdvancedAuxiliaryInterfaces\AdvancedAuxiliaryInterfaces.vbproj"> <Project>{b4b9bd2f-fd8f-4bb8-82fa-e2154d2c7fbd}</Project> <Name>AdvancedAuxiliaryInterfaces</Name> @@ -1512,11 +1511,11 @@ <PostBuildEvent> </PostBuildEvent> </PropertyGroup> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> --> </Project> \ No newline at end of file diff --git a/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj b/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj index 989a904fca10cdc632065069bdacf4cfd1ce3c4a..5cefae0c9615ebc81c3c485d7b8c65862f626cc0 100644 --- a/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj +++ b/VECTOAux/VectoAuxiliaries/VectoAuxiliaries.vbproj @@ -12,10 +12,14 @@ <MyType>Windows</MyType> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkProfile /> - <SccProjectName>SAK</SccProjectName> - <SccLocalPath>SAK</SccLocalPath> - <SccAuxPath>SAK</SccAuxPath> - <SccProvider>SAK</SccProvider> + <SccProjectName> + </SccProjectName> + <SccLocalPath> + </SccLocalPath> + <SccAuxPath> + </SccAuxPath> + <SccProvider> + </SccProvider> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> diff --git a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj index 58f507916fa3315dca31e11cfaee077a04add5f3..949a37358e4eb5e30f511ba1ca7dd1733b7c7b04 100644 --- a/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj +++ b/VECTOAux/VectoAuxiliariesTests/VectoAuxiliariesTests.vbproj @@ -17,10 +17,14 @@ <IsCodedUITest>False</IsCodedUITest> <TestProjectType>UnitTest</TestProjectType> <TargetFrameworkProfile /> - <SccProjectName>SAK</SccProjectName> - <SccLocalPath>SAK</SccLocalPath> - <SccAuxPath>SAK</SccAuxPath> - <SccProvider>SAK</SccProvider> + <SccProjectName> + </SccProjectName> + <SccLocalPath> + </SccLocalPath> + <SccAuxPath> + </SccAuxPath> + <SccProvider> + </SccProvider> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> diff --git a/VectoCommon/AdvancedAuxiliaryInterfaces/AdvancedAuxiliaryInterfaces.vbproj b/VectoCommon/AdvancedAuxiliaryInterfaces/AdvancedAuxiliaryInterfaces.vbproj index e4a61b496fda7765b2ed2f2ccde22818fb6a8d0c..4195ff47a5af2870a700ba6daf798781c707e7e2 100644 --- a/VectoCommon/AdvancedAuxiliaryInterfaces/AdvancedAuxiliaryInterfaces.vbproj +++ b/VectoCommon/AdvancedAuxiliaryInterfaces/AdvancedAuxiliaryInterfaces.vbproj @@ -11,10 +11,14 @@ <FileAlignment>512</FileAlignment> <MyType>Windows</MyType> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> - <SccProjectName>SAK</SccProjectName> - <SccLocalPath>SAK</SccLocalPath> - <SccAuxPath>SAK</SccAuxPath> - <SccProvider>SAK</SccProvider> + <SccProjectName> + </SccProjectName> + <SccLocalPath> + </SccLocalPath> + <SccAuxPath> + </SccAuxPath> + <SccProvider> + </SccProvider> <TargetFrameworkProfile /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> diff --git a/VectoCommon/VectoCommon/InputData/IImportPlugin.cs b/VectoCommon/VectoCommon/InputData/IImportPlugin.cs new file mode 100644 index 0000000000000000000000000000000000000000..715c3cda57e07729764d5d9dd5e0eec5b1228692 --- /dev/null +++ b/VectoCommon/VectoCommon/InputData/IImportPlugin.cs @@ -0,0 +1,11 @@ +namespace TUGraz.VectoCommon.InputData +{ + public interface IImportPlugin + { + string Key { get; } + + string Name { get; } + + string ImportJob(); + } +} \ No newline at end of file diff --git a/VectoCommon/VectoCommon/InputData/IInputDataPlugin.cs b/VectoCommon/VectoCommon/InputData/IInputDataPlugin.cs new file mode 100644 index 0000000000000000000000000000000000000000..c2949892837fe65f9a1ae6970ef8831f4f94eec6 --- /dev/null +++ b/VectoCommon/VectoCommon/InputData/IInputDataPlugin.cs @@ -0,0 +1,17 @@ +using System.Threading; + +namespace TUGraz.VectoCommon.InputData +{ + public interface IInputDataPlugin + { + string Key { get; } + + string Name { get; } + + bool CanHandleJob(string filename); + + IInputDataProvider ReadVectoJob(string filename); + + string[] KnownExtensions { get; } + } +} \ No newline at end of file diff --git a/VectoCommon/VectoCommon/OutputData/IExportPlugin.cs b/VectoCommon/VectoCommon/OutputData/IExportPlugin.cs new file mode 100644 index 0000000000000000000000000000000000000000..3ee1c4b0626d4984922ae9ae40f833c3d93e6fd3 --- /dev/null +++ b/VectoCommon/VectoCommon/OutputData/IExportPlugin.cs @@ -0,0 +1,13 @@ +using TUGraz.VectoCommon.InputData; + +namespace TUGraz.VectoCommon.OutputData +{ + public interface IExportPlugin + { + string Key { get; } + + string Name { get; } + + void ExportJob(IInputDataProvider data); + } +} \ No newline at end of file diff --git a/VectoCommon/VectoCommon/OutputData/IOutputFileWriter.cs b/VectoCommon/VectoCommon/OutputData/IOutputFileWriter.cs new file mode 100644 index 0000000000000000000000000000000000000000..fd4415e672de1db5fca41dea477d6665365ea97e --- /dev/null +++ b/VectoCommon/VectoCommon/OutputData/IOutputFileWriter.cs @@ -0,0 +1,19 @@ +using System; +using TUGraz.VectoCommon.InputData; + +namespace TUGraz.VectoCommon.OutputData +{ + public interface IOutputFileWriter + { + void SaveEngine(IEngineEngineeringInputData eng, string filename); + + void SaveGearbox(IGearboxEngineeringInputData gbx, IAxleGearInputData axl, string filename); + + void SaveVehicle(IVehicleEngineeringInputData vehicle, IRetarderInputData retarder, + IPTOTransmissionInputData pto, IAngledriveInputData angledrive, string filename); + + void SaveJob(IEngineeringInputDataProvider input, string filename); + + void ExportJob(IEngineeringInputDataProvider input, string filename, bool separateFiles); + } +} \ No newline at end of file diff --git a/VectoCommon/VectoCommon/OutputData/IOutputPlugin.cs b/VectoCommon/VectoCommon/OutputData/IOutputPlugin.cs new file mode 100644 index 0000000000000000000000000000000000000000..893a4c00dadbfe1bf7d44525a7b99f53b34639e0 --- /dev/null +++ b/VectoCommon/VectoCommon/OutputData/IOutputPlugin.cs @@ -0,0 +1,11 @@ +namespace TUGraz.VectoCommon.OutputData +{ + public interface IOutputPlugin + { + string Key { get; } + + string Name { get; } + + IOutputFileWriter Instance { get; } + } +} \ No newline at end of file diff --git a/VectoCommon/VectoCommon/Utils/PluginRegistry.cs b/VectoCommon/VectoCommon/Utils/PluginRegistry.cs new file mode 100644 index 0000000000000000000000000000000000000000..839f71fe84c062428f74549a5957e87221fe62f6 --- /dev/null +++ b/VectoCommon/VectoCommon/Utils/PluginRegistry.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using TUGraz.VectoCommon.InputData; +using TUGraz.VectoCommon.OutputData; + +namespace TUGraz.VectoCommon.Utils +{ + public class PluginRegistry + { + private static PluginRegistry _instance; + + private readonly Dictionary<string, IExportPlugin> _exportPlugins = new Dictionary<string, IExportPlugin>(); + private readonly Dictionary<string, IImportPlugin> _importPlugins = new Dictionary<string, IImportPlugin>(); + private readonly Dictionary<string, IInputDataPlugin> _inputDataPlugins = new Dictionary<string, IInputDataPlugin>(); + + public static PluginRegistry Instance + { + get { return _instance ?? (_instance = new PluginRegistry()); } + } + + public void RegisterPlugin(IExportPlugin plugin) + { + _exportPlugins.Add(plugin.Key, plugin); + } + + public void RegisterPlugin(IImportPlugin plugin) + { + _importPlugins.Add(plugin.Key, plugin); + } + + public void RegisterPlugin(IInputDataPlugin plugin) + { + _inputDataPlugins.Add(plugin.Key, plugin); + } + + public IExportPlugin GetExportPlugin(string key) + { + return _exportPlugins.ContainsKey(key) ? _exportPlugins[key] : null; + } + + public IImportPlugin GetImportPlugin(string key) + { + return _importPlugins.ContainsKey(key) ? _importPlugins[key] : null; + } + + public IEnumerable<KeyValuePair<string, IInputDataPlugin>> GetInputDataPlugins() + { + return _inputDataPlugins.Select(x => x).ToList(); + } + + public IInputDataPlugin GetInputDataPlugin(string key) + { + return _inputDataPlugins.ContainsKey(key) ? _inputDataPlugins[key] : null; + } + + public IEnumerable<string> GetKnownInputExtensions() + { + var retVal = new List<string>(); + foreach (var entry in _inputDataPlugins) { + retVal.AddRange(entry.Value.KnownExtensions); + } + return retVal; + } + } +} \ No newline at end of file diff --git a/VectoCommon/VectoCommon/VectoCommon.csproj b/VectoCommon/VectoCommon/VectoCommon.csproj index b0036079b3dc1a950d06f3706d3bd738774d2e81..9142f35b213f4521179c5d646d5074e5c002456c 100644 --- a/VectoCommon/VectoCommon/VectoCommon.csproj +++ b/VectoCommon/VectoCommon/VectoCommon.csproj @@ -45,6 +45,8 @@ </ItemGroup> <ItemGroup> <Compile Include="InputData\DataSourceType.cs" /> + <Compile Include="InputData\IImportPlugin.cs" /> + <Compile Include="InputData\IInputDataPlugin.cs" /> <Compile Include="InputData\TableData.cs"> <SubType>Component</SubType> </Compile> @@ -68,11 +70,15 @@ <Compile Include="Models\OperatingPoint.cs" /> <Compile Include="Models\RetarderType.cs" /> <Compile Include="Models\VehicleCategory.cs" /> + <Compile Include="OutputData\IExportPlugin.cs" /> + <Compile Include="OutputData\IOutputFileWriter.cs" /> + <Compile Include="OutputData\IOutputPlugin.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Utils\DoubleExtensionMethods.cs" /> <Compile Include="Utils\EnumerableExtensionMethods.cs" /> <Compile Include="Utils\EnumHelper.cs" /> <Compile Include="Utils\IntExtensionMethods.cs" /> + <Compile Include="Utils\PluginRegistry.cs" /> <Compile Include="Utils\SI.cs" /> <Compile Include="Utils\StringExtensionMethods.cs" /> <Compile Include="Utils\Validation.cs" /> diff --git a/VectoConsole/Program.cs b/VectoConsole/Program.cs index 493c3c14e6c8e03f778807199aaa210930bb8a29..38d2182cbb29710c956c7891af11a192b1daef43 100644 --- a/VectoConsole/Program.cs +++ b/VectoConsole/Program.cs @@ -36,12 +36,11 @@ using System.IO; using System.Linq; using System.Reflection; using System.Threading; -using System.Xml; using NLog; using NLog.Config; using NLog.Targets; -using TUGraz.VectoAPI.InputData; using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; using TUGraz.VectoCore.InputData.FileIO.JSON; using TUGraz.VectoCore.Models.Simulation.Impl; @@ -183,6 +182,7 @@ Examples: return 1; } + var plugins = PluginRegistry.Instance.GetInputDataPlugins().ToArray(); foreach (var file in jobFiles) { Console.WriteLine(@"Reading job: " + file); if (Path.GetExtension(file) == Constants.FileExtensions.VectoJobFile) { @@ -194,15 +194,20 @@ Examples: }; _jobContainer.AddRuns(runsFactory); - } - if (Path.GetExtension(file) == Constants.FileExtensions.VectoXMLDeclarationFile) { - var dataProvider = new XMLInputDataProvider(new XmlTextReader(file), true); - fileWriter = new FileOutputWriter(file); - var runsFactory = new SimulatorFactory(ExecutionMode.Declaration, dataProvider, fileWriter); - if (args.Contains("-mod")) { - runsFactory.WriteModalResults = true; + } else { + var handled = false; + foreach (var plugin in plugins) { + if (!handled && plugin.Value.CanHandleJob(file)) { + var dataProvider = plugin.Value.ReadVectoJob(file); + fileWriter = new FileOutputWriter(file); + var runsFactory = new SimulatorFactory(mode, dataProvider, fileWriter); + runsFactory.ModalResults1Hz = args.Contains("-1Hz"); + runsFactory.WriteModalResults = args.Contains("-mod"); + + _jobContainer.AddRuns(runsFactory); + handled = true; + } } - _jobContainer.AddRuns(runsFactory); } } diff --git a/VectoConsole/VectoConsole.csproj b/VectoConsole/VectoConsole.csproj index 7b92a69924c1391553f66d1adede323201b10fa5..d26900aee611e2c00e5e9cea8446362f9e5c6384 100644 --- a/VectoConsole/VectoConsole.csproj +++ b/VectoConsole/VectoConsole.csproj @@ -60,9 +60,6 @@ <Reference Include="System" /> <Reference Include="System.Core" /> <Reference Include="System.Xml" /> - <Reference Include="VectoAPI"> - <HintPath>..\..\VECTO_API\VectoAPI\bin\Release\VectoAPI.dll</HintPath> - </Reference> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs index f72f374986fd58084fc340d4e387c71bdeb3f728..e175de4e1a1aba615719ba4248c8a3da7139a22c 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs @@ -352,7 +352,7 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON { get { - return Body[JsonKeys.Gearbox_TorqueConverter_ReferenceRPM] != null ? + return Body[JsonKeys.Gearbox_TorqueConverter] != null && Body[JsonKeys.Gearbox_TorqueConverter][JsonKeys.Gearbox_TorqueConverter_ReferenceRPM] != null ? Body.GetEx(JsonKeys.Gearbox_TorqueConverter) .GetEx<double>(JsonKeys.Gearbox_TorqueConverter_ReferenceRPM) .RPMtoRad() : null; diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs index bbd61cfc25a3ad961485f3f09397c2b9cc902c65..4112592ec539df5ba938420a50bc0b33da7f1ae3 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONInputData.cs @@ -117,49 +117,65 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON protected readonly IGearboxEngineeringInputData Gearbox; protected readonly IAxleGearInputData AxleGear; protected readonly ITorqueConverterEngineeringInputData TorqueConverter; - protected readonly IAngledriveInputData Angledrive; + protected IAngledriveInputData Angledrive; protected readonly IEngineEngineeringInputData Engine; - protected readonly IVehicleEngineeringInputData VehicleData; - protected readonly IRetarderInputData Retarder; - protected readonly IPTOTransmissionInputData PTOTransmission; + protected IVehicleEngineeringInputData VehicleData; + protected IRetarderInputData Retarder; + protected IPTOTransmissionInputData PTOTransmission; private readonly string _jobname; public JSONInputDataV2(JObject data, string filename) : base(data, filename) { _jobname = Path.GetFileNameWithoutExtension(filename); + + Engine = ReadEngine(); + + if (Body.GetEx(JsonKeys.Job_EngineOnlyMode).Value<bool>()) { + return; + } + + Gearbox = ReadGearbox(); + AxleGear = Gearbox as IAxleGearInputData; + TorqueConverter = Gearbox as ITorqueConverterEngineeringInputData; + + VehicleData = ReadVehicle(); + Angledrive = VehicleData as IAngledriveInputData; + Retarder = VehicleData as IRetarderInputData; + PTOTransmission = VehicleData as IPTOTransmissionInputData; + } + + private IVehicleEngineeringInputData ReadVehicle() + { try { - var gearboxFile = Body.GetEx(JsonKeys.Vehicle_GearboxFile).Value<string>(); - if (!EmptyOrInvalidFileName(gearboxFile)) { - Gearbox = JSONInputDataFactory.ReadGearbox(Path.Combine(BasePath, gearboxFile)); - } - AxleGear = Gearbox as IAxleGearInputData; - TorqueConverter = Gearbox as ITorqueConverterEngineeringInputData; + var vehicleFile = Body.GetEx(JsonKeys.Vehicle_VehicleFile).Value<string>(); + return JSONInputDataFactory.ReadJsonVehicle( + Path.Combine(BasePath, vehicleFile)); } catch (Exception e) { - throw new VectoException("JobFile: Failed to read Gearbox file '{0}': {1}", e, Body[JsonKeys.Vehicle_GearboxFile], + throw new VectoException("JobFile: Failed to read Vehicle file '{0}': {1}", e, Body[JsonKeys.Vehicle_VehicleFile], e.Message); } + } + private IGearboxEngineeringInputData ReadGearbox() + { try { - Engine = JSONInputDataFactory.ReadEngine( - Path.Combine(BasePath, Body.GetEx(JsonKeys.Vehicle_EngineFile).Value<string>())); + var gearboxFile = Body.GetEx(JsonKeys.Vehicle_GearboxFile).Value<string>(); + + return JSONInputDataFactory.ReadGearbox(Path.Combine(BasePath, gearboxFile)); } catch (Exception e) { - throw new VectoException("JobFile: Failed to read Engine file '{0}': {1}", e, Body[JsonKeys.Vehicle_EngineFile], + throw new VectoException("JobFile: Failed to read Gearbox file '{0}': {1}", e, Body[JsonKeys.Vehicle_GearboxFile], e.Message); } + } + private IEngineEngineeringInputData ReadEngine() + { try { - var vehicleFile = Body.GetEx(JsonKeys.Vehicle_VehicleFile).Value<string>(); - if (!EmptyOrInvalidFileName(vehicleFile)) { - VehicleData = JSONInputDataFactory.ReadJsonVehicle( - Path.Combine(BasePath, vehicleFile)); - - Angledrive = VehicleData as IAngledriveInputData; - Retarder = VehicleData as IRetarderInputData; - PTOTransmission = VehicleData as IPTOTransmissionInputData; - } + return JSONInputDataFactory.ReadEngine( + Path.Combine(BasePath, Body.GetEx(JsonKeys.Vehicle_EngineFile).Value<string>())); } catch (Exception e) { - throw new VectoException("JobFile: Failed to read Vehicle file '{0}': {1}", e, Body[JsonKeys.Vehicle_VehicleFile], + throw new VectoException("JobFile: Failed to read Engine file '{0}': {1}", e, Body[JsonKeys.Vehicle_EngineFile], e.Message); } } diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/TorqueConverterData.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/TorqueConverterData.cs index 8127ff2a2a0311c48afac4719eea97ef44cc84d3..485c9567d278de5a6f23bb16705a0f74573d45b6 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/TorqueConverterData.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/TorqueConverterData.cs @@ -62,12 +62,16 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox /// </summary> /// <param name="torqueOut">torque provided at the TC output</param> /// <param name="angularSpeedOut">angular speed at the TC output</param> + /// <param name="minSpeed"></param> /// <returns></returns> - public TorqueConverterOperatingPoint FindOperatingPoint(NewtonMeter torqueOut, PerSecond angularSpeedOut) + public IList<TorqueConverterOperatingPoint> FindOperatingPoint(NewtonMeter torqueOut, PerSecond angularSpeedOut, + PerSecond minSpeed) { var solutions = new List<double>(); var mpNorm = ReferenceSpeed.Value(); + var min = minSpeed == null ? 0 : minSpeed.Value(); + // Find analytic solution for torque converter operating point // mu = f(nu) = f(n_out / n_in) = T_out / T_in // MP1000 = f(nu) = f(n_out / n_in) @@ -88,7 +92,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox torqueOut.Value(); var sol = VectoMath.QuadraticEquationSolver(a, b, c); - var selected = sol.Where(x => x > 0 + var selected = sol.Where(x => x > min && angularSpeedOut.Value() / x >= muEdge.P1.X && angularSpeedOut.Value() / x < muEdge.P2.X && angularSpeedOut.Value() / x >= mpEdge.P1.X && angularSpeedOut.Value() / x < mpEdge.P2.X); solutions.AddRange(selected); @@ -98,15 +102,18 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox torqueOut); } - var retVal = new TorqueConverterOperatingPoint { - OutTorque = torqueOut, - OutAngularVelocity = angularSpeedOut, - InAngularVelocity = solutions.Min().SI<PerSecond>() - }; - retVal.SpeedRatio = angularSpeedOut / retVal.InAngularVelocity; - retVal.TorqueRatio = MuLookup(angularSpeedOut / retVal.InAngularVelocity); - retVal.InTorque = torqueOut / retVal.TorqueRatio; - + var retVal = new List<TorqueConverterOperatingPoint>(); + foreach (var sol in solutions) { + var tmp = new TorqueConverterOperatingPoint { + OutTorque = torqueOut, + OutAngularVelocity = angularSpeedOut, + InAngularVelocity = sol.SI<PerSecond>() + }; + tmp.SpeedRatio = angularSpeedOut / tmp.InAngularVelocity; + tmp.TorqueRatio = MuLookup(angularSpeedOut / tmp.InAngularVelocity); + tmp.InTorque = torqueOut / tmp.TorqueRatio; + retVal.Add(tmp); + } return retVal; } @@ -139,8 +146,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox retVal.OutTorque = retVal.InTorque * retVal.TorqueRatio; return retVal; } - throw new VectoException("No solution for output speed/input speed found! n_out: {0}, n_in: {1}", outAngularVelocity, - inAngularVelocity); + throw new VectoException( + "No solution for output speed/input speed found! n_out: {0}, n_in: {1}, nu: {2}, nu_max: {3}", outAngularVelocity, + inAngularVelocity, outAngularVelocity / inAngularVelocity, TorqueConverterEntries.Last().SpeedRatio); } @@ -153,7 +161,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox /// <param name="inAngularVelocity"></param> /// <param name="outAngularSpeedEstimated"></param> /// <returns></returns> - public TorqueConverterOperatingPoint FindOperatingPoint(NewtonMeter inTorque, PerSecond inAngularVelocity, + public TorqueConverterOperatingPoint FindOperatingPointForward(NewtonMeter inTorque, PerSecond inAngularVelocity, PerSecond outAngularSpeedEstimated) { var referenceTorque = inTorque.Value() / inAngularVelocity.Value() / inAngularVelocity.Value() * diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs index 3d1f40e3348da9be7e9f87110699db2bcc623115..ebab9c27613051f27cc58d832643a1c7dca89edc 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/CycleGearbox.cs @@ -29,6 +29,8 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ +using System.Collections.Generic; +using System.Linq; using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; @@ -254,20 +256,21 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl (ResponseDryRun)NextComponent.Request(absTime, dt, dryOperatingPoint.InTorque, dryOperatingPoint.InAngularVelocity, true); - var deltaTorqueConverter = (outTorque - dryOperatingPoint.OutTorque) * - (PreviousState.OutAngularVelocity + dryOperatingPoint.OutAngularVelocity) / 2.0; + //var deltaTorqueConverter = (outTorque - dryOperatingPoint.OutTorque) * + // (PreviousState.OutAngularVelocity + dryOperatingPoint.OutAngularVelocity) / 2.0; - var deltaEngine = (engineResponse.DeltaFullLoad > 0 ? engineResponse.DeltaFullLoad : 0.SI<Watt>()) + - (engineResponse.DeltaDragLoad < 0 ? -engineResponse.DeltaDragLoad : 0.SI<Watt>()); + //var deltaEngine = (engineResponse.DeltaFullLoad > 0 ? engineResponse.DeltaFullLoad : 0.SI<Watt>()) + + // (engineResponse.DeltaDragLoad < 0 ? -engineResponse.DeltaDragLoad : 0.SI<Watt>()); dryOperatingPoint = outTorque.IsGreater(0) && DataBus.BrakePower.IsEqual(0) ? GetMaxPowerOperatingPoint(dt, outAngularVelocity, engineResponse) : GetDragPowerOperatingPoint(dt, outAngularVelocity, engineResponse); - engineResponse = (ResponseDryRun)NextComponent.Request(absTime, dt, dryOperatingPoint.InTorque, - dryOperatingPoint.InAngularVelocity, true); + //engineResponse = (ResponseDryRun)NextComponent.Request(absTime, dt, dryOperatingPoint.InTorque, + // dryOperatingPoint.InAngularVelocity, true); var delta = (outTorque - dryOperatingPoint.OutTorque) * (PreviousState.OutAngularVelocity + dryOperatingPoint.OutAngularVelocity) / 2.0; + //var tmp = FindOperatingPoint(dryOperatingPoint.OutTorque, dryOperatingPoint.OutAngularVelocity); //deltaTorqueConverter.Value() * (deltaEngine.IsEqual(0) ? 1 : deltaEngine.Value()); return new ResponseDryRun() { Source = this, @@ -331,11 +334,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl PerSecond outAngularVelocity) { try { - var operatingPoint = TorqueConverter.FindOperatingPoint(outTorque, outAngularVelocity); - if (operatingPoint.InAngularVelocity.IsSmaller(DataBus.EngineIdleSpeed)) { - throw new VectoException("Invalid operating point, inAngularVelocity below engine's idle speed: {0}", - operatingPoint.InAngularVelocity); - } + var operatingPointList = TorqueConverter.FindOperatingPoint(outTorque, outAngularVelocity, DataBus.EngineIdleSpeed); + var operatingPoint = SelectOperatingPoint(operatingPointList); if (operatingPoint.InAngularVelocity.IsGreater(DataBus.EngineRatedSpeed)) { operatingPoint = TorqueConverter.FindOperatingPoint(DataBus.EngineRatedSpeed, outAngularVelocity); } @@ -347,6 +347,24 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } } + private TorqueConverterOperatingPoint SelectOperatingPoint(IList<TorqueConverterOperatingPoint> operatingPointList) + { + if (operatingPointList.Count == 1) { + return operatingPointList[0]; + } + + var filtered = operatingPointList.Where(x => + (x.InTorque * x.InAngularVelocity).IsSmallerOrEqual(DataBus.EngineStationaryFullPower(x.InAngularVelocity), + Constants.SimulationSettings.LineSearchTolerance.SI<Watt>()) && + (x.InTorque * x.InAngularVelocity).IsGreaterOrEqual(DataBus.EngineDragPower(x.InAngularVelocity), + Constants.SimulationSettings.LineSearchTolerance.SI<Watt>()) + ).ToArray(); + if (filtered.Count() == 1) { + return filtered.First(); + } + return operatingPointList[0]; + } + private TorqueConverterOperatingPoint GetDragPowerOperatingPoint(Second dt, PerSecond outAngularVelocity, ResponseDryRun engineResponse) { @@ -430,12 +448,12 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl container[ModalResultField.TC_angularSpeedOut] = CurrentState.TorqueConverterOperatingPoint.OutAngularVelocity; var avgOutVelocity = ((PreviousState.TorqueConverterOperatingPoint != null - ? PreviousState.TorqueConverterOperatingPoint.OutAngularVelocity - : PreviousState.InAngularVelocity) + + ? PreviousState.TorqueConverterOperatingPoint.OutAngularVelocity + : PreviousState.InAngularVelocity) + CurrentState.TorqueConverterOperatingPoint.OutAngularVelocity) / 2.0; var avgInVelocity = ((PreviousState.TorqueConverterOperatingPoint != null - ? PreviousState.TorqueConverterOperatingPoint.InAngularVelocity - : PreviousState.InAngularVelocity) + + ? PreviousState.TorqueConverterOperatingPoint.InAngularVelocity + : PreviousState.InAngularVelocity) + CurrentState.TorqueConverterOperatingPoint.InAngularVelocity) / 2.0; container[ModalResultField.P_TC_out] = CurrentState.OutTorque * avgOutVelocity; container[ModalResultField.P_TC_loss] = CurrentState.InTorque * avgInVelocity - diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs index 5840f0311cf7fa07bafb3a132b03ed78d6aaa114..35c37c67ab293fc6c683d01a91fc46964e769dc5 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/TorqueConverter.cs @@ -1,4 +1,6 @@ -using TUGraz.VectoCommon.Exceptions; +using System.Collections.Generic; +using System.Linq; +using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; @@ -41,14 +43,15 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public IResponse Initialize(NewtonMeter outTorque, PerSecond outAngularVelocity) { - var operatingPoint = ModelData.FindOperatingPoint(outTorque, outAngularVelocity); - + var operatingPointList = ModelData.FindOperatingPoint(outTorque, outAngularVelocity, DataBus.EngineIdleSpeed); + var operatingPoint = SelectOperatingPoint(operatingPointList); var retVal = NextComponent.Initialize(operatingPoint.InTorque, operatingPoint.InAngularVelocity); PreviousState.SetState(operatingPoint.InTorque, operatingPoint.InAngularVelocity, operatingPoint.OutTorque, operatingPoint.OutAngularVelocity); return retVal; } + public IResponse Request(Second absTime, Second dt, NewtonMeter outTorque, PerSecond outAngularVelocity, bool dryRun = false) { @@ -153,7 +156,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl PerSecond outAngularVelocity) { try { - var operatingPoint = ModelData.FindOperatingPoint(outTorque, outAngularVelocity); + var operatingPointList = ModelData.FindOperatingPoint(outTorque, outAngularVelocity, DataBus.EngineIdleSpeed); + var operatingPoint = SelectOperatingPoint(operatingPointList); if (operatingPoint.InAngularVelocity.IsSmaller(DataBus.EngineIdleSpeed)) { throw new VectoException("Invalid operating point, inAngularVelocity below engine's idle speed: {0}", operatingPoint.InAngularVelocity); @@ -169,6 +173,24 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl } } + + private TorqueConverterOperatingPoint SelectOperatingPoint(IList<TorqueConverterOperatingPoint> operatingPointList) + { + if (operatingPointList.Count == 1) { + return operatingPointList[0]; + } + var filtered = operatingPointList.Where(x => + (x.InTorque * x.InAngularVelocity).IsSmallerOrEqual(DataBus.EngineStationaryFullPower(x.InAngularVelocity), + Constants.SimulationSettings.LineSearchTolerance.SI<Watt>()) && + (x.InTorque * x.InAngularVelocity).IsGreaterOrEqual(DataBus.EngineDragPower(x.InAngularVelocity), + Constants.SimulationSettings.LineSearchTolerance.SI<Watt>()) + ).ToArray(); + if (filtered.Count() == 1) { + return filtered.First(); + } + return operatingPointList[0]; + } + protected override void DoWriteModalResults(IModalDataContainer container) { if (CurrentState.OperatingPoint == null) { diff --git a/VectoCore/VectoCoreTest/Models/SimulationComponentData/TorqueConverterDataTest.cs b/VectoCore/VectoCoreTest/Models/SimulationComponentData/TorqueConverterDataTest.cs index a395445c598cc95831ce57b059085ad263e9aa8d..6aae74a91a8c2dfc38b521c8afa59e4ec9a3df73 100644 --- a/VectoCore/VectoCoreTest/Models/SimulationComponentData/TorqueConverterDataTest.cs +++ b/VectoCore/VectoCoreTest/Models/SimulationComponentData/TorqueConverterDataTest.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Linq; +using NLog.Targets; using NUnit.Framework; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Configuration; @@ -52,7 +54,9 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var outAngularSpeed = nOut.RPMtoRad(); var outTorque = (Pout * 1000).SI<Watt>() / outAngularSpeed; - var result = tqData.FindOperatingPoint(outTorque, outAngularSpeed); + var resultList = tqData.FindOperatingPoint(outTorque, outAngularSpeed, 0.SI<PerSecond>()); + Assert.AreEqual(1, resultList.Count); + var result = resultList[0]; Assert.AreEqual(outAngularSpeed.Value(), result.OutAngularVelocity.Value(), 1e-3); Assert.AreEqual(outTorque.Value(), result.OutTorque.Value(), 1e-3); @@ -85,13 +89,16 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData tqInput), 1000.RPMtoRad(), tqLimit.RPMtoRad()); - var operatingPoint = tqData.FindOperatingPoint(tqIn.SI<NewtonMeter>(), nIn.RPMtoRad(), null); + var operatingPoint = tqData.FindOperatingPointForward(tqIn.SI<NewtonMeter>(), nIn.RPMtoRad(), null); Assert.AreEqual(operatingPoint.InTorque.Value(), tqIn, 1e-6); Assert.AreEqual(operatingPoint.InAngularVelocity.Value(), nIn.RPMtoRad().Value(), 1e-6); - var reverseOP = tqData.FindOperatingPoint(operatingPoint.OutTorque, operatingPoint.OutAngularVelocity); + var resultList = tqData.FindOperatingPoint(operatingPoint.OutTorque, operatingPoint.OutAngularVelocity, + 0.SI<PerSecond>()); + Assert.AreEqual(1, resultList.Count); + var reverseOP = resultList[0]; Assert.AreEqual(operatingPoint.InTorque.Value(), reverseOP.InTorque.Value(), 1e-6); Assert.AreEqual(operatingPoint.OutTorque.Value(), reverseOP.OutTorque.Value(), 1e-6); @@ -131,7 +138,7 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData foreach (var entry in testData) { var torqueTCOut = entry.Item1.SI<NewtonMeter>(); var angularSpeedOut = entry.Item2.RPMtoRad(); - var result = tqData.FindOperatingPoint(torqueTCOut, angularSpeedOut); + var result = tqData.FindOperatingPoint(torqueTCOut, angularSpeedOut, 0.SI<PerSecond>()).First(); Debug.WriteLine("n_out: {0}, tq_out: {1}, n_in: {2}, Tq_in: {3}", angularSpeedOut.Value() / Constants.RPMToRad, torqueTCOut.Value(), result.InAngularVelocity.Value() / Constants.RPMToRad, result.InTorque.Value()); } @@ -176,9 +183,80 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponentData var outAngularSpeed = nOut.RPMtoRad(); var outTorque = (Pout * 1000).SI<Watt>() / outAngularSpeed; - var result = tqData.FindOperatingPoint(outTorque, outAngularSpeed); + var resultList = tqData.FindOperatingPoint(outTorque, outAngularSpeed, 0.SI<PerSecond>()); + Assert.AreEqual(1, resultList.Count); + var result = resultList[0]; Assert.IsTrue(result.InAngularVelocity.Value() > tqLimit.Value()); } + + + [TestCase()] + public void TestForwardBackward() + { + var tqLimit = 1600.RPMtoRad(); + + var tqInput = new[] { + "0,4.6,708 ", + "0.1,3.7,641 ", + "0.2,2.9,560 ", + "0.3,2.4,465 ", + "0.4,1.8,356 ", + "0.5,1.4,251 ", + "0.6,0.9,166 ", + "0.735,0.9,1 ", + "0.738,1.361,0 ", + "0.808,1.351,-40 ", + "0.898,1.349,-80 ", + "1.01,1.338,-136 ", + "1.154,1.327,-217 ", + "1.347,1.316,-335 ", + "1.616,1.305,-529 ", + "3 ,1.294,-729 ", + }; + + var tqInput_1 = new[] { + "0.0,1.80,377.80 ", + "0.1,1.71,365.21 ", + "0.2,1.61,352.62 ", + "0.3,1.52,340.02 ", + "0.4,1.42,327.43 ", + "0.5,1.33,314.84 ", + "0.6,1.23,302.24 ", + "0.7,1.14,264.46 ", + "0.8,1.04,226.68 ", + "0.9,0.95,188.90 ", + "1.0,0.95,0.00 ", + "1.100,0.99,-40.34 ", + "1.222,0.98,-80.34 ", + "1.375,0.97,-136.11 ", + "1.571,0.96,-216.52 ", + "1.833,0.95,-335.19 ", + "2.200,0.94,-528.77 ", + "2.750,0.93,-883.40 ", + "4.400,0.92,-2462.17 ", + "11.000,0.91,-16540.98 ", + }; + var tqData = + TorqueConverterDataReader.ReadFromStream(InputDataHelper.InputDataAsStream("Speed Ratio, Torque Ratio,MP1000", + tqInput), 1000.RPMtoRad(), tqLimit); + + var operatingPoint = tqData.FindOperatingPointForPowerDemand(20000.SI<Watt>(), 113.5.SI<PerSecond>(), + 1200.RPMtoRad(), 4.SI<KilogramSquareMeter>(), 0.5.SI<Second>()); + + var tmp = tqData.FindOperatingPoint(operatingPoint.OutTorque, operatingPoint.OutAngularVelocity, 0.RPMtoRad()); + var backward = tmp.First(); + + Debug.WriteLine(operatingPoint); + Debug.WriteLine(operatingPoint.InAngularVelocity * operatingPoint.InTorque); + + Debug.WriteLine(backward); + Debug.WriteLine(backward.InAngularVelocity * backward.InTorque); + + Assert.AreEqual(backward.OutAngularVelocity.Value(), operatingPoint.OutAngularVelocity.Value(), 1e-9); + Assert.AreEqual(backward.OutTorque.Value(), operatingPoint.OutTorque.Value(), 1e-9); + Assert.AreEqual(backward.InAngularVelocity.Value(), operatingPoint.InAngularVelocity.Value(), 1e-9); + Assert.AreEqual(backward.InTorque.Value(), operatingPoint.InTorque.Value(), 1e-9); + } } } \ No newline at end of file