Esempio n. 1
0
        private EInterpretationCategory AssembleInterpretationCategory(FailureMechanismSectionAssemblyInput input, IAssessmentResultsTranslator kernel, Probability probability)
        {
            ICategoryLimitsCalculator assemblyGroupsKernel = factory.CreateAssemblyGroupsKernel();
            CategoriesList <InterpretationCategory> interpretationCategories = assemblyGroupsKernel.CalculateInterpretationCategoryLimitsBoi01(
                new AssessmentSection(AssemblyCalculatorInputCreator.CreateProbability(input.SignalFloodingProbability),
                                      AssemblyCalculatorInputCreator.CreateProbability(input.MaximumAllowableFloodingProbability)));

            return(kernel.DetermineInterpretationCategoryFromFailureMechanismSectionProbabilityBoi0B1(
                       probability, interpretationCategories));
        }
Esempio n. 2
0
        private static bool IsProbabilityDefined(FailureMechanismSectionAssemblyInput input)
        {
            if (!input.IsRelevant)
            {
                return(false);
            }

            return(input.FurtherAnalysisType == FailureMechanismSectionResultFurtherAnalysisType.NotNecessary &&
                   input.HasProbabilitySpecified ||
                   input.FurtherAnalysisType == FailureMechanismSectionResultFurtherAnalysisType.Executed);
        }
Esempio n. 3
0
        public FailureMechanismSectionAssemblyResultWrapper AssembleFailureMechanismSection(FailureMechanismSectionAssemblyInput input)
        {
            if (ThrowExceptionOnCalculate)
            {
                throw new FailureMechanismSectionAssemblyCalculatorException("Message", new Exception());
            }

            FailureMechanismSectionAssemblyInput = input;

            return(FailureMechanismSectionAssemblyResultOutput ??
                   (FailureMechanismSectionAssemblyResultOutput =
                        new FailureMechanismSectionAssemblyResultWrapper(
                            new FailureMechanismSectionAssemblyResult(0.01, 0.1, 10, FailureMechanismSectionAssemblyGroup.I),
                            AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1)));
        }
        /// <summary>
        /// Performs the assembly based on the <see cref="FailureMechanismSectionAssemblyInput"/>.
        /// </summary>
        /// <param name="input">The input to use in the assembly.</param>
        /// <returns>A <see cref="FailureMechanismSectionAssemblyResultWrapper"/>.</returns>
        /// <exception cref="AssemblyException">Thrown when the section could not be successfully assembled.</exception>
        private static FailureMechanismSectionAssemblyResultWrapper PerformAssembly(FailureMechanismSectionAssemblyInput input)
        {
            IFailureMechanismSectionAssemblyCalculator calculator = AssemblyToolCalculatorFactory.Instance.CreateFailureMechanismSectionAssemblyCalculator(
                AssemblyToolKernelFactory.Instance);

            try
            {
                return(input is FailureMechanismSectionWithProfileProbabilityAssemblyInput probabilityAssemblyInput
                           ? calculator.AssembleFailureMechanismSection(probabilityAssemblyInput)
                           : calculator.AssembleFailureMechanismSection(input));
            }
            catch (FailureMechanismSectionAssemblyCalculatorException e)
            {
                throw new AssemblyException(e.Message, e);
            }
        }
Esempio n. 5
0
        public void AssembleSectionAdoptableSectionWithoutProfileProbability_WithInput_ReturnsExpectedOutput(
            AdoptableInitialFailureMechanismResultType initialFailureMechanismResultType, bool expectedHasProbabilitySpecified)
        {
            // Setup
            var    random     = new Random(21);
            bool   isRelevant = random.NextBoolean();
            double manualSectionProbability     = random.NextDouble();
            double calculatedSectionProbability = random.NextDouble();
            var    furtherAnalysisType          = random.NextEnumValue <FailureMechanismSectionResultFurtherAnalysisType>();
            double refinedSectionProbability    = random.NextDouble();

            var assessmentSection = new AssessmentSectionStub();

            var sectionResult = new AdoptableFailureMechanismSectionResult(FailureMechanismSectionTestFactory.CreateFailureMechanismSection())
            {
                IsRelevant = isRelevant,
                InitialFailureMechanismResultType = initialFailureMechanismResultType,
                ManualInitialFailureMechanismResultSectionProbability = manualSectionProbability,
                FurtherAnalysisType       = furtherAnalysisType,
                RefinedSectionProbability = refinedSectionProbability
            };

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                // Call
                FailureMechanismSectionAssemblyResultFactory.AssembleSection(sectionResult, assessmentSection, () => calculatedSectionProbability);

                // Assert
                FailureMechanismSectionAssemblyInput calculatorInput = calculator.FailureMechanismSectionAssemblyInput;
                FailureMechanismContribution         failureMechanismContribution = assessmentSection.FailureMechanismContribution;
                Assert.AreEqual(failureMechanismContribution.SignalFloodingProbability, calculatorInput.SignalFloodingProbability);
                Assert.AreEqual(failureMechanismContribution.MaximumAllowableFloodingProbability, calculatorInput.MaximumAllowableFloodingProbability);

                Assert.AreEqual(isRelevant, calculatorInput.IsRelevant);
                Assert.AreEqual(expectedHasProbabilitySpecified, calculatorInput.HasProbabilitySpecified);

                double expectedInitialSectionProbability = IsInitialFailureMechanismResultTypeAdopt(initialFailureMechanismResultType)
                                                               ? calculatedSectionProbability
                                                               : manualSectionProbability;
                Assert.AreEqual(expectedInitialSectionProbability, calculatorInput.InitialSectionProbability);
                Assert.AreEqual(furtherAnalysisType, calculatorInput.FurtherAnalysisType);
                Assert.AreEqual(refinedSectionProbability, calculatorInput.RefinedSectionProbability);
            }
        }
Esempio n. 6
0
        private static EAnalysisState GetAnalysisStatus(FailureMechanismSectionAssemblyInput input)
        {
            if (!input.IsRelevant)
            {
                return(EAnalysisState.NotRelevant);
            }

            if (input.FurtherAnalysisType == FailureMechanismSectionResultFurtherAnalysisType.NotNecessary)
            {
                return(!input.HasProbabilitySpecified
                           ? EAnalysisState.NoProbabilityEstimationNecessary
                           : EAnalysisState.ProbabilityEstimated);
            }

            return(input.FurtherAnalysisType == FailureMechanismSectionResultFurtherAnalysisType.Necessary
                       ? EAnalysisState.ProbabilityEstimationNecessary
                       : EAnalysisState.ProbabilityEstimated);
        }
Esempio n. 7
0
        public void AssembleSection_WithInput_SetsInputOnCalculator()
        {
            // Setup
            var random = new Random(21);

            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section)
            {
                IsRelevant = random.NextBoolean(),
                InitialFailureMechanismResultType = AdoptableInitialFailureMechanismResultType.Manual,
                ManualInitialFailureMechanismResultProfileProbability = random.NextDouble(),
                FurtherAnalysisType       = random.NextEnumValue <FailureMechanismSectionResultFurtherAnalysisType>(),
                ProbabilityRefinementType = ProbabilityRefinementType.Both,
                RefinedSectionProbability = random.NextDouble()
            };

            var failureMechanism  = new GrassCoverErosionInwardsFailureMechanism();
            var assessmentSection = new AssessmentSectionStub();

            using (new AssemblyToolCalculatorFactoryConfig())
            {
                var calculatorFactory = (TestAssemblyToolCalculatorFactory)AssemblyToolCalculatorFactory.Instance;
                FailureMechanismSectionAssemblyCalculatorStub calculator = calculatorFactory.LastCreatedFailureMechanismSectionAssemblyCalculator;

                // Call
                GrassCoverErosionInwardsFailureMechanismAssemblyFactory.AssembleSection(sectionResult, failureMechanism, assessmentSection);

                // Assert
                FailureMechanismSectionAssemblyInput calculatorInput = calculator.FailureMechanismSectionAssemblyInput;
                FailureMechanismContribution         failureMechanismContribution = assessmentSection.FailureMechanismContribution;
                Assert.AreEqual(failureMechanismContribution.SignalFloodingProbability, calculatorInput.SignalFloodingProbability);
                Assert.AreEqual(failureMechanismContribution.MaximumAllowableFloodingProbability, calculatorInput.MaximumAllowableFloodingProbability);

                Assert.AreEqual(sectionResult.IsRelevant, calculatorInput.IsRelevant);
                Assert.IsTrue(calculatorInput.HasProbabilitySpecified);

                Assert.AreEqual(sectionResult.ManualInitialFailureMechanismResultSectionProbability, calculatorInput.InitialSectionProbability);
                Assert.AreEqual(sectionResult.FurtherAnalysisType, calculatorInput.FurtherAnalysisType);
                Assert.AreEqual(sectionResult.RefinedSectionProbability, calculatorInput.RefinedSectionProbability);
            }
        }
        /// <summary>
        /// Assembles a failure mechanism section result based on the input arguments.
        /// </summary>
        /// <param name="sectionResult">The section result to assemble for.</param>
        /// <param name="assessmentSection">The <see cref="IAssessmentSection"/> to assemble with.</param>
        /// <returns>A <see cref="FailureMechanismSectionAssemblyResultWrapper"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="AssemblyException">Thrown when the section could not be successfully assembled.</exception>
        public static FailureMechanismSectionAssemblyResultWrapper AssembleSection(
            NonAdoptableFailureMechanismSectionResult sectionResult, IAssessmentSection assessmentSection)
        {
            if (sectionResult == null)
            {
                throw new ArgumentNullException(nameof(sectionResult));
            }

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

            bool hasProbabilitySpecified = sectionResult.InitialFailureMechanismResultType != NonAdoptableInitialFailureMechanismResultType.NoFailureProbability;

            FailureMechanismSectionAssemblyInput input = CreateInput(
                assessmentSection, sectionResult.IsRelevant, sectionResult.ManualInitialFailureMechanismResultSectionProbability,
                sectionResult.FurtherAnalysisType, sectionResult.RefinedSectionProbability, hasProbabilitySpecified);

            return(PerformAssembly(input));
        }
Esempio n. 9
0
        public void AssembleFailureMechanismSection_InputWithProbabilityDefinedKernelWithCompleteOutput_ReturnsExpectedFailureMechanismSectionAssembly()
        {
            // Setup
            var random = new Random(21);
            var input  = new FailureMechanismSectionAssemblyInput(
                0.001, 0.0001, true, true, random.NextDouble(),
                FailureMechanismSectionResultFurtherAnalysisType.Executed, random.NextDouble());

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                AssemblyCategoryLimitsKernelStub categoryLimitsKernel = factory.LastCreatedAssemblyCategoryLimitsKernel;
                categoryLimitsKernel.InterpretationCategoryLimits = CreateInterpretationCategories();

                FailureMechanismSectionAssemblyKernelStub failureMechanismSectionAssemblyKernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
                var categoryOutput     = random.NextEnumValue <EInterpretationCategory>();
                var sectionProbability = new Probability(random.NextDouble(0.0, 0.01));
                failureMechanismSectionAssemblyKernel.CategoryOutput     = categoryOutput;
                failureMechanismSectionAssemblyKernel.SectionProbability = sectionProbability;

                var calculator = new FailureMechanismSectionAssemblyCalculator(factory);

                // Call
                FailureMechanismSectionAssemblyResultWrapper resultWrapper = calculator.AssembleFailureMechanismSection(input);

                // Assert
                Assert.IsTrue(categoryLimitsKernel.Calculated);
                Assert.IsTrue(failureMechanismSectionAssemblyKernel.Calculated);

                FailureMechanismSectionAssemblyResult result = resultWrapper.AssemblyResult;
                Assert.AreEqual(sectionProbability, result.ProfileProbability);
                Assert.AreEqual(sectionProbability, result.SectionProbability);
                Assert.AreEqual(1.0, result.N);
                Assert.AreEqual(FailureMechanismSectionAssemblyGroupConverter.ConvertTo(categoryOutput),
                                result.FailureMechanismSectionAssemblyGroup);
                Assert.AreEqual(AssemblyMethod.BOI0A1, resultWrapper.ProbabilityMethod);
                Assert.AreEqual(AssemblyMethod.BOI0B1, resultWrapper.AssemblyGroupMethod);
            }
        }
Esempio n. 10
0
        public void AssembleFailureMechanismSection_WithValidInputAndNoProbabilityDefined_InputCorrectlySentToKernel(
            FailureMechanismSectionAssemblyInput input, EAnalysisState expectedAnalysisState)
        {
            // Setup
            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                FailureMechanismSectionAssemblyKernelStub failureMechanismSectionAssemblyKernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;

                var random         = new Random(21);
                var categoryOutput = random.NextEnumValue <EInterpretationCategory>();
                failureMechanismSectionAssemblyKernel.CategoryOutput     = categoryOutput;
                failureMechanismSectionAssemblyKernel.SectionProbability = new Probability(random.NextDouble());

                var calculator = new FailureMechanismSectionAssemblyCalculator(factory);

                // Call
                calculator.AssembleFailureMechanismSection(input);

                // Assert
                Assert.AreEqual(expectedAnalysisState, failureMechanismSectionAssemblyKernel.AnalysisState);
                Assert.AreEqual(categoryOutput, failureMechanismSectionAssemblyKernel.CategoryInput);
            }
        }
Esempio n. 11
0
        public void AssembleFailureMechanismSection_KernelThrowsException_ThrowsFailureMechanismSectionAssemblyCalculatorException()
        {
            // Setup
            FailureMechanismSectionAssemblyInput input = CreateFailureMechanismSectionAssemblyInput();

            using (new AssemblyToolKernelFactoryConfig())
            {
                var factory = (TestAssemblyToolKernelFactory)AssemblyToolKernelFactory.Instance;
                FailureMechanismSectionAssemblyKernelStub failureMechanismSectionAssemblyKernel = factory.LastCreatedFailureMechanismSectionAssemblyKernel;
                failureMechanismSectionAssemblyKernel.ThrowExceptionOnCalculate = true;

                var calculator = new FailureMechanismSectionAssemblyCalculator(factory);

                // Call
                void Call() => calculator.AssembleFailureMechanismSection(input);

                // Assert
                var exception = Assert.Throws <FailureMechanismSectionAssemblyCalculatorException>(Call);
                Assert.IsInstanceOf <Exception>(exception.InnerException);
                Assert.AreEqual(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), exception.Message);

                Assert.IsFalse(failureMechanismSectionAssemblyKernel.Calculated);
            }
        }
Esempio n. 12
0
        public FailureMechanismSectionAssemblyResultWrapper AssembleFailureMechanismSection(FailureMechanismSectionAssemblyInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            try
            {
                IAssessmentResultsTranslator kernel = factory.CreateFailureMechanismSectionAssemblyKernel();

                if (!IsProbabilityDefined(input))
                {
                    return(AssembleWithUndefinedProbabilities(input, kernel));
                }

                Probability sectionProbability = kernel.DetermineRepresentativeProbabilityBoi0A1(
                    input.FurtherAnalysisType != FailureMechanismSectionResultFurtherAnalysisType.NotNecessary,
                    AssemblyCalculatorInputCreator.CreateProbability(input.InitialSectionProbability),
                    AssemblyCalculatorInputCreator.CreateProbability(input.RefinedSectionProbability));
                EInterpretationCategory interpretationCategory = AssembleInterpretationCategory(input, kernel, sectionProbability);

                return(new FailureMechanismSectionAssemblyResultWrapper(
                           FailureMechanismSectionAssemblyResultCreator.Create(sectionProbability, interpretationCategory),
                           AssemblyMethod.BOI0A1, AssemblyMethod.BOI0B1));
            }
            catch (AssemblyException e)
            {
                throw new FailureMechanismSectionAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateErrorMessage(e.Errors), e);
            }
            catch (Exception e)
            {
                throw new FailureMechanismSectionAssemblyCalculatorException(AssemblyErrorMessageCreator.CreateGenericErrorMessage(), e);
            }
        }
Esempio n. 13
0
        private static FailureMechanismSectionAssemblyResultWrapper AssembleWithUndefinedProbabilities(FailureMechanismSectionAssemblyInput input, IAssessmentResultsTranslator kernel)
        {
            EInterpretationCategory interpretationCategory = kernel.DetermineInterpretationCategoryWithoutProbabilityEstimationBoi0C1(GetAnalysisStatus(input));
            Probability             sectionProbability     = kernel.TranslateInterpretationCategoryToProbabilityBoi0C2(interpretationCategory);

            return(new FailureMechanismSectionAssemblyResultWrapper(
                       FailureMechanismSectionAssemblyResultCreator.Create(sectionProbability, interpretationCategory),
                       AssemblyMethod.BOI0C2, AssemblyMethod.BOI0C1));
        }