// 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.Linq; using Ringtoets.AssemblyTool.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Exceptions; using Ringtoets.Integration.IO.Assembly; using Ringtoets.Integration.IO.Helpers; using Ringtoets.Piping.Data; namespace Ringtoets.Integration.IO.Factories { /// /// Factory to create instances of /// with assembly results for piping. /// public static class ExportablePipingFailureMechanismFactory { private const ExportableFailureMechanismType failureMechanismCode = ExportableFailureMechanismType.STPH; private const ExportableFailureMechanismGroup failureMechanismGroup = ExportableFailureMechanismGroup.Group2; private const ExportableAssemblyMethod failureMechanismAssemblyMethod = ExportableAssemblyMethod.WBI1B1; /// /// Creates an /// with assembly results based on the input parameters. /// /// The to create an /// for. /// The assessment section the failure mechanism belongs to. /// An with assembly results. /// Thrown when any parameter is null. /// Thrown when assembly results cannot be created. public static ExportableFailureMechanism CreateExportableFailureMechanism( PipingFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (assessmentSection == null) { throw new ArgumentNullException(nameof(assessmentSection)); } if (!failureMechanism.IsRelevant) { return ExportableFailureMechanismFactory.CreateDefaultExportableFailureMechanismWithProbability(assessmentSection, failureMechanismCode, failureMechanismGroup, failureMechanismAssemblyMethod); } FailureMechanismAssembly failureMechanismAssembly = PipingFailureMechanismAssemblyFactory.AssembleFailureMechanism(failureMechanism, assessmentSection, false); return new ExportableFailureMechanism( new ExportableFailureMechanismAssemblyResultWithProbability(failureMechanismAssemblyMethod, failureMechanismAssembly.Group, failureMechanismAssembly.Probability), CreateExportableFailureMechanismSectionResults(failureMechanism, assessmentSection), failureMechanismCode, failureMechanismGroup); } /// /// Creates a collection of /// with assembly results based on . /// /// The to create a /// collection of for. /// The assessment section the sections belong to. /// A collection of . /// Thrown when assembly results cannot be created. private static IEnumerable CreateExportableFailureMechanismSectionResults( PipingFailureMechanism failureMechanism, IAssessmentSection assessmentSection) { IDictionary failureMechanismSectionsLookup = ExportableFailureMechanismSectionHelper.CreateFailureMechanismSectionResultLookup(failureMechanism.SectionResults); IEnumerable pipingCalculationScenarios = failureMechanism.Calculations.Cast(); var exportableResults = new List(); foreach (KeyValuePair failureMechanismSectionPair in failureMechanismSectionsLookup) { PipingFailureMechanismSectionResult failureMechanismSectionResult = failureMechanismSectionPair.Key; FailureMechanismSectionAssembly simpleAssembly = PipingFailureMechanismAssemblyFactory.AssembleSimpleAssessment(failureMechanismSectionResult); FailureMechanismSectionAssembly detailedAssembly = PipingFailureMechanismAssemblyFactory.AssembleDetailedAssessment(failureMechanismSectionResult, pipingCalculationScenarios, failureMechanism, assessmentSection); FailureMechanismSectionAssembly tailorMadeAssembly = PipingFailureMechanismAssemblyFactory.AssembleTailorMadeAssessment(failureMechanismSectionResult, failureMechanism, assessmentSection); FailureMechanismSectionAssembly combinedAssembly = PipingFailureMechanismAssemblyFactory.AssembleCombinedAssessment(failureMechanismSectionResult, pipingCalculationScenarios, failureMechanism, assessmentSection); exportableResults.Add( new ExportableAggregatedFailureMechanismSectionAssemblyResultWithProbability( failureMechanismSectionPair.Value, ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(simpleAssembly, ExportableAssemblyMethod.WBI0E1), ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(detailedAssembly, ExportableAssemblyMethod.WBI0G5), ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(tailorMadeAssembly, ExportableAssemblyMethod.WBI0T5), ExportableSectionAssemblyResultFactory.CreateExportableSectionAssemblyResultWithProbability(combinedAssembly, ExportableAssemblyMethod.WBI0A1))); } return exportableResults; } } }