public BasicFluid2D(int max_x, int max_y) { if (max_x != max_y) throw new ArgumentException(); this.max_x = max_x; this.max_y = max_y; u_x = new double[max_x + 1, max_y]; u_y = new double[max_x, max_y + 1]; cells = new GridCell[max_x, max_y]; A = new SparseMatrix(max_x * max_y); for (int i = 0; i < max_x; i++) for (int j = 0; j < max_y; j++) { A[i * max_x + j, i * max_x + j] = 2 + (i == 0 || i + 1 == max_x ? 1 : 0) + (j == 0 || j + 1 == max_y ? 1 : 0); if (i > 0) A[(i - 1) * max_x + j, i * max_x + j] = A[i * max_x + j, (i - 1) * max_x + j] = -1; if (j > 0) A[i * max_x + j - 1, i * max_x + j] = A[i * max_x + j, i * max_x + j - 1] = -1; if (i < max_x - 1) A[(i + 1) * max_x + j, i * max_x + j] = A[i * max_x + j, (i + 1) * max_x + j] = -1; if (j < max_y - 1) A[i * max_x + j + 1, i * max_x + j] = A[i * max_x + j, i * max_x + j + 1] = -1; cells[i, j] = new GridCell(); //cells[i, j].Adiag = (short)(2 + (i == 0 || i + 1 == max_x ? 1 : 0) + (j == 0 || j + 1 == max_y ? 1 : 0)); //cells[i, j].Aplusi = (short)(i + 1 < max_x ? -1 : 0); //cells[i, j].Aplusj = (short)(j + 1 < max_y ? -1 : 0); if (new Vector2(i - max_x / 2, j - max_y / 2).LengthSquared < max_x * max_y / 16) cells[i, j].ImplicitSurface = 5; } using (TextWriter tw = new StreamWriter("output.txt")) tw.WriteLine(A.ToMatrixString(900, 900)); solver = new MathNet.Numerics.LinearAlgebra.Double.Solvers.Preconditioners.IncompleteLU(); solver.Initialize(A); p = new DenseVector(max_x * max_y); d = new DenseVector(max_x * max_y); }