Inspired by Henrik's answer, I think I find the root of problem: "Pardiso"
method of LinearSolve
is the culprit. According to the tutorial NDSolve Options for Finite Elements:
The finite element method uses the efficient direct PARDISO solver as the default linear solver.
Let's test Pardiso
:
n = 1000; m =
SparseArray[{{i_, i_} -> -2., {i_, j_} /; Abs[i - j] == 1 -> 1.}, {n, n}];
b = Table[0., {n}]; b[[99]] = 1.;
sollinear := LinearSolve[m, b, Method -> "Pardiso"]
sollinear - sollinear // Abs // Max
(* 2.13163*10^-12 *)
It's worth noting that n
should be large enough. For small system e.g. n = 100
, the randomness becomes 0.
. This explains why Alex's method works. (MaxCellMeasure -> 10^-2
actually results in a mesh coarser than default. )
If we turn to following methods for LinearSolve
, deterministic solution will be produced (in reasonable time):
solmethod[method_] :=
NDSolveValue[{Laplacian[u[x, y], {x, y}] + 1 == 0,
DirichletCondition[u[x, y] == 0, True]}, u, {x, 0, 1}, {y, 0, 1},
Method -> {"PDEDiscretization" -> {"FiniteElement",
"PDESolveOptions" -> {"LinearSolver" -> {Automatic, Method -> method}}}}]
Table[
solmethod[#] === solmethod[#] & /@ {"Multifrontal", "Krylov",
"IterativeRefinement", "Banded"}, {10}] // Flatten // Union
(* {True} *)
Still, this isn't the end: what if the Pardiso
method is necessary for certain equation solving? Is it possible to adjust option of Pardiso
method to remove its randomness?
sol
on the same mesh? $\endgroup$