using System.Collections.Generic; using System.Drawing; using System.Linq; using Deltares.DSoilModel.Data; using Deltares.Geographic; using Deltares.Geotechnics; using Deltares.Geotechnics.ConePenetrationTest; using Deltares.Geotechnics.Mechanisms; using Deltares.Geotechnics.TestUtils; using Deltares.Probabilistic; using Deltares.Standard; using Deltares.Standard.Maps; using Deltares.Standard.EventPublisher; using Deltares.Standard.Forms; using Deltares.Standard.Validation; using NUnit.Framework; namespace Deltares.DSoilModel.Tests { [TestFixture] public class DSoilModelProjectTest { private object geographicHelper; [TestFixtureSetUp] public void FixtureSetup() { oldIsDataEventPublishStopped = DataEventPublisher.IsDataEventPublishStopped; DataEventPublisher.IsDataEventPublishStopped = true; geographicHelper = GeographicHelper.Instance; GeographicHelper.Instance = new DotSpatialGeographicHelper(); } [TestFixtureTearDown] public void FixtureTearDown() { DataEventPublisher.IsDataEventPublishStopped = oldIsDataEventPublishStopped; GeographicHelper.Instance = geographicHelper as GeographicHelper; } [Test] [Category("Work_In_Progress")] // DSB-390 public void TestCaseSensitivityOfImportedSoilNames() { var project = new DSoilModelProject(); project.ReadSoilsFromDatabase(@"..\..\..\data\TestData\OnlyZand.mdb"); Assert.AreEqual("Zand", project.Soils.Soils[0].Name); project.Soils.Soils[0].Name = "zand"; project.ReadSoilsFromDatabase(@"..\..\..\data\TestData\OnlyZand.mdb"); // soil names should not be case sensitive during import Assert.AreEqual(1, project.Soils.Soils.Count); } [Test] public void TestLinkCptsAndBoringsToNearestSoilSegment() { var project = (DSoilModelProject) DSoilModelIO.OpenSoilDatabase(@"..\..\..\data\TestData\SosDataPlusBorings.soil"); var selection = new List(); // a combination of Cpts, Borings and Segments to link with are selected selection.AddRange(project.SoilSegments.Where(x => x.Name.StartsWith("36009_"))); selection.AddRange(project.SoilSegments.Where(x => x.Name.StartsWith("36010_"))); // none of the segments are linked Assert.IsFalse(project.SoilSegments.Any(s => s.Cpts.Count > 0 || s.Borings.Count > 0)); // 36009_Piping & 36009_Stability & 36010_Piping & 36010_Stability Assert.AreEqual(4, selection.Count); // CPT's along these segments selection.Add(project.CPTs.First(x => x.Name == "S45E00003")); selection.Add(project.CPTs.First(x => x.Name == "S39G00196")); selection.Add(project.CPTs.First(x => x.Name == "S39G00042")); selection.Add(project.CPTs.First(x => x.Name == "S45F00115")); selection.Add(project.CPTs.First(x => x.Name == "S45F00080")); selection.Add(project.CPTs.First(x => x.Name == "S45F00128")); // dummy borings, only 2 in this project selection.AddRange(project.Borings); Assert.AreEqual(12, selection.Count); // call project.LinkCptsAndBoringsToNearestSegment(selection.ToArray()); // assert (see the map in D-Soil Model for reference) Assert.AreEqual(4, project.SoilSegments.Count(s => s.Cpts.Count > 0 || s.Borings.Count > 0)); Assert.AreEqual(2, project.SoilSegments.Count(s => s.Borings.Count > 0)); // the 2 segments on the west side both get the same 3 Cpts, 2 Borings var segment = project.SoilSegments.First(s => s.Name == "36009_Piping"); Assert.AreEqual(3, segment.Cpts.Count); Assert.AreEqual(2, segment.Borings.Count); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S45E00003")); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S39G00196")); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S39G00042")); Assert.IsTrue(segment.Borings.Any(b => b.Boring.Name == "TestBoring1")); Assert.IsTrue(segment.Borings.Any(b => b.Boring.Name == "TestBoring2")); segment = project.SoilSegments.First(s => s.Name == "36009_Stability"); Assert.AreEqual(3, segment.Cpts.Count); Assert.AreEqual(2, segment.Borings.Count); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S45E00003")); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S39G00196")); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S39G00042")); Assert.IsTrue(segment.Borings.Any(b => b.Boring.Name == "TestBoring1")); Assert.IsTrue(segment.Borings.Any(b => b.Boring.Name == "TestBoring2")); // the 2 segments on the east side both get the same 3 Cpts, no Borings segment = project.SoilSegments.First(s => s.Name == "36010_Piping"); Assert.AreEqual(3, segment.Cpts.Count); Assert.AreEqual(0, segment.Borings.Count); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S45F00115")); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S45F00080")); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S45F00128")); segment = project.SoilSegments.First(s => s.Name == "36010_Stability"); Assert.AreEqual(3, segment.Cpts.Count); Assert.AreEqual(0, segment.Borings.Count); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S45F00115")); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S45F00080")); Assert.IsTrue(segment.Cpts.Any(c => c.ConePenetrationTestData.Name == "S45F00128")); } [Test] public void TestSplitSimpleSoilSegment() { var project = new DSoilModelProject(); var restoreHelper = GeographicHelper.Instance; GeographicHelper.Instance = new DotSpatialGeographicHelper(); var cpt1 = new ConePenetrationTestData { Name = "cpt1" }; var cpt2 = new ConePenetrationTestData { Name = "cpt2" }; project.CPTs.Add(cpt1); project.CPTs.Add(cpt2); var boring1 = new Boring { Name = "boring1" }; var boring2 = new Boring { Name = "Boring2" }; var segment = new SoilSegment { Name = "Segment X" }; segment.Points.Add(new GeographicPoint(0,0)); segment.Points.Add(new GeographicPoint(35.355, 35.355)); segment.Points.Add(new GeographicPoint(70.71, 70.71)); segment.Cpts.Add(new ConePenetrationTestPerSegment { ConePenetrationTestData = cpt1, Xlocal = 20}); segment.Cpts.Add(new ConePenetrationTestPerSegment { ConePenetrationTestData = cpt2, Xlocal = 80 }); segment.Borings.Add(new BoringPerSegment { Boring = boring1, Xlocal = 45 }); segment.Borings.Add(new BoringPerSegment { Boring = boring2, Xlocal = 55 }); project.SoilSegments.Add(segment); project.SplitSoilSegment(segment, 50); Assert.AreEqual(2, project.SoilSegments.Count); Assert.AreEqual(2, project.SoilSegments[0].Points.Count); Assert.AreEqual(2, project.SoilSegments[1].Points.Count); // check the resulting two segments Assert.AreEqual(1, project.SoilSegments[0].Cpts.Count); Assert.AreEqual(1, project.SoilSegments[1].Cpts.Count); Assert.AreEqual(1, project.SoilSegments[0].Borings.Count); Assert.AreEqual(1, project.SoilSegments[1].Borings.Count); Assert.AreEqual(50, project.SoilSegments[0].GetSegmentLength(), 0.01); Assert.AreEqual(cpt1, project.SoilSegments[0].Cpts[0].ConePenetrationTestData); Assert.AreEqual(boring1, project.SoilSegments[0].Borings[0].Boring); Assert.AreEqual("Segment X (0)", project.SoilSegments[0].Name); Assert.AreEqual(50, project.SoilSegments[1].GetSegmentLength(), 0.01); Assert.AreEqual(cpt2, project.SoilSegments[1].Cpts[0].ConePenetrationTestData); Assert.AreEqual(boring2, project.SoilSegments[1].Borings[0].Boring); Assert.AreEqual("Segment X (1)", project.SoilSegments[1].Name); // undo ! UndoRedoManager.Instance.Undo(); Assert.AreEqual(2, project.SoilSegments.Count); GeographicHelper.Instance = restoreHelper; } [Test] public void AddSoilDataToProject_AddSameSoilNameWithDifferentPropertyWithEqualStochasts_AddSecondSoil() { // Create a soil with specific stochasts defined var mySoil = CreateTestSoil(); mySoil.CohesionStochast.DistributionType = DistributionType.Gamma; mySoil.FrictionAngleStochast.DistributionType = DistributionType.Gamma; mySoil.StressTableStochast.DistributionType = DistributionType.Gamma; mySoil.POPStochast.DistributionType = DistributionType.Gamma; mySoil.OCRStochast.DistributionType = DistributionType.Gamma; mySoil.RatioCuPcStochast.DistributionType = DistributionType.Gamma; mySoil.RatioCuPcPassiveStochast.DistributionType = DistributionType.Gamma; mySoil.RatioCuPcActiveStochast.DistributionType = DistributionType.Gamma; mySoil.CuStochast.DistributionType = DistributionType.Gamma; mySoil.CuTopStochast.DistributionType = DistributionType.Gamma; mySoil.CuActiveTopStochast.DistributionType = DistributionType.Gamma; mySoil.CuPassiveTopStochast.DistributionType = DistributionType.Gamma; mySoil.CuBottomStochast.DistributionType = DistributionType.Gamma; mySoil.CuActiveBottomStochast.DistributionType = DistributionType.Gamma; mySoil.CuPassiveBottomStochast.DistributionType = DistributionType.Gamma; mySoil.CuGradientStochast.DistributionType = DistributionType.Gamma; mySoil.RRatioStochast.DistributionType = DistributionType.Gamma; mySoil.PnStochast.DistributionType = DistributionType.Gamma; mySoil.PermeabKxStochast.DistributionType = DistributionType.Gamma; mySoil.DiameterD50Stochast.DistributionType = DistributionType.Gamma; mySoil.DiameterD70Stochast.DistributionType = DistributionType.Gamma; mySoil.BeddingAngleStochast.DistributionType = DistributionType.Gamma; mySoil.WhitesConstantStochast.DistributionType = DistributionType.Gamma; // Create another identical soil with one property different var myOtherSoil = CreateTestSoil(); myOtherSoil.BelowPhreaticLevel = 20.0; // other soil has the stochasts defined identical myOtherSoil.CohesionStochast.DistributionType = DistributionType.Gamma; myOtherSoil.FrictionAngleStochast.DistributionType = DistributionType.Gamma; myOtherSoil.StressTableStochast.DistributionType = DistributionType.Gamma; myOtherSoil.POPStochast.DistributionType = DistributionType.Gamma; myOtherSoil.OCRStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcPassiveStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcActiveStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuActiveTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuPassiveTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuActiveBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuPassiveBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuGradientStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RRatioStochast.DistributionType = DistributionType.Gamma; myOtherSoil.PnStochast.DistributionType = DistributionType.Gamma; myOtherSoil.PermeabKxStochast.DistributionType = DistributionType.Gamma; myOtherSoil.DiameterD50Stochast.DistributionType = DistributionType.Gamma; myOtherSoil.DiameterD70Stochast.DistributionType = DistributionType.Gamma; myOtherSoil.BeddingAngleStochast.DistributionType = DistributionType.Gamma; myOtherSoil.WhitesConstantStochast.DistributionType = DistributionType.Gamma; var myProject = new DSoilModelProject(); // Add mySoil to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); // Try to add the soil with the same name and the differences in the stochastic properties to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { myOtherSoil } }); Assert.AreEqual(2, myProject.Soils.Soils.Count, "Soil with the same name and the small difference in properties should be added with a postfix to make the name unique"); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); Assert.AreEqual(myOtherSoil, myProject.Soils.Soils.Last()); Assert.AreEqual(myOtherSoil.Name, mySoil.Name + " (1)"); } [Test] public void AddSoilDataToProject_AddSameSoilNameWithDifferentProperty_AddSecondSoil() { var mySoil = CreateTestSoil(); var myOtherSoil = CreateTestSoil(); myOtherSoil.BelowPhreaticLevel = 20.0; var myProject = new DSoilModelProject(); // Add mySoil to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); // Try to add the soil with the same name and the small difference in properties to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { myOtherSoil } }); Assert.AreEqual(2, myProject.Soils.Soils.Count, "Soil with the same name and the small difference in properties should be added with a postfix to make the name unique"); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); Assert.AreEqual(myOtherSoil, myProject.Soils.Soils.Last()); Assert.AreEqual(myOtherSoil.Name, mySoil.Name + " (1)"); } [Test] public void AddSoilDataToProject_AddSameSoilNameWithDifferentStochasts_DoNotAddSecondSoil() { // Create a soil with specific stochasts defined var mySoil = CreateTestSoil(); mySoil.CohesionStochast.DistributionType = DistributionType.Normal; mySoil.FrictionAngleStochast.DistributionType = DistributionType.Normal; mySoil.StressTableStochast.DistributionType = DistributionType.Normal; mySoil.POPStochast.DistributionType = DistributionType.Normal; mySoil.OCRStochast.DistributionType = DistributionType.Normal; mySoil.RatioCuPcStochast.DistributionType = DistributionType.Normal; mySoil.RatioCuPcPassiveStochast.DistributionType = DistributionType.Normal; mySoil.RatioCuPcActiveStochast.DistributionType = DistributionType.Normal; mySoil.CuStochast.DistributionType = DistributionType.Normal; mySoil.CuTopStochast.DistributionType = DistributionType.Normal; mySoil.CuActiveTopStochast.DistributionType = DistributionType.Normal; mySoil.CuPassiveTopStochast.DistributionType = DistributionType.Normal; mySoil.CuBottomStochast.DistributionType = DistributionType.Normal; mySoil.CuActiveBottomStochast.DistributionType = DistributionType.Normal; mySoil.CuPassiveBottomStochast.DistributionType = DistributionType.Normal; mySoil.CuGradientStochast.DistributionType = DistributionType.Normal; mySoil.RRatioStochast.DistributionType = DistributionType.Normal; mySoil.PnStochast.DistributionType = DistributionType.Normal; mySoil.PermeabKxStochast.DistributionType = DistributionType.Normal; mySoil.DiameterD50Stochast.DistributionType = DistributionType.Normal; mySoil.DiameterD70Stochast.DistributionType = DistributionType.Normal; mySoil.BeddingAngleStochast.DistributionType = DistributionType.Normal; mySoil.WhitesConstantStochast.DistributionType = DistributionType.Normal; // Create another identical soil, but with the stochasts defined differently var myOtherSoil = CreateTestSoil(); myOtherSoil.CohesionStochast.DistributionType = DistributionType.Gamma; myOtherSoil.FrictionAngleStochast.DistributionType = DistributionType.Gamma; myOtherSoil.StressTableStochast.DistributionType = DistributionType.Gamma; myOtherSoil.POPStochast.DistributionType = DistributionType.Gamma; myOtherSoil.OCRStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcPassiveStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcActiveStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuActiveTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuPassiveTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuActiveBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuPassiveBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuGradientStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RRatioStochast.DistributionType = DistributionType.Gamma; myOtherSoil.PnStochast.DistributionType = DistributionType.Gamma; myOtherSoil.PermeabKxStochast.DistributionType = DistributionType.Gamma; myOtherSoil.DiameterD50Stochast.DistributionType = DistributionType.Gamma; myOtherSoil.DiameterD70Stochast.DistributionType = DistributionType.Gamma; myOtherSoil.BeddingAngleStochast.DistributionType = DistributionType.Gamma; myOtherSoil.WhitesConstantStochast.DistributionType = DistributionType.Gamma; var myProject = new DSoilModelProject(); // Add mySoil to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); // Try to add the soil with the same name and the differences in the stochastic properties to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { myOtherSoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count, "Already present soil should not be added a second time"); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); } [Test] public void AddSoilDataToProject_AddSameSoil_DoNotAddSecondSoil() { var mySoil = CreateTestSoil(); var myProject = new DSoilModelProject(); // Add mySoil to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); // Try to add the same soil for the second time myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count, "Already present soil should not be added a second time"); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); } [Test] public void AddSoilDataToProject_SoilsWithoutStressTables_AddSameSoilNameWithDifferentPropertyWithEqualStochasts_AddSecondSoil() { // Create a soil with specific stochasts defined var mySoil = CreateTestSoil(defineStressTables: false); mySoil.CohesionStochast.DistributionType = DistributionType.Gamma; mySoil.FrictionAngleStochast.DistributionType = DistributionType.Gamma; mySoil.StressTableStochast.DistributionType = DistributionType.Gamma; mySoil.POPStochast.DistributionType = DistributionType.Gamma; mySoil.OCRStochast.DistributionType = DistributionType.Gamma; mySoil.RatioCuPcStochast.DistributionType = DistributionType.Gamma; mySoil.RatioCuPcPassiveStochast.DistributionType = DistributionType.Gamma; mySoil.RatioCuPcActiveStochast.DistributionType = DistributionType.Gamma; mySoil.CuStochast.DistributionType = DistributionType.Gamma; mySoil.CuTopStochast.DistributionType = DistributionType.Gamma; mySoil.CuActiveTopStochast.DistributionType = DistributionType.Gamma; mySoil.CuPassiveTopStochast.DistributionType = DistributionType.Gamma; mySoil.CuBottomStochast.DistributionType = DistributionType.Gamma; mySoil.CuActiveBottomStochast.DistributionType = DistributionType.Gamma; mySoil.CuPassiveBottomStochast.DistributionType = DistributionType.Gamma; mySoil.CuGradientStochast.DistributionType = DistributionType.Gamma; mySoil.RRatioStochast.DistributionType = DistributionType.Gamma; mySoil.PnStochast.DistributionType = DistributionType.Gamma; mySoil.PermeabKxStochast.DistributionType = DistributionType.Gamma; mySoil.DiameterD50Stochast.DistributionType = DistributionType.Gamma; mySoil.DiameterD70Stochast.DistributionType = DistributionType.Gamma; mySoil.BeddingAngleStochast.DistributionType = DistributionType.Gamma; mySoil.WhitesConstantStochast.DistributionType = DistributionType.Gamma; // Create another identical soil with one property different var myOtherSoil = CreateTestSoil(defineStressTables: false); myOtherSoil.BelowPhreaticLevel = 20.0; // other soil has the stochasts defined identical myOtherSoil.CohesionStochast.DistributionType = DistributionType.Gamma; myOtherSoil.FrictionAngleStochast.DistributionType = DistributionType.Gamma; myOtherSoil.StressTableStochast.DistributionType = DistributionType.Gamma; myOtherSoil.POPStochast.DistributionType = DistributionType.Gamma; myOtherSoil.OCRStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcPassiveStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcActiveStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuActiveTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuPassiveTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuActiveBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuPassiveBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuGradientStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RRatioStochast.DistributionType = DistributionType.Gamma; myOtherSoil.PnStochast.DistributionType = DistributionType.Gamma; myOtherSoil.PermeabKxStochast.DistributionType = DistributionType.Gamma; myOtherSoil.DiameterD50Stochast.DistributionType = DistributionType.Gamma; myOtherSoil.DiameterD70Stochast.DistributionType = DistributionType.Gamma; myOtherSoil.BeddingAngleStochast.DistributionType = DistributionType.Gamma; myOtherSoil.WhitesConstantStochast.DistributionType = DistributionType.Gamma; var myProject = new DSoilModelProject(); // Add mySoil to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); // Try to add the soil with the same name and the differences in the stochastic properties to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { myOtherSoil } }); Assert.AreEqual(2, myProject.Soils.Soils.Count, "Soil with the same name and the small difference in properties should be added with a postfix to make the name unique"); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); Assert.AreEqual(myOtherSoil, myProject.Soils.Soils.Last()); Assert.AreEqual(myOtherSoil.Name, mySoil.Name + " (1)"); } [Test] public void AddSoilDataToProject_SoilsWithoutStressTables_AddSameSoilNameWithDifferentProperty_AddSecondSoil() { var mySoil = CreateTestSoil(defineStressTables: false); var myOtherSoil = CreateTestSoil(defineStressTables: false); myOtherSoil.BelowPhreaticLevel = 20.0; var myProject = new DSoilModelProject(); // Add mySoil to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); // Try to add the soil with the same name and the small difference in properties to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { myOtherSoil } }); Assert.AreEqual(2, myProject.Soils.Soils.Count, "Soil with the same name and the small difference in properties should be added with a postfix to make the name unique"); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); Assert.AreEqual(myOtherSoil, myProject.Soils.Soils.Last()); Assert.AreEqual(myOtherSoil.Name, mySoil.Name + " (1)"); } [Test] public void AddSoilDataToProject_SoilsWithoutStressTables_AddSameSoilNameWithDifferentStochasts_DoNotAddSecondSoil() { // Create a soil with specific stochasts defined var mySoil = CreateTestSoil(defineStressTables: false); mySoil.CohesionStochast.DistributionType = DistributionType.Normal; mySoil.FrictionAngleStochast.DistributionType = DistributionType.Normal; mySoil.StressTableStochast.DistributionType = DistributionType.Normal; mySoil.POPStochast.DistributionType = DistributionType.Normal; mySoil.OCRStochast.DistributionType = DistributionType.Normal; mySoil.RatioCuPcStochast.DistributionType = DistributionType.Normal; mySoil.RatioCuPcPassiveStochast.DistributionType = DistributionType.Normal; mySoil.RatioCuPcActiveStochast.DistributionType = DistributionType.Normal; mySoil.CuStochast.DistributionType = DistributionType.Normal; mySoil.CuTopStochast.DistributionType = DistributionType.Normal; mySoil.CuActiveTopStochast.DistributionType = DistributionType.Normal; mySoil.CuPassiveTopStochast.DistributionType = DistributionType.Normal; mySoil.CuBottomStochast.DistributionType = DistributionType.Normal; mySoil.CuActiveBottomStochast.DistributionType = DistributionType.Normal; mySoil.CuPassiveBottomStochast.DistributionType = DistributionType.Normal; mySoil.CuGradientStochast.DistributionType = DistributionType.Normal; mySoil.RRatioStochast.DistributionType = DistributionType.Normal; mySoil.PnStochast.DistributionType = DistributionType.Normal; mySoil.PermeabKxStochast.DistributionType = DistributionType.Normal; mySoil.DiameterD50Stochast.DistributionType = DistributionType.Normal; mySoil.DiameterD70Stochast.DistributionType = DistributionType.Normal; mySoil.BeddingAngleStochast.DistributionType = DistributionType.Normal; mySoil.WhitesConstantStochast.DistributionType = DistributionType.Normal; // Create another identical soil, but with the stochasts defined differently var myOtherSoil = CreateTestSoil(defineStressTables: false); myOtherSoil.CohesionStochast.DistributionType = DistributionType.Gamma; myOtherSoil.FrictionAngleStochast.DistributionType = DistributionType.Gamma; myOtherSoil.StressTableStochast.DistributionType = DistributionType.Gamma; myOtherSoil.POPStochast.DistributionType = DistributionType.Gamma; myOtherSoil.OCRStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcPassiveStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RatioCuPcActiveStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuActiveTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuPassiveTopStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuActiveBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuPassiveBottomStochast.DistributionType = DistributionType.Gamma; myOtherSoil.CuGradientStochast.DistributionType = DistributionType.Gamma; myOtherSoil.RRatioStochast.DistributionType = DistributionType.Gamma; myOtherSoil.PnStochast.DistributionType = DistributionType.Gamma; myOtherSoil.PermeabKxStochast.DistributionType = DistributionType.Gamma; myOtherSoil.DiameterD50Stochast.DistributionType = DistributionType.Gamma; myOtherSoil.DiameterD70Stochast.DistributionType = DistributionType.Gamma; myOtherSoil.BeddingAngleStochast.DistributionType = DistributionType.Gamma; myOtherSoil.WhitesConstantStochast.DistributionType = DistributionType.Gamma; var myProject = new DSoilModelProject(); // Add mySoil to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); // Try to add the soil with the same name and the differences in the stochastic properties to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count, "Already present soil should not be added a second time"); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); } [Test] public void AddSoilDataToProject_SoilsWithoutStressTables_AddSameSoil_DoNotAddSecondSoil() { var mySoil = CreateTestSoil(defineStressTables: false); var myProject = new DSoilModelProject(); // Add mySoil to the project myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); // Try to add the same soil for the second time myProject.AddSoilDataToProject(new SoilList { Soils = new List { mySoil } }); Assert.AreEqual(1, myProject.Soils.Soils.Count, "Already present soil should not be added a second time"); Assert.AreEqual(mySoil, myProject.Soils.Soils.First()); } [Test] public void TestRepairAllValidationResultsOnSoilsMinimumUnitWeight() { // setup var oldMechanisms = Soil.Mechanisms; Soil.Mechanisms = new[] { Mechanism.Stability }; using (var project = new DSoilModelProject()) { for (int i = 1; i <= 10; i++) { project.Soils.Soils.Add(new Soil { Name = string.Format("Soil{0}", i), BelowPhreaticLevel = -i, // minimum is 0.001 AbovePhreaticLevel = -i // minimum is 0.001 }); } var validationResults = Validator.Validate(project); Assert.AreEqual(20, validationResults.Count(r => r.MessageType == ValidationResultType.Error)); RealTimeBackgroundValidator.ValidationResults.AddRange(validationResults); // call project.RepairAllValidationResults(); // assert validationResults = Validator.Validate(project); Assert.AreEqual(0, validationResults.Count(r => r.MessageType == ValidationResultType.Error)); } Soil.Mechanisms = oldMechanisms; } private bool oldIsDataEventPublishStopped; private static Soil CreateTestSoil(bool defineStressTables = true) { Soil.Mechanisms = new[] { Mechanism.Stability }; var soil = new Soil { Name = "myClay", Description = "Clay", Color = Color.FromArgb(69, 184, 95), BelowPhreaticLevel = 20.58, AbovePhreaticLevel = 19.6, DryUnitWeight = 0.01, Cohesion = 20, EMod = 0, FrictionAngle = 30, POP = 10, OCR = 1, RatioCuPc = 0.22, RatioCuPcPassive = 0.22, RatioCuPcActive = 0.22, Cu = 0, CuTop = 0.0001, CuActiveTop = 0.0001, CuPassiveTop = 0.0001, CuBottom = 0.0001, CuActiveBottom = 0.0001, CuPassiveBottom = 0.0001, CuGradient = 0, UseDefaultProbabilisticValues = true, UsePop = true, RRatio = 0, ExcessPorePressure = 0, PorePressureFactor = 0, CorrelationCPhi = 0, Pn = 0, FormReferencePn = 0, UseDefaultShearStrengthModel = true, DilatancyType = DilatancyType.Phi, StrengthIncreaseExponent = 1, ShearStrengthModel = ShearStrengthModel.CPhi, UserShearStrengthModel = ShearStrengthModel.CPhi, UseDefaultShearStrengthInput = true, InputModeReliabilityAnalysisOption = ReliabilityAnalysisOption.Mean, UserShearStrengthInput = ReliabilityAnalysisOption.Mean, RestSlope = 0, SoilType = SoilType.Clay, PermeabKx = 0, DiameterD15 = 0.01, DiameterD50 = 0.01, DiameterD70 = 0.01, DiameterD90 = 0.01, BeddingAngle = 0, WhitesConstant = 0, UseSoilType = false, SoilGroup = 0, Alpha = 0, AlphaGrd = 0, Equilibrium = false, Iterations = 0, CalculationPoints = 0, ComputedPermeability = 0, Vwal = 0, FlowWidth = 1, Porosity = 0, MinPorosity = 1.5, MaxPorosity = 1.5, StateParameter = 0, Evoldm = 0.0025, Ks0 = 50000, ParS2 = 1.3, GammaKorrel = 26.5, ParM = 2, ParR = 7, ParU = 1, ParV = 1.25 }; if (defineStressTables) { soil.StressTable = StressCurveBuilder.CreateTestStressCurve(); soil.BondStressTable = BondStressCurveBuilder.CreateTestBondStressCurve(); } return soil; } } }