Exemplo n.º 1
0
        private Dictionary<SpeciesId, XSpatialOperator.SpeciesFrameMatrix<IMutableMatrixEx>> GetFrameMatrices<M>(M Matrix, UnsetteledCoordinateMapping RowMap, UnsetteledCoordinateMapping ColMap)
            where M : IMutableMatrixEx
        {
            var ret = new Dictionary<SpeciesId, XSpatialOperator.SpeciesFrameMatrix<IMutableMatrixEx>>();
            foreach (var kv in DictAgglomeration) {
                var Species = kv.Key;
                var mtx_spc = new XSpatialOperator.SpeciesFrameMatrix<IMutableMatrixEx>(Matrix, this.Tracker.Regions, Species, RowMap, ColMap);
                ret.Add(Species, mtx_spc);
            }

            return ret;
        }
Exemplo n.º 2
0
        /// <summary>
        /// some helper for manual debugging
        /// </summary>
        private void MatrixTests(MsrMatrix OpMatrix)
        {
            int J = this.GridData.Cells.NoOfLocalUpdatedCells;
            int E = this.GridData.Edges.Count;

            int[,] e2c = this.GridData.Edges.CellIndices;

            MsrMatrix ConMatrix  = new MsrMatrix(new Partitioning(J));
            MsrMatrix ConMatrix2 = new MsrMatrix(new Partitioning(J));
            var       map        = new UnsetteledCoordinateMapping(new Basis(this.GridData, 0));
            var       FConMatrix = new XSpatialOperator.SpeciesFrameMatrix <MsrMatrix>(ConMatrix2, this.LsTrk.Regions, this.LsTrk.GetSpeciesId("B"), map, map);

            int jCell0 = this.GridData.CellPartitioning.i0;



            //for (int e = 0; e < E; e++) {
            foreach (int e in this.LsTrk.Regions.GetSpeciesSubGrid("B").InnerEdgesMask.ItemEnum)
            {
                int j0 = e2c[e, 0];
                int j1 = e2c[e, 1];

                int j0G;
                if (j0 >= J)
                {
                    j0G = (int)(this.GridData.Parallel.GlobalIndicesExternalCells[j0 - J]);
                }
                else
                {
                    j0G = j0 + jCell0;
                }

                int j1G;
                if (j1 >= 0)
                {
                    if (j1 >= J)
                    {
                        j1G = (int)(this.GridData.Parallel.GlobalIndicesExternalCells[j1 - J]);
                    }
                    else
                    {
                        j1G = j1 + jCell0;
                    }
                }
                else
                {
                    j1G = -1;
                }

                ConMatrix[j0G, j0G]  += 1.0;
                FConMatrix[j0G, j0G] += 1.0;

                if (j1G >= 0)
                {
                    ConMatrix[j0G, j1G]  += 1.0;
                    FConMatrix[j0G, j1G] += 1.0;

                    if (this.GridData.CellPartitioning.IsInLocalRange(j1G))
                    {
                        ConMatrix[j1G, j1G]  += 1.0;
                        FConMatrix[j1G, j1G] += 1.0;
                        ConMatrix[j1G, j0G]  += 1.0;
                        FConMatrix[j1G, j0G] += 1.0;
                    }
                }
            }


            for (int jCell = 0; jCell < J; jCell++)
            {
                Debug.Assert(jCell + jCell0 == this.GridData.Cells.GetCell(jCell).GlobalID);
            }


            if (GridData.MpiSize == 1)
            {
                OpMatrix.SaveToFile("matrix.bin");
                ConMatrix.SaveToFile("conMtx.bin");
                ConMatrix2.SaveToFile("conMtx2.bin");

                //OpMatrix.SaveToTextFileSparse("C:\\tmp\\matrix1.txt");
            }
            else
            {
                var compOpMatrix   = MsrMatrix.LoadFromFile("matrix.bin", csMPI.Raw._COMM.WORLD, OpMatrix.RowPartitioning, OpMatrix.ColPartition);
                var compConMatrix  = MsrMatrix.LoadFromFile("conMtx.bin", csMPI.Raw._COMM.WORLD, ConMatrix.RowPartitioning, ConMatrix.ColPartition);
                var compConMatrix2 = MsrMatrix.LoadFromFile("conMtx2.bin", csMPI.Raw._COMM.WORLD, ConMatrix2.RowPartitioning, ConMatrix2.ColPartition);

                //OpMatrix.SaveToTextFileSparse("C:\\tmp\\matrix2.txt");

                compOpMatrix.Acc(-1.0, OpMatrix);
                compConMatrix.Acc(-1.0, ConMatrix);
                compConMatrix2.Acc(-1.0, ConMatrix2);

                double OpErrNrm   = compOpMatrix.InfNorm();
                double ConErrNrm  = compConMatrix.InfNorm();
                double Con2ErrNrm = compConMatrix.InfNorm();


                Console.WriteLine("Matrix Comparison: {0}, {1}, {2}", ConErrNrm, Con2ErrNrm, OpErrNrm);
            }
        }