// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the application DAM - Live. // // DAM - Live 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.Linq; using Deltares.Dam.Application.Live; using Deltares.Dam.Data; using Deltares.DamLive.TestHelper; using NUnit.Framework; namespace Deltares.DamLive.Tests; [TestFixture] [Category("Integration")] public class StabilityInsideUpliftVanGridTest { const string projectIntegrationFilename = @"DAMLive.damx"; const string input1AFilename = @"live.InputTimeSeriesMHW.xml"; const string output1AFilename = @"live.OutputTimeSeriesMHW.xml"; const string calculationParametersIntegrationFilename = @"live.ParametersFile.xml"; const string testWorkingFolder = @".\damLiveUpliftVanGridWork"; private const string testIntegrationDataFolder = @"..\..\..\..\data\IntegerationTests\StabilityInsideUpliftVanGrid"; private List locations; private DamEngineRunner runner; [SetUp] public void SetupFixture() { IoHelper.RemoveTestWorkingDirectory(testWorkingFolder + GeneralHelper.CMinCores); // to be sure no test directory exist from previous tests IoHelper.RemoveTestWorkingDirectory(testWorkingFolder + GeneralHelper.CMaxCores); } [TearDown] public void TearDownFixture() { IoHelper.RemoveTestWorkingDirectory(testWorkingFolder + GeneralHelper.CMinCores); IoHelper.RemoveTestWorkingDirectory(testWorkingFolder + GeneralHelper.CMaxCores); } [SetUp] public void SetupTest() {} [Test] [Category("Integration")] [TestCase(GeneralHelper.CMinCores)] [TestCase(GeneralHelper.CMaxCores)] public void CalculateStabilityInsideUpliftVanGridUsingTestFilesHasExpectedResultsInOutputFile(int maxCores) { const double cTolerance = 0.0005; var generalHelper = new GeneralHelper(); string testFileName = "CalculateStabilityInsideUpliftVanGrid"+ maxCores; generalHelper.SetupIntegrationProject(maxCores, testWorkingFolder, testIntegrationDataFolder, input1AFilename, output1AFilename, testFileName, calculationParametersIntegrationFilename, projectIntegrationFilename, out runner, out locations); runner.Initialize(); runner.MaxCalculationCores = maxCores; Assert.That(runner, Is.Not.Null); Assert.That(runner.DamProjectData, Is.Not.Null); Assert.That(runner.CalculationParameters, Is.Not.Null); Assert.That(runner.CalculationParameters.CalculationModules, Is.Not.Null); Assert.That(runner.CalculationParameters.MStabParameters, Is.Not.Null); runner.Run(); runner.OutputTimeSeriesCollection.Save("UpliftVanOutputFile" + maxCores); generalHelper.AssertNoErrors(runner); // Assertions List series = runner.OutputTimeSeriesCollection.Series; var seriesCount = 0; var resultsCount = 0; string[] validParameterIDs = Enum.GetNames(typeof(TimeSerieParameters)); foreach (TimeSerie timeSeries in series) { Assert.That(validParameterIDs.Any(n => n == timeSeries.ParameterId), Is.True); Assert.That(locations.Any(l => l.Name == timeSeries.LocationId), Is.True); // StabilityInside check if (timeSeries.ParameterId == TimeSerieParameters.StabilityInsideFactor.ToString()) { if (timeSeries.LocationId == "Purmer_PU0042+00_K") { TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(1.456).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; TimeSerieEntry lastEntry = timeSeries.Entries.Last(); Assert.That(lastEntry.Value, Is.EqualTo(1.583).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; } if (timeSeries.LocationId == "Purmer_PU0042+00_K_V") { TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(1.366).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; TimeSerieEntry lastEntry = timeSeries.Entries.Last(); Assert.That(lastEntry.Value, Is.EqualTo(1.480).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; } if (timeSeries.LocationId == "Purmer_PU0042+00_R") { TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(1.248).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; TimeSerieEntry lastEntry = timeSeries.Entries.Last(); Assert.That(lastEntry.Value, Is.EqualTo(1.359).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; } if (timeSeries.LocationId == "Purmer_PU0042+00_R_V") { TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(1.172).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; TimeSerieEntry lastEntry = timeSeries.Entries.Last(); Assert.That(lastEntry.Value, Is.EqualTo(1.271).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; } if (timeSeries.LocationId == "Purmer_PU0110+20_K") { TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(Double.NaN).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; TimeSerieEntry lastEntry = timeSeries.Entries.Last(); Assert.That(lastEntry.Value, Is.EqualTo(Double.NaN).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; } if (timeSeries.LocationId == "Purmer_PU0110+20_K_V") { TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(Double.NaN).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; TimeSerieEntry lastEntry = timeSeries.Entries.Last(); Assert.That(lastEntry.Value, Is.EqualTo(Double.NaN).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; } if (timeSeries.LocationId == "Purmer_PU0110+20_R") { TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(Double.NaN).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; TimeSerieEntry lastEntry = timeSeries.Entries.Last(); Assert.That(lastEntry.Value, Is.EqualTo(Double.NaN).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; } if (timeSeries.LocationId == "Purmer_PU0110+20_R_V") { TimeSerieEntry firstEntry = timeSeries.Entries.First(); Assert.That(firstEntry.Value, Is.EqualTo(Double.NaN).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; TimeSerieEntry lastEntry = timeSeries.Entries.Last(); Assert.That(lastEntry.Value, Is.EqualTo(Double.NaN).Within(cTolerance), "The computed safety factory is not correct"); resultsCount++; } } seriesCount++; } Assert.That(seriesCount > 0, Is.True, "No output time series"); Assert.That(resultsCount, Is.EqualTo(16), "Incorrect number of results"); } }