// 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 Core.Common.Utils;
using Ringtoets.MacroStabilityInwards.Data;
namespace Ringtoets.MacroStabilityInwards.Service
{
///
/// This class is responsible for calculating a factor of safety for macro stability inwards.
///
public class MacroStabilityInwardsSemiProbabilisticCalculationService
{
private readonly double norm;
private readonly double constantA;
private readonly double constantB;
private readonly double assessmentSectionLength;
private readonly double contribution;
private readonly double stabilityFactor;
private double macroStabilityInwardsProbability;
private double macroStabilityInwardsReliability;
private double requiredProbability;
private double requiredReliability;
private double macroStabilityInwardsFactorOfSafety;
///
/// Creates a new instance of .
///
/// The norm.
/// The constant a.
/// The constant b.
/// The length of the assessment section.
/// The contribution of macro stability inwards to the total failure.
/// The stability factor of the calculation result.
private MacroStabilityInwardsSemiProbabilisticCalculationService(double norm,
double constantA,
double constantB,
double assessmentSectionLength,
double contribution,
double stabilityFactor)
{
this.norm = norm;
this.constantA = constantA;
this.constantB = constantB;
this.assessmentSectionLength = assessmentSectionLength;
this.contribution = contribution;
this.stabilityFactor = stabilityFactor;
}
///
/// Calculates the semi-probabilistic results given a with .
///
/// The calculation which is used as input for the semi-probabilistic assessment. If the semi-
/// probabilistic calculation is successful, is set.
/// General input that influences the probability estimate for a
/// macro stability inwards assessment.
/// General input that influences the probability estimate for a
/// macro stability inwards assessment.
/// The norm to assess for.
/// The contribution of macro stability inwards as a percentage (0-100) to the total of the failure probability
/// of the assessment section.
/// Thrown when ,
/// or is null.
/// Thrown when calculation has no output from a macro stability inwards calculation.
public static void Calculate(MacroStabilityInwardsCalculation calculation,
MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput,
GeneralMacroStabilityInwardsInput generalInput,
double norm, double contribution)
{
if (calculation == null)
{
throw new ArgumentNullException(nameof(calculation));
}
if (probabilityAssessmentInput == null)
{
throw new ArgumentNullException(nameof(probabilityAssessmentInput));
}
if (generalInput == null)
{
throw new ArgumentNullException(nameof(generalInput));
}
var calculator = new MacroStabilityInwardsSemiProbabilisticCalculationService(
norm,
probabilityAssessmentInput.A,
probabilityAssessmentInput.B,
probabilityAssessmentInput.SectionLength,
contribution / 100, calculation.Output.FactorOfStability);
calculator.Calculate();
calculation.SemiProbabilisticOutput = new MacroStabilityInwardsSemiProbabilisticOutput(
calculation.Output.FactorOfStability,
calculator.requiredProbability,
calculator.requiredReliability,
calculator.macroStabilityInwardsProbability,
calculator.macroStabilityInwardsReliability,
calculator.macroStabilityInwardsFactorOfSafety
);
}
///
/// Performs the full semi-probabilistic calculation while setting intermediate results.
///
private void Calculate()
{
requiredProbability = CalculateRequiredProbability();
requiredReliability = StatisticsConverter.ProbabilityToReliability(requiredProbability);
macroStabilityInwardsReliability = CalculateEstimatedReliability();
macroStabilityInwardsProbability = StatisticsConverter.ReliabilityToProbability(macroStabilityInwardsReliability);
macroStabilityInwardsFactorOfSafety = macroStabilityInwardsReliability / requiredReliability;
}
///
/// Calculates the required probability of the macro stability inwards failure mechanism for the complete assessment section.
///
/// A value representing the required probability.
private double CalculateRequiredProbability()
{
return (norm * contribution) / (1 + (constantA * assessmentSectionLength) / constantB);
}
///
/// Calculates the estimated reliability of the macro stability inwards failure mechanism
/// based on the stability factor.
///
/// The estimated reliability based on the stability factor.
private double CalculateEstimatedReliability()
{
return (6.21 * stabilityFactor) - 2.88;
}
}
}