Example #1
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        //The List<string> in the methods below can be changed to a list of any type of identification more suitable for the toolkit
        //If no ids are provided, the convention is to return all elements of the type

        private List <FEMesh> ReadMesh(List <int> ids = null)
        {
            // Just reading mesh without properties. Use all nodes.
            int uID = 1;
            int err = 0;
            int numberPlateElements = 0;

            err = St7.St7GetTotal(uID, St7.tyPLATE, ref numberPlateElements);
            if (!St7ErrorCustom(err, "Could not get total number of plate elements."))
            {
                return(null);
            }
            List <Node>             nodes      = ReadNodes();
            List <ISurfaceProperty> plateProps = ReadSurfaceProperty();

            if (ids == null || ids.Count == 0)
            {
                ids = Enumerable.Range(1, numberPlateElements).ToList();
            }
            FEMesh[] meshes = new FEMesh[plateProps.Count];
            Dictionary <int, int> platePropsNumbers = new Dictionary <int, int>();

            for (int i = 0; i < plateProps.Count; i++)
            {
                platePropsNumbers.Add(GetAdapterId <int>(plateProps[i]), i);
                meshes[i]          = new FEMesh();
                meshes[i].Nodes    = nodes;
                meshes[i].Property = plateProps[i];
                meshes[i].Name     = plateProps[i].Name;
                SetAdapterId(meshes[i], i);
            }
            foreach (int id in ids)
            {
                int platePropNum = 0;
                err = St7.St7GetElementProperty(uID, St7.ptPLATEPROP, id, ref platePropNum);
                int        propIndex = platePropsNumbers[platePropNum];
                FEMeshFace face      = new FEMeshFace();
                SetAdapterId(face, id);
                int[] plateConnection = new int[St7.kMaxElementNode + 1];
                err = St7.St7GetElementConnection(uID, St7.tyPLATE, id, plateConnection);
                if (plateConnection[0] == 3 || plateConnection[0] == 6) // Plate elements Tri3 and Tri6. Firt index is a number of vertices
                {
                    face.NodeListIndices = new int[] { plateConnection[1] - 1, plateConnection[2] - 1, plateConnection[3] - 1 }.ToList();
                }
                else // All quad elements
                {
                    face.NodeListIndices = new int[] { plateConnection[1] - 1, plateConnection[2] - 1, plateConnection[3] - 1, plateConnection[4] - 1 }.ToList();
                }
                meshes[propIndex].Faces.Add(face);
            }
            return(meshes.ToList());
        }
Example #2
0
        public static GetMeshOut St7ReadMesh(bool clean = true, bool active = false)
        {
            if (!active)
            {
                return(null);
            }
            int err = 0;
            // Just reading mesh without properties
            List <Point> points     = new List <Point>();
            int          pointCount = 0;

            double[] XYZ = new double[3];
            err = St7.St7GetTotal(1, St7.tyNODE, ref pointCount);
            if (!St7Error(err))
            {
                return(null);
            }
            for (int nn = 0; nn < pointCount; nn++)
            {
                int nodeId = nn + 1;
                err = St7.St7GetNodeXYZ(1, nodeId, XYZ);
                points.Add(Geometry.Create.Point(XYZ[0], XYZ[1], XYZ[2]));
            }
            Dictionary <int, int> indicesUsed = new Dictionary <int, int>();
            int numberPlateElements           = 0;

            err = St7.St7GetTotal(1, St7.tyPLATE, ref numberPlateElements);
            if (!St7ErrorCustom(err, "Could not get total number of plate elements."))
            {
                return(null);
            }
            List <int> ids = new List <int>();

            if (ids == null || ids.Count == 0)
            {
                ids = Enumerable.Range(1, numberPlateElements).ToList();
            }
            Mesh mesh = new Mesh();

            int fcA = 0;
            int fcB = 0;
            int fcC = 0;
            int fcD = 0;

            foreach (int id in ids)
            {
                Face  face            = new Face();
                int[] plateConnection = new int[St7.kMaxElementNode + 1];
                err = St7.St7GetElementConnection(1, St7.tyPLATE, id, plateConnection);
                if (plateConnection[0] == 3 || plateConnection[0] == 6) // Plate elements Tri3 and Tri6. Firt index is a number of vertices
                {
                    fcA    = plateConnection[1] - 1;
                    fcB    = plateConnection[2] - 1;
                    fcC    = plateConnection[3] - 1;
                    face.A = clean ? AddItemToListAndReturnIndex(indicesUsed, fcA) : fcA;
                    face.B = clean ? AddItemToListAndReturnIndex(indicesUsed, fcB) : fcB;
                    face.C = clean ? AddItemToListAndReturnIndex(indicesUsed, fcC) : fcC;
                }
                else // All quad elements
                {
                    fcA    = plateConnection[1] - 1;
                    fcB    = plateConnection[2] - 1;
                    fcC    = plateConnection[3] - 1;
                    fcD    = plateConnection[4] - 1;
                    face.A = clean ? AddItemToListAndReturnIndex(indicesUsed, fcA) : fcA;
                    face.B = clean ? AddItemToListAndReturnIndex(indicesUsed, fcB) : fcB;
                    face.C = clean ? AddItemToListAndReturnIndex(indicesUsed, fcC) : fcC;
                    face.D = clean ? AddItemToListAndReturnIndex(indicesUsed, fcD) : fcD;
                }
                mesh.Faces.Add(face);
            }
            // creating a list of used Vertices
            if (clean)
            {
                mesh.Vertices = indicesUsed.Select(x => points[x.Key]).ToList();
                return(new GetMeshOut(true, mesh, indicesUsed.Select(x => x.Key).ToList()));
            }
            mesh.Vertices = points;
            return(new GetMeshOut(true, mesh, Enumerable.Range(0, pointCount).ToList()));
        }
Example #3
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        //The List<string> in the methods below can be changed to a list of any type of identification more suitable for the toolkit
        //If no ids are provided, the convention is to return all elements of the type

        private List <Panel> ReadPanel(List <int> ids = null)
        {
            // Just reading mesh without properties. Use all nodes.
            int uID = 1;
            int err = 0;
            int numberPlateElements = 0;

            err = St7.St7GetTotal(uID, St7.tyPLATE, ref numberPlateElements);
            if (!St7ErrorCustom(err, "Could not get total number of plate elements."))
            {
                return(null);
            }
            List <Node>             nodes      = ReadNodes();
            List <ISurfaceProperty> plateProps = ReadSurfaceProperty();

            if (ids == null || ids.Count == 0)
            {
                ids = Enumerable.Range(1, numberPlateElements).ToList();
            }
            List <Panel>          panels            = new List <Panel>();
            Dictionary <int, int> platePropsNumbers = new Dictionary <int, int>();

            for (int i = 0; i < plateProps.Count; i++)
            {
                platePropsNumbers.Add(GetAdapterId <int>(plateProps[i]), i);
            }
            foreach (int id in ids)
            {
                int platePropNum = 0;
                err = St7.St7GetElementProperty(uID, St7.ptPLATEPROP, id, ref platePropNum);
                int   propIndex = platePropsNumbers[platePropNum];
                Panel panel     = new Panel();
                SetAdapterId(panel, id);
                panel.Property = plateProps[propIndex];
                //panel.Name = plateProps[propIndex].Name;
                int[] plateConnection = new int[St7.kMaxElementNode + 1];
                err = St7.St7GetElementConnection(uID, St7.tyPLATE, id, plateConnection);
                if (!St7ErrorCustom(err, "Could not get plate nodes."))
                {
                    return(null);
                }
                if (plateConnection[0] == 3 || plateConnection[0] == 6) // Plate elements Tri3 and Tri6. Firt index is a number of vertices
                {
                    Point pt1  = nodes[plateConnection[1] - 1].Position;
                    Point pt2  = nodes[plateConnection[2] - 1].Position;
                    Point pt3  = nodes[plateConnection[3] - 1].Position;
                    Line  ln1  = BH.Engine.Geometry.Create.Line(pt1, pt2);
                    Line  ln2  = BH.Engine.Geometry.Create.Line(pt2, pt3);
                    Line  ln3  = BH.Engine.Geometry.Create.Line(pt3, pt1);
                    Edge  edg1 = BH.Engine.Structure.Create.Edge(ln1, null, "");
                    Edge  edg2 = BH.Engine.Structure.Create.Edge(ln2, null, "");
                    Edge  edg3 = BH.Engine.Structure.Create.Edge(ln3, null, "");
                    SetAdapterId(edg1, plateConnection[1] - 1);
                    SetAdapterId(edg2, plateConnection[2] - 1);
                    SetAdapterId(edg3, plateConnection[3] - 1);
                    panel.ExternalEdges.Add(edg1);
                    panel.ExternalEdges.Add(edg2);
                    panel.ExternalEdges.Add(edg3);
                }
                else // All quad elements
                {
                    Point pt1  = nodes[plateConnection[1] - 1].Position;
                    Point pt2  = nodes[plateConnection[2] - 1].Position;
                    Point pt3  = nodes[plateConnection[3] - 1].Position;
                    Point pt4  = nodes[plateConnection[4] - 1].Position;
                    Line  ln1  = BH.Engine.Geometry.Create.Line(pt1, pt2);
                    Line  ln2  = BH.Engine.Geometry.Create.Line(pt2, pt3);
                    Line  ln3  = BH.Engine.Geometry.Create.Line(pt3, pt4);
                    Line  ln4  = BH.Engine.Geometry.Create.Line(pt4, pt1);
                    Edge  edg1 = BH.Engine.Structure.Create.Edge(ln1, null, "");
                    Edge  edg2 = BH.Engine.Structure.Create.Edge(ln2, null, "");
                    Edge  edg3 = BH.Engine.Structure.Create.Edge(ln3, null, "");
                    Edge  edg4 = BH.Engine.Structure.Create.Edge(ln4, null, "");
                    SetAdapterId(edg1, plateConnection[1] - 1);
                    SetAdapterId(edg2, plateConnection[2] - 1);
                    SetAdapterId(edg3, plateConnection[3] - 1);
                    SetAdapterId(edg4, plateConnection[4] - 1);
                    panel.ExternalEdges.Add(edg1);
                    panel.ExternalEdges.Add(edg2);
                    panel.ExternalEdges.Add(edg3);
                    panel.ExternalEdges.Add(edg4);
                }
                panels.Add(panel);
            }
            return(panels);
        }
Example #4
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/
        private List <Bar> ReadBars(List <string> ids = null)
        {
            int        err   = 0;
            List <Bar> beams = new List <Bar>();
            Dictionary <int, ISectionProperty> allBeamProperties = ReadSectionProperties().ToDictionary(x => GetAdapterId <int>(x));
            Dictionary <int, Node>             allNodes          = ReadNodes().ToDictionary(x => GetAdapterId <int>(x));
            int beamCount = 0;

            err = St7.St7GetTotal(1, St7.tyBEAM, ref beamCount);
            if (!St7ErrorCustom(err, "Could not get total number of beams."))
            {
                return(beams);
            }
            for (int bm = 0; bm < beamCount; bm++)
            {
                // Getting nodes for a beam
                int   beamId  = bm + 1;
                int[] bmNodes = new int[St7.kMaxElementNode + 1];
                err = St7.St7GetElementConnection(1, St7.tyBEAM, beamId, bmNodes);
                if (!St7ErrorCustom(err, "Could not get nodes for a beam " + beamId.ToString()))
                {
                    continue;
                }
                if (bmNodes[0] != 2)    // checking number of nodes bmNodes[0]
                {
                    BH.Engine.Base.Compute.RecordError("Number of nodes doesn't equal 2 for beam N: " + beamId.ToString());
                    return(beams);
                }
                Node nd1 = allNodes[bmNodes[1]];
                Node nd2 = allNodes[bmNodes[2]];

                // getting a property for a beam
                int beamPropNum = 0;
                err = St7.St7GetElementProperty(1, St7.ptBEAMPROP, beamId, ref beamPropNum);
                if (!St7ErrorCustom(err, "Could not get property for a beam " + beamId.ToString()))
                {
                    continue;
                }
                ISectionProperty prop = allBeamProperties.ContainsKey(beamPropNum)? allBeamProperties[beamPropNum] : null;
                //// getting an orientation vector
                //double[] beamAxes = new double[9];
                //err = St7.St7GetBeamAxisSystem(1, beamId, St7.btTrue, beamAxes);
                //if (!St7ErrorCustom(err, "Could not get local axes for a beam " + beamId.ToString())) continue;
                //Vector i2 = BH.Engine.Geometry.Create.Vector(beamAxes[3], beamAxes[4], beamAxes[5]); // normal vector
                //Vector i3 = BH.Engine.Geometry.Create.Vector(beamAxes[6], beamAxes[7], beamAxes[8]); // vector along the beam
                //Vector reference = Vector.ZAxis;
                //if (Abs(1 - Query.DotProduct(i3, Vector.ZAxis)) < 0.001) reference = i3.CrossProduct(Vector.YAxis); // if beam is vertical use X or -X axis as reference
                //double orientationAngle = reference.Angle(i2, new Plane { Normal = i3 });
                double[] orientationAngle = new double[1];
                err = St7.St7GetBeamReferenceAngle1(1, beamId, orientationAngle);
                int[]    restrTranslationStart = new int[3];
                int[]    restrTranslationEnd   = new int[3];
                int[]    restrRotationStart    = new int[3];
                int[]    restrRotationEnd      = new int[3];
                double[] stiffTranslationStart = new double[3];
                double[] stiffTranslationEnd   = new double[3];
                double[] stiffRotationStart    = new double[3];
                double[] stiffRotationEnd      = new double[3];
                // getting beam releases
                err = St7.St7GetBeamTRelease3(1, beamId, 1, restrTranslationStart, stiffTranslationStart);
                if (err != St7.ERR7_NoError)
                {
                    restrTranslationStart = new int[] { 1, 1, 1 }
                }
                ;                                                                           // fixed if not set
                err = St7.St7GetBeamRRelease3(1, beamId, 1, restrRotationStart, stiffRotationStart);
                if (err != St7.ERR7_NoError)
                {
                    restrRotationStart = new int[] { 1, 1, 1 }
                }
                ;                                                                        // fixed if not set
                List <bool>   beamStartRestraint = restrTranslationStart.Concat(restrRotationStart).Select(rst => rst == St7.brFixed).ToList();
                List <double> stiffnessValsStart = stiffTranslationStart.Concat(stiffRotationStart).ToList();
                err = St7.St7GetBeamTRelease3(1, beamId, 2, restrTranslationEnd, stiffTranslationEnd);
                if (err != St7.ERR7_NoError)
                {
                    restrTranslationEnd = new int[] { 1, 1, 1 }
                }
                ;                                                                         // fixed if not set
                err = St7.St7GetBeamRRelease3(1, beamId, 2, restrRotationEnd, stiffRotationEnd);
                if (err != St7.ERR7_NoError)
                {
                    restrRotationEnd = new int[] { 1, 1, 1 }
                }
                ;                                                                      // fixed if not set
                List <bool>    beamEndRestraint = restrTranslationEnd.Concat(restrRotationEnd).Select(rst => rst == St7.brFixed).ToList();
                List <double>  stiffnessValsEnd = stiffTranslationEnd.Concat(stiffRotationEnd).ToList();
                Constraint6DOF startRelease     = BH.Engine.Structure.Create.Constraint6DOF("", beamStartRestraint, stiffnessValsStart);
                Constraint6DOF endRelease       = BH.Engine.Structure.Create.Constraint6DOF("", beamEndRestraint, stiffnessValsEnd);
                BarRelease     barRelease       = BH.Engine.Structure.Create.BarRelease(startRelease, endRelease);
                Bar            bar = BH.Engine.Structure.Create.Bar(nd1, nd2, prop, orientationAngle[0] * System.Math.PI / 180, barRelease);
                SetAdapterId(bar, beamId);
                beams.Add(bar);
            }

            return(beams);
        }

        /***************************************************/
    }
}