// 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.Globalization;
using Core.Common.Base;
using Core.Common.Base.Data;
using Ringtoets.Common.Data.Hydraulics;
using Ringtoets.Common.Service.Properties;
namespace Ringtoets.Common.Service
{
///
/// Service for providing common data calculation services.
///
public static class RingtoetsCommonDataCalculationService
{
private static readonly Range normValidityRange = new Range(0, 1);
private static readonly Range contributionValidityRange = new Range(0, 100);
///
/// Determines whether the calculated output is converged.
///
/// The value indicating whether convergence has been reached.
/// if the calculated output converged,
/// if the calculated output did not converge,
/// if no convergence was determined.
public static CalculationConvergence GetCalculationConvergence(bool? converged)
{
return converged.HasValue
? converged.Value
? CalculationConvergence.CalculatedConverged
: CalculationConvergence.CalculatedNotConverged
: CalculationConvergence.NotCalculated;
}
///
/// Gets the required probability which is needed in profile specific calculations.
///
/// The assessment section norm.
/// The failure mechanism contribution.
/// The 'N' parameter used to factor in the 'length effect'.
/// The profile specific required probability.
///
/// Thrown when:
///
/// - is not in the interval [0.0, 1.0] or is ;
/// - is not in the interval [0.0, 100.0] or is ;
/// - is not larger than 0.
///
///
public static double ProfileSpecificRequiredProbability(double norm, double failureMechanismContribution, int n)
{
if (!normValidityRange.InRange(norm))
{
string message = string.Format(Resources.RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_Norm_must_be_in_Range_0_,
normValidityRange.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture));
throw new ArgumentOutOfRangeException(nameof(norm), norm, message);
}
if (!contributionValidityRange.InRange(failureMechanismContribution))
{
string message = string.Format(Resources.RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_Contribution_must_be_in_Range_0_,
contributionValidityRange.ToString(FormattableConstants.ShowAtLeastOneDecimal, CultureInfo.CurrentCulture));
throw new ArgumentOutOfRangeException(nameof(failureMechanismContribution), failureMechanismContribution,
message);
}
if (n <= 0)
{
throw new ArgumentOutOfRangeException(nameof(n), n,
Resources.RingtoetsCommonDataCalculationService_ProfileSpecificRequiredProbability_N_must_be_larger_than_0);
}
return norm * (failureMechanismContribution / 100) / n;
}
}
}