示例#1
0
        public void Sph2DTest()
        {
            var    part = new List <IsotropicGasParticle>();
            double hmax = 0.499;
            double shagX = 0.25, shagY = 0.25;

            for (int i = 0; i < 30; i++)
            {
                for (int j = 0; j < 20; j++)
                {
                    var p = new IsotropicGasParticle(0.1, hmax);
                    p.X = i * shagX;
                    p.Y = j * shagY;
                    // p.Name = $"p{i * j}";
                    part.Add(p);
                }
            }
            var wall = new List <IsotropicGasParticle>();

            for (int i = 0; i < 30; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    var p = new IsotropicGasParticle(0.1, hmax);
                    p.X = i * shagX;
                    p.Y = -shagY - j * shagY;
                    // p.Name = $"w{i * j}";
                    wall.Add(p);
                }
            }


            var sph = new Sph2D(part, wall);
            var v0  = sph.Rebuild();

            sph.FillCells();
            sph.FillNeibs();

            var maxNeibs = sph.AllParticles.Max(p => p.Neibs.Where(n => p.GetDistTo(n) < hmax).Count());
            var minNeibs = sph.AllParticles.Min(p => p.Neibs.Where(n => p.GetDistTo(n) < hmax).Count());
            var gr       = from p in sph.AllParticles
                           group p by p.Neibs.Where(n => p.GetDistTo(n) < hmax).Count() into groups
                           select new {
                groups.Key,
                N = groups.Count()
            };
            var dict = gr.ToDictionary(g => g.Key);

            Assert.AreEqual(8 + 1, maxNeibs);
            Assert.AreEqual(3 + 1, minNeibs);
        }
示例#2
0
        public void SaveToDictLoadFromDictTest()
        {
            int    N = 200;
            double L = 0.1, shag = L / N, xL = 0.5 * L;
            double d = L / N, hmax = 1.4 * 2 * d;
            double P1 = 3E4, P2 = 1E4;
            double Ro1 = 1500, Ro2 = 1200;
            double k1 = 3, k2 = 3;

            var particles = new List <IsotropicGasParticle>(N);

            for (int i = 0; i < N; i++)
            {
                double x = i * shag;
                particles.Add(new IsotropicGasParticle(d, hmax)
                {
                    X      = x,
                    P      = x < xL ? P1 : P2,
                    Ro     = x < xL ? Ro1 : Ro2,
                    k      = x < xL ? k1 : k2,
                    isWall = x <hmax * 2 || x> (L - 2 * hmax)
                });
            }


            for (int i = 0; i < 1; i++)
            {
                particles.ForEach(p => {
                    p.M = p.Ro * Math.Pow(p.D, 1);
                });

                particles.ForEach(p => {
                    p.Ro = particles.Sum(n => IsotropicGasParticle.W_func(n.GetDistTo(p), p.alpha * (p.D + n.D) * 0.5) * n.M);
                    p.E  = p.P / ((p.k - 1d) * p.Ro);
                });
            }
            var masses = particles.Select(p => p.M).ToArray();
            var sph    = new Sph2D(particles, null);

            var dict = sph.SaveToDict();


            var particles_zero = new List <IsotropicGasParticle>(N);

            for (int i = 0; i < N; i++)
            {
                double x = i * shag;
                particles_zero.Add(new IsotropicGasParticle(d, hmax)
                {
                    X      = 0,
                    P      = 0,
                    Ro     = 0,
                    k      = 0,
                    isWall = x <hmax * 2 || x> (L - 2 * hmax)
                });
            }

            var sph_zero = new Sph2D(particles_zero, null);

            sph_zero.LoadFromDict(dict);

            var dictLoaded = sph_zero.SaveToDict();

            foreach (var elem0 in dict)
            {
                Assert.IsTrue(dictLoaded.ContainsKey(elem0.Key));
                Assert.AreEqual(elem0.Value, dictLoaded[elem0.Key]);
            }
        }