public void ConstructorTest()
    {
      NWK11File file = new NWK11File();

      var b = file.MIKE_11_Network_editor.BRANCHES.AddBranch();

      //b.definitions.Par1 = "AFLOEB_FRA_SOKLAND";
      //b.definitions.Par2 = "NOVANA_MODEL";
      //b.definitions.Par3 = 0;
      //b.definitions.Par4 = 2824;
      //b.definitions.Par5 = 0;
      //b.definitions.Par6 = 1000;
      //b.definitions.Par7 = 3;


      b.points.AddValue(1);
      b.points.AddValue(2);
      b.points.AddValue(3);
      b.points.AddValue(4);
      b.points.AddValue(5);


      file.FileName = @"..\..\..\PFS\unittest\TestData\Empty.nwk11";
      file.Save();


    }
Beispiel #2
0
    public void Load(string NWK11FileName)
    {
      nwkfile = new NWK11File(NWK11FileName);

      SortedDictionary<int, point> Points = new SortedDictionary<int, point>();
      foreach (var p in nwkfile.MIKE_11_Network_editor.POINTS.points)
      {
        Points.Add(p.Par1, p);
      }

      foreach (var b in nwkfile.MIKE_11_Network_editor.BRANCHES.branchs)
      {
        branches.Add(new M11Branch(b, Points));
        _branchsort.Add(branches.Last().ID, branches.Last());
      }

      foreach (var b in branches)
      {
        if (!b.IsEndPoint)
        {
          b.DownstreamBranch = branches.FirstOrDefault(br => br.Name == b.DownStreamConnection.Branchname & br.ChainageEnd >= b.DownStreamConnection.StartChainage & br.ChainageStart <= b.DownStreamConnection.StartChainage);
          if (b.DownstreamBranch != null)
            _branchsort[b.DownstreamBranch.ID].UpstreamBranches.Add(b);
        }
      }
    }
    public void SaveTest()
    {
      string SheFileName = @"..\..\..\PFS\unittest\TestData\novomr6.nwk11"; // TODO: Initialize to an appropriate value
      NWK11File target = new NWK11File(SheFileName); // TODO: Initialize to an appropriate value

      Assert.AreEqual(581119.81, target.MIKE_11_Network_editor.POINTS.points.First(p=>p.Par1 ==1700).Par2);

      Assert.IsTrue( target.MIKE_11_Network_editor.COMPUTATIONAL_SETUP.SaveAllGridPoints);
      Assert.AreEqual("BIRKMOSE_BAEK", target.MIKE_11_Network_editor.BRANCHES.branchs[9].definitions.Par1);

//      Assert.AreEqual(7024, target.MIKE_11_Network_editor.BRANCHES.branchs[4].ComputationalPoints[5].Chainage);

      Assert.AreEqual(0.000101257, target.MIKE_11_Network_editor.MIKESHECOUPLING.MikeSheCouplings[0].Par5);

      Assert.AreEqual(9313, target.MIKE_11_Network_editor.MIKESHECOUPLING.MikeSheCouplings[3].Par3);
      Assert.AreEqual(-7462, target.MIKE_11_Network_editor.MIKESHECOUPLING.MikeSheCouplings[4].Par2);
      Assert.AreEqual("BAEKKEN", target.MIKE_11_Network_editor.MIKESHECOUPLING.MikeSheCouplings[5].Par1);

      Assert.AreEqual(143, target.MIKE_11_Network_editor.MIKESHECOUPLING.MikeSheCouplings.Count);

      target.SaveAs(@"..\..\..\PFS\unittest\TestData\novomr6_new.nwk11");
    }
Beispiel #4
0
    public void SaveToMike11(string m11name)
    {
      NWK11File nwk = new NWK11File();

      double x0 = double.MaxValue;
      double x1 = double.MinValue;
      double y0 = double.MaxValue;
      double y1 = double.MinValue;

      int pointcount =1;

      //This is necessary because it fails if DHI.CrossSection.Dll tries to load UFS.dll
      DFS0 d = new DFS0(@"v");
      d.Dispose();



      CrossSectionCollection csc = new CrossSectionCollection();
      csc.Connection.FilePath = Path.ChangeExtension(m11name, ".xns11");
      csc.Connection.Bridge = csc.Connection.AvailableBridges[0];


      foreach (var b in Branches)
      {
        var newbranch = nwk.MIKE_11_Network_editor.BRANCHES.AddBranch();
        newbranch.definitions.Par1 = b.Name;

        double lastchainage = 0;
        for (int i = 0; i < b.Links.Count; i++)
        {
          var bp = nwk.MIKE_11_Network_editor.POINTS.AddPoint();
          bp.Par1 = pointcount;
          bp.Par2 = b.Links[i].UpstreamNode.Location.X;
          bp.Par3 = b.Links[i].UpstreamNode.Location.Y;

          x0 = Math.Min(b.Links[i].UpstreamNode.Location.X, x0);
          x1 = Math.Max(b.Links[i].UpstreamNode.Location.X, x1);
          y0 = Math.Min(b.Links[i].UpstreamNode.Location.Y, y0);
          y1 = Math.Max(b.Links[i].UpstreamNode.Location.Y, y1);

          if (i == 0)
          {
            bp.Par4 = 1;
          }
          else
          {
            bp.Par4 = 0;
            lastchainage += b.Links[i - 1].Length;
          }
          bp.Par5 = lastchainage;
          newbranch.points.AddValue(pointcount);


          //CrossSections

          CrossSection cs = new CrossSection(new DHI.Generic.RouteLocation(b.Name, "Topo-id", lastchainage, b.Links[i].pfslink.Par5));
          if (b.Links[i].Xsec != null && b.Links[i].Xsec.TypeNo == 4)
          {
            double bottom = double.MaxValue;
            int bottomindex = 0;
            int index = 0;
            foreach (var dat in b.Links[i].Xsec.Datas)
            {
              var z = dat.GetValue(1);
              if (z < bottom)
              {
                bottom = z;
                bottomindex = index;
              }
              cs.Points.AddPoint(new CrossSectionPoint(dat.GetValue(0), z));
              index++;
            }

            if (bottom == 0)
              cs.Datum = b.Links[i].UpstreamNode.pfsnode.InvertLevel;

            cs.Points.SetMarkerAt(1, 0);
            cs.Points.SetMarkerAt(3, b.Links[i].Xsec.Datas.Count - 1);
            cs.Points.SetMarkerAt(2, bottomindex);
            csc.Add(cs);
          }
          else if (b.Links[i].pfslink.Par4 == 1) //Assume circular
          {
            cs.Geometry = DHI.Mike1D.CrossSections.Geometry.ClosedCircular;
            cs.SetDiameter(b.Links[i].pfslink.Par7);
            cs.Datum = b.Links[i].UpstreamNode.pfsnode.InvertLevel;
            csc.Add(cs);
          }

          if (i == b.Links.Count - 1)
          {
            lastchainage += b.Links[i].Length;

            var connectionlink = b.Links[i].DownstreamNode.Links.FirstOrDefault(l => l.UpstreamNode == b.Links[i].DownstreamNode);
            if (connectionlink != null) //Create a connection
            {
              var branch = Branches.Single(br => br.Links.Contains(connectionlink));
              newbranch.connections.Par3 = branch.Name;
              newbranch.connections.Par4 = branch.GetChainage(connectionlink);
            }
            pointcount++;
            var bpn = nwk.MIKE_11_Network_editor.POINTS.AddPoint();
            bpn.Par1 = pointcount;
            bpn.Par2 = b.Links[i].DownstreamNode.Location.X;
            bpn.Par3 = b.Links[i].DownstreamNode.Location.Y;
            bpn.Par4 = 0;
            bpn.Par5 = lastchainage;
            newbranch.points.AddValue(pointcount);
          }
          pointcount++;
        }
        newbranch.definitions.Par3 = 0;
        newbranch.definitions.Par4 = (int) lastchainage;
        newbranch.definitions.Par6 = 1000;
        newbranch.definitions.Par7 = 3;
      }

      nwk.MIKE_11_Network_editor.DATA_AREA.x0 =(int) (x0- 0.1* (x1-x0));
      nwk.MIKE_11_Network_editor.DATA_AREA.x1 = (int)(x1 + 0.1 * (x1 - x0));
      nwk.MIKE_11_Network_editor.DATA_AREA.y0 = (int)(y0 - 0.1 * (y1 - y0));
      nwk.MIKE_11_Network_editor.DATA_AREA.y1 = (int)(y1 + 0.1 * (y1 - y0));

      nwk.FileName = m11name;
      nwk.Save();
      csc.Connection.Save();


    }