// Copyright (C) Stichting Deltares 2016. 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 Core.Common.Base.Data; using Ringtoets.Common.Data.AssessmentSection; using Ringtoets.Common.Data.Calculation; using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.GrassCoverErosionInwards.Service; using Ringtoets.GrassCoverErosionOutwards.Data; using Ringtoets.GrassCoverErosionOutwards.Service; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Service; using Ringtoets.HydraRing.Data; using Ringtoets.Piping.Data; using Ringtoets.Piping.Service; namespace Ringtoets.Integration.Service { /// /// Service for synchronizing ringtoets. /// public static class RingtoetsDataSynchronizationService { /// /// Clears all the output data and hydraulic boundary locations within the . /// /// The to clear the data for. /// An of calculations which are affected by /// removing data. /// /// Thrown when is null. public static IEnumerable ClearAllCalculationOutputAndHydraulicBoundaryLocations(IAssessmentSection assessmentSection) { if (assessmentSection == null) { throw new ArgumentNullException("assessmentSection"); } var affectedItems = new List(); foreach (var failureMechanism in assessmentSection.GetFailureMechanisms()) { var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; if (pipingFailureMechanism != null) { affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(pipingFailureMechanism)); } if (grassCoverErosionInwardsFailureMechanism != null) { affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(grassCoverErosionInwardsFailureMechanism)); } if (heightStructuresFailureMechanism != null) { affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutputAndHydraulicBoundaryLocations(heightStructuresFailureMechanism)); } } return affectedItems; } /// /// Clears the output of all calculations in the . /// /// The which contains the calculations. /// An of calculations which are affected by clearing the output. /// Thrown when is null. public static IEnumerable ClearFailureMechanismCalculationOutputs(IAssessmentSection assessmentSection) { if (assessmentSection == null) { throw new ArgumentNullException("assessmentSection"); } var affectedItems = new List(); foreach (var failureMechanism in assessmentSection.GetFailureMechanisms()) { var pipingFailureMechanism = failureMechanism as PipingFailureMechanism; var grassCoverErosionInwardsFailureMechanism = failureMechanism as GrassCoverErosionInwardsFailureMechanism; var heightStructuresFailureMechanism = failureMechanism as HeightStructuresFailureMechanism; if (pipingFailureMechanism != null) { affectedItems.AddRange(PipingDataSynchronizationService.ClearAllCalculationOutput(pipingFailureMechanism)); } if (grassCoverErosionInwardsFailureMechanism != null) { affectedItems.AddRange(GrassCoverErosionInwardsDataSynchronizationService.ClearAllCalculationOutput(grassCoverErosionInwardsFailureMechanism)); } if (heightStructuresFailureMechanism != null) { affectedItems.AddRange(HeightStructuresDataSynchronizationService.ClearAllCalculationOutput(heightStructuresFailureMechanism)); } } return affectedItems; } /// /// Clears the output of the hydraulic boundary locations within the /// and . /// /// The wich contains the locations. /// The which contains the locations. /// true when one or multiple locations are affected by clearing the output. false otherwise. /// Thrown when /// or is null. public static bool ClearHydraulicBoundaryLocationOutput(HydraulicBoundaryDatabase hydraulicBoundaryDatabase, GrassCoverErosionOutwardsFailureMechanism failureMechanism) { if (hydraulicBoundaryDatabase == null) { throw new ArgumentNullException("hydraulicBoundaryDatabase"); } if (failureMechanism == null) { throw new ArgumentNullException("failureMechanism"); } var locationsAffected = GrassCoverErosionOutwardsDataSynchronizationService.ClearHydraulicBoundaryLocationOutput(failureMechanism.GrassCoverErosionOutwardsHydraulicBoundaryLocations); foreach (var hydraulicBoundaryLocation in hydraulicBoundaryDatabase.Locations .Where(hydraulicBoundaryLocation => !double.IsNaN(hydraulicBoundaryLocation.DesignWaterLevel) || !double.IsNaN(hydraulicBoundaryLocation.WaveHeight))) { hydraulicBoundaryLocation.DesignWaterLevel = (RoundedDouble) double.NaN; hydraulicBoundaryLocation.WaveHeight = (RoundedDouble) double.NaN; hydraulicBoundaryLocation.DesignWaterLevelCalculationConvergence = CalculationConvergence.NotCalculated; hydraulicBoundaryLocation.WaveHeightCalculationConvergence = CalculationConvergence.NotCalculated; locationsAffected = true; } return locationsAffected; } } }