public static void CellwiseSubSelection( [Values(SelectionType.all_combined, SelectionType.degrees, SelectionType.species, SelectionType.variables)] SelectionType SType ) { Utils.TestInit((int)SType); Console.WriteLine("SubSelection({0})", SType); //Arrange --- extracts entries of matrix according to hardcoded selection int DGdegree = 2; int GridResolution = 4; var mgo = Utils.CreateTestMGOperator(XDGusage.all, DGdegree, MatrixShape.full_var_spec, GridResolution); int sampleCellA = Utils.GetIdxOfFirstBlockWith(mgo.Mapping, false); //1 species int sampleCellB = Utils.GetIdxOfFirstBlockWith(mgo.Mapping, true); //2 species BlockMsrMatrix compA = Utils.GetCellCompMatrix(SType, mgo, sampleCellA); BlockMsrMatrix compB = Utils.GetCellCompMatrix(SType, mgo, sampleCellB); int iBlock = sampleCellB + mgo.Mapping.AggGrid.CellPartitioning.i0; int i0 = mgo.Mapping.GetBlockI0(iBlock); var block = MultidimensionalArray.Create(mgo.Mapping.GetBlockLen(iBlock), mgo.Mapping.GetBlockLen(iBlock)); mgo.OperatorMatrix.ReadBlock(i0, i0, block); //Arrange --- setup masking, which correspond to hardcoded SubBlockSelector sbsA = new SubBlockSelector(mgo.Mapping); sbsA.GetDefaultSelection(SType, sampleCellA); // single spec BlockMask maskA = new BlockMask(sbsA, null); SubBlockSelector sbsB = new SubBlockSelector(mgo.Mapping); sbsB.GetDefaultSelection(SType, sampleCellB); // double spec BlockMask maskB = new BlockMask(sbsB, null); //Arrange --- some time measurement Stopwatch stw = new Stopwatch(); stw.Reset(); //Act --- subblock extraction stw.Start(); var blocksA = maskA.GetDiagonalBlocks(mgo.OperatorMatrix, false, false); var blocksB = maskB.GetDiagonalBlocks(mgo.OperatorMatrix, false, false); stw.Stop(); //Assert --- Assert.IsTrue(blocksA.Length == 1); Assert.IsTrue(blocksB.Length == 1); Assert.IsTrue(compA.RowPartitioning.LocalLength == blocksA[0].GetLength(0)); Assert.IsTrue(compB.RowPartitioning.LocalLength == blocksB[0].GetLength(0)); //Assert --- compare masking of single spec cell Debug.Assert(compA.InfNorm() != 0.0); compA.AccBlock(0, 0, -1.0, blocksA[0]); Assert.IsTrue(compA.InfNorm() == 0.0); //Assert --- compare masking of double spec cell Debug.Assert(compB.InfNorm() != 0.0); compB.AccBlock(0, 0, -1.0, blocksB[0]); Assert.IsTrue(compB.InfNorm() == 0.0, String.Format("proc{0}: not fulfilled at block {1}", mgo.Mapping.MpiRank, sampleCellB)); }
public static void SubSelection( [Values(SelectionType.all_combined, SelectionType.degrees, SelectionType.species, SelectionType.variables)] SelectionType SType ) { Utils.TestInit((int)SType); Console.WriteLine("SubSelection({0})", SType); //Arrange --- extracts entries of matrix according to hardcoded selection int DGdegree = 2; int GridResolution = 4; var mgo = Utils.CreateTestMGOperator(XDGusage.all, DGdegree, MatrixShape.full_var_spec, GridResolution); int sampleCellA = Utils.GetIdxOfFirstBlockWith(mgo.Mapping, false); //1 species int sampleCellB = Utils.GetIdxOfFirstBlockWith(mgo.Mapping, true); //2 species BlockMsrMatrix compA = Utils.GetCellCompMatrix(SType, mgo, sampleCellA); BlockMsrMatrix compB = Utils.GetCellCompMatrix(SType, mgo, sampleCellB); //Arrange --- setup masking, which correspond to hardcoded SubBlockSelector sbsA = new SubBlockSelector(mgo.Mapping); sbsA.GetDefaultSelection(SType, sampleCellA); // single spec BlockMask maskA = new BlockMask(sbsA, null); SubBlockSelector sbsB = new SubBlockSelector(mgo.Mapping); sbsB.GetDefaultSelection(SType, sampleCellB); // double spec BlockMask maskB = new BlockMask(sbsB, null); //Arrange --- stop the watch Stopwatch stw = new Stopwatch(); stw.Reset(); //Act --- get subblocks stw.Start(); BlockMsrMatrix subA = maskA.GetSubBlockMatrix(mgo.OperatorMatrix); BlockMsrMatrix subB = maskB.GetSubBlockMatrix(mgo.OperatorMatrix); stw.Stop(); //Assert --- compare masking of single spec cell Debug.Assert(compA.InfNorm() != 0.0); subA.Acc(-1.0, compA); Assert.IsTrue(subA.InfNorm() == 0.0); //Assert --- compare masking of double spec cell Debug.Assert(compB.InfNorm() != 0.0); subB.Acc(-1.0, compB); Assert.IsTrue(subB.InfNorm() == 0.0); }