예제 #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---variables---

            Brep       sphere = new Brep();
            Mesh_class mesh   = new Mesh_class();

            //---input---

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

            //---setup---

            //Setting up values for reflength and angle for rotation of area
            Brep origBrep            = mesh.GetOrigBrep();
            VolumeMassProperties vmp = VolumeMassProperties.Compute(origBrep);
            double volume            = origBrep.GetVolume();
            double sqrt3             = (double)1 / 3;
            double refLength         = Math.Pow(volume, sqrt3);

            //---solve---

            //List of global points with correct numbering
            Point3d[] globalPoints = mesh.GetGlobalPoints();

            VolumeMassProperties vmpSphere = VolumeMassProperties.Compute(sphere);
            Point3d centroidSphere         = vmpSphere.Centroid;


            Point3d closestPoint = FindClosestPoint(globalPoints, centroidSphere, refLength);

            String text = "Drag sphere to point";

            Plane textPlane = FindSpherePlane(centroidSphere, refLength);

            Color color = Color.Red;

            //---output---

            DA.SetData(0, closestPoint);
            DA.SetData(1, text);
            DA.SetData(2, textPlane);
            DA.SetData(3, color);
        }
예제 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // --- variables ---

            Mesh_class    mesh     = new Mesh_class();
            List <string> bctxt    = new List <string>();
            List <string> loadtxt  = new List <string>();
            List <string> deftxt   = new List <string>();
            Material      material = new Material();


            // --- input ---

            if (!DA.GetData(0, ref mesh))
            {
                return;
            }
            if (!DA.GetDataList(1, bctxt))
            {
                return;
            }
            if (!DA.GetDataList(2, loadtxt))
            {
                return;
            }
            if (!DA.GetDataList(3, deftxt))
            {
                return;
            }
            if (!DA.GetData(4, ref material))
            {
                return;
            }

            //double E = 210000;
            //double nu = 0.3;

            // --- solve ---
            //Boolean first = true;
            List <List <int> >     connectivity  = mesh.GetConnectivity();
            List <List <Point3d> > elementPoints = mesh.GetElementPoints();
            int sizeOfMatrix = mesh.GetSizeOfMatrix();

            Point3d[]   globalPoints = mesh.GetGlobalPoints();
            List <Node> nodes        = mesh.GetNodeList();
            Brep_class  brp          = mesh.GetBrep();
            Brep        origBrep     = brp.GetBrep();

            // mesh.RemoveElement();

            List <Element> elements = mesh.GetElements();
            //Create K_tot
            var             tupleK_B = CreateGlobalStiffnessMatrix(sizeOfMatrix, material, elements);
            Matrix <double> K_tot    = tupleK_B.Item1;

            //B_all
            List <List <Matrix <double> > > B_all = tupleK_B.Item2;

            //Create boundary condition list AND predeformations
            var        tupleBC = CreateBCList(bctxt, globalPoints);
            List <int> bcNodes = tupleBC.Item1;

            var           tupleDef    = CreateBCList(deftxt, globalPoints);
            List <int>    predefNodes = tupleDef.Item1;
            List <double> predef      = tupleDef.Item2;

            //Setter 0 i hver rad med bc og predef, og diagonal til 1.
            K_tot = ApplyBC_Row(K_tot, bcNodes);
            K_tot = ApplyBC_Row(K_tot, predefNodes);

            //Needs to take the predefs into account
            Vector <double> R_def = Vector <double> .Build.Dense(sizeOfMatrix);

            if (deftxt.Any())
            {
                R_def = ApplyPreDef(K_tot, predefNodes, predef, sizeOfMatrix);
            }

            //double[] R_array = SetLoads(sizeOfM, loadtxt);
            double[] R_array = AssignLoadsDefAndBC(loadtxt, predefNodes, predef, bcNodes, globalPoints);

            //Adding R-matrix for pre-deformations.
            var             V = Vector <double> .Build;
            Vector <double> R = (V.DenseOfArray(R_array)).Subtract(R_def);

            //Apply boundary condition and predeformations (Puts 0 in columns of K)
            K_tot = ApplyBC_Col(K_tot, bcNodes);
            K_tot = ApplyBC_Col(K_tot, predefNodes);

            //Inverting K matrix
            Matrix <double> K_tot_inverse = K_tot.Inverse();



            /*
             * For Cholesky calculation. Kept for now.
             * double[] R_array_def = R.ToArray();
             *
             * double[] R_array_def = new double[sizeOfM];
             * for (int j = 0; j < sizeOfM; j++)
             * {
             *  R_array_def[j] = R[j];
             * }
             *
             * //Cholesky calc. Kept for now,
             * Deformations def = new Deformations(K_tot, R_array_def);
             * List<double> u = def.Cholesky_Banachiewicz();
             */

            //Caluculation of the displacement vector u
            Vector <double> u = K_tot_inverse.Multiply(R);

            //Creating tree for output of deformation. Structured in x,y,z for each node. As well as asigning deformation to each node class
            DataTree <double> defTree = DefToTree(u, nodes);

            //Calculatin strains for each node in elements

            CalcStrainAndStress(elements, material);

            //Calculate global stresses from strain

            CalcStrainAndStressGlobal(nodes, material);
            SetAverageStresses(elements);


            DataTree <double> strainTree = new DataTree <double>();
            DataTree <double> stressTree = new DataTree <double>();

            for (int i = 0; i < nodes.Count; i++)
            {
                strainTree.AddRange(nodes[i].GetGlobalStrain(), new GH_Path(new int[] { 0, i }));
                stressTree.AddRange(nodes[i].GetGlobalStress(), new GH_Path(new int[] { 0, i }));
            }

            //FOR PREVIEW OF HEADLINE

            //Setting up reference values
            var     tupleRef  = GetRefValues(origBrep);
            double  refLength = tupleRef.Item1;
            Point3d centroid  = tupleRef.Item2;

            //Creating text-information for showing in VR
            var tupleHeadline = CreateHeadline(centroid, refLength);

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

            //---output---

            DA.SetDataTree(0, defTree);
            DA.SetDataTree(1, strainTree);
            DA.SetDataTree(2, stressTree);

            DA.SetData(3, headText);
            DA.SetData(4, headSize);
            DA.SetData(5, headPlane);
            DA.SetData(6, headColor);
        }