/// <summary> /// Obtains the Hydra-Ring settings based on the location and the failure mechanism obtained from the <paramref name="calculationInput"/> /// and sets these value on the <paramref name="calculationInput"/>. /// </summary> /// <param name="calculationInput">The calculation input for which the settings are updated.</param> /// <param name="hydraulicBoundaryDatabaseFilePath">The path to the hydraulic boundary database file.</param> /// <param name="usePreprocessor">Indicator whether to use the preprocessor in the calculation.</param> /// <exception cref="ArgumentException">Thrown when the <paramref name="hydraulicBoundaryDatabaseFilePath"/> /// contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of <paramref name="hydraulicBoundaryDatabaseFilePath"/> /// 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> public static void AssignSettingsFromDatabase(HydraRingCalculationInput calculationInput, string hydraulicBoundaryDatabaseFilePath, bool usePreprocessor) { IOUtils.ValidateFilePath(hydraulicBoundaryDatabaseFilePath); long locationId = calculationInput.HydraulicBoundaryLocationId; string settingsDatabaseFileName = HydraulicBoundaryDatabaseHelper.GetHydraulicBoundarySettingsDatabase(hydraulicBoundaryDatabaseFilePath); using (var preprocessorSettingsProvider = new PreprocessorSettingsProvider(settingsDatabaseFileName)) { calculationInput.PreprocessorSetting = preprocessorSettingsProvider.GetPreprocessorSetting(locationId, usePreprocessor); } using (var designTablesSettingsProviders = new DesignTablesSettingsProvider(settingsDatabaseFileName)) { calculationInput.DesignTablesSetting = designTablesSettingsProviders.GetDesignTablesSetting( locationId, calculationInput.FailureMechanismType); } using (var numericsSettingsProvider = new NumericsSettingsProvider(settingsDatabaseFileName)) { calculationInput.NumericsSettings = numericsSettingsProvider.GetNumericsSettings( locationId, calculationInput.FailureMechanismType); } using (var timeIntegrationSettingsProvider = new TimeIntegrationSettingsProvider(settingsDatabaseFileName)) { calculationInput.TimeIntegrationSetting = timeIntegrationSettingsProvider.GetTimeIntegrationSetting( locationId, calculationInput.FailureMechanismType); } }
/// <summary> /// Adds Hydra-Ring calculation input to the configuration. /// </summary> /// <param name="input">The calculation input to add to the configuration.</param> /// <exception cref="ArgumentException">Thrown when <paramref name="input"/> with /// the same <see cref="HydraRingSection.SectionId"/> has already been added.</exception> /// <exception cref="ArgumentException">Thrown when <paramref name="input"/> is not unique.</exception> /// <exception cref="NotSupportedException">Thrown when <see cref="HydraRingCalculationInput.FailureMechanismType"/> /// is not the same with already added input.</exception> public void AddHydraRingCalculationInput(HydraRingCalculationInput input) { if (hydraRingInputs.Any(h => h.Section.SectionId == input.Section.SectionId)) { throw new ArgumentException(@"Section id is not unique", nameof(input)); } if (hydraRingInputs.Count > 0 && hydraRingInputs.First().FailureMechanismType != input.FailureMechanismType) { throw new NotSupportedException("Running calculations for multiple failure mechanism types is not supported."); } hydraRingInputs.Add(input); }
/// <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); } }
private static void AssertInput(AssessmentLevelCalculationInput expectedInput, HydraRingCalculationInput hydraRingCalculationInput) { Assert.AreEqual(expectedInput.Section.SectionId, hydraRingCalculationInput.Section.SectionId); Assert.AreEqual(expectedInput.HydraulicBoundaryLocationId, hydraRingCalculationInput.HydraulicBoundaryLocationId); Assert.AreEqual(expectedInput.Beta, hydraRingCalculationInput.Beta); }
public void PublicCalculate(HydraRingCalculationInput hydraRingCalculationInput) { Calculate(HydraRingUncertaintiesType.All, hydraRingCalculationInput); }