Example #1
0
        public void Constructor_CalculationWithOutput_ExpectedValues(double sectionLength)
        {
            // Setup
            var failureMechanism = new PipingFailureMechanism();

            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);

            mocks.ReplayAll();

            var calculation = new SemiProbabilisticPipingCalculationScenario
            {
                Output = PipingTestDataGenerator.GetRandomSemiProbabilisticPipingOutput()
            };
            var failureMechanismSection = new FailureMechanismSection("test", new[]
            {
                new Point2D(0, 0),
                new Point2D(sectionLength, 0)
            });

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

            // Assert
            DerivedSemiProbabilisticPipingOutput expectedDerivedOutput = DerivedSemiProbabilisticPipingOutputFactory.Create(calculation.Output, assessmentSection.FailureMechanismContribution.NormativeProbability);

            Assert.AreEqual(expectedDerivedOutput.PipingProbability, row.FailureProbability);
            Assert.AreEqual(expectedDerivedOutput.UpliftProbability, row.FailureProbabilityUplift);
            Assert.AreEqual(expectedDerivedOutput.HeaveProbability, row.FailureProbabilityHeave);
            Assert.AreEqual(expectedDerivedOutput.SellmeijerProbability, row.FailureProbabilitySellmeijer);
            Assert.AreEqual(Math.Min(1.0, expectedDerivedOutput.PipingProbability * failureMechanism.PipingProbabilityAssessmentInput.GetN(
                                         failureMechanismSection.Length)),
                            row.SectionFailureProbability);
            mocks.VerifyAll();
        }
Example #2
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var failureMechanism = new PipingFailureMechanism();

            var mocks = new MockRepository();
            IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(failureMechanism, mocks);

            mocks.ReplayAll();

            var calculation = new SemiProbabilisticPipingCalculationScenario();
            FailureMechanismSection failureMechanismSection = FailureMechanismSectionTestFactory.CreateFailureMechanismSection();

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

            // Assert
            Assert.IsInstanceOf <PipingScenarioRow <SemiProbabilisticPipingCalculationScenario> >(row);
            Assert.AreSame(calculation, row.CalculationScenario);

            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilityUplift));
            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilityHeave));
            TestHelper.AssertTypeConverter <SemiProbabilisticPipingScenarioRow, NoProbabilityValueDoubleConverter>(
                nameof(SemiProbabilisticPipingScenarioRow.FailureProbabilitySellmeijer));
        }
Example #3
0
        public void Create_StochasticSoilProfileSet_EntityHasStochasticSoilProfileEntity()
        {
            // Setup
            PipingSoilProfile soilProfile = PipingSoilProfileTestFactory.CreatePipingSoilProfile();
            var stochasticSoilProfile     = new PipingStochasticSoilProfile(0.6, soilProfile);

            PipingStochasticSoilModel soilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel("A", new[]
            {
                stochasticSoilProfile
            });

            var registry = new PersistenceRegistry();
            StochasticSoilModelEntity soilModelEntity = soilModel.Create(registry, 0);

            var calculation = new SemiProbabilisticPipingCalculationScenario
            {
                InputParameters =
                {
                    StochasticSoilModel   = soilModel,
                    StochasticSoilProfile = stochasticSoilProfile
                }
            };

            // Call
            SemiProbabilisticPipingCalculationEntity entity = calculation.Create(registry, 0);

            // Assert
            PipingStochasticSoilProfileEntity expectedStochasticSoilProfileEntity = soilModelEntity.PipingStochasticSoilProfileEntities.First();

            Assert.AreSame(expectedStochasticSoilProfileEntity, entity.PipingStochasticSoilProfileEntity);
            Assert.IsTrue(registry.Contains(soilModel));
        }
Example #4
0
        public void Create_HasCalculationOutput_EntityHasPipingCalculationOutputEntity()
        {
            // Setup
            var registry = new PersistenceRegistry();

            SemiProbabilisticPipingOutput newOutput = PipingTestDataGenerator.GetRandomSemiProbabilisticPipingOutput();
            var calculation = new SemiProbabilisticPipingCalculationScenario
            {
                Output = newOutput
            };

            // Call
            SemiProbabilisticPipingCalculationEntity entity = calculation.Create(registry, 0);

            // Assert
            SemiProbabilisticPipingCalculationOutputEntity outputEntity = entity.SemiProbabilisticPipingCalculationOutputEntities.SingleOrDefault();

            Assert.IsNotNull(outputEntity);
            Assert.AreEqual(newOutput.HeaveFactorOfSafety, outputEntity.HeaveFactorOfSafety);
            Assert.AreEqual(newOutput.SellmeijerFactorOfSafety, outputEntity.SellmeijerFactorOfSafety);
            Assert.AreEqual(newOutput.UpliftFactorOfSafety, outputEntity.UpliftFactorOfSafety);
            Assert.AreEqual(newOutput.UpliftEffectiveStress, outputEntity.UpliftEffectiveStress, newOutput.UpliftEffectiveStress.GetAccuracy());
            Assert.AreEqual(newOutput.HeaveGradient, outputEntity.HeaveGradient, newOutput.HeaveGradient.GetAccuracy());
            Assert.AreEqual(newOutput.SellmeijerCreepCoefficient, outputEntity.SellmeijerCreepCoefficient, newOutput.SellmeijerCreepCoefficient.GetAccuracy());
            Assert.AreEqual(newOutput.SellmeijerCriticalFall, outputEntity.SellmeijerCriticalFall, newOutput.SellmeijerCriticalFall.GetAccuracy());
            Assert.AreEqual(newOutput.SellmeijerReducedFall, outputEntity.SellmeijerReducedFall, newOutput.SellmeijerReducedFall.GetAccuracy());
        }
Example #5
0
        public void Create_HasSurfaceLineSet_EntityHasSurfaceLineEntity()
        {
            // Setup
            var surfaceLine = new PipingSurfaceLine(string.Empty)
            {
                ReferenceLineIntersectionWorldPoint = new Point2D(1.1, 2.2)
            };

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(0.0, 0.0, 1.0),
                new Point3D(3.3, 6.6, 1.0)
            });

            var registry = new PersistenceRegistry();
            SurfaceLineEntity surfaceLineEntity = surfaceLine.Create(registry, 0);

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

            // Call
            SemiProbabilisticPipingCalculationEntity entity = calculation.Create(registry, 0);

            // Assert
            Assert.AreSame(surfaceLineEntity, entity.SurfaceLineEntity);
        }
Example #6
0
        public void CloseForData_NestedViewNotCorrespondingToRemovedAssessmentSection_ReturnsFalse()
        {
            // Setup
            var calculation      = new SemiProbabilisticPipingCalculationScenario();
            var calculationGroup = new CalculationGroup();

            calculationGroup.Children.Add(calculation);

            var failureMechanism = new PipingFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculationGroup);

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

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

            mocks.ReplayAll();

            using (var view = new PipingInputView
            {
                Data = new SemiProbabilisticPipingCalculationScenario()
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, assessmentSection);

                // Assert
                Assert.IsFalse(closeForData);
                mocks.VerifyAll();
            }
        }
Example #7
0
        public void CloseForData_NestedViewCorrespondingToRemovedFailureMechanismContext_ReturnsTrue()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

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

            calculationGroup.Children.Add(calculation);

            var failureMechanism = new PipingFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculationGroup);

            var context = new PipingFailureMechanismContext(failureMechanism, assessmentSection);

            using (var view = new PipingInputView
            {
                Data = calculation
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, context);

                // Assert
                Assert.IsTrue(closeForData);
                mocks.VerifyAll();
            }
        }
        public void Read_EntityWithSurfaceLineNotYetInCollector_CalculationWithCreatedSurfaceLineAndRegisteredNewEntities()
        {
            // Setup
            var points = new[]
            {
                new Point3D(1, 3, 4),
                new Point3D(7, 10, 11)
            };

            var surfaceLineEntity = new SurfaceLineEntity
            {
                Name      = "surface line",
                PointsXml = new Point3DCollectionXmlSerializer().ToXml(points)
            };

            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                SurfaceLineEntity     = surfaceLineEntity,
                EntryPointL           = 1,
                ExitPointL            = 2,
                DampingFactorExitMean = 1,
                ScenarioContribution  = 0
            };

            var collector = new ReadConversionCollector();

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            Assert.IsTrue(collector.ContainsPipingSurfaceLine(surfaceLineEntity));
            CollectionAssert.AreEqual(points, calculation.InputParameters.SurfaceLine.Points);
        }
Example #9
0
        public void ParameteredConstructor_ParentNull_ThrowsArgumentNullException()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var surfaceLines = new[]
            {
                new PipingSurfaceLine(string.Empty)
            };

            PipingStochasticSoilModel[] soilModels =
            {
                PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel()
            };
            var calculation      = new SemiProbabilisticPipingCalculationScenario();
            var failureMechanism = new PipingFailureMechanism();

            // Call
            TestDelegate call = () => new SemiProbabilisticPipingCalculationScenarioContext(calculation,
                                                                                            null,
                                                                                            surfaceLines,
                                                                                            soilModels,
                                                                                            failureMechanism,
                                                                                            assessmentSection);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(call);

            Assert.AreEqual("parent", exception.ParamName);
            mocks.VerifyAll();
        }
        public void Read_EntityWithSurfaceLineInCollector_CalculationHasAlreadyReadSurfaceLine()
        {
            // Setup
            var surfaceLine = new PipingSurfaceLine(string.Empty);

            surfaceLine.SetGeometry(new[]
            {
                new Point3D(1, 2, 3),
                new Point3D(4, 5, 6)
            });
            var surfaceLineEntity = new SurfaceLineEntity();
            var entity            = new SemiProbabilisticPipingCalculationEntity
            {
                SurfaceLineEntity     = surfaceLineEntity,
                EntryPointL           = 1,
                ExitPointL            = 2,
                DampingFactorExitMean = 1,
                ScenarioContribution  = 0
            };

            var collector = new ReadConversionCollector();

            collector.Read(surfaceLineEntity, surfaceLine);

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(surfaceLine, calculation.InputParameters.SurfaceLine);
            Assert.AreEqual(1, calculation.InputParameters.EntryPointL, 1e-6);
            Assert.AreEqual(2, calculation.InputParameters.ExitPointL, 1e-6);
        }
Example #11
0
        /// <summary>
        /// Assigns the hydraulic boundary location or the assessment level that is set manually.
        /// </summary>
        /// <param name="calculationConfiguration">The calculation read from the imported file.</param>
        /// <param name="pipingCalculation">The semi-probabilistic calculation to configure.</param>
        /// <returns><c>false</c> when the <paramref name="calculationConfiguration"/> has a <see cref="HydraulicBoundaryLocation"/>
        /// set which is not available in <see cref="availableHydraulicBoundaryLocations"/>, <c>true</c> otherwise.</returns>
        private bool TrySetSemiProbabilisticHydraulicBoundaryData(PipingCalculationConfiguration calculationConfiguration,
                                                                  SemiProbabilisticPipingCalculationScenario pipingCalculation)
        {
            bool locationRead = TryReadHydraulicBoundaryLocation(calculationConfiguration.HydraulicBoundaryLocationName,
                                                                 calculationConfiguration.Name,
                                                                 availableHydraulicBoundaryLocations,
                                                                 out HydraulicBoundaryLocation location);

            if (!locationRead)
            {
                return(false);
            }

            if (calculationConfiguration.AssessmentLevel.HasValue)
            {
                pipingCalculation.InputParameters.UseAssessmentLevelManualInput = true;
                pipingCalculation.InputParameters.AssessmentLevel = (RoundedDouble)calculationConfiguration.AssessmentLevel.Value;
            }
            else
            {
                SetLocation(pipingCalculation, location);
            }

            return(true);
        }
Example #12
0
        public void CloseForData_ViewCorrespondingToRemovedPipingCalculationScenarioContext_ReturnsTrue()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var pipingCalculation = new SemiProbabilisticPipingCalculationScenario();
            var pipingCalculationScenarioContext = new SemiProbabilisticPipingCalculationScenarioContext(pipingCalculation,
                                                                                                         new CalculationGroup(),
                                                                                                         Enumerable.Empty <PipingSurfaceLine>(),
                                                                                                         Enumerable.Empty <PipingStochasticSoilModel>(),
                                                                                                         new PipingFailureMechanism(),
                                                                                                         assessmentSection);

            using (var view = new PipingInputView
            {
                Data = pipingCalculation
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, pipingCalculationScenarioContext);

                // Assert
                Assert.IsTrue(closeForData);
                mocks.VerifyAll();
            }
        }
Example #13
0
        public void CloseForData_NestedViewNotCorrespondingWithRemovedParentPipingCalculationGroupContext_ReturnsFalse()
        {
            // Setup
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

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

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

            calculationGroup.Children.Add(nestedGroup);

            var calculationGroupContext = new PipingCalculationGroupContext(new CalculationGroup(),
                                                                            null,
                                                                            Enumerable.Empty <PipingSurfaceLine>(),
                                                                            Enumerable.Empty <PipingStochasticSoilModel>(),
                                                                            new PipingFailureMechanism(),
                                                                            assessmentSection);

            using (var view = new PipingInputView
            {
                Data = calculation
            })
            {
                // Call
                bool closeForData = info.CloseForData(view, calculationGroupContext);

                // Assert
                Assert.IsFalse(closeForData);
                mocks.VerifyAll();
            }
        }
        public void Read_EntityWithHydraulicBoundaryLocationInCollector_CalculationHasAlreadyReadHydraulicBoundaryLocation()
        {
            // Setup
            var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation();
            var hydraulicLocationEntity   = new HydraulicLocationEntity();
            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                HydraulicLocationEntity = hydraulicLocationEntity,
                EntryPointL             = 1,
                ExitPointL                    = 2,
                DampingFactorExitMean         = 1,
                AssessmentLevel               = 5.81,
                UseAssessmentLevelManualInput = Convert.ToByte(false),
                ScenarioContribution          = 0
            };

            var collector = new ReadConversionCollector();

            collector.Read(hydraulicLocationEntity, hydraulicBoundaryLocation);

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(hydraulicBoundaryLocation, calculation.InputParameters.HydraulicBoundaryLocation);
        }
Example #15
0
        /// <summary>
        /// Gets a <see cref="SemiProbabilisticPipingCalculationScenario"/> with <c>double.NegativeInfinity</c>
        /// and <c>double.PositiveInfinity</c> values set.
        /// </summary>
        /// <returns>A <see cref="SemiProbabilisticPipingCalculationScenario"/> with <c>double.NegativeInfinity</c>
        /// and <c>double.PositiveInfinity</c> values.</returns>
        public static SemiProbabilisticPipingCalculationScenario GetSemiProbabilisticPipingCalculationScenarioWithInfinities()
        {
            SemiProbabilisticPipingCalculationScenario calculation = GetPipingCalculationScenarioWithAssessmentLevel();

            calculation.InputParameters.SurfaceLine.SetGeometry(new[]
            {
                new Point3D(0, double.NegativeInfinity, 0),
                new Point3D(0, double.PositiveInfinity, 0)
            });

            calculation.InputParameters.AssessmentLevel   = (RoundedDouble)double.NegativeInfinity;
            calculation.InputParameters.EntryPointL       = (RoundedDouble)double.NegativeInfinity;
            calculation.InputParameters.ExitPointL        = (RoundedDouble)double.PositiveInfinity;
            calculation.InputParameters.PhreaticLevelExit = new NormalDistribution
            {
                Mean = (RoundedDouble)double.NegativeInfinity,
                StandardDeviation = (RoundedDouble)double.PositiveInfinity
            };
            calculation.InputParameters.DampingFactorExit = new LogNormalDistribution
            {
                Mean = (RoundedDouble)double.PositiveInfinity,
                StandardDeviation = (RoundedDouble)double.PositiveInfinity
            };

            return(calculation);
        }
        public void Read_EntityWithStochasticSoilModelEntityInCollector_CalculationHasAlreadyReadStochasticSoilModel()
        {
            // Setup
            PipingStochasticSoilModel stochasticSoilModel = PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel();
            var stochasticSoilModelEntity = new StochasticSoilModelEntity();

            var stochasticSoilProfile       = new PipingStochasticSoilProfile(1, PipingSoilProfileTestFactory.CreatePipingSoilProfile());
            var stochasticSoilProfileEntity = new PipingStochasticSoilProfileEntity
            {
                StochasticSoilModelEntity = stochasticSoilModelEntity
            };

            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                PipingStochasticSoilProfileEntity = stochasticSoilProfileEntity,
                EntryPointL           = 1,
                ExitPointL            = 2,
                DampingFactorExitMean = 1,
                ScenarioContribution  = 0
            };

            var collector = new ReadConversionCollector();

            collector.Read(stochasticSoilProfileEntity, stochasticSoilProfile);
            collector.Read(stochasticSoilModelEntity, stochasticSoilModel);

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            Assert.AreSame(stochasticSoilProfile, calculation.InputParameters.StochasticSoilProfile);
            Assert.AreSame(stochasticSoilModel, calculation.InputParameters.StochasticSoilModel);
        }
        public void ParameteredConstructor_ExpectedValues()
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            mocks.ReplayAll();

            var calculation  = new SemiProbabilisticPipingCalculationScenario();
            var surfaceLines = new[]
            {
                new PipingSurfaceLine(string.Empty)
            };

            PipingStochasticSoilModel[] stochasticSoilModels =
            {
                PipingStochasticSoilModelTestFactory.CreatePipingStochasticSoilModel()
            };

            var failureMechanism = new PipingFailureMechanism();

            // Call
            var context = new SemiProbabilisticPipingInputContext(calculation.InputParameters, calculation, surfaceLines, stochasticSoilModels, failureMechanism, assessmentSection);

            // Assert
            Assert.IsInstanceOf <PipingContext <SemiProbabilisticPipingInput> >(context);
            Assert.AreSame(calculation.InputParameters, context.WrappedData);
            Assert.AreSame(calculation, context.PipingCalculation);
            Assert.AreSame(failureMechanism, context.FailureMechanism);
            Assert.AreSame(assessmentSection, context.AssessmentSection);
            CollectionAssert.AreEqual(surfaceLines, context.AvailablePipingSurfaceLines);
            CollectionAssert.AreEqual(stochasticSoilModels, context.AvailableStochasticSoilModels);
            mocks.VerifyAll();
        }
        public void Read_EntityWithSemiProbabilisticPipingCalculationOutputEntity_CalculationWithSemiProbabilisticPipingOutput()
        {
            // Setup
            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                SemiProbabilisticPipingCalculationOutputEntities =
                {
                    new SemiProbabilisticPipingCalculationOutputEntity()
                },
                ScenarioContribution = 0
            };

            var collector = new ReadConversionCollector();

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            SemiProbabilisticPipingOutput output = calculation.Output;

            Assert.IsNotNull(output);

            Assert.IsNaN(output.HeaveFactorOfSafety);
            Assert.IsNaN(output.SellmeijerFactorOfSafety);
            Assert.IsNaN(output.UpliftFactorOfSafety);
            Assert.IsNaN(output.UpliftEffectiveStress);
            Assert.IsNaN(output.HeaveGradient);
            Assert.IsNaN(output.SellmeijerCreepCoefficient);
            Assert.IsNaN(output.SellmeijerCriticalFall);
            Assert.IsNaN(output.SellmeijerReducedFall);
        }
Example #19
0
 public DerivedSemiProbabilisticPipingCalculationScenarioContext(SemiProbabilisticPipingCalculationScenario calculation,
                                                                 CalculationGroup parent,
                                                                 IEnumerable <PipingSurfaceLine> surfaceLines,
                                                                 IEnumerable <PipingStochasticSoilModel> stochasticSoilModels,
                                                                 PipingFailureMechanism pipingFailureMechanism, IAssessmentSection assessmentSection)
     : base(calculation, parent, surfaceLines, stochasticSoilModels, pipingFailureMechanism, assessmentSection)
 {
 }
Example #20
0
        private static void ReadCalculationOutputs(SemiProbabilisticPipingCalculationScenario calculation,
                                                   SemiProbabilisticPipingCalculationEntity entity)
        {
            SemiProbabilisticPipingCalculationOutputEntity calculationOutputEntity = entity.SemiProbabilisticPipingCalculationOutputEntities.SingleOrDefault();

            if (calculationOutputEntity != null)
            {
                calculation.Output = calculationOutputEntity.Read();
            }
        }
Example #21
0
        public void UpdateModelWithImportedData_ProfilesAssignedToCalculationsWithOneImportedModelProfileRemoved_OneProfileRemovedCalculationUpdatedAccordingly()
        {
            // Setup
            const string modelsName = "same model";
            PipingStochasticSoilModel existingModel = CreateSimpleModel(modelsName, "Unaffected Profile", "Removed Profile");

            var failureMechanism = new PipingFailureMechanism();
            PipingStochasticSoilModelCollection targetCollection = failureMechanism.StochasticSoilModels;

            targetCollection.AddRange(new[]
            {
                existingModel
            }, sourceFilePath);

            PipingStochasticSoilProfile firstExistingProfile = existingModel.StochasticSoilProfiles.First();
            PipingStochasticSoilModel   readModel            = CreateSimpleModel(modelsName, firstExistingProfile.SoilProfile.Name);

            var calculationWithNotUpdatedProfile = new SemiProbabilisticPipingCalculationScenario();

            calculationWithNotUpdatedProfile.InputParameters.StochasticSoilModel   = existingModel;
            calculationWithNotUpdatedProfile.InputParameters.StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(0);
            calculationWithNotUpdatedProfile.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties());

            var calculationWithDeletedProfile = new SemiProbabilisticPipingCalculationScenario();

            calculationWithDeletedProfile.InputParameters.StochasticSoilModel   = existingModel;
            calculationWithDeletedProfile.InputParameters.StochasticSoilProfile = existingModel.StochasticSoilProfiles.ElementAt(1);
            calculationWithDeletedProfile.Output = new SemiProbabilisticPipingOutput(new SemiProbabilisticPipingOutput.ConstructionProperties());

            failureMechanism.CalculationsGroup.Children.Add(calculationWithDeletedProfile);
            failureMechanism.CalculationsGroup.Children.Add(calculationWithNotUpdatedProfile);

            var strategy = new PipingStochasticSoilModelUpdateDataStrategy(failureMechanism);

            // Call
            IEnumerable <IObservable> affectedObjects = strategy.UpdateModelWithImportedData(new[]
            {
                readModel
            }, sourceFilePath).ToArray();

            // Assert
            PipingStochasticSoilModel firstSoilModel = targetCollection[0];

            Assert.AreSame(existingModel, firstSoilModel);
            Assert.AreSame(firstExistingProfile, firstSoilModel.StochasticSoilProfiles.ElementAt(0));

            Assert.IsTrue(calculationWithNotUpdatedProfile.HasOutput);
            CollectionAssert.DoesNotContain(affectedObjects, calculationWithNotUpdatedProfile);
            CollectionAssert.DoesNotContain(affectedObjects, calculationWithNotUpdatedProfile.InputParameters);

            Assert.IsFalse(calculationWithDeletedProfile.HasOutput);
            Assert.IsNull(calculationWithDeletedProfile.InputParameters.StochasticSoilProfile);
            CollectionAssert.Contains(affectedObjects, calculationWithDeletedProfile);
            CollectionAssert.Contains(affectedObjects, calculationWithDeletedProfile.InputParameters);
        }
Example #22
0
        public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnsExpectedInquiryMessage(bool isActionConfirmed)
        {
            // Setup
            var mocks             = new MockRepository();
            var assessmentSection = mocks.Stub <IAssessmentSection>();

            var mainWindow = mocks.Stub <IMainWindow>();
            var gui        = mocks.Stub <IGui>();

            gui.Stub(g => g.MainWindow).Return(mainWindow);
            mocks.ReplayAll();

            plugin.Gui = gui;

            var failureMechanism      = new PipingFailureMechanism();
            var calculationWithOutput = new SemiProbabilisticPipingCalculationScenario
            {
                Output = PipingTestDataGenerator.GetRandomSemiProbabilisticPipingOutput()
            };

            failureMechanism.CalculationsGroup.Children.Add(calculationWithOutput);

            var surfaceLines = new PipingSurfaceLineCollection();
            var context      = new PipingSurfaceLinesContext(surfaceLines, failureMechanism, assessmentSection);

            string textBoxMessage = null;

            DialogBoxHandler = (name, wnd) =>
            {
                var helper = new MessageBoxTester(wnd);
                textBoxMessage = helper.Text;

                if (isActionConfirmed)
                {
                    helper.ClickOk();
                }
                else
                {
                    helper.ClickCancel();
                }
            };

            // Call
            bool updatesVerified = importInfo.VerifyUpdates(context);

            // Assert
            string expectedInquiryMessage = "Als u profielschematisaties importeert, " +
                                            "dan worden alle rekenresultaten van dit faalmechanisme verwijderd." +
                                            $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?";

            Assert.AreEqual(expectedInquiryMessage, textBoxMessage);
            Assert.AreEqual(isActionConfirmed, updatesVerified);
            mocks.VerifyAll();
        }
Example #23
0
        public void Clone_NotAllPropertiesSet_ReturnNewInstanceWithCopiedValues()
        {
            // Setup
            SemiProbabilisticPipingCalculationScenario original = CreateRandomCalculationScenarioWithoutOutput();

            // Call
            object clone = original.Clone();

            // Assert
            CoreCloneAssert.AreObjectClones(original, clone, PipingCloneAssert.AreClones);
        }
Example #24
0
        public void Contribution_SetValidValue_ValueSet(double newValue)
        {
            // Setup
            var calculationScenario = new SemiProbabilisticPipingCalculationScenario();

            // Call
            calculationScenario.Contribution = (RoundedDouble)newValue;

            // Assert
            Assert.AreEqual(4, calculationScenario.Contribution.NumberOfDecimalPlaces);
            Assert.AreEqual(newValue, calculationScenario.Contribution, calculationScenario.Contribution.GetAccuracy());
        }
Example #25
0
        public void Create_PersistenceRegistryIsNull_ThrowArgumentNullException()
        {
            // Setup
            var calculation = new SemiProbabilisticPipingCalculationScenario();

            // Call
            void Call() => calculation.Create(null, 0);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(Call);

            Assert.AreEqual("registry", exception.ParamName);
        }
Example #26
0
        public void Constructor_ExpectedValues()
        {
            // Call
            var scenario = new SemiProbabilisticPipingCalculationScenario();

            // Assert
            Assert.IsInstanceOf <SemiProbabilisticPipingCalculation>(scenario);
            Assert.IsInstanceOf <IPipingCalculationScenario <SemiProbabilisticPipingInput> >(scenario);

            Assert.IsTrue(scenario.IsRelevant);
            Assert.AreEqual(4, scenario.Contribution.NumberOfDecimalPlaces);
            Assert.AreEqual(1.0, scenario.Contribution, scenario.Contribution.GetAccuracy());
        }
Example #27
0
        public void Contribution_SetInvalidValue_ThrowArgumentException(double newValue)
        {
            // Setup
            var calculationScenario = new SemiProbabilisticPipingCalculationScenario();

            // Call
            void Call() => calculationScenario.Contribution = (RoundedDouble)newValue;

            // Assert
            const string expectedMessage = "De waarde voor de bijdrage moet binnen het bereik [0, 100] liggen.";

            TestHelper.AssertThrowsArgumentExceptionAndTestMessage <ArgumentOutOfRangeException>(Call, expectedMessage);
        }
        public void Read_ValidEntity_ReturnSemiProbabilisticPipingCalculationScenario(
            bool isRelevant, bool useAssessmentLevelManualInput, double contribution,
            string name, string comments, double entryPoint, double exitPoint,
            double assessmentLevel, int seed)
        {
            // Setup
            var random = new Random(seed);

            var entity = new SemiProbabilisticPipingCalculationEntity
            {
                RelevantForScenario  = Convert.ToByte(isRelevant),
                ScenarioContribution = contribution,
                Name                  = name,
                Comments              = comments,
                EntryPointL           = entryPoint.ToNaNAsNull(),
                ExitPointL            = exitPoint.ToNaNAsNull(),
                PhreaticLevelExitMean = random.NextDouble(-9999.99, 9999.99),
                PhreaticLevelExitStandardDeviation = random.NextDouble(0, 9999.99),
                DampingFactorExitMean = random.NextDouble(1e-6, 9999.99),
                DampingFactorExitStandardDeviation = random.NextDouble(0, 9999.99),
                AssessmentLevel = assessmentLevel.ToNaNAsNull(),
                UseAssessmentLevelManualInput = Convert.ToByte(useAssessmentLevelManualInput)
            };

            var collector = new ReadConversionCollector();

            // Call
            SemiProbabilisticPipingCalculationScenario calculation = entity.Read(collector);

            // Assert
            Assert.AreEqual(isRelevant, calculation.IsRelevant);
            RoundedDoubleTestHelper.AssertRoundedDouble(contribution, calculation.Contribution);
            Assert.AreEqual(name, calculation.Name);
            Assert.AreEqual(comments, calculation.Comments.Body);

            RoundedDoubleTestHelper.AssertRoundedDouble(entryPoint, calculation.InputParameters.EntryPointL);
            RoundedDoubleTestHelper.AssertRoundedDouble(exitPoint, calculation.InputParameters.ExitPointL);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.PhreaticLevelExitMean, calculation.InputParameters.PhreaticLevelExit.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.PhreaticLevelExitStandardDeviation, calculation.InputParameters.PhreaticLevelExit.StandardDeviation);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.DampingFactorExitMean, calculation.InputParameters.DampingFactorExit.Mean);
            RoundedDoubleTestHelper.AssertRoundedDouble(entity.DampingFactorExitStandardDeviation, calculation.InputParameters.DampingFactorExit.StandardDeviation);

            Assert.AreEqual(useAssessmentLevelManualInput, calculation.InputParameters.UseAssessmentLevelManualInput);
            Assert.AreEqual(entity.AssessmentLevel.ToNullAsNaN(), calculation.InputParameters.AssessmentLevel.Value);

            Assert.IsNull(calculation.InputParameters.SurfaceLine);
            Assert.IsNull(calculation.InputParameters.HydraulicBoundaryLocation);
            Assert.IsNull(calculation.InputParameters.StochasticSoilModel);
            Assert.IsNull(calculation.InputParameters.StochasticSoilProfile);
            Assert.IsNull(calculation.Output);
        }
Example #29
0
        public void Create_WithCalculationGroup_ReturnFailureMechanismEntityWithCalculationGroupEntities()
        {
            // Setup
            var calculationGroup = new CalculationGroup();
            var semiProbabilisticPipingCalculationScenario = new SemiProbabilisticPipingCalculationScenario();
            var probabilisticPipingCalculationScenario     = new ProbabilisticPipingCalculationScenario();

            var failureMechanism = new PipingFailureMechanism();

            failureMechanism.CalculationsGroup.Children.Add(calculationGroup);
            failureMechanism.CalculationsGroup.Children.Add(semiProbabilisticPipingCalculationScenario);
            failureMechanism.CalculationsGroup.Children.Add(probabilisticPipingCalculationScenario);

            // Call
            FailureMechanismEntity entity = failureMechanism.Create(new PersistenceRegistry());

            // Assert
            Assert.IsNotNull(entity);
            Assert.AreEqual(failureMechanism.CalculationsGroup.Name, entity.CalculationGroupEntity.Name);
            Assert.AreEqual(0, entity.CalculationGroupEntity.Order);

            CalculationGroupEntity[] childGroupEntities = entity.CalculationGroupEntity.CalculationGroupEntity1
                                                          .OrderBy(cge => cge.Order)
                                                          .ToArray();
            Assert.AreEqual(1, childGroupEntities.Length);
            CalculationGroupEntity childGroupEntity = childGroupEntities[0];

            Assert.AreEqual(calculationGroup.Name, childGroupEntity.Name);
            Assert.AreEqual(0, childGroupEntity.Order);

            SemiProbabilisticPipingCalculationEntity[] semiProbabilisticPipingCalculationEntities = entity.CalculationGroupEntity
                                                                                                    .SemiProbabilisticPipingCalculationEntities
                                                                                                    .OrderBy(ce => ce.Order)
                                                                                                    .ToArray();
            Assert.AreEqual(1, semiProbabilisticPipingCalculationEntities.Length);
            SemiProbabilisticPipingCalculationEntity semiProbabilisticPipingCalculationEntity = semiProbabilisticPipingCalculationEntities[0];

            Assert.AreEqual(semiProbabilisticPipingCalculationScenario.Name, semiProbabilisticPipingCalculationEntity.Name);
            Assert.AreEqual(1, semiProbabilisticPipingCalculationEntity.Order);

            ProbabilisticPipingCalculationEntity[] probabilisticPipingCalculationEntities = entity.CalculationGroupEntity
                                                                                            .ProbabilisticPipingCalculationEntities
                                                                                            .OrderBy(ce => ce.Order)
                                                                                            .ToArray();
            Assert.AreEqual(1, probabilisticPipingCalculationEntities.Length);
            ProbabilisticPipingCalculationEntity probabilisticPipingCalculationEntity = probabilisticPipingCalculationEntities[0];

            Assert.AreEqual(probabilisticPipingCalculationScenario.Name, probabilisticPipingCalculationEntity.Name);
            Assert.AreEqual(2, probabilisticPipingCalculationEntity.Order);
        }
Example #30
0
        /// <summary>
        /// Parses a semi-probabilistic calculation from the provided <paramref name="readCalculation"/>.
        /// </summary>
        /// <param name="readCalculation">The calculation read from XML.</param>
        /// <returns>The parsed <see cref="SemiProbabilisticPipingCalculationScenario"/>,
        /// or <c>null</c> when parsing failed.</returns>
        private ICalculation ParseReadCalculationAsSemiProbabilistic(PipingCalculationConfiguration readCalculation)
        {
            var pipingCalculation = new SemiProbabilisticPipingCalculationScenario
            {
                Name = readCalculation.Name
            };

            if (TrySetSemiProbabilisticHydraulicBoundaryData(readCalculation, pipingCalculation) &&
                TrySetGenericData(readCalculation, pipingCalculation))
            {
                return(pipingCalculation);
            }

            return(null);
        }