Exemplo n.º 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---variables---

            int          surfNo   = 0;
            Vector3d     forceVec = new Vector3d();
            BrepGeometry brp      = new BrepGeometry();
            MeshGeometry mesh     = new MeshGeometry();

            //---input---

            if (!DA.GetData(0, ref surfNo))
            {
                return;
            }
            if (!DA.GetData(1, ref forceVec))
            {
                return;
            }
            if (!DA.GetData(2, ref mesh))
            {
                return;
            }

            //---solve---

            brp = mesh.GetBrep();
            Brep        surface = mesh.GetSurfaceAsBrep(surfNo);
            double      area    = surface.GetArea();
            List <Node> nodes   = mesh.GetNodeList();

            (List <string> pointLoads, double maxLoad) = FindPointLoads(surfNo, area, forceVec, nodes, brp);

            // For previewing of loads

            double      refLength = brp.GetRefLength();
            List <Line> arrows    = DrawLoads(pointLoads, refLength, maxLoad);
            Color       color     = Color.FromArgb(135, 206, 255);

            //---output---

            DA.SetDataList(0, pointLoads);
            DA.SetDataList(1, arrows);
            DA.SetData(2, color);
        }
Exemplo n.º 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---variables---

            int          surfNo    = 0;
            string       restrains = "0,0,0";
            MeshGeometry mesh      = new MeshGeometry();

            //---input---

            if (!DA.GetData(0, ref surfNo))
            {
                return;
            }
            if (!DA.GetData(1, ref mesh))
            {
                return;
            }

            BrepGeometry brp   = mesh.GetBrep();
            List <Node>  nodes = mesh.GetNodeList();

            //---solve---

            List <string> pointsBC = FindBCPoints(surfNo, restrains, nodes);

            //For previewing of bc
            double      refLength = brp.GetRefLength();
            List <Brep> cones     = DrawBC(pointsBC, refLength);
            Color       color     = Color.FromArgb(0, 100, 255);

            //---output---

            DA.SetDataList(0, pointsBC);
            DA.SetDataList(1, cones);
            DA.SetData(2, color);
        }
Exemplo n.º 3
0
 public void SetBrep(BrepGeometry _brp)
 {
     brp = _brp;
 }
Exemplo n.º 4
0
        public (List <string>, double) FindPointLoads(int surfNo, double area, Vector3d forceVec, List <Node> nodes, BrepGeometry brp)
        {
            List <string> pointLoads         = new List <string>();
            Vector3d      maxLoads           = new Vector3d(0, 0, 0);
            double        maxLoad            = 0;
            List <string> centerPointsString = new List <string>();
            List <string> cornerPointsString = new List <string>();
            List <string> edgePointsString   = new List <string>();

            forceVec = forceVec * area;
            for (int i = 0; i < nodes.Count; i++)
            {
                if (nodes[i].GetSurfaceNum().Contains(surfNo))

                {
                    nodes[i].SetRemovable(false);
                    if (nodes[i].GetIsMiddle())
                    {
                        Point3d node        = nodes[i].GetCoord();
                        string  pointString = node.X.ToString() + "," + node.Y.ToString() + "," + node.Z.ToString();
                        centerPointsString.Add(pointString);
                    }
                    else if (nodes[i].GetIsCorner())
                    {
                        Point3d node        = nodes[i].GetCoord();
                        string  pointString = node.X.ToString() + "," + node.Y.ToString() + "," + node.Z.ToString();
                        cornerPointsString.Add(pointString);
                    }
                    else if (nodes[i].GetIsEdge())
                    {
                        Point3d node        = nodes[i].GetCoord();
                        string  pointString = node.X.ToString() + "," + node.Y.ToString() + "," + node.Z.ToString();
                        edgePointsString.Add(pointString);
                    }
                }
            }
            double pointsCount = 4 * centerPointsString.Count + cornerPointsString.Count + 2 * edgePointsString.Count;

            List <string> centerPointLoads = new List <string>();
            List <string> cornerPointLoads = new List <string>();
            List <string> edgePointLoads   = new List <string>();
            string        centerVector     = 4 * (forceVec.X) / pointsCount + "," + 4 * (forceVec.Y) / pointsCount + "," + 4 * (forceVec.Z) / pointsCount;
            string        cornerVector     = (forceVec.X) / pointsCount + "," + (forceVec.Y) / pointsCount + "," + (forceVec.Z) / pointsCount;
            string        edgeVector       = 2 * (forceVec.X) / pointsCount + "," + 2 * (forceVec.Y) / pointsCount + "," + 2 * (forceVec.Z) / pointsCount;

            foreach (string s in centerPointsString)
            {
                centerPointLoads.Add(s + ";" + centerVector);

                string[] centerLoads = (centerVector.Split(','));

                double   loadX = Math.Round(double.Parse(centerLoads[0]), 8);
                double   loadY = Math.Round(double.Parse(centerLoads[1]), 8);
                double   loadZ = Math.Round(double.Parse(centerLoads[2]), 8);
                Vector3d loads = new Vector3d(loadX, loadY, loadZ);

                if (loads.Length > maxLoads.Length)
                {
                    maxLoads = loads;
                    maxLoad  = Math.Abs(maxLoads.MaximumCoordinate);
                }
            }

            foreach (string s in cornerPointsString)
            {
                cornerPointLoads.Add(s + ";" + cornerVector);
            }
            foreach (string s in edgePointsString)
            {
                edgePointLoads.Add(s + ";" + edgeVector);
            }

            pointLoads.AddRange(centerPointLoads);
            pointLoads.AddRange(edgePointLoads);
            pointLoads.AddRange(cornerPointLoads);

            return(pointLoads, maxLoad);
        }
Exemplo n.º 5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---variables---

            MeshGeometry             mesh       = new MeshGeometry();
            GH_Structure <GH_Number> treeStress = new GH_Structure <GH_Number>();
            int    dir   = new int();
            double scale = new double();


            //---input---

            if (!DA.GetData(0, ref mesh))
            {
                return;
            }
            if (!DA.GetDataTree(1, out treeStress))
            {
                return;
            }
            if (!DA.GetData(2, ref dir))
            {
                return;
            }
            if (!DA.GetData(3, ref scale))
            {
                return;
            }

            //---setup---

            BrepGeometry brp       = mesh.GetBrep();
            Brep         brep      = brp.GetBrep();
            Point3d      centroid  = brp.GetCentroid();
            double       refLength = brp.GetRefLength();
            Point3d      center    = Point3d.Add(centroid, new Point3d(0, -refLength * 6.5, 0));
            double       angle     = 90 * Math.PI / 180;

            //---solve---

            List <Element> elements = mesh.GetElements();
            List <Node>    nodes    = mesh.GetNodeList();

            List <Brep> breps = CreateDefBreps(elements, scale, angle, center);

            //Getting colors for each brep
            (List <Color> brepColors, List <string> rangeValues) = ColorBreps(elements, breps, dir);

            //Creating breps stress legend
            List <Brep> brepRanges = CreateBrepRanges(centroid, refLength, center, angle);

            //Getting colors stress legend
            List <Color> colorRange = CreateColorRange(); //Output brep colors legend

            (List <Plane> planeRanges, double textSize) = CreateTextPlanes(brepRanges, refLength);

            List <double> textSizeRange  = Enumerable.Repeat(textSize, rangeValues.Count).ToList();    //Output text legend size
            List <Color>  textColorRange = Enumerable.Repeat(Color.White, rangeValues.Count).ToList(); // Output text color legend

            //Createing headline for area
            var tuple3 = CreateHeadline(centroid, angle, center, refLength);

            string headText  = tuple3.Item1;
            double headSize  = tuple3.Item2;
            Plane  headPlane = tuple3.Item3;
            Color  headColor = tuple3.Item4;

            //Adding the different text components together to one output.

            rangeValues.Add(headText);
            List <string> text = rangeValues;

            textSizeRange.Add(headSize);
            List <double> textSizes = textSizeRange;

            planeRanges.Add(headPlane);
            List <Plane> textPlanes = planeRanges;

            textColorRange.Add(headColor);
            List <Color> textColors = textColorRange;

            //---output---

            DA.SetDataList(0, breps);
            DA.SetDataList(1, brepColors);
            DA.SetDataList(2, brepRanges);
            DA.SetDataList(3, colorRange);
            DA.SetDataList(4, text);
            DA.SetDataList(5, textSizes);
            DA.SetDataList(6, textPlanes);
            DA.SetDataList(7, textColors);
        }
Exemplo n.º 6
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---variables---

            MeshGeometry             mesh    = new MeshGeometry();
            GH_Structure <GH_Number> treeDef = new GH_Structure <GH_Number>();
            double scale = 1;

            //---input---

            if (!DA.GetData(0, ref mesh))
            {
                return;
            }
            if (!DA.GetDataTree(1, out treeDef))
            {
                return;
            }
            if (!DA.GetData(2, ref scale))
            {
                return;
            }

            //---setup---

            List <Brep>  breps     = new List <Brep>();
            BrepGeometry brp       = mesh.GetBrep();
            Brep         brep      = brp.GetBrep();
            Point3d      centroid  = brp.GetCentroid();
            double       refLength = brp.GetRefLength();
            double       refSize   = (double)(refLength / 10);
            double       angle     = 270 * Math.PI / 180;
            Point3d      center    = Point3d.Add(centroid, new Point3d(0, -refLength * 6.5, 0)); //Center for viewpoint

            //---solve---

            List <Element> elements = mesh.GetElements();
            List <Node>    nodes    = mesh.GetNodeList();

            breps = CreateDefBreps(elements, scale, angle, center);

            //Finding point with max deformation
            (double defMax, Node nodeMax) = GetMaxDeformation(nodes);

            Brep  sphere      = DrawSphere(nodeMax, angle, center, scale, refSize);
            Color colorSphere = Color.Orange;

            VolumeMassProperties vmpt = VolumeMassProperties.Compute(sphere);
            Point3d centroidt         = vmpt.Centroid;

            //Creating text for displaying it for max value
            var    tuple2       = CreateText(defMax, nodeMax, scale, refSize, angle, center);
            string textDef      = tuple2.Item1;
            double textDefSize  = tuple2.Item2;
            Plane  textDefPlane = tuple2.Item3;
            Color  textDefColor = tuple2.Item4;

            //Createing headline for area
            var tuple3 = CreateHeadline(centroid, angle, center, refLength);

            string headText  = tuple3.Item1;
            double headSize  = tuple3.Item2;
            Plane  headPlane = tuple3.Item3;
            Color  headColor = tuple3.Item4;

            //Adding geometry together for output
            List <Color> brepColors = AssignColors(breps);

            breps.Add(sphere);
            List <Brep> geoBreps = breps;

            brepColors.Add(colorSphere);
            List <Color> geoColor = brepColors;

            Curve[] lines      = DrawOuterCurves(brep, angle, center);
            Color   linesColor = Color.White;

            //Adding the different text components together to one output.

            List <string> text = new List <String>
            {
                textDef,
                headText,
            };

            List <double> textSizes = new List <double>
            {
                textDefSize,
                headSize,
            };

            List <Plane> textPlanes = new List <Plane>
            {
                textDefPlane,
                headPlane,
            };

            List <Color> textColors = new List <Color>
            {
                textDefColor,
                headColor,
            };

            //---output---

            //Geometry
            DA.SetDataList(0, geoBreps);
            DA.SetDataList(1, geoColor);
            DA.SetDataList(2, lines);
            DA.SetData(3, linesColor);
            DA.SetDataList(4, text);
            DA.SetDataList(5, textSizes);
            DA.SetDataList(6, textPlanes);
            DA.SetDataList(7, textColors);
        }