public static void MapConsistencyTest( [Values(XDGusage.none, XDGusage.all)] XDGusage UseXdg, [Values(2)] int DGOrder ) { //if no selection is chosen mapping should be the same as of origin //assume: indexing is right 'cause of other tests Utils.TestInit((int)UseXdg, DGOrder); Console.WriteLine("MapConsistencyTest({0},{1})", UseXdg, DGOrder); //Arrange MultigridOperator MGOp = Utils.CreateTestMGOperator(UseXdg, DGOrder); var sbs = new SubBlockSelector(MGOp.Mapping); var mask = new BlockMask(sbs); var stw = new Stopwatch(); stw.Restart(); //Act --- Create Mapping from mask stw.Start(); var submatrix = mask.GetSubBlockMatrix(MGOp.OperatorMatrix); stw.Stop(); var rowpart = submatrix._RowPartitioning; var colpart = submatrix._ColPartitioning; //Assert --- Equal Partition of mask and origin Assert.AreEqual(rowpart, colpart); Assert.IsTrue(rowpart.IsLocallyEqual(MGOp.Mapping)); }
public WorldEditor(SegmentManager parent) { ParentSegmentManager = parent; _blockMasks = new List <BlockMask>(); _blockMasks.Add(BlockHelper.BlockMasks.Debug); _blockMasks.Add(BlockHelper.BlockMasks.Soil); _topRampMasks = new List <BlockMask>(); _topRampMasks.Add(BlockHelper.RampBlockMasks.Top.Debug); _topRampMasks.Add(BlockHelper.RampBlockMasks.Top.Soil); _bottomRampMasks = new List <BlockMask>(); _bottomRampMasks.Add(BlockHelper.RampBlockMasks.Bottom.Debug); _bottomRampMasks.Add(BlockHelper.RampBlockMasks.Bottom.Soil); _index = 0; _selectedType = EditorType.Blocks; _keyboardCursor = new SegmentLocation(Vector3.Zero); _RampBlockDirection = RampBlockDirection.North; _activeBlockMask = BlockHelper.BlockMasks.Soil; _previewData = new BlockVertexData(); }
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 void SetBlockMaskAt(SegmentLocation segmentLocation, BlockMask blockMask) { if (IsLocationInRange(segmentLocation)) { // can't place block on obstructed air as its an item! if (GetBlockMaskAt(segmentLocation) == BlockHelper.BlockMasks.AirBlocked) { return; } // can't delete block with item above it! if (blockMask == BlockHelper.BlockMasks.Air) { if (GetBlockMaskAt(segmentLocation.TranslateAndClone(new Vector3(0, 1, 0))) == BlockHelper.BlockMasks.AirBlocked) { return; } } GetRenderSegmentAt(segmentLocation).Blocks[ segmentLocation.BlockX, segmentLocation.RenderSegmentBlockMaskIndex, segmentLocation.BlockZ] = blockMask; // Mark all around it as dirty. SetLocationDirty(segmentLocation); SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.Up)); SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.Down)); SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.North)); SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.East)); SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.South)); SetLocationDirty(segmentLocation.TranslateAndClone(WorldDirection.West)); } }
public void RemoveFlagAt(SegmentLocation segmentLocation, BlockMask flag) { if (IsLocationInRange(segmentLocation)) { SetBlockMaskAt(segmentLocation, GetBlockMaskAt(segmentLocation) & ~flag); } }
public static void GetExternalRowsTest( [Values(XDGusage.none, XDGusage.all)] XDGusage UseXdg, [Values(2)] int DGOrder, [Values(4)] int Res) { //Matlabaufruf --> gesamte Matrix nach Matlab schreiben //Teilmatritzen gemäß Globalid extrahieren //Mit ExternalRows vergleichen //Die große Frage: funktioniert der batchmode connector parallel? Beim rausschreiben beachten Utils.TestInit((int)UseXdg, DGOrder); Console.WriteLine("GetExternalRowsTest({0},{1})", UseXdg, DGOrder); //Arrange --- setup mgo and mask MultigridOperator mgo = Utils.CreateTestMGOperator(UseXdg, DGOrder, MatrixShape.laplace, Res); MultigridMapping map = mgo.Mapping; BlockMsrMatrix M = mgo.OperatorMatrix; //Delete this plz ... //M.SaveToTextFileSparse("M"); //int[] A = Utils.GimmeAllBlocksWithSpec(map, 9); //int[] B = Utils.GimmeAllBlocksWithSpec(map, 18); //if (map.MpiRank == 0) { // A.SaveToTextFileDebug("ACells"); // B.SaveToTextFileDebug("BCells"); //} var selector = new SubBlockSelector(map); var dummy = new BlockMsrMatrix(map); // we are only interested in getting indices, so a dummy is sufficient var mask = new BlockMask(selector, dummy); //Arrange --- get stuff to put into matlab int[] GlobalIdx_ext = Utils.GetAllExtCellIdc(map); double[] GlobIdx = GlobalIdx_ext.Length.ForLoop(i => (double)GlobalIdx_ext[i] + 1.0); //Arrange --- get external rows by mask BlockMsrMatrix extrows = BlockMask.GetAllExternalRows(mgo.Mapping, mgo.OperatorMatrix); //Assert --- idc and rows of extrows have to be the same Assert.IsTrue(GlobIdx.Length == extrows._RowPartitioning.LocalLength); //Arrange --- get external rows by matlab var infNorm = MultidimensionalArray.Create(1, 1); using (BatchmodeConnector matlab = new BatchmodeConnector()) { //note: BatchmodeCon maybe working on proc0 but savetotxt file, etc. (I/O) is full mpi parallel //so concider this as full mpi-parallel matlab.PutSparseMatrix(M, "M"); matlab.PutSparseMatrix(extrows, "M_test"); matlab.PutVector(GlobIdx, "Idx"); matlab.Cmd(String.Format("M_ext = M(Idx, :);")); matlab.Cmd("n=norm(M_test-M_ext,inf)"); matlab.GetMatrix(infNorm, "n"); matlab.Execute(); } //Assert --- test if we actually got the right Matrix corresponding to Index Assert.IsTrue(infNorm[0, 0] == 0.0); }
public static BlockVertexData GetBlockMaskVertexData(BlockMask blockMask) { if (BlockHelper.IsBlock(blockMask)) { return(_blockData[BlockHelper.GetBlockID(blockMask)]); } return(new BlockVertexData()); }
public static BlockMask RotateRampTo(BlockMask blockMask, BlockMask direction) { // unset direction blockMask = blockMask | ~BlockMask.Data1 | ~BlockMask.Data2; // set new direciton blockMask = blockMask | direction; return(blockMask); }
public static void SubSelection( [Values(XDGusage.none, XDGusage.all)] XDGusage UseXdg, [Values(2)] int DGOrder, [Values(MatrixShape.full_var_spec, MatrixShape.full_spec, MatrixShape.full_var, MatrixShape.full)] MatrixShape MShape, [Values(4)] int Res) { Utils.TestInit((int)UseXdg, DGOrder, (int)MShape, Res); Console.WriteLine("SubSelection({0},{1},{2},{3})", UseXdg, DGOrder, MShape, Res); //Arrange --- create test matrix, MG mapping MultigridOperator mgo = Utils.CreateTestMGOperator(UseXdg, DGOrder, MShape, Res); MultigridMapping map = mgo.Mapping; BlockMsrMatrix M = mgo.OperatorMatrix; //Arrange --- get mask int[] cells = Utils.GetCellsOfOverlappingTestBlock(map); Array.Sort(cells); var sbs = new SubBlockSelector(map); sbs.CellSelector(cells, false); BlockMsrMatrix M_ext = BlockMask.GetAllExternalRows(map, M); var mask = new BlockMask(sbs, M_ext); //Arrange --- get GlobalIdxList int[] idc = Utils.GetIdcOfSubBlock(map, cells); bool[] coup = Utils.SetCoupling(MShape); var M_sub = mask.GetSubBlockMatrix(M, false, coup[0], coup[1]); var infNorm = MultidimensionalArray.Create(4, 1); int rank = map.MpiRank; using (BatchmodeConnector matlab = new BatchmodeConnector()) { double[] GlobIdx = idc.Count().ForLoop(i => (double)idc[i] + 1.0); Assert.IsTrue(GlobIdx.Length == M_sub.NoOfRows); matlab.PutSparseMatrix(M, "M"); // note: M_sub lives on Comm_Self, therefore we have to distinguish between procs ... matlab.PutSparseMatrixRankExclusive(M_sub, "M_sub"); matlab.PutVectorRankExclusive(GlobIdx, "Idx"); matlab.Cmd("M_0 = full(M(Idx_0, Idx_0));"); matlab.Cmd("M_1 = full(M(Idx_1, Idx_1));"); matlab.Cmd("M_2 = full(M(Idx_2, Idx_2));"); matlab.Cmd("M_3 = full(M(Idx_3, Idx_3));"); matlab.Cmd("n=[0; 0; 0; 0];"); matlab.Cmd("n(1,1)=norm(M_0-M_sub_0,inf);"); matlab.Cmd("n(2,1)=norm(M_1-M_sub_1,inf);"); matlab.Cmd("n(3,1)=norm(M_2-M_sub_2,inf);"); matlab.Cmd("n(4,1)=norm(M_3-M_sub_3,inf);"); matlab.GetMatrix(infNorm, "n"); matlab.Execute(); } Assert.IsTrue(infNorm[rank, 0] == 0.0); }
public void BlockMask_Internals() { var mask = new BlockMask(".", new Block('('), new Block('0', 2, 2), new Block(')')); mask.Clear(); // make sure it is initialized mask.Mask.Should().Be(@"^\(([\.](\d(\d([\.](\))?)?)?)?)?$"); mask = new BlockMask(".", new Block('0', 1, 2), new Block('0', 1, 2), new Block('0', 2, 4)); mask.Clear(); // make sure it is initialized mask.Mask.Should().Be(@"^\d(\d)?([\.](\d(\d)?([\.](\d(\d(\d(\d)?)?)?)?)?)?)?$"); Assert.Throws <ArgumentException>(() => new BlockMask()); }
public static void SplitVectorOperations( XDGusage UseXdg, int DGOrder, MatrixShape MShape ) { Utils.TestInit((int)UseXdg, DGOrder, (int)MShape); Console.WriteLine("SplitVectorOperations({0},{1},{2})", UseXdg, DGOrder, MShape); //matrix Erzeugung wie in ExtractDiagonalCellBlocks... //Auf der HierarchieEbene, auf der Kopplung ausgesetzt wird kann Auswahl vorgenommen werden //bei var: 0 / 1, bei DG: <=1 / >1, bei spec: A / B, bei Cells: odd / even //accumulierte Teilergebnisse sind dann == fullM*fullX var mop = Utils.CreateTestMGOperator(UseXdg, DGOrder, MShape); var map = mop.Mapping; double[] Vec = Utils.GetRandomVector(mop.Mapping.LocalLength); //Arrange --- setup masking SubBlockSelector sbsA = new SubBlockSelector(map); sbsA.SetDefaultSplitSelection(MShape, true); BlockMask maskA = new BlockMask(sbsA, null); SubBlockSelector sbsB = new SubBlockSelector(map); sbsB.SetDefaultSplitSelection(MShape, false); BlockMask maskB = new BlockMask(sbsB, null); double[] VecAB = new double[Vec.Length]; //Arrange --- some time measurement Stopwatch stw = new Stopwatch(); stw.Reset(); //Act --- stw.Start(); var VecA = maskA.GetSubVec(Vec); var VecB = maskB.GetSubVec(Vec); maskA.AccSubVec(VecA, VecAB); maskB.AccSubVec(VecB, VecAB); stw.Stop(); Debug.Assert(Vec.L2Norm() != 0); double fac = ((MShape == MatrixShape.full_var || MShape == MatrixShape.diagonal_var) && UseXdg == XDGusage.none) ? -2.0 : -1.0; VecAB.AccV(fac, Vec); //Assert --- are extracted blocks and Assert.IsTrue(VecAB.L2Norm() == 0.0, String.Format("L2Norm neq 0!")); }
public static void VectorSplitOperation( [Values(XDGusage.none, XDGusage.all)] XDGusage UseXdg, [Values(2)] int DGOrder, [Values(MatrixShape.full_var_spec, MatrixShape.full_spec, MatrixShape.full)] MatrixShape MShape, [Values(4)] int Res) { Utils.TestInit((int)UseXdg, DGOrder, (int)MShape, Res); Console.WriteLine("VectorSplitOperation({0},{1},{2},{3})", UseXdg, DGOrder, MShape, Res); //Arrange --- create test matrix, MG mapping MultigridOperator mgo = Utils.CreateTestMGOperator(UseXdg, DGOrder, MShape, Res); MultigridMapping map = mgo.Mapping; BlockMsrMatrix M = mgo.OperatorMatrix; BlockMsrMatrix M_ext = BlockMask.GetAllExternalRows(map, M); double[] Vec = Utils.GetRandomVector(M_ext.RowPartitioning.LocalLength); //Arrange --- setup masking SubBlockSelector sbsA = new SubBlockSelector(map); sbsA.SetDefaultSplitSelection(MShape, true, false); BlockMask maskA = new BlockMask(sbsA, M_ext); SubBlockSelector sbsB = new SubBlockSelector(map); sbsB.SetDefaultSplitSelection(MShape, false, false); BlockMask maskB = new BlockMask(sbsB, M_ext); double[] VecAB = new double[Vec.Length]; //Arrange --- some time measurement Stopwatch stw = new Stopwatch(); stw.Reset(); //Act --- stw.Start(); var VecA = maskA.GetSubVec(Vec, new double[0]); var VecB = maskB.GetSubVec(Vec, new double[0]); maskA.AccSubVec(VecA, VecAB, new double[0]); maskB.AccSubVec(VecB, VecAB, new double[0]); stw.Stop(); Debug.Assert(Vec.L2Norm() != 0); double fac = ((MShape == MatrixShape.full_var || MShape == MatrixShape.diagonal_var) && UseXdg == XDGusage.none) ? -2.0 : -1.0; VecAB.AccV(fac, Vec); //Assert --- are extracted blocks and Assert.IsTrue(VecAB.L2Norm() == 0.0, String.Format("L2Norm neq 0!")); }
/// <inheritdoc/> public override string ToString() { string blockCellsStr = new CellCollection(BlockCells).ToString(); string blockDigitsStr = new DigitCollection(BlockMask.GetAllSets()).ToString(null); string lineCellsStr = new CellCollection(LineCells).ToString(); string lineDigitsStr = new DigitCollection(LineMask.GetAllSets()).ToString(null); string interCellsStr = new CellCollection(IntersectionCells).ToString(); string interDigitsStr = new DigitCollection(IntersectionMask.GetAllSets()).ToString(null); string elimStr = new ConclusionCollection(Conclusions).ToString(); return ($"{Name}: {interCellsStr}({interDigitsStr}) - " + $"{blockCellsStr}({blockDigitsStr}) & {lineCellsStr}({lineDigitsStr}) => {elimStr}"); }
public void Fill(BlockMask mask) { for (int x = 0; x < Blocks.GetLength(0); x++) { for (int y = 0; y < Blocks.GetLength(1); y++) { for (int z = 0; z < Blocks.GetLength(2); z++) { Blocks[x, y, z] = mask; } } } Dirty = true; }
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); }
public static void CellBlockVectorOperations( [Values(XDGusage.none, XDGusage.all)] XDGusage UseXdg, [Values(2)] int DGOrder, [Values(MatrixShape.diagonal, MatrixShape.diagonal_var, MatrixShape.diagonal_spec, MatrixShape.diagonal_var_spec)] MatrixShape MShape ) { //matrix Erzeugung wie in ExtractDiagonalCellBlocks... //Auf der HierarchieEbene, auf der Kopplung ausgesetzt wird kann Auswahl vorgenommen werden //bei var: 0 / 1, bei DG: <=1 / >1, bei spec: A / B, bei Cells: odd / even //accumulierte Teilergebnisse sind dann == fullM*fullX Utils.TestInit((int)UseXdg, DGOrder, (int)MShape); Console.WriteLine("CellBlockVectorOperations({0},{1},{2})", UseXdg, DGOrder, MShape); var mop = Utils.CreateTestMGOperator(UseXdg, DGOrder, MShape); var map = mop.Mapping; double[] Vec = Utils.GetRandomVector(mop.Mapping.LocalLength); //Arrange --- setup masking SubBlockSelector SBS = new SubBlockSelector(map); BlockMask mask = new BlockMask(SBS, null); //Arrange --- some time measurement Stopwatch stw = new Stopwatch(); stw.Reset(); //Assert --- all diagonal blocks are extracted //Assert.IsTrue(blocks.Length == map.LocalNoOfBlocks); double[] Vec_col = new double[map.LocalLength]; for (int i = 0; i < map.LocalNoOfBlocks; i++) { stw.Start(); double[] Vec_i = mask.GetSubVecOfCell(Vec, i); mask.AccSubVecOfCell(Vec_i, i, Vec_col); stw.Stop(); } Vec_col.AccV(-1.0, Vec); //Assert --- are extracted blocks and Assert.IsTrue(Vec_col.L2Norm() == 0.0, String.Format("L2Norm neq 0!")); }
public static BlockMask GetRampBlockDirection(BlockMask blockMask) { if (blockMask.HasFlag(RampBlockDirection.West)) { return(RampBlockDirection.West); } if (blockMask.HasFlag(RampBlockDirection.East)) { return(RampBlockDirection.East); } if (blockMask.HasFlag(RampBlockDirection.South)) { return(RampBlockDirection.South); } return(RampBlockDirection.North); }
public bool IsLocationWalkable(SegmentLocation segmentLocation) { if (IsLocationInRange(segmentLocation)) { if (IsLocationObstructed(segmentLocation)) { return(false); } BlockMask blockBelow = GetBlockMaskAt(segmentLocation.TranslateAndClone(WorldDirection.Down)); if (BlockHelper.IsBlock(blockBelow) || BlockHelper.HasTopRamp(blockBelow)) { return(true); } } return(false); }
public static BlockVertexData GetCopyOfBlockMasBlockVertexData(BlockMask blockMask) { BlockVertexData toCopy = GetBlockMaskVertexData(blockMask); BlockVertexData toReturn = new BlockVertexData(); toReturn.UpIndices = toCopy.UpIndices; toReturn.UpVertices = toCopy.UpVertices; toReturn.DownIndices = toCopy.DownIndices; toReturn.DownVertices = toCopy.DownVertices; toReturn.NorthIndices = toCopy.NorthIndices; toReturn.NorthVertices = toCopy.NorthVertices; toReturn.EastIndices = toCopy.EastIndices; toReturn.EastVertices = toCopy.EastVertices; toReturn.SouthIndices = toCopy.SouthIndices; toReturn.SouthVertices = toCopy.SouthVertices; toReturn.WestIndices = toCopy.WestIndices; toReturn.WestVertices = toCopy.WestVertices; return(toReturn); }
public void BlockMask_UpdateFrom() { var mask = new BlockMask(".", new Block('('), new Block('0', 2, 2), new Block(')')); mask.Blocks.Length.Should().Be(3); mask.Delimiters.Should().Be("."); mask.SetText("(1234)"); mask.ToString().Should().Be("(.12.)|"); mask.CaretPos = 1; mask.UpdateFrom(new BlockMask(":", new Block('0', 1, 1), new Block('0', 1, 1))); mask.Blocks.Length.Should().Be(2); mask.Delimiters.Should().Be(":"); // state should be preserved (Text, Caret/Selection) mask.ToString().Should().Be("1|:2"); mask.UpdateFrom(null); mask.Blocks.Length.Should().Be(2); mask.Delimiters.Should().Be(":"); // state should be preserved (Text, Caret/Selection) mask.ToString().Should().Be("1|:2"); }
public void BlockMask_Insert() { var mask = new BlockMask(".", new Block('0', 1, 2), new Block('0', 1, 2), new Block('0', 2, 4)); mask.ToString().Should().Be("|"); mask.Insert("12."); mask.ToString().Should().Be("12.|"); mask.Clear(); mask.Insert("xx12.34xx.5678"); mask.Text.Should().Be("12.34.5678"); mask.Clear(); mask.Insert("1.1.99"); mask.ToString().Should().Be("1.1.99|"); mask.CaretPos = 0; mask.Insert("0"); mask.ToString().Should().Be("0|1.1.99"); mask.Insert("0"); mask.ToString().Should().Be("00|.1.199"); mask.Insert("0"); mask.ToString().Should().Be("00.0|.1199"); mask.Insert("0"); mask.ToString().Should().Be("00.00|.1199"); // w/o separator mask = new BlockMask("", new Block('0', 1, 2), new Block('a', 1, 2), new Block('0', 2, 4)); mask.Insert("xx12.34xx.5678"); mask.Text.Should().Be("12xx5678"); mask.Clear(); mask.Insert("1.x.99"); mask.ToString().Should().Be("1x99|"); mask.CaretPos = 0; mask.Insert("0"); mask.ToString().Should().Be("0|1x99"); mask.Insert("0"); mask.ToString().Should().Be("00|x99"); mask.Insert("y"); mask.ToString().Should().Be("00y|x99"); mask.Insert("z"); mask.ToString().Should().Be("00yz|99"); mask.Insert("1"); mask.ToString().Should().Be("00yz1|99"); }
public static void SubMatrixExtractionWithCoupling( [Values(XDGusage.none, XDGusage.all)] XDGusage UseXdg, [Values(2)] int DGOrder, [Values(MatrixShape.diagonal, MatrixShape.diagonal_var, MatrixShape.full_spec, MatrixShape.full_var_spec)] MatrixShape MShape ) { Utils.TestInit((int)UseXdg, DGOrder, (int)MShape); Console.WriteLine("ExtractSubMatrixAndIgnoreCoupling({0},{1},{2})", UseXdg, DGOrder, MShape); //Arrange --- get multigridoperator MultigridOperator MGOp = Utils.CreateTestMGOperator(UseXdg, DGOrder, MShape); BlockMsrMatrix M = MGOp.OperatorMatrix; MultigridMapping map = MGOp.Mapping; //Arrange --- setup masking SubBlockSelector SBS = new SubBlockSelector(map); BlockMask mask = new BlockMask(SBS, null); bool[] coup = Utils.SetCoupling(MShape); //Arrange --- some time measurement Stopwatch stw = new Stopwatch(); stw.Reset(); //Act --- establish submatrix stw.Start(); //var Ones = M.CloneAs(); //Ones.Clear(); //Ones.SetAll(1); //var extractOnes = mask.GetSubBlockMatrix(Ones, false, coup[0], coup[1]); var Mext = mask.GetSubBlockMatrix(M, false, coup[0], coup[1]); stw.Stop(); var Mquad = M.ConvertToQuadraticBMsr(mask.GlobalIList_Internal.ToArray(), true); Mext.Acc(-1.0, Mquad); //Assert --- Mext conains only diagonal blocks of M Assert.IsTrue(Mext.InfNorm() == 0); }
public void BlockMask_Backspace() { var mask = new BlockMask(".", new Block('0', 1, 2), new Block('0', 1, 2), new Block('0', 2, 4)); mask.ToString().Should().Be("|"); mask.Insert("12.34.5678"); mask.ToString().Should().Be("12.34.5678|"); mask.Backspace(); mask.ToString().Should().Be("12.34.567|"); mask.CaretPos = 3; mask.ToString().Should().Be("12.|34.567"); mask.Backspace(); mask.ToString().Should().Be("1|3.4.567"); mask.Backspace(); mask.ToString().Should().Be("|3.4.567"); mask.Backspace(); mask.ToString().Should().Be("|3.4.567"); mask.Selection = (2, 3); mask.Backspace(); mask.ToString().Should().Be("3.|56.7"); }
/// <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); } }
public static void ExternalIndexTest( [Values(XDGusage.none, XDGusage.all)] XDGusage UseXdg, [Values(2)] int DGOrder, [Values(4)] int Res ) { Utils.TestInit((int)UseXdg, DGOrder); Console.WriteLine("ExternalIndexTest({0},{1})", UseXdg, DGOrder); //Arrange --- Get global index by mapping MultigridOperator MGOp = Utils.CreateTestMGOperator(UseXdg, DGOrder, MatrixShape.laplace, Res); var map = MGOp.Mapping; int[] GlobalIdxMap_ext = Utils.GetAllExtCellIdc(map); //Arrange --- Prepare stuff for mask var selector = new SubBlockSelector(map); var dummy = new BlockMsrMatrix(map); // we are only interested in getting indices, so a dummy is sufficient var stw = new Stopwatch(); stw.Reset(); //Act --- do the masking to get index lists stw.Start(); var mask = new BlockMask(selector, dummy); stw.Stop(); int[] GlobalIdxMask_ext = mask.GlobalIList_External.ToArray(); //Assert --- Idx lists are of same length Assert.IsTrue(GlobalIdxMap_ext.Length == GlobalIdxMask_ext.Length); //Assert --- Compare map and mask indices for (int iLoc = 0; iLoc < GlobalIdxMask_ext.Length; iLoc++) { Assert.IsTrue(GlobalIdxMask_ext[iLoc] == GlobalIdxMap_ext[iLoc]); } }
/// <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); }
public static void LocalIndexTest( [Values(XDGusage.none, XDGusage.all)] XDGusage UseXdg, [Values(2)] int DGOrder) { Utils.TestInit((int)UseXdg, DGOrder); Console.WriteLine("LocalLIndexTest({0},{1})", UseXdg, DGOrder); //Arrange --- Get global index by mapping MultigridOperator MGOp = Utils.CreateTestMGOperator(UseXdg, DGOrder); var map = MGOp.Mapping; int[] fields = map.NoOfVariables.ForLoop(i => i); int[] GlobalIdxMap_loc = map.GetSubvectorIndices(fields); //Arrange --- Prepare stuff for mask var selector = new SubBlockSelector(map); var stw = new Stopwatch(); stw.Reset(); //Act --- do the masking to get index lists stw.Start(); var mask = new BlockMask(selector, null); stw.Stop(); int[] GlobalIdxMask_loc = mask.GlobalIList_Internal.ToArray(); //Assert --- Idx lists are of same length Assert.IsTrue(GlobalIdxMap_loc.Length == GlobalIdxMask_loc.Length); //Assert --- Compare map and mask indices for (int iLoc = 0; iLoc < GlobalIdxMask_loc.Length; iLoc++) { Assert.True(GlobalIdxMap_loc[iLoc] == GlobalIdxMask_loc[iLoc]); } }
public void BlockMask_Delete() { var mask = new BlockMask(".", new Block('0', 1, 2), new Block('0', 1, 2), new Block('0', 2, 4)); mask.ToString().Should().Be("|"); mask.Insert("12.34.5678"); mask.ToString().Should().Be("12.34.5678|"); mask.Delete(); mask.ToString().Should().Be("12.34.5678|"); mask.CaretPos = 0; mask.Delete(); mask.ToString().Should().Be("|2.34.5678"); mask.Delete(); mask.ToString().Should().Be("|34.56.78"); mask.SetText("12."); mask.Selection = (0, 2); mask.Delete(); mask.ToString().Should().Be("|"); mask.Insert("12345"); mask.ToString().Should().Be("12.34.5|"); mask.CaretPos = 5; mask.Delete(); mask.ToString().Should().Be("12.34|"); }
public void Update() { bool changed = false; // SHIFT if (InputHelper.IsKeyDown(Keys.LeftShift) || InputHelper.IsKeyDown(Keys.RightShift)) { if (InputHelper.IsNewKeyPress(Keys.Right)) { if (_RampBlockDirection == RampBlockDirection.North) { _RampBlockDirection = RampBlockDirection.East; } else if (_RampBlockDirection == RampBlockDirection.East) { _RampBlockDirection = RampBlockDirection.South; } else if (_RampBlockDirection == RampBlockDirection.South) { _RampBlockDirection = RampBlockDirection.West; } else if (_RampBlockDirection == RampBlockDirection.West) { _RampBlockDirection = RampBlockDirection.North; } changed = true; } if (InputHelper.IsNewKeyPress(Keys.Left)) { if (_RampBlockDirection == RampBlockDirection.North) { _RampBlockDirection = RampBlockDirection.West; } else if (_RampBlockDirection == RampBlockDirection.East) { _RampBlockDirection = RampBlockDirection.North; } else if (_RampBlockDirection == RampBlockDirection.South) { _RampBlockDirection = RampBlockDirection.East; } else if (_RampBlockDirection == RampBlockDirection.West) { _RampBlockDirection = RampBlockDirection.South; } changed = true; } } else { if (InputHelper.IsNewKeyPress(Keys.Up)) { switch (_selectedType) { case EditorType.Blocks: _selectedType = EditorType.BottomRamps; break; case EditorType.BottomRamps: _selectedType = EditorType.TopRamps; break; case EditorType.TopRamps: _selectedType = EditorType.Blocks; break; default: _previewData = new BlockVertexData(); break; } changed = true; } if (InputHelper.IsNewKeyPress(Keys.Down)) { switch (_selectedType) { case EditorType.Blocks: _selectedType = EditorType.TopRamps; break; case EditorType.BottomRamps: _selectedType = EditorType.Blocks; break; case EditorType.TopRamps: _selectedType = EditorType.BottomRamps; break; default: _previewData = new BlockVertexData(); break; } changed = true; } if (InputHelper.IsNewKeyPress(Keys.Right)) { _index++; if (_index >= CountCurrentList()) { _index = 0; } changed = true; } if (InputHelper.IsNewKeyPress(Keys.Left)) { _index--; if (_index < 0) { _index = CountCurrentList() - 1; } changed = true; } } if (changed) { switch (_selectedType) { case EditorType.Blocks: _activeBlockMask = _blockMasks[_index]; _previewData = BlockVertexData.GetBlockMaskVertexData(_blockMasks[_index]).Copy(); break; case EditorType.BottomRamps: _activeBlockMask = _bottomRampMasks[_index] | _RampBlockDirection; _previewData = RampBlockVertexData.GetBlockMaskVertexData(_bottomRampMasks[_index] | _RampBlockDirection).Copy(); break; case EditorType.TopRamps: _activeBlockMask = _topRampMasks[_index] | _RampBlockDirection; _previewData = RampBlockVertexData.GetBlockMaskVertexData(_topRampMasks[_index] | _RampBlockDirection).Copy(); break; default: _previewData = new BlockVertexData(); break; } } HandleHighlight(); }
public void DrawModels(Camera3D camera) { BlockMask maskAtCursor = ParentSegmentManager.GetBlockMaskAt(_keyboardCursor); switch (_selectedType) { case EditorType.Blocks: if (ParentSegmentManager.IsLocationObstructed(_keyboardCursor)) { _blockHighlightBlocked.Draw(ParentSegmentManager.Device, camera, _keyboardCursor.WorldLocation, Vector3.Zero, 0f, new Vector3(1, 1, 1)); } else { _blockHighlight.Draw(ParentSegmentManager.Device, camera, _keyboardCursor.WorldLocation, Vector3.Zero, 0f, new Vector3(1, 1, 1)); } break; case EditorType.BottomRamps: if (BlockHelper.HasTopRamp(maskAtCursor) && BlockHelper.GetRampBlockDirection(maskAtCursor) == _RampBlockDirection) { _blockHighlight.Draw(ParentSegmentManager.Device, camera, _keyboardCursor.WorldLocation, Vector3.Zero, 0f, new Vector3(1, 1, 1)); } else { if (ParentSegmentManager.IsLocationObstructed(_keyboardCursor)) { _blockHighlightBlocked.Draw(ParentSegmentManager.Device, camera, _keyboardCursor.WorldLocation, Vector3.Zero, 0f, new Vector3(1, 1, 1)); } else { _blockHighlight.Draw(ParentSegmentManager.Device, camera, _keyboardCursor.WorldLocation, Vector3.Zero, 0f, new Vector3(1, 1, 1)); } } break; case EditorType.TopRamps: if (BlockHelper.HasBottomRamp(maskAtCursor) && BlockHelper.GetRampBlockDirection(maskAtCursor) == _RampBlockDirection) { _blockHighlight.Draw(ParentSegmentManager.Device, camera, _keyboardCursor.WorldLocation, Vector3.Zero, 0f, new Vector3(1, 1, 1)); } else { if (ParentSegmentManager.IsLocationObstructed(_keyboardCursor)) { _blockHighlightBlocked.Draw(ParentSegmentManager.Device, camera, _keyboardCursor.WorldLocation, Vector3.Zero, 0f, new Vector3(1, 1, 1)); } else { _blockHighlight.Draw(ParentSegmentManager.Device, camera, _keyboardCursor.WorldLocation, Vector3.Zero, 0f, new Vector3(1, 1, 1)); } } break; default: _previewData = new BlockVertexData(); break; } }