// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Interface; using Deltares.DamEngine.Io; using Deltares.DamEngine.Io.XmlOutput; using Deltares.DamEngine.TestHelpers; using NUnit.Framework; namespace Deltares.DamEngine.IntegrationTests.IntegrationTests; [TestFixture] public class MultiCoreMacroStabilityTests { private const string mapTestFiles = @"TestFiles\"; const string testWorkingFolder = @"MultiCore\"; [SetUp] public void Setup()// Fixture() { RemoveTestWorkingDirectory(testWorkingFolder); // to be sure no test directory exist from previous tests } [TearDown] public void TearDown()//Fixture() { RemoveTestWorkingDirectory(testWorkingFolder); // to be sure no test directory exist after the tests } [Test] [TestCase("OperationalBishopGrid1Core.xml")] [TestCase("OperationalBishopGrid2Cores.xml")] [TestCase("OperationalBishopGrid4Cores.xml")] [TestCase("OperationalBishopGrid8Cores.xml")] [TestCase("OperationalBishopGrid18Cores.xml")] public void OperationalBishopGridTestsWithXmlInputFile(string aFileName) { //const string inputFilename = "InputForDebugging.xml"; // or put your own name here; string fullInputFilename = Path.Combine(mapTestFiles, aFileName); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; string inputString = File.ReadAllText(fullInputFilename); var engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); engineInterface.DamProjectData.ProjectPath = @"MultiCore\"; string result = engineInterface.Validate(); Assert.IsTrue(result == null, "Validation must succeed but does not, see output xml in debugger"); string outputString = engineInterface.Run(); File.WriteAllText("Output.xml", outputString); Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString); if (engineInterface.DamProjectData.DamProjectType == DamProjectType.Design) { Assert.AreNotEqual(null, output.Results.CalculationResults); } else { Assert.AreEqual(8, output.Results.OperationalOutputTimeSeries.Length); int numberOfResults = 0; int numberOfRealResults = 0; foreach (TimeSerie resultSerie in output.Results.OperationalOutputTimeSeries) { numberOfResults += resultSerie.Entries.TimeSerieEntry.Length; foreach (TimeSerieEntriesTimeSerieEntry timeSerieEntriesTimeSerieEntry in resultSerie.Entries.TimeSerieEntry) { if (!Double.IsNaN(timeSerieEntriesTimeSerieEntry.Value)) { numberOfRealResults++; } } } Assert.AreEqual(16, numberOfResults); Assert.AreEqual(16, numberOfRealResults); } } [Test]//, Ignore("This test is only used for debugging XML files generated by Dam UI")] [TestCase("DesignBishopGrid1Core.xml")] [TestCase("DesignBishopGrid2Cores.xml")] [TestCase("DesignBishopGrid4Cores.xml")] [TestCase("DesignBishopGrid8Cores.xml")] [TestCase("DesignBishopGrid18Cores.xml")] public void DebugDesignWithXmlInputFile(string aFileName) { string fullInputFilename = Path.Combine(mapTestFiles, aFileName); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; string inputString = File.ReadAllText(fullInputFilename); var engineInterface = new EngineInterface(inputString); Assert.IsNotNull(engineInterface.DamProjectData); engineInterface.DamProjectData.ProjectPath = @"MultiCore\"; string result = engineInterface.Validate(); Assert.IsTrue(result == null, "Validation must succeed but does not, see output xml in debugger"); string outputString = engineInterface.Run(); File.WriteAllText("Output.xml", outputString); Output output = DamXmlSerialization.LoadOutputFromXmlString(outputString); if (engineInterface.DamProjectData.DamProjectType == DamProjectType.Design) { Assert.AreNotEqual(null, output.Results.CalculationResults); } else { Assert.AreEqual(8, output.Results.OperationalOutputTimeSeries.Length); int numberOfResults = 0; int numberOfRealResults = 0; foreach (TimeSerie resultSerie in output.Results.OperationalOutputTimeSeries) { numberOfResults += resultSerie.Entries.TimeSerieEntry.Length; foreach (TimeSerieEntriesTimeSerieEntry timeSerieEntriesTimeSerieEntry in resultSerie.Entries.TimeSerieEntry) { if (!Double.IsNaN(timeSerieEntriesTimeSerieEntry.Value)) { numberOfRealResults++; } } } Assert.AreEqual(16, numberOfResults); Assert.AreEqual(16, numberOfRealResults); } } private static void RemoveTestWorkingDirectory(string testWorkingFolder) { if (Directory.Exists(testWorkingFolder)) { const bool recursive = true; Directory.Delete(testWorkingFolder, recursive); } } }