using System.Collections.Generic;
using System.Globalization;
using System.Xml;
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;
using Deltares.Standard.Logging;
using Deltares.Standard.Validation;
namespace Deltares.Stability.IO.WTI
{
public class WTISerializer
{
///
/// Serializes an stability model to an xml string obeying WTIStabilityModel.xsd or WTIStochasticStabilityModel.xsd
///
/// The model
/// Indication whether stochast information should be added
/// The xml string
public static string Serialize(StabilityModel model, bool includeStochasts)
{
XmlDocument doc = new XmlDocument();
doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
string name = includeStochasts ? "WTIStochasticStabilityModel" : "WTIStabilityModel";
bool useTransformer = TransformerManager.UseTransformer;
try
{
TransformerManager.UseTransformer = false;
WriteStabilityModel(doc, model, name, new Dictionary(), includeStochasts);
}
finally
{
TransformerManager.UseTransformer = useTransformer;
}
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();
doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
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();
doc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
string name = "WTIStabilityModelValidation";
WriteValidation(doc, validationResults, name);
return doc.InnerXml;
}
private static void WriteStabilityModel(XmlDocument doc, StabilityModel model, string name, Dictionary keys, bool includeStochasts)
{
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("OnlyMinimumSafetyCurve", model.OnlyMinimumSafetyCurve.ToString().ToLower());
element.SetAttribute("ModelUncertaintyParameter", model.ModelUncertaintyParameter.ToString(CultureInfo.InvariantCulture));
WriteSoilModel(doc, element, model.SoilModel, "SoilModel", keys, includeStochasts);
WriteSoilProfile(doc, element, model.SoilProfile, "SoilProfile", keys);
WriteSurfaceLine(doc, element, model.SurfaceLine2, "SurfaceLine", keys);
WriteLocation(doc, element, model.Location, "Location");
WritePreconsolidationStresses(doc, element, model, "PreconsolidationStresses", keys, includeStochasts);
WriteUniformLoads(doc, element, model.UniformLoads, "UniformLoads", keys);
if (includeStochasts)
{
WriteStochast(doc, element, model.ModelUncertaintyParameterStochast, "ModelUncertaintyParameterStochast");
}
WriteConsolidationValues(doc, element, model, "ConsolidationValues", keys);
WriteMultiplicationFactorsCPhiForUplift(doc, element, model.MultiplicationFactorsCPhiForUpliftList, "MultiplicationFactorsCPhiForUplift", keys);
WriteWaternet(doc, element, model.GeotechnicsData.CurrentWaternet, model.Location, "Waternet", keys);
WriteSpencerSlipPlanes(doc, element, model, "SpencerSlipPlanes", keys);
WriteUpliftVanCalculationGrid(doc, element, model, "UpliftVanCalculationGrid", keys);
WriteSlipPlaneConstraints(doc, element, model, "SlipPlaneConstraints", keys);
WriteGeneticAlgorithmOptions(doc, element, model.GeneticAlgorithmOptions, "GeneticAlgorithmOptions", keys);
WriteLevenbergMarquardtOptions(doc, element, model.LevenbergMarquardtOptions, "LevenbergMarquardtOptions", keys);
doc.AppendChild(element);
}
private static void WriteLevenbergMarquardtOptions(XmlDocument doc, XmlElement parent, LevenbergMarquardtOptions options, string name, Dictionary keys)
{
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, Dictionary keys)
{
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, string name, Dictionary keys)
{
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("XEntryMin", constraints.XEntryMin.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("XEntryMax", constraints.XEntryMax.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 WriteUpliftVanCalculationGrid(XmlDocument doc, XmlElement parent, StabilityModel model, string name, Dictionary keys)
{
SlipPlaneUpliftVan slipPlane = model.SlipPlaneUpliftVan;
XmlElement element = doc.CreateElement(name);
WriteCalculationGrid(doc, element, slipPlane.SlipPlaneLeftGrid, "LeftGrid", keys);
WriteCalculationGrid(doc, element, slipPlane.SlipPlaneRightGrid, "RightGrid", keys);
XmlElement tangentLineElement = doc.CreateElement("TangentLines");
tangentLineElement.SetAttribute("MaxSpacingBetweenBoundaries", slipPlane.SlipCircleTangentLine.MaxSpacingBetweenBoundaries.ToString(CultureInfo.InvariantCulture));
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.AutomaticAtBoundaries.ToString(CultureInfo.InvariantCulture).ToLower());
element.AppendChild(tangentLineElement);
element.SetAttribute("Auto", model.SlipCircle.Auto.ToString(CultureInfo.InvariantCulture).ToLower());
element.SetAttribute("Orientation", model.SlipCircle.Orientation.ToString());
element.SetAttribute("ActiveSide", slipPlane.ActiveSide.ToString());
parent.AppendChild(element);
}
private static void WriteCalculationGrid(XmlDocument doc, XmlElement parent, SlipCircleGrid grid, string name, Dictionary keys)
{
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));
element.SetAttribute("ZIntervalNumber", grid.ZIntervalNumber.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("XIntervalNumber", grid.XIntervalNumber.ToString(CultureInfo.InvariantCulture));
parent.AppendChild(element);
}
private static void WriteSpencerSlipPlanes(XmlDocument doc, XmlElement parent, StabilityModel model, string name, Dictionary keys)
{
XmlElement element = doc.CreateElement(name);
XmlElement upperElement = doc.CreateElement("UpperSlipPlane");
if (model.SlipPlanes.Count > 0)
{
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)
{
foreach (GeometryPoint point in model.SlipPlanes[1].Points)
{
WritePoint(doc, lowerElement, point, "Point", keys);
}
}
element.AppendChild(lowerElement);
element.SetAttribute("Auto", model.AutoGenerateGeneticSpencer.ToString(CultureInfo.InvariantCulture).ToLower());
element.SetAttribute("SlipPlanePosition", model.SlipPlanePosition.ToString());
parent.AppendChild(element);
}
private static void WriteWaternet(XmlDocument doc, XmlElement parent, Waternet waternet, Location location, string name, Dictionary keys)
{
XmlElement element = doc.CreateElement(name);
if (waternet.PhreaticLine == null)
{
waternet.PhreaticLine = new PhreaticLine();
waternet.PhreaticLine.Points.Add(new GeometryPoint(0,0,0));
}
WriteWaternetLine(doc, element, waternet.PhreaticLine, "PhreaticLine", keys);
XmlElement headLinesElement = doc.CreateElement("HeadLines");
foreach (HeadLine headLine in waternet.HeadLineList)
{
WriteWaternetLine(doc, headLinesElement, headLine, "HeadLine", keys);
}
element.AppendChild(headLinesElement);
XmlElement waternetLinesElement = doc.CreateElement("WaternetLines");
foreach (WaternetLine waternetLine in waternet.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);
}
}
element.AppendChild(waternetLinesElement);
element.SetAttribute("UnitWeightWater", waternet.UnitWeight.ToString(CultureInfo.InvariantCulture).ToLower());
element.SetAttribute("IsGenerated", (location.WaternetCreationMode == WaternetCreationMode.CreateWaternet).ToString(CultureInfo.InvariantCulture).ToLower());
parent.AppendChild(element);
}
private static void WriteWaternetLine(XmlDocument doc, XmlElement parent, GeometryPointString waternetLine, string name, Dictionary keys)
{
XmlElement element = doc.CreateElement(name);
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, Dictionary keys)
{
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);
if (!keys.ContainsKey(model.ConsolidationLoad))
{
keys[model.ConsolidationLoad] = keys.Count + 1;
}
XmlElement loadElement = doc.CreateElement("ConsolidationLoad");
loadElement.SetAttribute("Key", keys[model.ConsolidationLoad].ToString(CultureInfo.InvariantCulture));
element.AppendChild(loadElement);
foreach (ConsolidationValue consolidationValue in model.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 WritePreconsolidationStresses(XmlDocument doc, XmlElement parent, StabilityModel stabilityModel, string name, Dictionary keys, bool includeStochasts)
{
XmlElement element = doc.CreateElement(name);
foreach (PreConsolidationStress stress in stabilityModel.SoilProfile.PreconsolidationStresses)
{
XmlElement stressElement = doc.CreateElement("PreconsolidationStress");
GeometryPoint point = new GeometryPoint(stress.X, stress.Y, stress.Z);
WritePoint(doc, stressElement, point, "Point", keys);
if (includeStochasts)
{
WriteStochast(doc, stressElement, stress.StressStochast, "StressStochast");
}
stressElement.SetAttribute("StressValue", stress.StressValue.ToString(CultureInfo.InvariantCulture));
element.AppendChild(stressElement);
}
element.SetAttribute("PreconsolidationStressModelFactor", stabilityModel.PreconsolidationStressModelFactor.ToString(CultureInfo.InvariantCulture));
parent.AppendChild(element);
}
private static void WriteUniformLoads(XmlDocument doc, XmlElement parent, List list, string name, Dictionary keys)
{
XmlElement element = doc.CreateElement(name);
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.Magnitude.ToString(CultureInfo.InvariantCulture));
uniformLoadElement.SetAttribute("DistributionAngle", uniformLoad.DistributionAngle.ToString(CultureInfo.InvariantCulture));
uniformLoadElement.SetAttribute("LoadType", uniformLoad.LoadType.ToString());
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, StabilityLocation stabilityLocation, string name)
{
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");
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 WriteSoilModel(XmlDocument doc, XmlElement parent, SoilModel soilModel, string name, Dictionary keys, bool includeStochasts)
{
XmlElement element = doc.CreateElement(name);
XmlElement listElement = doc.CreateElement("Soils");
foreach (Soil soil in soilModel.Soils)
{
WriteSoil(doc, listElement, soil, "Soil", keys, includeStochasts);
}
element.AppendChild(listElement);
parent.AppendChild(element);
}
private static void WriteSoil(XmlDocument doc, XmlElement parent, Soil soil, string name, Dictionary keys, bool includeStochasts)
{
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));
element.SetAttribute("DilatancyType", soil.DilatancyType.ToString());
element.SetAttribute("Cohesion", soil.Cohesion.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("FrictionAngle", soil.FrictionAngle.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("UsePop", soil.UsePop.ToString().ToLower());
element.SetAttribute("POP", soil.POP.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("RatioCuPc", soil.RatioCuPc.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("StrengthIncreaseExponent", soil.StrengthIncreaseExponent.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("OCR", soil.OCR.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("ShearStrengthModel", soil.ShearStrengthModel.ToString());
if (includeStochasts)
{
WriteStochast(doc, element, soil.CohesionStochast, "CohesionStochast");
WriteStochast(doc, element, soil.FrictionAngleStochast, "FrictionAngleStochast");
WriteStochast(doc, element, soil.POPStochast, "POPStochast");
WriteStochast(doc, element, soil.RatioCuPcStochast, "RatioCuPcStochast");
WriteStochast(doc, element, soil.StrengthIncreaseExponentStochast, "StrengthIncreaseExponentStochast");
}
parent.AppendChild(element);
}
private static void WriteStochast(XmlDocument doc, XmlElement parent, Stochast stochast, string name)
{
XmlElement element = doc.CreateElement(name);
element.SetAttribute("DistributionType", stochast.DistributionType.ToString());
element.SetAttribute("Mean", stochast.Mean.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("Deviation", stochast.Deviation.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("Shift", stochast.Shift.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("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 (GeometryPoint 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);
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, 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, Point2D point, string name)
{
XmlElement element = doc.CreateElement(name);
element.SetAttribute("X", point.X.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("Z", point.Y.ToString(CultureInfo.InvariantCulture));
parent.AppendChild(element);
}
private static void WriteStabilityResult(XmlDocument doc, StabilityAssessmentCalculationResult result, string name)
{
XmlElement element = doc.CreateElement(name);
element.SetAttribute("Succeeded", result.Calculated.ToString().ToLower());
element.SetAttribute("SafetyFactor", result.FactorOfSafety.ToString(CultureInfo.InvariantCulture));
element.SetAttribute("ZValue", result.ZValue.ToString(CultureInfo.InvariantCulture));
WriteWaternet(doc, element, result.Waternet, result.Location, "Waternet", new Dictionary());
WriteSlidingCurve(doc, element, result.Curve, "MinimumSafetyCurve");
WriteMessages(doc, element, result.Messages, "Messages");
doc.AppendChild(element);
}
private static void WriteSlidingCurve(XmlDocument doc, XmlElement parent, SlidingCurve slidingCurve, string name)
{
XmlElement element = doc.CreateElement(name);
XmlElement slicesElement = doc.CreateElement("Slices");
if (slidingCurve.Slices.Count > 0)
{
foreach (Slice slice in slidingCurve.Slices)
{
XmlElement sliceElement = doc.CreateElement("Slice");
WritePoint2D(doc, sliceElement, slice.TopLeft, "TopLeftPoint");
WritePoint2D(doc, sliceElement, slice.TopRight, "TopRightPoint");
WritePoint2D(doc, sliceElement, slice.BottomLeft, "BottomLeftPoint");
WritePoint2D(doc, sliceElement, slice.BottomRight, "BottomRightPoint");
sliceElement.SetAttribute("Cohesion", slice.Cohesion.ToString(CultureInfo.InvariantCulture));
sliceElement.SetAttribute("FrictionAngle", slice.Phi.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("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));
slicesElement.AppendChild(sliceElement);
}
}
element.AppendChild(slicesElement);
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;
if (result.Subject != null)
{
text = result.Subject + ": " + 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 (Stochast stochast in stabilityModel.Stochasts)
{
valid &= stochast.DistributionType == DistributionType.Deterministic || stochast.DistributionType == DistributionType.Normal || stochast.DistributionType == DistributionType.LogNormal;
}
foreach (Soil soil in stabilityModel.Soils)
{
valid &= soil.ShearStrengthModel == ShearStrengthModel.CPhi || soil.ShearStrengthModel == ShearStrengthModel.CuCalculated || soil.ShearStrengthModel == ShearStrengthModel.CuMeasured;
}
return valid;
}
}
}