示例#1
0
        private static IUpliftVanCalculator GetCalculator(MacroStabilityInwardsCalculation calculation, GeneralMacroStabilityInwardsInput generalInput, RoundedDouble normativeAssessmentLevel)
        {
            UpliftVanCalculatorInput upliftVanCalculatorInput = CreateInputFromData(calculation.InputParameters, generalInput, normativeAssessmentLevel);
            IUpliftVanCalculator     calculator = MacroStabilityInwardsCalculatorFactory.Instance.CreateUpliftVanCalculator(upliftVanCalculatorInput, MacroStabilityInwardsKernelWrapperFactory.Instance);

            return(calculator);
        }
示例#2
0
        public void CreateUpliftVanCalculator_WithUpliftVanCalculatorInput_ReturnsUpliftVanCalculator()
        {
            // Setup
            IMacroStabilityInwardsCalculatorFactory factory = MacroStabilityInwardsCalculatorFactory.Instance;

            using (new MacroStabilityInwardsKernelFactoryConfig())
            {
                // Call
                IUpliftVanCalculator upliftVanCalculator = factory.CreateUpliftVanCalculator(
                    new UpliftVanCalculatorInput(new UpliftVanCalculatorInput.ConstructionProperties
                {
                    SurfaceLine = new MacroStabilityInwardsSurfaceLine("test"),
                    SoilProfile = new TestSoilProfile(),
                    PhreaticLineOffsetsExtreme = new PhreaticLineOffsets(),
                    PhreaticLineOffsetsDaily   = new PhreaticLineOffsets(),
                    DrainageConstruction       = new DrainageConstruction(),
                    SlipPlane = new UpliftVanSlipPlane()
                }),
                    MacroStabilityInwardsKernelWrapperFactory.Instance);

                // Assert
                Assert.IsInstanceOf <UpliftVanCalculator>(upliftVanCalculator);
            }
        }
示例#3
0
        /// <summary>
        /// Performs validation over the values on the given <paramref name="calculation"/>. Error and status information is logged during
        /// the execution of the operation.
        /// </summary>
        /// <param name="calculation">The <see cref="MacroStabilityInwardsCalculation"/> for which to validate the values.</param>
        /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param>
        /// <param name="normativeAssessmentLevel">The normative assessment level to use in case the manual assessment level is not applicable.</param>
        /// <returns><c>false</c> if <paramref name="calculation"/> contains validation errors; <c>true</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        public static bool Validate(MacroStabilityInwardsCalculation calculation, GeneralMacroStabilityInwardsInput generalInput, RoundedDouble normativeAssessmentLevel)
        {
            if (calculation == null)
            {
                throw new ArgumentNullException(nameof(calculation));
            }

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

            CalculationServiceHelper.LogValidationBegin();

            string[] inputValidationResults = MacroStabilityInwardsInputValidator.Validate(calculation.InputParameters, normativeAssessmentLevel).ToArray();

            if (inputValidationResults.Length > 0)
            {
                CalculationServiceHelper.LogMessagesAsError(inputValidationResults);
                CalculationServiceHelper.LogValidationEnd();

                return(false);
            }

            IEnumerable <MacroStabilityInwardsKernelMessage> waternetExtremeKernelMessages;
            IEnumerable <MacroStabilityInwardsKernelMessage> waternetDailyKernelMessages;

            try
            {
                waternetExtremeKernelMessages = ValidateWaternet(() => WaternetCalculationService.ValidateExtreme(
                                                                     calculation.InputParameters, generalInput, GetEffectiveAssessmentLevel(calculation.InputParameters, normativeAssessmentLevel)),
                                                                 Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_extreme_validation_started);
                waternetDailyKernelMessages = ValidateWaternet(() => WaternetCalculationService.ValidateDaily(calculation.InputParameters, generalInput),
                                                               Resources.MacroStabilityInwardsCalculationService_Validate_Waternet_daily_validation_started);
            }
            catch (WaternetCalculationException e)
            {
                HandleExceptionOnValidation(e);

                return(false);
            }

            IEnumerable <MacroStabilityInwardsKernelMessage> kernelMessages = Enumerable.Empty <MacroStabilityInwardsKernelMessage>();

            if (!waternetExtremeKernelMessages.Any() && !waternetDailyKernelMessages.Any())
            {
                IUpliftVanCalculator calculator = GetCalculator(calculation, generalInput, normativeAssessmentLevel);

                try
                {
                    kernelMessages = calculator.Validate().ToArray();
                }
                catch (UpliftVanCalculatorException e)
                {
                    HandleExceptionOnValidation(e);

                    return(false);
                }

                LogKernelMessages(kernelMessages);
            }

            CalculationServiceHelper.LogValidationEnd();

            return(kernelMessages.Concat(waternetDailyKernelMessages)
                   .Concat(waternetExtremeKernelMessages)
                   .All(r => r.Type != MacroStabilityInwardsKernelMessageType.Error));
        }
示例#4
0
        /// <summary>
        /// Performs a macro stability inwards calculation based on the supplied <see cref="MacroStabilityInwardsCalculation"/>
        /// and sets <see cref="MacroStabilityInwardsCalculation.Output"/> based on the result if the calculation was successful.
        /// Error and status information is logged during the execution of the operation.
        /// </summary>
        /// <param name="calculation">The <see cref="MacroStabilityInwardsCalculation"/> to base the input for the calculation upon.</param>
        /// <param name="generalInput">General calculation parameters that are the same across all calculations.</param>
        /// <param name="normativeAssessmentLevel">The normative assessment level to use in case the manual assessment level is not applicable.</param>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="UpliftVanCalculatorException">Thrown when an error (both expected or unexpected) occurred during the calculation.</exception>
        /// <remarks>Consider calling <see cref="Validate"/> first to see if calculation is possible.</remarks>
        public static void Calculate(MacroStabilityInwardsCalculation calculation, GeneralMacroStabilityInwardsInput generalInput, RoundedDouble normativeAssessmentLevel)
        {
            if (calculation == null)
            {
                throw new ArgumentNullException(nameof(calculation));
            }

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

            UpliftVanCalculatorResult macroStabilityInwardsResult;

            CalculationServiceHelper.LogCalculationBegin();

            try
            {
                IUpliftVanCalculator calculator = GetCalculator(calculation, generalInput, normativeAssessmentLevel);

                macroStabilityInwardsResult = calculator.Calculate();
            }
            catch (UpliftVanCalculatorException e)
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.AppendLine(Resources.MacroStabilityInwardsCalculationService_Calculate_Kernel_provides_messages);

                foreach (MacroStabilityInwardsKernelMessage kernelMessage in e.KernelMessages)
                {
                    stringBuilder.AppendLine(string.Format(Resources.MacroStabilityInwardsCalculationService_Calculate_LogMessageType_0_LogMessage_1, kernelMessage.Type, kernelMessage.Message));
                }

                CalculationServiceHelper.LogExceptionAsError($"{RiskeerCommonServiceResources.CalculationService_Calculate_unexpected_error} {stringBuilder}", e);
                CalculationServiceHelper.LogCalculationEnd();

                throw;
            }

            if (macroStabilityInwardsResult.CalculationMessages.Any(cm => cm.Type == MacroStabilityInwardsKernelMessageType.Error))
            {
                CalculationServiceHelper.LogMessagesAsError(new[]
                {
                    CreateAggregatedLogMessage(Resources.MacroStabilityInwardsCalculationService_Calculate_Errors_in_MacroStabilityInwards_calculation, macroStabilityInwardsResult)
                });

                CalculationServiceHelper.LogCalculationEnd();

                throw new UpliftVanCalculatorException();
            }

            if (macroStabilityInwardsResult.CalculationMessages.Any())
            {
                CalculationServiceHelper.LogMessagesAsWarning(new[]
                {
                    CreateAggregatedLogMessage(Resources.MacroStabilityInwardsCalculationService_Calculate_Warnings_in_MacroStabilityInwards_calculation, macroStabilityInwardsResult)
                });
            }

            calculation.Output = new MacroStabilityInwardsOutput(
                MacroStabilityInwardsSlidingCurveConverter.Convert(macroStabilityInwardsResult.SlidingCurveResult),
                MacroStabilityInwardsSlipPlaneUpliftVanConverter.Convert(macroStabilityInwardsResult.CalculationGridResult),
                new MacroStabilityInwardsOutput.ConstructionProperties
            {
                FactorOfStability       = macroStabilityInwardsResult.FactorOfStability,
                ForbiddenZonesXEntryMin = macroStabilityInwardsResult.ForbiddenZonesXEntryMin,
                ForbiddenZonesXEntryMax = macroStabilityInwardsResult.ForbiddenZonesXEntryMax
            });

            CalculationServiceHelper.LogCalculationEnd();
        }