Hello, I recently made this post on a PDE with constraint, and I would like to make a much simpler one here so other users can reply more easily.
I need to solve a complex PDE for two unknowns, subject to a constraint. Here I reproduce a minimal example of such a PDE. This example can be solved by solving analytically for the constraint and substituting, of course, but this is not my goal. I am providing this example to test whether Fenics can handle these constrained problems.
Consider a poisson equation in \Omega = [0,1]\times [0,1] for the two unknowns u and v
\nabla^2 (u+v) = f
with the additional constraint u - v = g,
and BCs
u=u_0 on \partial \Omega.
I can easily solve this in Fenics. However, as soon as I take a nonlinear constraint:
u^2 - v^2 = g,
the solution blows up. Do you have any idea of why ? Here is a snippet of the variational problem, let me know if you need the complete minimal working example, thank you.
So you are trying to add a quadratic penalty enforcing the second constraint
If that is the case, how are you actually adding the quadratic penalty to the energy minimization problem, as the usual way to formulate a penalty approach is to start with for instance the Dirichlet-energy
\min_{u} J = \min_{u} \int_\Omega \nabla u \cdot \nabla u~\mathrm{d}x - \int_\Omega f \cdot v ~ \mathrm{d}x
subject to
and add the quadratic penalty to this equation, i.e.
\min_{u} J + P =\min_{u} J + \frac{\alpha}{2}\int_\partial\Omega (u - g)^2~\mathrm{d}s
and then derive the optimality conditions (your residual) from this.
It is not super clear how you would do that in your case, and how you derived your system.
Additionally, your code is not reproducible, and one has to guess what spaces u, v, g, nu_u, nu_v are in.
My whole point was to illustrate how one would usually go about implementing a penalty method, with the hope that you in turn could explain how you ended up with your variational formulation.
When using quadratic penalty, you usually come from an energy minimisation perspective, as I showed in my previous post.
What kind of energy are you minimizing?
It would really help for readability that you write out your variational form in mathematics , ie using latex notation, as it is way more readable than the code you have provided, and makes it easier to link to the aforementioned functional.
Thank you for your reply. I am sorry, I have sent you the wrong variational problem. Here is the variational functional which I think should implement the constraint:
F = F_{\rm Poisson} + F_{\rm constraint}
where F_{\rm Poisson} is the functional related to the Poisson equation that you wrote:
If I vary F_{\rm Poisson} with respect to u and v I obtain
\delta F_{\rm Poisson} = \int_{\Omega} \{[ \nabla (u+v) ]\cdot[ \nabla (\nu_u+\nu_v)] ] + f (\nu_u + \nu_v)\} = \int_{\Omega} \{[ -\nabla^2 (u+v) +f] (\nu_u + \nu_v)\}, where \nu_u = \delta u, \nu_v = \delta v are the test functions related to u and v, respectively.
\delta F_{\rm Poisson} =0 is the equation which I obtain if I consider the original PDE \nabla^2 (u+v)-f=0, multiplied it by \nu_u + \nu_v, and integrated.
Following the example in your post, the functional F_{\rm constraint} which enforces the constraint u^2-v^2=g could be (?)
I don’t know why in your post you wrote the integral over the boundary only. Here F_{\rm constraint} is an integral over \Omega, dx, because I want to enforce the constraint in \Omega. If I vary F_{\rm constraint} I get
\delta F_{\rm constraint} = \alpha \int_{\Omega} dx (u^2 -v^2-g) (2 u \nu_u - 2 v \nu_v).
Would I obtain the solution of the PDE above with the constraint above if I solved the variational problem \delta F_{\rm Poisson} + \delta F_{\rm constraint} = 0?
The reason for doing it over the boundary was to illustrate how the penalty method works. As you had only provided your variational formulation, it was very unclear how you had derived your scheme.
If you look at your derivation above, you observe that you do get
Another thing you should consider is to start with a non-zero initial guess, as you can see from your maths above, the constraint part of the residual is 0 if u=v=0.
Thank you, it converges to the correct solution indeed, but the initial guess has to be extremely close to the exact solution.
Are you aware of any way to make the algorithm converge even if one starts further away from the exact solution? Maybe some specific solver options?
Lowering the relaxation_parameter helps a bit, but if I start too far away form the exact solution lowering the relaxation parameter does not solve the issue, and the error blows up during the solver iteration.
I can provide a full minimal working example if this helps.