sunnuntai 30. maaliskuuta 2014

Progress on Julia code

Today I implemented a not-so-well-thought-out way to have node-wise defined material parameters in the bilinear forms. The whole assembly process is implemented as a macro, since that way there won't be any performance losses related to e.g. evaluation of some anonymous function defining the bilinear form. Such approach however forces me to build an additional macros for different bilinear forms with different amount of nodal parameters. I haven't yet come up with any particularly elegant solution and because of that I currently just have two different macros like
macro bilin_asm(bilin_form,mesh)
...
end
macro bilin_asm_mat(bilin_form,mesh,mat)
...
end
which are then used as follows:
S = @bilin_asm(ux*vx+uy*vy,mesh)
S = @bilin_asm_mat(a*(ux*vx+uy*vy),mesh,mat)
Here mat is a vector of size $N \times 1$ where $N$ is the amount of nodes in the mesh. Using this approach I can quite easily solve some simple non-linear Poisson equations using e.g. Picard iteration. As an example I decided to try the minimal surface problem: Find the function $u$ for which $$\nabla \cdot \left(\frac{\nabla u}{\sqrt{1+|\nabla u|^2}}\right) = 0$$ on the domain $\Omega = (0,1)^2$ and $u = g$ on the boundary $\partial \Omega$. Such function has minimal surface area of all functions satisfying the boundary condition $u|_{\partial \Omega} = g$. The weak formulation reads: Find $u \in V := \{ w \in H^1(\Omega)\,|\,w|_{\partial \Omega} = g\}$ such that $$\int_\Omega \frac{\nabla u \cdot \nabla v}{\sqrt{1+|\nabla u|^2}} \, \mathrm{d}x = 0$$ for every $v \in H^1_0(\Omega)$. The linearized problem using the Picard iteration reads: Find $u_k \in V$ such that $$\int_\Omega \frac{\nabla u_k \cdot \nabla v}{\sqrt{1+|\nabla u_{k-1}|^2}} \, \mathrm{d}x = 0$$ for every $v \in H^1_0(\Omega)$. Initial guess $u_0$ can be for example some constant. In my test case I have $$g = \sin(2 \pi x - 7/10) \sin(2\pi y-3/10)$$ and the initial guess $u_0(x) = g(x)$.

Initial guess
 
First iteration
Second iteration