public void GetInitialFailureMechanismResultProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double factorOfStability1 = 1.0 / 10.0;
            const double factorOfStability2 = 1.0 / 20.0;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability1, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability2, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)0.2111;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)0.7889;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2,
                macroStabilityInwardsCalculationScenario3
            };

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(calculations, 1.1);

            // Assert
            Assert.AreEqual(0.99052414832077185, initialFailureMechanismResultProbability);
        }
        public void Constructor_CalculationWithoutOutputAndWithWaternet_ChartDataEmpty()
        {
            // Setup
            MacroStabilityInwardsSurfaceLine           surfaceLine           = GetSurfaceLineWithGeometry();
            MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D();

            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                InputParameters =
                {
                    SurfaceLine           = surfaceLine,
                    StochasticSoilProfile = stochasticSoilProfile
                }
            };

            // Call
            using (new MacroStabilityInwardsCalculatorFactoryConfig())
                using (var control = new MacroStabilityInwardsOutputChartControl(calculation,
                                                                                 new GeneralMacroStabilityInwardsInput(),
                                                                                 AssessmentSectionTestHelper.GetTestAssessmentLevel))
                {
                    // Assert
                    IChartControl       chartControl = GetChartControl(control);
                    ChartDataCollection chartData    = chartControl.Data;
                    MacroStabilityInwardsOutputViewChartDataAssert.AssertEmptyChartDataWithEmptySoilLayerAndWithWaternetChartData(chartData);
                    MacroStabilityInwardsOutputViewChartDataAssert.AssertEmptyOutputChartData(chartData);
                    Assert.AreEqual(calculation.Name, chartControl.ChartTitle);
                }
        }
        public void GivenViewWithWaternets_WhenWaternetSetEmpty_ThenNoChartData()
        {
            // Setup
            MacroStabilityInwardsStochasticSoilProfile originalSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D();

            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                InputParameters =
                {
                    StochasticSoilProfile = originalSoilProfile,
                    SurfaceLine           = GetSurfaceLineWithGeometry()
                },
                Output = MacroStabilityInwardsOutputTestFactory.CreateOutput()
            };

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
                using (var control = new MacroStabilityInwardsOutputChartControl(calculation,
                                                                                 new GeneralMacroStabilityInwardsInput(),
                                                                                 AssessmentSectionTestHelper.GetTestAssessmentLevel))
                {
                    // Precondition
                    MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, GetChartControl(control).Data);

                    var calculatorFactory = (TestMacroStabilityInwardsCalculatorFactory)MacroStabilityInwardsCalculatorFactory.Instance;
                    calculatorFactory.LastCreatedWaternetDailyCalculator.Output   = WaternetCalculatorResultTestFactory.CreateEmptyResult();
                    calculatorFactory.LastCreatedWaternetExtremeCalculator.Output = WaternetCalculatorResultTestFactory.CreateEmptyResult();

                    // Call
                    control.UpdateChartData();

                    // Assert
                    MacroStabilityInwardsOutputViewChartDataAssert.AssertEmptyWaternetChartData(GetChartControl(control).Data);
                }
        }
        private static MacroStabilityInwardsFailureMechanismSectionResultCalculateProbabilityStrategy CreateStrategyForMultipleScenarios(FailureMechanismSection section)
        {
            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double factorOfStability1 = 1.0 / 10.0;
            const double factorOfStability2 = 1.0 / 20.0;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability1, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability2, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)0.2111;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)0.7889;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2,
                macroStabilityInwardsCalculationScenario3
            };

            return(new MacroStabilityInwardsFailureMechanismSectionResultCalculateProbabilityStrategy(
                       sectionResult, calculations, new MacroStabilityInwardsFailureMechanism()));
        }
        public void GivenPropertiesWithData_WhenChangingProperties_ThenPropertiesSetOnInput()
        {
            // Given
            var calculation = new MacroStabilityInwardsCalculationScenario();
            MacroStabilityInwardsInput input = calculation.InputParameters;

            var handler    = new ObservablePropertyChangeHandler(calculation, input);
            var properties = new MacroStabilityInwardsGridSettingsProperties(input, handler);

            var    random   = new Random(21);
            bool   moveGrid = random.NextBoolean();
            var    gridDeterminationType        = random.NextEnumValue <MacroStabilityInwardsGridDeterminationType>();
            var    tangentLineDeterminationType = random.NextEnumValue <MacroStabilityInwardsTangentLineDeterminationType>();
            double tangentLineZTop    = random.NextDouble(2.0, 3.0);
            double tangentLineZBottom = random.NextDouble(0.0, 1.0);
            int    tangentLineNumber  = random.Next(1, 51);

            // When
            properties.MoveGrid = moveGrid;
            properties.GridDeterminationType        = gridDeterminationType;
            properties.TangentLineDeterminationType = tangentLineDeterminationType;
            properties.TangentLineZTop    = (RoundedDouble)tangentLineZTop;
            properties.TangentLineZBottom = (RoundedDouble)tangentLineZBottom;
            properties.TangentLineNumber  = tangentLineNumber;

            // Then
            Assert.AreEqual(moveGrid, input.MoveGrid);
            Assert.AreEqual(gridDeterminationType, input.GridDeterminationType);
            Assert.AreEqual(tangentLineDeterminationType, input.TangentLineDeterminationType);
            Assert.AreEqual(tangentLineZTop, input.TangentLineZTop, input.TangentLineZTop.GetAccuracy());
            Assert.AreEqual(tangentLineZBottom, input.TangentLineZBottom, input.TangentLineZBottom.GetAccuracy());
            Assert.AreEqual(tangentLineNumber, input.TangentLineNumber);
        }
        public void CloseForData_NestedViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse()
        {
            // Setup
            var calculation      = new MacroStabilityInwardsCalculationScenario();
            var calculationGroup = new CalculationGroup();

            calculationGroup.Children.Add(calculation);

            var failureMechanism = new MacroStabilityInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculationGroup);

            var assessmentSection = mocks.Stub <IAssessmentSection>();

            assessmentSection.Stub(section => section.FailureMechanismContribution).Return(null);
            assessmentSection.Stub(section => section.GetFailureMechanisms()).Return(new[]
            {
                failureMechanism
            });

            mocks.ReplayAll();

            using (var view = new MacroStabilityInwardsInputView(new MacroStabilityInwardsCalculationScenario(),
                                                                 new GeneralMacroStabilityInwardsInput(),
                                                                 assessmentSection,
                                                                 GetHydraulicBoundaryLocationCalculation))
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsFalse(closeForData);
                mocks.VerifyAll();
            }
        }
Exemplo n.º 7
0
        public void Constructor_WithCalculationWithOutput_PropertiesFromCalculation(double sectionLength)
        {
            // Setup
            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                Output = MacroStabilityInwardsOutputTestFactory.CreateOutput(new MacroStabilityInwardsOutput.ConstructionProperties
                {
                    FactorOfStability = 0.1
                })
            };
            var failureMechanism        = new MacroStabilityInwardsFailureMechanism();
            var failureMechanismSection = new FailureMechanismSection("test", new[]
            {
                new Point2D(0, 0),
                new Point2D(sectionLength, 0)
            });

            // Call
            var row = new MacroStabilityInwardsScenarioRow(calculation, failureMechanism, failureMechanismSection);

            // Assert
            DerivedMacroStabilityInwardsOutput expectedDerivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(calculation.Output, failureMechanism.GeneralInput.ModelFactor);

            Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability, row.FailureProbability);
            Assert.AreEqual(Math.Min(1.0, expectedDerivedOutput.MacroStabilityInwardsProbability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN(
                                         failureMechanismSection.Length)),
                            row.SectionFailureProbability);
        }
Exemplo n.º 8
0
        public void Create_SoilProfileWithMultiplePreconsolidationStressesOnOneLayer_ReturnsPersistableStates()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(
                new TestHydraulicBoundaryLocation());

            calculation.InputParameters.StochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[]
            {
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1)),
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 2))
            });

            IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine;

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            PersistableGeometryFactory.Create(soilProfile, idFactory, registry);

            // Call
            IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry);

            // Assert
            Assert.AreEqual(1, states.Count());

            PersistableState state = states.First();

            Assert.IsNotNull(state.Id);
            CollectionAssert.IsEmpty(state.StateLines);
            CollectionAssert.IsEmpty(state.StatePoints);
        }
        public void GivenPropertiesWithData_WhenChangingProperties_ThenPropertiesSetOnInput()
        {
            // Given
            var calculation = new MacroStabilityInwardsCalculationScenario();
            MacroStabilityInwardsInput input = calculation.InputParameters;

            var handler    = new ObservablePropertyChangeHandler(calculation, input);
            var properties = new MacroStabilityInwardsSlipPlaneSettingsProperties(input, handler);

            var           random            = new Random(21);
            bool          createZones       = random.NextBoolean();
            var           determinationType = random.NextEnumValue <MacroStabilityInwardsZoningBoundariesDeterminationType>();
            RoundedDouble boundaryLeft      = random.NextRoundedDouble();
            RoundedDouble boundaryRight     = random.NextRoundedDouble();

            // When
            properties.CreateZones = createZones;
            properties.ZoningBoundariesDeterminationType = determinationType;
            properties.ZoneBoundaryLeft  = boundaryLeft;
            properties.ZoneBoundaryRight = boundaryRight;

            // Then
            Assert.AreEqual(createZones, input.CreateZones);
            Assert.AreEqual(determinationType, input.ZoningBoundariesDeterminationType);
            Assert.AreEqual(boundaryLeft, input.ZoneBoundaryLeft, input.ZoneBoundaryLeft.GetAccuracy());
            Assert.AreEqual(boundaryRight, input.ZoneBoundaryRight, input.ZoneBoundaryRight.GetAccuracy());
        }
        public void GivenPropertiesWithData_WhenChangingProperties_ThenPropertiesSetOnGrid()
        {
            // Given
            var calculation = new MacroStabilityInwardsCalculationScenario();
            MacroStabilityInwardsInput input = calculation.InputParameters;
            MacroStabilityInwardsGrid  grid  = input.LeftGrid;

            var handler    = new ObservablePropertyChangeHandler(calculation, input);
            var properties = new MacroStabilityInwardsGridProperties(grid, handler, false);

            var           random  = new Random(21);
            RoundedDouble xLeft   = random.NextRoundedDouble();
            var           xRight  = (RoundedDouble)(1 + random.NextDouble());
            var           zTop    = (RoundedDouble)(1 + random.NextDouble());
            RoundedDouble zBottom = random.NextRoundedDouble();
            int           numberOfHorizontalPoints = random.Next(1, 100);
            int           numberOfVerticalPoints   = random.Next(1, 100);

            // When
            properties.XLeft   = xLeft;
            properties.XRight  = xRight;
            properties.ZTop    = zTop;
            properties.ZBottom = zBottom;
            properties.NumberOfHorizontalPoints = numberOfHorizontalPoints;
            properties.NumberOfVerticalPoints   = numberOfVerticalPoints;

            // Then
            Assert.AreEqual(xLeft, grid.XLeft, grid.XLeft.GetAccuracy());
            Assert.AreEqual(xRight, grid.XRight, grid.XRight.GetAccuracy());
            Assert.AreEqual(zTop, grid.ZTop, grid.ZTop.GetAccuracy());
            Assert.AreEqual(zBottom, grid.ZBottom, grid.ZBottom.GetAccuracy());
            Assert.AreEqual(numberOfHorizontalPoints, grid.NumberOfHorizontalPoints);
            Assert.AreEqual(numberOfVerticalPoints, grid.NumberOfVerticalPoints);
        }
Exemplo n.º 11
0
        public void Create_WithValidData_ReturnsPersistableStates()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario   calculation           = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());
            MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[]
            {
                MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(2, 1))
            });

            IMacroStabilityInwardsSoilLayer lastLayer = stochasticSoilProfile.SoilProfile.Layers.Last();

            lastLayer.Data.UsePop = true;
            lastLayer.Data.Pop    = new VariationCoefficientLogNormalDistribution
            {
                Mean = (RoundedDouble)1,
                CoefficientOfVariation = (RoundedDouble)2
            };
            calculation.InputParameters.StochasticSoilProfile = stochasticSoilProfile;

            IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine;

            var idFactory = new IdFactory();
            var registry  = new MacroStabilityInwardsExportRegistry();

            PersistableGeometryFactory.Create(soilProfile, idFactory, registry);

            // Call
            IEnumerable <PersistableState> states = PersistableStateFactory.Create(soilProfile, idFactory, registry);

            // Assert
            PersistableDataModelTestHelper.AssertStates(soilProfile, states);
            PersistableState state = states.First();

            Assert.AreEqual(registry.States[MacroStabilityInwardsExportStageType.Daily], state.Id);
        }
 /// <summary>
 /// Method that asserts whether <paramref name="original"/> and <paramref name="clone"/>
 /// are clones.
 /// </summary>
 /// <param name="original">The original object.</param>
 /// <param name="clone">The cloned object.</param>
 /// <exception cref="AssertionException">Thrown when <paramref name="original"/> and
 /// <paramref name="clone"/> are not clones.</exception>
 public static void AreClones(MacroStabilityInwardsCalculationScenario original,
                              MacroStabilityInwardsCalculationScenario clone)
 {
     Assert.AreEqual(original.Contribution, clone.Contribution);
     Assert.AreEqual(original.IsRelevant, clone.IsRelevant);
     AreClones((MacroStabilityInwardsCalculation)original, clone);
 }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a scenario for which the surface line on the input intersects with <paramref name="section"/> and
        /// is marked as not relevant for the assessment.
        /// </summary>
        /// <param name="section">The section for which an intersection will be created.</param>
        /// <returns>A new <see cref="MacroStabilityInwardsCalculationScenario"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="section"/> is <c>null</c>.</exception>
        public static MacroStabilityInwardsCalculationScenario CreateIrrelevantMacroStabilityInwardsCalculationScenario(FailureMechanismSection section)
        {
            MacroStabilityInwardsCalculationScenario scenario = CreateMacroStabilityInwardsCalculationScenario(0.2, section);

            scenario.IsRelevant = false;
            return(scenario);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Creates a scenario for which the surface line on the input intersects with <paramref name="section"/> and
        /// the calculation has not been performed.
        /// </summary>
        /// <param name="section">The section for which an intersection will be created.</param>
        /// <returns>A new <see cref="MacroStabilityInwardsCalculationScenario"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="section"/> is <c>null</c>.</exception>
        public static MacroStabilityInwardsCalculationScenario CreateNotCalculatedMacroStabilityInwardsCalculationScenario(FailureMechanismSection section)
        {
            if (section == null)
            {
                throw new ArgumentNullException(nameof(section));
            }

            var     surfaceLine = new MacroStabilityInwardsSurfaceLine(string.Empty);
            Point2D p           = section.Points.First();

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(p.X, p.Y, 0),
                new Point3D(p.X + 2, p.Y + 2, 0)
            });
            surfaceLine.ReferenceLineIntersectionWorldPoint = section.Points.First();

            var scenario = new MacroStabilityInwardsCalculationScenario
            {
                IsRelevant      = true,
                InputParameters =
                {
                    SurfaceLine = surfaceLine
                }
            };

            return(scenario);
        }
        public void CloseForData_NestedViewNotCorrespondingWithRemovedParentCalculationGroupContext_ReturnsFalse()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculation = new MacroStabilityInwardsCalculationScenario();
            var nestedGroup = new CalculationGroup();

            nestedGroup.Children.Add(calculation);
            var calculationGroup = new CalculationGroup();

            calculationGroup.Children.Add(nestedGroup);

            var calculationGroupContext = new MacroStabilityInwardsCalculationGroupContext(new CalculationGroup(),
                                                                                           null,
                                                                                           Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(),
                                                                                           Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(),
                                                                                           new MacroStabilityInwardsFailureMechanism(),
                                                                                           assessmentSection);

            using (var view = new MacroStabilityInwardsInputView(calculation,
                                                                 new GeneralMacroStabilityInwardsInput(),
                                                                 assessmentSection,
                                                                 GetHydraulicBoundaryLocationCalculation))
            {
                // Call
                bool closeForData = info.CloseForData(view, calculationGroupContext);

                // Assert
                Assert.IsFalse(closeForData);
                mocks.VerifyAll();
            }
        }
Exemplo n.º 16
0
        public void Run_ValidMacroStabilityInwardsCalculation_PerformMacroStabilityInwardsValidationAndCalculationAndLogStartAndEnd()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario validMacroStabilityInwardsCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                var activity = new MacroStabilityInwardsCalculationActivity(validMacroStabilityInwardsCalculation,
                                                                            new GeneralMacroStabilityInwardsInput(),
                                                                            AssessmentSectionTestHelper.GetTestAssessmentLevel());

                // Call
                Action call = () => activity.Run();

                // Assert
                TestHelper.AssertLogMessages(call, messages =>
                {
                    string[] msgs = messages.ToArray();
                    Assert.AreEqual(7, msgs.Length);
                    Assert.AreEqual($"Uitvoeren van berekening '{validMacroStabilityInwardsCalculation.Name}' is gestart.", msgs[0]);
                    CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                    Assert.AreEqual("Validatie van waterspanningen in extreme omstandigheden is gestart.", msgs[2]);
                    Assert.AreEqual("Validatie van waterspanningen in dagelijkse omstandigheden is gestart.", msgs[3]);
                    CalculationServiceTestHelper.AssertValidationEndMessage(msgs[4]);
                    CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[5]);
                    CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[6]);
                });
                Assert.AreEqual(ActivityState.Executed, activity.State);
                Assert.IsNotNull(validMacroStabilityInwardsCalculation.Output);
            }
        }
        public void CloseForData_NestedViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculation      = new MacroStabilityInwardsCalculationScenario();
            var calculationGroup = new CalculationGroup();

            calculationGroup.Children.Add(calculation);

            var failureMechanism = new MacroStabilityInwardsFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculationGroup);

            var context = new MacroStabilityInwardsFailureMechanismContext(failureMechanism, assessmentSection);

            using (var view = new MacroStabilityInwardsInputView(calculation,
                                                                 new GeneralMacroStabilityInwardsInput(),
                                                                 assessmentSection,
                                                                 GetHydraulicBoundaryLocationCalculation))
            {
                // Call
                bool closeForData = info.CloseForData(view, context);

                // Assert
                Assert.IsTrue(closeForData);
                mocks.VerifyAll();
            }
        }
Exemplo n.º 18
0
        public void Finish_ValidMacroStabilityInwardsCalculationAndRan_NotifyObserversOfMacroStabilityInwardsCalculation()
        {
            // Setup
            var mocks    = new MockRepository();
            var observer = mocks.StrictMock <IObserver>();

            observer.Expect(o => o.UpdateObserver());
            mocks.ReplayAll();

            MacroStabilityInwardsCalculationScenario validMacroStabilityInwardsCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            validMacroStabilityInwardsCalculation.Output = null;
            validMacroStabilityInwardsCalculation.Attach(observer);

            var activity = new MacroStabilityInwardsCalculationActivity(validMacroStabilityInwardsCalculation,
                                                                        new GeneralMacroStabilityInwardsInput(),
                                                                        AssessmentSectionTestHelper.GetTestAssessmentLevel());

            activity.Run();

            // Call
            activity.Finish();

            // Assert
            mocks.VerifyAll();
        }
Exemplo n.º 19
0
        public void GivenScenarioRow_WhenOutputSetToNullAndUpdate_ThenDerivedOutputUpdated()
        {
            // Given
            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput()
            };
            var failureMechanism = new MacroStabilityInwardsFailureMechanism();
            FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

            var row = new MacroStabilityInwardsScenarioRow(calculation, failureMechanism, failureMechanismSection);

            // Precondition
            DerivedMacroStabilityInwardsOutput expectedDerivedOutput = DerivedMacroStabilityInwardsOutputFactory.Create(calculation.Output, failureMechanism.GeneralInput.ModelFactor);

            Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability, row.FailureProbability);
            Assert.AreEqual(expectedDerivedOutput.MacroStabilityInwardsProbability * failureMechanism.MacroStabilityInwardsProbabilityAssessmentInput.GetN(
                                failureMechanismSection.Length),
                            row.SectionFailureProbability);

            // When
            calculation.Output = null;
            row.Update();

            // Then
            Assert.IsNaN(row.FailureProbability);
            Assert.IsNaN(row.SectionFailureProbability);
        }
Exemplo n.º 20
0
        public void Run_InvalidMacroStabilityInwardsCalculation_LogValidationStartAndEndWithErrors()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario invalidMacroStabilityInwardsCalculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput();

            var activity = new MacroStabilityInwardsCalculationActivity(invalidMacroStabilityInwardsCalculation,
                                                                        new GeneralMacroStabilityInwardsInput(),
                                                                        AssessmentSectionTestHelper.GetTestAssessmentLevel());

            // Call
            Action call = () => activity.Run();

            // Assert
            TestHelper.AssertLogMessagesWithLevelAndLoggedExceptions(call, messages =>
            {
                Tuple <string, Level, Exception>[] tupleArray = messages.ToArray();
                string[] msgs = tupleArray.Select(tuple => tuple.Item1).ToArray();

                Assert.AreEqual(6, msgs.Length);
                Assert.AreEqual($"Uitvoeren van berekening '{invalidMacroStabilityInwardsCalculation.Name}' is gestart.", msgs[0]);
                CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]);
                Assert.AreEqual(Level.Error, tupleArray[2].Item2);
                Assert.AreEqual(Level.Error, tupleArray[3].Item2);
                Assert.AreEqual(Level.Error, tupleArray[4].Item2);
                CalculationServiceTestHelper.AssertValidationEndMessage(msgs[5]);
            });
            Assert.AreEqual(ActivityState.Failed, activity.State);
        }
        public void GivenAssessmentSectionResultObserverWithAttachedObserver_WhenMacroStabilityInwardsCalculationScenarioNotified_ThenAttachedObserverNotified()
        {
            // Given
            AssessmentSection assessmentSection = CreateAssessmentSection();
            MacroStabilityInwardsCalculationScenario calculation =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithInvalidInput();

            assessmentSection.MacroStabilityInwards.CalculationsGroup.Children.Add(calculation);

            using (var resultObserver = new AssessmentSectionResultObserver(assessmentSection))
            {
                var mocks    = new MockRepository();
                var observer = mocks.StrictMock <IObserver>();
                observer.Expect(o => o.UpdateObserver());
                mocks.ReplayAll();

                resultObserver.Attach(observer);

                // When
                calculation.NotifyObservers();

                // Then
                mocks.VerifyAll();
            }
        }
        public void CreateCalculationFeatures_GivenCalculations_ReturnsCalculationFeaturesCollection()
        {
            // Setup
            MacroStabilityInwardsCalculationScenario calculationA = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new HydraulicBoundaryLocation(1, string.Empty, 5.0, 4.0));
            MacroStabilityInwardsCalculationScenario calculationB = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new HydraulicBoundaryLocation(1, string.Empty, 2.2, 3.8));

            calculationA.InputParameters.SurfaceLine.ReferenceLineIntersectionWorldPoint = new Point2D(1.0, 3.0);
            calculationB.InputParameters.SurfaceLine.ReferenceLineIntersectionWorldPoint = new Point2D(1.0, 4.0);

            // Call
            IEnumerable <MapFeature> features = MacroStabilityInwardsMapDataFeaturesFactory.CreateCalculationFeatures(new[]
            {
                calculationA,
                calculationB
            });

            // Assert
            Assert.AreEqual(2, features.Count());
            Assert.AreEqual(1, features.ElementAt(0).MapGeometries.Count());
            Assert.AreEqual(1, features.ElementAt(1).MapGeometries.Count());
            AssertEqualPointCollections(new[]
            {
                new Point2D(1.0, 3.0),
                new Point2D(5.0, 4.0)
            }, features.ElementAt(0).MapGeometries.ElementAt(0));
            AssertEqualPointCollections(new[]
            {
                new Point2D(1.0, 4.0),
                new Point2D(2.2, 3.8)
            }, features.ElementAt(1).MapGeometries.ElementAt(0));
        }
        public void CalculateProfileProbability_MultipleScenarios_ReturnsValueBasedOnRelevantScenarios()
        {
            // Setup
            FailureMechanismSection section = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var sectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double factorOfStability1 = 1.0 / 10.0;
            const double factorOfStability2 = 1.0 / 20.0;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability1, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(factorOfStability2, section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario3 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateIrrelevantMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)0.2111;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)0.7889;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2,
                macroStabilityInwardsCalculationScenario3
            };

            var strategy = new MacroStabilityInwardsFailureMechanismSectionResultCalculateProbabilityStrategy(
                sectionResult, calculations, new MacroStabilityInwardsFailureMechanism());

            // Call
            double profileProbability = strategy.CalculateProfileProbability();

            // Assert
            Assert.AreEqual(0.99012835, profileProbability, 1e-8);
        }
        /// <summary>
        /// Asserts whether <paramref name="actual"/> corresponds to the output of <paramref name="calculationScenario"/>.
        /// </summary>
        /// <param name="calculationScenario">The original <see cref="MacroStabilityInwardsCalculationScenario"/>.</param>
        /// <param name="actual">The actual <see cref="ChartDataCollection"/>.</param>
        /// <exception cref="AssertionException">Thrown when <paramref name="actual"/>
        /// does not correspond to <paramref name="calculationScenario"/>.</exception>
        public static void AssertOutputChartData(MacroStabilityInwardsCalculationScenario calculationScenario, ChartDataCollection actual)
        {
            Assert.AreEqual(nrOfChartData, actual.Collection.Count());

            MacroStabilityInwardsViewChartDataAssert.AssertGridChartData(calculationScenario.Output.SlipPlane.LeftGrid,
                                                                         (ChartPointData)actual.Collection.ElementAt(leftGridIndex));
            MacroStabilityInwardsViewChartDataAssert.AssertGridChartData(calculationScenario.Output.SlipPlane.RightGrid,
                                                                         (ChartPointData)actual.Collection.ElementAt(rightGridIndex));

            AssertTangentLinesChartData(calculationScenario.Output.SlipPlane.TangentLines, calculationScenario.InputParameters.SurfaceLine,
                                        (ChartMultipleLineData)actual.Collection.ElementAt(tangentLinesIndex));

            AssertSlicesChartData(calculationScenario.Output.SlidingCurve.Slices,
                                  (ChartMultipleAreaData)actual.Collection.ElementAt(slicesIndex));

            AssertSliceParametersChartData(calculationScenario.Output.SlidingCurve.Slices,
                                           (ChartDataCollection)actual.Collection.ElementAt(sliceParameterIndex));

            AssertSlipPlaneChartData(calculationScenario.Output.SlidingCurve,
                                     (ChartLineData)actual.Collection.ElementAt(slipPlaneIndex));

            AssertCircleRadiusChartData(calculationScenario.Output.SlidingCurve.Slices.First().TopLeftPoint,
                                        calculationScenario.Output.SlidingCurve.LeftCircle,
                                        (ChartLineData)actual.Collection.ElementAt(activeCircleRadiusIndex));
            AssertCircleRadiusChartData(calculationScenario.Output.SlidingCurve.Slices.Last().TopRightPoint,
                                        calculationScenario.Output.SlidingCurve.RightCircle,
                                        (ChartLineData)actual.Collection.ElementAt(passiveCircleRadiusIndex));
        }
        public void Constructor_CalculationWithoutStochasticSoilProfile_ChartDataSetWithDefaultSoilProfileChartDataName()
        {
            // Setup
            MacroStabilityInwardsSurfaceLine surfaceLine = GetSurfaceLineWithGeometry();

            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                InputParameters =
                {
                    SurfaceLine = surfaceLine
                }
            };

            // Call
            using (new MacroStabilityInwardsCalculatorFactoryConfig())
                using (var control = new MacroStabilityInwardsOutputChartControl(calculation,
                                                                                 new GeneralMacroStabilityInwardsInput(),
                                                                                 AssessmentSectionTestHelper.GetTestAssessmentLevel))
                {
                    // Assert
                    IChartControl       chartControl = GetChartControl(control);
                    ChartDataCollection chartData    = chartControl.Data;
                    MacroStabilityInwardsViewChartDataAssert.AssertSoilProfileChartData(calculation.InputParameters.SoilProfileUnderSurfaceLine,
                                                                                        "Ondergrondschematisatie",
                                                                                        false,
                                                                                        chartData.Collection.ElementAt(soilProfileIndex));

                    Assert.AreEqual(calculation.Name, chartControl.ChartTitle);
                }
        }
        private static void AssertCalculationsMapData(IEnumerable <MacroStabilityInwardsCalculationScenario> calculations, MapData mapData)
        {
            Assert.IsInstanceOf <MapLineData>(mapData);
            var calculationsMapData = (MapLineData)mapData;

            MacroStabilityInwardsCalculationScenario[] calculationsArray = calculations.ToArray();
            MapFeature[] calculationsFeatures = calculationsMapData.Features.ToArray();
            Assert.AreEqual(calculationsArray.Length, calculationsFeatures.Length);

            for (var index = 0; index < calculationsArray.Length; index++)
            {
                MapGeometry[] geometries = calculationsFeatures[index].MapGeometries.ToArray();
                Assert.AreEqual(1, geometries.Length);

                MacroStabilityInwardsCalculationScenario calculation = calculationsArray[index];
                CollectionAssert.AreEquivalent(new[]
                {
                    calculation.InputParameters.SurfaceLine.ReferenceLineIntersectionWorldPoint,
                    calculation.InputParameters.HydraulicBoundaryLocation.Location
                },
                                               geometries[0].PointCollections.First());
            }

            Assert.AreEqual("Berekeningen", mapData.Name);
        }
        public void GivenCalculationWithStochasticSoilProfileAndSurfaceLine_WhenStochasticSoilProfileUpdate_ThenChartDataUpdated()
        {
            // Given
            MacroStabilityInwardsStochasticSoilProfile originalSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D();

            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                InputParameters =
                {
                    StochasticSoilProfile = originalSoilProfile,
                    SurfaceLine           = GetSurfaceLineWithGeometry()
                },
                Output = MacroStabilityInwardsOutputTestFactory.CreateOutput()
            };

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
                using (var control = new MacroStabilityInwardsOutputChartControl(calculation,
                                                                                 new GeneralMacroStabilityInwardsInput(),
                                                                                 AssessmentSectionTestHelper.GetTestAssessmentLevel))
                {
                    ChartDataCollection chartData = GetChartControl(control).Data;

                    // Precondition
                    MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, chartData);

                    MacroStabilityInwardsStochasticSoilProfile newSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D();

                    // When
                    calculation.InputParameters.StochasticSoilProfile = newSoilProfile;
                    control.UpdateChartData();

                    // Then
                    MacroStabilityInwardsOutputViewChartDataAssert.AssertInputChartData(calculation, chartData);
                }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Gets a <see cref="MacroStabilityInwardsCalculationScenario"/> with <c>double.NaN</c> values set.
        /// </summary>
        /// <returns>A <see cref="MacroStabilityInwardsCalculationScenario"/> with <c>double.NaN</c> values.</returns>
        public static MacroStabilityInwardsCalculationScenario GetMacroStabilityInwardsCalculationScenarioWithNaNs()
        {
            MacroStabilityInwardsCalculationScenario calculation = GetMacroStabilityInwardsCalculationScenarioWithAssessmentLevel();

            MacroStabilityInwardsInput input = calculation.InputParameters;

            input.WaterLevelRiverAverage          = RoundedDouble.NaN;
            input.XCoordinateDrainageConstruction = RoundedDouble.NaN;
            input.ZCoordinateDrainageConstruction = RoundedDouble.NaN;

            input.MinimumLevelPhreaticLineAtDikeTopPolder = RoundedDouble.NaN;
            input.MinimumLevelPhreaticLineAtDikeTopRiver  = RoundedDouble.NaN;

            input.LeakageLengthInwardsPhreaticLine3    = RoundedDouble.NaN;
            input.LeakageLengthOutwardsPhreaticLine3   = RoundedDouble.NaN;
            input.LeakageLengthInwardsPhreaticLine4    = RoundedDouble.NaN;
            input.LeakageLengthOutwardsPhreaticLine4   = RoundedDouble.NaN;
            input.PiezometricHeadPhreaticLine2Inwards  = RoundedDouble.NaN;
            input.PiezometricHeadPhreaticLine2Outwards = RoundedDouble.NaN;

            input.AssessmentLevel        = RoundedDouble.NaN;
            input.SlipPlaneMinimumDepth  = RoundedDouble.NaN;
            input.SlipPlaneMinimumLength = RoundedDouble.NaN;
            input.MaximumSliceWidth      = RoundedDouble.NaN;

            input.TangentLineZTop    = RoundedDouble.NaN;
            input.TangentLineZBottom = RoundedDouble.NaN;

            input.LeftGrid.XLeft   = RoundedDouble.NaN;
            input.LeftGrid.XRight  = RoundedDouble.NaN;
            input.LeftGrid.ZTop    = RoundedDouble.NaN;
            input.LeftGrid.ZBottom = RoundedDouble.NaN;

            input.RightGrid.XLeft   = RoundedDouble.NaN;
            input.RightGrid.XRight  = RoundedDouble.NaN;
            input.RightGrid.ZTop    = RoundedDouble.NaN;
            input.RightGrid.ZBottom = RoundedDouble.NaN;

            IMacroStabilityInwardsLocationInputDaily inputDaily = input.LocationInputDaily;

            inputDaily.WaterLevelPolder = RoundedDouble.NaN;
            inputDaily.PhreaticLineOffsetBelowDikeTopAtRiver     = RoundedDouble.NaN;
            inputDaily.PhreaticLineOffsetBelowDikeTopAtPolder    = RoundedDouble.NaN;
            inputDaily.PhreaticLineOffsetBelowShoulderBaseInside = RoundedDouble.NaN;
            inputDaily.PhreaticLineOffsetBelowDikeToeAtPolder    = RoundedDouble.NaN;

            IMacroStabilityInwardsLocationInputExtreme inputExtreme = input.LocationInputExtreme;

            inputExtreme.PenetrationLength = RoundedDouble.NaN;
            inputExtreme.WaterLevelPolder  = RoundedDouble.NaN;
            inputExtreme.PhreaticLineOffsetBelowDikeTopAtRiver     = RoundedDouble.NaN;
            inputExtreme.PhreaticLineOffsetBelowDikeTopAtPolder    = RoundedDouble.NaN;
            inputExtreme.PhreaticLineOffsetBelowShoulderBaseInside = RoundedDouble.NaN;
            inputExtreme.PhreaticLineOffsetBelowDikeToeAtPolder    = RoundedDouble.NaN;

            input.ZoneBoundaryLeft  = RoundedDouble.NaN;
            input.ZoneBoundaryRight = RoundedDouble.NaN;

            return(calculation);
        }
        public void IsEnabled_CalculationGroupChildIsNestedGroupWithCalculationWithAndWithoutOutput_ReturnTrue()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculation = new MacroStabilityInwardsCalculationScenario
            {
                Output = MacroStabilityInwardsOutputTestFactory.CreateOutput()
            };

            var nestedGroup = new CalculationGroup();

            nestedGroup.Children.Add(calculation);
            nestedGroup.Children.Add(new MacroStabilityInwardsCalculationScenario());

            var calculationGroup = new CalculationGroup();

            calculationGroup.Children.Add(nestedGroup);

            var context = new MacroStabilityInwardsCalculationGroupContext(calculationGroup,
                                                                           null,
                                                                           Enumerable.Empty <MacroStabilityInwardsSurfaceLine>(),
                                                                           Enumerable.Empty <MacroStabilityInwardsStochasticSoilModel>(),
                                                                           new MacroStabilityInwardsFailureMechanism(),
                                                                           assessmentSection);

            // Call
            bool isEnabled = info.IsEnabled(context);

            // Assert
            Assert.IsTrue(isEnabled);
        }
        public void GetInitialFailureMechanismResultProbability_ScenarioWithNaNResults_ReturnsNaN()
        {
            // Setup
            FailureMechanismSection section   = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();
            var failureMechanismSectionResult = new AdoptableWithProfileProbabilityFailureMechanismSectionResult(section);

            const double contribution1 = 0.2;
            const double contribution2 = 0.8;

            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario1 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithNaNOutput(section);
            MacroStabilityInwardsCalculationScenario macroStabilityInwardsCalculationScenario2 =
                MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenario(section);

            macroStabilityInwardsCalculationScenario1.IsRelevant   = true;
            macroStabilityInwardsCalculationScenario1.Contribution = (RoundedDouble)contribution1;

            macroStabilityInwardsCalculationScenario2.IsRelevant   = true;
            macroStabilityInwardsCalculationScenario2.Contribution = (RoundedDouble)contribution2;

            MacroStabilityInwardsCalculationScenario[] calculations =
            {
                macroStabilityInwardsCalculationScenario1,
                macroStabilityInwardsCalculationScenario2
            };

            // Call
            double initialFailureMechanismResultProbability = failureMechanismSectionResult.GetInitialFailureMechanismResultProbability(calculations, 0.1);

            // Assert
            Assert.IsNaN(initialFailureMechanismResultProbability);
        }