Esempio n. 1
0
 public static Project Make(string name, string addr1, string addr2,
                            string city, string state, string zip,
                            string permit, string desgnr, string company, string summary,
                            DateTime crtd, DateTime modfd, Catchments catchments = null)
 {
     return(new Project
     {
         Name = name, Address1 = addr1, Address2 = addr2,
         City = city, State = state, Zip = zip,
         Permit = permit, Designer = desgnr,
         Company = company, Summary = summary,
         CreatedUTC = crtd, ModifiedUTC = modfd,
         Catchments = catchments ?? Catchments.Empty
     });
 }
Esempio n. 2
0
        public void DebugPrint(string Directory)
        {
            //We need to process data for extra output while we have the particles
            {
                foreach (var c in Catchments.Where(ca => ca.EndParticles.Count >= 1))
                {
                    if (c.EndParticles.Count >= 20)
                    {
                        c.ParticleBreakthroughCurves = new List <Tuple <double, double> >();
                        MathNet.Numerics.Statistics.Percentile p = new MathNet.Numerics.Statistics.Percentile(c.EndParticles.Select(pa => pa.TravelTime));
                        for (int i = 1; i < np; i++)
                        {
                            c.ParticleBreakthroughCurves.Add(new Tuple <double, double>(i / np * 100.0, p.Compute(i / np)));
                        }
                        //Also do oxidized breakthrough curves
                        if (c.EndParticles.Count(pp => pp.Registration != 1) >= 20)
                        {
                            c.ParticleBreakthroughCurvesOxidized = new List <Tuple <double, double> >();
                            p = new MathNet.Numerics.Statistics.Percentile(c.EndParticles.Where(pp => pp.Registration != 1).Select(pa => pa.TravelTime));
                            for (int i = 1; i < np; i++)
                            {
                                c.ParticleBreakthroughCurvesOxidized.Add(new Tuple <double, double>(i / np * 100.0, p.Compute(i / np)));
                            }
                        }
                    }
                    DataRow row = DebugData.Rows.Find(c.ID);
                    if (row == null)
                    {
                        row    = DebugData.NewRow();
                        row[0] = c.ID;
                        DebugData.Rows.Add(row);
                    }

                    row["PartCount"]  = c.EndParticles.Count;
                    row["RedoxCount"] = c.EndParticles.Count(pp => pp.Registration == 1);
                    row["RedoxRatio"] = c.EndParticles.Count(pp => pp.Registration == 1) / (double)c.EndParticles.Count;
                    if (c.EndParticles.Count > 0)
                    {
                        row["Drain_to_River"]    = c.EndParticles.Count(pa => pa.SinkType == SinkType.Drain_to_River) / (double)c.EndParticles.Count;
                        row["Drain_to_Boundary"] = c.EndParticles.Count(pa => pa.SinkType == SinkType.Drain_to_Boundary) / (double)c.EndParticles.Count;
                        row["Unsaturated_zone"]  = c.EndParticles.Count(pa => pa.SinkType == SinkType.Unsaturated_zone) / (double)c.EndParticles.Count;
                        row["River"]             = c.EndParticles.Count(pa => pa.SinkType == SinkType.River) / (double)c.EndParticles.Count;
                    }
                    row["PartCount_start"] = c.StartParticles.Count;
                }
            }



            NewMessage("Writing breakthrough curves");

            var selectedCatchments = Catchments.Where(cc => cc.ParticleBreakthroughCurves != null);

            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Path.Combine(Directory, "BC.csv")))
            {
                StringBuilder headline = new StringBuilder();
                headline.Append("ID\tNumber of Particles");

                for (int i = 1; i < np; i++)
                {
                    headline.Append("\t + " + (i / np * 100.0));
                }
                sw.WriteLine(headline);

                foreach (var c in selectedCatchments.Where(cc => cc.ParticleBreakthroughCurves != null))
                {
                    StringBuilder line = new StringBuilder();
                    line.Append(c.ID + "\t" + c.EndParticles.Count);
                    foreach (var pe in c.ParticleBreakthroughCurves)
                    {
                        line.Append("\t" + pe.Item2);
                    }
                    sw.WriteLine(line);
                }
            }

            if (selectedCatchments.Count() > 0)
            {
                using (ShapeWriter sw = new ShapeWriter(Path.Combine(Directory, Name + "_debug.shp"))
                {
                    Projection = MainModel.projection
                })
                {
                    foreach (var bc in selectedCatchments.First().ParticleBreakthroughCurves)
                    {
                        DebugData.Columns.Add(((int)bc.Item1).ToString(), typeof(double));
                    }
                    foreach (var bc in selectedCatchments.First().ParticleBreakthroughCurves)
                    {
                        DebugData.Columns.Add(((int)bc.Item1).ToString() + "Ox", typeof(double));
                    }

                    foreach (var c in selectedCatchments)
                    {
                        GeoRefData gd = new GeoRefData()
                        {
                            Geometry = c.Geometry
                        };
                        var row = DebugData.Rows.Find(c.ID);

                        if (c.ParticleBreakthroughCurves != null)
                        {
                            foreach (var bc in c.ParticleBreakthroughCurves)
                            {
                                row[((int)bc.Item1).ToString()] = bc.Item2;
                            }
                        }

                        if (c.ParticleBreakthroughCurvesOxidized != null)
                        {
                            foreach (var bc in c.ParticleBreakthroughCurvesOxidized)
                            {
                                row[((int)bc.Item1).ToString() + "Ox"] = bc.Item2;
                            }
                        }

                        gd.Data = row;
                        sw.Write(gd);
                    }
                }
            }

            //selectedCatchments = Catchments.Where(cc => cc.EndParticles.Count > 0).ToList();

            //foreach (var c in selectedCatchments)
            //{
            //  DataTable dt = new DataTable();
            //  dt.Columns.Add("Part_Id", typeof(int));
            //  dt.Columns.Add("Sink", typeof(string));
            //  dt.Columns.Add("Reg", typeof(int));

            //  using (ShapeWriter sw = new ShapeWriter(Path.Combine(Directory, c.ID + "_particles.shp")) { Projection = MainModel.projection })
            //  {
            //    foreach (var p in c.EndParticles)
            //    {
            //      var row = dt.NewRow();
            //      row["Part_Id"] = p.ID;
            //      row["Sink"] = p.SinkType.ToString();
            //      row["Reg"] = p.Registration;
            //      sw.Write(new GeoRefData() { Geometry = new XYLine(p.XStart, p.YStart, p.X, p.Y), Data = row });

            //    }
            //  }
            //}
        }
Esempio n. 3
0
 public void SetIsBinding(bool isBndng)
 {
     IsBinding = isBndng;
     Catchments.SetIsBinding(isBndng);
 }
Esempio n. 4
0
        public void Distribute(IEnumerable <Particle> Particles)
        {
            //Get the bounding box immediately
            double xmin = double.MaxValue;
            double xmax = double.MinValue;
            double ymin = double.MaxValue;
            double ymax = double.MinValue;

            foreach (var p in Particles)
            {
                //Get min-max coordinates from both start and end
                xmin = Math.Min(Math.Min(xmin, p.X), p.XStart);
                xmax = Math.Max(Math.Max(xmax, p.X), p.XStart);
                ymin = Math.Min(Math.Min(ymin, p.Y), p.YStart);
                ymax = Math.Max(Math.Max(ymax, p.Y), p.YStart);
            }
            var Boundingbox = Geometry.XYGeometryTools.Box(xmin, xmax, ymin, ymax);

            NewMessage("Distributing " + Particles.Count() + " particles on catchments");
            //Only test the catchments that overlaps the particles.
            var selectedCatchments = Catchments.Where(c => c.Geometry.OverLaps(Boundingbox)).ToArray();

            int noend   = EndNotFound.Count;
            int nostart = StartNotFound.Count;

            Parallel.ForEach(Particles,
                             (p) =>
            {
                bool endfound   = false;
                bool startfound = false;
                foreach (var c in selectedCatchments)
                {
                    if (c.Geometry.Contains(p.X, p.Y))
                    {
                        lock (Lock)
                            c.EndParticles.Add(p);
                        endfound = true;
                        if (c.Geometry.Contains(p.XStart, p.YStart))
                        {
                            lock (Lock)
                                c.StartParticles.Add(p);
                            startfound = true;
                        }
                        break;
                    }
                }
                if (!startfound)
                {
                    foreach (var innerc in selectedCatchments)
                    {
                        if (innerc.Geometry.Contains(p.XStart, p.YStart))
                        {
                            lock (Lock)
                                innerc.StartParticles.Add(p);
                            startfound = true;
                            break;
                        }
                    }
                }
                if (!startfound)
                {
                    lock (Lock)
                        StartNotFound.Add(p);
                }
                if (!endfound)
                {
                    lock (Lock)
                        EndNotFound.Add(p);
                }
            });

            NewMessage((EndNotFound.Count - noend) + " endpoints could not be found in the catchments");
            NewMessage((StartNotFound.Count - nostart) + " endpoints could not be found in the catchments");
        }