Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorPLLineCreatorTest.cs =================================================================== diff -u -r6102 -r6127 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorPLLineCreatorTest.cs (.../SensorPLLineCreatorTest.cs) (revision 6102) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators.Tests/Sensors/SensorPLLineCreatorTest.cs (.../SensorPLLineCreatorTest.cs) (revision 6127) @@ -276,13 +276,11 @@ double expectedZValueP4 = sensorValues[sensor4]; Assert.That(p4.Z, Is.EqualTo(expectedZValueP4)); } - + [Test] - public void CreatePlLine_Pl1DikeToeAtPolderToSurfaceLevelInside_ZValueShouldBePolderLevel() + public void CreatePlLine_NoLocationDataAtPl1DikeToeAtPolderAndNoPolderSensor_HorizontalLineExpectedBetweenLastSensorValueAndSurfaceLevelOutside() { // setup - const double polderLevel = -0.5; - const double expectedEndPoint = -0.1; // Is not polderlevel, but level under toe of dike inward var surfaceLine = new SurfaceLine2 { CharacteristicPoints = @@ -291,126 +289,12 @@ }, Geometry = new GeometryPointString() }; - Location location = CreateConfiguredLocation("test", 5, polderLevel); - location.AddSensorLocation(); - location.SensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = DataSourceTypeSensors.LocationData; - location.SensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder = DataSourceTypeSensors.LocationData; - location.SensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver = DataSourceTypeSensors.LocationData; - location.SensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside = DataSourceTypeSensors.LocationData; - - // create dike with ditch - - surfaceLine.EnsurePointOfType(0.0, 0.0, CharacteristicPointType.SurfaceLevelOutside); - surfaceLine.EnsurePointOfType(50.0, 0.0, CharacteristicPointType.DikeToeAtRiver); - surfaceLine.EnsurePointOfType(85.0, 8.0, CharacteristicPointType.DikeTopAtRiver); - surfaceLine.EnsurePointOfType(95.0, 8.0, CharacteristicPointType.DikeTopAtPolder); - surfaceLine.EnsurePointOfType(108.0, 4.0, CharacteristicPointType.ShoulderBaseInside); - surfaceLine.EnsurePointOfType(116.0, 3.0, CharacteristicPointType.ShoulderTopInside); - surfaceLine.EnsurePointOfType(121.0, 0.0, CharacteristicPointType.DikeToeAtPolder); - surfaceLine.EnsurePointOfType(190.0, 0.0, CharacteristicPointType.SurfaceLevelInside); - - location.SurfaceLine = surfaceLine; - - var sensor1 = new Sensor - { - ID = 1, - Name = "Test1", - Depth = 2, - RelativeLocation = 50, - PlLineMappings = new[] - { - PlLineType.Pl1 - }, - SensorType = SensorType.WaterLevel - }; - var sensor2 = new Sensor - { - ID = 2, - Name = "Test2", - Depth = 2, - RelativeLocation = 90, - PlLineMappings = new[] - { - PlLineType.Pl1 - } - }; - var sensor3 = new Sensor - { - ID = 3, - Name = "Test3", - Depth = 2, - RelativeLocation = 104, - PlLineMappings = new[] - { - PlLineType.Pl1 - } - }; - var sensor4 = new Sensor - { - ID = 4, - Name = "Test4", - Depth = 2, - RelativeLocation = 123.3, - PlLineMappings = new[] - { - PlLineType.Pl1 - } - }; - - var repository = new SensorRepository(location); - - repository.Add(sensor1); - repository.Add(sensor2); - repository.Add(sensor3); - repository.Add(sensor4); - - IDictionary sensorValues = new Dictionary - { - { - sensor1, 1 - }, - { - sensor2, 1 - }, - { - sensor3, 1 - }, - { - sensor4, 1 - } - }; - - SensorLocation sensorLocation = location.SensorLocation; - - var creator = new SensorPlLine1Creator(sensorLocation, sensorValues); - - // call - PlLine actual = creator.CreatePlLine(); - - // asserts - PlLinePoint lastPoint = actual.Points.Last(); - Assert.That(lastPoint.Z, Is.EqualTo(expectedEndPoint)); - } - - [Test, Category(Categories.WorkInProgress)] - public void CreatePlLine_Pl1DikeToeAtPolderToSurfaceLevelInsideAndNoLocationData_ZValueShouldBeSurfaceLevel() - { - // setup - const int expectedValue = 1; - var surfaceLine = new SurfaceLine2 - { - CharacteristicPoints = - { - GeometryMustContainPoint = true - }, - Geometry = new GeometryPointString() - }; Location location = CreateConfiguredLocation("test", 5, -1); location.AddSensorLocation(); location.SensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtRiver = DataSourceTypeSensors.LocationData; location.SensorLocation.SourceTypePl1PlLineOffsetBelowDikeTopAtPolder = DataSourceTypeSensors.LocationData; location.SensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside = DataSourceTypeSensors.LocationData; - location.SensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = DataSourceTypeSensors.Sensor; + location.SensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder = DataSourceTypeSensors.Ignore; surfaceLine.EnsurePointOfType(0.0, 0.0, CharacteristicPointType.SurfaceLevelOutside); surfaceLine.EnsurePointOfType(50.0, 0.0, CharacteristicPointType.DikeToeAtRiver); @@ -419,7 +303,7 @@ surfaceLine.EnsurePointOfType(108.0, 4.0, CharacteristicPointType.ShoulderBaseInside); surfaceLine.EnsurePointOfType(116.0, 3.0, CharacteristicPointType.ShoulderTopInside); surfaceLine.EnsurePointOfType(121.0, 0.0, CharacteristicPointType.DikeToeAtPolder); - surfaceLine.EnsurePointOfType(190.0, expectedValue, CharacteristicPointType.SurfaceLevelInside); + surfaceLine.EnsurePointOfType(190.0, 0.0, CharacteristicPointType.SurfaceLevelInside); location.SurfaceLine = surfaceLine; @@ -476,19 +360,23 @@ repository.Add(sensor3); repository.Add(sensor4); + const double sensor1Value = 1.1; + const double sensor2Value = 1.2; + const double sensor3Value = 1.3; + const double sensor4Value = 1.4; IDictionary sensorValues = new Dictionary { { - sensor1, 1 + sensor1, sensor1Value }, { - sensor2, 1 + sensor2, sensor2Value }, { - sensor3, 1 + sensor3, sensor3Value }, { - sensor4, 1 + sensor4, sensor4Value } }; @@ -501,7 +389,25 @@ // asserts PlLinePoint lastPoint = actual.Points.Last(); - Assert.That(lastPoint.Z, Is.EqualTo(expectedValue), "Incorrect last point of PL1: Test must be reviewed."); + Assert.That(actual.Points, Has.Count.EqualTo(9)); + Assert.That(actual.Points[0].X, Is.EqualTo(0)); + Assert.That(actual.Points[0].Z, Is.EqualTo(5)); + Assert.That(actual.Points[1].X, Is.EqualTo(71.875)); + Assert.That(actual.Points[1].Z, Is.EqualTo(5)); + Assert.That(actual.Points[2].X, Is.EqualTo(85)); + Assert.That(actual.Points[2].Z, Is.EqualTo(4.5)); + Assert.That(actual.Points[3].X, Is.EqualTo(90)); + Assert.That(actual.Points[3].Z, Is.EqualTo(sensor2Value)); + Assert.That(actual.Points[4].X, Is.EqualTo(95)); + Assert.That(actual.Points[4].Z, Is.EqualTo(3.5)); + Assert.That(actual.Points[5].X, Is.EqualTo(104)); + Assert.That(actual.Points[5].Z, Is.EqualTo(sensor3Value)); + Assert.That(actual.Points[6].X, Is.EqualTo(108)); + Assert.That(actual.Points[6].Z, Is.EqualTo(3.9)); + Assert.That(actual.Points[7].X, Is.EqualTo(123.3)); + Assert.That(actual.Points[7].Z, Is.EqualTo(sensor4Value)); + Assert.That(actual.Points[8].X, Is.EqualTo(190)); + Assert.That(actual.Points[8].Z, Is.EqualTo(sensor4Value)); } [Test] @@ -691,11 +597,11 @@ // asserts - // Number of expected points in line - const int expectedNumberOfCharacteristicPoints = 2; + // Number of expected points in PL 1 + const int expectedNumberOfCharacteristicPoints = 1; // Surface line inside int pl1SensorCount = repository.Sensors.Count(s => s.PlLineMappings.Contains(PlLineType.Pl1)) + - expectedNumberOfCharacteristicPoints + 1; // plus one for the intersection point + one for point below toe of dike - Assert.That(actual.Points.Count, Is.EqualTo(pl1SensorCount)); + expectedNumberOfCharacteristicPoints + 1; // plus one for the intersection point + Assert.That(actual.Points, Has.Count.EqualTo(pl1SensorCount)); // P2 PlLinePoint p2 = actual.Points.FirstOrDefault(p => p.Name == sensor2.Name); Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/SensorPlLine1Creator.cs =================================================================== diff -u -r6087 -r6127 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/SensorPlLine1Creator.cs (.../SensorPlLine1Creator.cs) (revision 6087) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/SensorPlLine1Creator.cs (.../SensorPlLine1Creator.cs) (revision 6127) @@ -239,12 +239,10 @@ // add all sensors to the pl line List sortedSensors = SensorsSortedAlongProfile.ToList(); - double lastZ = waterLevel; - double lastX = XBeginBoundary; foreach (Sensor sensor in sortedSensors) { - double x = lastX = GetSensorXValue(sensor); - double z = lastZ = GetSensorZValue(sensor); + double x = GetSensorXValue(sensor); + double z = GetSensorZValue(sensor); var point = new PlLinePoint(x, z) { @@ -288,21 +286,16 @@ // insert offset below shoulder base inside? if (useLocationAsDataSource.IsSatisfiedBy(SensorLocation.SourceTypePl1PlLineOffsetBelowShoulderBaseInside)) { - double offset = lastZ = ZShouldeBaseInside - SensorLocation.PlLineOffsetDryBelowShoulderBaseInside; + double offset = ZShouldeBaseInside - SensorLocation.PlLineOffsetDryBelowShoulderBaseInside; lineConstructor.Insert(new PlLinePoint(XShoulderBaseInside, offset)); } // insert offset below dike toe at polder? if (useLocationAsDataSource.IsSatisfiedBy(SensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder)) { - double offset = lastZ = ZDikeToeAtPolder - SensorLocation.PlLineOffsetBelowDikeToeAtPolder; + double offset = ZDikeToeAtPolder - SensorLocation.PlLineOffsetBelowDikeToeAtPolder; double x = XDikeToeAtPolder; lineConstructor.Insert(new PlLinePoint(x, offset)); - - if (lastX < x) - { - lastX = x; - } } if (DikeHasDitch) @@ -328,43 +321,25 @@ } else { - double depth = lastZ; - double xLocation = XDikeToeAtPolder; if (useLocationAsDataSource.IsSatisfiedBy(SensorLocation.SourceTypePl1PlLineOffsetBelowDikeToeAtPolder)) { - depth = ZDikeToeAtPolder - SensorLocation.PlLineOffsetBelowDikeToeAtPolder; + double xLocation = XDikeToeAtPolder; + double depth = ZDikeToeAtPolder - SensorLocation.PlLineOffsetBelowDikeToeAtPolder; + lineConstructor.Insert(xLocation, depth); } else { Sensor sensor = PolderLevelSensor; if (sensor != null) { - xLocation = sensor.RelativeLocation; - depth = PolderLevel; + double xLocation = sensor.RelativeLocation; + double depth = PolderLevel; + lineConstructor.Insert(xLocation, depth); } } - lineConstructor.Insert(new PlLinePoint(xLocation, depth)); - // always continue horizontal to end - lineConstructor.Insert(new PlLinePoint(XEndBoundary, depth)); - - /* - * TODO: verify with Kin Sun - else if (lastZ <= PolderLevel) - { - lineConstructor.Insert(new PlLinePoint(XEndBoundary, lastZ)); - } - else - { - - // add tail of surface line - foreach (Point2D Point2D in SensorLocation.SurfaceLine.GetSurfaceLineTailExcluding(lastX)) - { - lineConstructor.Insert(new PlLinePoint(Point2D.X, Point2D.Z) { Name = Point2D.Name }); - } - } - */ + lineConstructor.Insert(new PlLinePoint(XEndBoundary, lineConstructor.GetLastZ())); } return lineConstructor.CreatePlLine(PlLineType); Index: DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/PLLineConstructor.cs =================================================================== diff -u -r4540 -r6127 --- DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/PLLineConstructor.cs (.../PLLineConstructor.cs) (revision 4540) +++ DamEngine/trunk/src/Deltares.DamEngine.Calculators/PlLinesCreator/PLLineConstructor.cs (.../PLLineConstructor.cs) (revision 6127) @@ -20,6 +20,7 @@ // All rights reserved. using System.Collections.Generic; +using System.Linq; using Deltares.DamEngine.Data.General; using Deltares.DamEngine.Data.General.PlLines; @@ -62,6 +63,11 @@ Insert(new PlLinePoint(x, z)); } + public double GetLastZ() + { + return line[line.Keys.Max()].Z; + } + /// /// Gets the PL line from the internal constructed line. ///