From f5a847933bffd12d57f3f01c359735936e3fa950 Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Wed, 20 Apr 2022 12:32:25 +0200 Subject: [PATCH] Minor changes in DebugData (Local Variable stores LocalData, but all will also be stored in Global Data) --- .../VectoCore/Models/Simulation/Impl/VectoRun.cs | 1 - VectoCore/VectoCore/Utils/DebugData.cs | 15 ++++++--------- VectoCore/VectoCore/Utils/SearchAlgorithm.cs | 12 ++++++------ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs b/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs index 2edb5fed86..2061f830f3 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/VectoRun.cs @@ -106,7 +106,6 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl try { do { response = DoSimulationStep(); - DebugData.Clear(); debug.Add($"[VR.R] ---- ITERATION {iterationCount++} ---- ", response); if (response is ResponseSuccess) { Container.CommitSimulationStep(AbsTime, dt); diff --git a/VectoCore/VectoCore/Utils/DebugData.cs b/VectoCore/VectoCore/Utils/DebugData.cs index f286def640..dfe34c565c 100644 --- a/VectoCore/VectoCore/Utils/DebugData.cs +++ b/VectoCore/VectoCore/Utils/DebugData.cs @@ -42,14 +42,9 @@ namespace TUGraz.VectoCore.Utils private static readonly ThreadLocal<Queue<dynamic>> _data = new ThreadLocal<Queue<dynamic>>( () => new Queue<dynamic>(Capacity)); - private readonly bool _globalDebug; - - internal Queue<dynamic> Data => _globalDebug ? GlobalData : LocalData; - internal static Queue<dynamic> GlobalData => _data.Value; - internal Queue<dynamic> LocalData { get; } = new Queue<dynamic>(); - public DebugData(bool globalDebug = true) => _globalDebug = globalDebug; + internal Queue<dynamic> LocalData { get; } = new Queue<dynamic>(); [Conditional("DEBUG")] public static void Clear() => GlobalData.Clear(); @@ -57,10 +52,12 @@ namespace TUGraz.VectoCore.Utils [Conditional("DEBUG")] public void Add(dynamic value) { - while (Data.Count >= Capacity) { - Data.Dequeue(); + while (GlobalData.Count >= Capacity) { + GlobalData.Dequeue(); } - Data.Enqueue(value); + GlobalData.Enqueue(value); + + LocalData.Enqueue(value); } [Conditional("DEBUG")] diff --git a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs index f56ff31029..11ff01cdc0 100644 --- a/VectoCore/VectoCore/Utils/SearchAlgorithm.cs +++ b/VectoCore/VectoCore/Utils/SearchAlgorithm.cs @@ -187,16 +187,16 @@ namespace TUGraz.VectoCore.Utils [Conditional("TRACE")] private static void AppendDebug(DebugData debug) { - var xmin = debug.Data.Min(d => d.x); - var xmax = debug.Data.Max(d => d.x); - var ymin = debug.Data.Min(d => d.y); - var ymax = debug.Data.Max(d => d.y); + var xmin = debug.LocalData.Min(d => d.x); + var xmax = debug.LocalData.Max(d => d.x); + var ymin = debug.LocalData.Min(d => d.y); + var ymax = debug.LocalData.Max(d => d.y); var rand = new Random().Next(); using ( var f = new StreamWriter(File.Open("LineSearch-" + Thread.CurrentThread.ManagedThreadId + "-statistics.csv", FileMode.Append))) { - foreach (var d in debug.Data) { + foreach (var d in debug.LocalData) { f.WriteLine($"{rand}, " + $"{(d.x - xmin) / (xmax - xmin)}, " + $"{(d.y - ymin) / (ymax - ymin)}, " + @@ -312,7 +312,7 @@ namespace TUGraz.VectoCore.Utils table.Columns.Add("engineSpeed", typeof(double)); table.Columns.Add("enginePower", typeof(double)); - foreach (var entry in debug.Data.Skip(1)) { + foreach (var entry in debug.LocalData.Skip(1)) { var response = entry.result as ResponseDryRun; if (response == null) { continue; -- GitLab