예제 #1
0
파일: Utils.cs 프로젝트: rohitvuppala/BoSSS
        public static void GetDefaultSelection(this SubBlockSelector sbs, SelectionType SType, int iCell)
        {
            SpeciesId A = ((XdgAggregationBasis)sbs.GetMapping.AggBasis[0]).UsedSpecies[0];
            SpeciesId B = ((XdgAggregationBasis)sbs.GetMapping.AggBasis[0]).UsedSpecies[1];

            sbs.CellSelector(iCell, false);
            //do not change this, selection corresponds to hardcoded masking
            //see GetSubIndices
            switch (SType)
            {
            case SelectionType.degrees:
                sbs.ModeSelector(p => p == 1);
                break;

            case SelectionType.species:
                sbs.SpeciesSelector(A);
                break;

            case SelectionType.variables:
                sbs.VariableSelector(1);
                break;

            case SelectionType.all_combined:
                sbs.ModeSelector(p => p == 1);
                sbs.SpeciesSelector(A);
                sbs.VariableSelector(1);
                break;
            }
        }
예제 #2
0
파일: Utils.cs 프로젝트: rohitvuppala/BoSSS
        private static void DefaultVarSplit(this SubBlockSelector sbs, bool upper)
        {
            sbs.VariableSelector(upper ? 0 : 1);
            int NoOfVar = sbs.GetMapping.NoOfVariables;

            int[] OtherVars = (NoOfVar - 1).ForLoop(i => i + 1);
            if (upper)
            {
                sbs.VariableSelector(0);
            }
            else
            {
                sbs.VariableSelector(OtherVars);
            }
        }
예제 #3
0
        /// <summary>
        /// returns the condition number of the full matrix
        /// </summary>
        public double CondNumMatlab()
        {
            int[] DepVars       = this.VarGroup;
            var   grd           = m_map.GridDat;
            int   NoOfCells     = grd.Grid.NumberOfCells;
            int   NoOfBdryCells = grd.GetBoundaryCells().NoOfItemsLocally_WithExternal;


            var Mtx = m_MultigridOp.OperatorMatrix;



            // Blocks and selectors
            // ====================
            var InnerCellsMask = grd.GetBoundaryCells().Complement();

            var FullSel = new SubBlockSelector(m_MultigridOp.Mapping);

            FullSel.VariableSelector(this.VarGroup);


            // Matlab
            // ======

            double[] Full_0Vars = (new BlockMask(FullSel)).GlobalIndices.Select(i => i + 1.0).ToArray();

            MultidimensionalArray output = MultidimensionalArray.Create(2, 1);

            string[] names = new string[] { "Full_0Vars", "Inner_0Vars" };

            using (BatchmodeConnector bmc = new BatchmodeConnector()) {
                // if Octave should be used instead of Matlab....
                // BatchmodeConnector.Flav = BatchmodeConnector.Flavor.Octave;

                bmc.PutSparseMatrix(Mtx, "FullMatrix");

                bmc.PutVector(Full_0Vars, "Full_0Vars");

                bmc.Cmd("output = ones(2,1);");

                bmc.Cmd("output(1) = condest(FullMatrix(Full_0Vars,Full_0Vars));");


                bmc.GetMatrix(output, "output");
                bmc.Execute(false);

                double condestFull = output[0, 0];
                Debug.Assert(condestFull.MPIEquals(), "value does not match on procs");


                Console.WriteLine($"MATLAB condition number: {condestFull:0.###e-00}");


                return(condestFull);
            }
        }
예제 #4
0
        /// <summary>
        /// Local condition number formed by the block of each cell and its neighbors.
        /// </summary>
        /// <returns>
        /// one value per cell:
        /// - index: local cell index
        /// - content: condition number (one norm) of the local stencil
        /// </returns>
        public double[] StencilCondNumbers()
        {
            using (new FuncTrace()) {
                int J = m_map.LocalNoOfBlocks;
                Debug.Assert(J == m_map.GridDat.iLogicalCells.NoOfLocalUpdatedCells);

                var Mtx = m_MultigridOp.OperatorMatrix;
                Debug.Assert(Mtx._ColPartitioning.LocalNoOfBlocks == J);
                Debug.Assert(Mtx._RowPartitioning.LocalNoOfBlocks == J);

                var grd = m_MultigridOp.Mapping.AggGrid;

                double[] BCN = new double[J];
                for (int j = 0; j < J; j++)
                {
                    var LocBlk = grd.GetCellNeighboursViaEdges(j).Select(t => t.Item1).ToList();
                    LocBlk.Add(j);
                    for (int i = 0; i < LocBlk.Count; i++)
                    {
                        if (LocBlk[i] >= J)
                        {
                            LocBlk.RemoveAt(i);
                            i--;
                        }
                    }

                    var Sel = new SubBlockSelector(m_MultigridOp.Mapping);
                    Sel.VariableSelector(this.VarGroup);
                    Sel.CellSelector(LocBlk, global: false);
                    var Mask = new BlockMask(Sel);

                    MultidimensionalArray[,] Blocks = Mask.GetFullSubBlocks(Mtx, ignoreSpecCoupling: false, ignoreVarCoupling: false);

                    MultidimensionalArray FullBlock = Blocks.Cat();

                    BCN[j] = FullBlock.Cond('I');
                }
                return(BCN);
            }
        }
예제 #5
0
        /// <summary>
        /// Local condition number for the block formed by each cell.
        /// </summary>
        /// <returns>
        /// one value per cell:
        /// - index: local cell index
        /// - content: condition number (one norm) of the local stencil
        /// </returns>
        public double[] BlockCondNumbers()
        {
            int J = m_map.LocalNoOfBlocks;

            Debug.Assert(J == m_map.GridDat.iLogicalCells.NoOfLocalUpdatedCells);

            var Mtx = m_MultigridOp.OperatorMatrix;

            Debug.Assert(Mtx._ColPartitioning.LocalNoOfBlocks == J);
            Debug.Assert(Mtx._RowPartitioning.LocalNoOfBlocks == J);


            var Sel = new SubBlockSelector(m_MultigridOp.Mapping);

            Sel.VariableSelector(this.VarGroup);

            var Mask = new BlockMask(Sel);

            MultidimensionalArray[] Blocks = Mask.GetDiagonalBlocks(Mtx, ignoreSpecCoupling: false, ignoreVarCoupling: false);
            Debug.Assert(Blocks.Length == J);

            double[] BCN = new double[J];
            for (int j = 0; j < J; j++)
            {
#if DEBUG
                int N = this.VarGroup.Sum(iVar => m_MultigridOp.Mapping.AggBasis[iVar].GetLength(j, m_MultigridOp.Degrees[iVar]));
                Debug.Assert(Blocks[j].NoOfCols == N);
                Debug.Assert(Blocks[j].NoOfRows == N);

                int i0 = m_MultigridOp.Mapping.GlobalUniqueIndex(this.VarGroup.Min(), j, 0);
                Debug.Assert(Mtx[i0, i0] == Blocks[j][0, 0]);
#endif

                BCN[j] = Blocks[j].Cond();
            }

            return(BCN);
        }
예제 #6
0
        /// <summary>
        /// returns the condition number of the full matrix using MUMPS;
        /// Note:
        /// </summary>

        public double CondNumMUMPS()
        {
            using (new FuncTrace()) {
                int[] DepVars       = this.VarGroup;
                var   grd           = m_map.GridDat;
                int   NoOfCells     = grd.Grid.NumberOfCells;
                int   NoOfBdryCells = grd.GetBoundaryCells().NoOfItemsLocally_WithExternal;


                var Mtx = m_MultigridOp.OperatorMatrix;

                // Blocks and selectors
                // ====================
                var InnerCellsMask = grd.GetBoundaryCells().Complement();

                var FullSel = new SubBlockSelector(m_MultigridOp.Mapping);
                FullSel.VariableSelector(this.VarGroup);

                var InnerSel = new SubBlockSelector(m_MultigridOp.Mapping);
                InnerSel.VariableSelector(this.VarGroup);
                InnerSel.CellSelector(InnerCellsMask);


                // MUMPS condition number
                // ======================

                double condestFullMUMPS = (new BlockMask(FullSel)).GetSubBlockMatrix(Mtx).Condest_MUMPS();
                //double condestInnerMUMPS = 1.0;

                //if(InnerCellsMask.NoOfItemsLocally.MPISum() > 0) {
                //    condestInnerMUMPS = (new BlockMask(InnerSel)).GetSubBlockMatrix(Mtx).Condest_MUMPS();
                //}


                //return new[] { condestFullMUMPS, condestInnerMUMPS };
                return(condestFullMUMPS);
            }
        }