// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using Core.Common.Base.IO;
using Ringtoets.Common.IO.Configurations;
using Ringtoets.Common.IO.Configurations.Helpers;
using Ringtoets.Common.IO.Configurations.Import;
using Ringtoets.MacroStabilityInwards.IO.Configurations.Helpers;
using Ringtoets.MacroStabilityInwards.IO.Properties;
using RingtoetsCommonIOResources = Ringtoets.Common.IO.Properties.Resources;
namespace Ringtoets.MacroStabilityInwards.IO.Configurations
{
///
/// This class reads a macro stability inwards calculation configuration from XML and creates
/// a collection of corresponding , typically containing one
/// or more .
///
public class MacroStabilityInwardsCalculationConfigurationReader
: CalculationConfigurationReader
{
private const string scenarioSchemaName = "ScenarioSchema.xsd";
private const string waternetCreatorSchemaSchemaName = "MacroStabiliteitBinnenwaartsWaterspanningenSchema.xsd";
private const string slopeStabilityZonesSchemaName = "MacroStabiliteitBinnenwaartsZonesSchema.xsd";
private const string slopeStabilityGridsSchemaName = "MacroStabiliteitBinnenwaartsGridsSchema.xsd";
///
/// Creates a new instance of .
///
/// The file path to the XML file.
/// Thrown when is invalid.
/// Thrown when:
///
/// - points to a file that does not exist.
/// - points to a file that does not contain valid XML.
/// - points to a file that does not pass the schema validation.
/// - points to a file that does not contain configuration elements.
///
///
internal MacroStabilityInwardsCalculationConfigurationReader(string xmlFilePath)
: base(xmlFilePath,
Resources.MacroStabiliteitBinnenwaartsConfiguratieSchema,
new Dictionary
{
{
scenarioSchemaName, RingtoetsCommonIOResources.ScenarioSchema
},
{
waternetCreatorSchemaSchemaName, Resources.MacroStabiliteitBinnenwaartsWaterspanningenSchema
},
{
slopeStabilityZonesSchemaName, Resources.MacroStabiliteitBinnenwaartsZonesSchema
},
{
slopeStabilityGridsSchemaName, Resources.MacroStabiliteitBinnenwaartsGridsSchema
}
}) {}
protected override MacroStabilityInwardsCalculationConfiguration ParseCalculationElement(XElement calculationElement)
{
var configuration = new MacroStabilityInwardsCalculationConfiguration(
calculationElement.Attribute(ConfigurationSchemaIdentifiers.NameAttribute).Value)
{
AssessmentLevel = GetAssessmentLevel(calculationElement),
HydraulicBoundaryLocationName = calculationElement.GetHydraulicBoundaryLocationName(),
SurfaceLineName = calculationElement.GetStringValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.SurfaceLineElement),
StochasticSoilModelName = calculationElement.GetStringValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.StochasticSoilModelElement),
StochasticSoilProfileName = calculationElement.GetStringValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.StochasticSoilProfileElement),
DikeSoilScenario = (ConfigurationDikeSoilScenario?)
calculationElement.GetConvertedValueFromDescendantStringElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.DikeSoilScenarioElement),
WaterLevelRiverAverage = calculationElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.WaterLevelRiverAverageElement),
DrainageConstructionPresent = calculationElement.GetBoolValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.DrainageConstructionPresentElement),
XCoordinateDrainageConstruction = calculationElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.XCoordinateDrainageConstructionElement),
ZCoordinateDrainageConstruction = calculationElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.ZCoordinateDrainageConstructionElement),
AdjustPhreaticLine3And4ForUplift = calculationElement.GetBoolValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.AdjustPhreaticLine3And4ForUpliftElement),
LocationInputDaily = calculationElement.GetMacroStabilityInwardsLocationInputConfiguration(),
LocationInputExtreme = calculationElement.GetMacroStabilityInwardsLocationInputExtremeConfiguration(),
SlipPlaneMinimumDepth = calculationElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.SlipPlaneMinimumDepthElement),
SlipPlaneMinimumLength = calculationElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.SlipPlaneMinimumLengthElement),
MaximumSliceWidth = calculationElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.MaximumSliceWidthElement),
Scenario = calculationElement.GetScenarioConfiguration()
};
SetMinimumLevelPhreaticLineProperties(configuration, calculationElement);
SetPiezometricHeadPhreaticLine2Properties(configuration, calculationElement);
SetLeakageLengthPhreaticLine3Properties(configuration, calculationElement);
SetLeakageLengthPhreaticLine4Properties(configuration, calculationElement);
SetZonesProperties(configuration, calculationElement);
SetGridProperties(configuration, calculationElement);
return configuration;
}
private static double? GetAssessmentLevel(XElement calculationElement)
{
return calculationElement.GetDoubleValueFromDescendantElement(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.WaterLevelElement)
?? calculationElement.GetDoubleValueFromDescendantElement(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.AssessmentLevelElement);
}
///
/// Sets the minimum level phreatic line related properties to .
///
/// The configuration to set to the minimum level phreatic line properties.
/// The that contains the phreatic line 1 element.
/// Thrown when the value for a property isn't in the correct format.
/// Thrown when the value for a property represents a number less
/// than or greater than .
/// Thrown when any conversion cannot be performed.
private static void SetMinimumLevelPhreaticLineProperties(MacroStabilityInwardsCalculationConfiguration configuration,
XElement calculationElement)
{
XElement descendantElement = calculationElement.GetDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLine1MinimumLevelElement);
if (descendantElement == null)
{
return;
}
configuration.MinimumLevelPhreaticLineAtDikeTopPolder = descendantElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.MinimumLevelPhreaticLineAtDikeTopPolderElement);
configuration.MinimumLevelPhreaticLineAtDikeTopRiver = descendantElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.MinimumLevelPhreaticLineAtDikeTopRiverElement);
}
///
/// Sets the piezometric head phreatic line 2 related properties to .
///
/// The configuration to set to the piezometric head phreatic line 2 properties.
/// The that contains the phreatic line 2 element.
/// Thrown when the value for a property isn't in the correct format.
/// Thrown when the value for a property represents a number less
/// than or greater than .
/// Thrown when any conversion cannot be performed.
private static void SetPiezometricHeadPhreaticLine2Properties(MacroStabilityInwardsCalculationConfiguration configuration,
XElement calculationElement)
{
XElement descendantElement = calculationElement.GetDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLine2PiezometricHeadElement);
if (descendantElement == null)
{
return;
}
configuration.PiezometricHeadPhreaticLine2Inwards = descendantElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLineInwardsElement);
configuration.PiezometricHeadPhreaticLine2Outwards = descendantElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLineOutwardsElement);
}
///
/// Sets the leakage length phreatic line 3 related properties to .
///
/// The configuration to set to the leakage length phreatic line 3 properties.
/// The that contains the phreatic line 3 element.
/// Thrown when the value for a property isn't in the correct format.
/// Thrown when the value for a property represents a number less
/// than or greater than .
/// Thrown when any conversion cannot be performed.
private static void SetLeakageLengthPhreaticLine3Properties(MacroStabilityInwardsCalculationConfiguration configuration,
XElement calculationElement)
{
XElement phreaticLine1Element = calculationElement.GetDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLine3LeakageLengthElement);
if (phreaticLine1Element == null)
{
return;
}
configuration.LeakageLengthInwardsPhreaticLine3 = phreaticLine1Element.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLineInwardsElement);
configuration.LeakageLengthOutwardsPhreaticLine3 = phreaticLine1Element.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLineOutwardsElement);
}
///
/// Sets the leakage length phreatic line 4 related properties to .
///
/// The configuration to set to the leakage length phreatic line 4 properties.
/// The that contains the phreatic line 4 element.
/// Thrown when the value for a property isn't in the correct format.
/// Thrown when the value for a property represents a number less
/// than or greater than .
/// Thrown when any conversion cannot be performed.
private static void SetLeakageLengthPhreaticLine4Properties(MacroStabilityInwardsCalculationConfiguration configuration,
XElement calculationElement)
{
XElement phreaticLine1Element = calculationElement.GetDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLine4LeakageLengthElement);
if (phreaticLine1Element == null)
{
return;
}
configuration.LeakageLengthInwardsPhreaticLine4 = phreaticLine1Element.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLineInwardsElement);
configuration.LeakageLengthOutwardsPhreaticLine4 = phreaticLine1Element.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.PhreaticLineOutwardsElement);
}
///
/// Sets the zone related properties to .
///
/// The configuration to set to the zone properties.
/// The that contains the zone element.
/// Thrown when the value for a property isn't in the correct format.
private static void SetZonesProperties(MacroStabilityInwardsCalculationConfiguration configuration,
XElement calculationElement)
{
XElement zonesElement = calculationElement.GetDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.ZonesElement);
if (zonesElement == null)
{
return;
}
configuration.CreateZones = zonesElement.GetBoolValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.CreateZonesElement);
configuration.ZoningBoundariesDeterminationType = (ConfigurationZoningBoundariesDeterminationType?) zonesElement.GetConvertedValueFromDescendantStringElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.ZoningBoundariesDeterminationTypeElement);
configuration.ZoneBoundaryLeft = zonesElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.ZoneBoundaryLeft);
configuration.ZoneBoundaryRight = zonesElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.ZoneBoundaryRight);
}
///
/// Sets the grid related properties to .
///
/// The configuration to set to the grid properties.
/// The that contains the grid element.
/// Thrown when the value for a property isn't in the correct format.
/// Thrown when the value for a property represents a number less
/// than or greater than .
/// Thrown when any conversion cannot be performed.
private static void SetGridProperties(MacroStabilityInwardsCalculationConfiguration configuration,
XElement calculationElement)
{
XElement gridElement = calculationElement.GetDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.GridsElement);
if (gridElement == null)
{
return;
}
configuration.MoveGrid = gridElement.GetBoolValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.MoveGridElement);
configuration.GridDeterminationType = (ConfigurationGridDeterminationType?)
gridElement.GetConvertedValueFromDescendantStringElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.GridDeterminationTypeElement);
SetTangentLineProperties(configuration, gridElement);
configuration.LeftGrid = gridElement.GetMacroStabilityInwardsGridConfiguration(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.LeftGridElement);
configuration.RightGrid = gridElement.GetMacroStabilityInwardsGridConfiguration(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.RightGridElement);
}
///
/// Sets the tangent line related properties to .
///
/// The configuration to set to the tangent line properties.
/// The that contains the tangent line element.
/// Thrown when the value for a property isn't in the correct format.
/// Thrown when the value for a property represents a number less
/// than or greater than .
/// Thrown when any conversion cannot be performed.
private static void SetTangentLineProperties(MacroStabilityInwardsCalculationConfiguration configuration,
XElement gridElement)
{
XElement tangentLineElement = gridElement.GetDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.TangentLineElement);
if (tangentLineElement == null)
{
return;
}
configuration.TangentLineDeterminationType = (ConfigurationTangentLineDeterminationType?)
tangentLineElement.GetConvertedValueFromDescendantStringElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.TangentLineDeterminationTypeElement);
configuration.TangentLineZTop = tangentLineElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.TangentLineZTopElement);
configuration.TangentLineZBottom = tangentLineElement.GetDoubleValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.TangentLineZBottomElement);
configuration.TangentLineNumber = tangentLineElement.GetIntegerValueFromDescendantElement(
MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.TangentLineNumberElement);
}
}
}