Ejemplo n.º 1
0
        public IMatrix2D <double> MassMatrix(Element element)
        {
            double x2 = Math.Pow(element.Nodes[1].X - element.Nodes[0].X, 2);
            double y2 = Math.Pow(element.Nodes[1].Y - element.Nodes[0].Y, 2);
            double z2 = Math.Pow(element.Nodes[1].Z - element.Nodes[0].Z, 2);
            double L  = 1d / Math.Sqrt(x2 + y2 + z2);
            //double halfMass = 0.5 * Density * SectionArea * L;

            //var massMatrix = new SymmetricMatrix2D<double>(new double[] { halfMass, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            //    halfMass, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            //    halfMass, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            //    halfMass, 0, 0, 0, 0, 0, 0, 0, 0,
            //    halfMass, 0, 0, 0, 0, 0, 0, 0,
            //    halfMass, 0, 0, 0, 0, 0, 0,
            //    halfMass, 0, 0, 0, 0, 0,
            //    halfMass, 0, 0, 0, 0,
            //    halfMass, 0, 0, 0,
            //    halfMass, 0, 0,
            //    halfMass, 0,
            //    halfMass
            //});
            double halfMass   = Density * SectionArea / L / 6d;
            var    massMatrix = new SymmetricMatrix2D <double>(new double[] { halfMass, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                                              halfMass, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                                              halfMass, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                                              0, 0, 0, 0, 0, 0, 0, 0, 0,
                                                                              0, 0, 0, 0, 0, 0, 0, 0,
                                                                              0, 0, 0, 0, 0, 0, 0,
                                                                              halfMass, 0, 0, 0, 0, 0,
                                                                              halfMass, 0, 0, 0, 0,
                                                                              halfMass, 0, 0, 0,
                                                                              0, 0, 0,
                                                                              0, 0,
                                                                              0 });

            var refx = new double[] { 1, 1, 1 };
            var beamTransformation = new Matrix2D <double>(12, 12);

            beamTransformation[0, 0] = (element.Nodes[1].X - element.Nodes[0].X) * L;
            beamTransformation[0, 1] = (element.Nodes[1].Y - element.Nodes[0].Y) * L;
            beamTransformation[0, 2] = (element.Nodes[1].Z - element.Nodes[0].Z) * L;

            beamTransformation[1, 0] = refx[1] * beamTransformation[0, 2] - refx[2] * beamTransformation[0, 1];
            beamTransformation[1, 1] = refx[2] * beamTransformation[0, 0] - refx[0] * beamTransformation[0, 2];
            beamTransformation[1, 2] = refx[0] * beamTransformation[0, 1] - refx[1] * beamTransformation[0, 0];
            double dn = 1.0 / Math.Sqrt(beamTransformation[1, 0] * beamTransformation[1, 0] + beamTransformation[1, 1] * beamTransformation[1, 1] + beamTransformation[1, 2] * beamTransformation[1, 2]);

            beamTransformation[1, 0] = beamTransformation[1, 0] * dn;
            beamTransformation[1, 1] = beamTransformation[1, 1] * dn;
            beamTransformation[1, 2] = beamTransformation[1, 2] * dn;
            beamTransformation[2, 0] = beamTransformation[0, 1] * beamTransformation[1, 2] - beamTransformation[0, 2] * beamTransformation[1, 1];
            beamTransformation[2, 1] = beamTransformation[0, 2] * beamTransformation[1, 0] - beamTransformation[0, 0] * beamTransformation[1, 2];
            beamTransformation[2, 2] = beamTransformation[0, 0] * beamTransformation[1, 1] - beamTransformation[0, 1] * beamTransformation[1, 0];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    beamTransformation[i + 3, j + 3] = beamTransformation[i, j];
                    beamTransformation[i + 6, j + 6] = beamTransformation[i, j];
                    beamTransformation[i + 9, j + 9] = beamTransformation[i, j];
                }
            }
            CalculateRotTranformation(element);

            return(dofEnumerator.GetTransformedMatrix(new SymmetricMatrix2D <double>(rotTransformation.Transpose() * beamTransformation.Transpose() * massMatrix.ToMatrix2D() * beamTransformation * rotTransformation)));
        }
Ejemplo n.º 2
0
        private IMatrix2D <double> StiffnessMatrixPure(Element element)
        {
            //var m = (material as IFiniteElementMaterial3D);//TODO remove material
            double x2 = Math.Pow(element.Nodes[1].X - element.Nodes[0].X, 2);
            double y2 = Math.Pow(element.Nodes[1].Y - element.Nodes[0].Y, 2);
            double z2 = Math.Pow(element.Nodes[1].Z - element.Nodes[0].Z, 2);
            double L  = 1 / Math.Sqrt(x2 + y2 + z2);
            double L2 = L * L;
            double L3 = L2 * L;
            //double EIx = m.YoungModulus * MomentOfInertiaX;

            /* deprecated calculations after the removal of the material class as input
             * double EIy = m.YoungModulus * MomentOfInertiaY;
             * double EIz = m.YoungModulus * MomentOfInertiaZ;
             * double GJL = m.YoungModulus * L * MomentOfInertiaPolar / (2 * (1 + m.PoissonRatio));
             * double EAL = m.YoungModulus * SectionArea * L;
             */

            double EIy = this.youngModulus * MomentOfInertiaY;
            double EIz = this.youngModulus * MomentOfInertiaZ;
            double GJL = this.youngModulus * L * MomentOfInertiaPolar / (2 * (1 + this.poissonRatio));
            double EAL = this.youngModulus * SectionArea * L;

            var stiffnessMatrix = new SymmetricMatrix2D <double>(new double[] { EAL, 0, 0, 0, 0, 0, -EAL, 0, 0, 0, 0, 0,
                                                                                12 * EIz * L3, 0, 0, 0, 6 * EIz * L2, 0, -12 * EIz * L3, 0, 0, 0, 6 * EIz * L2,
                                                                                12 * EIy * L3, 0, -6 * EIy * L2, 0, 0, 0, -12 * EIy * L3, 0, -6 * EIy * L2, 0,
                                                                                GJL, 0, 0, 0, 0, 0, -GJL, 0, 0,
                                                                                4 * EIy * L, 0, 0, 0, 6 * EIy * L2, 0, 2 * EIy * L, 0,
                                                                                4 * EIz * L, 0, -6 * EIz * L2, 0, 0, 0, 2 * EIz * L,
                                                                                EAL, 0, 0, 0, 0, 0,
                                                                                12 * EIz * L3, 0, 0, 0, -6 * EIz * L2,
                                                                                12 * EIy * L3, 0, 6 * EIy * L2, 0,
                                                                                GJL, 0, 0,
                                                                                4 * EIy * L, 0,
                                                                                4 * EIz * L });

            var refx = new double[] { 1, 1, 1 };
            var beamTransformation = new Matrix2D <double>(12, 12);

            beamTransformation[0, 0] = (element.Nodes[1].X - element.Nodes[0].X) * L;
            beamTransformation[0, 1] = (element.Nodes[1].Y - element.Nodes[0].Y) * L;
            beamTransformation[0, 2] = (element.Nodes[1].Z - element.Nodes[0].Z) * L;

            //beamTransformation[2, 0] = refx[0];
            //beamTransformation[2, 1] = refx[1];
            //beamTransformation[2, 2] = refx[2];

            //beamTransformation[1, 0] = beamTransformation[2, 1] * beamTransformation[0, 2] - beamTransformation[2, 2] * beamTransformation[0, 1];
            //beamTransformation[1, 1] = beamTransformation[2, 2] * beamTransformation[0, 0] - beamTransformation[2, 0] * beamTransformation[0, 2];
            //beamTransformation[1, 2] = beamTransformation[2, 0] * beamTransformation[0, 1] - beamTransformation[2, 1] * beamTransformation[0, 0];
            beamTransformation[1, 0] = refx[1] * beamTransformation[0, 2] - refx[2] * beamTransformation[0, 1];
            beamTransformation[1, 1] = refx[2] * beamTransformation[0, 0] - refx[0] * beamTransformation[0, 2];
            beamTransformation[1, 2] = refx[0] * beamTransformation[0, 1] - refx[1] * beamTransformation[0, 0];
            double dn = 1.0 / Math.Sqrt(beamTransformation[1, 0] * beamTransformation[1, 0] + beamTransformation[1, 1] * beamTransformation[1, 1] + beamTransformation[1, 2] * beamTransformation[1, 2]);

            beamTransformation[1, 0] = beamTransformation[1, 0] * dn;
            beamTransformation[1, 1] = beamTransformation[1, 1] * dn;
            beamTransformation[1, 2] = beamTransformation[1, 2] * dn;
            beamTransformation[2, 0] = beamTransformation[0, 1] * beamTransformation[1, 2] - beamTransformation[0, 2] * beamTransformation[1, 1];
            beamTransformation[2, 1] = beamTransformation[0, 2] * beamTransformation[1, 0] - beamTransformation[0, 0] * beamTransformation[1, 2];
            beamTransformation[2, 2] = beamTransformation[0, 0] * beamTransformation[1, 1] - beamTransformation[0, 1] * beamTransformation[1, 0];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    beamTransformation[i + 3, j + 3] = beamTransformation[i, j];
                    beamTransformation[i + 6, j + 6] = beamTransformation[i, j];
                    beamTransformation[i + 9, j + 9] = beamTransformation[i, j];
                }
            }

            return(new SymmetricMatrix2D <double>(beamTransformation.Transpose() * stiffnessMatrix.ToMatrix2D() * beamTransformation));

            ////if (element.Nodes.Count(n => n.EmbeddedInElement != null) == 0) return stiffnessMatrix;
            //stiffnessMatrix = new SymmetricMatrix2D<double>(beamTransformation.Transpose() * stiffnessMatrix.ToMatrix2D() * beamTransformation);
            //if (embeddedNodes.Count == 0) return stiffnessMatrix;

            ////var hostElements = element.Nodes.Select(x => x.EmbeddedInElement).Distinct();
            //var size = GetElementDOFTypes(element).SelectMany(x => x).Count();
            //transformation = new Matrix2D<double>(dofs.SelectMany(d => d).Count(), size);
            //isNodeEmbedded = new bool[element.Nodes.Count];

            ////TODO : SEPARATE FROM ELEMENT!!
            ////TODO: Must match DOFs of host with embedded element
            //int row = 0;
            //int col = 0;
            //hostElementList = new List<Element>();
            //for (int i = 0; i < element.Nodes.Count; i++)
            //{
            //    var node = element.Nodes[i];
            //    var embeddedNode = embeddedNodes.Where(x => x.Node == node).FirstOrDefault();
            //    //var hostElement = node.EmbeddedInElement;
            //    Element hostElement = embeddedNode == null ? null : embeddedNode.EmbeddedInElement;
            //    if (hostElement == null)
            //    {
            //        isNodeEmbedded[i] = false;
            //        for (int j = 0; j < dofs[i].Length; j++)
            //        {
            //            transformation[row, col] = 1;
            //            row++;
            //            col++;
            //        }
            //    }
            //    else
            //    {
            //        isNodeEmbedded[i] = true;
            //        //double[] hostShapeFunctions = ((IEmbeddedHostElement)hostElement.ElementType).GetShapeFunctionsForNode(hostElement, node);
            //        double[] hostShapeFunctions = ((IEmbeddedHostElement)hostElement.ElementType).GetShapeFunctionsForNode(hostElement, embeddedNode);

            //        if (hostElementList.IndexOf(hostElement) < 0)
            //            hostElementList.Add(hostElement);
            //        else
            //            col -= hostShapeFunctions.Length * hostDofsPerNode;

            //        for (int j = 0; j < commonDofsPerNode; j++)
            //        {
            //            for (int k = 0; k < hostShapeFunctions.Length; k++)
            //                transformation[row, hostDofsPerNode * k + col + j] = hostShapeFunctions[k];
            //            row++;
            //        }
            //        row += embeddedDofsPerNode - commonDofsPerNode;
            //        col += hostShapeFunctions.Length * hostDofsPerNode;
            //    }
            //}

            //// Add identity matrix
            //int index = 0;
            //if (isNodeEmbedded[0])
            //{
            //    transformation[3, col] = 1;
            //    transformation[4, col + 1] = 1;
            //    transformation[5, col + 2] = 1;
            //    index += 3;
            //}
            //if (isNodeEmbedded[1])
            //{
            //    transformation[9, col + index] = 1;
            //    transformation[10, col + index + 1] = 1;
            //    transformation[11, col + index + 2] = 1;
            //}

            //var transformedMatrix = new SymmetricMatrix2D<double>(transformation.Transpose() * stiffnessMatrix.ToMatrix2D() * transformation);
            ////var sw = File.CreateText(@"d:\BeamTransformed.txt");
            ////for (int i = 0; i < 54; i++)
            ////{
            ////    var s = string.Empty;
            ////    for (int j = 0; j < 54; j++)
            ////        s += transformedMatrix[i, j].ToString() + ";";
            ////    sw.WriteLine(s);
            ////}
            ////sw.Close();
            //return transformedMatrix;
        }