コード例 #1
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);
        }
コード例 #2
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++;
                }
            });
        }
コード例 #3
0
        public void CloneHydroNetwork()
        {
            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);
            network.CrossSectionSectionTypes.Add(new CrossSectionSectionType {
                Name = "JemigdePemig"
            });
            var crossSectionSectionTypesCount = network.CrossSectionSectionTypes.Count;

            // The default CrossSectionSectionType and JDP
            Assert.AreEqual(2, crossSectionSectionTypesCount);
            var clonedHydroNetwork = (IHydroNetwork)network.Clone();

            clonedHydroNetwork.GetType().Should().Be.EqualTo(typeof(HydroNetwork));

            clonedHydroNetwork.Branches.Count.Should().Be.EqualTo(1);
            clonedHydroNetwork.Nodes.Count.Should().Be.EqualTo(2);
            clonedHydroNetwork.CrossSectionSectionTypes.Count.Should().Be.EqualTo(crossSectionSectionTypesCount);
            Assert.AreEqual("JemigdePemig", clonedHydroNetwork.CrossSectionSectionTypes.Last().Name);
        }
コード例 #4
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);
        }
コード例 #5
0
        public void SetDefaultGeometryWithBrancheGeometry()
        {
            const double defaultLength = 2;
            var          hydroNetwork  = new HydroNetwork();

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

            var crossSection = new CrossSection
            {
                CrossSectionType = CrossSectionType.GeometryBased,
                Geometry         = new LineString(new[] { new Coordinate(10, 0), new Coordinate(10, 0) }),
                ThalWay          = defaultLength / 2
            };

            hydroNetwork.Branches.Add(channel);
            NetworkHelper.AddBranchFeatureToBranch(channel, crossSection, crossSection.Offset);
            crossSection.Offset = 12;

            CrossSectionHelper.SetDefaultGeometry(crossSection, defaultLength);

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

            Assert.AreEqual(12, crossSection.Geometry.Coordinates[0].X);
            Assert.AreEqual(12, crossSection.Geometry.Coordinates[1].X);
            Assert.AreEqual(-defaultLength / 2, crossSection.Geometry.Coordinates[0].Y);
            Assert.AreEqual(defaultLength / 2, crossSection.Geometry.Coordinates[1].Y);
        }
コード例 #6
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());
        }
コード例 #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(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);
        }
コード例 #8
0
ファイル: HydroNetworkTest.cs プロジェクト: lishxi/_SharpMap
        public void AddManyBranchesWithCrossSections()
        {
            TestHelper.AssertIsFasterThan(2000,() =>
                                                     {
                                                         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};
                                                             NetworkHelper.AddBranchFeatureToBranch(channel,
                                                                                                    new CrossSection(),
                                                                                                    0);

                                                             network.Branches.Add(channel);
                                                         }

                                                         int crossSectionCount = 0;
                                                         foreach (ICrossSection crossSection in network.CrossSections)
                                                             // access all CrossSections should be also fast
                                                         {
                                                             crossSectionCount++;
                                                         }
                                                     });
        }
コード例 #9
0
        public void CloneHydroNetworkAndAddBranch()
        {
            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 clonedNetwork = (IHydroNetwork)network.Clone();

            var from2 = new HydroNode("from2");
            var to2   = new HydroNode("to2");

            clonedNetwork.Nodes.Add(from2);
            clonedNetwork.Nodes.Add(to2);
            var channel2 = new Channel {
                Name = "channel2", Source = from2, Target = to2
            };

            clonedNetwork.Branches.Add(channel2);

            Assert.AreEqual(1, network.Branches.Count);
            Assert.AreEqual(2, clonedNetwork.Branches.Count);
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #12
0
        public void SetDefaultGeometryWithBrancheGeometry()
        {
            const double defaultLength = 2; 
            var hydroNetwork = new HydroNetwork();

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

            var crossSection = new CrossSection
                                   {
                                       CrossSectionType = CrossSectionType.GeometryBased,
                                       Geometry = new LineString(new[] {new Coordinate(10, 0), new Coordinate(10, 0)}),
                                       ThalWay = defaultLength/2
                                   };

            hydroNetwork.Branches.Add(channel);
            NetworkHelper.AddBranchFeatureToBranch(channel, crossSection, crossSection.Offset);
            crossSection.Offset = 12;

            CrossSectionHelper.SetDefaultGeometry(crossSection, defaultLength);

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

            Assert.AreEqual(12, crossSection.Geometry.Coordinates[0].X);
            Assert.AreEqual(12, crossSection.Geometry.Coordinates[1].X);
            Assert.AreEqual(-defaultLength/2, crossSection.Geometry.Coordinates[0].Y);
            Assert.AreEqual(defaultLength/2, crossSection.Geometry.Coordinates[1].Y);
        }
コード例 #13
0
        public void GetAllItemsRecursive()
        {
            //TODO: expand the asserts..
            var network  = new HydroNetwork();
            var allItems = network.GetAllItemsRecursive().ToArray();

            Assert.AreEqual(new object[] { network, network.CrossSectionSectionTypes[0] }, allItems);
        }
コード例 #14
0
        public void ClonedNetworkIsCollected()
        {
            //issue 5410 openda memory problems
            var          weakReference = new WeakReference(null);
            HydroNetwork network       = GetNetwork();

            for (int i = 0; i < 10; i++)
            {
                weakReference.Target = network.Clone();//create clones that get out of scope
            }
            GC.Collect();
            //test it was collected
            Assert.IsNull(weakReference.Target);
        }
コード例 #15
0
        public void DetectAndUpdateBranchBoundaries()
        {
            var network = new HydroNetwork();

            var branch1 = new Channel();
            var node1   = new HydroNode();
            var node2   = new HydroNode();

            branch1.Source = node1;
            branch1.Target = node2;

            network.Branches.Add(branch1);
            network.Nodes.Add(node1);
            network.Nodes.Add(node2);

            Assert.IsTrue(node1.IsBoundaryNode);
            Assert.IsTrue(node2.IsBoundaryNode);
        }
コード例 #16
0
        public void DetectAndUpdateBranchBoundaries()
        {
            var network = new HydroNetwork();

            var branch1 = new Channel();
            var node1 = new HydroNode();
            var node2 = new HydroNode();

            branch1.Source = node1;
            branch1.Target = node2;

            network.Branches.Add(branch1);
            network.Nodes.Add(node1);
            network.Nodes.Add(node2);

            Assert.IsTrue(node1.IsBoundaryNode);
            Assert.IsTrue(node2.IsBoundaryNode);
        }
コード例 #17
0
        public void CloneHydroNetworkWithCrossSection()
        {
            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);
            NetworkHelper.AddBranchFeatureToBranch(channel, new CrossSection(), 0);

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

            clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1);
        }
コード例 #18
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);
        }
コード例 #19
0
        public void DeletingDefaultCsSharedDefinitionClearsDefault()
        {
            var hydroNetwork = new HydroNetwork();

            var csDef1 = new CrossSectionDefinitionYZ();
            var csDef2 = new CrossSectionDefinitionYZ();
            var csDef3 = new CrossSectionDefinitionYZ();

            hydroNetwork.SharedCrossSectionDefinitions.Add(csDef1);
            hydroNetwork.SharedCrossSectionDefinitions.Add(csDef2);
            hydroNetwork.SharedCrossSectionDefinitions.Add(csDef3);
            hydroNetwork.DefaultCrossSectionDefinition = csDef2;

            Assert.AreSame(csDef2, hydroNetwork.DefaultCrossSectionDefinition);
            hydroNetwork.SharedCrossSectionDefinitions.Remove(csDef1);
            Assert.AreSame(csDef2, hydroNetwork.DefaultCrossSectionDefinition);
            hydroNetwork.SharedCrossSectionDefinitions.Remove(csDef3);
            Assert.AreSame(csDef2, hydroNetwork.DefaultCrossSectionDefinition);
            hydroNetwork.SharedCrossSectionDefinitions.Remove(csDef2);
            Assert.AreSame(null, hydroNetwork.DefaultCrossSectionDefinition);
        }
コード例 #20
0
        public void CloneHydroNetwork()
        {
            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 clonedHydroNetwork = (IHydroNetwork)network.Clone();

            clonedHydroNetwork.GetType().Should().Be.EqualTo(typeof(HydroNetwork));

            clonedHydroNetwork.Branches.Count.Should().Be.EqualTo(1);
            clonedHydroNetwork.Nodes.Count.Should().Be.EqualTo(2);
        }
コード例 #21
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);
        }
コード例 #22
0
        public void CloneNetworkWithManyCrossSectionWithProcessedData()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var network  = new HydroNetwork();
            var fromNode = new Node();
            var toNode   = new Node();
            var branch   = new Channel(fromNode, toNode, 5000);

            network.Nodes.Add(fromNode);
            network.Nodes.Add(toNode);
            network.Branches.Add(branch);

            for (var i = 0.0; i <= 5000; i++)
            {
                var crossSection = new CrossSection {
                    Offset = i
                };
                var processedData = crossSection.ConveyanceData; // makes sure it is created
                branch.BranchFeatures.Add(crossSection);
            }
            stopwatch.Stop();

            log.DebugFormat("It took {0} ms to create network containing 5000 cross-sections", stopwatch.ElapsedMilliseconds);

            stopwatch = new Stopwatch();
            stopwatch.Start();
            var networkClone = network.Clone();

            stopwatch.Stop();

            log.DebugFormat("It took {0} ms to clone network containing 5000 cross-sections", stopwatch.ElapsedMilliseconds);

            stopwatch.ElapsedMilliseconds
            .Should("Clone of network containing many cross-sections with processed data should be reasonable")
            .Be.LessThan(13000);
        }
コード例 #23
0
        public void CloneHydroNetworkWithCrossSection()
        {
            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 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);
        }
コード例 #24
0
ファイル: HydroNetworkTest.cs プロジェクト: lishxi/_SharpMap
        public void CloneHydroNetwork()
        {
            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 clonedHydroNetwork = (IHydroNetwork) network.Clone();
            clonedHydroNetwork.GetType().Should().Be.EqualTo(typeof (HydroNetwork));

            clonedHydroNetwork.Branches.Count.Should().Be.EqualTo(1);
            clonedHydroNetwork.Nodes.Count.Should().Be.EqualTo(2);
        }
コード例 #25
0
ファイル: HydroNetworkTest.cs プロジェクト: lishxi/_SharpMap
        public void CloneHydroNetworkWithCrossSection()
        {
            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);
            NetworkHelper.AddBranchFeatureToBranch(channel, new CrossSection(), 0);

            var clonedHydroNetwork = (IHydroNetwork) network.Clone();
            clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1);
        }
コード例 #26
0
ファイル: HydroNetworkTest.cs プロジェクト: lishxi/_SharpMap
        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);
        }
コード例 #27
0
ファイル: HydroNetworkTest.cs プロジェクト: lishxi/_SharpMap
        public void CloneNetworkWithManyCrossSectionWithProcessedData()
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var network = new HydroNetwork();
            var fromNode = new Node();
            var toNode = new Node();
            var branch = new Channel(fromNode, toNode, 5000);
            network.Nodes.Add(fromNode);
            network.Nodes.Add(toNode);
            network.Branches.Add(branch);

            for (var i = 0.0; i <= 5000; i++)
            {
                var crossSection = new CrossSection { Offset = i };
                var processedData = crossSection.ConveyanceData; // makes sure it is created
                branch.BranchFeatures.Add(crossSection);
            }
            stopwatch.Stop();

            log.DebugFormat("It took {0} ms to create network containing 5000 cross-sections", stopwatch.ElapsedMilliseconds);

            stopwatch = new Stopwatch();
            stopwatch.Start();
            var networkClone = network.Clone();
            stopwatch.Stop();

            log.DebugFormat("It took {0} ms to clone network containing 5000 cross-sections", stopwatch.ElapsedMilliseconds);

            stopwatch.ElapsedMilliseconds
                .Should("Clone of network containing many cross-sections with processed data should be reasonable")
                    .Be.LessThan(13000);
        }
コード例 #28
0
ファイル: HydroNetworkTest.cs プロジェクト: lishxi/_SharpMap
        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);
        }