From 6cd42f10bc15afe5dc3bb882384b6709b8a29a6e Mon Sep 17 00:00:00 2001
From: Raphael Luz <luz@ivt.tugraz.at>
Date: Wed, 4 Feb 2015 11:40:09 +0100
Subject: [PATCH] - Bugfix: VECTO didn't check if the full load curve covers
 the range up to nhi. Now it will abort if the full load curve is "too short"
 - Update in Torque Convert model: Allowed engine speed range up to n95h
 (before: Pmax-speed)

---
 VECTO/GUI/F_ENG.vb        | 41 ++++++++++++++++++++-------------------
 VECTO/GUI/F_VECTO.vb      | 41 ++++++++++++++++++++-------------------
 VECTO/Input Files/cENG.vb |  2 +-
 VECTO/Input Files/cFLD.vb | 35 +++++++++++++++++++++++++++++++--
 VECTO/Input Files/cGBX.vb |  2 +-
 VECTO/M_MAIN.vb           |  2 +-
 VECTO/VECTO_Global.vb     |  2 +-
 7 files changed, 79 insertions(+), 46 deletions(-)

diff --git a/VECTO/GUI/F_ENG.vb b/VECTO/GUI/F_ENG.vb
index f35f921cd7..1a0d85e8c4 100644
--- a/VECTO/GUI/F_ENG.vb
+++ b/VECTO/GUI/F_ENG.vb
@@ -555,26 +555,27 @@ Public Class F_ENG
 
             If IsNumeric(Me.TbNleerl.Text) AndAlso Me.TbNleerl.Text > 0 Then
 
-                FLD0.Init(CSng(Me.TbNleerl.Text))
-
-                Shiftpoly = New cGBX.cShiftPolygon("", 0)
-                Shiftpoly.SetGenericShiftPoly(FLD0, Me.TbNleerl.Text)
-
-                s = New System.Windows.Forms.DataVisualization.Charting.Series
-                s.Points.DataBindXY(Shiftpoly.gs_nUup, Shiftpoly.gs_TqUp)
-                s.ChartType = DataVisualization.Charting.SeriesChartType.FastLine
-                s.BorderWidth = 2
-                s.Color = Color.DarkRed
-                s.Name = "Upshift curve"
-                MyChart.Series.Add(s)
-
-                s = New System.Windows.Forms.DataVisualization.Charting.Series
-                s.Points.DataBindXY(Shiftpoly.gs_nUdown, Shiftpoly.gs_TqDown)
-                s.ChartType = DataVisualization.Charting.SeriesChartType.FastLine
-                s.BorderWidth = 2
-                s.Color = Color.DarkRed
-                s.Name = "Downshift curve"
-                MyChart.Series.Add(s)
+                If FLD0.Init(CSng(Me.TbNleerl.Text)) Then
+
+                    Shiftpoly = New cGBX.cShiftPolygon("", 0)
+                    Shiftpoly.SetGenericShiftPoly(FLD0, Me.TbNleerl.Text)
+
+                    s = New System.Windows.Forms.DataVisualization.Charting.Series
+                    s.Points.DataBindXY(Shiftpoly.gs_nUup, Shiftpoly.gs_TqUp)
+                    s.ChartType = DataVisualization.Charting.SeriesChartType.FastLine
+                    s.BorderWidth = 2
+                    s.Color = Color.DarkRed
+                    s.Name = "Upshift curve"
+                    MyChart.Series.Add(s)
+
+                    s = New System.Windows.Forms.DataVisualization.Charting.Series
+                    s.Points.DataBindXY(Shiftpoly.gs_nUdown, Shiftpoly.gs_TqDown)
+                    s.ChartType = DataVisualization.Charting.SeriesChartType.FastLine
+                    s.BorderWidth = 2
+                    s.Color = Color.DarkRed
+                    s.Name = "Downshift curve"
+                    MyChart.Series.Add(s)
+                End If
 
             End If
 
diff --git a/VECTO/GUI/F_VECTO.vb b/VECTO/GUI/F_VECTO.vb
index e916ef0687..d7366c0dde 100644
--- a/VECTO/GUI/F_VECTO.vb
+++ b/VECTO/GUI/F_VECTO.vb
@@ -1055,26 +1055,27 @@ lbDlog:
                     MyChart.Series.Add(s)
 
                     If Cfg.DeclMode Then
-                        FLD0.Init(ENG0.Nidle)
-
-                        Shiftpoly = New cGBX.cShiftPolygon("", 0)
-                        Shiftpoly.SetGenericShiftPoly(FLD0, ENG0.Nidle)
-
-                        s = New System.Windows.Forms.DataVisualization.Charting.Series
-                        s.Points.DataBindXY(Shiftpoly.gs_nUup, Shiftpoly.gs_TqUp)
-                        s.ChartType = DataVisualization.Charting.SeriesChartType.FastLine
-                        s.BorderWidth = 2
-                        s.Color = Color.DarkRed
-                        s.Name = "Upshift curve"
-                        MyChart.Series.Add(s)
-
-                        s = New System.Windows.Forms.DataVisualization.Charting.Series
-                        s.Points.DataBindXY(Shiftpoly.gs_nUdown, Shiftpoly.gs_TqDown)
-                        s.ChartType = DataVisualization.Charting.SeriesChartType.FastLine
-                        s.BorderWidth = 2
-                        s.Color = Color.DarkRed
-                        s.Name = "Downshift curve"
-                        MyChart.Series.Add(s)
+
+                        If FLD0.Init(ENG0.Nidle) Then
+                            Shiftpoly = New cGBX.cShiftPolygon("", 0)
+                            Shiftpoly.SetGenericShiftPoly(FLD0, ENG0.Nidle)
+
+                            s = New System.Windows.Forms.DataVisualization.Charting.Series
+                            s.Points.DataBindXY(Shiftpoly.gs_nUup, Shiftpoly.gs_TqUp)
+                            s.ChartType = DataVisualization.Charting.SeriesChartType.FastLine
+                            s.BorderWidth = 2
+                            s.Color = Color.DarkRed
+                            s.Name = "Upshift curve"
+                            MyChart.Series.Add(s)
+
+                            s = New System.Windows.Forms.DataVisualization.Charting.Series
+                            s.Points.DataBindXY(Shiftpoly.gs_nUdown, Shiftpoly.gs_TqDown)
+                            s.ChartType = DataVisualization.Charting.SeriesChartType.FastLine
+                            s.BorderWidth = 2
+                            s.Color = Color.DarkRed
+                            s.Name = "Downshift curve"
+                            MyChart.Series.Add(s)
+                        End If
 
                     End If
 
diff --git a/VECTO/Input Files/cENG.vb b/VECTO/Input Files/cENG.vb
index c7875237d2..20c460514b 100644
--- a/VECTO/Input Files/cENG.vb	
+++ b/VECTO/Input Files/cENG.vb	
@@ -376,7 +376,7 @@ Public Class cENG
                 Return False
             End Try
 
-            FLD(i).Init(Nidle)
+            If Not FLD(i).Init(Nidle) Then Return False
 
         Next
 
diff --git a/VECTO/Input Files/cFLD.vb b/VECTO/Input Files/cFLD.vb
index 8f961e3c64..7f125edc3c 100644
--- a/VECTO/Input Files/cFLD.vb	
+++ b/VECTO/Input Files/cFLD.vb	
@@ -330,6 +330,8 @@ lbInt:
 
         N95h = fnUofPfull(0.95 * Pfull(fnUrated), False)
 
+        If N95h < 0 Then Return -1
+
         Amax = Area(Nidle, N95h)
 
         For i = 0 To iDim - 1
@@ -465,6 +467,8 @@ lbInt:
             LastPe = nMtoPe(nU, Tq(nU))
             nUtarget = nU
 
+            If LastPe > PeTarget Then Return -1
+
             Do
                 Pe = nMtoPe(nU, Tq(nU))
 
@@ -486,6 +490,8 @@ lbInt:
             LastPe = nMtoPe(nU, Tq(nU))
             nUtarget = nU
 
+            If LastPe > PeTarget Then Return -1
+
             Do
                 Pe = nMtoPe(nU, Tq(nU))
 
@@ -525,20 +531,45 @@ lbInt:
 
     End Function
 
-    Public Sub Init(ByVal Nidle As Single)
+    Public Function Init(ByVal Nidle As Single) As Boolean
         Dim Pmax As Single
+        Dim MsgSrc As String
+
+        MsgSrc = "Main/ReadInp/Eng.Init"
 
         Pmax = Pfull(fnUrated)
 
         Nlo = fnUofPfull(0.55 * Pmax, True)
 
+        If Nlo < 0 Then
+            WorkerMsg(tMsgID.Err, "Failed to calculate Nlo! Check full load curve!", MsgSrc)
+            Return False
+        End If
+
         N95h = fnUofPfull(0.95 * Pmax, False)
 
+        If N95h < 0 Then
+            WorkerMsg(tMsgID.Err, "Failed to calculate N95h! Check full load curve!", MsgSrc)
+            Return False
+        End If
+
         Npref = fNpref(Nidle)
 
+        If Npref < 0 Then
+            WorkerMsg(tMsgID.Err, "Failed to calculate Npref! Check full load curve!", MsgSrc)
+            Return False
+        End If
+
         Nhi = fnUofPfull(0.7 * Pmax, False)
 
-    End Sub
+        If Nhi < 0 Then
+            WorkerMsg(tMsgID.Err, "Failed to calculate Nhi! Check full load curve!", MsgSrc)
+            Return False
+        End If
+
+        Return True
+
+    End Function
 
     Public Sub DeclInit()
         Dim i As Integer
diff --git a/VECTO/Input Files/cGBX.vb b/VECTO/Input Files/cGBX.vb
index ae1e3bb196..b7c19677ed 100644
--- a/VECTO/Input Files/cGBX.vb	
+++ b/VECTO/Input Files/cGBX.vb	
@@ -467,7 +467,7 @@ Public Class cGBX
             nuMax = Math.Min(TCnu(TCdim), nUout / ENG.Nidle)
 
         Else
-            nuMin = Math.Max(nUout / ENG.Nrated, TCnu(0))
+            nuMin = Math.Max(nUout / FLD(Gear).N95h, TCnu(0))
             nuMax = Math.Min(TCnuMax, nUout / ENG.Nidle)
         End If
 
diff --git a/VECTO/M_MAIN.vb b/VECTO/M_MAIN.vb
index 33953d1ead..026c9ab013 100644
--- a/VECTO/M_MAIN.vb
+++ b/VECTO/M_MAIN.vb
@@ -787,7 +787,7 @@ lbExit:
         End If
 
         'Must be called after cGBX.ReadFile because cGBX.GearCount is needed
-        ENG.Init()
+        If Not ENG.Init() Then Return False
 
         'Must be called after cENG.Init because FLD must be loaded
         If Cfg.DeclMode Then
diff --git a/VECTO/VECTO_Global.vb b/VECTO/VECTO_Global.vb
index e1a4a4ad24..6332293aaf 100644
--- a/VECTO/VECTO_Global.vb
+++ b/VECTO/VECTO_Global.vb
@@ -12,7 +12,7 @@ Imports System.Collections.Generic
 
 Module VECTO_Global
 
-    Public Const VECTOvers As String = "2.0.4-beta3"
+    Public Const VECTOvers As String = "2.0.4-beta4"
     Public Const LicSigAppCode As String = "VECTO-Release-0093C61E0A2E4BFA9A7ED7E729C56AE4"
     Public MyAppPath As String
     Public MyConfPath As String
-- 
GitLab