// Copyright (C) Stichting Deltares 2018. 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.Util;
using Ringtoets.Common.Data.AssessmentSection;
namespace Ringtoets.MacroStabilityInwards.Data
{
///
/// Factory class to create .
///
public static class DerivedMacroStabilityInwardsOutputFactory
{
///
/// Calculates the semi-probabilistic results given a with .
///
/// The output of a calculation.
/// The failure mechanism the output belongs to.
/// The assessment section the output belongs to.
/// Thrown when any parameter is null.
public static DerivedMacroStabilityInwardsOutput Create(MacroStabilityInwardsOutput output,
MacroStabilityInwardsFailureMechanism failureMechanism,
IAssessmentSection assessmentSection)
{
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
if (failureMechanism == null)
{
throw new ArgumentNullException(nameof(failureMechanism));
}
if (assessmentSection == null)
{
throw new ArgumentNullException(nameof(assessmentSection));
}
MacroStabilityInwardsProbabilityAssessmentInput probabilityAssessmentInput = failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput;
double contribution = failureMechanism.Contribution / 100;
double norm = assessmentSection.FailureMechanismContribution.Norm;
double factorOfStability = output.FactorOfStability;
double requiredProbability = CalculateRequiredProbability(probabilityAssessmentInput.A,
probabilityAssessmentInput.B,
assessmentSection.ReferenceLine.Length,
norm,
contribution);
double requiredReliability = StatisticsConverter.ProbabilityToReliability(requiredProbability);
double macroStabilityInwardsReliability = CalculateEstimatedReliability(factorOfStability, failureMechanism.GeneralInput.ModelFactor);
double macroStabilityInwardsProbability = StatisticsConverter.ReliabilityToProbability(macroStabilityInwardsReliability);
double macroStabilityInwardsFactorOfSafety = macroStabilityInwardsReliability / requiredReliability;
return new DerivedMacroStabilityInwardsOutput(factorOfStability,
requiredProbability,
requiredReliability,
macroStabilityInwardsProbability,
macroStabilityInwardsReliability,
macroStabilityInwardsFactorOfSafety);
}
///
/// Calculates the required probability of the macro stability inwards failure mechanism for the complete assessment section.
///
/// The constant a.
/// The constant b.
/// The length of the assessment section.
/// The norm.
/// The contribution of macro stability inwards to the total failure.
/// A value representing the required probability.
private static double CalculateRequiredProbability(double constantA, double constantB, double sectionLength, double norm, double contribution)
{
return (norm * contribution) / (1 + (constantA * sectionLength) / constantB);
}
///
/// Calculates the estimated reliability of the macro stability inwards failure mechanism
/// based on the stability factor and model factor.
///
/// The factory of stability to calculate the reliability for.
/// The model factor of the calculation result.
/// The estimated reliability based on the stability and model factor.
private static double CalculateEstimatedReliability(double factorOfStability, double modelFactor)
{
return ((factorOfStability / modelFactor) - 0.41) / 0.15;
}
}
}