Index: Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableStateFactory.cs =================================================================== diff -u -rd87bd516fe235ff936cf4fc25e04a88216861a56 -r254879576a8e47483035335ff6deef1b28e1b832 --- Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableStateFactory.cs (.../PersistableStateFactory.cs) (revision d87bd516fe235ff936cf4fc25e04a88216861a56) +++ Riskeer/MacroStabilityInwards/src/Riskeer.MacroStabilityInwards.IO/Factories/PersistableStateFactory.cs (.../PersistableStateFactory.cs) (revision 254879576a8e47483035335ff6deef1b28e1b832) @@ -82,11 +82,19 @@ .Select(l => CreatePOPStatePoint(l, stageType, idFactory, registry)) .ToArray()); - statePoints.AddRange(soilProfile.PreconsolidationStresses.Select( - pcs => CreateYieldStressStatePoint( - GetLayerForPreconsolidationStress(layers, pcs), - pcs, stageType, idFactory, registry)) - .ToArray()); + var preconsolidationStressPoints = new List(); + + foreach (IMacroStabilityInwardsPreconsolidationStress preconsolidationStress in soilProfile.PreconsolidationStresses) + { + MacroStabilityInwardsSoilLayer2D layer = GetLayerForPreconsolidationStress(layers, preconsolidationStress); + if (layer != null) + { + preconsolidationStressPoints.Add( + CreateYieldStressStatePoint(layer, preconsolidationStress, stageType, idFactory, registry)); + } + } + + statePoints.AddRange(preconsolidationStressPoints); } var state = new PersistableState @@ -103,10 +111,10 @@ private static MacroStabilityInwardsSoilLayer2D GetLayerForPreconsolidationStress(IEnumerable layers, IMacroStabilityInwardsPreconsolidationStress pcs) { - return layers.Single(l => AdvancedMath2D.PointInPolygon( - pcs.Location, - l.OuterRing.Points, - l.NestedLayers.Select(nl => nl.OuterRing.Points))); + return layers.SingleOrDefault(l => AdvancedMath2D.PointInPolygon( + pcs.Location, + l.OuterRing.Points, + l.NestedLayers.Select(nl => nl.OuterRing.Points))); } private static PersistableStatePoint CreateYieldStressStatePoint(MacroStabilityInwardsSoilLayer2D layer, IMacroStabilityInwardsPreconsolidationStress preconsolidationStress, Index: Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableStateFactoryTest.cs =================================================================== diff -u -r8e43aa4021689e559f7b3e8a9274f103c89844dc -r254879576a8e47483035335ff6deef1b28e1b832 --- Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableStateFactoryTest.cs (.../PersistableStateFactoryTest.cs) (revision 8e43aa4021689e559f7b3e8a9274f103c89844dc) +++ Riskeer/MacroStabilityInwards/test/Riskeer.MacroStabilityInwards.IO.Test/Factories/PersistableStateFactoryTest.cs (.../PersistableStateFactoryTest.cs) (revision 254879576a8e47483035335ff6deef1b28e1b832) @@ -159,6 +159,37 @@ } [Test] + public void Create_SoilProfileWithPreconsolidationStressOutsideLayers_ReturnsPersistableStates() + { + // Setup + MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation()); + MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile = MacroStabilityInwardsStochasticSoilProfileTestFactory.CreateMacroStabilityInwardsStochasticSoilProfile2D(new[] + { + MacroStabilityInwardsPreconsolidationStressTestFactory.CreateMacroStabilityInwardsPreconsolidationStress(new Point2D(50, 1)) + }); + calculation.InputParameters.StochasticSoilProfile = stochasticSoilProfile; + + IMacroStabilityInwardsSoilProfileUnderSurfaceLine soilProfile = calculation.InputParameters.SoilProfileUnderSurfaceLine; + + var idFactory = new IdFactory(); + var registry = new MacroStabilityInwardsExportRegistry(); + + PersistableGeometryFactory.Create(soilProfile, idFactory, registry); + + // Call + IEnumerable 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); + } + + [Test] public void Create_WithValidData_ReturnsPersistableStates() { // Setup