Пример #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 <Node> ReadNodes(List <string> ids = null)
        {
            int         err       = 0;
            int         nodeCount = 0;
            List <Node> nodes     = new List <Node>();

            double[] XYZ = new double[3];

            err = St7.St7GetTotal(1, St7.tyNODE, ref nodeCount);
            if (!St7Error(err))
            {
                return(nodes);
            }
            for (int nn = 0; nn < nodeCount; nn++)
            {
                int nodeId = nn + 1;
                // getting node coordinates
                err = St7.St7GetNodeXYZ(1, nodeId, XYZ);
                if (!St7ErrorCustom(err, "Could not get a position of node: " + nodeId.ToString()))
                {
                    continue;
                }
                // getting node restraints
                // !!! LOCAL RESTRAINTS ARE NOT IMPLEMENTED !!!! read UCS and write it to Orientation property in Node
                int         ucsId          = 1;
                int[]       restraints     = new int[6];
                double[]    enforcedDispls = new double[6];
                List <bool> bhFixed        = new List <bool>();
                err     = St7.St7GetNodeRestraint6(1, nodeId, 1, ref ucsId, restraints, enforcedDispls);
                bhFixed = restraints.Select(rst => rst == St7.btTrue).ToList();
                double[] translationStiff = new double[3];
                err = St7.St7GetNodeKTranslation3F(1, nodeId, 1, ref ucsId, translationStiff);
                double[] rotationStiff = new double[3];
                err = St7.St7GetNodeKRotation3F(1, nodeId, 1, ref ucsId, rotationStiff);
                List <double> stiffnessVals = new List <double>();
                stiffnessVals.AddRange(translationStiff);
                stiffnessVals.AddRange(rotationStiff);
                Constraint6DOF bhRestraint = BH.Engine.Structure.Create.Constraint6DOF("", bhFixed, stiffnessVals);
                Node           bhNode      = BH.Engine.Structure.Create.Node(BH.Engine.Geometry.Create.Point(XYZ[0], XYZ[1], XYZ[2]), "", bhRestraint);
                SetAdapterId(bhNode, nodeId);
                nodes.Add(bhNode);
            }
            return(nodes);
        }
Пример #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()));
        }