public List <Vector <double> > CalcStrain(List <GH_Integer> c_e, Vector <double> u, List <Matrix <Double> > B_e, double E, double nu)
        {
            DataTree <double> treeStrain = new DataTree <double>();

            Cmatrix         C_new = new Cmatrix(E, nu);
            Matrix <double> C     = C_new.CreateMatrix();

            StrainCalc sC = new StrainCalc();
            List <Vector <double> > strain = new List <Vector <double> >();

            //For calculating the strains and stress
            strain = sC.calcStrain(B_e, u, c_e);

            return(strain);
        }
        public List <Vector <double> > CalcStress(List <List <double> > globalStrain, double E, double nu)
        {
            List <Vector <double> > globalStress = new List <Vector <double> >();
            Cmatrix         C        = new Cmatrix(E, nu);
            Matrix <double> C_matrix = C.CreateMatrix();


            for (int i = 0; i < globalStrain.Count; i++)
            {
                Vector <double> strainVec = Vector <double> .Build.Dense(globalStrain[i].ToArray());

                globalStress.Add(C_matrix.Multiply(strainVec));
            }

            return(globalStress);
        }
        public List <List <Vector <double> > > CalcStrain(Vector <double> u, List <List <Matrix <double> > > B_all, GH_Structure <GH_Integer> treeConnectivity, double E, double nu)
        {
            List <Matrix <double> > B_e         = new List <Matrix <double> >();
            List <GH_Integer>       c_e         = new List <GH_Integer>();
            DataTree <double>       strain_node = new DataTree <double>();

            Cmatrix         C        = new Cmatrix(E, nu);
            Matrix <double> C_matrix = C.CreateMatrix();

            List <List <Vector <double> > > strain = new List <List <Vector <double> > >();

            for (int i = 0; i < B_all.Count; i++)
            {
                B_e = B_all[i];
                c_e = (List <GH_Integer>)treeConnectivity.get_Branch(i);
                List <Vector <double> > calcedStrain = CalcStrain(c_e, u, B_e, E, nu);

                strain.Add(calcedStrain);
            }

            return(strain);
        }
Beispiel #4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_Structure <GH_Integer> treeConnectivity = new GH_Structure <GH_Integer>();
            GH_Structure <GH_Point>   treePoints       = new GH_Structure <GH_Point>();
            List <string>             bctxt            = new List <string>();
            List <string>             loadtxt          = new List <string>();
            List <string>             deftxt           = new List <string>();

            if (!DA.GetDataTree(0, out treeConnectivity))
            {
                return;
            }
            if (!DA.GetDataTree(1, out treePoints))
            {
                return;
            }
            if (!DA.GetDataList(2, bctxt))
            {
                return;
            }
            if (!DA.GetDataList(3, loadtxt))
            {
                return;
            }
            if (!DA.GetDataList(4, deftxt))
            {
                return;
            }


            // Temporary way of finding the size of stiffness matrix and B matrix
            int sizeOfM = FindSizeOfM(treeConnectivity);

            //List of global points with correct numbering
            Point3d[] globalPoints = CreatePointList(treeConnectivity, treePoints, sizeOfM);

            //Create K_tot
            var tuple = CreateGlobalStiffnessMatrix(treeConnectivity, treePoints, sizeOfM);

            double[,] K_tot = tuple.Item1;

            //B_all
            //List<List<Matrix<double>>> B_all = tuple.Item2;
            Matrix <double>[,] B_all = tuple.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;

            //Apply boundary condition and predeformations
            K_tot = ApplyBC(K_tot, bcNodes);
            K_tot = ApplyBC(K_tot, predefNodes);

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

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

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

            //double[] R_array = SetLoads(sizeOfM, loadtxt);
            double[] R_array = AssignLoadsAndBC(loadtxt, bcNodes, globalPoints);
            var      V       = Vector <double> .Build;
            var      R       = (V.DenseOfArray(R_array)).Subtract(R_def);

            double[] R_array_def = new double[sizeOfM];
            for (int j = 0; j < sizeOfM; j++)
            {
                R_array_def[j] = R[j];
            }


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

            //Trying with cholesky
            Deformations  def = new Deformations(K_tot, R_array_def);
            List <double> u   = def.Cholesky_Banachiewicz();

            DataTree <double> defTree = new DataTree <double>();
            int n = 0;

            for (int i = 0; i < u.Count; i += 3)
            {
                List <double> u_node = new List <double>(3);
                u_node.Add(u[i]);
                u_node.Add(u[i + 1]);
                u_node.Add(u[i + 2]);

                defTree.AddRange(u_node, new GH_Path(new int[] { 0, n }));
                n++;
            }

            //Calculatin strains for each node and stresses based on strain.
            List <Matrix <double> > B_e         = new List <Matrix <double> >();
            List <GH_Integer>       c_e         = new List <GH_Integer>();
            DataTree <double>       strain_node = new DataTree <double>();
            Cmatrix         C        = new Cmatrix(E, nu);
            Matrix <double> C_matrix = C.CreateMatrix();



            //List<List<Vector<double>>> strain = new List<List<Vector<double>>>();
            Vector <double>[,] strain = CalcStrain(treeConnectivity, u, B_all);



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

            double[,] globalStrain = FindGlobalStrain(strain, treeConnectivity, sizeOfM);

            Vector <double>[] globalStress = CalcStress(globalStrain, C_matrix);

            for (int i = 0; i < globalStrain.GetLength(0); i++)
            {
                //strainTree.AddRange(globalStrain[i], new GH_Path(new int[] { 0, i }));
                stressTree.AddRange(globalStress[i], new GH_Path(new int[] { 0, i }));
                for (int j = 0; j < globalStrain.GetLength(1); j++)
                {
                    strainTree.Add(globalStrain[i, j], new GH_Path(new int[] { 0, i }));
                }
            }

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


            /*
             * GH_Boolean => Boolean
             * GH_Integer => int
             * GH_Number => double
             * GH_Vector => Vector3d
             * GH_Matrix => Matrix
             * GH_Surface => Brep
             */
        }