// Copyright (C) Stichting Deltares 2018. 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.Collections.Generic;
using Deltares.DamEngine.Data.General;
using Deltares.DamEngine.Data.General.Results;
using Deltares.DamEngine.Data.Geometry;
using Deltares.DamEngine.Data.Geotechnics;
using Deltares.DamEngine.Data.Standard.Calculation;
using Deltares.DamEngine.Data.Standard.Logging;
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.General.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("location " + i, "Scenario " + (i * 2))
{
BaseFileName = "my basefilename " + i,
ProfileName = "profile" + i
};
result.CalculationResult = CalculationResult.RunFailed;
result.PipingDesignResults = new PipingDesignResults(PipingModelType.Bligh)
{
ResultMessage = "no run made",
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
};
var surfaceline = new SurfaceLine2();
surfaceline.Name = "Redesigned Surfaceline";
surfaceline.CharacteristicPoints.Geometry = surfaceline.Geometry;
var p1 = new CharacteristicPoint
{
CharacteristicPointType = CharacteristicPointType.SurfaceLevelOutside,
GeometryPoint = new GeometryPoint(),
X = 0,
Z = 0
};
surfaceline.CharacteristicPoints.Add(p1);
var p2 = new CharacteristicPoint
{
CharacteristicPointType = CharacteristicPointType.DikeToeAtRiver,
GeometryPoint = new GeometryPoint(),
X = 10,
Z = 0
};
surfaceline.CharacteristicPoints.Add(p2);
var p3 = new CharacteristicPoint
{
CharacteristicPointType = CharacteristicPointType.DikeTopAtRiver,
GeometryPoint = new GeometryPoint(),
X = 15,
Z = 2
};
surfaceline.CharacteristicPoints.Add(p3);
var p4 = new CharacteristicPoint
{
CharacteristicPointType = CharacteristicPointType.DikeTopAtPolder,
GeometryPoint = new GeometryPoint(),
X = 18,
Z = 2
};
surfaceline.CharacteristicPoints.Add(p4);
var p5 = new CharacteristicPoint
{
CharacteristicPointType = CharacteristicPointType.DikeToeAtPolder,
GeometryPoint = new GeometryPoint(),
X = 23,
Z = 0
};
surfaceline.CharacteristicPoints.Add(p5);
var p6 = new CharacteristicPoint
{
CharacteristicPointType = CharacteristicPointType.SurfaceLevelInside,
GeometryPoint = new GeometryPoint(),
X = 100,
Z = 0
};
surfaceline.CharacteristicPoints.Add(p6);
result.PipingDesignResults.RedesignedSurfaceLine = surfaceline;
result.PipingDesignResults.UpliftSituation = situation;
result.StabilityDesignResults = new StabilityDesignResults
{
ResultMessage = "no problemo",
SafetyFactor = (i + 1) * 0.66,
Zone1SafetyFactor = (i + 1) * 0.64,
LocalZone1EntryPointX = (i + 1) * 12.66,
LocalZone1ExitPointX = (i + 1) * 21.66,
Zone2SafetyFactor = (i + 2) * 0.64,
LocalZone2EntryPointX = (i + 2) * 12.66,
LocalZone2ExitPointX = (i + 2) * 21.66,
NumberOfIterations = (i + 1) * 3,
UpliftSituation = situation,
RedesignedSurfaceLine = surfaceline
};
damProjectData.DesignCalculations.Add(result);
}
damProjectData.CalculationMessages = new List();
damProjectData.CalculationMessages.Add(new LogMessage(LogMessageType.Error, null, "Error 1"));
damProjectData.CalculationMessages.Add(new LogMessage(LogMessageType.Error, null, "Error 2"));
damProjectData.CalculationMessages.Add(new LogMessage(LogMessageType.Warning, null, "Warning 1"));
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");
}
}
}