// 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 based on the sub calculations.
///
public class MacroStabilityInwardsSemiProbabilisticCalculationService
{
private readonly double norm;
private readonly double constantA;
private readonly double constantB;
private readonly double assessmentSectionLength;
private readonly double contribution;
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.
private MacroStabilityInwardsSemiProbabilisticCalculationService(double norm, double constantA,
double constantB, double assessmentSectionLength, double contribution)
{
this.norm = norm;
this.constantA = constantA;
this.constantB = constantB;
this.assessmentSectionLength = assessmentSectionLength;
this.contribution = contribution;
}
///
/// 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.
/// 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 calculation has no output from a macro stability inwards calculation.
public static void Calculate(MacroStabilityInwardsCalculation calculation,
MacroStabilityInwardsProbabilityAssessmentInput macroStabilityInwardsProbabilityAssessmentInput,
double norm, double contribution)
{
var calculator = new MacroStabilityInwardsSemiProbabilisticCalculationService(
norm,
macroStabilityInwardsProbabilityAssessmentInput.A,
macroStabilityInwardsProbabilityAssessmentInput.B,
macroStabilityInwardsProbabilityAssessmentInput.SectionLength,
contribution / 100);
calculator.Calculate();
calculation.SemiProbabilisticOutput = new MacroStabilityInwardsSemiProbabilisticOutput(
calculator.requiredProbability,
calculator.requiredReliability,
calculator.macroStabilityInwardsProbability,
calculator.macroStabilityInwardsReliability,
calculator.macroStabilityInwardsFactorOfSafety
);
}
///
/// Performs the full semi-probabilistic calculation while setting intermediate results.
///
private void Calculate()
{
CalculateMacroStabilityInwardsReliability();
CalculateRequiredReliability();
macroStabilityInwardsFactorOfSafety = macroStabilityInwardsReliability / requiredReliability;
}
///
/// Calculates the required reliability based on the norm and length of the assessment section and the contribution of
/// macro stability inwards.
///
private void CalculateRequiredReliability()
{
requiredProbability = RequiredProbability();
requiredReliability = StatisticsConverter.ProbabilityToReliability(requiredProbability);
}
///
/// Calculates the reliability of macro stability inwards based on the factors of safety from the sub-mechanisms.
///
private void CalculateMacroStabilityInwardsReliability()
{
macroStabilityInwardsProbability = RequiredProbability();
macroStabilityInwardsReliability = StatisticsConverter.ProbabilityToReliability(macroStabilityInwardsProbability);
}
///
/// Calculates the required probability of the macro stability inwards failure mechanism for the complete assessment section.
///
/// A value representing the required probability.
private double RequiredProbability()
{
return (norm * contribution) / (1 + (constantA * assessmentSectionLength) / constantB);
}
}
}