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 1964)
@@ -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());
+ return doc.InnerXml;
+ }
+
+ ///
+ /// Serializes an stability model result to an xml string obeying WTIStabilityModelResult.xsd
+ ///
+ /// The stability model result
+ /// The xml string
+ public static string SerializeResult(StabilityAssessmentCalculationResult result)
+ {
+ XmlDocument doc = new XmlDocument();
+ var declaration = doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
+ doc.AppendChild(declaration);
+
+ string name = "WTIStabilityModelResult";
+
+ WriteStabilityResult(doc, result, name);
+
+ return doc.InnerXml;
+ }
+
+ ///
+ /// Serializes an stability model validation to an xml string obeying WTIStabilityModelValidation.xsd
+ ///
+ /// The stability model results
+ /// The xml string
+ public static string SerializeValidation(IValidationResult[] validationResults)
+ {
+ XmlDocument doc = new XmlDocument();
+ var declaration = doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
+ doc.AppendChild(declaration);
+
+ string name = "WTIStabilityModelValidation";
+
+ WriteValidation(doc, validationResults, name);
+
+ return doc.InnerXml;
+ }
+
+ ///
+ /// Serializes a waternet (and the eventual validation messages) to an xml string obeying WTIWaternetUsedDuringCalculation.xsd
+ ///
+ /// The locations.
+ /// The waternets.
+ /// The validation messages before/during creation of the waternet.
+ ///
+ /// The xml string
+ ///
+ public static string SerializeWaternet(List locations, List waternets, IValidationResult[] validationResults)
+ {
+ var doc = new XmlDocument();
+ var declaration = doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
+ doc.AppendChild(declaration);
+
+ WriteWaternet(doc, waternets, locations, validationResults, new Dictionary());
+ return doc.InnerXml;
+ }
+
+ private static void WriteWaternet(XmlDocument doc, List waternets, List locations, IValidationResult[] validationResults, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement("WTIWaternetUsedDuringCalculation");
+
+ WriteWaternet(doc, element, waternets, locations, keys);
+
+ XmlElement validationElement = doc.CreateElement("Validations");
+ foreach (IValidationResult result in validationResults)
+ {
+ XmlElement messageElement = doc.CreateElement("Validation");
+ messageElement.SetAttribute("Severity", result.MessageType.ToString());
+
+ string text = result.Text;
+ messageElement.SetAttribute("Message", text);
+ validationElement.AppendChild(messageElement);
+ }
+
+ element.AppendChild(validationElement);
+
+ doc.AppendChild(element);
+ }
+
+ private static void WriteStabilityModel(XmlDocument doc, KernelModel kernelModel, string name, Dictionary keys)
+ {
+ StabilityModel model = kernelModel.StabilityModel;
+ PreprocessingModel automationModel = kernelModel.PreprocessingModel;
+
+ XmlElement element = doc.CreateElement(name);
+
+ element.SetAttribute("MoveGrid", model.MoveGrid.ToString().ToLower());
+ element.SetAttribute("MaximumSliceWidth", model.MaximumSliceWidth.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("SearchAlgorithm", model.SearchAlgorithm.ToString());
+ element.SetAttribute("ModelOption", model.ModelOption.ToString());
+ element.SetAttribute("Orientation", model.GridOrientation.ToString());
+
+ WriteVersionInfo(doc, element, "VersionInfo");
+ WriteSoilModel(doc, element, model.SoilModel, model.FirstStage, "SoilModel", keys);
+ WriteSoilProfile(doc, element, model.SoilProfile, "SoilProfile", keys);
+ WriteSurfaceLine(doc, element, automationModel.LastStage.SurfaceLine, "SurfaceLine", keys);
+ WriteLocation(doc, element, automationModel.LastStage.Locations[0], "Location");
+
+ if (automationModel.ConstructionStages.Count > 1)
+ {
+ WriteLocation(doc, element, automationModel.ConstructionStages[0].Locations[0], "LocationDaily");
+ }
+
+ WritePreconsolidationStresses(doc, element, model, "PreconsolidationStresses", keys);
+ WriteUniformLoads(doc, element, model.LastStage.UniformLoads,model.LastStage.InvalidUniformLoads, "UniformLoads", keys);
+
+ WriteConsolidationValues(doc, element, model, "ConsolidationValues", keys);
+ WriteMultiplicationFactorsCPhiForUplift(doc, element, model.LastStage.MultiplicationFactorsCPhiForUpliftList, "MultiplicationFactorsCPhiForUplift");
+
+ var waternets = new List();
+ var locations = new List();
+
+ waternets.Add(model.GeotechnicsData.CurrentWaternet);
+ locations.Add(automationModel.LastStage.Locations[0]);
+
+ if (model.ConstructionStages.Count > 1)
+ {
+ waternets.Add(model.ConstructionStages[0].GeotechnicsData.CurrentWaternet);
+ locations.Add(automationModel.ConstructionStages[0].Locations[0]);
+ }
+ WriteWaternet(doc, element, waternets, locations, keys);
+
+ WriteSpencerSlipPlanes(doc, element, model, automationModel, "SpencerSlipPlanes", keys);
+ WriteUpliftVanCalculationGrid(doc, element, model, automationModel, "UpliftVanCalculationGrid");
+ WriteSlipPlaneConstraints(doc, element, model, automationModel, "SlipPlaneConstraints");
+ WriteGeneticAlgorithmOptions(doc, element, model.GeneticAlgorithmOptions, "GeneticAlgorithmOptions");
+ WriteLevenbergMarquardtOptions(doc, element, model.LevenbergMarquardtOptions, "LevenbergMarquardtOptions");
+
+ doc.AppendChild(element);
+ }
+
+ private static void WriteLevenbergMarquardtOptions(XmlDocument doc, XmlElement parent, LevenbergMarquardtOptions options,
+ string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ element.SetAttribute("IterationCount", options.IterationCount.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Shift", options.Shift.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("DriftGrant", options.DriftGrant.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ParameterCount", options.ParameterCount.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("VariableCount", options.VariableCount.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteGeneticAlgorithmOptions(XmlDocument doc, XmlElement parent, GeneticAlgorithmOptions options, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ element.SetAttribute("EliteCount", options.EliteCount.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("PopulationCount", options.PopulationCount.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("GenerationCount", options.GenerationCount.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("MutationRate", options.MutationRate.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("CrossOverScatterFraction", options.CrossOverScatterFraction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("CrossOverSinglePointFraction", options.CrossOverSinglePointFraction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("CrossOverDoublePointFraction", options.CrossOverDoublePointFraction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("MutationJumpFraction", options.MutationJumpFraction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("MutationCreepFraction", options.MutationCreepFraction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("MutationInverseFraction", options.MutationInverseFraction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("MutationCreepReduction", options.MutationCreepReduction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Seed", options.Seed.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteSlipPlaneConstraints(XmlDocument doc, XmlElement parent, StabilityModel model, PreprocessingModel preprocessing, string name)
+ {
+ SlipPlaneConstraints constraints = model.SlipPlaneConstraints;
+
+ XmlElement element = doc.CreateElement(name);
+
+ element.SetAttribute("SlipPlaneMinDepth", constraints.SlipPlaneMinDepth.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("SlipPlaneMinLength", constraints.SlipPlaneMinLength.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("CreateZones", preprocessing.SearchAreaConditions.AutomaticForbiddenZones.ToString(CultureInfo.InvariantCulture).ToLower());
+ element.SetAttribute("AutomaticForbiddenZones", preprocessing.SearchAreaConditions.AutomaticForbiddenZones.ToString(CultureInfo.InvariantCulture).ToLower());
+ element.SetAttribute("XEntryMin", constraints.XLeftMin.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("XEntryMax", constraints.XLeftMax.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("MaxAllowedAngleBetweenSlices", model.MaxAllowedAngleBetweenSlices.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("RequiredForcePointsInSlices", model.RequiredForcePointsInSlices.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteUsedForbiddenZones(XmlDocument doc, XmlElement parent, StabilityAssessmentCalculationResult result, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ element.SetAttribute("AutomaticallyCalculated", result.AreForbiddenZonesAuto.ToString(CultureInfo.InvariantCulture).ToLower());
+ element.SetAttribute("XEntryMin", result.XMinEntry.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("XEntryMax", result.XMaxEntry.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteUpliftVanCalculationGrid(XmlDocument doc, XmlElement parent, StabilityModel model, PreprocessingModel preprocessing, string name)
+ {
+ SlipPlaneUpliftVan slipPlane = model.SlipPlaneUpliftVan;
+
+ XmlElement element = doc.CreateElement(name);
+
+ WriteCalculationGrid(doc, element, slipPlane.SlipPlaneLeftGrid, "LeftGrid");
+ WriteCalculationGrid(doc, element, slipPlane.SlipPlaneRightGrid, "RightGrid");
+
+ XmlElement tangentLineElement = doc.CreateElement("TangentLines");
+
+ tangentLineElement.SetAttribute("TangentLineZTop", slipPlane.SlipCircleTangentLine.TangentLineZTop.ToString(CultureInfo.InvariantCulture));
+ tangentLineElement.SetAttribute("TangentLineZBottom", slipPlane.SlipCircleTangentLine.TangentLineZBottom.ToString(CultureInfo.InvariantCulture));
+ tangentLineElement.SetAttribute("TangentLineNumber", slipPlane.SlipCircleTangentLine.TangentLineNumber.ToString(CultureInfo.InvariantCulture));
+ tangentLineElement.SetAttribute("AutomaticAtBoundaries", (slipPlane.SlipCircleTangentLine.SearchValuesType == SearchValuesType.Enumerated).ToString(CultureInfo.InvariantCulture).ToLower());
+
+ element.AppendChild(tangentLineElement);
+
+ element.SetAttribute("Auto", preprocessing.SearchAreaConditions.AutoSearchArea.ToString(CultureInfo.InvariantCulture).ToLower());
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteUsedUpliftVanCalculationGrid(XmlDocument doc, XmlElement parent, StabilityAssessmentCalculationResult result, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ bool auto = result.IsGridAuto;
+ SlipPlaneUpliftVan slipPlane = result.SlipPlaneUpliftVan;
+
+ element.SetAttribute("AutomaticallyCalculated", auto.ToString(CultureInfo.InvariantCulture).ToLower());
+ WriteCalculationGrid(doc, element, slipPlane.SlipPlaneLeftGrid, "LeftGrid");
+ WriteCalculationGrid(doc, element, slipPlane.SlipPlaneRightGrid, "RightGrid");
+
+ XmlElement tangentLinesElement = doc.CreateElement("TangentLines");
+
+ if (slipPlane.SlipCircleTangentLine.BoundaryHeights.Count > 0)
+ {
+ foreach (TangentLine tangentLine in slipPlane.SlipCircleTangentLine.BoundaryHeights)
+ {
+ XmlElement tangentLineElement = doc.CreateElement("TangentLine");
+ tangentLineElement.SetAttribute("Level", tangentLine.Height.ToString(CultureInfo.InvariantCulture));
+ tangentLinesElement.AppendChild(tangentLineElement);
+ }
+ }
+
+ element.AppendChild(tangentLinesElement);
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteCalculationGrid(XmlDocument doc, XmlElement parent, SlipCircleGrid grid, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ element.SetAttribute("GridXLeft", grid.GridXLeft.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("GridXRight", grid.GridXRight.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("GridZTop", grid.GridZTop.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("GridZBottom", grid.GridZBottom.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("GridXNumber", grid.GridXNumber.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("GridZNumber", grid.GridZNumber.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteSpencerSlipPlanes(XmlDocument doc, XmlElement parent, StabilityModel model, PreprocessingModel preprocessing, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ XmlElement upperElement = doc.CreateElement("UpperSlipPlane");
+ if (model.SlipPlanes.Count > 0)
+ {
+ model.SlipPlanes[0].SyncPoints();
+ foreach (GeometryPoint point in model.SlipPlanes[0].Points)
+ {
+ WritePoint(doc, upperElement, point, "Point", keys);
+ }
+ }
+ element.AppendChild(upperElement);
+
+ XmlElement lowerElement = doc.CreateElement("LowerSlipPlane");
+ if (model.SlipPlanes.Count > 1)
+ {
+ model.SlipPlanes[1].SyncPoints();
+ foreach (GeometryPoint point in model.SlipPlanes[1].Points)
+ {
+ WritePoint(doc, lowerElement, point, "Point", keys);
+ }
+ }
+ element.AppendChild(lowerElement);
+
+ element.SetAttribute("Auto", preprocessing.SearchAreaConditions.AutoSearchArea.ToString(CultureInfo.InvariantCulture).ToLower());
+ element.SetAttribute("SlipPlanePosition", preprocessing.SearchAreaConditions.SlipPlanePosition.ToString());
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteWaternet(XmlDocument doc, XmlElement parent, List waternets, List locations, Dictionary keys)
+ {
+ if (waternets != null && locations != null)
+ {
+ XmlElement element = doc.CreateElement("Waternets");
+
+ for (int i = 0; i < waternets.Count; i++)
+ {
+ bool isDaily = waternets[i].Name == "WaternetDaily";
+
+ if (locations[i] != null)
+ {
+ XmlElement waternetElement = doc.CreateElement("Waternet");
+ if (waternets[i].PhreaticLine == null)
+ {
+ waternets[i].PhreaticLine = new PhreaticLine
+ {
+ Name = LocalizationManager.GetTranslatedText(typeof(Waternet), "PhreaticLine")
+ };
+ waternets[i].PhreaticLine.Points.Add(new GeometryPoint(0, 0));
+ }
+
+ WriteWaternetLine(doc, waternetElement, waternets[i].PhreaticLine, "PhreaticLine", keys);
+
+ XmlElement headLinesElement = doc.CreateElement("HeadLines");
+ foreach (HeadLine headLine in waternets[i].HeadLineList)
+ {
+ WriteWaternetLine(doc, headLinesElement, headLine, "HeadLine", keys);
+ }
+ waternetElement.AppendChild(headLinesElement);
+
+ XmlElement waternetLinesElement = doc.CreateElement("WaternetLines");
+ foreach (WaternetLine waternetLine in waternets[i].WaternetLineList)
+ {
+ if (waternetLine.HeadLine != null)
+ {
+ XmlElement waternetLineElement = doc.CreateElement("WaternetLine");
+ WriteWaternetLine(doc, waternetLineElement, waternetLine, "WaternetLine", keys);
+ waternetLineElement.SetAttribute("AssociatedHeadLine",
+ keys[waternetLine.HeadLine].ToString(
+ CultureInfo.InvariantCulture));
+ waternetLinesElement.AppendChild(waternetLineElement);
+ }
+ }
+ waternetElement.AppendChild(waternetLinesElement);
+
+ waternetElement.SetAttribute("UnitWeightWater",
+ waternets[i].UnitWeight.ToString(CultureInfo.InvariantCulture).ToLower());
+ waternetElement.SetAttribute("IsGenerated",
+ (locations[i].WaternetCreationMode == WaternetCreationMode.CreateWaternet)
+ .ToString
+ (CultureInfo.InvariantCulture).ToLower());
+
+ waternetElement.SetAttribute("IsDaily", isDaily.ToString(CultureInfo.InvariantCulture).ToLower());
+
+ element.AppendChild(waternetElement);
+ }
+ }
+ parent.AppendChild(element);
+ }
+ }
+
+ private static void WriteWaternetLine(XmlDocument doc, XmlElement parent, GeometryPointString waternetLine, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+ waternetLine.SyncPoints();
+ if (!keys.ContainsKey(waternetLine))
+ {
+ keys[waternetLine] = keys.Count + 1;
+ }
+
+ element.SetAttribute("Key", keys[waternetLine].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Name", waternetLine.Name);
+
+ XmlElement listElement = doc.CreateElement("Points");
+ foreach (GeometryPoint point in waternetLine.Points)
+ {
+ WritePoint(doc, listElement, point, "Point", keys);
+ }
+ element.AppendChild(listElement);
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteMultiplicationFactorsCPhiForUplift(XmlDocument doc, XmlElement parent, List list, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ foreach (MultiplicationFactorOnCPhiForUplift factor in list)
+ {
+ XmlElement factorElement = doc.CreateElement("MultiplicationFactorsCPhiForUplift");
+ factorElement.SetAttribute("UpliftFactor", factor.UpliftFactor.ToString(CultureInfo.InvariantCulture));
+ factorElement.SetAttribute("MultiplicationFactor", factor.MultiplicationFactor.ToString(CultureInfo.InvariantCulture));
+
+ element.AppendChild(factorElement);
+ }
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteConsolidationValues(XmlDocument doc, XmlElement parent, StabilityModel model, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ UniformLoad consolidationLoad = new UniformLoad();
+ keys[consolidationLoad] = keys.Count + 1;
+
+ XmlElement loadElement = doc.CreateElement("ConsolidationLoad");
+ loadElement.SetAttribute("Key", keys[consolidationLoad].ToString(CultureInfo.InvariantCulture));
+ element.AppendChild(loadElement);
+
+ foreach (ConsolidationValue consolidationValue in model.LastStage.XmlConsolidationValues)
+ {
+ if (consolidationValue.Consolidator != null && keys.ContainsKey(consolidationValue.Consolidator) &&
+ consolidationValue.Consolidated != null && keys.ContainsKey(consolidationValue.Consolidated))
+ {
+ XmlElement consElement = doc.CreateElement("ConsolidationValue");
+
+ consElement.SetAttribute("Consolidator", keys[consolidationValue.Consolidator].ToString(CultureInfo.InvariantCulture));
+ consElement.SetAttribute("Consolidated", keys[consolidationValue.Consolidated].ToString(CultureInfo.InvariantCulture));
+ consElement.SetAttribute("Value", consolidationValue.Value.ToString(CultureInfo.InvariantCulture));
+
+ element.AppendChild(consElement);
+ }
+ }
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteConsolidationValuesForTrafficLoad(XmlDocument doc, XmlElement parent, StabilityAssessmentCalculationResult result, string name, Dictionary keys)
+ {
+ if (result.TrafficLoad != null && result.TrafficLoad.Count > 0)
+ {
+ XmlElement element = doc.CreateElement(name);
+ {
+ if (!keys.ContainsKey(result.TrafficLoad[0]))
+ {
+ keys[result.TrafficLoad[0]] = keys.Count + 1;
+ }
+
+ XmlElement loadElement = doc.CreateElement("ConsolidationLoad");
+ loadElement.SetAttribute("Key", keys[result.TrafficLoad[0]].ToString(CultureInfo.InvariantCulture));
+ element.AppendChild(loadElement);
+
+ foreach (ConsolidationValue consolidationValue in result.DegreeOfConsolidationMatrix.ConsolidationValues)
+ {
+ if (consolidationValue.Consolidator != null && keys.ContainsKey(consolidationValue.Consolidator) &&
+ consolidationValue.Consolidated != null && keys.ContainsKey(consolidationValue.Consolidated))
+ {
+ XmlElement consElement = doc.CreateElement("ConsolidationValue");
+
+ consElement.SetAttribute("Consolidator", keys[consolidationValue.Consolidator].ToString(CultureInfo.InvariantCulture));
+ consElement.SetAttribute("Consolidated", keys[consolidationValue.Consolidated].ToString(CultureInfo.InvariantCulture));
+ consElement.SetAttribute("Value", consolidationValue.Value.ToString(CultureInfo.InvariantCulture));
+
+ element.AppendChild(consElement);
+ }
+ }
+ }
+
+ parent.AppendChild(element);
+ }
+ }
+
+ private static void WritePreconsolidationStresses(XmlDocument doc, XmlElement parent, StabilityModel stabilityModel, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ foreach (PreConsolidationStress stress in stabilityModel.ConstructionStages[0].PreconsolidationStresses)
+ {
+ XmlElement stressElement = doc.CreateElement("PreconsolidationStress");
+
+ GeometryPoint point = new GeometryPoint(stress.X, stress.Z);
+
+ WritePoint(doc, stressElement, point, "Point", keys);
+
+ stressElement.SetAttribute("StressValue", stress.StressValue.ToString(CultureInfo.InvariantCulture));
+
+ element.AppendChild(stressElement);
+ }
+ parent.AppendChild(element);
+ }
+
+ private static void WriteUniformLoads(XmlDocument doc, XmlElement parent, List list, List invalidList, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ if (list != null)
+ {
+ foreach (UniformLoad uniformLoad in list)
+ {
+ if (!keys.ContainsKey(uniformLoad))
+ {
+ keys[uniformLoad] = keys.Count + 1;
+ }
+
+ XmlElement uniformLoadElement = doc.CreateElement("UniformLoad");
+ uniformLoadElement.SetAttribute("Key", keys[uniformLoad].ToString(CultureInfo.InvariantCulture));
+ uniformLoadElement.SetAttribute("Magnitude", uniformLoad.Pressure.ToString(CultureInfo.InvariantCulture));
+ uniformLoadElement.SetAttribute("DistributionAngle", uniformLoad.DistributionAngle.ToString(CultureInfo.InvariantCulture));
+ uniformLoadElement.SetAttribute("LoadType", "Permanent");
+ uniformLoadElement.SetAttribute("XEnd", uniformLoad.XEnd.ToString(CultureInfo.InvariantCulture));
+ uniformLoadElement.SetAttribute("XStart", uniformLoad.XStart.ToString(CultureInfo.InvariantCulture));
+
+ element.AppendChild(uniformLoadElement);
+ }
+ }
+ if (invalidList != null)
+ {
+ foreach (UniformLoad uniformLoad in invalidList)
+ {
+ if (!keys.ContainsKey(uniformLoad))
+ {
+ keys[uniformLoad] = keys.Count + 1;
+ }
+
+ XmlElement uniformLoadElement = doc.CreateElement("UniformLoad");
+ uniformLoadElement.SetAttribute("Key", keys[uniformLoad].ToString(CultureInfo.InvariantCulture));
+ uniformLoadElement.SetAttribute("Magnitude", uniformLoad.Pressure.ToString(CultureInfo.InvariantCulture));
+ uniformLoadElement.SetAttribute("DistributionAngle", uniformLoad.DistributionAngle.ToString(CultureInfo.InvariantCulture));
+ uniformLoadElement.SetAttribute("LoadType", "Permanent");
+ uniformLoadElement.SetAttribute("XEnd", uniformLoad.XEnd.ToString(CultureInfo.InvariantCulture));
+ uniformLoadElement.SetAttribute("XStart", uniformLoad.XStart.ToString(CultureInfo.InvariantCulture));
+
+ element.AppendChild(uniformLoadElement);
+ }
+ }
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteLocation(XmlDocument doc, XmlElement parent, Location stabilityLocation, string name)
+ {
+ if (stabilityLocation != null)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ element.SetAttribute("DikeSoilScenario", stabilityLocation.DikeSoilScenario.ToString());
+ element.SetAttribute("WaterLevelRiver", stabilityLocation.WaterLevelRiver.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("WaterLevelRiverAverage", stabilityLocation.WaterLevelRiverAverage.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("WaterLevelRiverLow", stabilityLocation.WaterLevelRiverLow.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("WaterLevelPolder", stabilityLocation.WaterLevelPolder.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("DrainageConstructionPresent", stabilityLocation.DrainageConstructionPresent.ToString(CultureInfo.InvariantCulture).ToLower());
+ element.SetAttribute("XCoordMiddleDrainageConstruction", stabilityLocation.XCoordMiddleDrainageConstruction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ZCoordMiddleDrainageConstruction", stabilityLocation.ZCoordMiddleDrainageConstruction.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("MinimumLevelPhreaticLineAtDikeTopRiver", stabilityLocation.MinimumLevelPhreaticLineAtDikeTopRiver.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("MinimumLevelPhreaticLineAtDikeTopPolder", stabilityLocation.MinimumLevelPhreaticLineAtDikeTopPolder.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("UseDefaultOffsets", stabilityLocation.UseDefaultOffsets.ToString(CultureInfo.InvariantCulture).ToLower());
+ element.SetAttribute("PlLineOffsetBelowPointBRingtoetsWti2017", stabilityLocation.PlLineOffsetBelowPointBRingtoetsWti2017.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("PlLineOffsetBelowDikeTopAtPolder", stabilityLocation.PlLineOffsetBelowDikeTopAtPolder.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("PlLineOffsetBelowShoulderBaseInside", stabilityLocation.PlLineOffsetBelowShoulderBaseInside.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("PlLineOffsetBelowDikeToeAtPolder", stabilityLocation.PlLineOffsetBelowDikeToeAtPolder.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("HeadInPLLine2Outwards", stabilityLocation.HeadInPlLine2Outwards.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("HeadInPLLine2Inwards", stabilityLocation.HeadInPlLine2Inwards.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("HeadInPLLine3", stabilityLocation.HeadInPlLine3.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("HeadInPLLine4", stabilityLocation.HeadInPlLine4.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("AdjustPl3And4ForUplift", stabilityLocation.AdjustPl3And4ForUplift.ToString(CultureInfo.InvariantCulture).ToLower());
+ element.SetAttribute("PenetrationLength", stabilityLocation.PenetrationLength.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("LeakageLengthOutwardsPl3", stabilityLocation.LeakageLengthOutwardsPl3.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("LeakageLengthInwardsPl3", stabilityLocation.LeakageLengthInwardsPl3.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("LeakageLengthOutwardsPl4", stabilityLocation.LeakageLengthOutwardsPl4.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("LeakageLengthInwardsPl4", stabilityLocation.LeakageLengthInwardsPl4.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+ }
+
+ private static void WriteSurfaceLine(XmlDocument doc, XmlElement parent, SurfaceLine2 surfaceLine, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+ XmlElement listElement = doc.CreateElement("CharacteristicPoints");
+ surfaceLine.Geometry.SyncPoints();
+ foreach (CharacteristicPoint point in surfaceLine.CharacteristicPoints)
+ {
+ XmlElement pointElement = doc.CreateElement("CharacteristicPoint");
+ pointElement.SetAttribute("CharacteristicPointType", point.CharacteristicPointType.ToString());
+ WritePoint(doc, pointElement, point.GeometryPoint, "GeometryPoint", keys);
+
+ listElement.AppendChild(pointElement);
+ }
+
+ element.AppendChild(listElement);
+ parent.AppendChild(element);
+ }
+
+ private static void WriteVersionInfo(XmlDocument doc, XmlElement parent, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+ element.SetAttribute("FileVersion", fileVersion.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ProgramVersion", Assembly.GetAssembly(typeof(WtiSerializer)).ImageRuntimeVersion);
+ parent.AppendChild(element);
+ }
+
+ private static void WriteSoilModel(XmlDocument doc, XmlElement parent, SoilModel soilModel, ConstructionStage stage, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+ XmlElement listElement = doc.CreateElement("Soils");
+
+ foreach (Soil soil in soilModel.Soils)
+ {
+ FixedSoilStress soilStress = stage.SoilStresses.FirstOrDefault(p => p.Soil == soil);
+
+ WriteSoil(doc, listElement, soil, soilStress, "Soil", keys);
+ }
+
+ element.AppendChild(listElement);
+ parent.AppendChild(element);
+ }
+
+ private static void WriteSoil(XmlDocument doc, XmlElement parent, Soil soil, FixedSoilStress soilStress, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ if (!keys.ContainsKey(soil))
+ {
+ keys[soil] = keys.Count + 1;
+ }
+
+ element.SetAttribute("Key", keys[soil].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Name", soil.Name);
+ element.SetAttribute("AbovePhreaticLevel", soil.AbovePhreaticLevel.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("BelowPhreaticLevel", soil.BelowPhreaticLevel.ToString(CultureInfo.InvariantCulture));
+
+ if (soil.Dilatancy == soil.FrictionAngle)
+ {
+ element.SetAttribute("DilatancyType", "Phi");
+ }
+ else if (soil.Dilatancy == -soil.FrictionAngle)
+ {
+ element.SetAttribute("DilatancyType", "MinusPhi");
+ }
+ else if (soil.Dilatancy == 0)
+ {
+ element.SetAttribute("DilatancyType", "Zero");
+ }
+ else
+ {
+ element.SetAttribute("DilatancyType", "Phi");
+ }
+
+ element.SetAttribute("Cohesion", soil.Cohesion.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("FrictionAngle", soil.FrictionAngle.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("RatioCuPc", soil.RatioCuPc.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("StrengthIncreaseExponent", soil.StrengthIncreaseExponent.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ShearStrengthModel", soil.ShearStrengthModel.ToString());
+
+ if (soilStress != null)
+ {
+ element.SetAttribute("UsePop", true.ToString().ToLower());
+ element.SetAttribute("POP", soilStress.CenterStressValue.POP.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("OCR", 1.ToString(CultureInfo.InvariantCulture));
+ }
+ else
+ {
+ element.SetAttribute("UsePop", false.ToString().ToLower());
+ element.SetAttribute("POP", 0.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("OCR", 1.ToString(CultureInfo.InvariantCulture));
+ }
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteSoilProfile(XmlDocument doc, XmlElement parent, SoilProfile2D soilProfile, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ WriteGeometry(doc, element, soilProfile.Geometry, "Geometry", keys);
+
+ XmlElement listElement = doc.CreateElement("Surfaces");
+
+ foreach (SoilLayer2D surface in soilProfile.Surfaces)
+ {
+ WriteSoilLayer(doc, listElement, surface, "Surface", keys);
+ }
+
+ element.AppendChild(listElement);
+ parent.AppendChild(element);
+ }
+
+ private static void WriteSoilLayer(XmlDocument doc, XmlElement parent, SoilLayer2D surface, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ if (!keys.ContainsKey(surface))
+ {
+ keys[surface] = keys.Count + 1;
+ }
+
+ element.SetAttribute("Soil", keys[surface.Soil].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Surface", keys[surface.GeometrySurface].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("IsAquifer", surface.IsAquifer.ToString().ToLower());
+ element.SetAttribute("WaterpressureInterpolationModel", surface.WaterpressureInterpolationModel.ToString());
+ element.SetAttribute("Key", keys[surface].ToString(CultureInfo.InvariantCulture).ToLower());
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteGeometry(XmlDocument doc, XmlElement parent, GeometryData geometry, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ XmlElement pointsElement = doc.CreateElement("Points");
+ foreach (Point2D point in geometry.Points)
+ {
+ WritePoint(doc, pointsElement, point, "Point", keys);
+ }
+ element.AppendChild(pointsElement);
+
+ XmlElement curvesElement = doc.CreateElement("Curves");
+ foreach (GeometryCurve curve in geometry.Curves)
+ {
+ WriteCurve(doc, curvesElement, curve, "Curve", keys);
+ }
+ element.AppendChild(curvesElement);
+ geometry.SynchronizeLoops();
+ XmlElement loopsElement = doc.CreateElement("Loops");
+ foreach (GeometryLoop loop in geometry.Loops)
+ {
+ WriteLoop(doc, loopsElement, loop, "Loop", keys);
+ }
+ element.AppendChild(loopsElement);
+
+ XmlElement surfacesElement = doc.CreateElement("Surfaces");
+ foreach (GeometrySurface surface in geometry.Surfaces)
+ {
+ WriteSurface(doc, surfacesElement, surface, "Surface", keys);
+ }
+ element.AppendChild(surfacesElement);
+
+ element.SetAttribute("Left", geometry.Left.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Right", geometry.Right.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Bottom", geometry.Bottom.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteSurface(XmlDocument doc, XmlElement parent, GeometrySurface surface, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ if (!keys.ContainsKey(surface))
+ {
+ keys[surface] = keys.Count + 1;
+ }
+
+ element.SetAttribute("Key", keys[surface].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("OuterLoop", keys[surface.OuterLoop].ToString(CultureInfo.InvariantCulture));
+
+ XmlElement innerLoopsElement = doc.CreateElement("InnerLoops");
+ foreach (GeometryLoop loop in surface.InnerLoops)
+ {
+ XmlElement loopElement = doc.CreateElement("InnerLoop");
+ loopElement.SetAttribute("Loop", keys[loop].ToString(CultureInfo.InvariantCulture));
+ innerLoopsElement.AppendChild(loopElement);
+ }
+ element.AppendChild(innerLoopsElement);
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteLoop(XmlDocument doc, XmlElement parent, GeometryLoop loop, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ if (!keys.ContainsKey(loop))
+ {
+ keys[loop] = keys.Count + 1;
+ }
+
+ element.SetAttribute("Key", keys[loop].ToString(CultureInfo.InvariantCulture));
+
+ XmlElement curvesElement = doc.CreateElement("Curves");
+ foreach (GeometryCurve curve in loop.CurveList)
+ {
+ XmlElement curveElement = doc.CreateElement("Curve");
+ curveElement.SetAttribute("Curve", keys[curve].ToString(CultureInfo.InvariantCulture));
+ curvesElement.AppendChild(curveElement);
+ }
+ element.AppendChild(curvesElement);
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteCurve(XmlDocument doc, XmlElement parent, GeometryCurve curve, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ if (!keys.ContainsKey(curve))
+ {
+ keys[curve] = keys.Count + 1;
+ }
+
+ element.SetAttribute("Key", keys[curve].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("HeadPoint", keys[curve.HeadPoint].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("EndPoint", keys[curve.EndPoint].ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WritePoint(XmlDocument doc, XmlElement parent, Point2D point, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ if (!keys.ContainsKey(point))
+ {
+ keys[point] = keys.Count + 1;
+ }
+
+ element.SetAttribute("Key", keys[point].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("X", point.X.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Z", point.Z.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WritePoint(XmlDocument doc, XmlElement parent, GeometryPoint point, string name, Dictionary keys)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ if (!keys.ContainsKey(point))
+ {
+ keys[point] = keys.Count + 1;
+ }
+
+ element.SetAttribute("Key", keys[point].ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("X", point.X.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Z", point.Z.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WritePoint2D(XmlDocument doc, XmlElement parent, GeometryPoint point, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ element.SetAttribute("X", point.X.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("Z", point.Z.ToString(CultureInfo.InvariantCulture));
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteStabilityResult(XmlDocument doc, StabilityAssessmentCalculationResult result, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+ element.SetAttribute("ModelOption", result.ModelOption.ToString());
+ element.SetAttribute("Succeeded", result.Calculated.ToString().ToLower());
+ element.SetAttribute("SafetyFactor", result.FactorOfSafety.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ZValue", result.ZValue.ToString(CultureInfo.InvariantCulture));
+
+ WriteLocation(doc, element, result.Location, "Location");
+ WriteLocation(doc, element, result.LocationDaily, "LocationDaily");
+
+ var waternets = new List();
+ var locations = new List();
+
+ waternets.Add(result.Waternet);
+ locations.Add(result.Location);
+ if (result.WaternetDaily != null)
+ {
+ waternets.Add(result.WaternetDaily);
+ locations.Add(result.LocationDaily);
+ }
+ WriteWaternet(doc, element, waternets, locations, new Dictionary());
+ WriteSlidingCurve(doc, element, result, "MinimumSafetyCurve");
+ WriteUsedUpliftVanCalculationGrid(doc, element, result, "UpliftVanCalculationGrid");
+ WriteUniformLoads(doc, element, result.TrafficLoad,new List(), "TrafficLoad", new Dictionary());
+ WriteConsolidationValuesForTrafficLoad(doc, element, result, "ConsolidationValues", new Dictionary());
+ WriteUsedForbiddenZones(doc, element, result, "ForbiddenZones");
+ WriteMessages(doc, element, result.Messages, "Messages");
+
+ doc.AppendChild(element);
+ }
+
+ private static void WriteSlidingCurve(XmlDocument doc, XmlElement parent, StabilityAssessmentCalculationResult result, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+ if (result.ModelOption == ModelOptions.Bishop || result.ModelOption == ModelOptions.Fellenius)
+ {
+ element.SetAttribute("CurveType", "Circle");
+ }
+ else if (result.ModelOption == ModelOptions.UpliftVan)
+ {
+ element.SetAttribute("CurveType", "DualCircle");
+ }
+ else if (result.ModelOption == ModelOptions.Spencer)
+ {
+ element.SetAttribute("CurveType", "Plane");
+ }
+
+ XmlElement slicesElement = doc.CreateElement("Slices");
+
+ if (result.Curve != null && result.Curve.Slices.Count > 0)
+ {
+ foreach (Slice slice in result.Curve.Slices)
+ {
+ XmlElement sliceElement = doc.CreateElement("Slice");
+
+ WritePoint2D(doc, sliceElement, new GeometryPoint(slice.TopLeftX, slice.TopLeftZ), "TopLeftPoint");
+ WritePoint2D(doc, sliceElement, new GeometryPoint(slice.TopRightX, slice.TopRightZ), "TopRightPoint");
+ WritePoint2D(doc, sliceElement, new GeometryPoint(slice.BottomLeftX, slice.BottomLeftZ), "BottomLeftPoint");
+ WritePoint2D(doc, sliceElement, new GeometryPoint(slice.BottomRightX, slice.BottomRightZ), "BottomRightPoint");
+
+ sliceElement.SetAttribute("Cohesion", slice.CohesionOutput.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("FrictionAngle", slice.PhiOutput.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("CriticalPressure", slice.PGrens.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("OCR", slice.OCR.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("POP", slice.POP.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("DegreeofConsolidationPorePressure", slice.DegreeofConsolidationPorePressure.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("PorePressureDueToDegreeOfConsolidationLoad", slice.PorePressureDueToDegreeOfConsolidationLoad.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("Dilatancy", slice.Dilatancy.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("ExternalLoad", slice.ExternalLoad.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("HydrostaticPorePressure", slice.HydrostaticPorePressure.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("LeftForce", slice.LeftForce.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("LeftForceAngle", slice.LeftForceAngle.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("LeftForceY", slice.LeftForceY.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("RightForce", slice.RightForce.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("RightForceAngle", slice.RightForceAngle.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("RightForceY", slice.RightForceY.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("LoadStress", slice.LoadStress.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("NormalStress", slice.NormalStress.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("PorePressure", slice.PoreOnSurface.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("HorizontalPorePressure", slice.HPoreOnSurface.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("VerticalPorePressure", slice.VPoreOnSurface.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("PiezometricPorePressure", slice.PiezometricPorePressure.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("EffectiveStress", slice.EffectiveStress.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("EffectiveStressDaily", slice.EffectiveStressDaily.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("ExcessPorePressure", slice.ExcessPorePressure.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("ShearStress", slice.ShearStress.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("SoilStress", slice.SoilStress.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("TotalPorePressure", slice.TotalPorePressure.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("TotalStress", slice.TotalStress.ToString(CultureInfo.InvariantCulture));
+ sliceElement.SetAttribute("Weight", slice.Weight.ToString(CultureInfo.InvariantCulture));
+ if (slice.ShearStrengthModel == ShearStrengthModel.None)
+ {
+ sliceElement.SetAttribute("ShearStrengthModel", ShearStrengthModel.CuCalculated.ToString());
+ }
+ else
+ {
+ sliceElement.SetAttribute("ShearStrengthModel", slice.ShearStrengthModel.ToString());
+ }
+ sliceElement.SetAttribute("Su", slice.SuOutput.ToString(CultureInfo.InvariantCulture));
+ slicesElement.AppendChild(sliceElement);
+ }
+ }
+
+ element.AppendChild(slicesElement);
+
+ var slidingDualCircle = result.Curve as SlidingDualCircle;
+ if (slidingDualCircle != null)
+ {
+ element.SetAttribute("ActiveCircleCenterX", slidingDualCircle.ActiveCircleCenterX.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ActiveCircleCenterZ", slidingDualCircle.ActiveCircleCenterY.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ActiveCircleRadius", slidingDualCircle.ActiveRadius.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("PassiveCircleCenterX", slidingDualCircle.PassiveCircleCenterX.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("PassiveCircleCenterZ", slidingDualCircle.PassiveCircleCenterY.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("PassiveCircleRadius", slidingDualCircle.PassiveRadius.ToString(CultureInfo.InvariantCulture));
+
+ element.SetAttribute("NonIteratedHorizontaleForce", slidingDualCircle.HorizontalForce0.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("NonIteratedActiveForce", slidingDualCircle.ActiveForce0.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("NonIteratedPassiveForce", slidingDualCircle.PassiveForce0.ToString(CultureInfo.InvariantCulture));
+
+ element.SetAttribute("IteratedHorizontaleForce", slidingDualCircle.HorizontalForce.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("IteratedActiveForce", slidingDualCircle.ActiveForce.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("IteratedPassiveForce", slidingDualCircle.PassiveForce.ToString(CultureInfo.InvariantCulture));
+
+ element.SetAttribute("DrivingMomentActive", slidingDualCircle.DrivingMomentActive.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("DrivingMomentPassive", slidingDualCircle.DrivingMomentPassive.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ResistingMomentActive", slidingDualCircle.ResistingMomentActive.ToString(CultureInfo.InvariantCulture));
+ element.SetAttribute("ResistingMomentPassive", slidingDualCircle.ResistingMomentPassive.ToString(CultureInfo.InvariantCulture));
+
+ element.SetAttribute("LeftCircleIsActive", true.ToString(CultureInfo.InvariantCulture).ToLower());
+ }
+ parent.AppendChild(element);
+ }
+
+ private static void WriteMessages(XmlDocument doc, XmlElement parent, List messages, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+
+ foreach (LogMessage message in messages)
+ {
+ XmlElement messageElement = doc.CreateElement("Message");
+ messageElement.SetAttribute("MessageType", message.MessageType.ToString());
+ messageElement.SetAttribute("Message", message.Message);
+ element.AppendChild(messageElement);
+ }
+
+ parent.AppendChild(element);
+ }
+
+ private static void WriteValidation(XmlDocument doc, IValidationResult[] validationResults, string name)
+ {
+ XmlElement element = doc.CreateElement(name);
+ XmlElement validationElement = doc.CreateElement("Validations");
+
+ foreach (IValidationResult result in validationResults)
+ {
+ XmlElement messageElement = doc.CreateElement("Validation");
+ messageElement.SetAttribute("Severity", result.MessageType.ToString());
+
+ string text = result.Text;
+ messageElement.SetAttribute("Message", text);
+ validationElement.AppendChild(messageElement);
+ }
+
+ element.AppendChild(validationElement);
+ doc.AppendChild(element);
+ }
+
+ ///
+ /// Indicates whether the stability model is limited to the requirements of WTI
+ ///
+ /// Stability model
+ /// Indication
+ public static bool CanSerialize(StabilityModel stabilityModel)
+ {
+ bool valid = stabilityModel.ModelOption == ModelOptions.Bishop || stabilityModel.ModelOption == ModelOptions.Spencer || stabilityModel.ModelOption == ModelOptions.UpliftVan;
+
+ foreach (Soil soil in stabilityModel.Soils)
+ {
+ valid &= soil.ShearStrengthModel == ShearStrengthModel.CPhi || soil.ShearStrengthModel == ShearStrengthModel.CuCalculated || soil.ShearStrengthModel == ShearStrengthModel.CuMeasured;
+ }
+
+ return valid;
+ }
+ }
+}
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 1964)
@@ -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.WTIStability.IO.WtiVersionInfo.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.WTIGeometry.xsd", false));
+ 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.WTISoilModel.xsd", false));
+ document.Schemas.Add(GetSchema("Deltares.WTIStability.IO.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);
+ }
+ }
+ }
+}