// 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 a stability model validation to an xml string obeying WTIStabilityModelValidation.xsd
///
/// The validation 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.AlmostEquals(soil.FrictionAngle))
{
element.SetAttribute("DilatancyType", "Phi");
}
else if (soil.Dilatancy.AlmostEquals(-soil.FrictionAngle))
{
element.SetAttribute("DilatancyType", "MinusPhi");
}
else if (soil.Dilatancy.AlmostEquals(0.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");
// Ignore innerloops, they are not needed for the calculation and are thrown away in
// MacroStability.GeometryData.SynchronizeLoops()
// 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;
}
}
}