示例#1
0
 private void calculation()
 {
     for (int go = 0; go < 1; go++)
     {
         for (int node = 0; node < numNode; node++)
         {
             if (nodeType[node] != 0)
             {
                 for (int xyz = 0; xyz <= 2; xyz++)
                 {
                     force[node, xyz] = 0.0;
                 }
             }
         }
         for (int member = 0; member < numMember; member++)
         {
             if (MemberType[member] == 1)
             {
                 double dx = x[thatEnd[member], 0] - x[thisEnd[member], 0];
                 double dy = x[thatEnd[member], 1] - x[thisEnd[member], 1];
                 double dz = x[thatEnd[member], 2] - x[thisEnd[member], 2];
                 for (int xyz = 0; xyz <= 2; xyz++)
                 {
                     force[thisEnd[member], 0] += dx;
                     force[thisEnd[member], 1] += dy;
                     force[thisEnd[member], 2] += dz;
                     force[thatEnd[member], 0] -= dx;
                     force[thatEnd[member], 1] -= dy;
                     force[thatEnd[member], 2] -= dz;
                 }
             }
         }
         for (int node = 0; node < numNode; node++)
         {
             res f = newFunction.Value.Func(x[node, 0], x[node, 1]);
             if (nodeType[node] == 2)
             {
                 double scalarProduct = 0.0;
                 double zDiffMagSq    = 0.0;
                 scalarProduct  += force[node, 0] * f.zDiffX;
                 scalarProduct  += force[node, 1] * f.zDiffY;
                 zDiffMagSq     += f.zDiffX * f.zDiffX + f.zDiffY * f.zDiffY;
                 force[node, 0] -= f.zDiffX * scalarProduct / zDiffMagSq; // This removes component of force perpendicular to the boundary
                 force[node, 1] -= f.zDiffY * scalarProduct / zDiffMagSq; // This removes component of force perpendicular to the boundary
                 force[node, 0] -= f.z * f.zDiffX / zDiffMagSq;           //This moves node to boundary
                 force[node, 1] -= f.z * f.zDiffY / zDiffMagSq;           //This moves node to boundary
             }
             force[node, 2] = 0.0;
             x[node, 2]     = 1.0 * f.z;
         }
         for (int node = 0; node < numNode; node++)
         {
             if (nodeType[node] != 0)
             {
                 for (int xy = 0; xy <= 1; xy++)
                 {
                     velocity[node, xy] = 0.98 * velocity[node, xy] + force[node, xy] / 50.0;
                     x[node, xy]       += velocity[node, xy];
                 }
             }
         }
     }
 }
示例#2
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            List <GH_hill> listHill = new List <GH_hill>();
            int            uMax = 0, vMax = 0;
            double         size = 0.0;

            if (!DA.GetDataList(0, listHill))
            {
                return;
            }
            if (!DA.GetData(1, ref size))
            {
                return;
            }
            if (!DA.GetData(2, ref uMax))
            {
                return;
            }
            if (!DA.GetData(3, ref vMax))
            {
                return;
            }
            double ContourInterval = 0.01 * listHill[0].Value.h;
            double seaLevel        = 30.0 * ContourInterval;

            double c      = size / uMax;
            double otherc = size / vMax;

            if (c > otherc)
            {
                c = otherc;
            }
            double maxX = c * uMax / 2d;
            double maxY = c * vMax / 2d;

            GH_function newFunction = new GH_function();

            newFunction.Value      = new function();
            newFunction.Value.Func = new _function((xValue, yValue) => {
                res f          = new res();
                double z       = -seaLevel;
                double zDiff_X = 0;
                double zDiff_Y = 0;
                double dx      = 0;
                double dy      = 0;
                for (int hill = 0; hill < listHill.Count; hill++)
                {
                    dx = xValue - listHill[hill].Value.x;
                    dy = yValue - listHill[hill].Value.y;
                    double expThingy = listHill[hill].Value.h * Math.Exp(-(dx * dx + dy * dy) / (listHill[hill].Value.size * listHill[hill].Value.size));
                    z       += expThingy;
                    zDiff_X -= dx * expThingy / (listHill[hill].Value.size * listHill[hill].Value.size);
                    zDiff_Y -= dy * expThingy / (listHill[hill].Value.size * listHill[hill].Value.size);
                }
                f.z      = z;
                f.zDiffX = zDiff_X;
                f.zDiffY = zDiff_Y;

                return(f);
            });
            Rhino.Geometry.PointCloud pc = new Rhino.Geometry.PointCloud();

            for (int i = 0; i <= uMax * 4; i++)
            {
                for (int j = 0; j <= vMax * 4; j++)
                {
                    double x = -maxX + (c / 4d) * i;
                    double y = -maxY + (c / 4d) * j;
                    pc.Add(new Rhino.Geometry.Point3d(x, y, newFunction.Value.Func(x, y).z));
                }
            }
            Rhino.Geometry.Plane        plane     = new Rhino.Geometry.Plane(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Vector3d(1.0, 0, 0), new Rhino.Geometry.Vector3d(0.0, 1.0, 0));
            Rhino.Geometry.PlaneSurface planeSurf = new Rhino.Geometry.PlaneSurface(plane, new Rhino.Geometry.Interval(-size / 2d * 1.2d, size / 2d * 1.2d), new Rhino.Geometry.Interval(-size / 2d * 1.2d, size / 2d * 1.2d));
            DA.SetDataList(0, pc.GetPoints().ToList());
            DA.SetData(1, planeSurf);
            newFunction.size            = size;
            newFunction.uMax            = uMax;
            newFunction.vMax            = vMax;
            newFunction.maxX            = maxX;
            newFunction.maxY            = maxY;
            newFunction.c               = c;
            newFunction.seaLevel        = seaLevel;
            newFunction.ContourInterval = ContourInterval;
            newFunction.a               = c * (Math.Sqrt(7.0) - 1.0) / 6.0;
            newFunction.bsin            = c / 4.0;
            newFunction.bcos            = c * (4.0 - Math.Sqrt(7.0)) / 12.0;
            DA.SetData(2, newFunction);
        }