/// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override StiffnessMatrix LocalStiffnessMatrix()
        {
            KeyedSquareMatrix <Strain> materialMatrix = this.MaterialMatrix;

            SharpFE.Maths.Integration.Gauss.GaussianIntegration2D gaussianIntegrator = new SharpFE.Maths.Integration.Gauss.GaussianIntegration2D(2);

            Matrix <double> k = gaussianIntegrator.Integrate((gaussIntegrationPointi, gaussIntegrationPointj) => {
                CartesianPoint pnt = new CartesianPoint(gaussIntegrationPointi, gaussIntegrationPointj, 0);

                KeyedRowColumnMatrix <Strain, NodalDegreeOfFreedom> strainDisplacementMatrix = this.StrainDisplacementMatrix(pnt);
                KeyedRowColumnMatrix <NodalDegreeOfFreedom, Strain> bte = strainDisplacementMatrix.TransposeThisAndMultiply <Strain>(materialMatrix);
                KeyedRowColumnMatrix <NodalDegreeOfFreedom, NodalDegreeOfFreedom> bteb = bte.Multiply <Strain, NodalDegreeOfFreedom>(strainDisplacementMatrix);

                double jacobianDeterminant = this.Jacobian(pnt).Determinant();
                bteb = bteb.Multiply(jacobianDeterminant);
                return((Matrix <double>)bteb);
            });

            double thickness = this.Element.Thickness; //TODO interpolate over element (i.e. allow varying thickness over element)

            k = k.Multiply(thickness);

            IList <NodalDegreeOfFreedom> supportedNodalDegreesOfFreedom = this.Element.SupportedLocalNodalDegreeOfFreedoms;

            return(new StiffnessMatrix(supportedNodalDegreesOfFreedom, supportedNodalDegreesOfFreedom, k));
        }
        private void AssertProperties(KeyedRowColumnMatrix <string, string> SUT, double ax, double ay, double bx, double by, double cx, double cy)
        {
            Assert.IsNotNull(SUT);

            Assert.AreEqual(3, SUT.RowCount);
            Assert.AreEqual(2, SUT.ColumnCount);

            IList <string> returnedRowKeys = SUT.RowKeys;

            Assert.IsNotNull(returnedRowKeys);
            Assert.IsTrue(returnedRowKeys.Contains("a"));
            Assert.IsTrue(returnedRowKeys.Contains("b"));
            Assert.IsTrue(returnedRowKeys.Contains("c"));

            IList <string> returnedColumnKeys = SUT.ColumnKeys;

            Assert.IsNotNull(returnedColumnKeys);
            Assert.IsTrue(returnedColumnKeys.Contains("x"));
            Assert.IsTrue(returnedColumnKeys.Contains("y"));

            Assert.AreEqual(ax, SUT["a", "x"], "ax");
            Assert.AreEqual(ay, SUT["a", "y"], "ay");
            Assert.AreEqual(bx, SUT["b", "x"], "bx");
            Assert.AreEqual(by, SUT["b", "y"], "by");
            Assert.AreEqual(cx, SUT["c", "x"], "cx");
            Assert.AreEqual(cy, SUT["c", "y"], "cy");
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override KeyedRowColumnMatrix <Strain, NodalDegreeOfFreedom> StrainDisplacementMatrix(XYZ locationInLocalCoordinates)
        {
            IList <Strain> supportedStrains = this.SupportedStrains;
            IList <NodalDegreeOfFreedom> supportedNodalDegreesOfFreedom = this.Element.SupportedLocalNodalDegreeOfFreedoms;
            KeyedRowColumnMatrix <Strain, NodalDegreeOfFreedom> strainDisplacementMatrix = new KeyedRowColumnMatrix <Strain, NodalDegreeOfFreedom>(supportedStrains, supportedNodalDegreesOfFreedom);

            IFiniteElementNode node0 = this.Element.Nodes[0];
            IFiniteElementNode node1 = this.Element.Nodes[1];
            IFiniteElementNode node2 = this.Element.Nodes[2];

            IDictionary <IFiniteElementNode, XYZ> localCoords = this.Element.CalculateLocalPositionsOfNodes();
            XYZ node0Pos = localCoords[node0];
            XYZ node1Pos = localCoords[node1];
            XYZ node2Pos = localCoords[node2];

            double constant = 1.0 / (2.0 * this.Element.Area);

            strainDisplacementMatrix.At(Strain.LinearStrainX, new NodalDegreeOfFreedom(node0, DegreeOfFreedom.X), constant * (node1Pos.Y - node2Pos.Y));
            strainDisplacementMatrix.At(Strain.LinearStrainX, new NodalDegreeOfFreedom(node1, DegreeOfFreedom.X), constant * (node2Pos.Y - node0Pos.Y));
            strainDisplacementMatrix.At(Strain.LinearStrainX, new NodalDegreeOfFreedom(node2, DegreeOfFreedom.X), constant * (node0Pos.Y - node1Pos.Y));

            strainDisplacementMatrix.At(Strain.LinearStrainY, new NodalDegreeOfFreedom(node0, DegreeOfFreedom.Y), constant * (node2Pos.X - node1Pos.X));
            strainDisplacementMatrix.At(Strain.LinearStrainY, new NodalDegreeOfFreedom(node1, DegreeOfFreedom.Y), constant * (node0Pos.X - node2Pos.X));
            strainDisplacementMatrix.At(Strain.LinearStrainY, new NodalDegreeOfFreedom(node2, DegreeOfFreedom.Y), constant * (node1Pos.X - node0Pos.X));

            strainDisplacementMatrix.At(Strain.ShearStrainXY, new NodalDegreeOfFreedom(node0, DegreeOfFreedom.X), constant * (node2Pos.X - node1Pos.X));
            strainDisplacementMatrix.At(Strain.ShearStrainXY, new NodalDegreeOfFreedom(node0, DegreeOfFreedom.Y), constant * (node1Pos.Y - node2Pos.Y));
            strainDisplacementMatrix.At(Strain.ShearStrainXY, new NodalDegreeOfFreedom(node1, DegreeOfFreedom.X), constant * (node0Pos.X - node2Pos.X));
            strainDisplacementMatrix.At(Strain.ShearStrainXY, new NodalDegreeOfFreedom(node1, DegreeOfFreedom.Y), constant * (node2Pos.Y - node0Pos.Y));
            strainDisplacementMatrix.At(Strain.ShearStrainXY, new NodalDegreeOfFreedom(node2, DegreeOfFreedom.X), constant * (node1Pos.X - node0Pos.X));
            strainDisplacementMatrix.At(Strain.ShearStrainXY, new NodalDegreeOfFreedom(node2, DegreeOfFreedom.Y), constant * (node0Pos.Y - node1Pos.Y));

            return(strainDisplacementMatrix);
        }
 public void SetUp()
 {
     rowKeys = new List <string> {
         "a", "b", "c"
     };
     colKeys = new List <string> {
         "x", "y"
     };
     SUT = new KeyedRowColumnMatrix <string, string>(rowKeys, colKeys);
     InitialiseSUTValues();
 }
        public void It_can_generate_a_sub_matrix()
        {
            IList <string> rowsToInclude = new List <string> {
                "a"
            };
            IList <string> columnsToInclude = new List <string> {
                "x", "y"
            };

            KeyedRowColumnMatrix <string, string> result = SUT.SubMatrix(rowsToInclude, columnsToInclude);

            Assert.AreEqual(1, result.RowCount);
            Assert.AreEqual(2, result.ColumnCount);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override StiffnessMatrix LocalStiffnessMatrix()
        {
            double elementVolume = this.Element.Thickness * this.Element.Area;
            KeyedSquareMatrix <Strain> materialMatrix = this.MaterialMatrix;
            KeyedRowColumnMatrix <Strain, NodalDegreeOfFreedom> strainDisplacementMatrix           = this.StrainDisplacementMatrix(null);
            KeyedRowColumnMatrix <NodalDegreeOfFreedom, Strain> transposedStrainDisplacementMatrix = strainDisplacementMatrix.Transpose();

            KeyedRowColumnMatrix <NodalDegreeOfFreedom, Strain> bte = transposedStrainDisplacementMatrix.Multiply <Strain, Strain>(materialMatrix);

            KeyedRowColumnMatrix <NodalDegreeOfFreedom, NodalDegreeOfFreedom> bteb = bte.Multiply <Strain, NodalDegreeOfFreedom>(strainDisplacementMatrix);

            StiffnessMatrix k = new StiffnessMatrix(bteb.Multiply(elementVolume));

            return(k);
        }
Exemple #7
0
        /// <summary>
        /// Generates the transposed strain-displacement matrix for the given element
        /// </summary>
        /// <returns></returns>
        public override KeyedRowColumnMatrix <Strain, NodalDegreeOfFreedom> StrainDisplacementMatrix(XYZ locationInLocalCoordinates)
        {
            IList <Strain> supportedDegreesOfFreedom = new List <Strain>(1);

            supportedDegreesOfFreedom.Add(Strain.LinearStrainX);
            IList <NodalDegreeOfFreedom> supportedNodalDegreeOfFreedoms = this.Element.SupportedLocalNodalDegreeOfFreedoms;
            KeyedRowColumnMatrix <Strain, NodalDegreeOfFreedom> strainDisplacementMatrix = new KeyedRowColumnMatrix <Strain, NodalDegreeOfFreedom>(supportedDegreesOfFreedom, supportedNodalDegreeOfFreedoms);

            double originalLength = this.Element.OriginalLength;

            strainDisplacementMatrix.At(Strain.LinearStrainX, new NodalDegreeOfFreedom(this.Element.StartNode, DegreeOfFreedom.X), -1.0 / originalLength);
            strainDisplacementMatrix.At(Strain.LinearStrainX, new NodalDegreeOfFreedom(this.Element.EndNode, DegreeOfFreedom.X), 1.0 / originalLength);

            return(strainDisplacementMatrix);
        }
Exemple #8
0
 public static string PrettyPrintKeyedRowColumnMatrix <TRowKey, TColumnKey>(KeyedRowColumnMatrix <TRowKey, TColumnKey> matrix)
 {
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     if (matrix == null)
     {
         sb.Append("KeyedRowColumnMatrix<");
         sb.Append(typeof(TRowKey).Name);
         sb.Append(", ");
         sb.Append(typeof(TColumnKey).Name);
         sb.Append(">");
         sb.Append(" is null");
     }
     else
     {
         PrettyPrintKeyedRowColumnMatrix(sb, matrix);
     }
     return(sb.ToString());
 }
Exemple #9
0
        public static void AssertMatrix <TRowKey, TColumnKey>(KeyedRowColumnMatrix <TRowKey, TColumnKey> actual, int expectedRowCount, int expectedColumnCount, params double[] expectedValues)
        {
            if (expectedValues == null)
            {
                throw new ArgumentNullException("expectedValues");
            }

            if (expectedRowCount * expectedColumnCount != expectedValues.Length)
            {
                throw new ArgumentException(String.Format("You have not provided the correct number of values to check for in the matrix.  " +
                                                          "You provided a expected Row count of {0} and an expected column count of {1}.  " +
                                                          "We would have expected {2} values, but you provided {3}.  The actual matrix has {4} values.\n\r{5}",
                                                          expectedRowCount,
                                                          expectedColumnCount,
                                                          expectedRowCount * expectedColumnCount,
                                                          expectedValues.Length,
                                                          actual.ColumnCount * actual.RowCount,
                                                          actual));
            }

            Assert.IsNotNull(actual);
            Assert.AreEqual(expectedRowCount, actual.RowCount, "RowCount is not correct");
            Assert.AreEqual(expectedColumnCount, actual.ColumnCount, "ColumnCount");

            int currentArrayIndex = 0;

            foreach (TRowKey rowKey in actual.RowKeys)
            {
                foreach (TColumnKey columnKey in actual.ColumnKeys)
                {
                    Assert.AreEqual(expectedValues[currentArrayIndex], actual.At(rowKey, columnKey), 0.0005, String.Format("Row : {0}; Column : {1},\r\n" +
                                                                                                                           "Actual : \r\n" +
                                                                                                                           "{2}", rowKey, columnKey, PrettyPrintKeyedRowColumnMatrix(actual)));
                    currentArrayIndex++;
                }
            }
        }
 public void Can_be_constructed_with_initial_value()
 {
     SUT = new KeyedRowColumnMatrix <string, string>(rowKeys, colKeys, 33);
     AssertProperties(SUT, 33, 33, 33, 33, 33, 33);
 }
 public StiffnessMatrix(KeyedRowColumnMatrix <NodalDegreeOfFreedom, NodalDegreeOfFreedom> matrix)
     : base(matrix)
 {
     // empty
 }
Exemple #12
0
 public Svd(KeyedRowColumnMatrix <TRowKey, TColumnKey> matrix, bool computeVectors)
 {
     data = matrix.Clone();
     this._underlyingSvd = new DenseSvd((DenseMatrix)data.ToMatrix(), computeVectors);
 }
 public void Can_be_constructed_with_initial_value()
 {
     SUT = new KeyedRowColumnMatrix<string, string>(rowKeys, colKeys, 33);
     AssertProperties(SUT, 33, 33, 33, 33, 33, 33);
 }
        private void AssertProperties(KeyedRowColumnMatrix<string, string> SUT, double ax, double ay, double bx, double by, double cx, double cy)
        {
            Assert.IsNotNull(SUT);

            Assert.AreEqual(3, SUT.RowCount);
            Assert.AreEqual(2, SUT.ColumnCount);

            IList<string> returnedRowKeys = SUT.RowKeys;
            Assert.IsNotNull(returnedRowKeys);
            Assert.IsTrue(returnedRowKeys.Contains("a"));
            Assert.IsTrue(returnedRowKeys.Contains("b"));
            Assert.IsTrue(returnedRowKeys.Contains("c"));

            IList<string> returnedColumnKeys = SUT.ColumnKeys;
            Assert.IsNotNull(returnedColumnKeys);
            Assert.IsTrue(returnedColumnKeys.Contains("x"));
            Assert.IsTrue(returnedColumnKeys.Contains("y"));

            Assert.AreEqual(ax, SUT["a", "x"], "ax");
            Assert.AreEqual(ay, SUT["a", "y"], "ay");
            Assert.AreEqual(bx, SUT["b", "x"], "bx");
            Assert.AreEqual(by, SUT["b", "y"], "by");
            Assert.AreEqual(cx, SUT["c", "x"], "cx");
            Assert.AreEqual(cy, SUT["c", "y"], "cy");
        }
 public void SetUp()
 {
     rowKeys = new List<string>{"a", "b", "c"};
     colKeys = new List<string>{"x", "y"};
     SUT = new KeyedRowColumnMatrix<string, string>(rowKeys, colKeys);
     InitialiseSUTValues();
 }
Exemple #16
0
        public static void PrettyPrintKeyedRowColumnMatrix <TRowKey, TColumnKey>(System.Text.StringBuilder sb, KeyedRowColumnMatrix <TRowKey, TColumnKey> matrix)
        {
            sb.AppendLine(string.Format("KeyedRowColumnMatrix<{0}, {1}>", typeof(TRowKey).Name, typeof(TColumnKey).Name));

            sb.Append("Column Keys : ");
            IList <TColumnKey> columnKeys = matrix.ColumnKeys;

            PrettyPrintList <TColumnKey>(sb, columnKeys);

            IList <TRowKey> rowKeys = matrix.RowKeys;

            sb.AppendLine();
            sb.Append("Row Keys : ");
            PrettyPrintList <TRowKey>(sb, rowKeys);

            sb.AppendLine();
            sb.Append(matrix);
        }