Esempio n. 1
0
        /// <summary>
        /// Read a time integration setting for a given location and <see cref="HydraRingFailureMechanismType"/>.
        /// </summary>
        /// <param name="locationId">The id of a hydraulic boundary location.</param>
        /// <param name="calculationType">The type of the calculation to obtain the <see cref="TimeIntegrationSetting"/> for.</param>
        /// <returns>A new <see cref="TimeIntegrationSetting"/> containing values read from the database.</returns>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="calculationType"/> is not a valid
        /// <see cref="HydraRingFailureMechanismType"/> value.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when a column that is being read doesn't
        /// contain expected type.</exception>
        public TimeIntegrationSetting ReadTimeIntegrationSetting(long locationId, HydraRingFailureMechanismType calculationType)
        {
            if (!Enum.IsDefined(calculationType.GetType(), calculationType))
            {
                throw new InvalidEnumArgumentException(nameof(calculationType), (int)calculationType, calculationType.GetType());
            }

            using (IDataReader reader = CreateTimeIntegrationDataReader(locationId, calculationType))
            {
                if (MoveNext(reader))
                {
                    try
                    {
                        return(new TimeIntegrationSetting(
                                   reader.Read <int>(timeIntegrationSchemeIdColumn)));
                    }
                    catch (ConversionException)
                    {
                        throw new CriticalFileReadException(Resources.HydraRingSettingsDatabase_Hydraulic_calculation_settings_database_has_invalid_schema);
                    }
                }
            }

            return(null);
        }
Esempio n. 2
0
            public HydraRingCalculationInputImplementation(int sectionId, int hydraulicBoundaryLocationId, bool withForeland = true, bool withBreakWater = true)
                : base(hydraulicBoundaryLocationId)
            {
                this.sectionId      = sectionId;
                this.withForeland   = withForeland;
                this.withBreakWater = withBreakWater;

                failureMechanismType = HydraRingFailureMechanismType.AssessmentLevel;
            }
Esempio n. 3
0
        public void GetVariableDefaults_ReturnsExpectedVariableDefaults(HydraRingFailureMechanismType failureMechanismType, int variableId, double expectedCorrelationLength)
        {
            // Setup
            var variableDefaultsProvider = new VariableDefaultsProvider();

            // Call
            VariableDefaults variableDefaults = variableDefaultsProvider.GetVariableDefaults(failureMechanismType, variableId);

            // Assert
            Assert.AreEqual(expectedCorrelationLength, variableDefaults.CorrelationLength);
        }
Esempio n. 4
0
        public void ReadTimeIntegrationSetting_ValidLocationIdAndFailureMechanismType_TimeIntegrationSettingWithExpectedValues(
            long locationId, HydraRingFailureMechanismType calculationType, int expectedTimeIntegrationScheme)
        {
            // Setup
            using (var reader = new HydraRingSettingsDatabaseReader(completeDatabasePath))
            {
                // Call
                TimeIntegrationSetting setting = reader.ReadTimeIntegrationSetting(locationId, calculationType);

                // Assert
                Assert.AreEqual(expectedTimeIntegrationScheme, setting.TimeIntegrationSchemeId);
            }
        }
        public void GetTimeIntegrationSetting_KnownLocationIdAndFailureMechanismType_ReturnsExpectedTimeIntegrationSetting(
            HydraRingFailureMechanismType failureMechanismType, long locationId, int expectedTimeIntegrationSchemeId)
        {
            // Setup
            using (var timeIntegrationSettingsProvider = new TimeIntegrationSettingsProvider(completeDatabaseDataPath))
            {
                // Call
                TimeIntegrationSetting timeIntegrationSetting = timeIntegrationSettingsProvider.GetTimeIntegrationSetting(locationId, failureMechanismType);

                // Assert
                Assert.AreEqual(expectedTimeIntegrationSchemeId, timeIntegrationSetting.TimeIntegrationSchemeId);
            }
        }
Esempio n. 6
0
        public void GetDesignTablesSetting_UnknownFailureMechanismTypeOrLocationId_ReturnsDefaultDesignTablesSetting(
            HydraRingFailureMechanismType failureMechanismType, long locationId, double expectedValueMin, double expectedValueMax)
        {
            // Setup
            using (var designTablesSettingsProvider = new DesignTablesSettingsProvider(completeDatabaseDataPath))
            {
                // Call
                DesignTablesSetting designTablesSetting = designTablesSettingsProvider.GetDesignTablesSetting(locationId, failureMechanismType);

                // Assert
                Assert.AreEqual(expectedValueMin, designTablesSetting.ValueMin);
                Assert.AreEqual(expectedValueMax, designTablesSetting.ValueMax);
            }
        }
Esempio n. 7
0
        public void ReadDesignTableSetting_ValidLocationIdAndFailureMechanismType_DesignTableSettingWithExpectedValues(
            long locationId, HydraRingFailureMechanismType calculationType, double expectedMin, double expectedMax)
        {
            // Setup
            using (var reader = new HydraRingSettingsDatabaseReader(completeDatabasePath))
            {
                // Call
                DesignTablesSetting setting = reader.ReadDesignTableSetting(locationId, calculationType);

                // Assert
                Assert.AreEqual(expectedMin, setting.ValueMin);
                Assert.AreEqual(expectedMax, setting.ValueMax);
            }
        }
Esempio n. 8
0
        private IDataReader CreateTimeIntegrationDataReader(long locationId, HydraRingFailureMechanismType calculationType)
        {
            var locationParameter = new SQLiteParameter
            {
                DbType        = DbType.Int64,
                ParameterName = locationIdParameterName,
                Value         = locationId
            };

            var typeParameter = new SQLiteParameter
            {
                DbType        = DbType.Int32,
                ParameterName = calculationTypeIdParameterName,
                Value         = (int)calculationType
            };

            return(CreateDataReader(
                       timeIntegrationSettingsForLocationAndCalculationTypeQuery,
                       locationParameter,
                       typeParameter));
        }
Esempio n. 9
0
        public void GetNumericsSettings_UnknownLocationId_ReturnsExpectedDefaultNumericsSetting(
            HydraRingFailureMechanismType failureMechanismType, int subMechanismId, int expectedCalculationTechniqueId,
            int expectedFormStartMethod, int expectedDsMinNumberOfIterations, int expectedDsMaxNumberOfIterations)
        {
            // Setup
            using (var numericsSettingsProvider = new NumericsSettingsProvider(completeDatabaseDataPath))
            {
                // Call
                Dictionary <int, NumericsSetting> numericsSettings = numericsSettingsProvider.GetNumericsSettings(-1, failureMechanismType);

                // Assert
                Assert.IsTrue(numericsSettings.ContainsKey(subMechanismId));

                var expected = new NumericsSetting(expectedCalculationTechniqueId,
                                                   expectedFormStartMethod,
                                                   150, 0.15, 0.005, 0.005, 0.005, 2,
                                                   expectedDsMinNumberOfIterations,
                                                   expectedDsMaxNumberOfIterations,
                                                   0.1, -6.0, 6.0, 25);
                AssertNumericsSetting(expected, numericsSettings[subMechanismId]);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new instance of the <see cref="HydraRingInitializationService"/> class.
        /// </summary>
        /// <param name="failureMechanismType">The failure mechanism type.</param>
        /// <param name="sectionId">The section id.</param>
        /// <param name="temporaryWorkingDirectory">The working directory.</param>
        /// <param name="settings">The <see cref="HydraRingCalculationSettings"/>
        /// which holds all the general information to start a Hydra-Ring calculation.</param>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory"/>
        /// matches <see cref="string.Empty"/>.</remarks>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="settings"/> is <c>null</c>.</exception>
        public HydraRingInitializationService(HydraRingFailureMechanismType failureMechanismType,
                                              int sectionId,
                                              string temporaryWorkingDirectory,
                                              HydraRingCalculationSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            mechanismId               = new FailureMechanismDefaultsProvider().GetFailureMechanismDefaults(failureMechanismType).MechanismId;
            this.sectionId            = sectionId;
            TemporaryWorkingDirectory = temporaryWorkingDirectory;
            hlcdFilePath              = settings.HlcdFilePath;

            string applicationFolder = AssemblyHelper.GetApplicationDirectory();

            hydraRingDirectory = Path.Combine(applicationFolder, "Standalone", "Deltares", $"{hydraRingBinariesSubDirectory}-{HydraRingFileConstants.HydraRingVersionNumber}");

            configurationDatabaseFilePath = Path.Combine(hydraRingDirectory, HydraRingFileConstants.ConfigurationDatabaseFileName);
            preprocessorDirectory         = settings.PreprocessorDirectory;
            usePreprocessorClosure        = settings.UsePreprocessorClosure;
        }
 /// <summary>
 /// Gets <see cref="TimeIntegrationSetting"/> based on the provided failure mechanism type and location id.
 /// </summary>
 /// <param name="locationId">The location id to obtain the <see cref="TimeIntegrationSetting"/> for.</param>
 /// <param name="failureMechanismType">The <see cref="HydraRingFailureMechanismType"/> to obtain the <see cref="TimeIntegrationSetting"/> for.</param>
 /// <returns>The <see cref="TimeIntegrationSetting"/> corresponding to the provided failure mechanism type and location id.</returns>
 /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="failureMechanismType"/> is not a valid
 /// <see cref="HydraRingFailureMechanismType"/> value.</exception>
 /// <exception cref="CriticalFileReadException">Thrown when a column that is being read doesn't
 /// contain expected type.</exception>
 public TimeIntegrationSetting GetTimeIntegrationSetting(long locationId, HydraRingFailureMechanismType failureMechanismType)
 {
     return(timeIntegrationSettingsReader.ReadTimeIntegrationSetting(locationId, failureMechanismType) ??
            new TimeIntegrationSetting(1));
 }
 /// <summary>
 /// Returns <see cref="FailureMechanismDefaults"/> based on the provided <see cref="HydraRingFailureMechanismType"/>.
 /// </summary>
 /// <param name="failureMechanismType">The <see cref="HydraRingFailureMechanismType"/> to obtain the <see cref="FailureMechanismDefaults"/> for.</param>
 /// <returns>The <see cref="FailureMechanismDefaults"/> corresponding to the provided <see cref="HydraRingFailureMechanismType"/>.</returns>
 public FailureMechanismDefaults GetFailureMechanismDefaults(HydraRingFailureMechanismType failureMechanismType)
 {
     return(failureMechanismDefaults[failureMechanismType]);
 }
Esempio n. 13
0
        /// <summary>
        /// Returns <see cref="NumericsSetting"/> based on the provided combination of failure mechanism type, sub mechanism id and location id.
        /// </summary>
        /// <param name="locationId">The location id to obtain the <see cref="NumericsSetting"/> for.</param>
        /// <param name="failureMechanismType">The <see cref="HydraRingFailureMechanismType"/> to obtain the <see cref="NumericsSetting"/> for.</param>
        /// <returns>A new <see cref="Dictionary{T, T}"/> where the key is the sub mechanism id, and the value is
        /// the <see cref="NumericsSetting"/> containing values corresponding to the provided failure mechanism type and location id.</returns>
        /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="failureMechanismType"/> is not a valid
        /// <see cref="HydraRingFailureMechanismType"/> value.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when a column that is being read doesn't
        /// contain expected type.</exception>
        public Dictionary <int, NumericsSetting> GetNumericsSettings(long locationId, HydraRingFailureMechanismType failureMechanismType)
        {
            FailureMechanismDefaults failureMechanismDefaults = new FailureMechanismDefaultsProvider().GetFailureMechanismDefaults(failureMechanismType);
            IEnumerable <int>        subMechanismIds          = failureMechanismDefaults.SubMechanismIds;
            int mechanismId = failureMechanismDefaults.MechanismId;

            var numericsSettings = new Dictionary <int, NumericsSetting>();

            foreach (int subMechanismId in subMechanismIds)
            {
                numericsSettings[subMechanismId] = numericsSettingsReader.ReadNumericsSetting(locationId, mechanismId, subMechanismId) ??
                                                   defaultNumericsSettings[failureMechanismType][subMechanismId];
            }

            return(numericsSettings);
        }
Esempio n. 14
0
 /// <summary>
 /// Gets <see cref="DesignTablesSetting"/> based on the provided failure mechanism type and location id.
 /// </summary>
 /// <param name="locationId">The location id to obtain the <see cref="DesignTablesSetting"/> for.</param>
 /// <param name="failureMechanismType">The <see cref="HydraRingFailureMechanismType"/> to obtain the <see cref="DesignTablesSetting"/> for.</param>
 /// <returns>The <see cref="DesignTablesSetting"/> corresponding to the provided failure mechanism type and location id.</returns>
 /// <exception cref="InvalidEnumArgumentException">Thrown when <paramref name="failureMechanismType"/> is not a valid
 /// <see cref="HydraRingFailureMechanismType"/> value.</exception>
 /// <exception cref="CriticalFileReadException">Thrown when a column that is being read doesn't
 /// contain expected type.</exception>
 public DesignTablesSetting GetDesignTablesSetting(long locationId, HydraRingFailureMechanismType failureMechanismType)
 {
     return(designTablesSettingsReader.ReadDesignTableSetting(locationId, failureMechanismType) ??
            defaultDesignTablesSettings[failureMechanismType]);
 }
Esempio n. 15
0
        public void ReadDesignTableSetting_InvalidFailureMechanismType_ThrowsInvalidEnumArgumentException(HydraRingFailureMechanismType calculationType)
        {
            // Setup
            using (var reader = new HydraRingSettingsDatabaseReader(completeDatabasePath))
            {
                // Call
                TestDelegate test = () => reader.ReadDesignTableSetting(123, calculationType);

                // Assert
                Assert.Throws <InvalidEnumArgumentException>(test);
            }
        }
Esempio n. 16
0
        public void ReadTimeIntegrationSetting_ValidLocationIdAndFailureMechanismTypeNotInDatabase_ReturnNull(long locationId, HydraRingFailureMechanismType calculationType)
        {
            // Setup
            using (var reader = new HydraRingSettingsDatabaseReader(completeDatabasePath))
            {
                // Call
                TimeIntegrationSetting setting = reader.ReadTimeIntegrationSetting(locationId, calculationType);

                // Assert
                Assert.IsNull(setting);
            }
        }
Esempio n. 17
0
 public void SetFailureMechanismType(HydraRingFailureMechanismType type)
 {
     failureMechanismType = type;
 }
Esempio n. 18
0
        public void ReadDesignTableSetting_InvalidValueInReadLocation_ThrowsCriticalFileReadException(long locationId, HydraRingFailureMechanismType type)
        {
            // Setup
            using (var reader = new HydraRingSettingsDatabaseReader(invalidDatabasePath))
            {
                // Call
                TestDelegate test = () => reader.ReadDesignTableSetting(locationId, type);

                // Assert
                Assert.Throws <CriticalFileReadException>(test);
            }
        }
Esempio n. 19
0
        public void GetFailureMechanismDefaults_ReturnsExpectedFailureMechanismDefaults(HydraRingFailureMechanismType failureMechanismType,
                                                                                        int expectedMechanismId,
                                                                                        IEnumerable <int> expectedSubMechanismIds,
                                                                                        int expectedPreprocessorFaultTreeModelId,
                                                                                        int expectedPreprocessorMechanismId)
        {
            // Setup
            var failureMechanismDefaultsProvider = new FailureMechanismDefaultsProvider();

            // Call
            FailureMechanismDefaults failureMechanismDefaults = failureMechanismDefaultsProvider.GetFailureMechanismDefaults(failureMechanismType);

            // Assert
            Assert.AreEqual(expectedMechanismId, failureMechanismDefaults.MechanismId);
            Assert.AreEqual(expectedSubMechanismIds, failureMechanismDefaults.SubMechanismIds);
            Assert.AreEqual(expectedPreprocessorFaultTreeModelId, failureMechanismDefaults.PreprocessorFaultTreeModelId);
            Assert.AreEqual(expectedPreprocessorMechanismId, failureMechanismDefaults.PreprocessorMechanismId);
        }
Esempio n. 20
0
 /// <summary>
 /// Returns <see cref="VariableDefaults"/> based on the provided <see cref="HydraRingFailureMechanismType"/> and variable id.
 /// </summary>
 /// <param name="failureMechanismType">The <see cref="HydraRingFailureMechanismType"/> to obtain the <see cref="VariableDefaults"/> for.</param>
 /// <param name="variableId">The variable id to obtain the <see cref="VariableDefaults"/> for.</param>
 /// <returns>The <see cref="VariableDefaults"/> corresponding to the provided <see cref="HydraRingFailureMechanismType"/> and variable id.</returns>
 public VariableDefaults GetVariableDefaults(HydraRingFailureMechanismType failureMechanismType, int variableId)
 {
     return(variableDefaults[failureMechanismType][variableId]);
 }