// 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.Collections.Generic; using System.ComponentModel; using System.Linq; using Assembly.Kernel.Interfaces; using Assembly.Kernel.Model.AssessmentResultTypes; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Primitives; namespace Ringtoets.AssemblyTool.KernelWrapper.Creators { /// /// Creates input instances that can be used in . /// public static class FailureMechanismSectionAssemblyCalculatorInputCreator { /// /// Creates based on the given . /// /// The to create the result for. /// The created . /// Thrown when /// is an invalid value. /// Thrown when /// is a valid value, but unsupported. public static EAssessmentResultTypeE1 CreateAssessmentResultE1(SimpleAssessmentResultType input) { if (!Enum.IsDefined(typeof(SimpleAssessmentResultType), input)) { throw new InvalidEnumArgumentException(nameof(input), (int) input, typeof(SimpleAssessmentResultType)); } switch (input) { case SimpleAssessmentResultType.None: return EAssessmentResultTypeE1.Gr; case SimpleAssessmentResultType.NotApplicable: return EAssessmentResultTypeE1.Nvt; case SimpleAssessmentResultType.ProbabilityNegligible: return EAssessmentResultTypeE1.Fv; case SimpleAssessmentResultType.AssessFurther: return EAssessmentResultTypeE1.Vb; default: throw new NotSupportedException(); } } /// /// Creates based on the given . /// /// The to create the result for. /// The created . /// Thrown when /// is an invalid value. /// Thrown when /// is a valid value, but unsupported. public static EAssessmentResultTypeE2 CreateAssessmentResultTypeE2(SimpleAssessmentValidityOnlyResultType input) { if (!Enum.IsDefined(typeof(SimpleAssessmentValidityOnlyResultType), input)) { throw new InvalidEnumArgumentException(nameof(input), (int) input, typeof(SimpleAssessmentValidityOnlyResultType)); } switch (input) { case SimpleAssessmentValidityOnlyResultType.None: return EAssessmentResultTypeE2.Gr; case SimpleAssessmentValidityOnlyResultType.NotApplicable: return EAssessmentResultTypeE2.Nvt; case SimpleAssessmentValidityOnlyResultType.Applicable: return EAssessmentResultTypeE2.Wvt; default: throw new NotSupportedException(); } } /// /// Creates based on the given parameters. /// /// The calculated probability to create the input for. /// A collection of to /// create the input for. /// The created . /// Thrown when /// is null. /// Thrown when contains /// an invalid . /// Thrown when contains /// a valid but unsupported . /// Thrown when any input parameter has an /// invalid value. public static DetailedCalculationInputFromProbability CreateDetailedCalculationInputFromProbability( double probability, IEnumerable categories) { if (categories == null) { throw new ArgumentNullException(nameof(categories)); } return new DetailedCalculationInputFromProbability(new Probability(probability), categories.Select(category => new FailureMechanismSectionCategory( ConvertFailureMechanismSectionAssemblyCategoryGroup(category.Group), new Probability(category.LowerBoundary), new Probability(category.UpperBoundary))).ToArray()); } /// /// Creates based on the given parameters. /// /// The calculated probability to create the input for. /// A collection of to /// create the input for. /// The 'N' parameter used to factor in the 'length effect'. /// The created . /// Thrown when /// is null. /// Thrown when contains /// an invalid . /// Thrown when contains /// a valid but unsupported . /// Thrown when any input parameter has an /// invalid value. public static DetailedCalculationInputFromProbabilityWithLengthEffect CreateDetailedCalculationInputFromProbabilityWithLengthEffect( double probability, IEnumerable categories, double n) { if (categories == null) { throw new ArgumentNullException(nameof(categories)); } return new DetailedCalculationInputFromProbabilityWithLengthEffect( new Probability(probability), categories.Select(category => new FailureMechanismSectionCategory( ConvertFailureMechanismSectionAssemblyCategoryGroup(category.Group), new Probability(category.LowerBoundary), new Probability(category.UpperBoundary))).ToArray(), n); } /// /// Creates based on the given parameters. /// /// The assembly to convert. /// The created . /// Thrown when /// is null. /// Thrown when contains /// an invalid . /// Thrown when contains /// a valid but unsupported . /// Thrown when any input parameter has an /// invalid value. public static FailureMechanismSectionAssemblyCategoryResult CreateFailureMechanismSectionAssemblyCategoryResult(FailureMechanismSectionAssembly assembly) { if (assembly == null) { throw new ArgumentNullException(nameof(assembly)); } return new FailureMechanismSectionAssemblyCategoryResult( ConvertFailureMechanismSectionAssemblyCategoryGroup(assembly.Group), new Probability(assembly.Probability)); } /// /// Creates based on the given parameters. /// /// The detailed assessment result /// for category Iv - IIv. /// The detailed assessment result for category /// IIv - IIIv. /// The detailed assessment /// result for category IIIv - IVv. /// The detailed assessment result for category /// IVv - Vv. /// The detailed assessment result /// for category Vv - VIv. /// The created . /// Thrown when any parameter is an invalid /// . /// Thrown when any parameter is a valid but unsupported /// . public static DetailedCategoryBoundariesCalculationResult CreateDetailedCalculationInputFromCategoryResults( DetailedAssessmentResultType detailedAssessmentResultForFactorizedSignalingNorm, DetailedAssessmentResultType detailedAssessmentResultForSignalingNorm, DetailedAssessmentResultType detailedAssessmentResultForMechanismSpecificLowerLimitNorm, DetailedAssessmentResultType detailedAssessmentResultForLowerLimitNorm, DetailedAssessmentResultType detailedAssessmentResultForFactorizedLowerLimitNorm) { return new DetailedCategoryBoundariesCalculationResult( CreateAssessmentResultTypeG1(detailedAssessmentResultForFactorizedSignalingNorm), CreateAssessmentResultTypeG1(detailedAssessmentResultForSignalingNorm), CreateAssessmentResultTypeG1(detailedAssessmentResultForMechanismSpecificLowerLimitNorm), CreateAssessmentResultTypeG1(detailedAssessmentResultForLowerLimitNorm), CreateAssessmentResultTypeG1(detailedAssessmentResultForFactorizedLowerLimitNorm)); } /// /// Creates a based on the given . /// /// The detailed assessment result to create the result for. /// The created detailed calculation result. /// Thrown when /// is an invalid . /// Thrown when /// is a valid but unsupported . public static EAssessmentResultTypeG1 CreateAssessmentResultTypeG1(DetailedAssessmentResultType detailedAssessmentResult) { if (!Enum.IsDefined(typeof(DetailedAssessmentResultType), detailedAssessmentResult)) { throw new InvalidEnumArgumentException(nameof(detailedAssessmentResult), (int) detailedAssessmentResult, typeof(DetailedAssessmentResultType)); } switch (detailedAssessmentResult) { case DetailedAssessmentResultType.None: return EAssessmentResultTypeG1.Gr; case DetailedAssessmentResultType.Sufficient: return EAssessmentResultTypeG1.V; case DetailedAssessmentResultType.Insufficient: return EAssessmentResultTypeG1.Vn; case DetailedAssessmentResultType.NotAssessed: return EAssessmentResultTypeG1.Ngo; default: throw new NotSupportedException(); } } /// /// Creates a based on the given . /// /// The tailor made assessment result to create the result for. /// The created tailor made calculation result. /// Thrown when /// is an invalid . /// Thrown when /// is a valid but unsupported . public static TailorMadeCalculationResult CreateTailorMadeCalculationResult(TailorMadeAssessmentResultType tailorMadeAssessmentResult) { if (!Enum.IsDefined(typeof(TailorMadeAssessmentResultType), tailorMadeAssessmentResult)) { throw new InvalidEnumArgumentException(nameof(tailorMadeAssessmentResult), (int) tailorMadeAssessmentResult, typeof(TailorMadeAssessmentResultType)); } switch (tailorMadeAssessmentResult) { case TailorMadeAssessmentResultType.None: return TailorMadeCalculationResult.None; case TailorMadeAssessmentResultType.ProbabilityNegligible: return TailorMadeCalculationResult.FV; case TailorMadeAssessmentResultType.Sufficient: return TailorMadeCalculationResult.V; case TailorMadeAssessmentResultType.Insufficient: return TailorMadeCalculationResult.VN; case TailorMadeAssessmentResultType.NotAssessed: return TailorMadeCalculationResult.NGO; default: throw new NotSupportedException(); } } /// /// Creates based on the given parameters. /// /// The tailor made assessment result to create /// the input for. /// The calculated probability to create the input for. /// A collection of to /// create the input for. /// The created . /// Thrown when /// is null. /// Thrown when: /// /// contains an invalid ; /// is an invalid . /// /// /// Thrown when: /// /// contains a valid but unsupported ; /// a valid but unsupported . /// /// /// Thrown when any input parameter has an /// invalid value. public static TailorMadeCalculationInputFromProbability CreateTailorMadeCalculationInputFromProbability( TailorMadeAssessmentProbabilityCalculationResultType tailorMadeAssessmentResult, double probability, IEnumerable categories) { if (categories == null) { throw new ArgumentNullException(nameof(categories)); } return new TailorMadeCalculationInputFromProbability(ConvertTailorMadeProbabilityCalculationResult(tailorMadeAssessmentResult, probability), categories.Select(category => new FailureMechanismSectionCategory( ConvertFailureMechanismSectionAssemblyCategoryGroup(category.Group), new Probability(category.LowerBoundary), new Probability(category.UpperBoundary))).ToArray()); } /// /// Creates based on the given parameters. /// /// The tailor made assessment result to create /// the input for. /// The calculated probability to create the input for. /// A collection of to /// create the input for. /// The 'N' parameter used to factor in the 'length effect'. /// The created . /// Thrown when /// is null. /// Thrown when: /// /// contains an invalid ; /// is an invalid . /// /// /// Thrown when: /// /// contains a valid but unsupported ; /// a valid but unsupported . /// /// /// Thrown when any input parameter has an /// invalid value. public static TailorMadeCalculationInputFromProbabilityWithLengthEffectFactor CreateTailorMadeCalculationInputFromProbabilityWithLengthEffectFactor( TailorMadeAssessmentProbabilityCalculationResultType tailorMadeAssessmentResult, double probability, IEnumerable categories, double n) { if (categories == null) { throw new ArgumentNullException(nameof(categories)); } return new TailorMadeCalculationInputFromProbabilityWithLengthEffectFactor( ConvertTailorMadeProbabilityCalculationResult(tailorMadeAssessmentResult, probability), categories.Select(category => new FailureMechanismSectionCategory( ConvertFailureMechanismSectionAssemblyCategoryGroup(category.Group), new Probability(category.LowerBoundary), new Probability(category.UpperBoundary))).ToArray(), n); } /// /// Converts a into a . /// /// The to convert. /// A based on . /// Thrown when /// is an invalid value. /// Thrown when /// is a valid value, but unsupported. public static FailureMechanismSectionCategoryGroup ConvertFailureMechanismSectionAssemblyCategoryGroup( FailureMechanismSectionAssemblyCategoryGroup category) { if (!Enum.IsDefined(typeof(FailureMechanismSectionAssemblyCategoryGroup), category)) { throw new InvalidEnumArgumentException(nameof(category), (int) category, typeof(FailureMechanismSectionAssemblyCategoryGroup)); } switch (category) { case FailureMechanismSectionAssemblyCategoryGroup.Iv: return FailureMechanismSectionCategoryGroup.Iv; case FailureMechanismSectionAssemblyCategoryGroup.IIv: return FailureMechanismSectionCategoryGroup.IIv; case FailureMechanismSectionAssemblyCategoryGroup.IIIv: return FailureMechanismSectionCategoryGroup.IIIv; case FailureMechanismSectionAssemblyCategoryGroup.IVv: return FailureMechanismSectionCategoryGroup.IVv; case FailureMechanismSectionAssemblyCategoryGroup.Vv: return FailureMechanismSectionCategoryGroup.Vv; case FailureMechanismSectionAssemblyCategoryGroup.VIv: return FailureMechanismSectionCategoryGroup.VIv; case FailureMechanismSectionAssemblyCategoryGroup.VIIv: return FailureMechanismSectionCategoryGroup.VIIv; case FailureMechanismSectionAssemblyCategoryGroup.NotApplicable: return FailureMechanismSectionCategoryGroup.NotApplicable; case FailureMechanismSectionAssemblyCategoryGroup.None: return FailureMechanismSectionCategoryGroup.None; default: throw new NotSupportedException(); } } /// /// Converts a into a . /// /// The to convert. /// A based on . /// Thrown when /// is an invalid value. /// Thrown when /// is a valid value, but unsupported. public static TailorMadeCategoryCalculationResult ConvertTailorMadeFailureMechanismSectionAssemblyCategoryGroup( FailureMechanismSectionAssemblyCategoryGroup category) { if (!Enum.IsDefined(typeof(FailureMechanismSectionAssemblyCategoryGroup), category)) { throw new InvalidEnumArgumentException(nameof(category), (int) category, typeof(FailureMechanismSectionAssemblyCategoryGroup)); } switch (category) { case FailureMechanismSectionAssemblyCategoryGroup.Iv: return TailorMadeCategoryCalculationResult.FV; case FailureMechanismSectionAssemblyCategoryGroup.IIv: return TailorMadeCategoryCalculationResult.IIv; case FailureMechanismSectionAssemblyCategoryGroup.IIIv: return TailorMadeCategoryCalculationResult.IIIv; case FailureMechanismSectionAssemblyCategoryGroup.IVv: return TailorMadeCategoryCalculationResult.IVv; case FailureMechanismSectionAssemblyCategoryGroup.Vv: return TailorMadeCategoryCalculationResult.Vv; case FailureMechanismSectionAssemblyCategoryGroup.VIv: return TailorMadeCategoryCalculationResult.VIv; case FailureMechanismSectionAssemblyCategoryGroup.VIIv: return TailorMadeCategoryCalculationResult.NGO; case FailureMechanismSectionAssemblyCategoryGroup.NotApplicable: case FailureMechanismSectionAssemblyCategoryGroup.None: return TailorMadeCategoryCalculationResult.None; default: throw new NotSupportedException(); } } /// /// Converts a and the given /// to a . /// /// The tailor made assessment result to create /// the input for. /// The calculated probability to create the input for. /// The converted . /// Thrown when /// is an invalid . /// Thrown when /// is a valid but unsupported . private static TailorMadeProbabilityCalculationResult ConvertTailorMadeProbabilityCalculationResult( TailorMadeAssessmentProbabilityCalculationResultType tailorMadeAssessmentResult, double probability) { if (!Enum.IsDefined(typeof(TailorMadeAssessmentProbabilityCalculationResultType), tailorMadeAssessmentResult)) { throw new InvalidEnumArgumentException(nameof(tailorMadeAssessmentResult), (int) tailorMadeAssessmentResult, typeof(TailorMadeAssessmentProbabilityCalculationResultType)); } switch (tailorMadeAssessmentResult) { case TailorMadeAssessmentProbabilityCalculationResultType.None: return new TailorMadeProbabilityCalculationResult(TailorMadeProbabilityCalculationResultGroup.None); case TailorMadeAssessmentProbabilityCalculationResultType.ProbabilityNegligible: return new TailorMadeProbabilityCalculationResult(TailorMadeProbabilityCalculationResultGroup.FV); case TailorMadeAssessmentProbabilityCalculationResultType.NotAssessed: return new TailorMadeProbabilityCalculationResult(TailorMadeProbabilityCalculationResultGroup.NGO); case TailorMadeAssessmentProbabilityCalculationResultType.Probability: return new TailorMadeProbabilityCalculationResult(new Probability(probability)); default: throw new NotSupportedException(); } } } }