Index: dam engine/trunk/src/Deltares.DamEngine.Data/Properties/AssemblyInfo.cs =================================================================== diff -u -r452 -r469 --- dam engine/trunk/src/Deltares.DamEngine.Data/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 452) +++ dam engine/trunk/src/Deltares.DamEngine.Data/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 469) @@ -55,3 +55,6 @@ // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("17.1.0.0")] [assembly: AssemblyFileVersion("17.1.0.0")] + +[assembly: InternalsVisibleTo("Deltares.DamEngine.Interface")] +[assembly: InternalsVisibleTo("Deltares.DamEngine.Interface.Tests")] Index: dam engine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlOutput.cs =================================================================== diff -u --- dam engine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlOutput.cs (revision 0) +++ dam engine/trunk/src/Deltares.DamEngine.Interface/FillDamFromXmlOutput.cs (revision 469) @@ -0,0 +1,131 @@ +// Copyright (C) Stichting Deltares 2017. 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.Linq; +using System.Text; +using System.Threading.Tasks; +using Deltares.DamEngine.Data.General; +using Deltares.DamEngine.Io.XmlOutput; +using Location = Deltares.DamEngine.Data.General.Location; + +namespace Deltares.DamEngine.Interface +{ + /// + /// Class to fill the results in DamProjectData based on the output xml (for test purposes only) + /// + public class FillDamFromXmlOutput + { + /// + /// Creates the dam project data. + /// + /// The output. + /// + public static DamProjectData CreateDamProjectData(Output output) + { + var damProjectData = new DamProjectData(); + if (output != null && output.Results != null && output.Results.CalculationResults != null && output.Results.CalculationResults.DesignResults != null) + { + CreateDesignResultsOutput(output, damProjectData); + } + return damProjectData; + } + + private static void CreateDesignResultsOutput(Output output, DamProjectData damProjectData) + { + // Design results + damProjectData.DesignCalculations = new List(); + for (int i = 0; i < output.Results.CalculationResults.DesignResults.Length; i++) + { + var designResult = output.Results.CalculationResults.DesignResults[i]; + var desResult = new Data.General.Results.DesignResult(designResult.Id, designResult.Xrd, designResult.Yrd, designResult.LocationName, designResult.ScenarioName) + { + BaseFileName = designResult.BaseFileName, + ProfileName = designResult.ProfileName + }; + + if (designResult.SafetyFactorSpecified) desResult.SetSafetyFactor(designResult.SafetyFactor); + if (designResult.FailureProbabilitySpecified) desResult.FailureProbability = designResult.FailureProbability; + desResult.CalculationResult = ConversionHelper.ConvertToCalculationResult(designResult.CalculationResult); + + if (designResult.PipingDesignResults != null) + { + CreateDesignResultsPipingOutput(designResult, desResult); + } + damProjectData.DesignCalculations.Add(desResult); + } + } + + private static void CreateDesignResultsPipingOutput(DesignResult designResult, Data.General.Results.DesignResult desResult) + { + var model = PipingModelType.Bligh; + if (designResult.PipingDesignResults.Sellmeijer4ForcesFactorSpecified) + model = PipingModelType.Sellmeijer4Forces; + if (designResult.PipingDesignResults.SellmeijerVnkFactorSpecified) + model = PipingModelType.SellmeijerVnk; + if (designResult.PipingDesignResults.Wti2017FactorSpecified) + model = PipingModelType.Wti2017; + desResult.PipingDesignResults = new Data.General.Results.PipingDesignResults(model) + { + ResultMessage = designResult.PipingDesignResults.ResultMessage, + //RedesignedSurfaceLine2 = designResult.PipingDesignResults.RedesignedSurfaceLine + }; + if (designResult.PipingDesignResults.FailureProbabilitySpecified) desResult.PipingDesignResults.FailureProbability = designResult.PipingDesignResults.FailureProbability; + + if (designResult.PipingDesignResults.UpliftFactorSpecified) desResult.PipingDesignResults.UpliftFactor = designResult.PipingDesignResults.UpliftFactor; + + if (designResult.PipingDesignResults.HeaveFactorSpecified) desResult.PipingDesignResults.HeaveFactor = designResult.PipingDesignResults.HeaveFactor; + + if (designResult.PipingDesignResults.BlighFactorSpecified) desResult.PipingDesignResults.BlighFactor = designResult.PipingDesignResults.BlighFactor; + + if (designResult.PipingDesignResults.BlighHcriticalSpecified) desResult.PipingDesignResults.BlighHcritical = designResult.PipingDesignResults.BlighHcritical; + + if (designResult.PipingDesignResults.Sellmeijer4ForcesFactorSpecified) desResult.PipingDesignResults.Sellmeijer4ForcesFactor = designResult.PipingDesignResults.Sellmeijer4ForcesFactor; + + if (designResult.PipingDesignResults.Sellmeijer4ForcesHcriticalSpecified) desResult.PipingDesignResults.Sellmeijer4ForcesHcritical = designResult.PipingDesignResults.Sellmeijer4ForcesHcritical; + + if (designResult.PipingDesignResults.SellmeijerVnkFactorSpecified) desResult.PipingDesignResults.SellmeijerVnkFactor = designResult.PipingDesignResults.SellmeijerVnkFactor; + + if (designResult.PipingDesignResults.SellmeijerVnkHcriticalSpecified) desResult.PipingDesignResults.SellmeijerVnkHcritical = designResult.PipingDesignResults.SellmeijerVnkHcritical; + + if (designResult.PipingDesignResults.Wti2017FactorSpecified) desResult.PipingDesignResults.Wti2017Factor = designResult.PipingDesignResults.Wti2017Factor; + + if (designResult.PipingDesignResults.Wti2017HcriticalSpecified) desResult.PipingDesignResults.Wti2017Hcritical = designResult.PipingDesignResults.Wti2017Hcritical; + + if (designResult.PipingDesignResults.LocalExitPointXSpecified) desResult.PipingDesignResults.LocalExitPointX = designResult.PipingDesignResults.LocalExitPointX; + + if (designResult.PipingDesignResults.UpliftSituation != null) + { + var uplift = designResult.PipingDesignResults.UpliftSituation; + var situation = new Data.Design.UpliftSituation(); + situation.IsUplift = uplift.IsUplift; + situation.Pl3MinUplift = uplift.Pl3MinUplift; + situation.Pl3HeadAdjusted = uplift.Pl3HeadAdjusted; + situation.Pl3LocationXMinUplift = uplift.Pl3LocalLocationXMinUplift; + situation.Pl4MinUplift = uplift.Pl4MinUplift; + situation.Pl4HeadAdjusted = uplift.Pl4HeadAdjusted; + situation.Pl4LocationXMinUplift = uplift.Pl4LocalLocationXMinUplift; + desResult.PipingDesignResults.UpliftSituation = situation; + } + } + } +} Index: dam engine/trunk/src/Deltares.DamEngine.Data/General/Results/DesignResult.cs =================================================================== diff -u -r460 -r469 --- dam engine/trunk/src/Deltares.DamEngine.Data/General/Results/DesignResult.cs (.../DesignResult.cs) (revision 460) +++ dam engine/trunk/src/Deltares.DamEngine.Data/General/Results/DesignResult.cs (.../DesignResult.cs) (revision 469) @@ -82,22 +82,27 @@ get { double? maxDikeLength = null; - List dikeLengths = new List(); - SurfaceLine2 surfaceLine = Scenario.Location.SurfaceLine2; - if (surfaceLine != null) - dikeLengths.Add(surfaceLine.GetDikeLength()); - switch (DamFailureMechanismeCalculation.FailureMechanismSystemType) + var dikeLengths = new List(); + if (Scenario != null && Scenario.Location != null) { - case FailureMechanismSystemType.StabilityInside: - if (stabilityDesignResults.RedesignedSurfaceLine != null) - dikeLengths.Add(stabilityDesignResults.RedesignedSurfaceLine.GetDikeLength()); - break; - case FailureMechanismSystemType.Piping: - if (pipingDesignResults.RedesignedSurfaceLine != null) - dikeLengths.Add(pipingDesignResults.RedesignedSurfaceLine.GetDikeLength()); - break; + SurfaceLine2 surfaceLine = Scenario.Location.SurfaceLine2; + if (surfaceLine != null) + dikeLengths.Add(surfaceLine.GetDikeLength()); } - + if (DamFailureMechanismeCalculation != null) + { + switch (DamFailureMechanismeCalculation.FailureMechanismSystemType) + { + case FailureMechanismSystemType.StabilityInside: + if (stabilityDesignResults != null && stabilityDesignResults.RedesignedSurfaceLine != null) + dikeLengths.Add(stabilityDesignResults.RedesignedSurfaceLine.GetDikeLength()); + break; + case FailureMechanismSystemType.Piping: + if (pipingDesignResults != null && pipingDesignResults.RedesignedSurfaceLine != null) + dikeLengths.Add(pipingDesignResults.RedesignedSurfaceLine.GetDikeLength()); + break; + } + } foreach (double? dikeLength in dikeLengths) { if (dikeLength.HasValue && (!maxDikeLength.HasValue || maxDikeLength < dikeLength)) @@ -111,11 +116,20 @@ /// Initializes a new instance of the class. /// Is only to be used by this.Clone() and in FillDamFromXmlOutput (used in tests), nowhere else /// - public DesignResult() + internal DesignResult() { // only for Clone() method } + internal DesignResult(string id, double xRd, double yRd, string locationName, string scenarioName) + { + this.id = id; + xrd = xRd; + yrd = yRd; + this.locationName = locationName; + this.scenarioName = scenarioName; + } + /// /// Initializes a new instance of the class. /// @@ -166,14 +180,15 @@ LocalZone1ExitPointX = scenario.NwoResults[nwoResultIndex].MStabResults.zone1.exitPointXCoordinate, ResultIndex = nwoResultIndex }; - + if (scenario.NwoResults[nwoResultIndex].MStabResults.zone2 != null) { nwoDesignResults.Zone2SafetyFactor = scenario.NwoResults[nwoResultIndex].MStabResults.zone2.Value.safetyFactor; nwoDesignResults.LocalZone2EntryPointX = scenario.NwoResults[nwoResultIndex].MStabResults.zone2.Value.entryPointXCoordinate; nwoDesignResults.LocalZone2ExitPointX = scenario.NwoResults[nwoResultIndex].MStabResults.zone2.Value.exitPointXCoordinate; } baseFileName = scenario.NwoResults[nwoResultIndex].MStabResults.CalculationName; + safetyFactor = nwoDesignResults.SafetyFactor; } } else @@ -201,6 +216,7 @@ } stabilityDesignResults.FailureProbability = scenario.GetFailureProbabilityStability(soilProfile, soilGeometry2DName); failureProbability = stabilityDesignResults.FailureProbability; + safetyFactor = stabilityDesignResults.SafetyFactor; stabilityDesignResults.RedesignedSurfaceLine = scenario.GetRedesignedSurfaceLine(soilProfile, soilGeometry2DName); UpliftSituation? upliftSituation = scenario.GetStabilityUpliftSituation(soilProfile, soilGeometry2DName); @@ -238,6 +254,7 @@ pipingDesignResults.HeaveFactor = pipingResults.Value.HeaveFactor; pipingDesignResults.UpliftFactor = pipingResults.Value.UpliftFactor; } + safetyFactor = pipingDesignResults.SafetyFactor(); calculationResult = (pipingDesignResults.SafetyFactor() == null && pipingDesignResults.FailureProbability == null) ? CalculationResult.RunFailed : CalculationResult.Succeeded; break; } @@ -365,12 +382,13 @@ { return safetyFactor; } - set - { - safetyFactor = value; - } } + internal void SetSafetyFactor(double value) + { + safetyFactor = value; + } + /// /// Gets or sets the failure probability (derived result). /// Index: dam engine/trunk/src/Deltares.DamEngine.Interface/Deltares.DamEngine.Interface.csproj =================================================================== diff -u -r452 -r469 --- dam engine/trunk/src/Deltares.DamEngine.Interface/Deltares.DamEngine.Interface.csproj (.../Deltares.DamEngine.Interface.csproj) (revision 452) +++ dam engine/trunk/src/Deltares.DamEngine.Interface/Deltares.DamEngine.Interface.csproj (.../Deltares.DamEngine.Interface.csproj) (revision 469) @@ -58,6 +58,7 @@ + Index: dam engine/trunk/src/Deltares.DamEngine.Data/General/DamProjectData.cs =================================================================== diff -u -r452 -r469 --- dam engine/trunk/src/Deltares.DamEngine.Data/General/DamProjectData.cs (.../DamProjectData.cs) (revision 452) +++ dam engine/trunk/src/Deltares.DamEngine.Data/General/DamProjectData.cs (.../DamProjectData.cs) (revision 469) @@ -20,9 +20,7 @@ // All rights reserved. using System; -using System.Collections; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using Deltares.DamEngine.Data.Design; using Deltares.DamEngine.Data.General.Results; @@ -271,6 +269,10 @@ return designCalculations; } + set + { + designCalculations = value; + } } public List SchematizationFactors Index: dam engine/trunk/src/Deltares.DamEngine.Interface.Tests/FillXmlOutputFromDamTests.cs =================================================================== diff -u -r452 -r469 --- dam engine/trunk/src/Deltares.DamEngine.Interface.Tests/FillXmlOutputFromDamTests.cs (.../FillXmlOutputFromDamTests.cs) (revision 452) +++ dam engine/trunk/src/Deltares.DamEngine.Interface.Tests/FillXmlOutputFromDamTests.cs (.../FillXmlOutputFromDamTests.cs) (revision 469) @@ -19,16 +19,93 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. -using System; using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; +using Deltares.DamEngine.Data.General; +using Deltares.DamEngine.Data.General.Results; +using Deltares.DamEngine.Data.Standard.Calculation; +using Deltares.DamEngine.Io; +using Deltares.DamEngine.Io.XmlOutput; +using KellermanSoftware.CompareNetObjects; using NUnit.Framework; +using DesignResult = Deltares.DamEngine.Data.General.Results.DesignResult; +using UpliftSituation = Deltares.DamEngine.Data.Design.UpliftSituation; namespace Deltares.DamEngine.Interface.Tests { [TestFixture] public class FillXmlOutputFromDamTests { + [Test] + public void CanWriteAndReadDamProjectDataToXml() + { + const string outputFilename = "OutputFile.xml"; + DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); + Output output = FillXmlOutputFromDam.CreateOutput(expectedDamProjectData); + DamXmlSerialization.SaveOutputAsXmlFile(outputFilename, output); + output = DamXmlSerialization.LoadOutputFromXmlFile(outputFilename); + DamProjectData actualDamProjectData = FillDamFromXmlOutput.CreateDamProjectData(output); + CompareDamProjectData(actualDamProjectData, expectedDamProjectData); + } + + [Test] + public void CanWriteAndReadDamProjectDataToXmlString() + { + DamProjectData expectedDamProjectData = CreateExampleDamProjectData(); + Output output = FillXmlOutputFromDam.CreateOutput(expectedDamProjectData); + var xmlString = DamXmlSerialization.SaveOutputAsXmlString(output); + output = DamXmlSerialization.LoadOutputFromXmlString(xmlString); + DamProjectData actualDamProjectData = FillDamFromXmlOutput.CreateDamProjectData(output); + CompareDamProjectData(actualDamProjectData, expectedDamProjectData); + } + + private DamProjectData CreateExampleDamProjectData() + { + const int resultsCount = 3; + var damProjectData = new DamProjectData + { + DesignCalculations = new List() + }; + for (int i = 0; i < resultsCount; i++) + { + var result = new DesignResult("res " + i, i * 2.2, i * 3.3, "location " + i, "Scenario " + (i * 2)) + { + BaseFileName = "my basefilename " + i, + ProfileName = "profile" + i + }; + result.SetSafetyFactor(0.67 * i); + result.FailureProbability = 0.004 * i; + result.CalculationResult = CalculationResult.RunFailed; + result.PipingDesignResults = new PipingDesignResults(PipingModelType.Bligh) + { + ResultMessage = "no run made", + FailureProbability = 2, + UpliftFactor = 1.3 * i, + HeaveFactor = 1.1 * i, + BlighFactor = 1.03 * i, + BlighHcritical = 0.4, + LocalExitPointX = 34.21 + }; + var situation = new UpliftSituation + { + IsUplift = true, + Pl3MinUplift = 0.1, + Pl3HeadAdjusted = 0.2, + Pl3LocationXMinUplift = 0.3, + Pl4MinUplift = 0.1 * i, + Pl4HeadAdjusted = 0.2 * i, + Pl4LocationXMinUplift = 0.3 * i + }; + result.PipingDesignResults.UpliftSituation = situation; + damProjectData.DesignCalculations.Add(result); + } + return damProjectData; + } + + private void CompareDamProjectData(DamProjectData actual, DamProjectData expected) + { + var compare = new CompareLogic { Config = { MaxDifferences = 100 } }; + var result = compare.Compare(expected, actual); + Assert.AreEqual(0, result.Differences.Count, "Differences found read/write Input object"); + } } }