Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit aa9ad7ed authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Merge pull request #414 in VECTO/vecto-sim from...

Merge pull request #414 in VECTO/vecto-sim from ~EMQUARIMA/vecto-sim:feature/VECTO-494-implementation-of-fuel-types to develop

* commit '760eeca7':
  adding testcase for comparing results of different fuel types
  implement CO2 values per fuel type
parents 7dfaac32 760eeca7
No related branches found
No related tags found
No related merge requests found
Showing
with 158 additions and 57 deletions
......@@ -12,8 +12,10 @@ Imports System.Collections.Generic
Imports System.IO
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports TUGraz.VectoCommon.Models
Imports TUGraz.VectoCore.InputData.FileIO.JSON
Imports TUGraz.VectoCore.Models.Declaration
Imports TUGraz.VectoCore.Utils
Public Class Configuration
Public FilePath As String
......@@ -28,6 +30,8 @@ Public Class Configuration
Public FirstRun As Boolean
Public DeclMode As Boolean
Public Const DefaultFuelType As FuelType = FuelType.DieselCI
Private Const FormatVersion As Short = 2
Public Sub New()
......@@ -35,9 +39,9 @@ Public Class Configuration
End Sub
Public Sub DeclInit()
AirDensity = DeclarationData.Physics.AirDensity.Value() ' cDeclaration.AirDensity
FuelDens = DeclarationData.Physics.FuelDensity.Value() ' cDeclaration.FuelDens
CO2perFC = DeclarationData.Physics.CO2PerFuelWeight ' cDeclaration.CO2perFC
AirDensity = Physics.AirDensity.Value() ' cDeclaration.AirDensity
FuelDens = DeclarationData.FuelData.Lookup(DefaultFuelType).FuelDensity.Value() ' cDeclaration.FuelDens
Co2PerFc = DeclarationData.FuelData.Lookup(DefaultFuelType).CO2PerFuelWeight ' cDeclaration.CO2perFC
End Sub
Public Sub SetDefault()
......@@ -47,8 +51,8 @@ Public Class Configuration
AirDensity = 1.2
OpenCmd = "notepad"
OpenCmdName = "Notepad"
FuelDens = DeclarationData.Physics.FuelDensity.Value()
CO2perFC = DeclarationData.Physics.CO2PerFuelWeight
FuelDens = DeclarationData.FuelData.Lookup(DefaultFuelType).FuelDensity.Value()
Co2PerFc = DeclarationData.FuelData.Lookup(DefaultFuelType).CO2PerFuelWeight
FirstRun = True
DeclMode = True
End Sub
......
......@@ -55,7 +55,7 @@ Public Class EngineForm
cbFuelType.ValueMember = "Value"
cbFuelType.DisplayMember = "Label"
cbFuelType.DataSource =
[Enum].GetValues(GetType(FuelType)).Cast(Of FuelType).Select(
[Enum].GetValues(GetType(TUGraz.VectoCommon.Models.FuelType)).Cast(Of TUGraz.VectoCommon.Models.FuelType).Select(
Function(type) New With {Key .Value = type, .Label = type.GetLabel()}).ToList()
_changed = False
......@@ -257,7 +257,7 @@ Public Class EngineForm
engine.ratedSpeedInput = tbRatedSpeed.Text.ToDouble(0).RPMtoRad()
engine.maxTorqueInput = tbMaxTorque.Text.ToDouble(0).SI(Of NewtonMeter)()
engine.FuelTypeInput = CType(cbFuelType.SelectedValue, FuelType)
engine.FuelTypeInput = CType(cbFuelType.SelectedValue, TUGraz.VectoCommon.Models.FuelType)
If Not engine.SaveFile Then
MsgBox("Cannot safe to " & file, MsgBoxStyle.Critical)
......
......@@ -983,11 +983,6 @@ lbFound:
mode = ExecutionMode.Declaration
Else
mode = ExecutionMode.Engineering
Physics.FuelDensity = Cfg.FuelDens.SI(Of KilogramPerCubicMeter)() _
'New SI(Cfg.FuelDens).Kilo.Gramm.Per.Cubic.Dezi.Meter.Cast(Of KilogramPerCubicMeter)()
Physics.AirDensity = Cfg.AirDensity.SI(Of KilogramPerCubicMeter)() _
'New SI(Cfg.AirDensity).Kilo.Gramm.Per.Cubic.Meter.Cast(Of KilogramPerCubicMeter)()
Physics.CO2PerFuelWeight = Cfg.Co2PerFc
End If
'dictionary of run-identifiers to fileWriters (used for output directory of modfile)
......
......@@ -192,6 +192,7 @@ Partial Class Settings
Me.GrCalc.TabIndex = 1
Me.GrCalc.TabStop = False
Me.GrCalc.Text = "Calculation"
Me.GrCalc.Visible = False
'
'Label11
'
......
using System;
using System.Diagnostics.CodeAnalysis;
namespace TUGraz.VectoCommon.Models
{
......@@ -11,7 +10,7 @@ namespace TUGraz.VectoCommon.Models
PetrolPI,
EthanolPI,
LPG,
NG
NG,
// ReSharper restore InconsistentNaming
}
......
......@@ -593,6 +593,11 @@ namespace TUGraz.VectoCommon.Utils
{
return SIBase<Watt>.Create(joule.Val / s.Value());
}
public static JoulePerMeter operator /(Joule joule, Meter meter)
{
return SIBase<JoulePerMeter>.Create(joule.Val / meter.Value());
}
}
public class JoulePerKilogramm : SIBase<JoulePerKilogramm>
......@@ -608,6 +613,18 @@ namespace TUGraz.VectoCommon.Utils
}
}
/// <summary>
/// SI Class for KilogramPerMeter [J/m].
/// </summary>
public class JoulePerMeter : SIBase<JoulePerMeter>
{
private static readonly Unit[] NumeratorDefault = { Unit.J };
private static readonly Unit[] DenominatorDefault = { Unit.m };
[DebuggerHidden]
private JoulePerMeter(double val) : base(val, NumeratorDefault, DenominatorDefault) {}
}
/// <summary>
/// SI Class for one per second [1/s].
/// </summary>
......
......@@ -37,6 +37,7 @@ using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.InputData.Reader.ComponentData;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.SimulationComponent.Data;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
......@@ -121,6 +122,7 @@ namespace TUGraz.VectoCore.InputData.Reader.DataObjectAdapter
RatedPowerDeclared = data.RatedPowerDeclared,
RatedSpeedDeclared = data.RatedSpeedDeclared,
MaxTorqueDeclared = data.MaxTorqueDeclared,
FuelType = data.FuelType
};
return retVal;
}
......
......@@ -29,7 +29,6 @@
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
......@@ -54,6 +53,7 @@ namespace TUGraz.VectoCore.Models.Declaration
public static readonly Segments Segments = new Segments();
public static readonly Wheels Wheels = new Wheels();
public static readonly PT1 PT1 = new PT1();
public static readonly FuelData FuelData = FuelData.Instance();
public static readonly ElectricSystem ElectricSystem = new ElectricSystem();
public static readonly Fan Fan = new Fan();
......@@ -96,29 +96,6 @@ namespace TUGraz.VectoCore.Models.Declaration
return 1;
}
public static class Physics
{
/// <summary>
/// The standard acceleration for gravity on earth.
/// http://physics.nist.gov/Pubs/SP330/sp330.pdf (page 52)
/// </summary>
public static readonly MeterPerSquareSecond GravityAccelleration = 9.80665.SI<MeterPerSquareSecond>();
/// <summary>
/// Density of air.
/// </summary>
public static readonly KilogramPerCubicMeter AirDensity = 1.188.SI<KilogramPerCubicMeter>();
/// <summary>
/// Density of fuel.
/// </summary>
public static readonly KilogramPerCubicMeter FuelDensity = 832.SI<KilogramPerCubicMeter>();
/// <summary>
/// fuel[kg] => co2[kg]. Factor to convert from fuel weight to co2 weight.
/// </summary>
public static readonly double CO2PerFuelWeight = 3.16;
}
public static class Driver
{
......
using System;
using System.Data;
using System.Linq;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Declaration
{
public sealed class FuelData : LookupData<FuelType, FuelData.Entry>
{
private static FuelData _instance;
public static FuelData Instance()
{
return _instance ?? (_instance = new FuelData());
}
private FuelData() : base() {}
protected override string ResourceId
{
get { return DeclarationData.DeclarationDataResourcePrefix + ".FuelTypes.csv"; }
}
protected override string ErrorMessage
{
get { throw new InvalidOperationException("ErrorMessage not applicable."); }
}
public static Entry Diesel
{
get { return Instance().Lookup(FuelType.DieselCI); }
}
protected override void ParseData(DataTable table)
{
Data = table.Rows.Cast<DataRow>()
.Select(r => {
var density = r.Field<string>("fueldensity");
return new Entry(
r.Field<string>(0).ParseEnum<FuelType>(),
string.IsNullOrWhiteSpace(density) ? null : density.ToDouble(0).SI<KilogramPerCubicMeter>(),
r.ParseDouble("co2perfuelweight"),
r.ParseDouble("lowerheatingvalue").SI().Kilo.Joule.Per.Kilo.Gramm.Cast<JoulePerKilogramm>()
);
})
.ToDictionary(e => e.FuelType);
}
public FuelType[] GetFuelTypes()
{
return Data.Keys.ToArray();
}
public class Entry
{
public Entry(FuelType type, KilogramPerCubicMeter density, double weight, JoulePerKilogramm heatingValue)
{
FuelType = type;
FuelDensity = density;
CO2PerFuelWeight = weight;
LowerHeatingValue = heatingValue;
}
public FuelType FuelType { get; private set; }
public KilogramPerCubicMeter FuelDensity { get; private set; }
public double CO2PerFuelWeight { get; private set; }
public JoulePerKilogramm LowerHeatingValue { get; private set; }
}
}
}
\ No newline at end of file
......@@ -31,6 +31,7 @@
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.SimulationComponent;
namespace TUGraz.VectoCore.Models.Simulation.DataBus
......@@ -43,6 +44,8 @@ namespace TUGraz.VectoCore.Models.Simulation.DataBus
{
ExecutionMode ExecutionMode { get; }
FuelType FuelType { get; }
Second AbsTime { get; set; }
}
}
\ No newline at end of file
......@@ -181,7 +181,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
throw new ArgumentOutOfRangeException("CycleType unknown:" + data.Cycle.CycleType);
}
var validationErrors = run.Validate(_mode, data.GearboxData == null ? (GearboxType?)null : data.GearboxData.Type, data.Mission != null && data.Mission.MissionType.IsEMS());
var validationErrors = run.Validate(_mode, data.GearboxData == null ? (GearboxType?)null : data.GearboxData.Type,
data.Mission != null && data.Mission.MissionType.IsEMS());
if (validationErrors.Any()) {
throw new VectoException("Validation of Run-Data Failed: " +
string.Join("\n", validationErrors.Select(r => r.ErrorMessage + string.Join("; ", r.MemberNames))));
......
......@@ -37,6 +37,7 @@ using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.DataBus;
using TUGraz.VectoCore.Models.SimulationComponent;
......@@ -263,6 +264,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
return Cycle;
}
public FuelType FuelType { get { return ModData.FuelData.FuelType; } }
public Second AbsTime { get; set; }
public void AddComponent(VectoSimulationComponent component)
......
......@@ -35,6 +35,7 @@ using System.ComponentModel.DataAnnotations;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
namespace TUGraz.VectoCore.Models.SimulationComponent.Data
......@@ -75,7 +76,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
[Required, Range(double.MinValue, double.MaxValue)]
public double CorrectionFactorNCV { get; internal set; }
public double FuelConsumptionCorrectionFactor {get; internal set; }
public double FuelConsumptionCorrectionFactor { get; internal set; }
public PerSecond RatedSpeedDeclared { get; internal set; }
......@@ -112,6 +113,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data
RatedPowerDeclared = RatedPowerDeclared,
RatedSpeedDeclared = RatedSpeedDeclared,
MaxTorqueDeclared = MaxTorqueDeclared,
FuelType = FuelType
};
}
......
......@@ -33,6 +33,7 @@ using System;
using System.IO;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.DataBus;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
......@@ -79,7 +80,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
_fcMapAdapter = new FuelConsumptionAdapter() { FcMap = fcMap };
tmpAux.VectoInputs.FuelMap = _fcMapAdapter;
tmpAux.VectoInputs.FuelDensity = Physics.FuelDensity;
tmpAux.VectoInputs.FuelDensity = FuelData.Instance().Lookup(container.FuelType).FuelDensity;
//'Set Signals
tmpAux.Signals.EngineIdleSpeed = engineIdleSpeed;
......
......@@ -106,7 +106,7 @@ namespace TUGraz.VectoCore.OutputData
/// <summary>
/// The full load curve.
/// </summary>
internal Dictionary<uint, EngineFullLoadCurve> Flc { get; set; }
internal Dictionary<uint, EngineFullLoadCurve> Flc { get; set; }
/// <summary>
/// The declaration segment from the segment table
......
......@@ -35,6 +35,7 @@ using System.Data;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.DataBus;
using TUGraz.VectoCore.Models.Simulation.Impl;
......@@ -71,6 +72,8 @@ namespace TUGraz.VectoCore.OutputData
/// </summary>
void CommitSimulationStep();
FuelData.Entry FuelData { get; }
VectoRun.Status RunStatus { get; }
/// <summary>
......@@ -379,7 +382,7 @@ namespace TUGraz.VectoCore.OutputData
return null;
}
var fcVolumePerMeter = fuelConsumptionFinal / Physics.FuelDensity;
var fcVolumePerMeter = fuelConsumptionFinal / data.FuelData.FuelDensity;
return fcVolumePerMeter.ConvertTo().Cubic.Dezi.Meter * 100.SI().Kilo.Meter;
}
......@@ -389,7 +392,16 @@ namespace TUGraz.VectoCore.OutputData
if (distance == null || distance.IsEqual(0)) {
return null;
}
return data.TimeIntegral<Kilogram>(ModalResultField.FCFinal) * Physics.CO2PerFuelWeight / distance;
return data.TimeIntegral<Kilogram>(ModalResultField.FCFinal) * data.FuelData.CO2PerFuelWeight / distance;
}
public static JoulePerMeter EnergyPerMeter(this IModalDataContainer data)
{
var distance = data.Distance();
if (distance == null || distance.IsEqual(0)) {
return null;
}
return data.TimeIntegral<Kilogram>(ModalResultField.FCFinal) * data.FuelData.LowerHeatingValue / distance;
}
public static KilogramPerSecond FCMapPerSecond(this IModalDataContainer data)
......
......@@ -35,7 +35,9 @@ using System.Data;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Models.Simulation.Data;
using TUGraz.VectoCore.Models.Simulation.Impl;
......@@ -61,14 +63,17 @@ namespace TUGraz.VectoCore.OutputData
public bool WriteAdvancedAux { get; set; }
public ModalDataContainer(string runName, IModalDataWriter writer, bool writeEngineOnly = false)
: this(runName, "", "", writer, _ => { }, writeEngineOnly) {}
public ModalDataContainer(string runName, FuelType fuel, IModalDataWriter writer, bool writeEngineOnly = false)
: this(runName, "", fuel, "", writer, _ => { }, writeEngineOnly) {}
public ModalDataContainer(VectoRunData runData, IModalDataWriter writer, Action<ModalDataContainer> addReportResult,
bool writeEngineOnly, params IModalDataFilter[] filter)
: this(runData.JobName, runData.Cycle.Name, runData.ModFileSuffix, writer, addReportResult, writeEngineOnly, filter) {}
: this(
runData.JobName, runData.Cycle.Name, runData.EngineData.FuelType, runData.ModFileSuffix, writer, addReportResult,
writeEngineOnly, filter) {}
protected ModalDataContainer(string runName, string cycleName, string runSuffix, IModalDataWriter writer,
protected ModalDataContainer(string runName, string cycleName, FuelType fuelType, string runSuffix,
IModalDataWriter writer,
Action<ModalDataContainer> addReportResult, bool writeEngineOnly, params IModalDataFilter[] filters)
{
HasTorqueConverter = false;
......@@ -77,6 +82,8 @@ namespace TUGraz.VectoCore.OutputData
RunSuffix = runSuffix;
_writer = writer;
FuelData = Models.Declaration.FuelData.Instance().Lookup(fuelType);
_writeEngineOnly = writeEngineOnly;
_filters = filters ?? new IModalDataFilter[0];
_addReportResult = addReportResult ?? (x => { });
......@@ -95,6 +102,8 @@ namespace TUGraz.VectoCore.OutputData
CurrentRow = Data.NewRow();
}
public FuelData.Entry FuelData { get; internal set; }
public void Finish(VectoRun.Status runStatus)
{
var dataColumns = new List<ModalResultField> { ModalResultField.time };
......
FuelType , FuelDensity [kg/m3] , CO2 per FuelWeight [kgCo2/kgFuel] , Lower Heating Value [kJ/kg]
Diesel CI , 832 , 3.16 , 42700
Ethanol CI , 794 , 1.91 , 29200
Petrol PI , 745 , 3.17 , 41500
Ethanol PI , 794 , 1.91 , 29200
LPG , , 3.02 , 46000
NG , , 2.54 , 45100
\ No newline at end of file
......@@ -46,10 +46,6 @@ namespace TUGraz.VectoCore.Utils
/// </summary>
public static KilogramPerCubicMeter AirDensity = 1.188.SI<KilogramPerCubicMeter>();
/// <summary>
/// Density of fuel.
/// </summary>
public static KilogramPerCubicMeter FuelDensity = 832.SI<KilogramPerCubicMeter>();
public const double RollResistanceExponent = 0.9;
......@@ -67,10 +63,5 @@ namespace TUGraz.VectoCore.Utils
/// Hellmann Exponent for modelling of wind speed in specific heights.
/// </summary>
public const double HellmannExponent = 0.2;
/// <summary>
/// fuel[kg] => co2[kg]. Factor to convert from fuel weight to co2 weight.
/// </summary>
public static double CO2PerFuelWeight = 3.16;
}
}
\ No newline at end of file
......@@ -166,6 +166,7 @@
<Compile Include="Models\Connector\Ports\IFvPort.cs" />
<Compile Include="Models\Connector\Ports\ITnPort.cs" />
<Compile Include="InputData\Reader\ComponentData\AccelerationCurveReader.cs" />
<Compile Include="Models\Declaration\FuelData.cs" />
<Compile Include="Models\Declaration\PTOTransmission.cs" />
<Compile Include="Models\Declaration\IDeclarationAuxiliaryTable.cs" />
<Compile Include="Models\SimulationComponent\Data\AngledriveData.cs" />
......@@ -431,6 +432,7 @@
</EmbeddedResource>
<EmbeddedResource Include="Resources\Declaration\MissionCycles\MunicipalUtility_PTO_generic.vptoc" />
<EmbeddedResource Include="Resources\Declaration\MissionCycles\MunicipalUtility_PTO_generic.vptol" />
<EmbeddedResource Include="Resources\Declaration\FuelTypes.csv" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Declaration\Report\4x2r.png" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment