Example #1
0
 /// <summary>
 /// Asserts whether the <see cref="HydraRingCalculationSettings"/> contains the correct
 /// data from <see cref="HydraulicBoundaryCalculationSettings"/>.
 /// </summary>
 /// <param name="expectedSettings">The <see cref="HydraulicBoundaryCalculationSettings"/>
 /// to assert against.</param>
 /// <param name="actualSettings">The <see cref="HydraRingCalculationSettings"/> to be asserted.</param>
 /// <exception cref="AssertionException">Thrown when:
 /// <list type="bullet">
 /// <item>The HLCD file paths do not match.</item>
 /// <item>The preprocessor directories do not match.</item>
 /// <item>The use preprocessor closure indicators do not match.</item>
 /// </list>
 /// </exception>
 public static void AssertHydraRingCalculationSettings(HydraulicBoundaryCalculationSettings expectedSettings,
                                                       HydraRingCalculationSettings actualSettings)
 {
     Assert.AreEqual(expectedSettings.HlcdFilePath, actualSettings.HlcdFilePath);
     Assert.AreEqual(expectedSettings.PreprocessorDirectory, actualSettings.PreprocessorDirectory);
     Assert.AreEqual(expectedSettings.UsePreprocessorClosure, actualSettings.UsePreprocessorClosure);
 }
Example #2
0
        /// <summary>
        /// Create a new instance of <see cref="WaveHeightCalculator"/>.
        /// </summary>
        /// <param name="calculationSettings">The <see cref="HydraRingCalculationSettings"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationSettings"/>
        /// is <c>null</c>.</exception>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory"/>
        /// equals <see cref="string.Empty"/>.</remarks>
        internal WaveHeightCalculator(HydraRingCalculationSettings calculationSettings) : base(calculationSettings)
        {
            targetProbabilityParser = new ReliabilityIndexCalculationParser();
            convergenceParser       = new ConvergenceParser();

            WaveHeight       = double.NaN;
            ReliabilityIndex = double.NaN;
        }
        /// <summary>
        /// Create a new instance of <see cref="HydraulicLoadsCalculator"/>.
        /// </summary>
        /// <param name="calculationSettings">The <see cref="HydraRingCalculationSettings"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationSettings"/>
        /// is <c>null</c>.</exception>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory"/>
        /// equals <see cref="string.Empty"/>.</remarks>
        internal HydraulicLoadsCalculator(HydraRingCalculationSettings calculationSettings) : base(calculationSettings)
        {
            targetProbabilityParser = new ReliabilityIndexCalculationParser();
            convergenceParser       = new ConvergenceParser();

            Value            = double.NaN;
            ReliabilityIndex = double.NaN;
        }
        /// <summary>
        /// Create a new instance of <see cref="DesignWaterLevelCalculator"/>.
        /// </summary>
        /// <param name="calculationSettings">The <see cref="HydraRingCalculationSettings"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationSettings"/>
        /// is <c>null</c>.</exception>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory" />
        /// equals <see cref="string.Empty"/>.</remarks>
        internal DesignWaterLevelCalculator(HydraRingCalculationSettings calculationSettings) : base(calculationSettings)
        {
            targetProbabilityParser = new ReliabilityIndexCalculationParser();
            convergenceParser       = new ConvergenceParser();

            DesignWaterLevel = double.NaN;
            ReliabilityIndex = double.NaN;
        }
        /// <summary>
        /// Performs a piping calculation based on the supplied <see cref="ProbabilisticPipingCalculation"/> and sets <see cref="ProbabilisticPipingCalculation.Output"/>
        /// if the calculation was successful. Error and status information is logged during the execution of the operation.
        /// </summary>
        /// <param name="calculation">The <see cref="ProbabilisticPipingCalculation"/> that holds all the information required to perform the calculation.</param>
        /// <param name="generalInput">The <see cref="GeneralPipingInput"/> to derive values from during the calculation.</param>
        /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the
        /// hydraulic boundary calculation settings.</param>
        /// <param name="sectionLength">The length of the section the calculation belongs to.</param>
        /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculation"/>, <paramref name="generalInput"/>
        /// or <paramref name="calculationSettings"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path
        /// contains invalid characters.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>No settings database file could be found at the location of the hydraulic boundary database file path
        /// with the same name.</item>
        /// <item>Unable to open settings database file.</item>
        /// <item>Unable to read required data from database file.</item>
        /// </list></exception>
        /// <exception cref="HydraRingFileParserException">Thrown when an error occurs during parsing of the Hydra-Ring output.</exception>
        /// <exception cref="HydraRingCalculationException">Thrown when an error occurs during the calculation.</exception>
        internal void Calculate(ProbabilisticPipingCalculation calculation, GeneralPipingInput generalInput,
                                HydraulicBoundaryCalculationSettings calculationSettings, double sectionLength)
        {
            if (calculation == null)
            {
                throw new ArgumentNullException(nameof(calculation));
            }

            if (generalInput == null)
            {
                throw new ArgumentNullException(nameof(generalInput));
            }

            if (calculationSettings == null)
            {
                throw new ArgumentNullException(nameof(calculationSettings));
            }

            string hydraulicBoundaryDatabaseFilePath = calculationSettings.HydraulicBoundaryDatabaseFilePath;
            bool   usePreprocessor = !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory);

            HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings);

            profileSpecificCalculator = HydraRingCalculatorFactory.Instance.CreatePipingCalculator(
                hydraRingCalculationSettings);
            sectionSpecificCalculator = HydraRingCalculatorFactory.Instance.CreatePipingCalculator(
                hydraRingCalculationSettings);

            CalculationServiceHelper.LogCalculationBegin();

            try
            {
                IPartialProbabilisticPipingOutput profileSpecificOutput = CalculateProfileSpecific(
                    calculation, generalInput, hydraulicBoundaryDatabaseFilePath, usePreprocessor);

                if (canceled)
                {
                    return;
                }

                IPartialProbabilisticPipingOutput sectionSpecificOutput = CalculateSectionSpecific(
                    calculation, generalInput, sectionLength, hydraulicBoundaryDatabaseFilePath, usePreprocessor);

                if (canceled)
                {
                    return;
                }

                calculation.Output = new ProbabilisticPipingOutput(sectionSpecificOutput, profileSpecificOutput);
            }
            finally
            {
                CalculationServiceHelper.LogCalculationEnd();

                profileSpecificCalculator = null;
                sectionSpecificCalculator = null;
            }
        }
        /// <summary>
        /// Create a new instance of <see cref="OvertoppingCalculator"/>.
        /// </summary>
        /// <param name="calculationSettings">The <see cref="HydraRingCalculationSettings"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationSettings"/>
        /// is <c>null</c>.</exception>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory"/>
        /// equals <see cref="string.Empty"/>.</remarks>
        internal OvertoppingCalculator(HydraRingCalculationSettings calculationSettings) : base(calculationSettings)
        {
            exceedanceProbabilityCalculationParser = new ExceedanceProbabilityCalculationParser();
            waveHeightParser = new OvertoppingCalculationWaveHeightParser();

            ExceedanceProbabilityBeta = double.NaN;
            WaveHeight            = double.NaN;
            IsOvertoppingDominant = false;
        }
        public void CreateWaveHeightCalculator_Always_ReturnsWaveHeightCalculator()
        {
            // Setup
            HydraRingCalculationSettings settings = HydraRingCalculationSettingsTestFactory.CreateSettings();

            // Call
            IWaveHeightCalculator calculator = HydraRingCalculatorFactory.Instance.CreateWaveHeightCalculator(settings);

            // Assert
            Assert.IsInstanceOf <WaveHeightCalculator>(calculator);
        }
        public void CreateOvertoppingRateCalculator_Always_ReturnsHydraulicLoadsCalculator()
        {
            // Setup
            HydraRingCalculationSettings settings = HydraRingCalculationSettingsTestFactory.CreateSettings();

            // Call
            IHydraulicLoadsCalculator calculator = HydraRingCalculatorFactory.Instance.CreateOvertoppingRateCalculator(settings);

            // Assert
            Assert.IsInstanceOf <HydraulicLoadsCalculator>(calculator);
        }
        public void CreateDesignWaterLevelCalculator_Always_ReturnsDesignWaterLevelCalculator()
        {
            // Setup
            HydraRingCalculationSettings settings = HydraRingCalculationSettingsTestFactory.CreateSettings();

            // Call
            IDesignWaterLevelCalculator calculator = HydraRingCalculatorFactory.Instance.CreateDesignWaterLevelCalculator(settings);

            // Assert
            Assert.IsInstanceOf <DesignWaterLevelCalculator>(calculator);
        }
        public void CreateStructuresCalculator_Always_ReturnsStructuresCalculator()
        {
            // Setup
            HydraRingCalculationSettings settings = HydraRingCalculationSettingsTestFactory.CreateSettings();

            // Call
            IStructuresCalculator <ExceedanceProbabilityCalculationInput> calculator = HydraRingCalculatorFactory.Instance.CreateStructuresCalculator <ExceedanceProbabilityCalculationInput>(settings);

            // Assert
            Assert.IsInstanceOf <StructuresCalculator <ExceedanceProbabilityCalculationInput> >(calculator);
        }
        public void CreateDunesBoundaryConditionsCalculator_Always_ReturnsDunesBoundaryConditionsCalculator()
        {
            // Setup
            HydraRingCalculationSettings settings = HydraRingCalculationSettingsTestFactory.CreateSettings();

            // Call
            IDunesBoundaryConditionsCalculator calculator = HydraRingCalculatorFactory.Instance.CreateDunesBoundaryConditionsCalculator(settings);

            // Assert
            Assert.IsInstanceOf <DunesBoundaryConditionsCalculator>(calculator);
        }
Example #12
0
        /// <summary>
        /// Create a new instance of <see cref="DesignWaterLevelCalculator"/>.
        /// </summary>
        /// <param name="calculationSettings">The <see cref="HydraRingCalculationSettings"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationSettings"/>
        /// is <c>null</c>.</exception>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory"/>
        /// equals <see cref="string.Empty"/>.</remarks>
        internal DunesBoundaryConditionsCalculator(HydraRingCalculationSettings calculationSettings) : base(calculationSettings)
        {
            dunesBoundaryParser     = new DunesBoundaryConditionsCalculationParser();
            targetProbabilityParser = new ReliabilityIndexCalculationParser();
            convergenceParser       = new ConvergenceParser();

            WaterLevel       = double.NaN;
            WaveHeight       = double.NaN;
            WavePeriod       = double.NaN;
            ReliabilityIndex = double.NaN;
        }
        /// <summary>
        /// Create a new instance of <see cref="WaveConditionsCosineCalculator"/>.
        /// </summary>
        /// <param name="calculationSettings">The <see cref="HydraRingCalculationSettings"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationSettings"/>
        /// is <c>null</c>.</exception>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory" />
        /// equals <see cref="string.Empty"/>.</remarks>
        internal WaveConditionsCosineCalculator(HydraRingCalculationSettings calculationSettings) : base(calculationSettings)
        {
            waveConditionsCalculationParser   = new WaveConditionsCalculationParser();
            reliabilityIndexCalculationParser = new ReliabilityIndexCalculationParser();
            convergenceParser = new ConvergenceParser();

            WaveHeight       = double.NaN;
            WaveAngle        = double.NaN;
            WavePeakPeriod   = double.NaN;
            WaveDirection    = double.NaN;
            ReliabilityIndex = double.NaN;
        }
        /// <summary>
        /// Creates a new instance of <see cref="HydraRingCalculatorBase"/> with a default Hydra-Ring file parser
        /// initialized.
        /// </summary>
        /// <param name="calculationSettings">The <see cref="HydraRingCalculationSettings"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationSettings"/> is <c>null</c>.</exception>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory"/>
        /// equals <see cref="string.Empty"/>.</remarks>
        protected HydraRingCalculatorBase(HydraRingCalculationSettings calculationSettings)
        {
            if (calculationSettings == null)
            {
                throw new ArgumentNullException(nameof(calculationSettings));
            }

            this.calculationSettings = calculationSettings;

            lastErrorFileParser      = new LastErrorFileParser();
            illustrationPointsParser = new IllustrationPointsParser();
        }
        public void GenerateInitializationScript_ReturnsExpectedInitializationScript(
            [Values("", "D:\\preprocessor")] string preprocessorDirectory,
            [Values(true, false)] bool usePreprocessorClosure)
        {
            // Setup
            const string hlcdFilePath = "D:\\hlcd\\HlcdFile.sqlite";

            var settings = new HydraRingCalculationSettings(hlcdFilePath, preprocessorDirectory, usePreprocessorClosure);
            var hydraRingInitializationService = new HydraRingInitializationService(HydraRingFailureMechanismType.StructuresStructuralFailure,
                                                                                    700001,
                                                                                    TestHelper.GetScratchPadPath(),
                                                                                    settings);

            string expectedInitializationScript = "section                 = 700001" + Environment.NewLine +
                                                  "mechanism               = 112" + Environment.NewLine +
                                                  "alternative             = 1" + Environment.NewLine +
                                                  "layer                   = 1" + Environment.NewLine +
                                                  "logfile                 = 700001.log" + Environment.NewLine +
                                                  "outputverbosity         = basic" + Environment.NewLine +
                                                  "outputtofile            = file" + Environment.NewLine +
                                                  "projectdbfilename       = 700001.sql" + Environment.NewLine +
                                                  "outputfilename          = designTable.txt" + Environment.NewLine +
                                                  "configdbfilename        = " + Path.Combine(hydraRingDirectory, "config.sqlite") + Environment.NewLine +
                                                  "hydraulicdbfilename     = " + hlcdFilePath + Environment.NewLine +
                                                  "designpointOutput       = sqlite";

            if (preprocessorDirectory != string.Empty)
            {
                expectedInitializationScript += Environment.NewLine + "preprocessordbdirectory = " + preprocessorDirectory;
            }

            if (usePreprocessorClosure)
            {
                expectedInitializationScript += Environment.NewLine + "preprocessorclosingdbfilename = D:\\hlcd\\HlcdFile_preprocClosure.sqlite";
            }

            try
            {
                // Call
                hydraRingInitializationService.WriteInitializationScript();

                // Assert
                string initializationScript = File.ReadAllText(hydraRingInitializationService.IniFilePath);
                Assert.AreEqual(expectedInitializationScript, initializationScript);
            }
            finally
            {
                File.Delete(hydraRingInitializationService.IniFilePath);
            }
        }
Example #16
0
        public void Calculate_LastErrorFilePresent_LastErrorFileContentSet()
        {
            // Setup
            var settings   = new HydraRingCalculationSettings("D:\\HLCD.sqlite", string.Empty, false);
            var calculator = new TestHydraRingCalculator(settings, new TestParser());

            // Call
            calculator.PublicCalculate(new TestHydraRingCalculationInput());

            // Assert
            var expectedContent = $"Hydraulic database {settings.HlcdFilePath} not found.\r\n";

            Assert.AreEqual(expectedContent, calculator.LastErrorFileContent);
        }
Example #17
0
        public void Constructor_WithArguments_ExpectedValues()
        {
            // Setup
            const string hlcdFilePath           = "hlcdFilePath";
            const string preProcessorDirectory  = "PreprocessorDirectory";
            bool         usePreprocessorClosure = new Random(21).NextBoolean();

            // Call
            var settings = new HydraRingCalculationSettings(hlcdFilePath, preProcessorDirectory, usePreprocessorClosure);

            // Assert
            Assert.AreEqual(hlcdFilePath, settings.HlcdFilePath);
            Assert.AreEqual(preProcessorDirectory, settings.PreprocessorDirectory);
            Assert.AreEqual(usePreprocessorClosure, settings.UsePreprocessorClosure);
        }
        public void CreateSettings_WithHydraulicBoundaryCalculationSettings_ReturnsExpectedSettings()
        {
            // Setup
            var hydraulicBoundaryCalculationSettings = new HydraulicBoundaryCalculationSettings("HydraulicBoundaryDataBaseFilePath",
                                                                                                "hlcdFilePath",
                                                                                                false,
                                                                                                "preprocessorDirectory");

            // Call
            HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(hydraulicBoundaryCalculationSettings);

            // Assert
            Assert.AreEqual(hydraulicBoundaryCalculationSettings.HlcdFilePath, hydraRingCalculationSettings.HlcdFilePath);
            Assert.AreEqual(hydraulicBoundaryCalculationSettings.PreprocessorDirectory, hydraRingCalculationSettings.PreprocessorDirectory);
            Assert.AreEqual(hydraulicBoundaryCalculationSettings.UsePreprocessorClosure, hydraRingCalculationSettings.UsePreprocessorClosure);
        }
        public void ParameteredConstructor_ExpectedValues()
        {
            // Setup
            var settings = new HydraRingCalculationSettings("D:\\hlcd\\hlcdFilePath", "D:\\preprocessor", false);

            // Call
            var hydraRingInitializationService = new HydraRingInitializationService(HydraRingFailureMechanismType.AssessmentLevel,
                                                                                    700001,
                                                                                    "D:\\work",
                                                                                    settings);

            // Assert
            Assert.AreEqual("D:\\work\\700001.ini", hydraRingInitializationService.IniFilePath);
            Assert.AreEqual("D:\\work\\700001.sql", hydraRingInitializationService.DatabaseCreationScriptFilePath);
            Assert.AreEqual(Path.Combine(hydraRingDirectory, "MechanismComputation.exe"), hydraRingInitializationService.MechanismComputationExeFilePath);
            Assert.AreEqual("D:\\work", hydraRingInitializationService.TemporaryWorkingDirectory);
        }
Example #20
0
        public void Calculate_NoPreprocessorDirectoryWhenRequired_ThrowsInvalidOperationException()
        {
            // Setup
            var parser     = new TestParser();
            var settings   = new HydraRingCalculationSettings("D:\\hlcd.sqlite", string.Empty, false);
            var calculator = new TestHydraRingCalculator(settings, parser);
            var hydraRingCalculationInput = new TestHydraRingCalculationInput
            {
                PreprocessorSetting = new PreprocessorSetting(1, 2, new NumericsSetting(1, 4, 50, 0.15, 0.05, 0.01, 0.01, 0, 2, 20000, 100000, 0.1, -6, 6))
            };

            // Call
            void Call() => calculator.PublicCalculate(hydraRingCalculationInput);

            // Assert
            string message = Assert.Throws <InvalidOperationException>(Call).Message;

            Assert.AreEqual("Preprocessor directory required but not specified.", message);
        }
Example #21
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;
        }
        private int CreateCalculators(GrassCoverErosionInwardsCalculation calculation,
                                      HydraulicBoundaryCalculationSettings calculationSettings)
        {
            var numberOfCalculators = 1;

            HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings);

            overtoppingCalculator = HydraRingCalculatorFactory.Instance.CreateOvertoppingCalculator(
                hydraRingCalculationSettings);

            if (calculation.InputParameters.ShouldDikeHeightBeCalculated)
            {
                dikeHeightCalculator = HydraRingCalculatorFactory.Instance.CreateDikeHeightCalculator(hydraRingCalculationSettings);
                numberOfCalculators++;
            }

            if (calculation.InputParameters.ShouldOvertoppingRateBeCalculated)
            {
                overtoppingRateCalculator = HydraRingCalculatorFactory.Instance.CreateOvertoppingRateCalculator(hydraRingCalculationSettings);
                numberOfCalculators++;
            }

            return(numberOfCalculators);
        }
        /// <summary>
        /// Performs a calculation for the design water level.
        /// </summary>
        /// <param name="hydraulicBoundaryLocationCalculation">The hydraulic boundary location calculation to perform.</param>
        /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the
        /// hydraulic boundary calculation settings.</param>
        /// <param name="targetProbability">The target probability to use during the calculation.</param>
        /// <param name="messageProvider">The object which is used to build log messages.</param>
        /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="hydraulicBoundaryLocationCalculation"/>,
        /// <paramref name="calculationSettings"/> or <paramref name="messageProvider"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when
        /// <list type="bullet">
        /// <item>the hydraulic boundary database file path contains invalid characters.</item>
        /// <item>The target probability or the calculated probability falls outside the [0.0, 1.0] range and is not <see cref="double.NaN"/>.</item>
        /// </list></exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>No settings database file could be found at the location of hydraulic boundary database file path.
        /// with the same name.</item>
        /// <item>Unable to open settings database file.</item>
        /// <item>Unable to read required data from database file.</item>
        /// </list></exception>
        /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing the calculation.</exception>
        public void Calculate(HydraulicBoundaryLocationCalculation hydraulicBoundaryLocationCalculation,
                              HydraulicBoundaryCalculationSettings calculationSettings,
                              double targetProbability,
                              ICalculationMessageProvider messageProvider)
        {
            if (hydraulicBoundaryLocationCalculation == null)
            {
                throw new ArgumentNullException(nameof(hydraulicBoundaryLocationCalculation));
            }

            if (calculationSettings == null)
            {
                throw new ArgumentNullException(nameof(calculationSettings));
            }

            if (messageProvider == null)
            {
                throw new ArgumentNullException(nameof(messageProvider));
            }

            HydraulicBoundaryLocation hydraulicBoundaryLocation = hydraulicBoundaryLocationCalculation.HydraulicBoundaryLocation;

            CalculationServiceHelper.LogCalculationBegin();

            HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings);

            calculator = HydraRingCalculatorFactory.Instance.CreateDesignWaterLevelCalculator(hydraRingCalculationSettings);

            var exceptionThrown = false;

            try
            {
                PerformCalculation(hydraulicBoundaryLocationCalculation,
                                   calculationSettings,
                                   targetProbability,
                                   messageProvider);
            }
            catch (HydraRingCalculationException)
            {
                if (!canceled)
                {
                    string lastErrorContent = calculator.LastErrorFileContent;
                    log.Error(string.IsNullOrEmpty(lastErrorContent)
                                  ? messageProvider.GetCalculationFailedMessage(hydraulicBoundaryLocation.Name)
                                  : messageProvider.GetCalculationFailedWithErrorReportMessage(hydraulicBoundaryLocation.Name, lastErrorContent));

                    exceptionThrown = true;
                    throw;
                }
            }
            finally
            {
                string lastErrorFileContent = calculator.LastErrorFileContent;
                bool   errorOccurred        = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent);
                if (errorOccurred)
                {
                    log.Error(messageProvider.GetCalculationFailedWithErrorReportMessage(hydraulicBoundaryLocation.Name, lastErrorFileContent));
                }

                log.InfoFormat(Resources.DesignWaterLevelCalculationService_Calculate_Calculation_temporary_directory_can_be_found_on_location_0, calculator.OutputDirectory);
                CalculationServiceHelper.LogCalculationEnd();

                if (errorOccurred)
                {
                    throw new HydraRingCalculationException(lastErrorFileContent);
                }
            }
        }
 public IStructuresCalculator <TCalculationInput> CreateStructuresCalculator <TCalculationInput>(HydraRingCalculationSettings calculationSettings)
     where TCalculationInput : ExceedanceProbabilityCalculationInput
 {
     return(new StructuresCalculator <TCalculationInput>(calculationSettings));
 }
 public IPipingCalculator CreatePipingCalculator(HydraRingCalculationSettings calculationSettings)
 {
     return(new PipingCalculator(calculationSettings));
 }
        /// <summary>
        /// Calculates values for a single water level.
        /// </summary>
        /// <param name="waterLevel">The level of the water.</param>
        /// <param name="a">The 'a' factor decided on failure mechanism level.</param>
        /// <param name="b">The 'b' factor decided on failure mechanism level.</param>
        /// <param name="c">The 'c' factor decided on failure mechanism level.</param>
        /// <param name="targetProbability">The target probability to use.</param>
        /// <param name="input">The input that is different per calculation.</param>
        /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> containing all data
        /// to perform a hydraulic boundary calculation.</param>
        /// <returns>A <see cref="WaveConditionsOutput"/> if the calculation was successful; or <c>null</c> if it was canceled.</returns>
        /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks>
        /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path
        /// contains invalid characters.</exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>No settings database file could be found at the location of the hydraulic boundary database file path
        /// with the same name.</item>
        /// <item>Unable to open settings database file.</item>
        /// <item>Unable to read required data from database file.</item>
        /// </list>
        /// </exception>
        private WaveConditionsOutput CalculateWaterLevel(RoundedDouble waterLevel,
                                                         RoundedDouble a,
                                                         RoundedDouble b,
                                                         RoundedDouble c,
                                                         double targetProbability,
                                                         WaveConditionsInput input,
                                                         HydraulicBoundaryCalculationSettings calculationSettings)
        {
            HydraRingCalculationSettings settings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings);

            calculator = HydraRingCalculatorFactory.Instance.CreateWaveConditionsCosineCalculator(settings);
            WaveConditionsCosineCalculationInput calculationInput = CreateInput(waterLevel, a, b, c, targetProbability, input, calculationSettings);

            WaveConditionsOutput output;
            var exceptionThrown = false;

            try
            {
                calculator.Calculate(calculationInput);

                output = WaveConditionsOutputFactory.CreateOutput(waterLevel,
                                                                  calculator.WaveHeight,
                                                                  calculator.WavePeakPeriod,
                                                                  calculator.WaveAngle,
                                                                  calculator.WaveDirection,
                                                                  targetProbability,
                                                                  calculator.ReliabilityIndex,
                                                                  calculator.Converged);
            }
            catch (Exception e) when(e is HydraRingCalculationException || e is ArgumentOutOfRangeException)
            {
                if (!Canceled)
                {
                    string lastErrorContent = calculator.LastErrorFileContent;
                    if (string.IsNullOrEmpty(lastErrorContent))
                    {
                        log.ErrorFormat(CultureInfo.CurrentCulture,
                                        Resources.WaveConditionsCalculationService_CalculateWaterLevel_Error_in_wave_conditions_calculation_for_waterlevel_0_no_error_report,
                                        waterLevel);
                    }
                    else
                    {
                        log.ErrorFormat(CultureInfo.CurrentCulture,
                                        Resources.WaveConditionsCalculationService_CalculateWaterLevel_Error_in_wave_conditions_calculation_for_waterlevel_0_click_details_for_last_error_report_1,
                                        waterLevel,
                                        lastErrorContent);
                    }

                    exceptionThrown = true;
                }

                output = null;
            }
            finally
            {
                string lastErrorFileContent = calculator.LastErrorFileContent;
                bool   errorOccurred        = CalculationServiceHelper.HasErrorOccurred(Canceled, exceptionThrown, lastErrorFileContent);
                if (errorOccurred)
                {
                    log.ErrorFormat(CultureInfo.CurrentCulture,
                                    Resources.WaveConditionsCalculationService_CalculateWaterLevel_Error_in_wave_conditions_calculation_for_waterlevel_0_click_details_for_last_error_report_1,
                                    waterLevel,
                                    lastErrorFileContent);
                }

                log.InfoFormat(CultureInfo.CurrentCulture,
                               Resources.WaveConditionsCalculationService_CalculateWaterLevel_Calculation_temporary_directory_can_be_found_on_location_0,
                               calculator.OutputDirectory);

                if (errorOccurred)
                {
                    output = null;
                }
            }

            return(output);
        }
Example #27
0
        /// <summary>
        /// Create a new instance of <see cref="PipingCalculator"/>.
        /// </summary>
        /// <param name="calculationSettings">The <see cref="HydraRingCalculationSettings"/>.</param>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="calculationSettings"/>
        /// is <c>null</c>.</exception>
        /// <remarks>Preprocessing is disabled when <see cref="HydraRingCalculationSettings.PreprocessorDirectory"/>
        /// equals <see cref="string.Empty"/>.</remarks>
        internal PipingCalculator(HydraRingCalculationSettings calculationSettings) : base(calculationSettings)
        {
            exceedanceProbabilityCalculationParser = new ExceedanceProbabilityCalculationParser();

            ExceedanceProbabilityBeta = double.NaN;
        }
Example #28
0
 public TestHydraRingCalculator(HydraRingCalculationSettings calculationSettings, IHydraRingFileParser parser) : base(calculationSettings)
 {
     this.parser = parser;
 }
Example #29
0
 public TestHydraRingCalculator(HydraRingCalculationSettings calculationSettings) : base(calculationSettings)
 {
 }
        /// <summary>
        /// Performs the provided <see cref="DuneLocationCalculation"/> and sets its output if the calculation is successful.
        /// Error and status information is logged during the execution of the operation.
        /// </summary>
        /// <param name="duneLocationCalculation">The <see cref="DuneLocationCalculation"/> to perform.</param>
        /// <param name="targetProbability">The target probability to use during the calculation.</param>
        /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the
        /// hydraulic boundary calculation settings.</param>
        /// <param name="messageProvider">The object which is used to build log messages.</param>
        /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="duneLocationCalculation"/>,
        /// <paramref name="calculationSettings"/> or <paramref name="messageProvider"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Thrown when:
        /// <list type="bullet">
        /// <item>The hydraulic boundary location database file path contains invalid characters.</item>
        /// <item>The contribution of the failure mechanism is zero.</item>
        /// <item>The target probability or the calculated probability falls outside the [0.0, 1.0]
        /// range and is not <see cref="double.NaN"/>.</item>
        /// </list></exception>
        /// <exception cref="CriticalFileReadException">Thrown when:
        /// <list type="bullet">
        /// <item>No settings database file could be found at the location of the hydraulic boundary database
        /// with the same name.</item>
        /// <item>Unable to open settings database file.</item>
        /// <item>Unable to read required data from database file.</item>
        /// </list></exception>
        /// <exception cref="HydraRingCalculationException">Thrown when an error occurs while performing
        /// the calculation.</exception>
        public void Calculate(DuneLocationCalculation duneLocationCalculation,
                              double targetProbability,
                              HydraulicBoundaryCalculationSettings calculationSettings,
                              ICalculationMessageProvider messageProvider)
        {
            if (duneLocationCalculation == null)
            {
                throw new ArgumentNullException(nameof(duneLocationCalculation));
            }

            if (calculationSettings == null)
            {
                throw new ArgumentNullException(nameof(calculationSettings));
            }

            if (messageProvider == null)
            {
                throw new ArgumentNullException(nameof(messageProvider));
            }

            DuneLocation duneLocation     = duneLocationCalculation.DuneLocation;
            string       duneLocationName = duneLocation.Name;

            CalculationServiceHelper.LogCalculationBegin();

            HydraRingCalculationSettings hydraRingCalculationSettings = HydraRingCalculationSettingsFactory.CreateSettings(calculationSettings);

            calculator = HydraRingCalculatorFactory.Instance.CreateDunesBoundaryConditionsCalculator(hydraRingCalculationSettings);

            var exceptionThrown = false;

            try
            {
                DunesBoundaryConditionsCalculationInput calculationInput = CreateInput(duneLocation,
                                                                                       targetProbability,
                                                                                       calculationSettings);
                calculator.Calculate(calculationInput);

                if (string.IsNullOrEmpty(calculator.LastErrorFileContent))
                {
                    duneLocationCalculation.Output = CreateDuneLocationCalculationOutput(duneLocationName,
                                                                                         calculationInput.Beta,
                                                                                         targetProbability,
                                                                                         messageProvider);
                }
            }
            catch (HydraRingCalculationException)
            {
                if (!canceled)
                {
                    string lastErrorContent = calculator.LastErrorFileContent;
                    log.Error(string.IsNullOrEmpty(lastErrorContent)
                                  ? messageProvider.GetCalculationFailedMessage(duneLocationName)
                                  : messageProvider.GetCalculationFailedWithErrorReportMessage(duneLocationName, lastErrorContent));

                    exceptionThrown = true;
                    throw;
                }
            }
            finally
            {
                string lastErrorFileContent = calculator.LastErrorFileContent;
                bool   hasErrorOccurred     = CalculationServiceHelper.HasErrorOccurred(canceled, exceptionThrown, lastErrorFileContent);
                if (hasErrorOccurred)
                {
                    log.Error(messageProvider.GetCalculationFailedWithErrorReportMessage(duneLocationName, lastErrorFileContent));
                }

                log.InfoFormat(Resources.DuneLocationCalculationService_Calculate_Calculation_temporary_directory_can_be_found_on_location_0,
                               calculator.OutputDirectory);
                CalculationServiceHelper.LogCalculationEnd();

                if (hasErrorOccurred)
                {
                    throw new HydraRingCalculationException(lastErrorFileContent);
                }
            }
        }