Code development platform for open source projects from the European Union institutions

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

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

Merge pull request #283 in VECTO/vecto-sim from ~EMQUARIMA/vecto-sim:feature/VECTO-359-remove-duplicate-code to develop

* commit 'da9386cc':
  removing PT1Curve class, adding functionality to PT1 (Declaration)
  modified checklist for releases
parents 780b6775 da9386cc
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -89,7 +89,7 @@ namespace TUGraz.VectoCore.InputData.Reader
tmp = new PT1();
} else {
if (data.Columns.Count > 3) {
tmp = PT1Curve.Create(data);
tmp = new PT1(data);
} else {
tmp = new PT1();
}
......
......@@ -34,7 +34,9 @@ using System.Collections.Generic;
using System.Data;
using System.Linq;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Engine;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.Declaration
......@@ -58,6 +60,11 @@ namespace TUGraz.VectoCore.Models.Declaration
ParseData(ReadCsvResource(ResourceId));
}
public PT1(DataTable data)
{
ParseDataFromFld(data);
}
protected override void ParseData(DataTable table)
{
_entries = table.Rows.Cast<DataRow>()
......@@ -66,6 +73,30 @@ namespace TUGraz.VectoCore.Models.Declaration
.ToList();
}
private void ParseDataFromFld(DataTable data)
{
if (data.Columns.Count < 3) {
throw new VectoException("FullLoadCurve/PT1 Data File must consist of at least 4 columns.");
}
if (data.Rows.Count < 2) {
throw new VectoException(
"FullLoadCurve/PT1 must consist of at least two lines with numeric values (below file header)");
}
if (data.Columns.Contains(Fields.EngineSpeed) && data.Columns.Contains(Fields.PT1)) {
_entries = data.Rows.Cast<DataRow>()
.Select(
r => new KeyValuePair<PerSecond, Second>(DataTableExtensionMethods.ParseDouble(r, Fields.EngineSpeed).RPMtoRad(),
DataTableExtensionMethods.ParseDouble(r, Fields.PT1).SI<Second>()))
.OrderBy(x => x.Key).ToList();
} else {
_entries = data.Rows.Cast<DataRow>()
.Select(r => new KeyValuePair<PerSecond, Second>(r.ParseDouble(0).RPMtoRad(), r.ParseDouble(3).SI<Second>()))
.OrderBy(x => x.Key).ToList();
}
}
public override Second Lookup(PerSecond key)
{
var index = 1;
......@@ -86,5 +117,11 @@ namespace TUGraz.VectoCore.Models.Declaration
}
return pt1;
}
private static class Fields
{
public const string PT1 = "PT1";
public const string EngineSpeed = "engine speed";
}
}
}
\ No newline at end of file
/*
* This file is part of VECTO.
*
* Copyright © 2012-2016 European Union
*
* Developed by Graz University of Technology,
* Institute of Internal Combustion Engines and Thermodynamics,
* Institute of Technical Informatics
*
* VECTO is licensed under the EUPL, Version 1.1 or - as soon they will be approved
* by the European Commission - subsequent versions of the EUPL (the "Licence");
* You may not use VECTO except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* https://joinup.ec.europa.eu/community/eupl/og_page/eupl
*
* Unless required by applicable law or agreed to in writing, VECTO
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*
* Authors:
* Stefan Hausberger, hausberger@ivt.tugraz.at, IVT, Graz University of Technology
* Christian Kreiner, christian.kreiner@tugraz.at, ITI, Graz University of Technology
* Michael Krisper, michael.krisper@tugraz.at, ITI, Graz University of Technology
* Raphael Luz, luz@ivt.tugraz.at, IVT, Graz University of Technology
* Markus Quaritsch, markus.quaritsch@tugraz.at, IVT, Graz University of Technology
* Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology
*/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.Declaration;
using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
{
public sealed class PT1Curve : LookupData<PerSecond, Second>
{
private List<KeyValuePair<PerSecond, Second>> _entries;
// just for Lookup-inheritance compatibility
protected override string ResourceId
{
get { return null; }
}
// just for Lookup-inheritance compatibility
protected override string ErrorMessage
{
get { throw new InvalidOperationException(); }
}
private PT1Curve(DataTable data)
{
ParseData(data);
}
private PT1Curve(string file)
{
DataTable data;
try {
data = VectoCSVFile.Read(file);
} catch (Exception ex) {
throw new VectoException("ERROR while reading PT1 Curve File: " + ex.Message);
}
ParseData(data);
}
public static PT1Curve ReadFromFile(string fileName)
{
return new PT1Curve(fileName);
}
public static PT1Curve Create(DataTable data)
{
return new PT1Curve(data);
}
protected override void ParseData(DataTable data)
{
if (data.Columns.Count < 3) {
throw new VectoException("FullLoadCurve/PT1 Data File must consist of at least 4 columns.");
}
if (data.Rows.Count < 2) {
throw new VectoException(
"FullLoadCurve/PT1 must consist of at least two lines with numeric values (below file header)");
}
if (data.Columns.Contains(Fields.EngineSpeed) && data.Columns.Contains(Fields.PT1)) {
_entries = data.Rows.Cast<DataRow>()
.Select(r => new KeyValuePair<PerSecond, Second>(r.ParseDouble(Fields.EngineSpeed).RPMtoRad(),
r.ParseDouble(Fields.PT1).SI<Second>()))
.OrderBy(x => x.Key).ToList();
} else {
_entries = data.Rows.Cast<DataRow>()
.Select(r => new KeyValuePair<PerSecond, Second>(r.ParseDouble(0).RPMtoRad(), r.ParseDouble(3).SI<Second>()))
.OrderBy(x => x.Key).ToList();
}
}
public override Second Lookup(PerSecond key)
{
var index = 1;
if (key.IsSmaller(_entries[0].Key)) {
Log.Error("requested rpm below minimum rpm in pt1 - extrapolating. n_eng_avg: {0}, rpm_min: {1}",
key.ConvertTo().Rounds.Per.Minute, _entries[0].Key.ConvertTo().Rounds.Per.Minute);
} else {
index = _entries.FindIndex(x => x.Key.IsGreater(key));
if (index <= 0) {
index = key.IsGreater(_entries[0].Key) ? _entries.Count - 1 : 1;
}
}
var pt1 = VectoMath.Interpolate(_entries[index - 1].Key, _entries[index].Key, _entries[index - 1].Value,
_entries[index].Value, key);
if (pt1 < 0) {
throw new VectoException("The calculated pt1 value must not be smaller than 0. Value: " + pt1);
}
return pt1;
}
private static class Fields
{
public const string PT1 = "PT1";
public const string EngineSpeed = "engine speed";
}
}
}
\ No newline at end of file
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