Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void GetGeometryWidthYZDefinitionShouldBeFast()
        {
            var yz = new CrossSectionDefinitionYZ("");

            yz.YZDataTable.AddCrossSectionYZRow(10, 100, 0);
            yz.YZDataTable.AddCrossSectionYZRow(9, 90, 0);
            yz.YZDataTable.AddCrossSectionYZRow(8, 80, 0);
            yz.YZDataTable.AddCrossSectionYZRow(7, 60, 0);
            yz.YZDataTable.AddCrossSectionYZRow(6, 70, 0);
            yz.YZDataTable.AddCrossSectionYZRow(5, 40, 0);
            yz.YZDataTable.AddCrossSectionYZRow(4, 40, 0);
            yz.YZDataTable.AddCrossSectionYZRow(3, 20, 0);

            var network      = HydroNetworkHelper.GetSnakeHydroNetwork(1);
            var branch       = network.Channels.First();
            var crossSection = HydroNetworkHelper.AddCrossSectionDefinitionToBranch(branch, yz, 30);

            TestHelper.AssertIsFasterThan(50, () =>
            {
                for (int i = 0; i < 10000; i++)
                {
                    var geo = crossSection.Geometry;
                }
            });
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        public void MergeBranchWithCrossSections()
        {
            var network = CreateTestNetwork();
            var branch1 = network.Channels.First();

            var offset1 = Math.Sqrt(15 * 15 + 20 * 20);
            var offset2 = Math.Sqrt(30 * 30 + 40 * 40) + 40 + Math.Sqrt(15 * 15 + 20 * 20);
            var length1 = Math.Sqrt(30 * 30 + 40 * 40) + 20;
            var length2 = 20 + Math.Sqrt(30 * 30 + 60 * 60);

            var node = HydroNetworkHelper.SplitChannelAtNode(branch1, new Coordinate(50, 40), 0, 0);

            // remove the newly added node
            HydroNetworkHelper.MergeNodeBranches(node, network);

            Assert.AreEqual(1, network.Branches.Count);
            Assert.AreEqual(2, network.Nodes.Count);
            Assert.AreEqual(2, network.CrossSections.Count());
            Assert.AreEqual(2, branch1.CrossSections.Count());
            Assert.AreEqual(offset1, branch1.CrossSections.First().Offset);
            Assert.AreEqual(offset2, branch1.CrossSections.Skip(1).First().Offset);
            Assert.AreEqual(length1 + length2, branch1.Geometry.Length);

            Assert.AreEqual(branch1, branch1.CrossSections.First().Branch);
            Assert.AreEqual(branch1, branch1.CrossSections.Skip(1).First().Branch);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public void CloneHydroNetworkWithLinkSources()
        {
            var network   = HydroNetworkHelper.GetSnakeHydroNetwork(1);
            var catchment = new Catchment();

            network.Catchments.Add(catchment);
            var wasteWaterTreatmentPlant = new WasteWaterTreatmentPlant();

            network.WasteWaterTreatmentPlants.Add(wasteWaterTreatmentPlant);

            var lateral = new LateralSource();

            network.Branches.First().BranchFeatures.Add(lateral);

            catchment.OutgoingLinks.Add(wasteWaterTreatmentPlant);
            catchment.OutgoingLinks.Add(lateral);
            wasteWaterTreatmentPlant.IncomingLinks.Add(catchment);
            lateral.IncomingLinks.Add(catchment);

            var clone = (HydroNetwork)network.Clone();
            var links = TestReferenceHelper.SearchObjectInObjectGraph(catchment, clone);

            links.ForEach(Console.WriteLine);
            Assert.AreEqual(0, links.Count);

            Assert.AreEqual(2, clone.Catchments.First().OutgoingLinks.Count);
            Assert.AreEqual(1, clone.WasteWaterTreatmentPlants.First().IncomingLinks.Count);
            Assert.AreEqual(1, clone.LateralSources.First().IncomingLinks.Count);
        }
Beispiel #7
0
        public void CloneHydroNetworkWithVariousBranchFeatures()
        {
            var network = new HydroNetwork();
            var from    = new HydroNode();
            var to      = new HydroNode();

            network.Nodes.Add(from);
            network.Nodes.Add(to);
            var channel = new Channel {
                Source = from, Target = to
            };

            network.Branches.Add(channel);
            var compositeBranchStructure = new CompositeBranchStructure();

            NetworkHelper.AddBranchFeatureToBranch(channel, compositeBranchStructure, 0);
            HydroNetworkHelper.AddStructureToComposite(compositeBranchStructure, new Weir());
            HydroNetworkHelper.AddStructureToComposite(compositeBranchStructure, new Pump());

            NetworkHelper.AddBranchFeatureToBranch(channel, new CrossSection(), 0);

            var clonedHydroNetwork = (IHydroNetwork)network.Clone();

            clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1);
            clonedHydroNetwork.CompositeBranchStructures.Should().Have.Count.EqualTo(1);
            clonedHydroNetwork.Weirs.Should().Have.Count.EqualTo(1);
            clonedHydroNetwork.Pumps.Should().Have.Count.EqualTo(1);
        }
Beispiel #8
0
        public void CloneHydroNetworkWithVariousBranchFeatures()
        {
            var network = new HydroNetwork();
            var from    = new HydroNode();
            var to      = new HydroNode();

            network.Nodes.Add(from);
            network.Nodes.Add(to);
            var channel = new Channel {
                Source = from, Target = to
            };

            network.Branches.Add(channel);
            var compositeBranchStructure = new CompositeBranchStructure();

            NetworkHelper.AddBranchFeatureToBranch(compositeBranchStructure, channel, 0);
            HydroNetworkHelper.AddStructureToComposite(compositeBranchStructure, new Weir());
            HydroNetworkHelper.AddStructureToComposite(compositeBranchStructure, new Pump());

            var crossSectionXYZ = new CrossSectionDefinitionXYZ
            {
                Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) })
            };

            HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0);

            var clonedHydroNetwork = (IHydroNetwork)network.Clone();

            clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1);
            clonedHydroNetwork.CompositeBranchStructures.Should().Have.Count.EqualTo(1);
            clonedHydroNetwork.Weirs.Should().Have.Count.EqualTo(1);
            clonedHydroNetwork.Pumps.Should().Have.Count.EqualTo(1);
        }
Beispiel #9
0
        private HydroNetwork GetNetwork()
        {
            var network = new HydroNetwork();
            var crossSectionSectionType = new CrossSectionSectionType {
                Name = "Jan"
            };

            network.CrossSectionSectionTypes.Add(crossSectionSectionType);
            crossSectionSectionType.Id = 666;//debug easy by idd
            var from = new HydroNode();
            var to   = new HydroNode();

            network.Nodes.Add(from);
            network.Nodes.Add(to);
            var channel = new Channel {
                Source = from, Target = to
            };

            network.Branches.Add(channel);
            var crossSectionXYZ = new CrossSectionDefinitionXYZ
            {
                Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) })
            };

            crossSectionXYZ.Sections.Add(new CrossSectionSection {
                SectionType = crossSectionSectionType
            });

            HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0);
            return(network);
        }
Beispiel #10
0
        public void CannotRemoveSectionTypesThatAreUsedByCrossSections()
        {
            //setup a network with a crossection and a sectiontype that is used
            var channel                 = new Channel();
            var network                 = new HydroNetwork();
            var crossSectionZW          = new CrossSectionDefinitionZW();
            var crossSectionSectionType = new CrossSectionSectionType();

            crossSectionZW.Sections.Add(new CrossSectionSection {
                SectionType = crossSectionSectionType
            });
            HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionZW, 0.0);

            network.CrossSectionSectionTypes.Add(crossSectionSectionType);
            network.Branches.Add(channel);


            //action! remove the sectiontype
            network.CrossSectionSectionTypes.Remove(crossSectionSectionType);

            //still have 2. one plus a 'default'?
            Assert.AreEqual(2, network.CrossSectionSectionTypes.Count);

            Assert.IsTrue(network.CrossSectionSectionTypes.Contains(crossSectionSectionType));
        }
Beispiel #11
0
        [Category(TestCategory.BadQuality)] // TODO: test Add or change name
        public void AddManyBranchesWithSimpleBranchFeature()
        {
            const int count     = 10000;
            int       weirCount = 0;

            Action action = delegate // TODO: what are we testing here? Test only add.
            {
                var network = new HydroNetwork();
                for (int i = 0; i < count; i++)
                {
                    var from = new HydroNode();
                    var to   = new HydroNode();

                    network.Nodes.Add(from);
                    network.Nodes.Add(to);

                    var channel = new Channel {
                        Source = from, Target = to
                    };

                    var compositeBranchStructure = new CompositeBranchStructure();
                    NetworkHelper.AddBranchFeatureToBranch(compositeBranchStructure, channel, 0);
                    HydroNetworkHelper.AddStructureToComposite(compositeBranchStructure, new Weir());

                    network.Branches.Add(channel);
                }

                foreach (IWeir weir in network.Weirs)                     // access all Weirs should be also fast
                {
                    weirCount++;
                }
            };

            TestHelper.AssertIsFasterThan(2750, string.Format("Added {0} branches with {1} weirs", count, weirCount), action);
        }
Beispiel #12
0
        public void SetDefaultGeometryWithBrancheGeometry()
        {
            var hydroNetwork = new HydroNetwork();

            var channel = new Channel {
                Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(20, 0) })
            };

            var crossSectionDefinition = new CrossSectionDefinitionYZ();

            crossSectionDefinition.YZDataTable.AddCrossSectionYZRow(0, 5, 0);
            crossSectionDefinition.YZDataTable.AddCrossSectionYZRow(2, 0, 1);
            crossSectionDefinition.YZDataTable.AddCrossSectionYZRow(4, 5, 0);
            crossSectionDefinition.Thalweg = 2;

            hydroNetwork.Branches.Add(channel);
            int offset       = 12;
            var crossSection = HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionDefinition, offset);

            Assert.AreEqual(4, crossSection.Geometry.Length);
            Assert.AreEqual(2, crossSection.Geometry.Coordinates.Length);

            Assert.IsTrue(crossSection.Geometry.Coordinates.All(c => c.X == offset));
            Assert.AreEqual(new[] { 2d, -2d }, crossSection.Geometry.Coordinates.Select(c => c.Y).ToList());
        }
Beispiel #13
0
        public void AddManyBranchesWithCrossSections()
        {
            TestHelper.AssertIsFasterThan(2275, () =>
            {
                const int count = 10000;
                var network     = new HydroNetwork();
                for (int i = 0; i < count; i++)
                {
                    var from = new HydroNode();
                    var to   = new HydroNode();

                    network.Nodes.Add(from);
                    network.Nodes.Add(to);

                    var channel = new Channel {
                        Source = from, Target = to
                    };
                    HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel,
                                                                         new CrossSectionDefinitionXYZ(),
                                                                         0);
                }

                int crossSectionCount = 0;
                foreach (var crossSection in network.CrossSections)
                {
                    // access all CrossSections should be also fast
                    crossSectionCount++;
                }
            });
        }
Beispiel #14
0
        public void CloneHydroNetworkWithData()
        {
            var network = HydroNetworkHelper.GetSnakeHydroNetwork(1);

            var publicProperties = ReflectionTestHelper.GetPublicListProperties(network);

            foreach (var prop in publicProperties)
            {
                try
                {
                    var value = prop.GetValue(network, null);
                    if (value is IList)
                    {
                        var genericType = TypeUtils.GetFirstGenericTypeParameter(value.GetType());

                        var concreteType =
                            genericType.Assembly.GetTypes().Where(
                                t => genericType.IsAssignableFrom(t) &&
                                !t.IsInterface &&
                                !t.IsAbstract).FirstOrDefault();

                        var instance = Activator.CreateInstance(concreteType);
                        (value as IList).Add(instance);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine(String.Format("Unable to set property: {0}", prop));
                }
            }

            var clone = (HydroNetwork)network.Clone();

            TestReferenceHelper.AssertStringRepresentationOfGraphIsEqual(network, clone);
        }
Beispiel #15
0
        public void LateralSourceCheckGeometry()
        {
            var hydroNetwork = HydroNetworkHelper.GetSnakeHydroNetwork(new Point(0, 0), new Point(200, 0), new Point(200, 200));
            var branch1      = hydroNetwork.Branches[0];

            var lateralSource = new LateralSource
            {
                Name   = "Source1",
                Offset = 10,
            };

            branch1.BranchFeatures.Add(lateralSource);
            lateralSource.Branch    = branch1;
            lateralSource.IsDiffuse = true;

            //needed here; this is actually done via LateralSourceProperties
            HydroNetworkEditorHelper.UpdateBranchFeatureGeometry(lateralSource, 40);
            var geometry = lateralSource.Geometry;

            Assert.AreEqual(typeof(LineString), geometry.GetType());
            Assert.AreEqual(40.0, geometry.Length);

            lateralSource.IsDiffuse = false;
            HydroNetworkEditorHelper.UpdateBranchFeatureGeometry(lateralSource, 0);
            Assert.AreEqual(typeof(Point), lateralSource.Geometry.GetType());
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        public void ChangeInDefinitionUpdatesGeometry()
        {
            //v-shaped cs 100 wide
            var crossSectionDefinitionYZ = new CrossSectionDefinitionYZ("");

            crossSectionDefinitionYZ.YZDataTable.AddCrossSectionYZRow(0, 100, 0);
            crossSectionDefinitionYZ.YZDataTable.AddCrossSectionYZRow(50, 0, 0);
            crossSectionDefinitionYZ.YZDataTable.AddCrossSectionYZRow(100, 100, 0);
            crossSectionDefinitionYZ.Thalweg = 50;

            //horizontal line
            var           network      = HydroNetworkHelper.GetSnakeHydroNetwork(new Point(0, 0), new Point(100, 0));
            var           branch       = network.Channels.First();
            ICrossSection crossSection = HydroNetworkHelper.AddCrossSectionDefinitionToBranch(branch, crossSectionDefinitionYZ, 50);


            var expectedGeometry = new LineString(new[] { new Coordinate(50, 50), new Coordinate(50, -50) });

            //use equals exact because rounding errors occur
            Assert.IsTrue(expectedGeometry.EqualsExact(crossSection.Geometry, 0.0001));

            //action : change the profile
            crossSectionDefinitionYZ.YZDataTable[0].Yq = -20;

            expectedGeometry = new LineString(new[] { new Coordinate(50, 70), new Coordinate(50, -50) });
            Assert.IsTrue(expectedGeometry.EqualsExact(crossSection.Geometry, 0.0001));

            //action: change the thalweg
            crossSectionDefinitionYZ.Thalweg = 40;

            expectedGeometry = new LineString(new[] { new Coordinate(50, 60), new Coordinate(50, -60) });
            Assert.IsTrue(expectedGeometry.EqualsExact(crossSection.Geometry, 0.0001));
        }
Beispiel #18
0
        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);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        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);
        }
Beispiel #21
0
        public void SplitBranchIn2()
        {
            IHydroNetwork network = CreateTestNetwork();
            var           branch1 = network.Channels.First();
            double        length  = branch1.Geometry.Length;

            int        nodesCount = network.Nodes.Count;
            IHydroNode hydroNode  = HydroNetworkHelper.SplitChannelAtNode(branch1, length / 2);

            Assert.AreEqual(nodesCount + 1, network.Nodes.Count);
            Assert.AreNotEqual(-1, network.Nodes.IndexOf(hydroNode));
        }
Beispiel #22
0
        public void CloneHydroNetworkWithProxyDefinitions()
        {
            var network          = HydroNetworkHelper.GetSnakeHydroNetwork(1);
            var sharedDefinition = new CrossSectionDefinitionYZ();

            network.SharedCrossSectionDefinitions.Add(sharedDefinition);
            HydroNetworkHelper.AddCrossSectionDefinitionToBranch(network.Channels.First(),
                                                                 new CrossSectionDefinitionProxy(sharedDefinition),
                                                                 10.0d);

            var clone = (HydroNetwork)network.Clone();

            TestReferenceHelper.AssertStringRepresentationOfGraphIsEqual(network, clone);
        }
Beispiel #23
0
        public void BranchCrossSectionShouldRaiseCollectionChangedEvent()
        {
            var crossSection = new CrossSectionDefinitionXYZ();
            var branch       = new Channel(new HydroNode("from"), new HydroNode("To"));

            int count = 0;

            Post.Cast <Channel, INotifyCollectionChange>(branch).CollectionChanged += delegate { count++; };

            HydroNetworkHelper.AddCrossSectionDefinitionToBranch(branch, crossSection, 0.0);
            Assert.AreEqual(1, count);

            branch.BranchFeatures.Clear();
            Assert.AreEqual(2, count);
        }
Beispiel #24
0
        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);
        }
Beispiel #25
0
        public void MakeDefinitionSharedCopiesDefinitionToNetwork()
        {
            var crossSectionDefinitionYZ = CrossSectionDefinitionYZ.CreateDefault();

            var hydroNetwork = HydroNetworkHelper.GetSnakeHydroNetwork(1);

            var crossSection = new CrossSection(crossSectionDefinitionYZ)
            {
                Branch = hydroNetwork.Channels.First()
            };

            Assert.AreEqual(0, hydroNetwork.SharedCrossSectionDefinitions.Count);

            crossSection.ShareDefinitionAndChangeToProxy();

            Assert.AreEqual(1, hydroNetwork.SharedCrossSectionDefinitions.Count);
            Assert.AreEqual(crossSectionDefinitionYZ, hydroNetwork.SharedCrossSectionDefinitions.First());
        }
Beispiel #26
0
        public void ReverseBranchWithCrossSections()
        {
            var network = CreateTestNetwork();
            var branch1 = (IChannel)network.Branches[0];

            var nodeFrom = branch1.Source;
            var nodeTo   = branch1.Target;

            double offsetCrossSection1 = branch1.CrossSections.First().Offset;
            double offsetCrossSection2 = branch1.CrossSections.Skip(1).First().Offset;
            double length = branch1.Geometry.Length;

            HydroNetworkHelper.ReverseBranch(branch1);

            Assert.AreEqual(nodeFrom, branch1.Target);
            Assert.AreEqual(nodeTo, branch1.Source);
            Assert.AreEqual(length - offsetCrossSection2, branch1.CrossSections.First().Offset);
            Assert.AreEqual(length - offsetCrossSection1, branch1.CrossSections.Skip(1).First().Offset);
        }
Beispiel #27
0
        public void CloneRewiresProxyDefinitions()
        {
            var network          = HydroNetworkHelper.GetSnakeHydroNetwork(1);
            var sharedDefinition = new CrossSectionDefinitionYZ();

            network.SharedCrossSectionDefinitions.Add(sharedDefinition);
            var crossSectionDefinitionProxy = new CrossSectionDefinitionProxy(sharedDefinition);

            HydroNetworkHelper.AddCrossSectionDefinitionToBranch(network.Branches.First(),
                                                                 crossSectionDefinitionProxy, 10.0);

            var clonedNetwork = (HydroNetwork)network.Clone();

            Assert.AreEqual(1, clonedNetwork.SharedCrossSectionDefinitions.Count);
            //check the proxy got rewired
            var crossSectionClone     = clonedNetwork.CrossSections.First();
            var clonedProxyDefinition = (CrossSectionDefinitionProxy)crossSectionClone.Definition;

            Assert.AreEqual(clonedProxyDefinition.InnerDefinition, clonedNetwork.SharedCrossSectionDefinitions.First());
        }
Beispiel #28
0
        public void CloneHydroNetworkWithCrossSectionSectionTypes()
        {
            var network = new HydroNetwork();
            var crossSectionSectionType = new CrossSectionSectionType {
                Name = "Jan"
            };

            network.CrossSectionSectionTypes.Add(crossSectionSectionType);
            crossSectionSectionType.Id = 666;//debug easy by idd
            var from = new HydroNode();
            var to   = new HydroNode();

            network.Nodes.Add(from);
            network.Nodes.Add(to);
            var channel = new Channel {
                Source = from, Target = to
            };

            network.Branches.Add(channel);
            var crossSectionXYZ = new CrossSectionDefinitionXYZ
            {
                Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) })
            };

            crossSectionXYZ.Sections.Add(new CrossSectionSection {
                SectionType = crossSectionSectionType
            });

            HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0);

            var clonedHydroNetwork = (IHydroNetwork)network.Clone();

            clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1);
            var cloneCrossSection = clonedHydroNetwork.CrossSections.FirstOrDefault();
            var clonedType        = clonedHydroNetwork.CrossSectionSectionTypes.FirstOrDefault(t => t.Name == "Jan");

            //the type should be cloned
            Assert.AreNotEqual(clonedType, crossSectionSectionType);
            //the crosssection reference should be updated to use the cloned type
            Assert.AreEqual(clonedType, cloneCrossSection.Definition.Sections[0].SectionType);
        }
Beispiel #29
0
        public void AddManyBranchesWithSimpleBranchFeature()
        {
            DateTime t = DateTime.Now;

            const int count   = 10000;
            var       network = new HydroNetwork();

            for (int i = 0; i < count; i++)
            {
                var from = new HydroNode();
                var to   = new HydroNode();

                network.Nodes.Add(from);
                network.Nodes.Add(to);

                var channel = new Channel {
                    Source = from, Target = to
                };

                var compositeBranchStructure = new CompositeBranchStructure();
                NetworkHelper.AddBranchFeatureToBranch(channel, compositeBranchStructure, 0);
                HydroNetworkHelper.AddStructureToComposite(compositeBranchStructure, new Weir());

                network.Branches.Add(channel);
            }

            int weirCount = 0;

            foreach (IWeir weir in network.Weirs) // access all Weirs should be also fast
            {
                weirCount++;
            }

            TimeSpan dt = DateTime.Now - t;

            log.InfoFormat("Added {0} branches with {1} weirs in {2} sec", count, weirCount, dt.TotalSeconds);

            // 20091029 set to 5 seconds; original test only added weirs and created an invalid hydronetwork
            Assert.LessOrEqual(dt.TotalSeconds, 2.7);
        }
Beispiel #30
0
        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());
        }