示例#1
0
        //TODO удалить после тестирования, взято из CholeskySolver
        public static SymmetricMatrix <DoubleContainerElement> extractMatrix(SymmetricMatrix <MatrixDimension3> sourceMatrix)
        {
            int dimension = 3 * sourceMatrix.Dimension;
            SymmetricMatrix <DoubleContainerElement> result = new SymmetricMatrix <DoubleContainerElement>(dimension, new DoubleContainerElement());

            for (int sourceRowInd = 0; sourceRowInd < sourceMatrix.Dimension; sourceRowInd++)
            {
                int rightBound = sourceRowInd + sourceMatrix.getBandWidth() < sourceMatrix.Dimension ? sourceRowInd + sourceMatrix.getBandWidth() : sourceMatrix.Dimension;
                for (int sourceColInd = sourceRowInd; sourceColInd < rightBound; sourceColInd++)
                {
                    // Обрабатываем соответствующий блок
                    MatrixDimension3 block = sourceMatrix[sourceRowInd, sourceColInd];

                    for (int blockRowInd = 0; blockRowInd < 3; blockRowInd++)
                    {
                        for (int blockColInd = sourceRowInd == sourceColInd ? blockRowInd : 0; blockColInd < 3; blockColInd++)
                        {
                            result[sourceRowInd * 3 + blockRowInd, sourceColInd * 3 + blockColInd] = new DoubleContainerElement(block[blockRowInd, blockColInd]);
                        }
                    }
                }
            }

            return(result);
        }
示例#2
0
        private void createBCMatrix(SymmetricMatrix <DoubleContainerElement> BMatrix, SymmetricMatrix <DoubleContainerElement> CMatrix, SymmetricMatrix <DoubleContainerElement> globalMatrix)
        {
            int rightBound = globalMatrix.getBandWidth() < globalMatrix.Dimension ? globalMatrix.getBandWidth() : globalMatrix.Dimension;

            for (int rowInd = 0; rowInd < rightBound; rowInd++)
            {
                BMatrix[rowInd, 0] = globalMatrix[rowInd, 0];
                CMatrix[0, rowInd] = BMatrix[rowInd, 0] / BMatrix[0, 0];
            }

            for (int colInd = 1; colInd < globalMatrix.Dimension; colInd++)
            {
                rightBound = colInd + globalMatrix.getBandWidth() < globalMatrix.Dimension ? colInd + globalMatrix.getBandWidth() : globalMatrix.Dimension;
                for (int rowInd = colInd; rowInd < rightBound; rowInd++)
                {
                    DoubleContainerElement sum = new DoubleContainerElement(0);
                    for (int countInd = 0; countInd < colInd; countInd++)
                    {
                        sum = sum + (BMatrix[rowInd, countInd] * CMatrix[countInd, colInd]);
                    }
                    BMatrix[rowInd, colInd] = globalMatrix[rowInd, colInd] - sum;
                    if (BMatrix[colInd, colInd] != new DoubleContainerElement(0))
                    {
                        CMatrix[colInd, rowInd] = BMatrix[rowInd, colInd] / BMatrix[colInd, colInd];
                    }
                    else
                    {
                        Console.Write("Division to 0 error!");
                        break;
                    }
                }
            }
        }
        public override bool Equals(Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            if (!obj.GetType().Equals(typeof(DoubleContainerElement)))
            {
                return(false);
            }

            DoubleContainerElement anotherElement = obj as DoubleContainerElement;

            return(this.element == anotherElement.element);
        }
示例#4
0
        //TODO удалить после тестирования,
        public static SymmetricMatrix <DoubleContainerElement> fromMatrix(Matrix source)
        {
            SymmetricMatrix <DoubleContainerElement> result = new SymmetricMatrix <DoubleContainerElement>(source.RowsCount, new DoubleContainerElement());

            for (int rowInd = 0; rowInd < source.RowsCount; rowInd++)
            {
                for (int colInd = rowInd; colInd < source.ColumnsCount; colInd++)
                {
                    if (source[rowInd, colInd] != 0)
                    {
                        result[rowInd, colInd] = new DoubleContainerElement(source[rowInd, colInd]);
                    }
                }
            }

            return(result);
        }
        /*
         * Применение граничных условий.
         * globalMatrix - глобальная матрица [K]
         * rightSide - правая часть
         * boundaryConditions - массив номеров граничных узлов (нумерация начинается с 0!!!!!)
         */
        private void applyBoundaryConditions(SymmetricMatrix <DoubleContainerElement> globalMatrix, IList <Vector3D> rightSide, int[] boundaryConditions)
        {
            int dimension     = globalMatrix.Dimension;
            int bandWidth     = globalMatrix.getBandWidth();
            int boundaryCount = boundaryConditions.Length;
            //MatrixDimension3 neitralMatrix = new MatrixDimension3();
            DoubleContainerElement neitralMatrix = new DoubleContainerElement();
            Vector3D defaultVector = new Vector3D();

            for (int boundary = 0; boundary < boundaryCount; boundary++)
            {
                for (int delta = 0; delta < 3; delta++)
                {
                    int boundaryInd = boundaryConditions[boundary] * 3 + delta;
                    int leftBound   = boundaryInd < globalMatrix.getBandWidth() ? 0 : boundaryInd - globalMatrix.getBandWidth() + 1;
                    int rightBound  = boundaryInd + globalMatrix.getBandWidth() < globalMatrix.Dimension ? boundaryInd + globalMatrix.getBandWidth() : globalMatrix.Dimension;

                    for (int columnInd = leftBound; columnInd < rightBound; columnInd++)
                    {
                        if (!(boundaryInd).Equals(columnInd))
                        {
                            globalMatrix.setElement(boundaryInd, columnInd, neitralMatrix);
                        }
                    }

                    /*globalMatrix[boundaryInd, boundaryInd][0, 1] = 0;
                    *  globalMatrix[boundaryInd, boundaryInd][0, 2] = 0;
                    *  globalMatrix[boundaryInd, boundaryInd][1, 2] = 0;
                    *  globalMatrix[boundaryInd, boundaryInd][1, 0] = 0;
                    *  globalMatrix[boundaryInd, boundaryInd][2, 0] = 0;
                    *  globalMatrix[boundaryInd, boundaryInd][2, 1] = 0;*/

                    if (delta == 0)
                    {
                        rightSide[boundaryConditions[boundary]] = defaultVector;
                    }
                }
            }
        }