// 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 Core.Common.Base.IO; using Ringtoets.HydraRing.Calculation.Data; using Ringtoets.HydraRing.Calculation.Data.Defaults; using Ringtoets.HydraRing.Calculation.Data.Settings; using Ringtoets.HydraRing.Calculation.Providers; namespace Ringtoets.Common.IO.HydraRing { /// /// Provider of by reading from the settings database or by resorting /// to defaults if no settings could be found. /// public class NumericsSettingsProvider : IDisposable { private readonly HydraRingSettingsDatabaseReader numericsSettingsReader; private IDictionary> defaultNumericsSettings; /// /// Creates a new instance of the class. /// /// The full path to the database file to use when reading settings. /// Thrown when: /// /// The contains invalid characters. /// No file could be found at . /// Unable to open database file. /// The opened database doesn't have the expected schema. /// /// public NumericsSettingsProvider(string databaseFilePath) { InitializeDefaultNumericsSettings(); numericsSettingsReader = new HydraRingSettingsDatabaseReader(databaseFilePath); } /// /// Returns based on the provided combination of failure mechanism type, sub mechanism id and location id. /// /// The location id to obtain the for. /// The to obtain the for. /// A new where the key is the sub mechanism id, and the value is /// the containing values corresponding to the provided failure mechanism type and location id. /// Thrown when is not a valid /// value. /// Thrown when a column that is being read doesn't /// contain expected type. public Dictionary GetNumericsSettings(long locationId, HydraRingFailureMechanismType failureMechanismType) { FailureMechanismDefaults failureMechanismDefaults = new FailureMechanismDefaultsProvider().GetFailureMechanismDefaults(failureMechanismType); IEnumerable subMechanismIds = failureMechanismDefaults.SubMechanismIds; int mechanismId = failureMechanismDefaults.MechanismId; var numericsSettings = new Dictionary(); foreach (int subMechanismId in subMechanismIds) { numericsSettings[subMechanismId] = numericsSettingsReader.ReadNumericsSetting(locationId, mechanismId, subMechanismId) ?? defaultNumericsSettings[failureMechanismType][subMechanismId]; } return numericsSettings; } public void Dispose() { numericsSettingsReader.Dispose(); } private void InitializeDefaultNumericsSettings() { NumericsSetting numericsSettingForm = CreateDefaultNumericsSetting(1, 1); // Settings for a FORM calculation NumericsSetting numericsSettingFDir = CreateDefaultNumericsSetting(11, 4); // Settings for a hybrid calculation; FORM in first instance, DIRS in case of no convergence NumericsSetting numericsSettingDunes = CreateDefaultNumericsSetting(1, 4); var numericsSettingQVariant = new NumericsSetting(4, 4, 150, 0.15, 0.005, 0.005, 0.005, 2, 3000, 10000, 0.1, -6.0, 6.0, 25); defaultNumericsSettings = new Dictionary> { { HydraRingFailureMechanismType.AssessmentLevel, new Dictionary { { 1, numericsSettingFDir } } }, { HydraRingFailureMechanismType.WaveHeight, new Dictionary { { 11, numericsSettingFDir } } }, { HydraRingFailureMechanismType.WavePeakPeriod, new Dictionary { { 14, numericsSettingFDir } } }, { HydraRingFailureMechanismType.WaveSpectralPeriod, new Dictionary { { 16, numericsSettingFDir } } }, { HydraRingFailureMechanismType.QVariant, new Dictionary { { 5, numericsSettingQVariant } } }, { HydraRingFailureMechanismType.DikeHeight, GetOvertoppingDefaults(numericsSettingFDir) }, { HydraRingFailureMechanismType.DikesOvertopping, GetOvertoppingDefaults(numericsSettingFDir) }, { HydraRingFailureMechanismType.StructuresOvertopping, new Dictionary { { 421, numericsSettingFDir }, { 422, numericsSettingFDir }, { 423, numericsSettingFDir } } }, { HydraRingFailureMechanismType.StructuresClosure, new Dictionary { { 422, numericsSettingForm }, { 424, numericsSettingFDir }, { 425, numericsSettingFDir }, { 426, numericsSettingForm }, { 427, numericsSettingForm } } }, { HydraRingFailureMechanismType.StructuresStructuralFailure, new Dictionary { { 422, numericsSettingForm }, { 424, numericsSettingFDir }, { 425, numericsSettingFDir }, { 430, numericsSettingFDir }, { 431, numericsSettingForm }, { 432, numericsSettingForm }, { 433, numericsSettingForm }, { 434, numericsSettingFDir }, { 435, numericsSettingFDir } } }, { HydraRingFailureMechanismType.DunesBoundaryConditions, new Dictionary { { 6, numericsSettingDunes } } }, { HydraRingFailureMechanismType.OvertoppingRate, GetOvertoppingDefaults(numericsSettingFDir) } }; } private static NumericsSetting CreateDefaultNumericsSetting(int calculationTechniqueId, int formStartMethod) { return new NumericsSetting(calculationTechniqueId, formStartMethod, 150, 0.15, 0.005, 0.005, 0.005, 2, 10000, 40000, 0.1, -6.0, 6.0, 25); } private static Dictionary GetOvertoppingDefaults(NumericsSetting numericsSetting) { return new Dictionary { { 102, numericsSetting }, { 103, numericsSetting } }; } } }