Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                List <GH_Point> pointList = new List <GH_Point>();
                DA.GetDataList(0, pointList);
                bool x = true, y = true, z = true;
                if (!DA.GetData(1, ref x))
                {
                    return;
                }
                if (!DA.GetData(2, ref y))
                {
                    return;
                }
                if (!DA.GetData(3, ref z))
                {
                    return;
                }
                bool isGroup = true;
                if (!DA.GetData(4, ref isGroup))
                {
                    return;
                }
                _nNodes = pointList.Count;
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[_nNodes];
                for (int i = 0; i < _nNodes; i++)
                {
                    particles[i] = new particle(pointList[i].Value.X, pointList[i].Value.Y, pointList[i].Value.Z);
                }
                pS = new GH_particleSystem(particles);
                node[] lNodes = new node[_nNodes];
                for (int i = 0; i < _nNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                if (isGroup)
                {
                    fixedNodes fN = new fixedNodes(x, y, z);

                    for (int i = 0; i < _nNodes; i++)
                    {
                        fN.addNode(lNodes[i]);
                    }
                    pS.Value.addObject(fN);
                }
                else
                {
                    for (int i = 0; i < _nNodes; i++)
                    {
                        fixedNodes fN = new fixedNodes(x, y, z);
                        fN.addNode(lNodes[i]);
                        pS.Value.addObject(fN);
                    }
                }
                lGeometry  = new Rhino.Geometry.Point3d[_nNodes];
                lGeometry2 = new Rhino.Geometry.Point3d[_nNodes];
                for (int i = 0; i < _nNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
                this.DVPW = GetDVPW(lGeometry);
                this.BKGT = GetBKGT(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);
            }
            DA.SetData(0, pS);
        }
Exemplo n.º 3
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            init();
            _listSrf = new List <Surface>();
            _listCrv = new List <Curve>();
            listPnt  = new List <Point3d>();
            List <string> crvTypes   = new List <string>();
            List <string> pntHeights = new List <string>();

            if (!DA.GetDataList(0, _listSrf))
            {
                return;
            }
            if (!DA.GetDataList(1, _listCrv))
            {
                return;
            }
            if (!DA.GetDataList(2, crvTypes))
            {
                return;
            }
            if (!DA.GetDataList(3, listPnt))
            {
                listPnt.Clear();
            }
            if (!DA.GetData(4, ref globalC))
            {
                return;
            }

            if (_listCrv.Count != crvTypes.Count)
            {
                AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "need types for curves"); return;
            }

            listSlice  = new Dictionary <string, slice>();
            listSlice2 = new Dictionary <string, slice2>();
            listLeaf   = new List <leaf>();
            listBranch = new List <branch>();
            listNode   = new List <node>();
            myControlBox.clearSliders();

            for (int i = 0; i < _listCrv.Count; i++)
            {
                var branch = new branch();
                branch.crv     = _listCrv[i] as NurbsCurve;
                branch.N       = branch.crv.Points.Count;
                branch.dom     = branch.crv.Domain;
                branch.Dim     = branch.crv.Order;
                branch.dDim    = branch.crv.Order - 1;
                branch.nElem   = branch.N - branch.dDim;
                branch.scaleT  = (branch.dom.T1 - branch.dom.T0) / branch.nElem;
                branch.originT = branch.dom.T0;
                if (crvTypes[i].StartsWith("reinforce"))
                {
                    branch.branchType = branch.type.reinforce;
                    var key = crvTypes[i].Replace("reinforce", "");
                    branch.sliceKey = key;
                    try{
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    catch (KeyNotFoundException e) {
                        listSlice[key]         = new slice();
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                }
                else if (crvTypes[i].StartsWith("kink"))
                {
                    branch.branchType = branch.type.kink;
                    var    key = crvTypes[i].Replace("kink", "");
                    double lb  = 0.0d;
                    double _lb;
                    bool   res = double.TryParse(key, out _lb);
                    if (res)
                    {
                        lb = _lb;
                    }
                    else
                    {
                        lb = 0.0d;
                    }
                    branch.lb = lb;
                    //int NN;
                    //res = int.TryParse(key, out NN);
                    //if (res) { if (NN == 123) { branch.obj = true; } }
                }
                else if (crvTypes[i].StartsWith("open"))
                {
                    branch.branchType = branch.type.open;
                    var key = crvTypes[i].Replace("open", "");
                    branch.sliceKey = key;
                    try
                    {
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    catch (KeyNotFoundException e)
                    {
                        listSlice[key]         = new slice();
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                }
                else if (crvTypes[i].StartsWith("fix"))
                {
                    branch.branchType = branch.type.fix;
                    var key = crvTypes[i].Replace("fix", "");
                    branch.sliceKey = key;
                    try
                    {
                        branch.slice2 = listSlice2[key];
                    }
                    catch (KeyNotFoundException e)
                    {
                        listSlice2[key] = new slice2();
                        branch.slice2   = listSlice2[key];

                        var slider = myControlBox.addSliderVert(0, 1, 200, 100);
                        slider.Converter = (val) =>
                        {
                            double height = val / 10d - 10d;
                            branch.slice2.height = height;
                            this.ExpirePreview(true);
                            return(height);
                        };
                    }
                }
                else
                {
                    AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "type should be either of reinforce, kink, fix, or open");
                }
                listBranch.Add(branch);
            }

            // Connect nodes
            foreach (var node in listNode)
            {
                node.N = 0;
                node.share.Clear();
                node.number.Clear();
            }
            foreach (var branch in listBranch)
            {
                var  P    = branch.crv.Points[0].Location;
                bool flag = false;
                foreach (var node in listNode)
                {
                    if (node.compare(P))
                    {
                        flag = true;
                        node.N++;
                        node.share.Add(branch);
                        node.number.Add(0);
                        break;
                    }
                }
                if (!flag)
                {
                    var newNode = new node();
                    listNode.Add(newNode);
                    newNode.N++;
                    newNode.share.Add(branch);
                    newNode.number.Add(0);
                    newNode.x = P.X;
                    newNode.y = P.Y;
                    newNode.z = P.Z;
                }
                var Q = branch.crv.Points[branch.N - 1].Location;
                flag = false;
                foreach (var node in listNode)
                {
                    if (node.compare(Q))
                    {
                        flag = true;
                        node.N++;
                        node.share.Add(branch);
                        node.number.Add(branch.N - 1);
                        break;
                    }
                }
                if (!flag)
                {
                    var newNode = new node();
                    listNode.Add(newNode);
                    newNode.N++;
                    newNode.share.Add(branch);
                    newNode.number.Add(branch.N - 1);
                    newNode.x = Q.X;
                    newNode.y = Q.Y;
                    newNode.z = Q.Z;
                }
            }
            for (int i = 0; i < _listSrf.Count; i++)
            {
                var srf  = _listSrf[i];
                var leaf = new leaf();
                listLeaf.Add(leaf);
                leaf.srf     = srf as NurbsSurface;
                leaf.nU      = leaf.srf.Points.CountU;
                leaf.nV      = leaf.srf.Points.CountV;
                leaf.domU    = leaf.srf.Domain(0);
                leaf.domV    = leaf.srf.Domain(1);
                leaf.uDim    = leaf.srf.OrderU;
                leaf.vDim    = leaf.srf.OrderV;
                leaf.uDdim   = leaf.srf.OrderU - 1;
                leaf.vDdim   = leaf.srf.OrderV - 1;
                leaf.nUelem  = leaf.nU - leaf.uDdim;
                leaf.nVelem  = leaf.nV - leaf.vDdim;
                leaf.scaleU  = (leaf.domU.T1 - leaf.domU.T0) / leaf.nUelem;
                leaf.scaleV  = (leaf.domV.T1 - leaf.domV.T0) / leaf.nVelem;
                leaf.originU = leaf.domU.T0;
                leaf.originV = leaf.domV.T0;
                var domainU = leaf.srf.Domain(0);
                var domainV = leaf.srf.Domain(1);
                //Find corresponding curve
                //(0,0)->(1,0)
                var curve = leaf.srf.IsoCurve(0, domainV.T0) as NurbsCurve;
                leaf.flip[0] = findCurve(leaf, ref leaf.branch[0], listBranch, curve);//bottom
                //(1,0)->(1,1)
                curve        = leaf.srf.IsoCurve(1, domainU.T1) as NurbsCurve;
                leaf.flip[1] = findCurve(leaf, ref leaf.branch[1], listBranch, curve);//right
                //(1,1)->(0,1)
                curve        = leaf.srf.IsoCurve(0, domainV.T1) as NurbsCurve;
                leaf.flip[2] = findCurve(leaf, ref leaf.branch[2], listBranch, curve);//top
                //(0,1)->(0,0)
                curve        = leaf.srf.IsoCurve(1, domainU.T0) as NurbsCurve;
                leaf.flip[3] = findCurve(leaf, ref leaf.branch[3], listBranch, curve);//left
            }
            //multiqudric surface
            var A = new Rhino.Geometry.Matrix(listPnt.Count, listPnt.Count);
            var z = new Rhino.Geometry.Matrix(listPnt.Count, 1);

            for (int i = 0; i < listPnt.Count; i++)
            {
                for (int j = 0; j < listPnt.Count; j++)
                {
                    var pi = listPnt[i];
                    var pj = listPnt[j];
                    A[i, j] = quadFunc(pi.X, pj.X, pi.Y, pj.Y);
                    z[i, 0] = pi.Z;
                }
            }
            A.Invert(0.0);  //this parameter should be 0.0
            var c = A * z;

            globalCoeff = new double[listPnt.Count];
            for (int i = 0; i < listPnt.Count; i++)
            {
                globalCoeff[i] = c[i, 0];
            }
            targetSrf  = new List <Point3d>();
            globalFunc = (xi, yi) => {
                double Z = 0;
                for (int j = 0; j < listPnt.Count; j++)
                {
                    Z = Z + globalCoeff[j] * quadFunc(xi, listPnt[j].X, yi, listPnt[j].Y);
                }
                return(Z);
            };
            foreach (var leaf in listLeaf)
            {
                var domU = leaf.domU;
                var domV = leaf.domV;
                for (double i = 0; i <= 1.0; i += 0.05)
                {
                    for (double j = 0; j < 1.0; j += 0.05)
                    {
                        double u = domU[0] + i * (domU[1] - domU[0]);
                        double v = domV[0] + j * (domV[1] - domV[0]);
                        Rhino.Geometry.Point3d    P;
                        Rhino.Geometry.Vector3d[] V;
                        leaf.srf.Evaluate(u, v, 0, out P, out V);
                        var newP = new Rhino.Geometry.Point3d(P.X, P.Y, globalFunc(P.X, P.Y));
                        targetSrf.Add(newP);
                    }
                }
            }
        }
Exemplo n.º 4
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            stw.Stop();
            string dbg = stw.ElapsedMilliseconds.ToString();

            stw.Reset();
            double dist = 0;

            if (!DA.GetData(1, ref dist))
            {
                return;
            }
            if (_go == false)
            {
                t = 0;
                FriedChiken.clear();
                lpS = new List <GH_particleSystem>();

                if (fixedPointsGuids != null)
                {
                    foreach (Guid[] gs in fixedPointsGuids)
                    {
                        foreach (Guid g in gs)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.Delete(g, true);
                        }
                    }
                    fixedPointsGuids = null;
                }

                if (!DA.GetDataList(0, lpS))
                {
                    return;
                }
                particleSystem[] _ps = null;
                _ps = new particleSystem[lpS.Count];
                for (int i = 0; i < lpS.Count; i++)
                {
                    _ps[i] = lpS[i].Value;
                }
                FriedChiken.addParticleSystems(_ps);
                //FriedChiken.begin();
                __dist = dist;
                lS     = new List <Rhino.Geometry.GeometryBase>();
                lPC    = new List <Rhino.Geometry.PointCloud>();

                lfN = new List <NumericalMethodHelper.objects.fixedNodes>();
                fixedPointsGuids = new List <Guid[]>();

                foreach (GH_particleSystem pS in lpS)
                {
                    if (pS != null)
                    {
                        if (pS.UPGR != null)
                        {
                            pS.UPGR(dist, 0, 0);
                        }
                    }
                }
            }
            else
            {
                double dt = full.getDt();
                if (t == 0)
                {
                    output = new List <string>();
                    //firstAction(DA);
                    FriedChiken.clear();
                    lpS = new List <GH_particleSystem>();
                    if (!DA.GetDataList(0, lpS))
                    {
                        return;
                    }
                    particleSystem[] _ps = null;
                    _ps = new particleSystem[lpS.Count];
                    for (int i = 0; i < lpS.Count; i++)
                    {
                        _ps[i] = lpS[i].Value;
                    }
                    FriedChiken.addParticleSystems(_ps);
                    if (fixedPointsGuids != null)
                    {
                        foreach (Guid[] gs in fixedPointsGuids)
                        {
                            foreach (Guid g in gs)
                            {
                                Rhino.RhinoDoc.ActiveDoc.Objects.Delete(g, true);
                            }
                        }
                    }
                    FriedChiken.begin();
                    refX   = DoubleArray.From(FriedChiken.x.rawData);
                    __dist = dist;
                    if (FriedChiken.numCond > 0)
                    {
                        lambda = new vector(FriedChiken.numCond).zeros();
                        dx     = new vector(FriedChiken.q.nElem);
                        qo     = new vector(FriedChiken.q.nElem);
                        qr     = new vector(FriedChiken.numCond).zeros();
                    }
                    lS  = new List <Rhino.Geometry.GeometryBase>();
                    lPC = new List <Rhino.Geometry.PointCloud>();

                    lfN = new List <NumericalMethodHelper.objects.fixedNodes>();
                    fixedPointsGuids = new List <Guid[]>();
                    for (int i = 0; i < FriedChiken.particleSystems.Count; i++)
                    {
                        for (int j = 0; j < FriedChiken.particleSystems[i].objList.Count; j++)
                        {
                            if (FriedChiken.particleSystems[i].objList[j] is mikity.NumericalMethodHelper.objects.fixedNodes)
                            {
                                mikity.NumericalMethodHelper.objects.fixedNodes fN = (mikity.NumericalMethodHelper.objects.fixedNodes)FriedChiken.particleSystems[i].objList[j];
                                lfN.Add(fN);
                                fixedPointsGuids.Add(new Guid[fN.nNodes]);
                                Rhino.Geometry.Point3d[] ps = new Rhino.Geometry.Point3d[fN.nNodes];
                                Guid[] gs = fixedPointsGuids[fixedPointsGuids.Count - 1];

                                for (int k = 0; k < fN.nNodes; k++)
                                {
                                    ps[k] = new Rhino.Geometry.Point3d(fN.nodeList[k].getNodes()[0, 0] + dist, fN.nodeList[k].getNodes()[0, 1], fN.nodeList[k].getNodes()[0, 2]);
                                    gs[k] = Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(ps[k]);
                                }
                                Rhino.RhinoDoc.ActiveDoc.Groups.Add(gs);
                            }
                        }
                    }
                }
                //Computation

                while (stw.ElapsedMilliseconds < 25)
                {
                    stw.Start();
                    FriedChiken.Tick(t); //要素アップデート、勾配の計算
                    FriedChiken.Tack(t); //マスク等後処理
                    if (_IF)
                    {
                        FriedChiken.omega.zeros();
                    }
                    double resid = 0;
                    if (FriedChiken.numCond > 0)
                    {
                        resid = FriedChiken.getResidual().norm;
                        phi();
                    }
                    string tmp = "\t" + t.ToString() + "\t";
                    tmp += FriedChiken.omega.norm.ToString() + "\t";

                    if (_geodesic)
                    {
                        if (FriedChiken.numCond > 0)
                        {
                            varphi();
                        }
                    }
                    var    v     = DoubleArray.From(FriedChiken.q.rawData);
                    double normW = FriedChiken.omega.norm;
                    if (_normalize == true)
                    {
                        if (normW != 0)
                        {
                            FriedChiken.omega.dividedby(normW);//力を正規化
                        }
                        normW = FriedChiken.omega.norm;
                    }
                    var a = DoubleArray.From(FriedChiken.omega.rawData);

                    FriedChiken.omega.MinusTo(FriedChiken.r);//力を加速度に
                    double norm1 = (v * v.T)[0, 0];
                    double norm2 = (v * a.T)[0, 0];
                    double norm3 = (a * a.T)[0, 0];
                    double f     = 0;
                    if (norm1 * norm3 != 0)
                    {
                        f = -norm2 / Math.Sqrt(norm1 * norm3);
                    }
                    else if (norm1 == 0)
                    {
                        f = 1;
                    }
                    else
                    {
                        f = -1;
                    }
                    double damping = 0;
                    if (_drift1)
                    {
                        damping = Drift1(f);
                    }
                    else if (_drift2)
                    {
                        damping = Drift2(f);
                    }
                    else if (_drift3)
                    {
                        damping = Drift3(f);
                    }
                    else
                    {
                        damping = Drift0(f);
                    }
                    //damping = 0;
                    full.move(f);
                    dbg = "damping:" + damping.ToString() + "\n" + "dt:" + dt.ToString() + "\n" + "Step#:" + t.ToString();
                    full.setDbgText(dbg);
                    FriedChiken.q.times(damping).Add(dt, FriedChiken.r);
                    double normQ = FriedChiken.q.norm;
                    double K     = normQ * normQ * 0.5;
                    double P     = FriedChiken.energy;
                    double E     = K + P;
                    int    itr   = 0;
                    FriedChiken.x.Add(dt, FriedChiken.q);
                    if (FriedChiken.numCond > 0)
                    {
                        itr = psi();
                    }
                    full.addNorm(K, E, itr, normW, resid);

                    stw.Stop();
                    t++;
                    if (_RP == false)
                    {
                        break;
                    }
                }
                stw.Reset();

                //////////////
                for (int i = 0; i < lfN.Count; i++)
                {
                    Guid[] gs = fixedPointsGuids[i];
                    for (int j = 0; j < gs.Count(); j++)
                    {
                        Rhino.DocObjects.PointObject obj = (Rhino.DocObjects.PointObject)Rhino.RhinoDoc.ActiveDoc.Objects.Find(gs[j]);
                        Rhino.Geometry.Point3d       p   = new Rhino.Geometry.Point3d(obj.PointGeometry.Location.X, obj.PointGeometry.Location.Y, obj.PointGeometry.Location.Z);
                        if (lfN[i].fixX)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 0] = lfN[i].nodeList[j].getNodes()[0, 0] * 0.95 + (p.X - dist) * 0.05; //*
                            if (dist != __dist)
                            {
                                p.X = p.X + dist - __dist;
                            }
                        }
                        else
                        {
                            p.X = lfN[i].nodeList[j].getNodes()[0, 0] + dist;
                        }
                        if (lfN[i].fixY)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 1] = lfN[i].nodeList[j].getNodes()[0, 1] * 0.95 + p.Y * 0.05;//*
                        }
                        else
                        {
                            p.Y = lfN[i].nodeList[j].getNodes()[0, 1];
                        }
                        if (lfN[i].fixZ)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 2] = lfN[i].nodeList[j].getNodes()[0, 2] * 0.95 + p.Z * 0.05; //*
                        }
                        else
                        {
                            p.Z = lfN[i].nodeList[j].getNodes()[0, 2];
                        }
                        double x = 0, y = 0, z = 0;
                        x = p.X - obj.PointGeometry.Location.X;
                        y = p.Y - obj.PointGeometry.Location.Y;
                        z = p.Z - obj.PointGeometry.Location.Z;

                        Rhino.Geometry.Transform tx = Rhino.Geometry.Transform.Translation(x, y, z);
                        gs[j] = Rhino.RhinoDoc.ActiveDoc.Objects.Transform(gs[j], tx, true);
                    }
                }
                if (dist != __dist)
                {
                    __dist = dist;
                }


                foreach (GH_particleSystem pS in lpS)
                {
                    if (pS != null)
                    {
                        if (pS.UPGR != null)
                        {
                            pS.UPGR(dist, 0, 0);
                        }
                    }
                }
            }

            return;
        }
Exemplo n.º 5
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            double v = -1.0;

            DA.GetData(2, ref v);
            if (!FriedChiken.isInitialized)
            {
                List <GH_Point> pointList1   = new List <GH_Point>();
                List <GH_Point> pointList2   = new List <GH_Point>();
                List <GH_Point> tmpPointList = new List <GH_Point>();
                if (!DA.GetDataList(0, pointList1))
                {
                    return;
                }
                if (!DA.GetDataList(1, pointList2))
                {
                    return;
                }
                if (pointList1.Count != pointList2.Count)
                {
                    AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "The first and second lists must have the same elements");
                    return;
                }
                tmpPointList.AddRange(pointList1);
                tmpPointList.AddRange(pointList2);
                nNewNodes = tmpPointList.Count();
                nElements = pointList1.Count();
                lCV.Clear();
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new particle(tmpPointList[i].Value.X, tmpPointList[i].Value.Y, tmpPointList[i].Value.Z);
                }
                pS = new GH_particleSystem(particles);
                for (int i = 0; i < nElements; i++)
                {
                    lCV.Add(new constrainVolumeObject(v));
                    lCV[i].addElement(new isoparametricElement(i, i + nElements));
                }
                pS.Value.addObjects(lCV.ToArray());
                lGeometry.Clear();
                for (int i = 0; i < nElements; i++)
                {
                    lGeometry.Add(new Rhino.Geometry.Line(pS.Value.particles[i, 0], pS.Value.particles[i, 1], pS.Value.particles[i, 2], pS.Value.particles[i + nElements, 0], pS.Value.particles[i + nElements, 1], pS.Value.particles[i + nElements, 2]));
                }
            }
            else
            {
                if (lCV != null)
                {
                    if (v > 0)
                    {
                        for (int i = 0; i < nElements; i++)
                        {
                            lCV[i].refVolume = v;
                        }
                    }
                }
            }
            this.DVPW = GetDVPW(lGeometry);
            this.BKGT = GetBKGT(lGeometry);
            pS.DVPW   = GetDVPW(lGeometry2);
            pS.UPGR   = GetUPGR(lGeometry2);
            pS.BKGT   = GetBKGT(lGeometry2);
            DA.SetData(0, pS);
        }
Exemplo n.º 6
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                List <GH_Point> pointList1   = new List <GH_Point>();
                List <GH_Point> pointList2   = new List <GH_Point>();
                List <GH_Point> tmpPointList = new List <GH_Point>();

                eM = new generalSpring();
                if (!DA.GetDataList(0, pointList1))
                {
                    return;
                }
                if (!DA.GetDataList(1, pointList2))
                {
                    return;
                }
                if (pointList1.Count != pointList2.Count)
                {
                    AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "The first and second lists must have the same elements");
                    return;
                }
                tmpPointList.AddRange(pointList1);
                tmpPointList.AddRange(pointList2);
                nNewNodes = tmpPointList.Count();
                nElements = pointList1.Count();
                GH_material mat = null;
                GH_gravity  gvt = null;
                if (!DA.GetData(2, ref mat))
                {
                    return;
                }
                if (!DA.GetData(3, ref gvt))
                {
                    return;
                }

                //点群生成
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new particle(tmpPointList[i].Value.X, tmpPointList[i].Value.Y, tmpPointList[i].Value.Z);
                }
                pS = new GH_particleSystem(particles);
                for (int i = 0; i < nElements; i++)
                {
                    eM.addElement(new mikity.NumericalMethodHelper.elements.isoparametricElement(i, i + nElements));
                }
                eM.setMaterial(mat.Value, gvt.Value);
                pS.Value.addObject(eM);
                lGeometry.Clear();
                lGeometry2.Clear();
                for (int i = 0; i < nElements; i++)
                {
                    lGeometry.Add(new Rhino.Geometry.Line(pS.Value.particles[i, 0], pS.Value.particles[i, 1], pS.Value.particles[i, 2], pS.Value.particles[i + nElements, 0], pS.Value.particles[i + nElements, 1], pS.Value.particles[i + nElements, 2]));
                }
            }
            this.DVPW = GetDVPW(lGeometry);
            this.BKGT = GetBKGT(lGeometry);
            pS.DVPW   = GetDVPW(lGeometry2);
            pS.UPGR   = GetUPGR(lGeometry2);
            pS.BKGT   = GetBKGT(lGeometry2);

            DA.SetData(0, pS);
        }
Exemplo n.º 7
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                List <GH_Point> pointList1 = new List <GH_Point>();
                List <GH_Point> pointList2 = new List <GH_Point>();
                if (!DA.GetDataList(0, pointList1))
                {
                    return;
                }
                if (!DA.GetDataList(1, pointList2))
                {
                    return;
                }
                if (pointList1.Count != pointList2.Count)
                {
                    AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "The first and second lists must have the same elements");
                    return;
                }
                int __n = pointList1.Count;
                int nU  = 0;
                if (!DA.GetData(2, ref nU))
                {
                    return;
                }
                List <GH_Point[]> pointLists = new List <GH_Point[]>();
                for (int i = 0; i < __n; i++)
                {
                    pointLists.Add(new GH_Point[nU]);
                }
                bool x = true, y = true, z = true;
                if (!DA.GetData(3, ref x))
                {
                    return;
                }
                if (!DA.GetData(4, ref y))
                {
                    return;
                }
                if (!DA.GetData(5, ref z))
                {
                    return;
                }
                bool isGroup = true;
                if (!DA.GetData(6, ref isGroup))
                {
                    return;
                }
                //点群生成
                double[,] wt = mikity.MathUtil.bicubic(1, new int[1] {
                    nU
                });
                int nNewNodes = wt.GetLength(0);
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes * __n];
                for (int j = 0; j < __n; j++)
                {
                    for (int i = 0; i < nNewNodes; i++)
                    {
                        particles[i + j * nNewNodes]     = new particle(0, 0, 0);
                        particles[i + j * nNewNodes][0] += pointList1[j].Value.X * wt[i, 0];
                        particles[i + j * nNewNodes][1] += pointList1[j].Value.Y * wt[i, 0];
                        particles[i + j * nNewNodes][2] += pointList1[j].Value.Z * wt[i, 0];
                        particles[i + j * nNewNodes][0] += pointList2[j].Value.X * wt[i, 1];
                        particles[i + j * nNewNodes][1] += pointList2[j].Value.Y * wt[i, 1];
                        particles[i + j * nNewNodes][2] += pointList2[j].Value.Z * wt[i, 1];
                    }
                }
                pS = new GH_particleSystem(particles);
                node[] lNodes = new node[__n * nNewNodes];
                for (int i = 0; i < __n * nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                if (isGroup)
                {
                    fixedNodes fN = new fixedNodes(x, y, z);

                    for (int i = 0; i < __n * nNewNodes; i++)
                    {
                        fN.addNode(lNodes[i]);
                    }
                    pS.Value.addObject(fN);
                }
                else
                {
                    for (int i = 0; i < __n; i++)
                    {
                        fixedNodes fN = new fixedNodes(x, y, z);
                        for (int j = 0; j < nNewNodes; j++)
                        {
                            fN.addNode(lNodes[j + nNewNodes * i]);
                        }
                        pS.Value.addObject(fN);
                    }
                }


                if (isGroup)
                {
                }
                else
                {
                }
                lGeometry.Clear();
                lGeometry2.Clear();
                for (int i = 0; i < __n * nNewNodes; i++)
                {
                    lGeometry.Add(new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]));
                }
                this.DVPW = GetDVPW(lGeometry);
                this.BKGT = GetBKGT(lGeometry);
                pS.DVPW   = GetDVPW(lGeometry2);
                pS.UPGR   = GetUPGR(lGeometry2);
                pS.BKGT   = GetBKGT(lGeometry2);
            }
            DA.SetData(0, pS);
        }