// 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.ComponentModel; using AssemblyTool.Kernel; using AssemblyTool.Kernel.Assembly; using AssemblyTool.Kernel.Data.AssemblyCategories; using AssemblyTool.Kernel.Data.CalculationResults; using Ringtoets.AssemblyTool.KernelWrapper.Kernels; using Ringtoets.Common.Data.AssemblyTool; using Ringtoets.Common.Data.FailureMechanism; namespace Ringtoets.AssemblyTool.KernelWrapper.Calculators.Assessments { /// /// Class representing a failure mechanism section assembly assessment calculator. /// public class FailureMechanismSectionAssessmentAssemblyCalculator : IFailureMechanismSectionAssessmentAssemblyCalculator { private readonly IAssemblyToolKernelFactory factory; /// /// Creates a new instance of . /// /// The factory responsible for creating the assembly kernel. /// Thrown when any parameter is null. public FailureMechanismSectionAssessmentAssemblyCalculator(IAssemblyToolKernelFactory factory) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } this.factory = factory; } public FailureMechanismSectionAssessment AssembleSimpleAssessment(SimpleAssessmentResultType input) { IFailureMechanismSectionAssemblyCalculator kernel = factory.CreateFailureMechanismSectionAssemblyKernel(); CalculationOutput output = kernel.SimpleAssessmentDirectFailureMechanisms( ConvertSimpleAssessmentResultType(input)); return ConvertFailureMechanismSectionAssemblyCategoryResult(output.Result); } public FailureMechanismSectionAssessment AssembleSimpleAssessment(SimpleAssessmentResultValidityOnlyType input) { throw new NotImplementedException(); } private static FailureMechanismSectionAssessment ConvertFailureMechanismSectionAssemblyCategoryResult(FailureMechanismSectionAssemblyCategoryResult result) { FailureMechanismSectionAssemblyCategoryGroup group; FailureMechanismSectionCategoryGroup originalGroup = result.CategoryGroup; if (!Enum.IsDefined(typeof(FailureMechanismSectionCategoryGroup), originalGroup)) { throw new InvalidEnumArgumentException(nameof(originalGroup), (int) originalGroup, typeof(FailureMechanismSectionCategoryGroup)); } switch (originalGroup) { case FailureMechanismSectionCategoryGroup.Iv: group = FailureMechanismSectionAssemblyCategoryGroup.Iv; break; case FailureMechanismSectionCategoryGroup.IIv: group = FailureMechanismSectionAssemblyCategoryGroup.IIv; break; case FailureMechanismSectionCategoryGroup.IIIv: group = FailureMechanismSectionAssemblyCategoryGroup.IIIv; break; case FailureMechanismSectionCategoryGroup.IVv: group = FailureMechanismSectionAssemblyCategoryGroup.IVv; break; case FailureMechanismSectionCategoryGroup.Vv: group = FailureMechanismSectionAssemblyCategoryGroup.Vv; break; case FailureMechanismSectionCategoryGroup.VIv: group = FailureMechanismSectionAssemblyCategoryGroup.VIv; break; case FailureMechanismSectionCategoryGroup.VIIv: group = FailureMechanismSectionAssemblyCategoryGroup.VIIv; break; case FailureMechanismSectionCategoryGroup.None: group = FailureMechanismSectionAssemblyCategoryGroup.None; break; default: throw new NotSupportedException(); } return new FailureMechanismSectionAssessment(result.EstimatedProbabilityOfFailure.Value, group); } private static SimpleCalculationResult ConvertSimpleAssessmentResultType(SimpleAssessmentResultType resultType) { if (!Enum.IsDefined(typeof(SimpleAssessmentResultType), resultType)) { throw new InvalidEnumArgumentException(nameof(resultType), (int) resultType, typeof(SimpleAssessmentResultType)); } switch (resultType) { case SimpleAssessmentResultType.NotApplicable: return SimpleCalculationResult.NVT; case SimpleAssessmentResultType.ProbabilityNegligible: return SimpleCalculationResult.FV; case SimpleAssessmentResultType.AssessFurther: return SimpleCalculationResult.VB; default: throw new NotSupportedException(); } } } }