// 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.Collections.Generic; using System.ComponentModel; using System.Linq; using Core.Common.Base.Data; using Core.Common.Base.Geometry; using Ringtoets.Common.Data.Calculation; namespace Ringtoets.MacroStabilityInwards.Data { /// /// Extension methods for obtaining level 2a results from output for an assessment of the macro stability inwards failure mechanism. /// public static class MacroStabilityInwardsFailureMechanismSection2aAssessmentResultExtensions { /// /// Gets the value for the detailed assessment of safety per failure mechanism section as a probability. /// /// The result to get the result for. /// All calculations in the failure mechanism. public static double GetAssessmentLayerTwoA(this MacroStabilityInwardsFailureMechanismSectionResult macroStabilityInwardsFailureMechanismSectionResult, IEnumerable calculations) { List calculationScenarios = macroStabilityInwardsFailureMechanismSectionResult .GetCalculationScenarios(calculations) .Where(cs => cs.Status == CalculationScenarioStatus.Done) .ToList(); return calculationScenarios.Any() ? calculationScenarios.Sum(scenario => scenario.Probability * scenario.Contribution.Value) : double.NaN; } /// /// Gets the contribution of all relevant together. /// /// The result to get the result for. /// All calculations in the failure mechanism. public static RoundedDouble GetTotalContribution(this MacroStabilityInwardsFailureMechanismSectionResult macroStabilityInwardsFailureMechanismSectionResult, IEnumerable calculations) { return (RoundedDouble) macroStabilityInwardsFailureMechanismSectionResult .GetCalculationScenarios(calculations) .Aggregate(0, (current, calculationScenario) => current + calculationScenario.Contribution); } /// /// Gets a list of the relevant . /// /// The result to get the result for. /// All calculations in the failure mechanism. public static IEnumerable GetCalculationScenarios(this MacroStabilityInwardsFailureMechanismSectionResult macroStabilityInwardsFailureMechanismSectionResult, IEnumerable calculations) { IEnumerable lineSegments = Math2D.ConvertLinePointsToLineSegments(macroStabilityInwardsFailureMechanismSectionResult.Section.Points); return calculations .Where(pc => pc.IsRelevant && pc.IsSurfaceLineIntersectionWithReferenceLineInSection(lineSegments)); } /// /// Gets the status of the section result depending on the relevant calculation scenarios. /// /// The result to get the result for. /// All calculations in the failure mechanism. /// Thrown when any of the relevant calculations /// in has an invalid . public static CalculationScenarioStatus GetCalculationScenarioStatus( this MacroStabilityInwardsFailureMechanismSectionResult macroStabilityInwardsFailureMechanismSectionResult, IEnumerable calculations) { var failed = false; var notCalculated = false; foreach (PipingCalculationScenario calculationScenario in macroStabilityInwardsFailureMechanismSectionResult.GetCalculationScenarios(calculations).Where(cs => cs.IsRelevant)) { switch (calculationScenario.Status) { case CalculationScenarioStatus.Failed: failed = true; break; case CalculationScenarioStatus.NotCalculated: notCalculated = true; break; case CalculationScenarioStatus.Done: continue; default: throw new InvalidEnumArgumentException(nameof(macroStabilityInwardsFailureMechanismSectionResult), (int) calculationScenario.Status, typeof(CalculationScenarioStatus)); } } if (failed) { return CalculationScenarioStatus.Failed; } if (notCalculated) { return CalculationScenarioStatus.NotCalculated; } return CalculationScenarioStatus.Done; } } }