Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/WTIDeserializer.cs
===================================================================
diff -u
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/WTIDeserializer.cs (revision 0)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/WTIDeserializer.cs (revision 1972)
@@ -0,0 +1,1161 @@
+// Copyright (C) Stichting Deltares 2019. 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.Globalization;
+using System.IO;
+using System.Reflection;
+using System.Xml;
+using System.Xml.Schema;
+using Deltares.MacroStability.Data;
+using Deltares.MacroStability.Geometry;
+using Deltares.MacroStability.Kernel;
+using Deltares.MacroStability.Preprocessing;
+using Deltares.MacroStability.Standard;
+using Deltares.MacroStability.WaternetCreator;
+using Deltares.SearchAlgorithms;
+using Deltares.SoilStress.Data;
+using Deltares.WTIStability.Data;
+
+namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo
+{
+ ///
+ /// WTI xml format deserializer class
+ ///
+ public class WtiDeserializer
+ {
+ ///
+ /// Deserializes the specified XML.
+ ///
+ /// The XML.
+ /// The stability model.
+ public static KernelModel Deserialize(string xml)
+ {
+ XmlDocument document = new XmlDocument();
+ document.LoadXml(xml);
+ document.Schemas.Add(GetSchema("Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo.WtiVersionInfo.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo.WTIGeometry.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo.WTIWaternetDefinition.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo.WTIWaternet.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo.WTISoilModel.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo.WTIStabilityModel.xsd", true));
+
+ // the following call to Validate succeeds.
+ document.Validate(ValidationEventHandler);
+
+ // if survived here, the xml is all right
+ string name = "WTIStabilityModel";
+
+ KernelModel kernelModel = new KernelModel();
+
+ ReadStabilityModel(GetElement(document, name), kernelModel, new Dictionary());
+
+ return kernelModel;
+ }
+
+ ///
+ /// Deserializes the result.
+ ///
+ /// The XML.
+ /// The deserialized calculation results.
+ public static StabilityAssessmentCalculationResult DeserializeResult(string xml)
+ {
+ XmlDocument document = new XmlDocument();
+ document.LoadXml(xml);
+
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIWaternetDefinition.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIWaternet.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIStabilityModelResult.xsd", true));
+
+ // the following call to Validate succeeds.
+ document.Validate(ValidationEventHandler);
+
+ // if survived here, the xml is all right
+ string name = "WTIStabilityModelResult";
+
+ StabilityAssessmentCalculationResult result = new StabilityAssessmentCalculationResult();
+
+ ReadStabilityModelResult(GetElement(document, name), result);
+
+ return result;
+ }
+
+ ///
+ /// Deserializes the results of a calculation from the xml string.
+ ///
+ /// The XML.
+ /// The results of the calculation
+ public static ValidationResult[] DeserializeValidation(string xml)
+ {
+ XmlDocument document = new XmlDocument();
+ document.LoadXml(xml);
+
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIStabilityModelValidation.xsd", false));
+
+ // xsd validation
+ document.Validate(ValidationEventHandler);
+
+ string name = "WTIStabilityModelValidation";
+
+ var result = new List();
+
+ ReadValidationResult(GetElement(document, name), result);
+
+ return result.ToArray();
+ }
+
+ ///
+ /// Deserializes a waternet.
+ ///
+ /// The waternet in XML format.
+ /// if set to true [get waternet daily].
+ ///
+ /// The waternet.
+ ///
+ public static Waternet DeserializeWaternetUsedDuringCalculation(string xml, bool getDaily)
+ {
+ var document = new XmlDocument();
+ document.LoadXml(xml);
+
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIWaternet.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIWaternetUsedDuringCalculation.xsd", false));
+
+ // the following call to Validate succeeds.
+ document.Validate(ValidationEventHandler);
+
+ // if survived here, the xml is all right
+ const string name = "WTIWaternetUsedDuringCalculation";
+
+ var waternet = new Waternet();
+ var location = new Location();
+ if (getDaily)
+ {
+ waternet.Name = "WaternetDaily";
+ }
+ ReadWaternets(GetElement(GetElement(document, name), "Waternets"), ref waternet, location, getDaily,
+ new Dictionary());
+
+ return waternet;
+ }
+
+ ///
+ /// Deserializes the validation messages displayed during the creation of the waternet.
+ ///
+ /// The waternet with validation messages in XML format.
+ /// The validation messages.
+ public static List DeserializeValidationMessagesForWaternet(string xml)
+ {
+ XmlDocument document = new XmlDocument();
+ document.LoadXml(xml);
+
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIWaternet.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIWaternetUsedDuringCalculation.xsd", false));
+
+ // the following call to Validate succeeds.
+ document.Validate(ValidationEventHandler);
+
+ // if survived here, the xml is all right
+ string name = "WTIWaternetUsedDuringCalculation";
+ var validationMessages = new List();
+
+ ReadValidationResult(GetElement(document, name), validationMessages);
+
+ return validationMessages;
+ }
+
+ private static XmlSchema GetSchema(string path, bool validate)
+ {
+ Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path);
+ if (stream != null)
+ {
+ if (validate)
+ {
+ return XmlSchema.Read(stream, ValidationEventHandler);
+ }
+ else
+ {
+ return XmlSchema.Read(stream, null);
+ }
+ }
+ return null;
+ }
+
+ private static void ValidationEventHandler(object sender, ValidationEventArgs e)
+ {
+ throw new XmlSchemaValidationException(e.Message);
+ }
+
+ private static XmlElement GetElement(XmlNode parent, string name)
+ {
+ foreach (var xmlNode in parent.ChildNodes)
+ {
+ XmlElement element = xmlNode as XmlElement;
+ if (element != null)
+ {
+ if (element.Name == name)
+ {
+ return element;
+ }
+
+ }
+ }
+
+ return null;
+ }
+
+ private static IEnumerable GetElements(XmlElement parent, string name)
+ {
+ List elements = new List();
+ foreach (XmlElement element in parent.ChildNodes)
+ {
+ if (element.Name == name)
+ {
+ elements.Add(element);
+ }
+ }
+
+ return elements;
+ }
+
+ private static void ReadStabilityModel(XmlElement element, KernelModel kernelModel, Dictionary keys)
+ {
+ StabilityModel model = kernelModel.StabilityModel;
+ PreprocessingModel automationModel = kernelModel.PreprocessingModel;
+
+ if (element.GetAttribute("SearchAlgorithm") == "GeneticAndLevenbergMarquardt")
+ {
+ model.SearchAlgorithm = SearchAlgorithm.Genetic;
+ model.FinalizeWithLevenbergMarquardt = true;
+ }
+ else
+ {
+ model.SearchAlgorithm = (SearchAlgorithm)Enum.Parse(typeof(SearchAlgorithm), element.GetAttribute("SearchAlgorithm"));
+ model.FinalizeWithLevenbergMarquardt = false;
+ }
+ model.ModelOption = (ModelOptions)Enum.Parse(typeof(ModelOptions), element.GetAttribute("ModelOption"));
+
+ if (model.SearchAlgorithm == SearchAlgorithm.Grid && model.ModelOption == ModelOptions.Spencer)
+ {
+ model.SearchAlgorithm = SearchAlgorithm.Genetic;
+ }
+
+ model.GridOrientation = (GridOrientation)Enum.Parse(typeof(GridOrientation), element.GetAttribute("Orientation"));
+ model.FileVersionAsRead = ReadVersionInfo(GetElement(element, "VersionInfo"));
+
+ List soilStresses = model.LastStage.SoilStresses;
+
+ ReadSoilModel(GetElement(element, "SoilModel"), model.SoilModel, soilStresses, keys);
+ ReadSoilProfile(GetElement(element, "SoilProfile"), model.SoilProfile, keys);
+ ReadSurfaceLine(GetElement(element, "SurfaceLine"), automationModel.LastStage.SurfaceLine, keys);
+
+ Location loc = new Location();
+ ReadLocation(GetElement(element, "Location"), ref loc);
+ automationModel.LastStage.Locations.Add(loc);
+
+ if (GetElement(element, "LocationDaily") != null)
+ {
+ PreprocessingConstructionStage preDailyStage = new PreprocessingConstructionStage();
+ automationModel.ConstructionStages.Insert(0, preDailyStage);
+
+ ConstructionStage dailyStage = new ConstructionStage();
+ model.ConstructionStages.Insert(0, dailyStage);
+
+ Location locDaily = new Location();
+ ReadLocation(GetElement(element, "LocationDaily"), ref locDaily);
+ preDailyStage.Locations.Add(locDaily);
+ }
+
+ var currentWaternet = model.GeotechnicsData.CurrentWaternet;
+ ReadWaternets(GetElement(element, "Waternets"), ref currentWaternet, automationModel.LastStage.Locations[0], false, keys);
+ model.GeotechnicsData.CurrentWaternet = currentWaternet;
+ loc.Waternet = currentWaternet;
+ loc.Surfaceline = automationModel.LastStage.SurfaceLine;
+
+ if (automationModel.ConstructionStages.Count == 2) // daily waternet available
+ {
+ ConstructionStage dailyStage = model.ConstructionStages[0];
+
+ var currentWaternetDaily = dailyStage.GeotechnicsData.CurrentWaternet;
+ ReadWaternets(GetElement(element, "Waternets"), ref currentWaternetDaily, automationModel.ConstructionStages[0].Locations[0], true, keys);
+ currentWaternetDaily.Name = "WaternetDaily";
+ model.ConstructionStages[0].GeotechnicsData.CurrentWaternet = currentWaternetDaily;
+ automationModel.ConstructionStages[0].Locations[0].Waternet = currentWaternetDaily;
+
+ automationModel.ConstructionStages[0].SurfaceLine = automationModel.LastStage.SurfaceLine; // copy ref surface line
+ automationModel.ConstructionStages[0].Locations[0].Surfaceline = automationModel.LastStage.SurfaceLine;
+ }
+
+ Dictionary isTemporary = new Dictionary();
+ ReadUniformLoads(GetElement(element, "UniformLoads"), model.LastStage.UniformLoads, model.LastStage.InvalidUniformLoads, keys, isTemporary);
+ ReadPreconsolidationStresses(GetElement(element, "PreconsolidationStresses"), model, keys);
+ ReadConsolidationValues(GetElement(element, "ConsolidationValues"), model, keys, isTemporary);
+ ReadMultiplicationFactorsCPhiForUplift(GetElement(element, "MultiplicationFactorsCPhiForUplift"), model.LastStage.MultiplicationFactorsCPhiForUpliftList);
+ ReadSpencerSlipPlanes(GetElement(element, "SpencerSlipPlanes"), model, automationModel, keys);
+ ReadUpliftVanCalculationGrid(GetElement(element, "UpliftVanCalculationGrid"), model, kernelModel.PreprocessingModel);
+ ReadSlipPlaneConstraints(GetElement(element, "SlipPlaneConstraints"), model, kernelModel.PreprocessingModel);
+ ReadGeneticAlgorithmOptions(GetElement(element, "GeneticAlgorithmOptions"), model.GeneticAlgorithmOptions);
+ ReadLevenbergMarquardtOptions(GetElement(element, "LevenbergMarquardtOptions"), model.LevenbergMarquardtOptions);
+
+ model.MoveGrid = Boolean.Parse(element.GetAttribute("MoveGrid"));
+ model.SlipCircle.SlipCircleTangentLine.MoveTangentLines = model.MoveGrid;
+ model.MaximumSliceWidth = Double.Parse(element.GetAttribute("MaximumSliceWidth"), CultureInfo.InvariantCulture);
+
+ // Clone data if daily stage is added
+ if (model.ConstructionStages.Count > 1)
+ {
+ ConstructionStage dailyStage = model.ConstructionStages[0];
+ dailyStage.SoilProfile = kernelModel.StabilityModel.LastStage.SoilProfile;
+
+ // only use preconsolidation stresses in the daily stage
+ dailyStage.PreconsolidationStresses.AddRange(kernelModel.StabilityModel.LastStage.PreconsolidationStresses);
+ kernelModel.StabilityModel.LastStage.PreconsolidationStresses.Clear(); // stress points only applicable to daily stage
+
+ dailyStage.SoilStresses.AddRange(soilStresses);
+ kernelModel.StabilityModel.LastStage.SoilStresses.Clear();
+
+ dailyStage.UniformLoads.AddRange(kernelModel.StabilityModel.LastStage.UniformLoads);
+ dailyStage.ConsolidationMatrix = kernelModel.StabilityModel.LastStage.ConsolidationMatrix;
+
+ PreprocessingConstructionStage preDailyStage = automationModel.ConstructionStages[0];
+ preDailyStage.SurfaceLine = automationModel.LastStage.SurfaceLine;
+ }
+ }
+
+ private static int ReadVersionInfo(XmlElement element)
+ {
+ var fileVersion = 0;
+ if (element != null)
+ {
+ fileVersion = int.Parse(element.GetAttribute("FileVersion"), CultureInfo.InvariantCulture);
+ }
+ return fileVersion;
+ }
+
+ private static void ReadLevenbergMarquardtOptions(XmlElement element, LevenbergMarquardtOptions options)
+ {
+ options.IterationCount = Int32.Parse(element.GetAttribute("IterationCount"), CultureInfo.InvariantCulture);
+ options.Shift = Double.Parse(element.GetAttribute("Shift"), CultureInfo.InvariantCulture);
+ options.DriftGrant = Double.Parse(element.GetAttribute("DriftGrant"), CultureInfo.InvariantCulture);
+ options.ParameterCount = Int32.Parse(element.GetAttribute("ParameterCount"), CultureInfo.InvariantCulture);
+ options.VariableCount = Int32.Parse(element.GetAttribute("VariableCount"), CultureInfo.InvariantCulture);
+ }
+
+ private static void ReadGeneticAlgorithmOptions(XmlElement element, GeneticAlgorithmOptions options)
+ {
+ options.EliteCount = Int32.Parse(element.GetAttribute("EliteCount"), CultureInfo.InvariantCulture);
+ options.PopulationCount = Int32.Parse(element.GetAttribute("PopulationCount"), CultureInfo.InvariantCulture);
+ options.GenerationCount = Int32.Parse(element.GetAttribute("GenerationCount"), CultureInfo.InvariantCulture);
+ options.MutationRate = Double.Parse(element.GetAttribute("MutationRate"), CultureInfo.InvariantCulture);
+ options.CrossOverScatterFraction = Double.Parse(element.GetAttribute("CrossOverScatterFraction"), CultureInfo.InvariantCulture);
+ options.CrossOverSinglePointFraction = Double.Parse(element.GetAttribute("CrossOverSinglePointFraction"), CultureInfo.InvariantCulture);
+ options.CrossOverDoublePointFraction = Double.Parse(element.GetAttribute("CrossOverDoublePointFraction"), CultureInfo.InvariantCulture);
+ options.MutationJumpFraction = Double.Parse(element.GetAttribute("MutationJumpFraction"), CultureInfo.InvariantCulture);
+ options.MutationCreepFraction = Double.Parse(element.GetAttribute("MutationCreepFraction"), CultureInfo.InvariantCulture);
+ options.MutationInverseFraction = Double.Parse(element.GetAttribute("MutationInverseFraction"), CultureInfo.InvariantCulture);
+ options.MutationCreepReduction = Double.Parse(element.GetAttribute("MutationCreepReduction"), CultureInfo.InvariantCulture);
+ options.Seed = Int32.Parse(element.GetAttribute("Seed"), CultureInfo.InvariantCulture);
+ }
+
+ private static void ReadSlipPlaneConstraints(XmlElement element, StabilityModel model, PreprocessingModel preprocessing)
+ {
+ SlipPlaneConstraints constraints = model.SlipPlaneConstraints;
+
+ constraints.SlipPlaneMinDepth = Double.Parse(element.GetAttribute("SlipPlaneMinDepth"), CultureInfo.InvariantCulture);
+ constraints.SlipPlaneMinLength = Double.Parse(element.GetAttribute("SlipPlaneMinLength"), CultureInfo.InvariantCulture);
+ preprocessing.SearchAreaConditions.AutomaticForbiddenZones = Boolean.Parse(element.GetAttribute("AutomaticForbiddenZones")) && Boolean.Parse(element.GetAttribute("CreateZones"));
+ constraints.XLeftMin = Double.Parse(element.GetAttribute("XEntryMin"), CultureInfo.InvariantCulture);
+ constraints.XLeftMax = Double.Parse(element.GetAttribute("XEntryMax"), CultureInfo.InvariantCulture);
+ model.MaxAllowedAngleBetweenSlices = Double.Parse(element.GetAttribute("MaxAllowedAngleBetweenSlices"), CultureInfo.InvariantCulture);
+ model.RequiredForcePointsInSlices = Double.Parse(element.GetAttribute("RequiredForcePointsInSlices"), CultureInfo.InvariantCulture);
+ }
+
+ private static void ReadForbiddenZones(XmlElement element, StabilityAssessmentCalculationResult result)
+ {
+ result.AreForbiddenZonesAuto = Boolean.Parse(element.GetAttribute("AutomaticallyCalculated"));
+ result.XMinEntry = Double.Parse(element.GetAttribute("XEntryMin"), CultureInfo.InvariantCulture);
+ result.XMaxEntry = Double.Parse(element.GetAttribute("XEntryMax"), CultureInfo.InvariantCulture);
+ }
+
+ private static void ReadUpliftVanCalculationGrid(XmlElement element, StabilityModel model, PreprocessingModel preprocessing)
+ {
+ SlipPlaneUpliftVan slipPlane = model.SlipPlaneUpliftVan;
+
+ ReadCalculationGrid(GetElement(element, "LeftGrid"), slipPlane.SlipPlaneLeftGrid);
+ ReadCalculationGrid(GetElement(element, "RightGrid"), slipPlane.SlipPlaneRightGrid);
+
+ XmlElement tangentElement = GetElement(element, "TangentLines");
+
+ slipPlane.SlipCircleTangentLine.TangentLineZTop = Double.Parse(tangentElement.GetAttribute("TangentLineZTop"), CultureInfo.InvariantCulture);
+ slipPlane.SlipCircleTangentLine.TangentLineZBottom = Double.Parse(tangentElement.GetAttribute("TangentLineZBottom"), CultureInfo.InvariantCulture);
+ slipPlane.SlipCircleTangentLine.TangentLineNumber = Int32.Parse(tangentElement.GetAttribute("TangentLineNumber"), CultureInfo.InvariantCulture);
+ slipPlane.SlipCircleTangentLine.SearchValuesType = Boolean.Parse(tangentElement.GetAttribute("AutomaticAtBoundaries")) ? SearchValuesType.Enumerated : SearchValuesType.Interval;
+
+ if (model.ModelOption == ModelOptions.Bishop)
+ {
+ preprocessing.SearchAreaConditions.AutoSearchArea = Boolean.Parse(element.GetAttribute("Auto"));
+ preprocessing.SearchAreaConditions.AutoTangentLines = Boolean.Parse(tangentElement.GetAttribute("AutomaticAtBoundaries"));
+ }
+ else if (model.ModelOption == ModelOptions.UpliftVan)
+ {
+ preprocessing.SearchAreaConditions.AutoSearchArea = Boolean.Parse(element.GetAttribute("Auto"));
+ preprocessing.SearchAreaConditions.AutoTangentLines = preprocessing.SearchAreaConditions.AutoSearchArea || Boolean.Parse(tangentElement.GetAttribute("AutomaticAtBoundaries"));
+ }
+ }
+
+ private static void ReadUsedUpliftVanCalculationGrid(XmlElement element, StabilityAssessmentCalculationResult result)
+ {
+ result.IsGridAuto = Boolean.Parse(element.GetAttribute("AutomaticallyCalculated"));
+ ReadCalculationGrid(GetElement(element, "LeftGrid"), result.SlipPlaneUpliftVan.SlipPlaneLeftGrid);
+ ReadCalculationGrid(GetElement(element, "RightGrid"), result.SlipPlaneUpliftVan.SlipPlaneRightGrid);
+
+ XmlElement tangentElement = GetElement(element, "TangentLines");
+ foreach (XmlElement tangentLineElement in GetElements(tangentElement, "TangentLine"))
+ {
+ TangentLine tangentLine = new TangentLine
+ {
+ Height = Double.Parse(tangentLineElement.GetAttribute("Level"), CultureInfo.InvariantCulture)
+ };
+ result.SlipPlaneUpliftVan.SlipPlaneTangentLine.BoundaryHeights.Add(tangentLine);
+ }
+ }
+
+ private static void ReadCalculationGrid(XmlElement element, SlipCircleGrid grid)
+ {
+ grid.GridXLeft = Double.Parse(element.GetAttribute("GridXLeft"), CultureInfo.InvariantCulture);
+ grid.GridXRight = Double.Parse(element.GetAttribute("GridXRight"), CultureInfo.InvariantCulture);
+ grid.GridZTop = Double.Parse(element.GetAttribute("GridZTop"), CultureInfo.InvariantCulture);
+ grid.GridZBottom = Double.Parse(element.GetAttribute("GridZBottom"), CultureInfo.InvariantCulture);
+ grid.GridXNumber = Int32.Parse(element.GetAttribute("GridXNumber"), CultureInfo.InvariantCulture);
+ grid.GridZNumber = Int32.Parse(element.GetAttribute("GridZNumber"), CultureInfo.InvariantCulture);
+ }
+
+ private static void ReadSpencerSlipPlanes(XmlElement element, StabilityModel model, PreprocessingModel preprocessing, Dictionary keys)
+ {
+ model.SlipPlanes.Clear();
+
+ XmlElement upperElement = GetElement(element, "UpperSlipPlane");
+ foreach (XmlElement pointElement in GetElements(upperElement, "Point"))
+ {
+ if (model.SlipPlanes.Count < 1)
+ {
+ model.SlipPlanes.Add(new SlipPlane());
+ }
+
+ model.SlipPlanes[0].Points.Add(ReadPoint(pointElement, keys, model.SlipPlanes[0]));
+ model.SlipPlanes[0].SyncCalcPoints();
+ }
+
+ XmlElement lowerElement = GetElement(element, "LowerSlipPlane");
+ foreach (XmlElement pointElement in GetElements(lowerElement, "Point"))
+ {
+ if (model.SlipPlanes.Count < 2)
+ {
+ model.SlipPlanes.Add(new SlipPlane());
+ }
+
+ model.SlipPlanes[1].Points.Add(ReadPoint(pointElement, keys, model.SlipPlanes[1]));
+ model.SlipPlanes[1].SyncCalcPoints();
+ }
+
+ if (model.ModelOption == ModelOptions.Spencer)
+ {
+ preprocessing.SearchAreaConditions.AutoSearchArea = Boolean.Parse(element.GetAttribute("Auto"));
+ }
+ preprocessing.SearchAreaConditions.SlipPlanePosition = (SlipPlanePosition)Enum.Parse(typeof(SlipPlanePosition), element.GetAttribute("SlipPlanePosition"));
+ }
+
+ private static void ReadWaternets(XmlElement element, ref Waternet currentWaternet, Location location, bool getDaily, Dictionary keys)
+ {
+ foreach (XmlElement waternet in GetElements(element, "Waternet"))
+ {
+ var isDaily = Boolean.Parse(waternet.GetAttribute("IsDaily"));
+ if (isDaily == getDaily)
+ {
+ ReadWaternet(waternet, ref currentWaternet, location, keys);
+ }
+ }
+ }
+
+ private static void ReadWaternet(XmlElement element, ref Waternet waternet, Location location, Dictionary keys)
+ {
+ // if the location is null (daily can be), do NOT read the waternet (Daily)
+ if (element != null && location != null)
+ {
+ // if the waternet (daily) is not yet there, create it here.
+ if (waternet == null)
+ {
+ waternet = new Waternet
+ {
+ Name = "WaternetDaily"
+ };
+ }
+
+ if (waternet.PhreaticLine == null)
+ {
+ waternet.PhreaticLine = new PhreaticLine();
+ }
+
+ ReadWaternetLine(GetElement(element, "PhreaticLine"), waternet.PhreaticLine, keys);
+
+ foreach (XmlElement headLineElement in GetElements(GetElement(element, "HeadLines"), "HeadLine"))
+ {
+ HeadLine headLine = new HeadLine();
+ ReadWaternetLine(headLineElement, headLine, keys);
+ waternet.HeadLineList.Add(headLine);
+ }
+
+ foreach (
+ XmlElement waternetLineElement in GetElements(GetElement(element, "WaternetLines"), "WaternetLine"))
+ {
+ WaternetLine waternetLine = new WaternetLine();
+
+ ReadWaternetLine(GetElement(waternetLineElement, "WaternetLine"), waternetLine, keys);
+ waternetLine.HeadLine =
+ (GeometryPointString)
+ keys[
+ Convert.ToInt32(waternetLineElement.GetAttribute("AssociatedHeadLine"),
+ CultureInfo.InvariantCulture)];
+ waternet.WaternetLineList.Add(waternetLine);
+ }
+
+ waternet.UnitWeight = Double.Parse(element.GetAttribute("UnitWeightWater"), CultureInfo.InvariantCulture);
+
+ waternet.IsGenerated = Boolean.Parse(element.GetAttribute("IsGenerated"));
+ location.WaternetCreationMode = waternet.IsGenerated
+ ? WaternetCreationMode.CreateWaternet
+ : WaternetCreationMode.FillInWaternetValues;
+ }
+ }
+
+ private static void ReadWaternetLine(XmlElement element, GeometryPointString waternetLine, Dictionary keys)
+ {
+ keys[Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture)] = waternetLine;
+
+ waternetLine.Name = element.GetAttribute("Name");
+
+ foreach (XmlElement pointElement in GetElements(GetElement(element, "Points"), "Point"))
+ {
+ waternetLine.Points.Add(ReadPoint(pointElement, keys, waternetLine));
+ }
+ waternetLine.SyncCalcPoints();
+ }
+
+ private static void ReadMultiplicationFactorsCPhiForUplift(XmlElement element, List list)
+ {
+ list.Clear();
+
+ foreach (XmlElement factorElement in GetElements(element, "MultiplicationFactorsCPhiForUplift"))
+ {
+ MultiplicationFactorOnCPhiForUplift factor = new MultiplicationFactorOnCPhiForUplift
+ {
+ UpliftFactor = Double.Parse(factorElement.GetAttribute("UpliftFactor"), CultureInfo.InvariantCulture),
+ MultiplicationFactor = Double.Parse(factorElement.GetAttribute("MultiplicationFactor"), CultureInfo.InvariantCulture)
+ };
+
+ list.Add(factor);
+ }
+ }
+
+ private static void ReadConsolidationValues(XmlElement element, StabilityModel model, Dictionary keys, Dictionary isTemporary)
+ {
+ UniformLoad consolidationLoad = new UniformLoad();
+
+ XmlElement loadElement = GetElement(element, "ConsolidationLoad");
+ keys[Int32.Parse(loadElement.GetAttribute("Key"), CultureInfo.InvariantCulture)] = consolidationLoad;
+
+ foreach (XmlElement consElement in GetElements(element, "ConsolidationValue"))
+ {
+ object consolidator = keys[Int32.Parse(consElement.GetAttribute("Consolidator"), CultureInfo.InvariantCulture)];
+ object consolidated = keys[Int32.Parse(consElement.GetAttribute("Consolidated"), CultureInfo.InvariantCulture)];
+
+ if (consolidator == consolidationLoad)
+ {
+ foreach (UniformLoad load in model.LastStage.UniformLoads)
+ {
+ if (isTemporary[load])
+ {
+ ConsolidationValue consolidation = new ConsolidationValue
+ {
+ Consolidator = load,
+ Consolidated = consolidated,
+ Value = Double.Parse(consElement.GetAttribute("Value"), CultureInfo.InvariantCulture)
+ };
+
+ model.LastStage.XmlConsolidationValues.Add(consolidation);
+ }
+ }
+ }
+ else
+ {
+ ConsolidationValue consolidation = new ConsolidationValue
+ {
+ Consolidator = consolidator,
+ Consolidated = consolidated,
+ Value = Double.Parse(consElement.GetAttribute("Value"), CultureInfo.InvariantCulture)
+ };
+
+ model.LastStage.XmlConsolidationValues.Add(consolidation);
+ }
+ }
+ }
+
+ private static void ReadTrafficLoadConsolidationValues(XmlElement element, DegreeofConsolidationMatrix matrix, Dictionary keys)
+ {
+ if (element != null)
+ {
+ XmlElement loadElemet = GetElement(element, "ConsolidationLoad");
+ keys[Int32.Parse(loadElemet.GetAttribute("Key"), CultureInfo.InvariantCulture)] = matrix.Consolidators;
+
+ foreach (XmlElement consElement in GetElements(element, "ConsolidationValue"))
+ {
+ ConsolidationValue consolidation = new ConsolidationValue
+ {
+ Consolidator = keys[Int32.Parse(consElement.GetAttribute("Consolidator"), CultureInfo.InvariantCulture)],
+ Consolidated = keys[Int32.Parse(consElement.GetAttribute("Consolidated"), CultureInfo.InvariantCulture)],
+ Value = Double.Parse(consElement.GetAttribute("Value"), CultureInfo.InvariantCulture)
+ };
+
+ matrix.ConsolidationValues.Add(consolidation);
+ }
+ }
+ }
+
+ private static void ReadPreconsolidationStresses(XmlElement element, StabilityModel stabilityModel, Dictionary keys)
+ {
+ stabilityModel.LastStage.PreconsolidationStresses.Clear();
+
+ foreach (XmlElement stressElement in GetElements(element, "PreconsolidationStress"))
+ {
+ PreConsolidationStress stress = new PreConsolidationStress();
+
+ GeometryPoint point = ReadPoint(GetElement(stressElement, "Point"), keys, stress);
+ stress.X = point.X;
+ stress.Z = point.Z;
+
+ stress.StressValue = Double.Parse(stressElement.GetAttribute("StressValue"), CultureInfo.InvariantCulture);
+
+ stabilityModel.LastStage.PreconsolidationStresses.Add(stress);
+ }
+ }
+
+ private static void ReadUniformLoads(XmlElement element, List list, List invalidList, Dictionary keys, Dictionary isTemporary)
+ {
+ list.Clear();
+ invalidList.Clear();
+ foreach (XmlElement uniformLoadElement in GetElements(element, "UniformLoad"))
+ {
+ UniformLoad uniformLoad = new UniformLoad
+ {
+ Pressure = Double.Parse(uniformLoadElement.GetAttribute("Magnitude"), CultureInfo.InvariantCulture),
+ DistributionAngle = Double.Parse(uniformLoadElement.GetAttribute("DistributionAngle"), CultureInfo.InvariantCulture),
+ XEnd = Double.Parse(uniformLoadElement.GetAttribute("XEnd"), CultureInfo.InvariantCulture),
+ XStart = Double.Parse(uniformLoadElement.GetAttribute("XStart"), CultureInfo.InvariantCulture)
+ };
+
+ if (!uniformLoad.Pressure.AlmostEquals(0) && !(uniformLoad.XEnd - uniformLoad.XStart).AlmostEquals(0))
+ {
+ if (isTemporary != null)
+ {
+ string loadType = uniformLoadElement.GetAttribute("LoadType");
+ isTemporary[uniformLoad] = loadType.ToLower().Equals("temporary");
+ }
+
+ int key = Int32.Parse(uniformLoadElement.GetAttribute("Key"), CultureInfo.InvariantCulture);
+ keys[key] = uniformLoad;
+
+ list.Add(uniformLoad);
+ }
+ else
+ {
+ int key = Int32.Parse(uniformLoadElement.GetAttribute("Key"), CultureInfo.InvariantCulture);
+ keys[key] = uniformLoad;
+ invalidList.Add(uniformLoad);
+ }
+ }
+ }
+
+ private static void ReadLocation(XmlElement element, ref Location location)
+ {
+ // locationdaily is only to be created when the data is part of the file. If it is not, it must remain null in order
+ // to prevent bogus data.
+ if (element != null)
+ {
+ if (location == null)
+ {
+ location = new Location();
+ }
+ location.DikeSoilScenario = (DikeSoilScenario)Enum.Parse(typeof(DikeSoilScenario), element.GetAttribute("DikeSoilScenario"));
+ location.WaterLevelRiver = Double.Parse(element.GetAttribute("WaterLevelRiver"), CultureInfo.InvariantCulture);
+ location.WaterLevelRiverAverage = Double.Parse(element.GetAttribute("WaterLevelRiverAverage"), CultureInfo.InvariantCulture);
+ location.WaterLevelRiverLow = Double.Parse(element.GetAttribute("WaterLevelRiverLow"), CultureInfo.InvariantCulture);
+ location.WaterLevelPolder = Double.Parse(element.GetAttribute("WaterLevelPolder"), CultureInfo.InvariantCulture);
+ location.DrainageConstructionPresent = Boolean.Parse(element.GetAttribute("DrainageConstructionPresent"));
+ location.XCoordMiddleDrainageConstruction = Double.Parse(element.GetAttribute("XCoordMiddleDrainageConstruction"), CultureInfo.InvariantCulture);
+ location.ZCoordMiddleDrainageConstruction = Double.Parse(element.GetAttribute("ZCoordMiddleDrainageConstruction"), CultureInfo.InvariantCulture);
+ location.MinimumLevelPhreaticLineAtDikeTopRiver = Double.Parse(element.GetAttribute("MinimumLevelPhreaticLineAtDikeTopRiver"), CultureInfo.InvariantCulture);
+ location.MinimumLevelPhreaticLineAtDikeTopPolder = Double.Parse(element.GetAttribute("MinimumLevelPhreaticLineAtDikeTopPolder"), CultureInfo.InvariantCulture);
+ location.UseDefaultOffsets = Boolean.Parse(element.GetAttribute("UseDefaultOffsets"));
+ location.PlLineOffsetBelowPointBRingtoetsWti2017 = Double.Parse(element.GetAttribute("PlLineOffsetBelowPointBRingtoetsWti2017"), CultureInfo.InvariantCulture);
+ location.PlLineOffsetBelowDikeTopAtPolder = Double.Parse(element.GetAttribute("PlLineOffsetBelowDikeTopAtPolder"), CultureInfo.InvariantCulture);
+ location.PlLineOffsetBelowShoulderBaseInside = Double.Parse(element.GetAttribute("PlLineOffsetBelowShoulderBaseInside"), CultureInfo.InvariantCulture);
+ location.PlLineOffsetBelowDikeToeAtPolder = Double.Parse(element.GetAttribute("PlLineOffsetBelowDikeToeAtPolder"), CultureInfo.InvariantCulture);
+ location.HeadInPlLine2Outwards = Double.Parse(element.GetAttribute("HeadInPLLine2Outwards"), CultureInfo.InvariantCulture);
+ location.HeadInPlLine2Inwards = Double.Parse(element.GetAttribute("HeadInPLLine2Inwards"), CultureInfo.InvariantCulture);
+ location.HeadInPlLine3 = Double.Parse(element.GetAttribute("HeadInPLLine3"), CultureInfo.InvariantCulture);
+ location.HeadInPlLine4 = Double.Parse(element.GetAttribute("HeadInPLLine4"), CultureInfo.InvariantCulture);
+ location.AdjustPl3And4ForUplift = Boolean.Parse(element.GetAttribute("AdjustPl3And4ForUplift"));
+ location.PenetrationLength = Double.Parse(element.GetAttribute("PenetrationLength"), CultureInfo.InvariantCulture);
+ location.LeakageLengthOutwardsPl3 = Double.Parse(element.GetAttribute("LeakageLengthOutwardsPl3"), CultureInfo.InvariantCulture);
+ location.LeakageLengthInwardsPl3 = Double.Parse(element.GetAttribute("LeakageLengthInwardsPl3"), CultureInfo.InvariantCulture);
+ location.LeakageLengthOutwardsPl4 = Double.Parse(element.GetAttribute("LeakageLengthOutwardsPl4"), CultureInfo.InvariantCulture);
+ location.LeakageLengthInwardsPl4 = Double.Parse(element.GetAttribute("LeakageLengthInwardsPl4"), CultureInfo.InvariantCulture);
+ }
+ else
+ {
+ location = null;
+ }
+ }
+
+ private static void ReadSurfaceLine(XmlElement element, SurfaceLine2 surfaceLine, Dictionary keys)
+ {
+ surfaceLine.CharacteristicPoints.Clear();
+
+ foreach (XmlElement charNode in GetElements(GetElement(element, "CharacteristicPoints"), "CharacteristicPoint"))
+ {
+ CharacteristicPoint charPoint = new CharacteristicPoint
+ {
+ GeometryPoint = ReadPoint(GetElement(charNode, "GeometryPoint"), keys, surfaceLine),
+ CharacteristicPointType = (CharacteristicPointType)Enum.Parse(typeof(CharacteristicPointType), charNode.GetAttribute("CharacteristicPointType"))
+ };
+ surfaceLine.CharacteristicPoints.Add(charPoint);
+ }
+ surfaceLine.Geometry.SyncPoints();
+ }
+
+ private static void ReadSoilModel(XmlElement element, SoilModel soilModel, List soilStresses, Dictionary keys)
+ {
+ soilModel.Soils.Clear();
+
+ foreach (XmlElement soilNode in GetElements(GetElement(element, "Soils"), "Soil"))
+ {
+ Soil soil = new Soil();
+ FixedSoilStress fixedSoilStress = null;
+ ReadSoil(soilNode, soil, ref fixedSoilStress, keys);
+
+ if (fixedSoilStress != null)
+ {
+ soilStresses.Add(fixedSoilStress);
+ }
+
+ soilModel.Soils.Add(soil);
+ }
+ }
+
+ private static void ReadSoil(XmlElement element, Soil soil, ref FixedSoilStress fixedSoilStress, Dictionary keys)
+ {
+ keys[Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture)] = soil;
+
+ soil.Name = element.GetAttribute("Name");
+ soil.AbovePhreaticLevel = Double.Parse(element.GetAttribute("AbovePhreaticLevel"), CultureInfo.InvariantCulture);
+ soil.BelowPhreaticLevel = Double.Parse(element.GetAttribute("BelowPhreaticLevel"), CultureInfo.InvariantCulture);
+ soil.Cohesion = Double.Parse(element.GetAttribute("Cohesion"), CultureInfo.InvariantCulture);
+ soil.FrictionAngle = Double.Parse(element.GetAttribute("FrictionAngle"), CultureInfo.InvariantCulture);
+
+ string dilatancyType = element.GetAttribute("DilatancyType");
+ switch (dilatancyType)
+ {
+ case "Phi": soil.Dilatancy = soil.FrictionAngle; break;
+ case "MinusPhi": soil.Dilatancy = -soil.FrictionAngle; break;
+ case "Zero": soil.Dilatancy = 0; break;
+ }
+
+ soil.RatioCuPc = Double.Parse(element.GetAttribute("RatioCuPc"), CultureInfo.InvariantCulture);
+ soil.StrengthIncreaseExponent = Double.Parse(element.GetAttribute("StrengthIncreaseExponent"), CultureInfo.InvariantCulture);
+ soil.ShearStrengthModel = (ShearStrengthModel)Enum.Parse(typeof(ShearStrengthModel), element.GetAttribute("ShearStrengthModel"));
+
+ if (Boolean.Parse(element.GetAttribute("UsePop")))
+ {
+ fixedSoilStress = new FixedSoilStress();
+ fixedSoilStress.Soil = soil;
+ fixedSoilStress.CenterStressValue.POP = Double.Parse(element.GetAttribute("POP"), CultureInfo.InvariantCulture);
+ //fixedSoilStress.OCR = Double.Parse(element.GetAttribute("OCR"), CultureInfo.InvariantCulture);
+ }
+ }
+
+ private static void ReadSoilProfile(XmlElement element, SoilProfile2D soilProfile, Dictionary keys)
+ {
+ ReadGeometry(GetElement(element, "Geometry"), soilProfile.Geometry, keys);
+
+ foreach (XmlElement layerElement in GetElements(GetElement(element, "Surfaces"), "Surface"))
+ {
+ SoilLayer2D surface = new SoilLayer2D();
+
+ ReadSoilLayer(layerElement, surface, keys);
+ soilProfile.Surfaces.Add(surface);
+ }
+ }
+
+ private static void ReadSoilLayer(XmlElement element, SoilLayer2D surface, Dictionary keys)
+ {
+ keys[Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture)] = surface;
+
+ surface.Soil = (Soil)keys[Int32.Parse(element.GetAttribute("Soil"), CultureInfo.InvariantCulture)];
+ surface.GeometrySurface = (GeometrySurface)keys[Int32.Parse(element.GetAttribute("Surface"), CultureInfo.InvariantCulture)];
+ surface.IsAquifer = Boolean.Parse(element.GetAttribute("IsAquifer"));
+
+ if (element.HasAttribute("WaterpressureInterpolationModel"))
+ {
+ surface.WaterpressureInterpolationModel = (WaterpressureInterpolationModel)Enum.Parse(typeof(WaterpressureInterpolationModel), element.GetAttribute("WaterpressureInterpolationModel"));
+ }
+ else
+ {
+ surface.WaterpressureInterpolationModel = WaterpressureInterpolationModel.Automatic; //default value
+ }
+ }
+
+ private static void ReadGeometry(XmlElement element, GeometryData geometry, Dictionary keys)
+ {
+ geometry.Points.Clear();
+ geometry.Curves.Clear();
+ geometry.Loops.Clear();
+ geometry.Surfaces.Clear();
+
+ geometry.Left = Double.Parse(element.GetAttribute("Left"), CultureInfo.InvariantCulture);
+ geometry.Right = Double.Parse(element.GetAttribute("Right"), CultureInfo.InvariantCulture);
+ geometry.Bottom = Double.Parse(element.GetAttribute("Bottom"), CultureInfo.InvariantCulture);
+
+ foreach (XmlElement pointElement in GetElements(GetElement(element, "Points"), "Point"))
+ {
+ geometry.Points.Add(ReadPoint(pointElement, keys));
+ }
+
+ foreach (XmlElement curveElement in GetElements(GetElement(element, "Curves"), "Curve"))
+ {
+ geometry.Curves.Add(ReadCurve(curveElement, keys));
+ }
+
+ foreach (XmlElement loopElement in GetElements(GetElement(element, "Loops"), "Loop"))
+ {
+ geometry.Loops.Add(ReadLoop(loopElement, keys));
+ }
+
+ foreach (XmlElement surfaceElement in GetElements(GetElement(element, "Surfaces"), "Surface"))
+ {
+ geometry.Surfaces.Add(ReadSurface(surfaceElement, keys));
+ }
+ }
+
+ private static GeometrySurface ReadSurface(XmlElement element, Dictionary keys)
+ {
+ int key = Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture);
+
+ if (keys.ContainsKey(key))
+ {
+ return (GeometrySurface)keys[key];
+ }
+ else
+ {
+ GeometrySurface surface = new GeometrySurface();
+ keys[key] = surface;
+
+ surface.OuterLoop = (GeometryLoop)keys[Int32.Parse(element.GetAttribute("OuterLoop"), CultureInfo.InvariantCulture)];
+
+ surface.InnerLoops.Clear();
+
+ foreach (XmlElement loopElement in GetElements(GetElement(element, "InnerLoops"), "InnerLoop"))
+ {
+ GeometryLoop loop = (GeometryLoop)keys[Int32.Parse(loopElement.GetAttribute("Loop"), CultureInfo.InvariantCulture)];
+ surface.InnerLoops.Add(loop);
+ }
+
+ return surface;
+ }
+ }
+
+ private static GeometryLoop ReadLoop(XmlElement element, Dictionary keys)
+ {
+ int key = Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture);
+
+ if (keys.ContainsKey(key))
+ {
+ return (GeometryLoop)keys[key];
+ }
+ else
+ {
+ GeometryLoop loop = new GeometryLoop();
+ keys[key] = loop;
+
+ loop.CurveList.Clear();
+
+ foreach (XmlElement curveElement in GetElements(GetElement(element, "Curves"), "Curve"))
+ {
+ GeometryCurve curve = (GeometryCurve)keys[Int32.Parse(curveElement.GetAttribute("Curve"), CultureInfo.InvariantCulture)];
+ loop.CurveList.Add(curve);
+ }
+
+ return loop;
+ }
+ }
+
+ private static GeometryCurve ReadCurve(XmlElement element, Dictionary keys)
+ {
+ int key = Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture);
+
+ if (keys.ContainsKey(key))
+ {
+ return (GeometryCurve)keys[key];
+ }
+ else
+ {
+ GeometryCurve curve = new GeometryCurve();
+ keys[key] = curve;
+
+ curve.HeadPoint = (Point2D)keys[Int32.Parse(element.GetAttribute("HeadPoint"), CultureInfo.InvariantCulture)];
+ curve.EndPoint = (Point2D)keys[Int32.Parse(element.GetAttribute("EndPoint"), CultureInfo.InvariantCulture)];
+
+ return curve;
+ }
+ }
+
+ private static GeometryPoint ReadPoint(XmlElement element, Dictionary keys, object owner)
+ {
+ int key = Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture);
+
+ if (keys.ContainsKey(key))
+ {
+ if (keys[key] is Point2D)
+ {
+ var point = (Point2D)keys[key];
+ var geomPoint = new GeometryPoint(point.X, point.Z)
+ {
+ Owner = owner
+ };
+ return geomPoint;
+ }
+ return (GeometryPoint)keys[key];
+ }
+ else
+ {
+ GeometryPoint point = new GeometryPoint();
+ keys[key] = point;
+
+ point.X = Double.Parse(element.GetAttribute("X"), CultureInfo.InvariantCulture);
+ point.Z = Double.Parse(element.GetAttribute("Z"), CultureInfo.InvariantCulture);
+ point.Owner = owner;
+ return point;
+ }
+ }
+
+ private static Point2D ReadPoint(XmlElement element, Dictionary keys)
+ {
+ int key = Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture);
+
+ if (keys.ContainsKey(key))
+ {
+ return (Point2D)keys[key];
+ }
+ else
+ {
+ Point2D point = new Point2D();
+ keys[key] = point;
+
+ point.X = Double.Parse(element.GetAttribute("X"), CultureInfo.InvariantCulture);
+ point.Z = Double.Parse(element.GetAttribute("Z"), CultureInfo.InvariantCulture);
+ return point;
+ }
+ }
+
+ private static GeometryPoint ReadPoint2D(XmlElement element)
+ {
+ GeometryPoint point = new GeometryPoint()
+ {
+ X = Double.Parse(element.GetAttribute("X"), CultureInfo.InvariantCulture),
+ Z = Double.Parse(element.GetAttribute("Z"), CultureInfo.InvariantCulture)
+ };
+
+ return point;
+ }
+
+ private static void ReadValidationResult(XmlElement element, List result)
+ {
+ foreach (XmlElement validationElement in GetElements(GetElement(element, "Validations"), "Validation"))
+ {
+ result.Add(new ValidationResult
+ {
+ MessageType = (ValidationResultType)Enum.Parse(typeof(ValidationResultType), validationElement.GetAttribute("Severity")),
+ Text = validationElement.GetAttribute("Message")
+ });
+ }
+ }
+
+ private static void ReadStabilityModelResult(XmlElement element, StabilityAssessmentCalculationResult result)
+ {
+ result.ModelOption = (ModelOptions)Enum.Parse(typeof(ModelOptions), element.GetAttribute("ModelOption"));
+ result.Calculated = Boolean.Parse(element.GetAttribute("Succeeded"));
+ result.FactorOfSafety = Double.Parse(element.GetAttribute("SafetyFactor"), CultureInfo.InvariantCulture);
+ result.ZValue = Double.Parse(element.GetAttribute("ZValue"), CultureInfo.InvariantCulture);
+
+ result.Curve = ReadSlidingCurve(result.Calculated, GetElement(element, "MinimumSafetyCurve"));
+
+ result.Location = new Location();
+ result.LocationDaily = new Location();
+ result.Waternet = new Waternet();
+ result.WaternetDaily = new Waternet();
+ result.SlipPlaneUpliftVan = new SlipPlaneUpliftVan();
+ result.TrafficLoad = new List();
+ result.DegreeOfConsolidationMatrix = new DegreeofConsolidationMatrix();
+ result.XMinEntry = new double();
+ result.XMaxEntry = new double();
+ var location = (Location)result.Location;
+ ReadLocation(GetElement(element, "Location"), ref location);
+ result.Location = location;
+ var locationDaily = (Location)result.LocationDaily;
+ ReadLocation(GetElement(element, "LocationDaily"), ref locationDaily);
+ result.LocationDaily = locationDaily;
+ var waternet = result.Waternet;
+ ReadWaternets(GetElement(element, "Waternets"), ref waternet, result.Location, false, new Dictionary());
+ result.Waternet = waternet;
+ var waternetDaily = result.WaternetDaily;
+ ReadWaternets(GetElement(element, "Waternets"), ref waternetDaily, result.LocationDaily, true, new Dictionary());
+ result.WaternetDaily = waternetDaily;
+ ReadUsedUpliftVanCalculationGrid(GetElement(element, "UpliftVanCalculationGrid"), result);
+ ReadUniformLoads(GetElement(element, "TrafficLoad"), result.TrafficLoad,new List(), new Dictionary(), new Dictionary());
+ ReadTrafficLoadConsolidationValues(GetElement(element, "ConsolidationValues"), result.DegreeOfConsolidationMatrix, new Dictionary());
+ ReadForbiddenZones(GetElement(element, "ForbiddenZones"), result);
+
+ ReadMessages(GetElement(element, "Messages"), result.Messages);
+ }
+
+ private static SlidingCurve ReadSlidingCurve(bool calculationSucceded, XmlElement element)
+ {
+ SlidingCurve slidingCurve = new SlidingCurve();
+
+ string curveType = element.GetAttribute("CurveType");
+ switch (curveType)
+ {
+ case "Circle": slidingCurve = new SlidingCircle(); break;
+ case "DualCircle": slidingCurve = new SlidingDualCircle(); break;
+ case "Plane": slidingCurve = new SlidingPlane(); break;
+ }
+
+ if (slidingCurve is SlidingDualCircle && calculationSucceded)
+ {
+ SlidingDualCircle slidingDualCircle = (SlidingDualCircle)slidingCurve;
+
+ slidingDualCircle.ActiveCircle.X = Double.Parse(element.GetAttribute("ActiveCircleCenterX"), CultureInfo.InvariantCulture);
+ slidingDualCircle.ActiveCircle.Z = Double.Parse(element.GetAttribute("ActiveCircleCenterZ"), CultureInfo.InvariantCulture);
+ slidingDualCircle.ActiveRadius = Double.Parse(element.GetAttribute("ActiveCircleRadius"), CultureInfo.InvariantCulture);
+ slidingDualCircle.PassiveCircle.X = Double.Parse(element.GetAttribute("PassiveCircleCenterX"), CultureInfo.InvariantCulture);
+ slidingDualCircle.PassiveCircle.Z = Double.Parse(element.GetAttribute("PassiveCircleCenterZ"), CultureInfo.InvariantCulture);
+ slidingDualCircle.PassiveRadius = Double.Parse(element.GetAttribute("PassiveCircleRadius"), CultureInfo.InvariantCulture);
+
+ slidingDualCircle.HorizontalForce0 = Double.Parse(element.GetAttribute("NonIteratedHorizontaleForce"), CultureInfo.InvariantCulture);
+ slidingDualCircle.ActiveForce0 = Double.Parse(element.GetAttribute("NonIteratedActiveForce"), CultureInfo.InvariantCulture);
+ slidingDualCircle.PassiveForce0 = Double.Parse(element.GetAttribute("NonIteratedPassiveForce"), CultureInfo.InvariantCulture);
+
+ slidingDualCircle.HorizontalForce = Double.Parse(element.GetAttribute("IteratedHorizontaleForce"), CultureInfo.InvariantCulture);
+ slidingDualCircle.ActiveForce = Double.Parse(element.GetAttribute("IteratedActiveForce"), CultureInfo.InvariantCulture);
+ slidingDualCircle.PassiveForce = Double.Parse(element.GetAttribute("IteratedPassiveForce"), CultureInfo.InvariantCulture);
+
+ slidingDualCircle.DrivingMomentActive = Double.Parse(element.GetAttribute("DrivingMomentActive"), CultureInfo.InvariantCulture);
+ slidingDualCircle.DrivingMomentPassive = Double.Parse(element.GetAttribute("DrivingMomentPassive"), CultureInfo.InvariantCulture);
+ slidingDualCircle.ResistingMomentActive = Double.Parse(element.GetAttribute("ResistingMomentActive"), CultureInfo.InvariantCulture);
+ slidingDualCircle.ResistingMomentPassive = Double.Parse(element.GetAttribute("ResistingMomentPassive"), CultureInfo.InvariantCulture);
+ }
+
+ foreach (XmlElement sliceElement in GetElements(GetElement(element, "Slices"), "Slice"))
+ {
+ var topLeft = ReadPoint2D(GetElement(sliceElement, "TopLeftPoint"));
+ var topRight = ReadPoint2D(GetElement(sliceElement, "TopRightPoint"));
+ var bottomLeft = ReadPoint2D(GetElement(sliceElement, "BottomLeftPoint"));
+ var bottomRight = ReadPoint2D(GetElement(sliceElement, "BottomRightPoint"));
+ Slice slice = new Slice
+ {
+ TopLeftX = topLeft.X,
+ TopLeftZ = topLeft.Z,
+ TopRightX = topRight.X,
+ TopRightZ = topRight.Z,
+ BottomLeftX = bottomLeft.X,
+ BottomLeftZ = bottomLeft.Z,
+ BottomRightX = bottomRight.X,
+ BottomRightZ = bottomRight.Z,
+ CohesionOutput = Double.Parse(sliceElement.GetAttribute("Cohesion"), CultureInfo.InvariantCulture),
+ PhiOutput = Double.Parse(sliceElement.GetAttribute("FrictionAngle"), CultureInfo.InvariantCulture),
+ PGrens = Double.Parse(sliceElement.GetAttribute("CriticalPressure"), CultureInfo.InvariantCulture),
+ OCR = Double.Parse(sliceElement.GetAttribute("OCR"), CultureInfo.InvariantCulture),
+ POP = Double.Parse(sliceElement.GetAttribute("POP"), CultureInfo.InvariantCulture),
+ DegreeofConsolidationPorePressure = Double.Parse(sliceElement.GetAttribute("DegreeofConsolidationPorePressure"), CultureInfo.InvariantCulture),
+ PorePressureDueToDegreeOfConsolidationLoad = Double.Parse(sliceElement.GetAttribute("PorePressureDueToDegreeOfConsolidationLoad"), CultureInfo.InvariantCulture),
+ Dilatancy = Double.Parse(sliceElement.GetAttribute("Dilatancy"), CultureInfo.InvariantCulture),
+ ExternalLoad = Double.Parse(sliceElement.GetAttribute("ExternalLoad"), CultureInfo.InvariantCulture),
+ HydrostaticPorePressure = Double.Parse(sliceElement.GetAttribute("HydrostaticPorePressure"), CultureInfo.InvariantCulture),
+ LeftForce = Double.Parse(sliceElement.GetAttribute("LeftForce"), CultureInfo.InvariantCulture),
+ LeftForceAngle = Double.Parse(sliceElement.GetAttribute("LeftForceAngle"), CultureInfo.InvariantCulture),
+ LeftForceY = Double.Parse(sliceElement.GetAttribute("LeftForceY"), CultureInfo.InvariantCulture),
+ RightForce = Double.Parse(sliceElement.GetAttribute("RightForce"), CultureInfo.InvariantCulture),
+ RightForceAngle = Double.Parse(sliceElement.GetAttribute("RightForceAngle"), CultureInfo.InvariantCulture),
+ RightForceY = Double.Parse(sliceElement.GetAttribute("RightForceY"), CultureInfo.InvariantCulture),
+ LoadStress = Double.Parse(sliceElement.GetAttribute("LoadStress"), CultureInfo.InvariantCulture),
+ NormalStress = Double.Parse(sliceElement.GetAttribute("NormalStress"), CultureInfo.InvariantCulture),
+ PoreOnSurface = Double.Parse(sliceElement.GetAttribute("PorePressure"), CultureInfo.InvariantCulture),
+ HPoreOnSurface = Double.Parse(sliceElement.GetAttribute("HorizontalPorePressure"), CultureInfo.InvariantCulture),
+ VPoreOnSurface = Double.Parse(sliceElement.GetAttribute("VerticalPorePressure"), CultureInfo.InvariantCulture),
+ PiezometricPorePressure = Double.Parse(sliceElement.GetAttribute("PiezometricPorePressure"), CultureInfo.InvariantCulture),
+ EffectiveStress = Double.Parse(sliceElement.GetAttribute("EffectiveStress"), CultureInfo.InvariantCulture),
+ EffectiveStressDaily = Double.Parse(sliceElement.GetAttribute("EffectiveStressDaily"), CultureInfo.InvariantCulture),
+ ExcessPorePressure = Double.Parse(sliceElement.GetAttribute("ExcessPorePressure"), CultureInfo.InvariantCulture),
+ ShearStress = Double.Parse(sliceElement.GetAttribute("ShearStress"), CultureInfo.InvariantCulture),
+ SoilStress = Double.Parse(sliceElement.GetAttribute("SoilStress"), CultureInfo.InvariantCulture),
+ TotalPorePressure = Double.Parse(sliceElement.GetAttribute("TotalPorePressure"), CultureInfo.InvariantCulture),
+ TotalStress = Double.Parse(sliceElement.GetAttribute("TotalStress"), CultureInfo.InvariantCulture),
+ Weight = Double.Parse(sliceElement.GetAttribute("Weight"), CultureInfo.InvariantCulture),
+ SuOutput = Double.Parse(sliceElement.GetAttribute("Su"), CultureInfo.InvariantCulture)
+
+ };
+ var ssm = sliceElement.GetAttribute("ShearStrengthModel");
+ if (!string.IsNullOrEmpty(ssm))
+ {
+ slice.ShearStrengthModel = (ShearStrengthModel)Enum.Parse(typeof(ShearStrengthModel), ssm);
+ }
+ slidingCurve.Slices.Add(slice);
+ }
+
+ return slidingCurve;
+ }
+
+ private static void ReadMessages(XmlElement element, List messages)
+ {
+ messages.Clear();
+
+ foreach (XmlElement pointElement in GetElements(element, "Message"))
+ {
+ LogMessage message = new LogMessage
+ {
+ Message = pointElement.GetAttribute("Message"),
+ MessageType = (LogMessageType)Enum.Parse(typeof(LogMessageType), pointElement.GetAttribute("MessageType"))
+ };
+
+ messages.Add(message);
+ }
+ }
+ }
+}
Fisheye: Tag 1972 refers to a dead (removed) revision in file `DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroSstabilityIoTests.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroSstabilityIoTests.cs
===================================================================
diff -u -r1971 -r1972
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroSstabilityIoTests.cs (.../MacroSstabilityIoTests.cs) (revision 1971)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/KernelWrappers/MacroStabilityCommon/MacroSstabilityIoTests.cs (.../MacroStabilityIoTests.cs) (revision 1972)
@@ -22,13 +22,13 @@
using System.IO;
using NUnit.Framework;
using Deltares.MacroStability.Kernel;
-using Deltares.DamEngine.Calculators.KernelWrappers.MacroSstabilityCommon.MacroSstabilityIo;
+using Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo;
using Deltares.DamEngine.TestHelpers;
namespace Deltares.DamEngine.Calculators.Tests.KernelWrappers.MacroStabilityCommon
{
[TestFixture]
- public class MacroSstabilityIoTests
+ public class MacroStabilityIoTests
{
private const string WtiFilesMap = @"KernelWrappers\MacroStabilityCommon\TestFiles";
[Test]
Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj
===================================================================
diff -u -r1971 -r1972
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj (.../Deltares.DamEngine.Calculators.Tests.csproj) (revision 1971)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Deltares.DamEngine.Calculators.Tests.csproj (.../Deltares.DamEngine.Calculators.Tests.csproj) (revision 1972)
@@ -58,7 +58,7 @@
-
+
Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj
===================================================================
diff -u -r1971 -r1972
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj (.../Deltares.DamEngine.Calculators.csproj) (revision 1971)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/Deltares.DamEngine.Calculators.csproj (.../Deltares.DamEngine.Calculators.csproj) (revision 1972)
@@ -109,8 +109,8 @@
-
-
+
+
@@ -234,31 +234,31 @@
Designer
-
+
Designer
-
+
Designer
-
+
Designer
-
+
Designer
-
+
Designer
-
+
Designer
-
+
Designer
-
+
Designer
-
+
Designer
Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/WTISerializer.cs
===================================================================
diff -u
--- DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/WTISerializer.cs (revision 0)
+++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/KernelWrappers/MacroStabilityCommon/MacroStabilityIo/WTISerializer.cs (revision 1972)
@@ -0,0 +1,1077 @@
+// Copyright (C) Stichting Deltares 2019. 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 System.Globalization;
+using System.Linq;
+using System.Reflection;
+using System.Xml;
+using Deltares.MacroStability.Data;
+using Deltares.MacroStability.Geometry;
+using Deltares.MacroStability.Kernel;
+using Deltares.MacroStability.Preprocessing;
+using Deltares.MacroStability.Standard;
+using Deltares.MacroStability.WaternetCreator;
+using Deltares.SearchAlgorithms;
+using Deltares.SoilStress.Data;
+using Deltares.WTIStability.Data;
+
+namespace Deltares.DamEngine.Calculators.KernelWrappers.MacroStabilityCommon.MacroStabilityIo
+{
+ ///
+ /// WTI xml format serializer class
+ ///
+ public class WtiSerializer
+ {
+ // Fileversion for the WTI file. Only to be increased when content of file changes.
+ private const int fileVersion = 1;
+ ///
+ /// Serializes an stability model to an xml string obeying WTIStabilityModel.xsd
+ ///
+ /// The model
+ /// The xml string
+ public static string Serialize(KernelModel model)
+ {
+ XmlDocument doc = new XmlDocument();
+ var declaration = doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
+ doc.AppendChild(declaration);
+
+ string name = "WTIStabilityModel";
+ WriteStabilityModel(doc, model, name, new Dictionary