Finite element (1D) for steady state non-linear problem
I need to solve with linear finite elements the equation $$\frac{\partial }{\partial x}\Bigl(\text{sgn}(x) u \Big) +\frac{\partial}{\partial x} \Bigl[ \sqrt{u} \frac{\partial u}{\partial x} \Bigr] =0$$
with boundary conditions $u(-L)=u(L)=0$ where $L=6$
(It's the steady state version of the equation described here: https://scicomp.stackexchange.com/questions/35955/non-linear-advection-diffusion-with-nondifferetiable-advection-term)
I take $v \in H_0^1(-L,L)$ and after the usual steps I obtain $$- \int u(x) \text{sgn}(x) v' dx - \int \sqrt{u} u' v' dx = 0$$
Then, using linear finite elements: $$- \int \sum_{j} u_j \phi_j(x) \phi_i'(x) \text{sgn}(x)dx - \int \Bigl( \sum_k \sqrt{u_k \phi_k} \Bigr) \sum_j u_j \phi_j' \phi_i' dx = 0$$
which leads to the non-linear system (setting $U=[u_0,\ldots,u_N]$)
$$-C U -A(U) U =$$
where $(C){ij} = \int \sum{j} u_j \phi_j(x) \phi_i'(x) \text{sgn}(x)dx $
and $\Bigl(A(U)\Bigr)_{ij} =\int \Bigl( \sum_k \sqrt{u_k \phi_k} \Bigr) \sum_j u_j \phi_j' \phi_i' dx$
Now, I want to solve this non-linear equation with fix-point iterations, so I set $$CU^{k+1} = -A(U^k)U^k$$ and solve iteratively those linear systems.
The problem: unfortunately, the fix-point iteration gives me NaN and I can't find the solution. Is it because the problem is ill-posed, or did I do something wrong with my idea of fixpoint iterations?
After @cos_theta's comment, I modified my code with the right weak formulation, but still the solution can't be found. 935
Basically, I made two functions, one where I assemble the matrix $A(U)$, and the other one where I assemble the matrix $C$. Then I have the fixed-point iteration loop.
In particular, the matrix $A(U)$ corresponds to $$\int \sqrt{ \sum_k u_k \phi_k } \sum_j u_j \phi_j' \phi_i' dx = 0$$
so it's tridiagonal and, for instance, the diagonal entry is $$\int_{x_{i-1}}^{x_i} \sqrt{u_{i-1}}\sqrt{\phi_{i-1}} \frac{1}{h^2}dx + \int_{x_i}^{x_{i+1}} \sqrt{u_{i+1}} \sqrt{\phi_{i+1}} \frac{1}{h^2}dx + \int_{x_{i-1}}^{x_{i+1}} \sqrt{u_i} \sqrt{\phi_i} \frac{1}{h^2} dx $$
where the values $\sqrt{u_{i-1}}$, $\sqrt{u_i}$, $\sqrt{u_{i+1}}$ are given by the previous iteration.
For the matrix $C$, I have that $$C_{ii}= \int_{x_{i-1}}^{x_i} \frac{1}{h} \phi_i \text{sgn}(x) dx + \int_{x_i}^{x_{i+1}} \frac{-1}{h} \phi_i \text{sgn}(x)dx$$ If the interval does not contain $x=0$, then $C_{ii}=0$. Otherwise, as shown in the linked answer, the entry that contains $x=0$ is $-1$. 490