예제 #1
0
        public void Constructor_ExpectedValues()
        {
            // Call
            var hydraRingConfigurationService = new HydraRingConfigurationService(HydraRingUncertaintiesType.Model);

            // Assert
            Assert.AreEqual(HydraRingUncertaintiesType.Model, hydraRingConfigurationService.UncertaintiesType);
        }
예제 #2
0
        public void AddHydraRingCalculationInput_DuplicateSectionId_ThrowsArgumentException()
        {
            // Setup
            var hydraRingConfigurationService = new HydraRingConfigurationService(HydraRingUncertaintiesType.Model);
            var calculationInput1             = new HydraRingCalculationInputImplementation(1, 2);
            var calculationInput2             = new HydraRingCalculationInputImplementation(1, 3);

            hydraRingConfigurationService.AddHydraRingCalculationInput(calculationInput1);

            // Call
            TestDelegate test = () => hydraRingConfigurationService.AddHydraRingCalculationInput(calculationInput2);

            // Assert
            const string expectedMessage = "Section id is not unique";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentException>(test, expectedMessage);
        }
예제 #3
0
        public void AddHydraRingCalculationInput_MultipleFailureMechanismTypes_ThrowsNotSupportedException()
        {
            var hydraRingConfigurationService = new HydraRingConfigurationService(HydraRingUncertaintiesType.Model);
            var calculationInput1             = new HydraRingCalculationInputImplementation(1, 2);
            var calculationInput2             = new HydraRingCalculationInputImplementation(2, 3);

            calculationInput2.SetFailureMechanismType(HydraRingFailureMechanismType.DikeHeight);

            hydraRingConfigurationService.AddHydraRingCalculationInput(calculationInput1);

            // Call
            TestDelegate test = () => hydraRingConfigurationService.AddHydraRingCalculationInput(calculationInput2);

            // Assert
            const string expectedMessage = "Running calculations for multiple failure mechanism types is not supported.";
            var          exception       = Assert.Throws <NotSupportedException>(test);

            Assert.AreEqual(expectedMessage, exception.Message);
        }
예제 #4
0
        /// <summary>
        /// Performs the actual calculation by running the Hydra-Ring executable.
        /// </summary>
        /// <param name="uncertaintiesType">The uncertainty type used in the calculation.</param>
        /// <param name="hydraRingCalculationInput">The object containing input data.</param>
        /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing the calculation.</exception>
        /// <exception cref="InvalidOperationException">Thrown when preprocessor directory is required but not specified.</exception>
        protected void Calculate(HydraRingUncertaintiesType uncertaintiesType,
                                 HydraRingCalculationInput hydraRingCalculationInput)
        {
            try
            {
                if (string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory) && hydraRingCalculationInput.PreprocessorSetting.RunPreprocessor)
                {
                    throw new InvalidOperationException("Preprocessor directory required but not specified.");
                }

                int sectionId = hydraRingCalculationInput.Section.SectionId;
                OutputDirectory = CreateWorkingDirectory();

                var hydraRingConfigurationService = new HydraRingConfigurationService(uncertaintiesType);
                hydraRingConfigurationService.AddHydraRingCalculationInput(hydraRingCalculationInput);

                var hydraRingInitializationService = new HydraRingInitializationService(
                    hydraRingCalculationInput.FailureMechanismType,
                    sectionId,
                    OutputDirectory,
                    calculationSettings);
                hydraRingInitializationService.WriteInitializationScript();
                hydraRingConfigurationService.WriteDatabaseCreationScript(hydraRingInitializationService.DatabaseCreationScriptFilePath);

                PerformCalculation(OutputDirectory, hydraRingInitializationService);
                ExecuteGenericParsers(hydraRingInitializationService, sectionId);
                ExecuteCustomParsers(hydraRingInitializationService.TemporaryWorkingDirectory, sectionId);
            }
            catch (HydraRingFileParserException e)
            {
                throw new HydraRingCalculationException(e.Message, e.InnerException);
            }
            catch (Exception e) when(IsSupportedCalculatedException(e))
            {
                throw new HydraRingCalculationException(string.Format(Resources.HydraRingCalculatorBase_Calculate_Critical_error_during_calculation_Exception_0,
                                                                      e.Message),
                                                        e.InnerException);
            }
        }
예제 #5
0
        public void WriteDatabaseCreationScript_SingleHydraRingCalculationInput_WritesExpectedCreationScript([Values(true, false)] bool withForeland,
                                                                                                             [Values(true, false)] bool withBreakWater,
                                                                                                             [Values(true, false)] bool runPreprocessor)
        {
            // Setup
            var hydraRingConfigurationService = new HydraRingConfigurationService(HydraRingUncertaintiesType.Model);

            hydraRingConfigurationService.AddHydraRingCalculationInput(new HydraRingCalculationInputImplementation(1, 700004, withForeland, withBreakWater)
            {
                PreprocessorSetting = runPreprocessor
                                          ? new PreprocessorSetting(1001.1, 1002.2, new NumericsSetting(1008, 1009, 1010, 1011.11, 1012.12, 1013.13, 1014.14, 1015, 1016, 1017, 1018.18, 1019.19, 1020.20, 1021))
                                          : new PreprocessorSetting(),
                DesignTablesSetting = new DesignTablesSetting(6.6, 7.7),
                NumericsSettings    = new Dictionary <int, NumericsSetting>
                {
                    {
                        1, new NumericsSetting(8, 9, 10, 11.11, 12.12, 13.13, 14.14, 15, 16, 17, 18.18, 19.19, 20.20, 21)
                    }
                },
                TimeIntegrationSetting = new TimeIntegrationSetting(3)
            });

            string expectedForelandModelsScript = withForeland || withBreakWater
                                                      ? "INSERT INTO [ForelandModels] VALUES (1, 1, 3);" + Environment.NewLine
                                                      : string.Empty;
            string expectedForelandsScript = withForeland
                                                 ? "INSERT INTO [Forelands] VALUES (1, 1, 1.1, 2.2);" + Environment.NewLine +
                                             "INSERT INTO [Forelands] VALUES (1, 2, 2.2, 3.3);" + Environment.NewLine
                                                 : string.Empty;
            string expectedBreakWatersScript = withBreakWater
                                                   ? "INSERT INTO [Breakwaters] VALUES (1, 1, 99.9);" + Environment.NewLine
                                                   : string.Empty;

            string expectedCreationScript = "DELETE FROM [HydraulicModels];" + Environment.NewLine +
                                            "INSERT INTO [HydraulicModels] VALUES (1, 2, 'WTI 2017');" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [Sections];" + Environment.NewLine +
                                            "INSERT INTO [Sections] VALUES (1, 1, 1, 1, 1, 0, 0, 0, 0, 700004, 700004, 100, 3.3, 2.2);" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [SectionCalculationSchemes];" + Environment.NewLine +
                                            "INSERT INTO [SectionCalculationSchemes] VALUES (1, 1, 3);" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [DesignTables];" + Environment.NewLine +
                                            "INSERT INTO [DesignTables] VALUES (1, 1, 1, 1, 4, 5, 0, 0, 0, 0, 6.6, 7.7, 1.1);" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [PreprocessorSettings];" + Environment.NewLine +
                                            (runPreprocessor
                                                 ? "INSERT INTO [PreprocessorSettings] VALUES (1, 1001.1, 1002.2);" + Environment.NewLine
                                                 : string.Empty) +
                                            Environment.NewLine +
                                            "DELETE FROM [Numerics];" + Environment.NewLine +
                                            "INSERT INTO [Numerics] VALUES (1, 1, 1, 1, 1, 8, 9, 10, 11.11, 12.12, 13.13, 14.14, 15, 3, 16, 17, 18.18, 19.19, 20.2, 21);" + Environment.NewLine +
                                            (runPreprocessor
                                                 ? "INSERT INTO [Numerics] VALUES (1, 1, 1, 1, 7, 1008, 1009, 1010, 1011.11, 1012.12, 1013.13, 1014.14, 1015, 3, 1016, 1017, 1018.18, 1019.19, 1020.2, 1021);" + Environment.NewLine
                                                 : string.Empty) +
                                            Environment.NewLine +
                                            "DELETE FROM [VariableDatas];" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 0, 2.2, 3.3, 4.4, 5.5, 1, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 2, 2.2, 3.3, 4.4, 5.5, 1, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 2, 2.2, 3.3, 4.4, 5.5, 0, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 0, 2, 0, NULL, NULL, NULL, 1, 0, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 4, 2.2, 3.3, 4.4, 5.5, 1, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 4, 2.2, 3.3, 4.4, 5.5, 0, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 0, 4, 0, NULL, NULL, NULL, 1, 0, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 19, 2.2, 3.3, 4.4, 5.5, 1, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 19, 2.2, 3.3, 4.4, 5.5, 0, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 0, 19, 0, NULL, NULL, NULL, 1, 0, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 18, 2.2, 3.3, 4.4, 5.5, 1, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 1.1, 18, 2.2, 3.3, 4.4, 5.5, 0, 6.6, 300);" + Environment.NewLine +
                                            "INSERT INTO [VariableDatas] VALUES (1, 1, 1, 1, 26, 0, 18, 0, NULL, NULL, NULL, 1, 0, 300);" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [CalculationProfiles];" + Environment.NewLine +
                                            "INSERT INTO [CalculationProfiles] VALUES (1, 1, 1.1, 2.2, 3.3);" + Environment.NewLine +
                                            "INSERT INTO [CalculationProfiles] VALUES (1, 2, 11.1, 22.2, 33.3);" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [SectionFaultTreeModels];" + Environment.NewLine +
                                            "INSERT INTO [SectionFaultTreeModels] VALUES (1, 1, 1, 1, 6);" + Environment.NewLine +
                                            (runPreprocessor
                                                 ? "INSERT INTO [SectionFaultTreeModels] VALUES (1, 1, 1, 1, 9);" + Environment.NewLine
                                                 : string.Empty) +
                                            Environment.NewLine +
                                            "DELETE FROM [SectionSubMechanismModels];" + Environment.NewLine +
                                            "INSERT INTO [SectionSubMechanismModels] VALUES (1, 1, 1, 1, 1234);" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [Fetches];" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [AreaPoints];" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [PresentationSections];" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [Profiles];" + Environment.NewLine +
                                            "INSERT INTO [Profiles] VALUES (1, 1, 1.1, 2.2);" + Environment.NewLine +
                                            "INSERT INTO [Profiles] VALUES (1, 2, 11.1, 22.2);" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [ForelandModels];" + Environment.NewLine +
                                            expectedForelandModelsScript +
                                            Environment.NewLine +
                                            "DELETE FROM [Forelands];" + Environment.NewLine +
                                            expectedForelandsScript +
                                            Environment.NewLine +
                                            "DELETE FROM [ProbabilityAlternatives];" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [SetUpHeights];" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [CalcWindDirections];" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [Swells];" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [WaveReductions];" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [Areas];" + Environment.NewLine +
                                            "INSERT INTO [Areas] VALUES (1, '1', 'Nederland');" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [Projects];" + Environment.NewLine +
                                            "INSERT INTO [Projects] VALUES (1, 'BOI', 'Riskeer calculation');" + Environment.NewLine +
                                            Environment.NewLine +
                                            "DELETE FROM [Breakwaters];" + Environment.NewLine +
                                            expectedBreakWatersScript;

            string databaseFilePath = Path.Combine(hydraRingDirectory, "temp.db");

            using (new FileDisposeHelper(databaseFilePath))
            {
                // Call
                hydraRingConfigurationService.WriteDatabaseCreationScript(databaseFilePath);

                // Assert
                string creationScript = File.ReadAllText(databaseFilePath);
                Assert.AreEqual(expectedCreationScript, creationScript);
            }
        }