Ejemplo n.º 1
0
        /// <summary>
        /// Determines whether defined matrix is diagonal matrix or not.
        /// Diagonal matrix is a matrix that only have nonzero elements on its main diagonal.
        /// </summary>
        /// <param name="mtx">The MTX.</param>
        /// <returns></returns>
        public static bool IsDiagonalMatrix(this CCS mtx)
        {
            var n = mtx.ColumnCount;

            if (n != mtx.RowCount)
            {
                return(false);
            }

            if (mtx.Values.Length > n)
            {
                return(false);
            }

            for (int i = 0; i < n; i++)
            {
                var col = i;

                var st = mtx.ColumnPointers[i];
                var en = mtx.ColumnPointers[i + 1];

                for (int j = st; j < en; j++)
                {
                    var row = mtx.RowIndices[j];

                    if (row != col)
                    {
                        return(false);
                    }
                }
            }


            return(true);
        }
Ejemplo n.º 2
0
        internal static void EnumerateColumns(this CCS matrix, Action <int, Dictionary <int, double> > action)
        {
            var n = matrix.ColumnCount;

            for (int i = 0; i < n; i++)
            {
                var col = i;

                var st = matrix.ColumnPointers[i];
                var en = matrix.ColumnPointers[i + 1];

                var dic = new Dictionary <int, double>();

                for (int j = st; j < en; j++)
                {
                    var row = matrix.RowIndices[j];

                    var val = matrix.Values[j];
                    dic[row] = val;
                }


                action(col, dic);
            }
        }
Ejemplo n.º 3
0
 public static void MultiplyWithConstant(this CCS mtx, double coef)
 {
     for (var i = 0; i < mtx.Values.Length; i++)
     {
         mtx.Values[i] = mtx.Values[i] * coef;
     }
 }
Ejemplo n.º 4
0
        public static int EmptyColumnCount(this CCS matrix)
        {
            var buf = new bool[matrix.RowCount];

            matrix.EnumerateMembers((row, col, val) =>
            {
                buf[col] = true;
            });

            return(buf.Count(ii => !ii));
        }
Ejemplo n.º 5
0
        public static void SetMember(this CCS matrix, int row, int column, double value)
        {
            int index  = matrix.ColumnPointers[column];
            int length = matrix.ColumnPointers[column + 1] - index;
            int pos    = Array.BinarySearch(matrix.RowIndices, index, length, row);

            if (pos < 0)
            {
                throw new Exception();
            }

            matrix.Values[pos] = value;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a built in solver appropriated with <see cref="tp"/>.
        /// </summary>
        /// <param name="type">The solver type.</param>
        /// <returns></returns>
        public static ISolver CreateBuiltInSolver(BuiltInSolverType type, CCS A)
        {
            switch (type)
            {
            case BuiltInSolverType.CholeskyDecomposition:
                return(new CholeskySolverFactory().CreateSolver(A));

                break;

            case BuiltInSolverType.ConjugateGradient:
                return(new ConjugateGradientFactory().CreateSolver(A));   // PCG(new SSOR());

                break;

            default:
                throw new ArgumentOutOfRangeException("type");
            }
        }
Ejemplo n.º 7
0
        private ISolver CreateSolver(CCS a)
        {
            ISolver buf;

            switch (parent.LastResult.SolverType)
            {
            case BuiltInSolverType.CholeskyDecomposition:
                buf = new CholeskySolver(a);
                break;

            case BuiltInSolverType.ConjugateGradient:
                buf   = new PCG(new SSOR());
                buf.A = a;
                break;

            default:
                throw new NotImplementedException();
            }

            return(buf);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Does the specified <see cref="action"/> on all members of <see cref="matrix"/>
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="action"></param>
        internal static void EnumerateMembers(this CCS matrix, Action <int, int, double> action)
        {
            var n = matrix.ColumnCount;

            for (int i = 0; i < n; i++)
            {
                var col = i;

                var st = matrix.ColumnPointers[i];
                var en = matrix.ColumnPointers[i + 1];

                for (int j = st; j < en; j++)
                {
                    var row = matrix.RowIndices[j];

                    var val = matrix.Values[j];

                    action(row, col, val);
                }
            }
        }
Ejemplo n.º 9
0
        public static void MakeMatrixSymetric(this CCS mtx)
        {
            var n = mtx.ColumnCount;

            if (n != mtx.RowCount)
            {
                throw new Exception();
            }


            for (int i = 0; i < n; i++)
            {
                var col = i;

                var st = mtx.ColumnPointers[i];
                var en = mtx.ColumnPointers[i + 1];

                for (int j = st; j < en; j++)
                {
                    var row = mtx.RowIndices[j];



                    var valRowCol = mtx.Values[j];

                    var valColRow = mtx.At(col, row);

                    if (valColRow == valRowCol)
                    {
                        continue;
                    }


                    var avg = (valRowCol + valColRow) / 2;

                    SetMember(mtx, row, col, avg);
                    SetMember(mtx, col, row, avg);
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Divides the zones of reduced <see cref="matrix"/>.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="matrix">The reduced matrix.</param>
 /// <param name="dofMap">The DoF map.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public static ZoneDevidedMatrix DivideZones(Model model, CCS matrix, DofMappingManager dofMap)
 {
     //see Calcutil.GetReducedZoneDividedMatrix
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Extracts the free free part.
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 /// <param name="nodeMapping">The node mapping.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public static CCS ExtractFreeFreePart(CCS matrix, int[] nodeMapping)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Gets the reduced zone divided matrix.
        /// </summary>
        /// <param name="reducedMatrix">The reduced matrix.</param>
        /// <param name="map">The map.</param>
        /// <returns></returns>
        public static ZoneDevidedMatrix GetReducedZoneDividedMatrix(CCS reducedMatrix, DofMappingManager map)
        {
            var m = map.M;
            var n = map.N;
            var r = reducedMatrix;

            if (r.ColumnCount != r.RowCount || r.RowCount != 6 * m)
            {
                throw new InvalidOperationException();
            }

            var ff = new Coord(map.RMap2.Length, map.RMap2.Length, 1);
            var fs = new Coord(map.RMap2.Length, map.RMap3.Length, 1);
            var sf = new Coord(map.RMap3.Length, map.RMap2.Length, 1);
            var ss = new Coord(map.RMap3.Length, map.RMap3.Length, 1);

            for (var i = 0; i < 6 * m; i++)
            {
                var st = r.ColumnPointers[i];
                var en = r.ColumnPointers[i + 1];

                var col = i;

                for (var j = st; j < en; j++)
                {
                    var row = r.RowIndices[j];
                    var val = r.Values[j];

                    if (map.Fixity[map.RMap1[row]] == DofConstraint.Released &&
                        map.Fixity[map.RMap1[col]] == DofConstraint.Released)
                    {
                        ff.At(map.Map2[row], map.Map2[col], val);
                    }

                    if (map.Fixity[map.RMap1[row]] == DofConstraint.Released &&
                        map.Fixity[map.RMap1[col]] != DofConstraint.Released)
                    {
                        fs.At(map.Map2[row], map.Map3[col], val);
                    }

                    if (map.Fixity[map.RMap1[row]] != DofConstraint.Released &&
                        map.Fixity[map.RMap1[col]] == DofConstraint.Released)
                    {
                        sf.At(map.Map3[row], map.Map2[col], val);
                    }

                    if (map.Fixity[map.RMap1[row]] != DofConstraint.Released &&
                        map.Fixity[map.RMap1[col]] != DofConstraint.Released)
                    {
                        ss.At(map.Map3[row], map.Map3[col], val);
                    }
                }
            }

            var buf = new ZoneDevidedMatrix();

            buf.ReleasedReleasedPart = ff.ToCCs();
            buf.ReleasedFixedPart    = fs.ToCCs();
            buf.FixedReleasedPart    = sf.ToCCs();
            buf.FixedFixedPart       = ss.ToCCs();

            return(buf);
        }