Exemplo n.º 1
0
        public void CalculateProbabilityWorksWithPassingElement()
        {
            var hydraulicConditions = new[]
            {
                new HydraulicCondition(2.3, (Probability)3.33E-02, double.NaN, double.NaN),
                new HydraulicCondition(2.6, (Probability)1.00E-02, double.NaN, double.NaN),
                new HydraulicCondition(2.9, (Probability)3.33E-03, double.NaN, double.NaN),
                new HydraulicCondition(3.2, (Probability)1.00E-03, double.NaN, double.NaN),
                new HydraulicCondition(3.5, (Probability)3.33E-04, double.NaN, double.NaN),
                new HydraulicCondition(3.8, (Probability)1.00E-04, double.NaN, double.NaN),
            };

            var criticalPathElements = new[]
            {
                new CriticalPathElement(new TreeEvent(),
                                        new FragilityCurve
                {
                    new FragilityCurveElement(2.3, (Probability)0.001),
                    new FragilityCurveElement(2.6, (Probability)0.001),
                    new FragilityCurveElement(2.9, (Probability)0.001),
                    new FragilityCurveElement(3.2, (Probability)0.0028),
                    new FragilityCurveElement(3.5, (Probability)0.0226),
                    new FragilityCurveElement(3.8, (Probability)0.0406),
                }, false)
            };

            var probability =
                ClassEstimationFragilityCurveCalculator.CalculateProbability(hydraulicConditions, criticalPathElements);

            Assert.AreEqual(0.0332517, probability, 1e-6);
        }
Exemplo n.º 2
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (ExtractInput(values, out var hydraulics, out var pathElements, out var criticalPath))
            {
                return(values);
            }

            var plotModel = new PlotModel();

            plotModel.Axes.Add(new LogarithmicAxis
            {
                Position = AxisPosition.Bottom
            });
            plotModel.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Left
            });

            var orderedWaterLevels = hydraulics.Select(h => h.WaterLevel).Distinct().ToArray();
            var lowerElements      = pathElements.Select(p => new CriticalPathElement(p.Element, p.Element.GetLowerFragilityCurve(orderedWaterLevels), p.ElementFails)).ToArray();
            var lowerCurve         = ClassEstimationFragilityCurveCalculator.CalculateCombinedFragilityCurve(hydraulics, lowerElements);

            var upperCurves = pathElements.Select(p => new CriticalPathElement(p.Element, p.Element.GetUpperFragilityCurves(orderedWaterLevels), p.ElementFails)).ToArray();
            var upperCurve  = ClassEstimationFragilityCurveCalculator.CalculateCombinedFragilityCurve(hydraulics, upperCurves);

            var polygonDatas = new List <PolygonData>();

            for (int i = 0; i < orderedWaterLevels.Length; i++)
            {
                polygonDatas.Add(new PolygonData(lowerCurve[i].Probability, lowerCurve[i].WaterLevel, upperCurve[i].Probability, upperCurve[i].WaterLevel));
            }

            plotModel.Series.Add(new AreaSeries
            {
                ItemsSource = polygonDatas,
                DataFieldX  = nameof(PolygonData.X1),
                DataFieldY  = nameof(PolygonData.Y1),
                DataFieldX2 = nameof(PolygonData.X2),
                DataFieldY2 = nameof(PolygonData.Y2),
                Color       = OxyColors.AliceBlue
            });

            for (int i = 0; i < pathElements.Length; i++)
            {
                var curve = new FragilityCurveViewModel(
                    ClassEstimationFragilityCurveCalculator.CalculateCombinedFragilityCurve(hydraulics, pathElements.Take(i + 1).ToArray()));

                plotModel.Series.Add(new LineSeries
                {
                    ItemsSource     = curve.CurveElements,
                    MarkerSize      = 0,
                    StrokeThickness = 2,
                    DataFieldX      = nameof(FragilityCurveElementViewModel.ProbabilityDouble),
                    DataFieldY      = nameof(FragilityCurveElementViewModel.WaterLevel),
                    Title           = criticalPath[i].Name
                });
            }

            return(plotModel);
        }
Exemplo n.º 3
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (ExtractInput(values, out var hydraulics, out var curves, out var criticalPath))
            {
                return(values);
            }

            return(!hydraulics.Any() || !curves.Any()
                ? "NaN"
                : string.Format("1/{0}",
                                (int)(1.0 / ClassEstimationFragilityCurveCalculator.CalculateProbability(hydraulics, curves))));
        }
Exemplo n.º 4
0
        public void CalculateCombinedProbabilityFragilityCurveTest()
        {
            var hydraulicConditions = new[]
            {
                new HydraulicCondition(2.3, (Probability)3.33E-02, double.NaN, double.NaN),
                new HydraulicCondition(2.6, (Probability)1.00E-02, double.NaN, double.NaN),
                new HydraulicCondition(2.9, (Probability)3.33E-03, double.NaN, double.NaN),
                new HydraulicCondition(3.2, (Probability)1.00E-03, double.NaN, double.NaN),
                new HydraulicCondition(3.5, (Probability)3.33E-04, double.NaN, double.NaN),
                new HydraulicCondition(3.8, (Probability)1.00E-04, double.NaN, double.NaN),
            };

            var criticalPathElements = new[]
            {
                new CriticalPathElement(new TreeEvent(),
                                        new FragilityCurve
                {
                    new FragilityCurveElement(2.3, (Probability)0.001),
                    new FragilityCurveElement(2.6, (Probability)0.001),
                    new FragilityCurveElement(2.9, (Probability)0.001),
                    new FragilityCurveElement(3.2, (Probability)0.0028),
                    new FragilityCurveElement(3.5, (Probability)0.0226),
                    new FragilityCurveElement(3.8, (Probability)0.0406),
                }, true)
            };

            var interpolatedValues =
                ClassEstimationFragilityCurveCalculator.CalculateCombinedProbabilityFragilityCurve(hydraulicConditions, criticalPathElements);

            Assert.AreEqual(6, interpolatedValues.Count);
            Assert.AreEqual(2.33E-05, interpolatedValues[0].Probability, 1e-4);
            Assert.AreEqual(6.67E-06, interpolatedValues[1].Probability, 1e-4);
            Assert.AreEqual(4.02E-06, interpolatedValues[2].Probability, 1e-4);
            Assert.AreEqual(7.28E-06, interpolatedValues[3].Probability, 1e-4);
            Assert.AreEqual(6.96E-06, interpolatedValues[4].Probability, 1e-4);
            Assert.AreEqual(1.00E-04, interpolatedValues[5].Probability, 1e-4);
        }