public void CreateSegmentsCrossSectionAndMinimumDistanceNearEnd() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); AddTestCrossSectionAt(network, branch1, 99.0); var networkCoverage = new Discretization() { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage branch1, // branch 5.0, // minimumDistance false, // gridAtStructure 0.5, // structureDistance true, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength Assert.AreEqual(2, networkCoverage.Locations.Values.Count); Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(100.0, networkCoverage.Locations.Values[1].Offset, 1.0e-6); }
public void CreateSegmentsMultipleCrossSectionAndMinimumDistance() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); // add multiple cross sections and generate calculation points at the cross section locations // Grid cells too smal should not be generated. AddTestCrossSectionAt(network, branch1, 1.0); AddTestCrossSectionAt(network, branch1, 2.0); AddTestCrossSectionAt(network, branch1, 3.0); AddTestCrossSectionAt(network, branch1, 4.0); AddTestCrossSectionAt(network, branch1, 5.0); AddTestCrossSectionAt(network, branch1, 6.0); var networkCoverage = new Discretization() { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage branch1, // branch 5.0, // minimumDistance false, // gridAtStructure 0.5, // structureDistance true, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength Assert.AreEqual(3, networkCoverage.Locations.Values.Count); Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(5.0, networkCoverage.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(100.0, networkCoverage.Locations.Values[2].Offset, 1.0e-6); }
public void CreateSegments1StructureAtMinimumEndBranch() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); AddTestStructureAt(network, branch1, 99.6); var networkCoverage = new Discretization() { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage branch1, // branch 0.5, // minimumDistance true, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength // structure at less than minimumdistance; expect 1 point left out // [-----------------------------------------------------] // 99.6 // x-------------------------------------------x-----(x)--- x // 0 99.1 (99.8) 100 Assert.AreEqual(3, networkCoverage.Locations.Values.Count); Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(99.1, networkCoverage.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(100.0, networkCoverage.Locations.Values[2].Offset, 1.0e-6); }
public void CreateSegments1StructureAtNearMinimumBeginBranch() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); AddTestStructureAt(network, branch1, 0.8); var networkCoverage = new Discretization { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage branch1, // branch 0.5, // minimumDistance true, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength // structure at near minimumdistance; expect point centered at 0.8 - 0.5 = 0.3 not created // [---------------------- // 0.8 // x x x ----------------------------- x // 0 (0.3) 1.3 100 // ^ Assert.AreEqual(3, networkCoverage.Locations.Values.Count); Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(1.3, networkCoverage.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(100.0, networkCoverage.Locations.Values[2].Offset, 1.0e-6); }
public void CreateSegmentsMultipleStructures() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); AddTestStructureAt(network, branch1, 20); AddTestStructureAt(network, branch1, 40); AddTestStructureAt(network, branch1, 60); var networkCoverage = new Discretization { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage branch1, // branch 0, // minimumDistance true, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength Assert.AreEqual(8, networkCoverage.Locations.Values.Count); Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(19.5, networkCoverage.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(20.5, networkCoverage.Locations.Values[2].Offset, 1.0e-6); Assert.AreEqual(39.5, networkCoverage.Locations.Values[3].Offset, 1.0e-6); Assert.AreEqual(40.5, networkCoverage.Locations.Values[4].Offset, 1.0e-6); Assert.AreEqual(59.5, networkCoverage.Locations.Values[5].Offset, 1.0e-6); Assert.AreEqual(60.5, networkCoverage.Locations.Values[6].Offset, 1.0e-6); Assert.AreEqual(100.0, networkCoverage.Locations.Values[7].Offset, 1.0e-6); }
public void CreateSegmentsMultipleCrossSectionsAndFixedPoint() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); var discretization = new Discretization() { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage branch1, // branch 5.0, // minimumDistance false, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection true, // gridAtFixedLength 2); // fixedLength Assert.AreEqual(51, discretization.Locations.Values.Count); INetworkLocation networkLocation = discretization.Locations.Values.Where(nl => nl.Offset == 8).First(); //DiscretizationHelper.SetUserDefinedGridPoint(networkLocation, true); discretization.ToggleFixedPoint(networkLocation); networkLocation = discretization.Locations.Values.Where(nl => nl.Offset == 32).First(); discretization.ToggleFixedPoint(networkLocation); AddTestCrossSectionAt(network, branch1, 10.0); AddTestCrossSectionAt(network, branch1, 20.0); AddTestCrossSectionAt(network, branch1, 30.0); HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage branch1, // branch 5.0, // minimumDistance false, // gridAtStructure 0.5, // structureDistance true, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength // expect gridpoints at: // begin and end 0 and 100 // fixed locations 8 and 32. // 20 for the cross section, 10 and 30 should not be generated due to existing // fixed points and minimium distance 0f 5. Assert.AreEqual(5, discretization.Locations.Values.Count); Assert.AreEqual(0.0, discretization.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(8.0, discretization.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(20.0, discretization.Locations.Values[2].Offset, 1.0e-6); Assert.AreEqual(32.0, discretization.Locations.Values[3].Offset, 1.0e-6); Assert.AreEqual(100.0, discretization.Locations.Values[4].Offset, 1.0e-6); }
public void CreateSegments2StructureAtNearMinimumBeginBranch() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); AddTestStructureAt(network, branch1, 0.8); AddTestStructureAt(network, branch1, 1.2); var networkCoverage = new Discretization() { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage branch1, // branch 0.001, // minimumDistance true, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength // structure at near minimumdistance; expect 1 point centered at first segment // [---------------------- // 0.8 1.2 // x x x x ------------------ x // 0 0.3 1.0 1.7 100 // ^ Assert.AreEqual(5, networkCoverage.Locations.Values.Count); Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(0.3, networkCoverage.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(1.0, networkCoverage.Locations.Values[2].Offset, 1.0e-6); Assert.AreEqual(1.7, networkCoverage.Locations.Values[3].Offset, 1.0e-6); Assert.AreEqual(100.0, networkCoverage.Locations.Values[4].Offset, 1.0e-6); // repeat with minimumDistance set to 0.5 HydroNetworkHelper.GenerateDiscretization(networkCoverage, // networkCoverage branch1, // branch 0.5, // minimumDistance true, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength // expect gridpoints at 0.3 eliminated Assert.AreEqual(4, networkCoverage.Locations.Values.Count); Assert.AreEqual(0.0, networkCoverage.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(1.0, networkCoverage.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(1.7, networkCoverage.Locations.Values[2].Offset, 1.0e-6); Assert.AreEqual(100.0, networkCoverage.Locations.Values[3].Offset, 1.0e-6); }
public void CreateSegmentsFixedLocations() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); var discretization = new Discretization() { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage branch1, // branch 0.5, // minimumDistance false, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection true, // gridAtFixedLength 10); // fixedLength Assert.AreEqual(11, discretization.Locations.Values.Count); Assert.AreEqual(0.0, discretization.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(50.0, discretization.Locations.Values[5].Offset, 1.0e-6); Assert.AreEqual(100.0, discretization.Locations.Values[10].Offset, 1.0e-6); INetworkLocation networkLocation = discretization.Locations.Values[7]; Assert.AreEqual(70.0, networkLocation.Offset, 1.0e-6); discretization.ToggleFixedPoint(networkLocation); //DiscretizationHelper.SetUserDefinedGridPoint(networkLocation, true); HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage branch1, // branch 0.5, // minimumDistance false, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection true, // gridAtFixedLength 40); // fixedLength // expect values at // - 0 and 100 start and end // - 70 for fixed location // - none between 70 and 100 // - (0 - 70) > 40, divide in equal parts -> 35 Assert.AreEqual(4, discretization.Locations.Values.Count); Assert.AreEqual(0.0, discretization.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(35.0, discretization.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(70.0, discretization.Locations.Values[2].Offset, 1.0e-6); Assert.AreEqual(100.0, discretization.Locations.Values[3].Offset, 1.0e-6); }
public void SplitBranchWithBranchSegments() { IHydroNetwork network = CreateTestNetwork(); var branch1 = network.Channels.First(); double length = branch1.Geometry.Length; // see also test GenerateDiscretization INetworkCoverage networkCoverage = new NetworkCoverage { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocationsFullyCovered }; HydroNetworkHelper.GenerateDiscretization(networkCoverage, branch1, new[] { 0.0, length / 3, 2 * length / 3, length }); HydroNetworkHelper.SplitChannelAtNode(branch1, length / 2); var branch2 = network.Channels.Skip(1).First(); Assert.AreEqual(2, networkCoverage.Segments.Values.Count); Assert.AreEqual(2, networkCoverage.Segments.Values.Where(s => s.Branch == branch1).Count()); Assert.AreEqual(0, networkCoverage.Segments.Values.Where(s => s.Branch == branch2).Count()); }
public void CreateNetworkCoverageSegments() { IHydroNetwork network = CreateTestNetwork(); INetworkCoverage networkCoverage = new NetworkCoverage { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; var branch1 = network.Channels.First(); var length = branch1.Geometry.Length; HydroNetworkHelper.GenerateDiscretization(networkCoverage, branch1, new[] { 0.0, length / 3, 2 * length / 3, length }); Assert.AreEqual(4, networkCoverage.Locations.Values.Count); Assert.AreEqual(3, networkCoverage.Segments.Values.Count); Assert.AreEqual(0, networkCoverage.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(length / 3, networkCoverage.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(2 * length / 3, networkCoverage.Locations.Values[2].Offset, 1.0e-6); Assert.AreEqual(length, networkCoverage.Locations.Values[3].Offset, 1.0e-6); Assert.AreEqual(0, networkCoverage.Segments.Values[0].Offset, 1.0e-6); Assert.AreEqual(length / 3, networkCoverage.Segments.Values[0].EndOffset, 1.0e-6); Assert.AreEqual(length / 3, networkCoverage.Segments.Values[0].Length, 1.0e-6); Assert.AreEqual(length / 3, networkCoverage.Segments.Values[1].Offset, 1.0e-6); Assert.AreEqual(2 * length / 3, networkCoverage.Segments.Values[1].EndOffset, 1.0e-6); Assert.AreEqual(2 * length / 3, networkCoverage.Segments.Values[2].Offset, 1.0e-6); Assert.AreEqual(length, networkCoverage.Segments.Values[2].EndOffset, 1.0e-6); Assert.AreEqual(length / 3, networkCoverage.Segments.Values[0].Length, 1.0e-6); Assert.AreEqual(length / 3, networkCoverage.Segments.Values[1].Length, 1.0e-6); Assert.AreEqual(length / 3, networkCoverage.Segments.Values[2].Length, 1.0e-6); }
public void CreateSegmentsMultipleStructuresAndFixedPoint() { IHydroNetwork network = CreateSegmentTestNetwork(); var branch1 = network.Channels.First(); var discretization = new Discretization() { Network = network, SegmentGenerationMethod = SegmentGenerationMethod.SegmentBetweenLocations }; HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage branch1, // branch 5.0, // minimumDistance false, // gridAtStructure 0.5, // structureDistance false, // gridAtCrossSection true, // gridAtFixedLength 2); // fixedLength Assert.AreEqual(51, discretization.Locations.Values.Count); INetworkLocation networkLocation = discretization.Locations.Values.Where(nl => nl.Offset == 8).First(); //DiscretizationHelper.SetUserDefinedGridPoint(networkLocation, true); discretization.ToggleFixedPoint(networkLocation); networkLocation = discretization.Locations.Values.Where(nl => nl.Offset == 32).First(); discretization.ToggleFixedPoint(networkLocation); //DiscretizationHelper.SetUserDefinedGridPoint(networkLocation, true); AddTestStructureAt(network, branch1, 10.0); AddTestStructureAt(network, branch1, 20.0); AddTestStructureAt(network, branch1, 30.0); HydroNetworkHelper.GenerateDiscretization(discretization, // networkCoverage branch1, // branch 6.0, // minimumDistance true, // gridAtStructure 4.0, // structureDistance false, // gridAtCrossSection false, // gridAtFixedLength -1); // fixedLength // expect gridpoints with no minimumDistance // 0 8 (6 14) (16 24) (26 34) 32 100 // 0 6 8 14 16 24 26 32 34 100 // 10 20 30 // structure locations // 0 8 14 24 32 100 // result // fixed locations 8 and 32. // first structure (6) and 14 // second structure 16 and 24; 16 will be merged into 14 -> 15 // third structure 26 and (34); 26 will be merged into 24 -> 25 // fixed points and minimium distance 0f 5. Assert.AreEqual(6, discretization.Locations.Values.Count); Assert.AreEqual(0.0, discretization.Locations.Values[0].Offset, 1.0e-6); Assert.AreEqual(8.0, discretization.Locations.Values[1].Offset, 1.0e-6); Assert.AreEqual(15.0, discretization.Locations.Values[2].Offset, 1.0e-6); Assert.AreEqual(25.0, discretization.Locations.Values[3].Offset, 1.0e-6); Assert.AreEqual(32.0, discretization.Locations.Values[4].Offset, 1.0e-6); Assert.AreEqual(100.0, discretization.Locations.Values[5].Offset, 1.0e-6); }