using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Reflection; using System.Xml; using System.Xml.Schema; using Deltares.Geometry; using Deltares.Geotechnics; using Deltares.Geotechnics.Consolidation; using Deltares.Geotechnics.Soils; using Deltares.Geotechnics.SurfaceLines; using Deltares.Geotechnics.WaternetCreator; using Deltares.Mathematics; using Deltares.Probabilistic; using Deltares.Standard.Logging; namespace Deltares.Stability.IO.WTI { public class WTIDeserializer { public static StabilityModel Deserialize(string xml, bool includeStochasts) { XmlDocument document = new XmlDocument(); document.LoadXml(xml); document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.WTIGeometry.xsd", false)); document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.WTIWaternetDefinition.xsd", false)); document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.WTIWaternet.xsd", false)); document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.WTISoilModel.xsd", false)); if (includeStochasts) { document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.WTIStabilityModel.xsd", false)); document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.WTIStochasticStabilityModel.xsd", true)); } else { document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.WTIStabilityModel.xsd", true)); } // the following call to Validate succeeds. document.Validate(ValidationEventHandler); // if survived here, the xml is all right string name = includeStochasts ? "WTIStochasticStabilityModel" : "WTIStabilityModel"; StabilityModel stabilityModel = new StabilityModel(); stabilityModel.CalculationModel = CalculationModel.RTO; ReadStabilityModel(GetElement(document, name), stabilityModel, new Dictionary(), includeStochasts); return stabilityModel; } public static StabilityAssessmentCalculationResult DeserializeResult(string xml) { XmlDocument document = new XmlDocument(); document.LoadXml(xml); document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.WTIWaternet.xsd", false)); document.Schemas.Add(GetSchema("Deltares.Stability.IO.WTI.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; } private static XmlSchema GetSchema(string path, bool validate) { Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path); if (validate) { return XmlSchema.Read(stream, ValidationEventHandler); } else { return XmlSchema.Read(stream, 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, StabilityModel model, Dictionary keys, bool includeStochasts) { model.MoveGrid = Boolean.Parse(element.GetAttribute("MoveGrid")); model.MaximumSliceWidth = Double.Parse(element.GetAttribute("MaximumSliceWidth"), CultureInfo.InvariantCulture); model.SearchAlgorithm = (SearchAlgorithm)Enum.Parse(typeof(SearchAlgorithm), element.GetAttribute("SearchAlgorithm")); model.ModelOption = (ModelOptions)Enum.Parse(typeof(ModelOptions), element.GetAttribute("ModelOption")); model.OnlyMinimumSafetyCurve = Boolean.Parse(element.GetAttribute("OnlyMinimumSafetyCurve")); model.ModelUncertaintyParameter = Double.Parse(element.GetAttribute("ModelUncertaintyParameter"), CultureInfo.InvariantCulture); ReadSoilModel(GetElement(element, "SoilModel"), model.SoilModel, keys, includeStochasts); ReadSoilProfile(GetElement(element, "SoilProfile"), model.SoilProfile, keys); ReadSurfaceLine(GetElement(element, "SurfaceLine"), model.SurfaceLine2, keys); ReadLocation(GetElement(element, "Location"), model.Location); ReadPreconsolidationStresses(GetElement(element, "PreconsolidationStresses"), model, keys, includeStochasts); ReadUniformLoads(GetElement(element, "UniformLoads"), model.UniformLoads, keys); if (includeStochasts) { ReadStochast(GetElement(element, "ModelUncertaintyParameterStochast"), model.ModelUncertaintyParameterStochast); } ReadConsolidationValues(GetElement(element, "ConsolidationValues"), model, keys); ReadMultiplicationFactorsCPhiForUplift(GetElement(element, "MultiplicationFactorsCPhiForUplift"), model.MultiplicationFactorsCPhiForUpliftList, keys); ReadWaternet(GetElement(element, "Waternet"), model.GeotechnicsData.CurrentWaternet, model.Location, keys); ReadSpencerSlipPlanes(GetElement(element, "SpencerSlipPlanes"), model, keys); ReadUpliftVanCalculationGrid(GetElement(element, "UpliftVanCalculationGrid"), model, keys); ReadSlipPlaneConstraints(GetElement(element, "SlipPlaneConstraints"), model, keys); ReadGeneticAlgorithmOptions(GetElement(element, "GeneticAlgorithmOptions"), model.GeneticAlgorithmOptions, keys); ReadLevenbergMarquardtOptions(GetElement(element, "LevenbergMarquardtOptions"), model.LevenbergMarquardtOptions, keys); } private static void ReadLevenbergMarquardtOptions(XmlElement element, LevenbergMarquardtOptions options, Dictionary keys) { 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, Dictionary keys) { 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, Dictionary keys) { SlipplaneConstraints constraints = model.SlipPlaneConstraints; constraints.SlipPlaneMinDepth = Double.Parse(element.GetAttribute("SlipPlaneMinDepth"), CultureInfo.InvariantCulture); constraints.SlipPlaneMinLength = Double.Parse(element.GetAttribute("SlipPlaneMinLength"), CultureInfo.InvariantCulture); constraints.XEntryMin = Double.Parse(element.GetAttribute("XEntryMin"), CultureInfo.InvariantCulture); constraints.XEntryMax = 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 ReadUpliftVanCalculationGrid(XmlElement element, StabilityModel model, Dictionary keys) { SlipPlaneUpliftVan slipPlane = model.SlipPlaneUpliftVan; ReadCalculationGrid(GetElement(element, "LeftGrid"), slipPlane.SlipPlaneLeftGrid, keys); ReadCalculationGrid(GetElement(element, "RightGrid"), slipPlane.SlipPlaneRightGrid, keys); XmlElement tangentElement = GetElement(element, "TangentLines"); slipPlane.SlipCircleTangentLine.MaxSpacingBetweenBoundaries = Double.Parse(tangentElement.GetAttribute("MaxSpacingBetweenBoundaries"), CultureInfo.InvariantCulture); 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.AutomaticAtBoundaries = Boolean.Parse(tangentElement.GetAttribute("AutomaticAtBoundaries")); model.SlipCircle.Auto = Boolean.Parse(element.GetAttribute("Auto")); model.SlipCircle.Orientation = (GridOrientation)Enum.Parse(typeof(GridOrientation), element.GetAttribute("Orientation")); slipPlane.ActiveSide = (ActiveSideType)Enum.Parse(typeof(ActiveSideType), element.GetAttribute("ActiveSide")); } private static void ReadCalculationGrid(XmlElement element, SlipCircleGrid grid, Dictionary keys) { 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); grid.ZIntervalNumber = Int32.Parse(element.GetAttribute("ZIntervalNumber"), CultureInfo.InvariantCulture); grid.XIntervalNumber = Int32.Parse(element.GetAttribute("XIntervalNumber"), CultureInfo.InvariantCulture); } private static void ReadSpencerSlipPlanes(XmlElement element, StabilityModel model, 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)); } 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.AutoGenerateGeneticSpencer = Boolean.Parse(element.GetAttribute("Auto")); model.SlipPlanePosition = (SlipPlanePosition)Enum.Parse(typeof(SlipPlanePosition), element.GetAttribute("SlipPlanePosition")); } private static void ReadWaternet(XmlElement element, Waternet waternet, Location location, Dictionary keys) { 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)); } } private static void ReadMultiplicationFactorsCPhiForUplift(XmlElement element, List list, Dictionary keys) { list.Clear(); foreach (XmlElement factorElement in GetElements(element, "MultiplicationFactorsCPhiForUplift")) { MultiplicationFactorOnCPhiForUplift factor = new MultiplicationFactorOnCPhiForUplift(); factor.UpliftFactor = Double.Parse(factorElement.GetAttribute("UpliftFactor"), CultureInfo.InvariantCulture); factor.MultiplicationFactor = Double.Parse(factorElement.GetAttribute("MultiplicationFactor"), CultureInfo.InvariantCulture); list.Add(factor); } } private static void ReadConsolidationValues(XmlElement element, StabilityModel model, Dictionary keys) { XmlElement loadElemet = GetElement(element, "ConsolidationLoad"); keys[Int32.Parse(loadElemet.GetAttribute("Key"), CultureInfo.InvariantCulture)] = model.ConsolidationLoad; foreach (XmlElement consElement in GetElements(element, "ConsolidationValue")) { ConsolidationValue consolidation = new ConsolidationValue(); consolidation.Consolidator = keys[Int32.Parse(consElement.GetAttribute("Consolidator"), CultureInfo.InvariantCulture)]; consolidation.Consolidated = keys[Int32.Parse(consElement.GetAttribute("Consolidated"), CultureInfo.InvariantCulture)]; consolidation.Value = Double.Parse(consElement.GetAttribute("Value"), CultureInfo.InvariantCulture); model.XMLConsolidationValues.Add(consolidation); } } private static void ReadPreconsolidationStresses(XmlElement element, StabilityModel stabilityModel, Dictionary keys, bool includeStochasts) { stabilityModel.SoilProfile.PreconsolidationStresses.Clear(); foreach (XmlElement stressElement in GetElements(element, "PreconsolidationStress")) { PreConsolidationStress stress = new PreConsolidationStress(); GeometryPoint point = ReadPoint(GetElement(stressElement, "Point"), keys); stress.X = point.X; stress.Y = point.Y; stress.Z = point.Z; if (includeStochasts) { ReadStochast(GetElement(stressElement, "StressStochast"), stress.StressStochast); } stress.StressValue = Double.Parse(stressElement.GetAttribute("StressValue"), CultureInfo.InvariantCulture); stabilityModel.SoilProfile.PreconsolidationStresses.Add(stress); } stabilityModel.PreconsolidationStressModelFactor = Double.Parse(element.GetAttribute("PreconsolidationStressModelFactor"), CultureInfo.InvariantCulture); } private static void ReadUniformLoads(XmlElement element, List list, Dictionary keys) { list.Clear(); foreach (XmlElement uniformLoadElement in GetElements(element, "UniformLoad")) { UniformLoad uniformLoad = new UniformLoad(); uniformLoad.Magnitude = Double.Parse(uniformLoadElement.GetAttribute("Magnitude"), CultureInfo.InvariantCulture); uniformLoad.DistributionAngle = Double.Parse(uniformLoadElement.GetAttribute("DistributionAngle"), CultureInfo.InvariantCulture); uniformLoad.LoadType = (UniformLoad.LoadTypeEnum)Enum.Parse(typeof(UniformLoad.LoadTypeEnum), uniformLoadElement.GetAttribute("LoadType")); uniformLoad.XEnd = Double.Parse(uniformLoadElement.GetAttribute("XEnd"), CultureInfo.InvariantCulture); uniformLoad.XStart = Double.Parse(uniformLoadElement.GetAttribute("XStart"), CultureInfo.InvariantCulture); list.Add(uniformLoad); } } private static void ReadLocation(XmlElement element, StabilityLocation 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); } private static void ReadSurfaceLine(XmlElement element, SurfaceLine2 surfaceLine, Dictionary keys) { const double delta = 0.000001; surfaceLine.CharacteristicPoints.Clear(); foreach (XmlElement charNode in GetElements(GetElement(element, "CharacteristicPoints"), "CharacteristicPoint")) { CharacteristicPoint charPoint = new CharacteristicPoint(); charPoint.GeometryPoint = ReadPoint(GetElement(charNode, "GeometryPoint"), keys); double z = charPoint.Z; charPoint.CharacteristicPointType = (CharacteristicPointType)Enum.Parse(typeof(CharacteristicPointType), charNode.GetAttribute("CharacteristicPointType")); surfaceLine.CharacteristicPoints.Add(charPoint); // Reassign Z-Value, bug in surface line charPoint.Z = z; } } private static void ReadSoilModel(XmlElement element, SoilModel soilModel, Dictionary keys, bool includeStochasts) { soilModel.Soils.Clear(); foreach (XmlElement soilNode in GetElements(GetElement(element, "Soils"), "Soil")) { Soil soil = new Soil(); ReadSoil(soilNode, soil, keys, includeStochasts); soilModel.Soils.Add(soil); } } private static void ReadSoil(XmlElement element, Soil soil, Dictionary keys, bool includeStochasts) { 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.DilatancyType = (DilatancyType)Enum.Parse(typeof(DilatancyType), element.GetAttribute("DilatancyType")); soil.Cohesion = Double.Parse(element.GetAttribute("Cohesion"), CultureInfo.InvariantCulture); soil.FrictionAngle = Double.Parse(element.GetAttribute("FrictionAngle"), CultureInfo.InvariantCulture); soil.UsePop = Boolean.Parse(element.GetAttribute("UsePop")); soil.POP = Double.Parse(element.GetAttribute("POP"), CultureInfo.InvariantCulture); soil.RatioCuPc = Double.Parse(element.GetAttribute("RatioCuPc"), CultureInfo.InvariantCulture); soil.StrengthIncreaseExponent = Double.Parse(element.GetAttribute("StrengthIncreaseExponent"), CultureInfo.InvariantCulture); soil.OCR = Double.Parse(element.GetAttribute("OCR"), CultureInfo.InvariantCulture); soil.UseDefaultShearStrengthModel = false; soil.ShearStrengthModel = (ShearStrengthModel)Enum.Parse(typeof(ShearStrengthModel), element.GetAttribute("ShearStrengthModel")); if (includeStochasts) { ReadStochast(GetElement(element, "CohesionStochast"), soil.CohesionStochast); ReadStochast(GetElement(element, "FrictionAngleStochast"), soil.FrictionAngleStochast); ReadStochast(GetElement(element, "POPStochast"), soil.POPStochast); ReadStochast(GetElement(element, "RatioCuPcStochast"), soil.RatioCuPcStochast); ReadStochast(GetElement(element, "StrengthIncreaseExponentStochast"), soil.StrengthIncreaseExponentStochast); } } private static void ReadStochast(XmlElement element, Stochast stochast) { stochast.DistributionType = (DistributionType)Enum.Parse(typeof(DistributionType), element.GetAttribute("DistributionType")); stochast.Mean = Double.Parse(element.GetAttribute("Mean"), CultureInfo.InvariantCulture); stochast.Deviation = Double.Parse(element.GetAttribute("Deviation"), CultureInfo.InvariantCulture); stochast.Shift = Double.Parse(element.GetAttribute("Shift"), 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")); } 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 = (GeometryPoint)keys[Int32.Parse(element.GetAttribute("HeadPoint"), CultureInfo.InvariantCulture)]; curve.EndPoint = (GeometryPoint)keys[Int32.Parse(element.GetAttribute("EndPoint"), CultureInfo.InvariantCulture)]; return curve; } } private static GeometryPoint ReadPoint(XmlElement element, Dictionary keys) { int key = Int32.Parse(element.GetAttribute("Key"), CultureInfo.InvariantCulture); if (keys.ContainsKey(key)) { 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); return point; } } private static Point2D ReadPoint2D(XmlElement element) { Point2D point = new Point2D(); point.X = Double.Parse(element.GetAttribute("X"), CultureInfo.InvariantCulture); point.Y = Double.Parse(element.GetAttribute("Z"), CultureInfo.InvariantCulture); return point; } private static void ReadStabilityModelResult(XmlElement element, StabilityAssessmentCalculationResult result) { 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(GetElement(element, "MinimumSafetyCurve")); result.Location = new StabilityLocation(); result.Waternet = new Waternet(); ReadWaternet(GetElement(element, "Waternet"), result.Waternet, result.Location, new Dictionary()); ReadMessages(GetElement(element, "Messages"), result.Messages); } private static SlidingCurve ReadSlidingCurve(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) { SlidingDualCircle slidingDualCircle = (SlidingDualCircle)slidingCurve; slidingDualCircle.ActiveCircle.X = Double.Parse(element.GetAttribute("ActiveCircleCenterX"), CultureInfo.InvariantCulture); slidingDualCircle.ActiveCircle.Y = 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.Y = 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); slidingDualCircle.LeftCircleIsActive = Boolean.Parse(element.GetAttribute("LeftCircleIsActive")); } foreach (XmlElement sliceElement in GetElements(GetElement(element, "Slices"), "Slice")) { Slice slice = new Slice(); slice.Index = slidingCurve.Slices.Count; slice.TopLeft = ReadPoint2D(GetElement(sliceElement, "TopLeftPoint")); slice.TopRight = ReadPoint2D(GetElement(sliceElement, "TopRightPoint")); slice.BottomLeft = ReadPoint2D(GetElement(sliceElement, "BottomLeftPoint")); slice.BottomRight = ReadPoint2D(GetElement(sliceElement, "BottomRightPoint")); slice.Cohesion = Double.Parse(sliceElement.GetAttribute("Cohesion"), CultureInfo.InvariantCulture); slice.Phi = Double.Parse(sliceElement.GetAttribute("FrictionAngle"), CultureInfo.InvariantCulture); slice.PGrens = Double.Parse(sliceElement.GetAttribute("CriticalPressure"), CultureInfo.InvariantCulture); slice.OCR = Double.Parse(sliceElement.GetAttribute("OCR"), CultureInfo.InvariantCulture); slice.POP = Double.Parse(sliceElement.GetAttribute("POP"), CultureInfo.InvariantCulture); slice.DegreeofConsolidationPorePressure = Double.Parse(sliceElement.GetAttribute("DegreeofConsolidationPorePressure"), CultureInfo.InvariantCulture); slice.PorePressureDueToDegreeOfConsolidationLoad = Double.Parse(sliceElement.GetAttribute("PorePressureDueToDegreeOfConsolidationLoad"), CultureInfo.InvariantCulture); slice.Dilatancy = Double.Parse(sliceElement.GetAttribute("Dilatancy"), CultureInfo.InvariantCulture); slice.ExternalLoad = Double.Parse(sliceElement.GetAttribute("ExternalLoad"), CultureInfo.InvariantCulture); slice.HydrostaticPorePressure = Double.Parse(sliceElement.GetAttribute("HydrostaticPorePressure"), CultureInfo.InvariantCulture); slice.LeftForce = Double.Parse(sliceElement.GetAttribute("LeftForce"), CultureInfo.InvariantCulture); slice.LeftForceAngle = Double.Parse(sliceElement.GetAttribute("LeftForceAngle"), CultureInfo.InvariantCulture); slice.LeftForceY = Double.Parse(sliceElement.GetAttribute("LeftForceY"), CultureInfo.InvariantCulture); slice.RightForce = Double.Parse(sliceElement.GetAttribute("RightForce"), CultureInfo.InvariantCulture); slice.RightForceAngle = Double.Parse(sliceElement.GetAttribute("RightForceAngle"), CultureInfo.InvariantCulture); slice.RightForceY = Double.Parse(sliceElement.GetAttribute("RightForceY"), CultureInfo.InvariantCulture); slice.LoadStress = Double.Parse(sliceElement.GetAttribute("LoadStress"), CultureInfo.InvariantCulture); slice.NormalStress = Double.Parse(sliceElement.GetAttribute("NormalStress"), CultureInfo.InvariantCulture); slice.PoreOnSurface = Double.Parse(sliceElement.GetAttribute("PorePressure"), CultureInfo.InvariantCulture); slice.HPoreOnSurface = Double.Parse(sliceElement.GetAttribute("HorizontalPorePressure"), CultureInfo.InvariantCulture); slice.VPoreOnSurface = Double.Parse(sliceElement.GetAttribute("VerticalPorePressure"), CultureInfo.InvariantCulture); slice.PiezometricPorePressure = Double.Parse(sliceElement.GetAttribute("PiezometricPorePressure"), CultureInfo.InvariantCulture); slice.EffectiveStress = Double.Parse(sliceElement.GetAttribute("EffectiveStress"), CultureInfo.InvariantCulture); slice.ExcessPorePressure = Double.Parse(sliceElement.GetAttribute("ExcessPorePressure"), CultureInfo.InvariantCulture); slice.ShearStress = Double.Parse(sliceElement.GetAttribute("ShearStress"), CultureInfo.InvariantCulture); slice.SoilStress = Double.Parse(sliceElement.GetAttribute("SoilStress"), CultureInfo.InvariantCulture); slice.TotalPorePressure = Double.Parse(sliceElement.GetAttribute("TotalPorePressure"), CultureInfo.InvariantCulture); slice.TotalStress = Double.Parse(sliceElement.GetAttribute("TotalStress"), CultureInfo.InvariantCulture); slice.Weight = Double.Parse(sliceElement.GetAttribute("Weight"), CultureInfo.InvariantCulture); 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.Message = pointElement.GetAttribute("Message"); message.MessageType = (LogMessageType)Enum.Parse(typeof(LogMessageType), pointElement.GetAttribute("MessageType")); messages.Add(message); } } } }