void calc() { FluidParticle p; int i; for (i = 0; i < particles.Length; i++) { p = particles[i]; p.UpdateForce(); p.tempV = p.currentV + Time.fixedDeltaTime * p.force; p.tempPos = p.Pos(); p.transform.localPosition += p.tempV * Time.fixedDeltaTime; } for (i = 0; i < particles.Length; i++) { p = particles[i]; p.Initate(ref A, ref B, ref X, i); //A.SetRow(i, values); } //X = A.Solve(B); //outPutMatrices(); //Debug.DebugBreak(); Solve(A, B, ref X); /*for (i = 0; i < particles.Length; i++) * { * if (X.At(i) < 0) * X.At(i, 0); * }*/ //X = A.SolveIterative(B, new BiCgStab()); outPutMatrices(); Debug.DebugBreak(); for (i = 0; i < particles.Length; i++) { p = particles[i]; if (p.particleDensity < p.freeSurfaceTerm) { p.pressure.Set(0, 0, 0); } else { p.pressure = calcPressure(p); //resultP = p.pressure; //Debug.DebugBreak(); } p.currentV = p.tempV + (-Time.fixedDeltaTime / p.DENSITY) * p.pressure; p.transform.localPosition = p.tempPos + p.currentV * Time.fixedDeltaTime; } A.Clear(); //B.Clear(); //X.Clear(); }
public void When_SwappingRows_Expect_Reference() { // Build the matrix var matrix = new SparseMatrix <double>(); // We want to test all possible combinations for the row! We need 5 elements to be able to test it for (var i = 0; i < 32; i++) { // Our counter "i" will represent in binary which elements need to be filled. var fill = i; for (var k = 0; k < 5; k++) { // Get whether or not the element needs to be filled if ((fill & 0x01) != 0) { var expected = k * 32 + i + 1; matrix.GetElement(new MatrixLocation(k + 1, i + 1)).Value = expected; } fill = (fill >> 1) & 0b011111; } } // Swap the two rows of interest matrix.SwapRows(2, 4); // Find the elements back for (var i = 0; i < 32; i++) { var fill = i; for (var k = 0; k < 5; k++) { // Get the current row to test (remember we swapped them!) var crow = k + 1; if (crow == 2) { crow = 4; } else if (crow == 4) { crow = 2; } if ((fill & 0x01) != 0) { var expected = k * 32 + i + 1; Assert.AreEqual(expected, matrix[crow, i + 1], 1e-12); } else { Assert.AreEqual(null, matrix.FindElement(new MatrixLocation(crow, i + 1))); } fill = (fill >> 1) & 0b011111; } } matrix.Clear(); }
void calc() { Particle2D p; int i; for (i = 0; i < particles.Length; i++) { p = particles[i]; p.InitVelocity(); } for (i = 0; i < particles.Length; i++) { p = particles[i]; p.UpdatePND(); p.Initiate(ref A, ref B, ref X, i); } Solve(A, B, ref X); for (i = 0; i < particles.Length; i++) { if (X.At(i) < 0) { X.At(i, 0); } } for (i = 0; i < particles.Length; i++) { p = particles[i]; //if (p.PND < p.freeSurfaceTerm) //p.PRESSURE.Set(0, 0); //else //{ p.PRESSURE = calcPressure(p); //} p.UpdateForce(); p.UpdateVelocity(); } A.Clear(); //B.Clear(); //X.Clear(); }
public void When_BuildingMatrix_Expect_CorrectLinks() { var size = 20; var rStep = 7; var cStep = 11; var matrix = new SparseMatrix <double>(); for (var c = 0; c < rStep * size; c += rStep) { for (var r = 0; r < cStep * size; r += cStep) { var row = r % size; var col = c % size; var expected = row * size + col + 1; matrix.GetElement(new MatrixLocation(row + 1, col + 1)).Value = expected; } } // Check links from left to right ISparseMatrixElement <double> element; for (var r = 0; r < size; r++) { element = matrix.GetFirstInRow(r + 1); for (var c = 0; c < size; c++) { var expected = r * size + c + 1; Assert.AreEqual(expected, element.Value, 1e-12); element = element.Right; } } // Check links from right to left for (var r = 0; r < size; r++) { element = matrix.GetLastInRow(r + 1); for (var c = size - 1; c >= 0; c--) { var expected = r * size + c + 1; Assert.AreEqual(expected, element.Value, 1e-12); element = element.Left; } } // Check links from top to bottom for (var c = 0; c < size; c++) { element = matrix.GetFirstInColumn(c + 1); for (var r = 0; r < size; r++) { var expected = r * size + c + 1; Assert.AreEqual(expected, element.Value, 1e-12); element = element.Below; } } // Check links from bottom to top for (var c = 0; c < size; c++) { element = matrix.GetLastInColumn(c + 1); for (var r = size - 1; r >= 0; r--) { var expected = r * size + c + 1; Assert.AreEqual(expected, element.Value, 1e-12); element = element.Above; } } matrix.Clear(); }
public void AddingAfterClearingMatrix() { var matrix = new SparseMatrix <int>(); int maxRowsNumber = 1000; int maxColsNumber = 500; int rowIncrease = 3; int colIncrease = 2; int itemsCount = 0; for (int i = 0; i < maxRowsNumber; i += rowIncrease) { for (int j = 0; j < maxColsNumber; j += colIncrease) { if (!matrix.IsCellEmpty(i, j)) { Assert.Fail(); } matrix[i, j] = 5; itemsCount++; if (matrix.IsCellEmpty(i, j)) { Assert.Fail(); } } } if (matrix.Count != itemsCount) { Assert.Fail(); } itemsCount = 0; matrix.Clear(); if (matrix.Count != 0 || matrix.Height != 0 || matrix.Width != 0) { Assert.Fail(); } for (int i = 0; i < maxRowsNumber; i += rowIncrease) { for (int j = 0; j < maxColsNumber; j += colIncrease) { if (!matrix.IsCellEmpty(i, j)) { Assert.Fail(); } matrix[i, j] = 5; itemsCount++; if (matrix.IsCellEmpty(i, j)) { Assert.Fail(); } } } Assert.IsTrue(matrix.Count == itemsCount && matrix.Height == (maxRowsNumber - 1) / rowIncrease * rowIncrease + 1 && matrix.Width == (maxColsNumber - 1) / colIncrease * colIncrease + 1); }