I have written the numerical scheme of PSOR (Projected Successive Over Relaxation) method of a obstacle program in 1D, which is as follows:
\begin{align*} &u_0=u_N=0\\ &u_i^{k+\frac{1}{2}}=(1-\omega)u_i^k+\omega\Big[ \frac{1}{2}\Big(u_{i-1}^{k+1}+u_{i+1}^k\big)+\frac{h^2}{2T}f_i\Big]\\ &u_i^{k+1}=\min\{g_i,u_i^{k+\frac{1}{2}}\} \end{align*}
where $g_i$ represents the obstacle function in $x_i$. For this case we can take $g$ as $$g=0.1(x-1)^2+0.02(x-1)+\frac{0.1}{(1+30(x-1)^2)}$$
I have tried to code it in Mathematica, however the output it's not correct. Could someone try to identify what is wrong with it? Thank you in advance!
MetPSOR1D[a_,b_,n_,Omega_,t_,tol_,itMax_] := (h=(b-a)/n;
T = Table[a+i*h,{i,0,n}];
With[{list = Table[0,{n+1}]},
Compile[{},
Module[{listold = list, listnew = list, error = tol + 1, f = 1},
For[k = 0, error > tol && k < itMax, k++,
listnew[[1]]=0;
listnew[[n+1]]=0;
For[i = 2, i < n+1, i++,
g = 0.1*(T[[i-1]]-1)^2 + 0.02*(T[[i-1]]-1) + 0.1/(1 + 30*(T[[i-1]]-1)^2);
u12 = (1-Omega)listold[[i]] + (Omega(listold[[i-1]] + listold[[i+1]] + (f/t) * h^2))/2;
aux = Min[{u12,g}];
listnew[[i]] = aux;
]
error = Max[Abs[listnew - listold]];
listold = listnew;
];
s = listnew;
]
]
]
); s
T
and the beginning of yourModule
expression. $\endgroup$For[...]
anderror = ...
. Also, you need to supply us with test data so we can run your code. $\endgroup$